From 0b0265cb592685d8e6daec688229996d7b7e9f5a Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Fri, 1 Jul 2022 11:37:16 +0200 Subject: [PATCH 1/3] adapted tests --- tests/unit_tests/test_mesh_to_vtk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_mesh_to_vtk.py b/tests/unit_tests/test_mesh_to_vtk.py index 9247540a09..26a393b411 100644 --- a/tests/unit_tests/test_mesh_to_vtk.py +++ b/tests/unit_tests/test_mesh_to_vtk.py @@ -33,7 +33,7 @@ def test_write_data_to_vtk(mesh, tmpdir): # BUILD filename = Path(tmpdir) / "out.vtk" - data = np.random.random(mesh.dimension[0]*mesh.dimension[1]*mesh.dimension[2]) + data = np.random.random(mesh.num_mesh_cells) # RUN mesh.write_data_to_vtk(filename=filename, datasets={"label1": data, "label2": data}) @@ -68,7 +68,7 @@ def test_write_data_to_vtk_size_mismatch(mesh): mesh : openmc.StructuredMesh The mesh to test """ - right_size = mesh.dimension[0]*mesh.dimension[1]*mesh.dimension[2] + right_size = mesh.num_mesh_cells data = np.random.random(right_size + 1) expected_error_msg = "The size of the dataset label should be equal to the number of cells" From 9c892f04dbd36bc423a0560b72bb2da3a1b2a21a Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Fri, 1 Jul 2022 09:42:35 +0000 Subject: [PATCH 2/3] added num_mesh_cells property to StructuredMesh --- openmc/mesh.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openmc/mesh.py b/openmc/mesh.py index 2a53c8a91e..925a63aeec 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -193,6 +193,10 @@ class StructuredMesh(MeshBase): s1 = (slice(1, None),)*ndim + (slice(None),) return (vertices[s0] + vertices[s1]) / 2 + @property + def num_mesh_cells(self): + return np.prod(self.dimension) + def write_data_to_vtk(self, points, filename, datasets, volume_normalization=True): """Creates a VTK object of the mesh @@ -1547,6 +1551,7 @@ class UnstructuredMesh(MeshBase): "been loaded from a statepoint file.") return len(self._centroids) + @centroids.setter def centroids(self, centroids): cv.check_type("Unstructured mesh centroids", centroids, From 52d59a4c1a924039ca6eb790a1786fe85fce7574 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Fri, 1 Jul 2022 09:43:44 +0000 Subject: [PATCH 3/3] minor refactoring --- openmc/mesh.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 925a63aeec..d5a460baa8 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -348,10 +348,6 @@ class RegularMesh(StructuredMesh): dims = self._dimension return [(u - l) / d for u, l, d in zip(us, ls, dims)] - @property - def num_mesh_cells(self): - return np.prod(self._dimension) - @property def volumes(self): """Return Volumes for every mesh cell