From 6041ee6ae3a721a566382a5923d1576d5d8fdba9 Mon Sep 17 00:00:00 2001 From: David Andrs Date: Sat, 31 Jan 2026 16:02:39 -0700 Subject: [PATCH] `SpatialBox` can be constructed via ctor with parameters (#3760) --- include/openmc/distribution_spatial.h | 1 + src/distribution_spatial.cpp | 5 +++++ tests/cpp_unit_tests/test_distribution.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/openmc/distribution_spatial.h b/include/openmc/distribution_spatial.h index 26f106fca1..3e31b17a94 100644 --- a/include/openmc/distribution_spatial.h +++ b/include/openmc/distribution_spatial.h @@ -167,6 +167,7 @@ private: class SpatialBox : public SpatialDistribution { public: explicit SpatialBox(pugi::xml_node node, bool fission = false); + SpatialBox(Position lower_left, Position upper_right, bool fission = false); //! Sample a position from the distribution //! \param seed Pseudorandom number seed pointer diff --git a/src/distribution_spatial.cpp b/src/distribution_spatial.cpp index 80f8f7de14..e25e08d748 100644 --- a/src/distribution_spatial.cpp +++ b/src/distribution_spatial.cpp @@ -426,6 +426,11 @@ SpatialBox::SpatialBox(pugi::xml_node node, bool fission) upper_right_ = Position {params[3], params[4], params[5]}; } +SpatialBox::SpatialBox(Position lower_left, Position upper_right, bool fission) + : lower_left_(lower_left), upper_right_(upper_right), + only_fissionable_(fission) +{} + std::pair SpatialBox::sample(uint64_t* seed) const { Position xi {prn(seed), prn(seed), prn(seed)}; diff --git a/tests/cpp_unit_tests/test_distribution.cpp b/tests/cpp_unit_tests/test_distribution.cpp index 2024b812e6..f7c480c8d1 100644 --- a/tests/cpp_unit_tests/test_distribution.cpp +++ b/tests/cpp_unit_tests/test_distribution.cpp @@ -1,4 +1,6 @@ #include "openmc/distribution.h" +#include "openmc/distribution_spatial.h" +#include "openmc/position.h" #include "openmc/random_lcg.h" #include #include @@ -79,3 +81,14 @@ TEST_CASE("Test alias sampling method for pugixml constructor") REQUIRE(dist.alias()[i] == correct_alias[i]); } } + +TEST_CASE("Test construction of SpatialBox with parameters") +{ + openmc::Position ll {-1, -2, -3}; + openmc::Position ur {30, 15, 5}; + openmc::SpatialBox box(ll, ur); + + REQUIRE(box.lower_left() == openmc::Position {-1, -2, -3}); + REQUIRE(box.upper_right() == openmc::Position {30, 15, 5}); + REQUIRE_FALSE(box.only_fissionable()); +}