]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce Mapping::is_compatible_with
authorTimo Heister <timo.heister@gmail.com>
Fri, 22 Jan 2021 17:04:59 +0000 (12:04 -0500)
committerTimo Heister <timo.heister@gmail.com>
Fri, 22 Jan 2021 17:04:59 +0000 (12:04 -0500)
- Introduce Mapping::is_compatible_with()
- Implement for all Mapping classes
- Use in FEValues::reinit()

12 files changed:
include/deal.II/fe/mapping.h
include/deal.II/fe/mapping_cartesian.h
include/deal.II/fe/mapping_fe.h
include/deal.II/fe/mapping_fe_field.h
include/deal.II/fe/mapping_manifold.h
include/deal.II/fe/mapping_q.h
include/deal.II/fe/mapping_q_generic.h
source/fe/fe_values.cc
source/fe/mapping_cartesian.cc
source/fe/mapping_fe_field.cc
source/fe/mapping_q.cc
source/fe/mapping_q_generic.cc

index b6d587aa04be71e7393f2091b67bf66982f34882..ede2ebe400742a4128a7daff4a6acf825f56a3c4 100644 (file)
@@ -401,6 +401,14 @@ public:
   virtual bool
   preserves_vertex_locations() const = 0;
 
+  /**
+   * Returns is this instance of Mapping is compatible with the type of cell
+   * in @p cell_type.
+   *
+   */
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const = 0;
+
   /**
    * @name Mapping points between reference and real cells
    * @{
index 5fbb61f554b1d16f62716a3e3a653f17786ec677..543ab649dd91ed1e1bb9844b6b829ec950c46428 100644 (file)
@@ -88,6 +88,9 @@ public:
   virtual bool
   preserves_vertex_locations() const override;
 
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const override;
+
   /**
    * @name Mapping points between reference and real cells
    * @{
index 95c8591884d057e7971a253377393caa8dad5752..0e0bb66592bf1e076ed9b7b86f66fdcbb52f16a4 100644 (file)
@@ -85,6 +85,9 @@ public:
                      &cell) const override;
 
 
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const override;
+
   /**
    * Always returns @p true because the default implementation of functions in
    * this class preserves vertex locations.
@@ -604,6 +607,18 @@ MappingFE<dim, spacedim>::preserves_vertex_locations() const
   return true;
 }
 
+
+template <int dim, int spacedim>
+bool
+MappingFE<dim, spacedim>::is_compatible_with(
+  const ReferenceCell::Type &cell_type) const
+{
+  if (cell_type.get_dimension() != dim)
+    return false; // TODO: or is this an error?
+
+  return true;
+}
+
 #endif // DOXYGEN
 
 /* -------------- declaration of explicit specializations ------------- */
index 7f36f19cf96b992adea24920c33ef27e06e189ed..c0bf9d8e2bbb52c974ba10fe7890558dc7aaf34e 100644 (file)
@@ -210,6 +210,9 @@ public:
   virtual bool
   preserves_vertex_locations() const override;
 
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const override;
+
   /**
    * Return the mapped vertices of a cell.
    *
index 60c3f4b2064e4b038f115cba227746e1d53afe1f..aeb7ef723ba5c2514c7f11ff43307e87ab2c1eae 100644 (file)
@@ -79,6 +79,9 @@ public:
   virtual bool
   preserves_vertex_locations() const override;
 
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const override;
+
   /**
    * @name Mapping points between reference and real cells
    * @{
@@ -434,6 +437,23 @@ MappingManifold<dim, spacedim>::preserves_vertex_locations() const
   return true;
 }
 
+
+template <int dim, int spacedim>
+bool
+MappingManifold<dim, spacedim>::is_compatible_with(
+  const ReferenceCell::Type &cell_type) const
+{
+  if (cell_type.get_dimension() != dim)
+    return false; // TODO: or is this an error?
+
+  if (cell_type.is_hyper_cube())
+    return true;
+
+  return false;
+}
+
+
+
 #endif // DOXYGEN
 
 /* -------------- declaration of explicit specializations ------------- */
