Skip to content

Commit 2807fa3

Browse files
jacobmersoncwsmith
andauthored
add tolerances (#79)
* increase tolerances on shape function checks * fix capture of IIFE * define looser epilon tolerance, remove print --------- Co-authored-by: Cameron Smith <[email protected]>
1 parent 587b6e5 commit 2807fa3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/MeshField_Defines.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ enum Mesh_Topology {
1717
};
1818
static bool Debug = false;
1919
const Real MachinePrecision = 1e-15;
20+
const Real Epsilon = 1e-12;
2021
} // namespace MeshField
2122
#endif

src/MeshField_Shape.hpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@
66
// SCOREC/core apf/apfShape.cc @ 7cd76473
77

88
namespace {
9-
template <typename Array> KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi) {
10-
auto sum = 0.0;
11-
for (size_t i = 0; i < xi.size(); i++) {
12-
sum += xi[i];
13-
}
14-
return (Kokkos::fabs(sum - 1) <= MeshField::MachinePrecision);
9+
template <typename Array>
10+
KOKKOS_INLINE_FUNCTION bool
11+
sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) {
12+
// IIFE, capture by reference is preferred
13+
const bool sums_to_one = [&]() {
14+
auto sum = 0.0;
15+
for (size_t i = 0; i < xi.size(); i++) {
16+
sum += xi[i];
17+
}
18+
return (Kokkos::fabs(sum - 1) <= tol);
19+
}();
20+
return sums_to_one;
1521
}
1622

1723
template <typename Array>
18-
KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi) {
19-
auto gt = true;
24+
KOKKOS_INLINE_FUNCTION bool
25+
greaterThanOrEqualZero(Array &xi, double tol = MeshField::Epsilon) {
2026
for (size_t i = 0; i < xi.size(); i++) {
21-
gt = gt && (xi[i] >= 0);
27+
if (xi[i] < -tol) {
28+
return false;
29+
}
2230
}
23-
return gt;
31+
return true;
2432
}
2533
} // namespace
2634

0 commit comments

Comments
 (0)