diff --git a/src/MeshField_Defines.hpp b/src/MeshField_Defines.hpp index 36b0ff7..d3a216f 100644 --- a/src/MeshField_Defines.hpp +++ b/src/MeshField_Defines.hpp @@ -17,5 +17,6 @@ enum Mesh_Topology { }; static bool Debug = false; const Real MachinePrecision = 1e-15; +const Real Epsilon = 1e-12; } // namespace MeshField #endif diff --git a/src/MeshField_Shape.hpp b/src/MeshField_Shape.hpp index e724809..79b6b3f 100644 --- a/src/MeshField_Shape.hpp +++ b/src/MeshField_Shape.hpp @@ -6,21 +6,29 @@ // SCOREC/core apf/apfShape.cc @ 7cd76473 namespace { -template KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi) { - auto sum = 0.0; - for (size_t i = 0; i < xi.size(); i++) { - sum += xi[i]; - } - return (Kokkos::fabs(sum - 1) <= MeshField::MachinePrecision); +template +KOKKOS_INLINE_FUNCTION bool +sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) { + // IIFE, capture by reference is preferred + const bool sums_to_one = [&]() { + auto sum = 0.0; + for (size_t i = 0; i < xi.size(); i++) { + sum += xi[i]; + } + return (Kokkos::fabs(sum - 1) <= tol); + }(); + return sums_to_one; } template -KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi) { - auto gt = true; +KOKKOS_INLINE_FUNCTION bool +greaterThanOrEqualZero(Array &xi, double tol = MeshField::Epsilon) { for (size_t i = 0; i < xi.size(); i++) { - gt = gt && (xi[i] >= 0); + if (xi[i] < -tol) { + return false; + } } - return gt; + return true; } } // namespace