]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Better document what tolerance to use in MappingCartesian. 14103/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 6 Jul 2022 17:52:45 +0000 (11:52 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 8 Jul 2022 00:12:50 +0000 (18:12 -0600)
source/fe/mapping_cartesian.cc

index 47349a5dd1967c8676cbeed42256bed7082ea259..1620af218e764134620ecfa4586770d2f8d9af73 100644 (file)
@@ -55,19 +55,28 @@ is_cartesian(const CellType &cell)
   if (!cell->reference_cell().is_hyper_cube())
     return false;
 
-  const double tolerance         = 1e-14;
+  const double abs_tol           = 1e-15;
+  const double rel_tol           = 1e-14;
   const auto   bounding_box      = cell->bounding_box();
   const auto & bounding_vertices = bounding_box.get_boundary_points();
-  const auto   cell_measure =
+  const auto   bb_diagonal_length_squared =
     bounding_vertices.first.distance_square(bounding_vertices.second);
 
   for (const unsigned int v : cell->vertex_indices())
     {
-      const double vertex_tolerance =
-        tolerance * std::max(cell->vertex(v).norm_square(), cell_measure);
-
-      if (cell->vertex(v).distance_square(bounding_box.vertex(v)) >
-          vertex_tolerance)
+      // Choose a tolerance that takes into account both that vertices far
+      // away from the origin have only a finite number of digits
+      // that are considered correct (an "absolute tolerance"), as well as that
+      // vertices are supposed to be close to the corresponding vertices of the
+      // bounding box (a tolerance that is "relative" to the size of the cell).
+      //
+      // We need to do it this way because when a vertex is far away from
+      // the origin, computing the difference between two vertices is subject
+      // to cancellation.
+      const double tolerance = std::max(abs_tol * cell->vertex(v).norm_square(),
+                                        rel_tol * bb_diagonal_length_squared);
+
+      if (cell->vertex(v).distance_square(bounding_box.vertex(v)) > tolerance)
         return false;
     }
 

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.