From: Martin Kronbichler Date: Wed, 15 Jun 2022 12:33:12 +0000 (+0200) Subject: Similar test with equality comparison X-Git-Tag: v9.4.0-rc1~14^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e240cf3d683f9041a44963bc037629ffcae5da60;p=dealii.git Similar test with equality comparison --- diff --git a/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc b/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc index 678991dac9..99f3228eaf 100644 --- a/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc +++ b/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc @@ -56,7 +56,9 @@ test_view(const Vector & solution, { using View = typename std::remove_reference< typename std::remove_const::type>::type; - const View &fe_values_view = fe_values[extractor]; + const View & fe_values_view = fe_values[extractor]; + const NumberType tolerance = + std::is_same::value ? 1e-5 : 1e-13; // Typedefs using value_type = @@ -116,21 +118,24 @@ test_view(const Vector & 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 & solution, { using View = typename std::remove_reference< typename std::remove_const::type>::type; - const View &fe_values_view = fe_values[extractor]; + const View & fe_values_view = fe_values[extractor]; + const NumberType tolerance = + std::is_same::value ? 1e-5 : 1e-13; // Typedefs using value_type = @@ -239,35 +246,39 @@ test_view(const Vector & 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 & solution, { using View = typename std::remove_reference< typename std::remove_const::type>::type; - const View &fe_values_view = fe_values[extractor]; + const View & fe_values_view = fe_values[extractor]; + const NumberType tolerance = + std::is_same::value ? 1e-5 : 1e-13; // Typedefs using value_type = @@ -310,11 +323,12 @@ test_view(const Vector & 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 & solution, typename ProductType::type; using divergence_type = typename ProductType::type; + const NumberType tolerance = + std::is_same::value ? 1e-5 : 1e-13; // Values std::vector> @@ -367,14 +383,16 @@ test_view(const Vector & 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; } }