index 168191bce434cd95701f1f60adebe30a00fe23e5..54154b470dfcf5356806ac4661b02477b891c06a 100644 (file)
@@ -124,6 +124,9 @@ public:
   get_bounding_box(const typename Triangulation<dim, spacedim>::cell_iterator
                      &cell) const override;
 
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const override;
+
   /**
    * Transform the point @p p on the unit cell to the point @p p_real on the
    * real cell @p cell and returns @p p_real.
index 8a2d6ddb0e3df4e3f33ada353f511d59215079dc..d456a3ad6800fe9043568a46ce25bcf4356c1d37 100644 (file)
@@ -170,6 +170,9 @@ public:
   get_bounding_box(const typename Triangulation<dim, spacedim>::cell_iterator
                      &cell) const override;
 
+  virtual bool
+  is_compatible_with(const ReferenceCell::Type &cell_type) const override;
+
   /**
    * @name Mapping points between reference and real cells
    * @{
index 4f5348d568f0d0efe308e4673f25d35060549a8d..7000d921dd790cd44d2a546c61f66867cda2dcb0 100644 (file)
@@ -4499,6 +4499,13 @@ void
 FEValues<dim, spacedim>::reinit(
   const typename Triangulation<dim, spacedim>::cell_iterator &cell)
 {
+  // Check that mapping and reference cell type are compatible:
+  Assert(this->get_mapping().is_compatible_with(cell->reference_cell_type()),
+         ExcMessage(
+           "You are trying to call FEValues::reinit() with a cell of type " +
+           cell->reference_cell_type().to_string() +
+           " with a Mapping that is not compatible with it."));
+
   // no FE in this cell, so no assertion
   // necessary here
   this->maybe_invalidate_previous_present_cell(cell);
@@ -4528,6 +4535,13 @@ FEValues<dim, spacedim>::reinit(
            static_cast<const FiniteElementData<dim> &>(cell->get_fe()),
          (typename FEValuesBase<dim, spacedim>::ExcFEDontMatch()));
 
+  // Check that mapping and reference cell type are compatible:
+  Assert(this->get_mapping().is_compatible_with(cell->reference_cell_type()),
+         ExcMessage(
+           "You are trying to call FEValues::reinit() with a cell of type " +
+           cell->reference_cell_type().to_string() +
+           " with a Mapping that is not compatible with it."));
+
   this->maybe_invalidate_previous_present_cell(cell);
   this->check_cell_similarity(cell);
 
index dbb65d925e3a8b7d817bb744171447c5c47f986e..1a138613d11bf50c78eb4e59f6093fd9be1091a1 100644 (file)
@@ -70,6 +70,22 @@ MappingCartesian<dim, spacedim>::preserves_vertex_locations() const
 
 
 
+template <int dim, int spacedim>
+bool
+MappingCartesian<dim, spacedim>::is_compatible_with(
+  const ReferenceCell::Type &cell_type) const
+{
+  if (cell_type.get_dimension() != dim)
+    return false; // TODO: or is this an error?
+
+  if (cell_type.is_hyper_cube())
+    return true;
+
+  return false;
+}
+
+
+
 template <int dim, int spacedim>
 UpdateFlags
 MappingCartesian<dim, spacedim>::requires_update_flags(
index 0cad06d6f430a8d41331b9a9eff468ab137f4974..c9815c61b3a21bb76d9d26df4496faecb5d3081f 100644 (file)
@@ -342,6 +342,19 @@ MappingFEField<dim, spacedim, VectorType, void>::preserves_vertex_locations()
 
 
 
+template <int dim, int spacedim, typename VectorType>
+bool
+MappingFEField<dim, spacedim, VectorType, void>::is_compatible_with(
+  const ReferenceCell::Type &cell_type) const
+{
+  if (cell_type.get_dimension() != dim)
+    return false; // TODO: or is this an error?
+
+  return true;
+}
+
+
+
 template <int dim, int spacedim, typename VectorType>
 boost::container::small_vector<Point<spacedim>,
                                GeometryInfo<dim>::vertices_per_cell>
@@ -2221,6 +2234,7 @@ MappingFEField<dim, spacedim, VectorType, void>::get_degree() const
 }
 
 
+
 template <int dim, int spacedim, typename VectorType>
 ComponentMask
 MappingFEField<dim, spacedim, VectorType, void>::get_component_mask() const
index 38f412e293a3bf80ac90accfe8c9f049f96cab63..185bf102dc15585d4c212ac2ed693187688697cb 100644 (file)
@@ -559,6 +559,22 @@ MappingQ<dim, spacedim>::get_bounding_box(
 
 
 
+template <int dim, int spacedim>
+bool
+MappingQ<dim, spacedim>::is_compatible_with(
+  const ReferenceCell::Type &cell_type) const
+{
+  if (cell_type.get_dimension() != dim)
+    return false; // TODO: or is this an error?
+
+  if (cell_type.is_hyper_cube())
+    return true;
+
+  return false;
+}
+
+
+
 // explicit instantiations
 #include "mapping_q.inst"
 
index 02dd963685b11df556817542d481f6cec72de34e..0f90658d456c0893bb9f8896c8025c3bf54b1fba 100644 (file)
@@ -1652,6 +1652,22 @@ MappingQGeneric<dim, spacedim>::get_bounding_box(
 
 
 
+template <int dim, int spacedim>
+bool
+MappingQGeneric<dim, spacedim>::is_compatible_with(
+  const ReferenceCell::Type &cell_type) const
+{
+  if (cell_type.get_dimension() != dim)
+    return false; // TODO: or is this an error?
+
+  if (cell_type.is_hyper_cube())
+    return true;
+
+  return false;
+}
+
+
+
 //--------------------------- Explicit instantiations -----------------------
 #include "mapping_q_generic.inst"
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.