mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Implement depth-awareness when enforcing precedence between union/intersection operators (#3730)
Co-authored-by: GuySten <guyste@post.bgu.ac.il>
This commit is contained in:
parent
179048b801
commit
51ea89ccc8
4 changed files with 161 additions and 49 deletions
101
tests/cpp_unit_tests/test_region.cpp
Normal file
101
tests/cpp_unit_tests/test_region.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "openmc/cell.h"
|
||||
#include "openmc/surface.h"
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
// Helper class to set up and tear down test surfaces
|
||||
class SurfaceFixture {
|
||||
public:
|
||||
SurfaceFixture()
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
pugi::xml_node surf_node = doc.append_child("surface");
|
||||
surf_node.set_name("surface");
|
||||
surf_node.append_attribute("id") = "0";
|
||||
surf_node.append_attribute("type") = "x-plane";
|
||||
surf_node.append_attribute("coeffs") = "1";
|
||||
|
||||
for (int i = 1; i < 10; ++i) {
|
||||
surf_node.attribute("id") = i;
|
||||
openmc::model::surfaces.push_back(
|
||||
std::make_unique<openmc::SurfaceXPlane>(surf_node));
|
||||
openmc::model::surface_map[i] = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
~SurfaceFixture()
|
||||
{
|
||||
openmc::model::surfaces.clear();
|
||||
openmc::model::surface_map.clear();
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST_CASE("Test region simplification")
|
||||
{
|
||||
SurfaceFixture fixture;
|
||||
|
||||
SECTION("Original bug case from issue #3685")
|
||||
{
|
||||
// Input: "-1 2 (-3 4) | (-5 6)" was being incorrectly interpreted
|
||||
auto region = openmc::Region("(-1 2 (-3 4) | (-5 6))", 0);
|
||||
REQUIRE(region.str() == " ( ( -1 2 ( -3 4 ) ) | ( -5 6 ) )");
|
||||
}
|
||||
|
||||
SECTION("Simple union - no extra parentheses needed")
|
||||
{
|
||||
auto region = openmc::Region("1 | 2", 0);
|
||||
REQUIRE(region.str() == " 1 | 2");
|
||||
}
|
||||
|
||||
SECTION("Intersection then union")
|
||||
{
|
||||
// Intersection should have higher precedence, so (1 2) grouped
|
||||
auto region = openmc::Region("1 2 | 3", 0);
|
||||
REQUIRE(region.str() == " ( 1 2 ) | 3");
|
||||
}
|
||||
|
||||
SECTION("Union then intersection")
|
||||
{
|
||||
// The (2 3) intersection should be grouped
|
||||
auto region = openmc::Region("1 | 2 3", 0);
|
||||
REQUIRE(region.str() == " 1 | ( 2 3 )");
|
||||
}
|
||||
|
||||
SECTION("Nested parentheses preserved")
|
||||
{
|
||||
// These parentheses are meaningful and should be preserved
|
||||
auto region = openmc::Region("(1 | 2) (3 | 4)", 0);
|
||||
REQUIRE(region.str() == " ( 1 | 2 ) ( 3 | 4 )");
|
||||
}
|
||||
|
||||
SECTION("Deep nesting")
|
||||
{
|
||||
auto region = openmc::Region("((1 2) | (3 4)) 5", 0);
|
||||
REQUIRE(region.str() == " ( ( 1 2 ) | ( 3 4 ) ) 5");
|
||||
}
|
||||
|
||||
SECTION("Multiple unions")
|
||||
{
|
||||
auto region = openmc::Region("1 | 2 | 3", 0);
|
||||
REQUIRE(region.str() == " 1 | 2 | 3");
|
||||
}
|
||||
|
||||
SECTION("Multiple intersections")
|
||||
{
|
||||
auto region = openmc::Region("1 2 3", 0);
|
||||
// Simple cell - no operators in output
|
||||
REQUIRE(region.str() == " 1 2 3");
|
||||
}
|
||||
|
||||
SECTION("Complex mixed expression")
|
||||
{
|
||||
auto region = openmc::Region("1 2 | 3 4 | 5 6", 0);
|
||||
REQUIRE(region.str() == " ( 1 2 ) | ( 3 4 ) | ( 5 6 )");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue