From 5621037a0e28825fa76ed425c5478d2a9497fe6e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 27 Nov 2025 16:28:38 +0100 Subject: [PATCH] Support displacement vector origin in transformations --- src/openmc_mcnp_adapter/openmc_conversion.py | 23 +++++++++++++++----- src/openmc_mcnp_adapter/parse.py | 3 +++ tests/test_geometry.py | 12 ++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/openmc_mcnp_adapter/openmc_conversion.py b/src/openmc_mcnp_adapter/openmc_conversion.py index d8648ff..7e4c576 100644 --- a/src/openmc_mcnp_adapter/openmc_conversion.py +++ b/src/openmc_mcnp_adapter/openmc_conversion.py @@ -563,14 +563,22 @@ def get_openmc_universes(cells, surfaces, materials, data): # Drop parentheses trcl = trcl[1:-1].split() - vector = tuple(float(c) for c in trcl[:3]) - c['_region'] = c['_region'].translate(vector, translate_memo) + # Get displacement vector + vector = np.array([float(c) for c in trcl[:3]]) if len(trcl) > 3: - rotation_matrix = np.array([float(x) for x in trcl[3:]]).reshape((3, 3)) + # If displacement vector origin is -1, reverse displacement vector + if len(trcl) == 13: + if int(trcl[12]) == -1: + vector *= -1 + c['_region'] = c['_region'].translate(vector, translate_memo) + + rotation_matrix = np.array([float(x) for x in trcl[3:12]]).reshape((3, 3)) if use_degrees: rotation_matrix = np.cos(rotation_matrix * pi/180.0) c['_region'] = c['_region'].rotate(rotation_matrix.T, pivot=vector) + else: + c['_region'] = c['_region'].translate(vector, translate_memo) # Update surfaces dictionary with new surfaces for surf_id, surf in c['_region'].get_surfaces().items(): @@ -846,8 +854,13 @@ def get_universe(uid): if ftrans is not None: ftrans = ftrans.split() if len(ftrans) > 3: - cell.translation = tuple(float(x) for x in ftrans[:3]) - rotation_matrix = np.array([float(x) for x in ftrans[3:]]).reshape((3, 3)) + vector = np.array([float(x) for x in ftrans[:3]]) + if len(ftrans) == 13: + if int(ftrans[12]) == -1: + vector *= -1 + + cell.translation = tuple(vector) + rotation_matrix = np.array([float(x) for x in ftrans[3:12]]).reshape((3, 3)) if use_degrees: rotation_matrix = np.cos(rotation_matrix * pi/180.0) cell.rotation = rotation_matrix diff --git a/src/openmc_mcnp_adapter/parse.py b/src/openmc_mcnp_adapter/parse.py index d273012..b02dfc1 100644 --- a/src/openmc_mcnp_adapter/parse.py +++ b/src/openmc_mcnp_adapter/parse.py @@ -270,6 +270,9 @@ def parse_data(section): if len(values) >= 3: displacement = np.array([float(x) for x in values[:3]]) if len(values) >= 12: + if len(values) == 13: + if int(values[12]) == -1: + displacement *= -1 rotation = np.array([float(x) for x in values[3:12]]).reshape((3,3)).T if use_degrees: rotation = np.cos(rotation * pi/180.0) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index b67a2f6..87524ac 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -159,6 +159,14 @@ def test_trcl_macrobody(): "FILL=10(2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0)", "FILL=10 *TRCL=(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(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 TRCL=(2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 1)", + "FILL=10 TRCL=(-2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 -1)", + "FILL=10(2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 1)", + "FILL=10(-2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 -1)", + "FILL=10 *TRCL=(2.0 0.0 0.0 0.0 90.0 90.0 90.0 0.0 90.0 90.0 90.0 0.0 1)", + "FILL=10 *TRCL=(-2.0 0.0 0.0 0.0 90.0 90.0 90.0 0.0 90.0 90.0 90.0 0.0 -1)", + "*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 1)", + "*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 -1)", "FILL=10(1)", "FILL=10(2)", "FILL=10(3)", @@ -175,8 +183,8 @@ def test_fill_transformation(keywords): 2 so 1.0 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 + 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 1 + *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 -1 tr3 2.0 0.0 0.0 """) model = mcnp_str_to_model(mcnp_str)