]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Similar test with equality comparison 13979/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Wed, 15 Jun 2022 12:33:12 +0000 (14:33 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Wed, 15 Jun 2022 12:33:12 +0000 (14:33 +0200)
tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc

index 678991dac900ccafd3d2ed374397295f82437c4a..99f3228eafb05d00f3fa4c03df5c15041efd7f6f 100644 (file)
@@ -56,7 +56,9 @@ test_view(const Vector<double> &            solution,
 {
   using View = typename std::remove_reference<
     typename std::remove_const<decltype(fe_values[extractor])>::type>::type;
-  const View &fe_values_view = fe_values[extractor];
+  const View &     fe_values_view = fe_values[extractor];
+  const NumberType tolerance =
+    std::is_same<NumberType, float>::value ? 1e-5 : 1e-13;
 
   // Typedefs
   using value_type =
@@ -116,21 +118,24 @@ test_view(const Vector<double> &            solution,
   // Output
   for (unsigned int q = 0; q < n_q_points; ++q)
     {
-      if (value_type(qp_values_local[q]) != value_type(qp_values_global[q]))
+      if (std::abs(qp_values_local[q] - qp_values_global[q]) >
+          tolerance * std::abs(qp_values_global[q]))
         deallog << "NOT OK: Value @ " << q << std::endl;
 
-      if (gradient_type(qp_grads_local[q]) != gradient_type(qp_grads_global[q]))
+      if ((qp_grads_local[q] - qp_grads_global[q]).norm() >
+          tolerance * qp_grads_global[q].norm())
         deallog << "NOT OK: Grad @ " << q << std::endl;
 
-      if (hessian_type(qp_hess_local[q]) != hessian_type(qp_hess_global[q]))
+      if ((qp_hess_local[q] - qp_hess_global[q]).norm() >
+          tolerance * qp_hess_global[q].norm())
         deallog << "NOT OK: Hess @ " << q << std::endl;
 
-      if (laplacian_type(qp_laplace_local[q]) !=
-          laplacian_type(qp_laplace_global[q]))
+      if (std::abs(qp_laplace_local[q] - qp_laplace_global[q]) >
+          tolerance * std::abs(qp_laplace_global[q]))
         deallog << "NOT OK: Laplace @ " << q << std::endl;
 
-      if (third_derivative_type(qp_third_deriv_local[q]) !=
-          third_derivative_type(qp_third_deriv_global[q]))
+      if ((qp_third_deriv_local[q] - qp_third_deriv_global[q]).norm() >
+          tolerance * qp_third_deriv_global[q].norm())
         deallog << "NOT OK: 3rd der @ " << q << std::endl;
     }
 }
@@ -146,7 +151,9 @@ test_view(const Vector<double> &            solution,
 {
   using View = typename std::remove_reference<
     typename std::remove_const<decltype(fe_values[extractor])>::type>::type;
-  const View &fe_values_view = fe_values[extractor];
+  const View &     fe_values_view = fe_values[extractor];
+  const NumberType tolerance =
+    std::is_same<NumberType, float>::value ? 1e-5 : 1e-13;
 
   // Typedefs
   using value_type =
@@ -239,35 +246,39 @@ test_view(const Vector<double> &            solution,
   // Output
   for (unsigned int q = 0; q < n_q_points; ++q)
     {
-      if (value_type(qp_values_local[q]) != value_type(qp_values_global[q]))
+      if ((qp_values_local[q] - qp_values_global[q]).norm() >
+          tolerance * qp_values_global[q].norm())
         deallog << "NOT OK: Value @ " << q << std::endl;
 
-      if (gradient_type(qp_grads_local[q]) != gradient_type(qp_grads_global[q]))
+      if ((qp_grads_local[q] - qp_grads_global[q]).norm() >
+          tolerance * qp_grads_global[q].norm())
         deallog << "NOT OK: Grad @ " << q << std::endl;
 
-      if (gradient_type(qp_symm_grads_local[q]) !=
-          gradient_type(qp_symm_grads_global[q]))
+      if ((qp_symm_grads_local[q] - qp_symm_grads_global[q]).norm() >
+          tolerance * qp_symm_grads_global[q].norm())
         deallog << "NOT OK: Symm grad @ " << q << std::endl;
 
-      if (divergence_type(qp_divs_local[q]) !=
-          divergence_type(qp_divs_global[q]))
+      if (std::abs(qp_divs_local[q] - qp_divs_global[q]) >
+          tolerance * std::abs(qp_divs_global[q]))
         deallog << "NOT OK: Div @ " << q << std::endl;
 
       // Note: FE_Q's are curl free: Should always be zero'd
       // So we are just checking that we don't hit an internal assert
       // when doing the above calls, rather than testing the values
-      if (curl_type(qp_curls_local[q]) != curl_type(qp_curls_global[q]))
+      if ((qp_curls_local[q] - qp_curls_global[q]).norm() >
+          tolerance * qp_curls_global[q].norm())
         deallog << "NOT OK: Curl @ " << q << std::endl;
 
-      if (hessian_type(qp_hess_local[q]) != hessian_type(qp_hess_global[q]))
+      if ((qp_hess_local[q] - qp_hess_global[q]).norm() >
+          tolerance * qp_hess_global[q].norm())
         deallog << "NOT OK: Hess @ " << q << std::endl;
 
-      if (laplacian_type(qp_laplace_local[q]) !=
-          laplacian_type(qp_laplace_global[q]))
+      if ((qp_laplace_local[q] - qp_laplace_global[q]).norm() >
+          tolerance * qp_laplace_global[q].norm())
         deallog << "NOT OK: Laplace @ " << q << std::endl;
 
-      if (third_derivative_type(qp_third_deriv_local[q]) !=
-          third_derivative_type(qp_third_deriv_global[q]))
+      if ((qp_third_deriv_local[q] - qp_third_deriv_global[q]).norm() >
+          tolerance * qp_third_deriv_global[q].norm())
         deallog << "NOT OK: 3rd der @ " << q << std::endl;
     }
 }
@@ -283,7 +294,9 @@ test_view(const Vector<double> &                        solution,
 {
   using View = typename std::remove_reference<
     typename std::remove_const<decltype(fe_values[extractor])>::type>::type;
-  const View &fe_values_view = fe_values[extractor];
+  const View &     fe_values_view = fe_values[extractor];
+  const NumberType tolerance =
+    std::is_same<NumberType, float>::value ? 1e-5 : 1e-13;
 
   // Typedefs
   using value_type =
@@ -310,11 +323,12 @@ test_view(const Vector<double> &                        solution,
   // Output
   for (unsigned int q = 0; q < n_q_points; ++q)
     {
-      if (value_type(qp_values_local[q]) != value_type(qp_values_global[q]))
+      if ((qp_values_local[q] - qp_values_global[q]).norm() >
+          tolerance * qp_values_global[q].norm())
         deallog << "NOT OK: Value @ " << q << std::endl;
 
-      if (divergence_type(qp_divs_local[q]) !=
-          divergence_type(qp_divs_global[q]))
+      if ((qp_divs_local[q] - qp_divs_global[q]).norm() >
+          tolerance * qp_divs_global[q].norm())
         deallog << "NOT OK: Div @ " << q << std::endl;
     }
 }
@@ -339,6 +353,8 @@ test_view(const Vector<double> &               solution,
     typename ProductType<typename View::gradient_type, NumberType>::type;
   using divergence_type =
     typename ProductType<typename View::divergence_type, NumberType>::type;
+  const NumberType tolerance =
+    std::is_same<NumberType, float>::value ? 1e-5 : 1e-13;
 
   // Values
   std::vector<typename View::template solution_value_type<NumberType>>
@@ -367,14 +383,16 @@ test_view(const Vector<double> &               solution,
   // Output
   for (unsigned int q = 0; q < n_q_points; ++q)
     {
-      if (value_type(qp_values_local[q]) != value_type(qp_values_global[q]))
+      if ((qp_values_local[q] - qp_values_global[q]).norm() >
+          tolerance * qp_values_global[q].norm())
         deallog << "NOT OK: Value @ " << q << std::endl;
 
-      if (divergence_type(qp_divs_local[q]) !=
-          divergence_type(qp_divs_global[q]))
+      if ((qp_divs_local[q] - qp_divs_global[q]).norm() >
+          tolerance * qp_divs_global[q].norm())
         deallog << "NOT OK: Div @ " << q << std::endl;
 
-      if (gradient_type(qp_grads_local[q]) != gradient_type(qp_grads_global[q]))
+      if ((qp_grads_local[q] - qp_grads_global[q]).norm() >
+          tolerance * qp_grads_global[q].norm())
         deallog << "NOT OK: Grad @ " << q << std::endl;
     }
 }

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.