FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openmc/tests/cpp_unit_tests/test_region.cpp at develop · openmc-dev/openmc · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
openmc-dev
/
openmc
Public
Notifications
You must be signed in to change notification settings
Fork
675
Star
1.1k
Code
Issues
343
Pull requests
126
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
openmc
/
tests
/
cpp_unit_tests
/
test_region.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
225 lines (190 loc) · 6.52 KB
Breadcrumbs
openmc
/
tests
/
cpp_unit_tests
/
test_region.cpp
Copy path
File metadata and controls
225 lines (190 loc) · 6.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#
include
<
catch2/catch_approx.hpp
>
#
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
();
}
};
//
Helper class for testing multiple intersections with the same surface
class
MultiIntersectionFixture
{
public:
MultiIntersectionFixture
()
{
pugi::xml_document doc;
auto
plane = doc.
append_child
(
"
surface
"
);
plane.
append_attribute
(
"
id
"
) =
1
;
plane.
append_attribute
(
"
type
"
) =
"
x-plane
"
;
plane.
append_attribute
(
"
coeffs
"
) =
"
5
"
;
openmc::model::surfaces.
push_back
(
std::make_unique<openmc::SurfaceXPlane>(plane));
openmc::model::surface_map[
1
] =
0
;
auto
sphere = doc.
append_child
(
"
surface
"
);
sphere.
append_attribute
(
"
id
"
) =
2
;
sphere.
append_attribute
(
"
type
"
) =
"
sphere
"
;
sphere.
append_attribute
(
"
coeffs
"
) =
"
5 0 0 1
"
;
openmc::model::surfaces.
push_back
(
std::make_unique<openmc::SurfaceSphere>(sphere));
openmc::model::surface_map[
2
] =
1
;
}
~MultiIntersectionFixture
()
{
openmc::model::surfaces.
clear
();
openmc::model::surface_map.
clear
();
}
};
//
Helper class for testing coincident surfaces with different representations
class
CoincidentSurfaceFixture
{
public:
CoincidentSurfaceFixture
()
{
pugi::xml_document doc;
auto
cylinder = doc.
append_child
(
"
surface
"
);
cylinder.
append_attribute
(
"
id
"
) =
1
;
cylinder.
append_attribute
(
"
type
"
) =
"
z-cylinder
"
;
cylinder.
append_attribute
(
"
coeffs
"
) =
"
0 0 499.0000001
"
;
openmc::model::surfaces.
push_back
(
std::make_unique<openmc::SurfaceZCylinder>(cylinder));
openmc::model::surface_map[
1
] =
0
;
auto
quadric = doc.
append_child
(
"
surface
"
);
quadric.
append_attribute
(
"
id
"
) =
2
;
quadric.
append_attribute
(
"
type
"
) =
"
quadric
"
;
quadric.
append_attribute
(
"
coeffs
"
) =
"
1 1 7.498798913309288e-33 -7.498798913309288e-33
"
"
-1.2246467991473532e-16 -1.2246467991473532e-16 0 0 0
"
"
-249001.00009980003
"
;
openmc::model::surfaces.
push_back
(
std::make_unique<openmc::SurfaceQuadric>(quadric));
openmc::model::surface_map[
2
] =
1
;
}
~CoincidentSurfaceFixture
()
{
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 )
"
);
}
}
TEST_CASE
(
"
Find boundary after virtual surface crossings
"
)
{
MultiIntersectionFixture fixture;
openmc::Region
region
(
"
-1 | -2
"
,
0
);
SECTION
(
"
Starting inside the region
"
)
{
//
Along +x from x=1, entering the sphere at x=4 is virtual because x < 5.
//
Crossing the plane at x=5 is also virtual because the point is inside
//
the sphere. Exiting the sphere at x=6 is the first true boundary.
auto
[distance, surface] =
region.
distance
({
1.0
,
0.0
,
0.0
}, {
1.0
,
0.0
,
0.0
},
0
);
REQUIRE
(distance ==
Catch::Approx
(
5.0
));
REQUIRE
(surface ==
2
);
}
SECTION
(
"
Starting outside the region
"
)
{
//
Along -x from x=7, entering the sphere at x=6 is the first boundary.
auto
[distance, surface] =
region.
distance
({
7.0
,
0.0
,
0.0
}, {-
1.0
,
0.0
,
0.0
},
0
);
REQUIRE
(distance ==
Catch::Approx
(
1.0
));
REQUIRE
(surface == -
2
);
}
SECTION
(
"
Starting on a curved surface
"
)
{
//
Start on the sphere and travel obliquely through it. The plane crossing
//
is virtual, and accumulated roundoff must not cause the sphere exit to
//
be classified as another virtual crossing.
auto
[distance, surface] =
region.
distance
({
4.2
,
0.6
,
0.0
}, {
1.0
,
0.0
,
0.0
}, -
2
);
REQUIRE
(distance ==
Catch::Approx
(
1.6
));
REQUIRE
(surface ==
2
);
}
}
TEST_CASE
(
"
Ignore roundoff-scale virtual surface crossings
"
)
{
CoincidentSurfaceFixture fixture;
//
These two surfaces describe effectively coincident cylinders, but the
//
small rotation in the general quadric causes their calculated
//
intersections to differ by roundoff. The nearby quadric intersection is
//
virtual and the next meaningful crossing is on the far side of the
//
cylinders.
openmc::Region
region
(
"
1 | -2
"
,
0
);
auto
[distance, surface] = region.
distance
(
{-
427.64056354508085
, -
257.1469395319449
, -
20.851278766740666
},
{
0.8131471271523302
, -
0.39377148555937275
,
0.4286441026822566
}, -
1
);
REQUIRE
(distance ==
Catch::Approx
(
603.9161175466262
));
REQUIRE
(surface ==
1
);
}
Back
|
FazBrowse Home
|
New Git URL