Skip to content

Commit

Permalink
Assert that the incoming cell is Cartesian in MappingCartesian
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsticko committed May 17, 2022
1 parent c64238d commit 3dc8884
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions source/fe/mapping_cartesian.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@

DEAL_II_NAMESPACE_OPEN

DeclExceptionMsg(
ExcCellNotCartesian,
"You are using MappingCartesian, but the incoming cell is not Cartesian.");



/**
* Return whether the incoming cell is of Cartesian shape. This is determined by
* checking if the smallest BoundingBox that encloses the cell has the same
* vertices as the cell itself.
*/
template <class CellType>
bool
is_cartesian(const CellType &cell)
{
if (!cell->is_hyper_cube())
return false;

const double tolerance = 1e-14 * cell->diameter();
const auto bounding_box = cell->bounding_box();

for (const unsigned int v : cell->vertex_indices())
if (cell->vertex(v).distance(bounding_box.vertex(v)) > tolerance)
return false;

return true;
}



template <int dim, int spacedim>
Expand Down Expand Up @@ -455,6 +483,8 @@ MappingCartesian<dim, spacedim>::fill_fe_values(
internal::FEValuesImplementation::MappingRelatedData<dim, spacedim>
&output_data) const
{
Assert(is_cartesian(cell), ExcCellNotCartesian());

// convert data object to internal data for this class. fails with
// an exception if that is not possible
Assert(dynamic_cast<const InternalData *>(&internal_data) != nullptr,
Expand Down Expand Up @@ -504,6 +534,8 @@ MappingCartesian<dim, spacedim>::fill_mapping_data_for_generic_points(
if (update_flags == update_default)
return;

Assert(is_cartesian(cell), ExcCellNotCartesian());

Assert(update_flags & update_inverse_jacobians ||
update_flags & update_jacobians ||
update_flags & update_quadrature_points,
Expand Down Expand Up @@ -538,6 +570,7 @@ MappingCartesian<dim, spacedim>::fill_fe_face_values(
internal::FEValuesImplementation::MappingRelatedData<dim, spacedim>
&output_data) const
{
Assert(is_cartesian(cell), ExcCellNotCartesian());
AssertDimension(quadrature.size(), 1);

// convert data object to internal
Expand Down Expand Up @@ -591,6 +624,8 @@ MappingCartesian<dim, spacedim>::fill_fe_subface_values(
internal::FEValuesImplementation::MappingRelatedData<dim, spacedim>
&output_data) const
{
Assert(is_cartesian(cell), ExcCellNotCartesian());

// convert data object to internal data for this class. fails with
// an exception if that is not possible
Assert(dynamic_cast<const InternalData *>(&internal_data) != nullptr,
Expand Down Expand Up @@ -647,6 +682,7 @@ MappingCartesian<dim, spacedim>::fill_fe_immersed_surface_values(
&output_data) const
{
AssertDimension(dim, spacedim);
Assert(is_cartesian(cell), ExcCellNotCartesian());

// Convert data object to internal data for this class. Fails with an
// exception if that is not possible.
Expand Down Expand Up @@ -1113,6 +1149,8 @@ MappingCartesian<dim, spacedim>::transform_unit_to_real_cell(
const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const Point<dim> & p) const
{
Assert(is_cartesian(cell), ExcCellNotCartesian());

Tensor<1, dim> length;
const Point<dim> start = cell->vertex(0);
switch (dim)
Expand Down Expand Up @@ -1148,6 +1186,8 @@ MappingCartesian<dim, spacedim>::transform_real_to_unit_cell(
const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const Point<spacedim> & p) const
{
Assert(is_cartesian(cell), ExcCellNotCartesian());

if (dim != spacedim)
Assert(false, ExcNotImplemented());
const Point<dim> &start = cell->vertex(0);
Expand Down

0 comments on commit 3dc8884

Please sign in to comment.