Skip to content

Commit f2f9ae2

Browse files
authored
Add a few more tests (#52)
1 parent 3a69e84 commit f2f9ae2

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

src/openmc_mcnp_adapter/openmc_conversion.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ def flip_sense(surf):
262262
surf = surface_composite.XConeOneSided(x0=x0, y0=y0, z0=z0, r2=R2, up=up)
263263
elif s['mnemonic'] == 'k/y':
264264
surf = surface_composite.YConeOneSided(x0=x0, y0=y0, z0=z0, r2=R2, up=up)
265-
elif s['mnemonic'] == 'k/z':
265+
else:
266266
surf = surface_composite.ZConeOneSided(x0=x0, y0=y0, z0=z0, r2=R2, up=up)
267267
else:
268268
if s['mnemonic'] == 'k/x':
269269
surf = openmc.XCone(surface_id=s['id'], x0=x0, y0=y0, z0=z0, r2=R2)
270270
elif s['mnemonic'] == 'k/y':
271271
surf = openmc.YCone(surface_id=s['id'], x0=x0, y0=y0, z0=z0, r2=R2)
272-
elif s['mnemonic'] == 'k/z':
272+
else:
273273
surf = openmc.ZCone(surface_id=s['id'], x0=x0, y0=y0, z0=z0, r2=R2)
274274
elif s['mnemonic'] in ('kx', 'ky', 'kz'):
275275
x, R2 = coeffs[:2]
@@ -279,14 +279,14 @@ def flip_sense(surf):
279279
surf = surface_composite.XConeOneSided(x0=x, r2=R2, up=up)
280280
elif s['mnemonic'] == 'ky':
281281
surf = surface_composite.YConeOneSided(y0=x, r2=R2, up=up)
282-
elif s['mnemonic'] == 'kz':
282+
else:
283283
surf = surface_composite.ZConeOneSided(z0=x, r2=R2, up=up)
284284
else:
285285
if s['mnemonic'] == 'kx':
286286
surf = openmc.XCone(surface_id=s['id'], x0=x, r2=R2)
287287
elif s['mnemonic'] == 'ky':
288288
surf = openmc.YCone(surface_id=s['id'], y0=x, r2=R2)
289-
elif s['mnemonic'] == 'kz':
289+
else:
290290
surf = openmc.ZCone(surface_id=s['id'], z0=x, r2=R2)
291291
elif s['mnemonic'] == 'sq':
292292
a, b, c, D, E, F, G, x, y, z = coeffs

tests/test_geometry.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ def test_trcl(cell_card, surface_cards, points_inside, points_outside):
135135
assert point not in cell.region
136136

137137

138+
def test_trcl_macrobody():
139+
mcnp_str = dedent("""
140+
title
141+
1 0 -1 trcl=(2.0 0.0 0.0)
142+
143+
1 rpp -1.0 1.0 -1.0 1.0 -1.0 1.0
144+
145+
m1 1001.80c 1.0
146+
""")
147+
model = mcnp_str_to_model(mcnp_str)
148+
cell = model.geometry.get_all_cells()[1]
149+
assert (1.5, 0., 0.) in cell.region
150+
assert (0., 0., 0.) not in cell.region
151+
152+
138153
@mark.parametrize(
139154
"keywords",
140155
[
@@ -170,3 +185,17 @@ def test_fill_transformation(keywords):
170185
assert geometry.find((2.0, 0.0, 0.0))[-1] is cells[2]
171186
assert geometry.find((4.0, 0.0, 0.0))[-1] is cells[3]
172187
assert geometry.find((0.0, 0.0, 0.0))[-1] is cells[3]
188+
189+
190+
def test_cell_volume():
191+
mcnp_str = dedent("""
192+
title
193+
1 0 -1 VOL=5.0
194+
195+
1 so 1.0
196+
197+
m1 1001.80c 1.0
198+
""")
199+
model = mcnp_str_to_model(mcnp_str)
200+
cell = model.geometry.get_all_cells()[1]
201+
assert cell.volume == 5.0

tests/test_surfaces.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
RectangularParallelepiped, RightCircularCylinder, ConicalFrustum, \
88
XConeOneSided, YConeOneSided, ZConeOneSided
99
from openmc_mcnp_adapter import mcnp_str_to_model, get_openmc_surfaces
10-
from pytest import approx, mark
10+
from pytest import approx, mark, raises
1111

1212

1313
def convert_surface(mnemonic: str, params: Sequence[float]) -> openmc.Surface:
@@ -120,6 +120,16 @@ def test_plane_sense_rule4():
120120
assert (1e10, 0., 0.) in +surf
121121

122122

123+
def test_plane_invalid():
124+
coeffs = (
125+
0., 0., 0.,
126+
0., 0., 1.,
127+
0., 0., 2.,
128+
)
129+
with raises(ValueError):
130+
convert_surface("p", coeffs)
131+
132+
123133
def test_surface_transformation_with_tr_card():
124134
mcnp_str = dedent("""
125135
title
@@ -400,6 +410,21 @@ def test_box_macrobody():
400410
assert surf.ax3_max.d / surf.ax3_max.c == approx(3.0)
401411

402412

413+
def test_box_macrobody_inf():
414+
coeffs = (0.0, 0.0, 0.0,
415+
1.0, 0.0, 0.0,
416+
0.0, 2.0, 0.0)
417+
surf = convert_surface("box", coeffs)
418+
assert isinstance(surf, OrthogonalBox)
419+
420+
# Check a few points; since it is infinite in z, any value in z should work
421+
assert (0.5, 0.5, 0.0) in -surf
422+
assert (0.5, 0.5, -100.0) in -surf
423+
assert (0.5, 0.5, 100.0) in -surf
424+
assert (0.5, -0.01, 0.0) in +surf
425+
assert (1.01, 0.5, 0.0) in +surf
426+
427+
403428
def test_rpp_macrobody():
404429
coeffs = (-1.0, 2.0, -3.0, 4.0, 0.5, 5.5)
405430
surf = convert_surface("rpp", coeffs)

0 commit comments

Comments
 (0)