From 86a8faf87fde473863ad54c54df2e56c30142ec3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 10:35:03 -0500 Subject: [PATCH] Making the mesh filter translation an attribute instead of a parameter for consistency. --- openmc/filter.py | 26 +++++++++---------- .../filter_translations/test.py | 6 +++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index 94522891bf..affe7ed378 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -727,10 +727,10 @@ class MeshFilter(Filter): """ - def __init__(self, mesh, filter_id=None, translation=None): + def __init__(self, mesh, filter_id=None): self.mesh = mesh self.id = filter_id - self.translation = translation + self._translation = None def __hash__(self): string = type(self).__name__ + '\n' @@ -759,11 +759,12 @@ class MeshFilter(Filter): mesh_obj = kwargs['meshes'][mesh_id] filter_id = int(group.name.split('/')[-1].lstrip('filter ')) + + out = cls(mesh_obj, filter_id=filter_id) + translation = group.get('translation') if translation: - translation = translation[()] - - out = cls(mesh_obj, filter_id=filter_id, translation=translation) + cls.translation = translation[()] return out @@ -789,10 +790,9 @@ class MeshFilter(Filter): @translation.setter def translation(self, t): - if t is not None: - cv.check_type('mesh filter translation', t, Iterable, Real) - cv.check_length('mesh filter translation', t, 3) - self._translation = np.asarray(t) + cv.check_type('mesh filter translation', t, Iterable, Real) + cv.check_length('mesh filter translation', t, 3) + self._translation = np.asarray(t) def can_merge(self, other): # Mesh filters cannot have more than one bin @@ -875,7 +875,7 @@ class MeshFilter(Filter): element = super().to_xml_element() element[0].text = str(self.mesh.id) if self.translation is not None: - element.set('translation', ' '.join(map(str, self._translation))) + element.set('translation', ' '.join(map(str, self.translation))) return element @@ -996,9 +996,9 @@ class CollisionFilter(Filter): Parameters ---------- bins : Iterable of int - A list or iterable of the number of collisions, as integer values. - The events whose post-scattering collision number equals one of - the provided values will be counted. + A list or iterable of the number of collisions, as integer values. + The events whose post-scattering collision number equals one of + the provided values will be counted. filter_id : int Unique identifier for the filter diff --git a/tests/regression_tests/filter_translations/test.py b/tests/regression_tests/filter_translations/test.py index 075cabcbcf..a8d96158f5 100644 --- a/tests/regression_tests/filter_translations/test.py +++ b/tests/regression_tests/filter_translations/test.py @@ -49,8 +49,10 @@ def model(request): recti_mesh.z_grid = np.linspace(llc[2], urc[2], 17) # Create filters - filters = [openmc.MeshFilter(reg_mesh, translation=translation), - openmc.MeshFilter(recti_mesh, translation=translation)] + filters = [openmc.MeshFilter(reg_mesh), + openmc.MeshFilter(recti_mesh)] + for f in filters: + f.translation = translation # Create tallies for f in filters: