diff --git a/src/openmc_mcnp_adapter/openmc_conversion.py b/src/openmc_mcnp_adapter/openmc_conversion.py index 5dc341b..d8648ff 100644 --- a/src/openmc_mcnp_adapter/openmc_conversion.py +++ b/src/openmc_mcnp_adapter/openmc_conversion.py @@ -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'] @@ -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 diff --git a/src/openmc_mcnp_adapter/parse.py b/src/openmc_mcnp_adapter/parse.py index 05b8561..9249983 100644 --- a/src/openmc_mcnp_adapter/parse.py +++ b/src/openmc_mcnp_adapter/parse.py @@ -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+)+)') @@ -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, @@ -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 diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 51d07c8..b67a2f6 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -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): @@ -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 diff --git a/tests/test_surfaces.py b/tests/test_surfaces.py index 41a9b59..727c054 100644 --- a/tests/test_surfaces.py +++ b/tests/test_surfaces.py @@ -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(