Skip to content

Commit 8fa5b9b

Browse files
authored
Add support for periodic and white boundary conditions (#53)
1 parent f2f9ae2 commit 8fa5b9b

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

src/openmc_mcnp_adapter/openmc_conversion.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,14 @@ def flip_sense(surf):
382382
raise NotImplementedError('Surface type "{}" not supported'
383383
.format(s['mnemonic']))
384384

385-
if s['reflective']:
385+
# Set boundary conditions
386+
boundary = s.get('boundary')
387+
if boundary == 'reflective':
386388
surf.boundary_type = 'reflective'
389+
elif boundary == 'white':
390+
surf.boundary_type = 'white'
391+
elif boundary == 'periodic':
392+
surf.boundary_type = 'periodic'
387393

388394
if 'tr' in s:
389395
tr_num = s['tr']
@@ -400,6 +406,12 @@ def flip_sense(surf):
400406
if isinstance(surf, surface_composite.CompositeSurface):
401407
openmc_surfaces.update((-surf).get_surfaces())
402408

409+
# Make another pass to set periodic surfaces
410+
for s in surfaces:
411+
periodic_surface_id = s.get('periodic_surface')
412+
if periodic_surface_id is not None:
413+
surf.periodic_surface = openmc_surfaces[periodic_surface_id]
414+
403415
return openmc_surfaces
404416

405417

src/openmc_mcnp_adapter/parse.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_CELL1_RE = re.compile(r'\s*(\d+)\s+(\d+)([ \t0-9:#().dDeE\+-]+)\s*(.*)')
3939
_CELL2_RE = re.compile(r'\s*(\d+)\s+like\s+(\d+)\s+but\s*(.*)')
4040
_CELL_FILL_RE = re.compile(r'\s*(\d+)\s*(?:\((.*)\))?')
41-
_SURFACE_RE = re.compile(r'\s*(\*?\d+)(\s*[-0-9]+)?\s+(\S+)((?:\s+\S+)+)')
41+
_SURFACE_RE = re.compile(r'\s*([*+]?\d+)(\s*[-0-9]+)?\s+(\S+)((?:\s+\S+)+)')
4242
_MATERIAL_RE = re.compile(r'\s*[Mm](\d+)((?:\s+\S+)+)')
4343
_TR_RE = re.compile(r'\s*(\*)?[Tt][Rr](\d+)\s+(.*)')
4444
_SAB_RE = re.compile(r'\s*[Mm][Tt](\d+)((?:\s+\S+)+)')
@@ -199,10 +199,12 @@ def parse_surface(line):
199199
g = m.groups()
200200
surface = {}
201201
if '*' in g[0]:
202-
surface['reflective'] = True
202+
surface['boundary'] = 'reflective'
203+
uid = int(g[0][1:])
204+
elif '+' in g[0]:
205+
surface['boundary'] = 'white'
203206
uid = int(g[0][1:])
204207
else:
205-
surface['reflective'] = False
206208
uid = int(g[0])
207209
surface.update({
208210
'id': uid,
@@ -211,9 +213,8 @@ def parse_surface(line):
211213
})
212214
if g[1] is not None:
213215
if int(g[1]) < 0:
214-
surface['periodic'] = int(g[1])
215-
# TODO: Move into OpenMC conversion
216-
raise NotImplementedError('Periodic boundary conditions not supported')
216+
surface['boundary'] = 'periodic'
217+
surface['periodic_surface'] = abs(int(g[1]))
217218
else:
218219
surface['tr'] = int(g[1])
219220
return surface

tests/test_geometry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def test_trcl_macrobody():
161161
"*FILL=10(2.0 0.0 0.0 0.0 90.0 90.0 90.0 0.0 90.0 90.0 90.0 0.0)",
162162
"FILL=10(1)",
163163
"FILL=10(2)",
164+
"FILL=10(3)",
164165
]
165166
)
166167
def test_fill_transformation(keywords):
@@ -176,6 +177,7 @@ def test_fill_transformation(keywords):
176177
m1 1001.80c 1.0
177178
tr1 2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
178179
*tr2 2.0 0.0 0.0 0.0 90.0 90.0 90.0 0.0 90.0 90.0 90.0 0.0
180+
tr3 2.0 0.0 0.0
179181
""")
180182
model = mcnp_str_to_model(mcnp_str)
181183
geometry = model.geometry

tests/test_surfaces.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,45 @@ def convert_surface(mnemonic: str, params: Sequence[float]) -> openmc.Surface:
3030
return surfaces[1]
3131

3232

33-
def test_reflective_surface():
34-
mcnp_str = dedent("""
33+
@mark.parametrize(
34+
"prefix, boundary_type",
35+
[
36+
("*", "reflective"),
37+
("+", "white"),
38+
]
39+
)
40+
def test_boundary_conditions(prefix, boundary_type):
41+
mcnp_str = dedent(f"""
3542
title
36-
1 1.0 -1
43+
1 1 1.0 -1
3744
38-
*1 so 2.0
45+
{prefix}1 so 2.0
3946
4047
m1 1001.80c 1.0
4148
""")
4249
model = mcnp_str_to_model(mcnp_str)
4350
surf = model.geometry.get_all_surfaces()[1]
44-
assert surf.boundary_type == 'reflective'
51+
assert surf.boundary_type == boundary_type
52+
53+
54+
def test_boundary_periodic():
55+
mcnp_str = dedent("""
56+
title
57+
1 1 1.0 1 -2 imp:n=1
58+
2 0 -1:2 imp:n=0
59+
60+
1 -2 pz -10.0
61+
2 -1 pz 10.0
62+
63+
m1 1001.80c 1.0
64+
""")
65+
model = mcnp_str_to_model(mcnp_str)
66+
surf1 = model.geometry.get_all_surfaces()[1]
67+
surf2 = model.geometry.get_all_surfaces()[2]
68+
assert surf1.boundary_type == 'periodic'
69+
assert surf1.periodic_surface == surf2
70+
assert surf2.boundary_type == 'periodic'
71+
assert surf2.periodic_surface == surf1
4572

4673

4774
@mark.parametrize(

0 commit comments

Comments
 (0)