From c84336878bdfb38c261094205ab5360949d6743d Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Fri, 27 Jan 2023 08:58:10 -0500 Subject: [PATCH] replace is_flat by a one-line check --- openmc/mesh.py | 18 ++++-------------- tests/unit_tests/test_mesh.py | 22 ---------------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 3cdfc87f3b..60c5ade40d 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -433,8 +433,8 @@ class RegularMesh(StructuredMesh): cv.check_length('mesh lower_left', lower_left, 1, 3) self._lower_left = lower_left - if self.is_flat(): - raise ValueError("mesh cannot be flat") + if self.upper_right is not None and any(np.isclose(self.upper_right, lower_left)): + raise ValueError("mesh cannot have zero thickness is any dimension") @upper_right.setter def upper_right(self, upper_right): @@ -446,8 +446,8 @@ class RegularMesh(StructuredMesh): self._width = None warnings.warn("Unsetting width attribute.") - if self.is_flat(): - raise ValueError("mesh cannot be flat") + if self.lower_left is not None and any(np.isclose(self.lower_left, upper_right)): + raise ValueError("mesh cannot have zero thickness is any dimension") @width.setter def width(self, width): @@ -792,16 +792,6 @@ class RegularMesh(StructuredMesh): volume_normalization=volume_normalization ) - def is_flat(self): - """Returns True if the mesh is flat - """ - if self.lower_left is None or self.upper_right is None: - return False - - for val1, val2 in zip(self.lower_left, self.upper_right): - if val1 == val2: - return True - def Mesh(*args, **kwargs): warnings.warn("Mesh has been renamed RegularMesh. Future versions of " "OpenMC will not accept the name Mesh.") diff --git a/tests/unit_tests/test_mesh.py b/tests/unit_tests/test_mesh.py index 8bc00a2768..0f9b96b0b3 100644 --- a/tests/unit_tests/test_mesh.py +++ b/tests/unit_tests/test_mesh.py @@ -33,25 +33,3 @@ def test_raises_error_when_flat(val_left, val_right): with pytest.raises(ValueError): mesh.upper_right = [25, 25, val_right] mesh.lower_left = [-25, -25, val_left] - - -def test_corner_none_returns_false(): - """Checks mesh is not considered flat when one - corner is None - """ - mesh = openmc.RegularMesh() - mesh.lower_left = [-25, -25, -25] - assert not mesh.is_flat() - - mesh = openmc.RegularMesh() - mesh.upper_right = [-25, -25, -25] - assert not mesh.is_flat() - - # test with np array - mesh = openmc.RegularMesh() - mesh.lower_left = np.array([-25, -25, -25]) - assert not mesh.is_flat() - - mesh = openmc.RegularMesh() - mesh.upper_right = np.array([-25, -25, -25]) - assert not mesh.is_flat() \ No newline at end of file