From 7de41b48f9cea2684d3249c5ef996c8ca0b41147 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 15 Mar 2024 14:52:56 -0500 Subject: [PATCH 1/3] Add support for TRn displacements --- src/openmc_mcnp_adapter/openmc_conversion.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/openmc_mcnp_adapter/openmc_conversion.py b/src/openmc_mcnp_adapter/openmc_conversion.py index 6b0caea..f03e200 100644 --- a/src/openmc_mcnp_adapter/openmc_conversion.py +++ b/src/openmc_mcnp_adapter/openmc_conversion.py @@ -260,7 +260,7 @@ def flip_sense(surf): warnings.simplefilter("ignore", openmc.IDWarning) surf = surf.translate(displacement, inplace=True) if rotation is not None: - surf = surf.rotate(rotation, pivot=displacement, inplace=True) + surf = surf.rotate(rotation, pivot=displacement, inplace=True) openmc_surfaces[s['id']] = surf @@ -347,14 +347,18 @@ def get_openmc_universes(cells, surfaces, materials, data): else: c['parameters']['fill'] = f'{fill} {trcl}' + # check for a TRn card if not trcl.startswith('('): - raise NotImplementedError( - 'TRn card not supported (cell {}).'.format(c['id'])) - - # Drop parentheses - trcl = trcl[1:-1].split() + displacement, rotation = data['tr'][int(trcl)] + if rotation is not None: + raise NotImplementedError( + 'TRn card with rotations is not supported (cell {}).'.format(c['id'])) + vector = displacement + else: + # Drop parentheses + trcl = trcl[1:-1].split() + vector = tuple(float(c) for c in trcl[:3]) - vector = tuple(float(c) for c in trcl[:3]) c['_region'] = c['_region'].translate(vector, translate_memo) if len(trcl) > 3: @@ -646,7 +650,7 @@ def get_universe(uid): elif c['material'] > 0: cell.fill = mat - + if 'vol' in c["parameters"]: cell.volume = float(c["parameters"]["vol"]) From 899023894cf40de9329aad9f23a02559916a5a83 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 21 Mar 2024 23:05:57 -0500 Subject: [PATCH 2/3] Cleaning up a bit --- src/openmc_mcnp_adapter/openmc_conversion.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/openmc_mcnp_adapter/openmc_conversion.py b/src/openmc_mcnp_adapter/openmc_conversion.py index f03e200..6045ca8 100644 --- a/src/openmc_mcnp_adapter/openmc_conversion.py +++ b/src/openmc_mcnp_adapter/openmc_conversion.py @@ -349,11 +349,10 @@ def get_openmc_universes(cells, surfaces, materials, data): # check for a TRn card if not trcl.startswith('('): - displacement, rotation = data['tr'][int(trcl)] + vector, rotation = data['tr'][int(trcl)] if rotation is not None: raise NotImplementedError( 'TRn card with rotations is not supported (cell {}).'.format(c['id'])) - vector = displacement else: # Drop parentheses trcl = trcl[1:-1].split() From c316e24a1cabd6fa455ebdd6f7b065b9012d7cf1 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 21 Mar 2024 23:13:20 -0500 Subject: [PATCH 3/3] Making control flow for translation and rotation a little more clear. --- src/openmc_mcnp_adapter/openmc_conversion.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/openmc_mcnp_adapter/openmc_conversion.py b/src/openmc_mcnp_adapter/openmc_conversion.py index 6045ca8..af48f50 100644 --- a/src/openmc_mcnp_adapter/openmc_conversion.py +++ b/src/openmc_mcnp_adapter/openmc_conversion.py @@ -347,24 +347,26 @@ def get_openmc_universes(cells, surfaces, materials, data): else: c['parameters']['fill'] = f'{fill} {trcl}' + # Apply transformation to region + vector = None + rotation_matrix = None + # check for a TRn card if not trcl.startswith('('): vector, rotation = data['tr'][int(trcl)] - if rotation is not None: - raise NotImplementedError( - 'TRn card with rotations is not supported (cell {}).'.format(c['id'])) else: # Drop parentheses trcl = trcl[1:-1].split() vector = tuple(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 use_degrees: + rotation_matrix = np.cos(rotation_matrix * pi/180.0) - c['_region'] = c['_region'].translate(vector, translate_memo) + if vector is not None: + c['_region'] = c['_region'].translate(vector, translate_memo) - if len(trcl) > 3: - rotation_matrix = np.array([float(x) for x in trcl[3:]]).reshape((3, 3)) - if use_degrees: - rotation_matrix = np.cos(rotation_matrix * pi/180.0) - print(rotation_matrix) + if rotation_matrix is not None: c['_region'] = c['_region'].rotate(rotation_matrix.T, pivot=vector) # Update surfaces dictionary with new surfaces