]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test fe/fe_values_view_{07|10|13|16}: make Assert more robust 16849/head
authorMatthias Maier <tamiko@43-1.org>
Fri, 5 Apr 2024 03:19:25 +0000 (22:19 -0500)
committerMatthias Maier <tamiko@43-1.org>
Fri, 5 Apr 2024 03:19:25 +0000 (22:19 -0500)
The Assert checks that we computed with a relative error of less than
1e-12. This fails however, if the vector in question is 0. Thus, also
check for an absolute error.

tests/fe/fe_values_view_07.cc
tests/fe/fe_values_view_10.cc
tests/fe/fe_values_view_13.cc
tests/fe/fe_values_view_16.cc

index 044bf2257c8fc94abcf4253db352cdf7e15953ec..217d646dc8ba7d06fa4c27a4e6001ff4219f8a6c 100644 (file)
@@ -72,9 +72,10 @@ test(const Triangulation<dim> &tr, const FiniteElement<dim> &fe)
       for (const auto q : fe_values.quadrature_point_indices())
         {
           deallog << scalar_values[q] << std::endl;
-          Assert((scalar_values[q] - vector_values[q][c]).norm() <=
-                   1e-12 * scalar_values[q].norm(),
-                 ExcInternalError());
+          const auto norm = (scalar_values[q] - vector_values[q][c]).norm();
+          const auto tolerance =
+            std::max(1.e-11, 1.e-12 * scalar_values[q].norm());
+          Assert(norm <= tolerance, ExcInternalError());
         }
     }
 }
index 68e1df2e96af83402a180b9e5a90dee41da95f7a..d0592ae0155905add8d95580f8ee4ce4a5c9d1b8 100644 (file)
@@ -78,9 +78,10 @@ test(const Triangulation<dim> &tr, const FiniteElement<dim> &fe)
               deallog << scalar_values[q][d][e]
                       << (d < dim - 1 || e < dim - 1 ? " " : "");
           deallog << std::endl;
-          Assert((scalar_values[q] - vector_values[q][c]).norm() <=
-                   1e-12 * scalar_values[q].norm(),
-                 ExcInternalError());
+          const auto norm = (scalar_values[q] - vector_values[q][c]).norm();
+          const auto tolerance =
+            std::max(1.e-11, 1.e-12 * scalar_values[q].norm());
+          Assert(norm <= tolerance, ExcInternalError());
         }
     }
 }
index 26ee8fbbe4d2b5edceb9f1fd22dd4febc50fba89..50d9bafc07034b79e331cc8de41ad75a90320ceb 100644 (file)
@@ -78,9 +78,11 @@ test(const Triangulation<dim> &tr, const FiniteElement<dim> &fe)
           for (unsigned int d = 0; d < dim; ++d)
             {
               deallog << selected_vector_values[q][d] << std::endl;
-              Assert((selected_vector_values[q][d] - vector_values[q][c + d])
-                         .norm() <= 1e-12 * selected_vector_values[q][d].norm(),
-                     ExcInternalError());
+              const auto norm =
+                (selected_vector_values[q][d] - vector_values[q][c + d]).norm();
+              const auto tolerance =
+                std::max(1.e-11, 1.e-12 * selected_vector_values[q][d].norm());
+              Assert(norm <= tolerance, ExcInternalError());
             }
       }
 }
index 43ed89355c2beacc748256bd3c2f9d2f102fd172..fe281b40e3c5d101b38033e79b8c75d1a215154b 100644 (file)
@@ -83,9 +83,11 @@ test(const Triangulation<dim> &tr, const FiniteElement<dim> &fe)
                 for (unsigned int f = 0; f < dim; ++f)
                   deallog << selected_vector_values[q][d][e][f] << ' ';
               deallog << std::endl;
-              Assert((selected_vector_values[q][d] - vector_values[q][c + d])
-                         .norm() <= 1e-12 * selected_vector_values[q][d].norm(),
-                     ExcInternalError());
+              const auto norm =
+                (selected_vector_values[q][d] - vector_values[q][c + d]).norm();
+              const auto tolerance =
+                std::max(1.e-11, 1.e-12 * selected_vector_values[q][d].norm());
+              Assert(norm <= tolerance, ExcInternalError());
             }
       }
 }

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.