From 9e81f7377a628a271ac7a1f1dcdc98cde7a8ed92 Mon Sep 17 00:00:00 2001 From: Joffrey Dorville Date: Thu, 28 May 2026 16:09:47 -0500 Subject: [PATCH 1/6] Add failing test --- tests/cpp_unit_tests/test_mesh.cpp | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/cpp_unit_tests/test_mesh.cpp b/tests/cpp_unit_tests/test_mesh.cpp index 24c4f77373f..d48b7825fe6 100644 --- a/tests/cpp_unit_tests/test_mesh.cpp +++ b/tests/cpp_unit_tests/test_mesh.cpp @@ -255,3 +255,51 @@ TEST_CASE("Test multiple meshes HDF5 roundtrip - spherical") REQUIRE(regular_mesh_hdf5->lower_left() == regular_mesh_xml->lower_left()); REQUIRE(regular_mesh_hdf5->upper_right() == regular_mesh_xml->upper_right()); } + +TEST_CASE("Test get_index_in_direction - regular mesh") +{ + // The XML data as a string + std::string xml_string = R"( + + 3 4 5 + -2 -3 -5 + 2 3 5 + + )"; + + // Create a pugixml document object + pugi::xml_document doc; + + // Load the XML from the string + pugi::xml_parse_result result = doc.load_string(xml_string.c_str()); + + pugi::xml_node root = doc.child("mesh"); + + auto mesh = RegularMesh(root); + + REQUIRE(mesh.get_index_in_direction(-2.0, 0) == 1); +} + +TEST_CASE("Test get_index_in_direction - rectilinear mesh") +{ + // The XML data as a string + std::string xml_string = R"( + + 0.0 1.0 5.0 10.0 + -10.0 -5.0 0.0 + -100.0 0.0 100.0 + + )"; + + // Create a pugixml document object + pugi::xml_document doc; + + // Load the XML from the string + pugi::xml_parse_result result = doc.load_string(xml_string.c_str()); + + pugi::xml_node root = doc.child("mesh"); + + auto mesh = RectilinearMesh(root); + + REQUIRE(mesh.get_index_in_direction(0.0, 0) == 1); +} From 863bdcb4059dd9ca04f5029a88461ac9746f19f4 Mon Sep 17 00:00:00 2001 From: Joffrey Dorville Date: Wed, 6 May 2026 10:57:24 -0500 Subject: [PATCH 2/6] Fix regular mesh index calculation when point is on the lower boundary --- src/mesh.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 5ab7ac3988b..85fe9046c59 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1472,7 +1472,11 @@ RegularMesh::RegularMesh(hid_t group) : StructuredMesh {group} int RegularMesh::get_index_in_direction(double r, int i) const { - return std::ceil((r - lower_left_[i]) / width_[i]); + if (r == lower_left_[i]) { + return 1; + } else { + return std::ceil((r - lower_left_[i]) / width_[i]); + } } const std::string RegularMesh::mesh_type = "regular"; From 02f0f7964a2e49c45bae23fa90f473c915ca1ed1 Mon Sep 17 00:00:00 2001 From: Joffrey Dorville Date: Thu, 28 May 2026 16:21:27 -0500 Subject: [PATCH 3/6] Update fixed regression tests --- .../weightwindows/survival_biasing/local/results_true.dat | 2 +- .../weightwindows/survival_biasing/shared/results_true.dat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat b/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat index b457a245c7c..8a4d3368cc4 100644 --- a/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat +++ b/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat @@ -1 +1 @@ -386e507008ed3c72c6e1a101aafc01cfaaff2c0b10555558d1eab6332441f7b17264b55002d721151bac2f3e7c1a8aac4c5ed243f5270533d171850f985206ed \ No newline at end of file +0d7b17d4e364bda2be21feb2e5b2aae4be69fc8ed634c4f45062e8efc61b7bd24dcf448837692fd603afe3756501fe8821d134f2d6289179618f85178ddb8793 \ No newline at end of file diff --git a/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat b/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat index 11e5ffa77f5..ff146484a3a 100644 --- a/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat +++ b/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat @@ -1 +1 @@ -d17a437262d3316985fba4b48e21a7fcd5f32ac2d96ef0e66849f567deaeadc1e0f18d5d0bf5e9cab4246dbf823e7f43f249a1f67e928b27ae8c70b89f3cefbf \ No newline at end of file +20978d7e8d5b3ea3689f55128e8143f34857802cd4c23af487dff940c604cb9a37027db3bcee2b28d4a9fe57c548e2757ed0fdb617b3bade31b7c471d05f04fd \ No newline at end of file From 6ad643969c80a15703f8974bb3e185fedade8a36 Mon Sep 17 00:00:00 2001 From: Joffrey Dorville Date: Thu, 28 May 2026 16:21:53 -0500 Subject: [PATCH 4/6] Add another comparison point --- tests/cpp_unit_tests/test_mesh.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cpp_unit_tests/test_mesh.cpp b/tests/cpp_unit_tests/test_mesh.cpp index d48b7825fe6..ece3e9e0802 100644 --- a/tests/cpp_unit_tests/test_mesh.cpp +++ b/tests/cpp_unit_tests/test_mesh.cpp @@ -278,6 +278,7 @@ TEST_CASE("Test get_index_in_direction - regular mesh") auto mesh = RegularMesh(root); REQUIRE(mesh.get_index_in_direction(-2.0, 0) == 1); + REQUIRE(mesh.get_index_in_direction(-1.99, 0) == 1); } TEST_CASE("Test get_index_in_direction - rectilinear mesh") @@ -302,4 +303,5 @@ TEST_CASE("Test get_index_in_direction - rectilinear mesh") auto mesh = RectilinearMesh(root); REQUIRE(mesh.get_index_in_direction(0.0, 0) == 1); + REQUIRE(mesh.get_index_in_direction(0.01, 0) == 1); } From 67690798fedaf4b508b3846c53df7b13838d31a9 Mon Sep 17 00:00:00 2001 From: Joffrey Dorville Date: Fri, 29 May 2026 09:58:37 -0500 Subject: [PATCH 5/6] ENABLE_STRICT_FP on --- .../weightwindows/survival_biasing/shared/results_true.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat b/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat index ff146484a3a..2e88e2f0e81 100644 --- a/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat +++ b/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat @@ -1 +1 @@ -20978d7e8d5b3ea3689f55128e8143f34857802cd4c23af487dff940c604cb9a37027db3bcee2b28d4a9fe57c548e2757ed0fdb617b3bade31b7c471d05f04fd \ No newline at end of file +2f1c8efbf6ab0b0c7319fadd7ee8f27b545c1ebab94ebe15cf1133b54227487542966b6d798970c8b37bc19e7041e687687d5285803241bb83f4c8dc40a4d276 \ No newline at end of file From 13b1a0281ec71b56ae623a64c839df8e3054fb91 Mon Sep 17 00:00:00 2001 From: Joffrey Dorville Date: Fri, 29 May 2026 18:07:01 -0500 Subject: [PATCH 6/6] Check upper boundaries as well --- tests/cpp_unit_tests/test_mesh.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/cpp_unit_tests/test_mesh.cpp b/tests/cpp_unit_tests/test_mesh.cpp index ece3e9e0802..d2090db1f32 100644 --- a/tests/cpp_unit_tests/test_mesh.cpp +++ b/tests/cpp_unit_tests/test_mesh.cpp @@ -279,6 +279,8 @@ TEST_CASE("Test get_index_in_direction - regular mesh") REQUIRE(mesh.get_index_in_direction(-2.0, 0) == 1); REQUIRE(mesh.get_index_in_direction(-1.99, 0) == 1); + REQUIRE(mesh.get_index_in_direction(1.99, 0) == 3); + REQUIRE(mesh.get_index_in_direction(2.0, 0) == 3); } TEST_CASE("Test get_index_in_direction - rectilinear mesh") @@ -304,4 +306,6 @@ TEST_CASE("Test get_index_in_direction - rectilinear mesh") REQUIRE(mesh.get_index_in_direction(0.0, 0) == 1); REQUIRE(mesh.get_index_in_direction(0.01, 0) == 1); + REQUIRE(mesh.get_index_in_direction(9.99, 0) == 3); + REQUIRE(mesh.get_index_in_direction(10.0, 0) == 3); }