Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/openmc_mcnp_adapter/openmc_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,14 @@ def flip_sense(surf):
raise NotImplementedError('Surface type "{}" not supported'
.format(s['mnemonic']))

if s['reflective']:
# Set boundary conditions
boundary = s.get('boundary')
if boundary == 'reflective':
surf.boundary_type = 'reflective'
elif boundary == 'white':
surf.boundary_type = 'white'
elif boundary == 'periodic':
surf.boundary_type = 'periodic'

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

# Make another pass to set periodic surfaces
for s in surfaces:
periodic_surface_id = s.get('periodic_surface')
if periodic_surface_id is not None:
surf.periodic_surface = openmc_surfaces[periodic_surface_id]

return openmc_surfaces


Expand Down
13 changes: 7 additions & 6 deletions src/openmc_mcnp_adapter/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
_CELL1_RE = re.compile(r'\s*(\d+)\s+(\d+)([ \t0-9:#().dDeE\+-]+)\s*(.*)')
_CELL2_RE = re.compile(r'\s*(\d+)\s+like\s+(\d+)\s+but\s*(.*)')
_CELL_FILL_RE = re.compile(r'\s*(\d+)\s*(?:\((.*)\))?')
_SURFACE_RE = re.compile(r'\s*(\*?\d+)(\s*[-0-9]+)?\s+(\S+)((?:\s+\S+)+)')
_SURFACE_RE = re.compile(r'\s*([*+]?\d+)(\s*[-0-9]+)?\s+(\S+)((?:\s+\S+)+)')
_MATERIAL_RE = re.compile(r'\s*[Mm](\d+)((?:\s+\S+)+)')
_TR_RE = re.compile(r'\s*(\*)?[Tt][Rr](\d+)\s+(.*)')
_SAB_RE = re.compile(r'\s*[Mm][Tt](\d+)((?:\s+\S+)+)')
Expand Down Expand Up @@ -199,10 +199,12 @@ def parse_surface(line):
g = m.groups()
surface = {}
if '*' in g[0]:
surface['reflective'] = True
surface['boundary'] = 'reflective'
uid = int(g[0][1:])
elif '+' in g[0]:
surface['boundary'] = 'white'
uid = int(g[0][1:])
else:
surface['reflective'] = False
uid = int(g[0])
surface.update({
'id': uid,
Expand All @@ -211,9 +213,8 @@ def parse_surface(line):
})
if g[1] is not None:
if int(g[1]) < 0:
surface['periodic'] = int(g[1])
# TODO: Move into OpenMC conversion
raise NotImplementedError('Periodic boundary conditions not supported')
surface['boundary'] = 'periodic'
surface['periodic_surface'] = abs(int(g[1]))
else:
surface['tr'] = int(g[1])
return surface
Expand Down
2 changes: 2 additions & 0 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def test_trcl_macrobody():
"*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)",
"FILL=10(1)",
"FILL=10(2)",
"FILL=10(3)",
]
)
def test_fill_transformation(keywords):
Expand All @@ -176,6 +177,7 @@ def test_fill_transformation(keywords):
m1 1001.80c 1.0
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
*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
tr3 2.0 0.0 0.0
""")
model = mcnp_str_to_model(mcnp_str)
geometry = model.geometry
Expand Down
37 changes: 32 additions & 5 deletions tests/test_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,45 @@ def convert_surface(mnemonic: str, params: Sequence[float]) -> openmc.Surface:
return surfaces[1]


def test_reflective_surface():
mcnp_str = dedent("""
@mark.parametrize(
"prefix, boundary_type",
[
("*", "reflective"),
("+", "white"),
]
)
def test_boundary_conditions(prefix, boundary_type):
mcnp_str = dedent(f"""
title
1 1.0 -1
1 1 1.0 -1

*1 so 2.0
{prefix}1 so 2.0

m1 1001.80c 1.0
""")
model = mcnp_str_to_model(mcnp_str)
surf = model.geometry.get_all_surfaces()[1]
assert surf.boundary_type == 'reflective'
assert surf.boundary_type == boundary_type


def test_boundary_periodic():
mcnp_str = dedent("""
title
1 1 1.0 1 -2 imp:n=1
2 0 -1:2 imp:n=0

1 -2 pz -10.0
2 -1 pz 10.0

m1 1001.80c 1.0
""")
model = mcnp_str_to_model(mcnp_str)
surf1 = model.geometry.get_all_surfaces()[1]
surf2 = model.geometry.get_all_surfaces()[2]
assert surf1.boundary_type == 'periodic'
assert surf1.periodic_surface == surf2
assert surf2.boundary_type == 'periodic'
assert surf2.periodic_surface == surf1


@mark.parametrize(
Expand Down