Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MeshField_Defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ enum Mesh_Topology {
};
static bool Debug = false;
const Real MachinePrecision = 1e-15;
const Real Epsilon = 1e-12;
} // namespace MeshField
#endif
28 changes: 18 additions & 10 deletions src/MeshField_Shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
// SCOREC/core apf/apfShape.cc @ 7cd76473

namespace {
template <typename Array> 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 <typename Array>
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 <typename Array>
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

Expand Down
Loading