From 023a43d367155b1d62c7f108432b8c13b78ba44f Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Sun, 16 Nov 2025 11:54:26 -0800 Subject: [PATCH 1/5] increase tolerances on shape function checks --- src/MeshField_Shape.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/MeshField_Shape.hpp b/src/MeshField_Shape.hpp index ceafda5..687d66e 100644 --- a/src/MeshField_Shape.hpp +++ b/src/MeshField_Shape.hpp @@ -11,16 +11,27 @@ template KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi) { for (int i = 0; i < xi.size(); i++) { sum += xi[i]; } - return (Kokkos::fabs(sum - 1) <= MeshField::MachinePrecision); + bool sums_to_one = (Kokkos::fabs(sum - 1) <= 10*MeshField::MachinePrecision); + if(!sums_to_one) { + for (int i = 0; i < xi.size(); i++) { + printf("%e ", xi[i]); + } + printf("\n"); + printf("sum %e %e \n", std::fabs(sum-1), MeshField::MachinePrecision); + } + return (Kokkos::fabs(sum - 1) <= 1E-12); } template KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi) { auto gt = true; for (int i = 0; i < xi.size(); i++) { - gt = gt && (xi[i] >= 0); + if(xi[i] < -1E-12){ + printf("failure %d, %e, %e\n", i, xi[i], 10*MeshField::MachinePrecision); + return false; + } } - return gt; + return true; } } // namespace From fbb32ef70b9964601f448dc83bbcb118d0abb8d5 Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Sun, 16 Nov 2025 12:11:33 -0800 Subject: [PATCH 2/5] update formatting with clang-format --- src/MeshField_Shape.hpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/MeshField_Shape.hpp b/src/MeshField_Shape.hpp index f63d628..24d1940 100644 --- a/src/MeshField_Shape.hpp +++ b/src/MeshField_Shape.hpp @@ -6,29 +6,32 @@ // SCOREC/core apf/apfShape.cc @ 7cd76473 namespace { -template KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi, double tol=10*MeshField::MachinePrecision) { - const bool sums_to_one = [](){ +template +KOKKOS_INLINE_FUNCTION bool +sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) { + 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); }(); - if(!sums_to_one) { - for (int i = 0; i < xi.size(); i++) { + if (!sums_to_one) { + for (int i = 0; i < xi.size(); i++) { printf("%e ", xi[i]); - } - printf("\n"); - printf("sum: %e tol: %e \n", std::fabs(sum-1), tol); + } + printf("\n"); + printf("sum: %e tol: %e \n", std::fabs(sum - 1), tol); } return sums_to_one; } template -KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi, double tol=1E-12) { +KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi, + double tol = 1E-12) { for (size_t i = 0; i < xi.size(); i++) { - if(xi[i] < -tol){ - printf("failure %d, %e, %e\n", i, xi[i], tol); + if (xi[i] < -tol) { + printf("failure %d, %e, %e\n", i, xi[i], tol); return false; } } From e0be3e01748cdb5a6833e90f5b5d52371f28a1d4 Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Sun, 16 Nov 2025 13:35:25 -0800 Subject: [PATCH 3/5] fix capture of IIFE --- src/MeshField_Shape.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/MeshField_Shape.hpp b/src/MeshField_Shape.hpp index 24d1940..6da49f1 100644 --- a/src/MeshField_Shape.hpp +++ b/src/MeshField_Shape.hpp @@ -9,7 +9,8 @@ namespace { template KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) { - const bool sums_to_one = []() { + // 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]; @@ -21,7 +22,6 @@ sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) { printf("%e ", xi[i]); } printf("\n"); - printf("sum: %e tol: %e \n", std::fabs(sum - 1), tol); } return sums_to_one; } @@ -31,7 +31,6 @@ KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi, double tol = 1E-12) { for (size_t i = 0; i < xi.size(); i++) { if (xi[i] < -tol) { - printf("failure %d, %e, %e\n", i, xi[i], tol); return false; } } From db075a175f4f231c736967b2be5b25e6e2686306 Mon Sep 17 00:00:00 2001 From: Cameron Smith Date: Mon, 17 Nov 2025 11:50:31 -0500 Subject: [PATCH 4/5] define looser epilon tolerance, remove print --- src/MeshField_Defines.hpp | 1 + src/MeshField_Shape.hpp | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) 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 6da49f1..c79201e 100644 --- a/src/MeshField_Shape.hpp +++ b/src/MeshField_Shape.hpp @@ -17,18 +17,12 @@ sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) { } return (Kokkos::fabs(sum - 1) <= tol); }(); - if (!sums_to_one) { - for (int i = 0; i < xi.size(); i++) { - printf("%e ", xi[i]); - } - printf("\n"); - } return sums_to_one; } template KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi, - double tol = 1E-12) { + double tol = MeshField::Epsilon) { for (size_t i = 0; i < xi.size(); i++) { if (xi[i] < -tol) { return false; From 6b3906f310ab07ad18b1d89a00e008d76ce3cbff Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Mon, 17 Nov 2025 11:54:23 -0800 Subject: [PATCH 5/5] fix formatting --- src/MeshField_Shape.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MeshField_Shape.hpp b/src/MeshField_Shape.hpp index c79201e..79b6b3f 100644 --- a/src/MeshField_Shape.hpp +++ b/src/MeshField_Shape.hpp @@ -21,8 +21,8 @@ sumsToOne(Array &xi, double tol = 10 * MeshField::MachinePrecision) { } template -KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi, - double tol = MeshField::Epsilon) { +KOKKOS_INLINE_FUNCTION bool +greaterThanOrEqualZero(Array &xi, double tol = MeshField::Epsilon) { for (size_t i = 0; i < xi.size(); i++) { if (xi[i] < -tol) { return false;