From 5df43c82b4e73c4c19cb373df01c427ab8be2baa Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Fri, 27 Apr 2018 00:52:14 +0200 Subject: [PATCH] Adol-C advanced branching: Fix FEValues --- source/fe/fe_values.cc | 125 ++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 57 deletions(-) diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 9a6ad95206..fb368f2d2f 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -97,6 +97,36 @@ namespace internal return shape_function_to_row_table; } + + namespace + { + // Check to see if a DoF value is zero, implying that subsequent operations + // with the value have no effect. + template + struct CheckForZero + { + static bool + value (const Number &value) + { + return value == dealii::internal::NumberType::value(0.0); + } + }; + + // For auto-differentiable numbers, the fact that a DoF value is zero + // does not imply that its derivatives are zero as well. So we + // can't filter by value for these number types. + // Note that we also want to avoid actually checking the value itself, + // since some AD numbers are not contextually convertible to booleans. + template + struct CheckForZero::value>::type> + { + static bool + value (const Number &/*value*/) + { + return false; + } + }; + } } @@ -489,9 +519,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0) ) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; const double *shape_value_ptr = &shape_values(shape_function_data[shape_function].row_index, 0); @@ -527,9 +556,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0) ) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; const dealii::Tensor *shape_derivative_ptr = &shape_derivatives[shape_function_data[shape_function].row_index][0]; @@ -563,9 +591,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; const dealii::Tensor<2,spacedim> *shape_hessian_ptr = &shape_hessians[shape_function_data[shape_function].row_index][0]; @@ -605,9 +632,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -659,9 +685,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -715,9 +740,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -772,9 +796,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -837,9 +860,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -900,9 +922,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -1026,9 +1047,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -1084,9 +1104,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -1142,9 +1161,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -1234,9 +1252,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -1294,9 +1311,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -1358,9 +1374,8 @@ namespace FEValuesViews // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (snc != -1) { @@ -2847,9 +2862,8 @@ namespace internal // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (fe.is_primitive(shape_func)) { @@ -2928,9 +2942,8 @@ namespace internal // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; const Tensor *shape_derivative_ptr = &shape_derivatives[shape_func][0]; @@ -2992,9 +3005,8 @@ namespace internal // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (fe.is_primitive(shape_func)) { @@ -3127,9 +3139,8 @@ namespace internal // For auto-differentiable numbers, the fact that a DoF value is zero // does not imply that its derivatives are zero as well. So we // can't filter by value for these number types. - if (!Differentiation::AD::is_ad_number::value) - if (value == dealii::internal::NumberType::value(0.0)) - continue; + if (dealii::internal::CheckForZero::value(value) == true) + continue; if (fe.is_primitive(shape_func)) { -- 2.39.5