diff --git a/openmc/mesh.py b/openmc/mesh.py index 30ad738a20b..5313ebb398b 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -1225,6 +1225,15 @@ class CylindricalMesh(StructuredMesh): indices : Iterable of tuple An iterable of mesh indices for each mesh element, e.g. [(1, 1, 1), (2, 1, 1), ...] + lower_left : Iterable of float + The lower-left corner of the structured mesh. If only two coordinate + are given, it is assumed that the mesh is an x-y mesh. + upper_right : Iterable of float + The upper-right corner of the structured mesh. If only two coordinate + are given, it is assumed that the mesh is an x-y mesh. + bounding_box: openmc.OpenMC + Axis-aligned cartesian bounding box of cell defined by upper-right and lower- + left coordinates """ @@ -1305,6 +1314,27 @@ def indices(self): for p in range(1, np + 1) for r in range(1, nr + 1)) + + @property + def lower_left(self): + return np.array(( + self.origin[0] - self.r_grid[-1], + self.origin[1] - self.r_grid[-1], + self.origin[2] - self.z_grid[-1] + )) + + @property + def upper_right(self): + return np.array(( + self.origin[0] + self.r_grid[-1], + self.origin[1] + self.r_grid[-1], + self.origin[2] + self.z_grid[-1] + )) + + @property + def bounding_box(self): + return openmc.BoundingBox(self.lower_left, self.upper_right) + def __repr__(self): fmt = '{0: <16}{1}{2}\n' string = super().__repr__() diff --git a/tests/unit_tests/test_mesh.py b/tests/unit_tests/test_mesh.py index 60d14a27929..480104154d5 100644 --- a/tests/unit_tests/test_mesh.py +++ b/tests/unit_tests/test_mesh.py @@ -44,8 +44,32 @@ def test_regular_mesh_bounding_box(): mesh.upper_right = [2, 3, 5] bb = mesh.bounding_box assert isinstance(bb, openmc.BoundingBox) - np.testing.assert_array_equal(bb.lower_left, np.array([-2, -3 ,-5])) - np.testing.assert_array_equal(bb.upper_right, np.array([2, 3, 5])) + np.testing.assert_array_equal(bb.lower_left, (-2, -3 ,-5)) + np.testing.assert_array_equal(bb.upper_right, (2, 3, 5)) + + +def test_cylindrical_mesh_bounding_box(): + # test with mesh at origin (0, 0, 0) + mesh = openmc.CylindricalMesh( + r_grid=[0.1, 0.2, 0.5, 1.], + z_grid=[0.1, 0.2, 0.4, 0.6, 1.], + origin=(0, 0, 0) + ) + np.testing.assert_array_equal(mesh.upper_right, (1, 1, 1)) + np.testing.assert_array_equal(mesh.lower_left, (-1, -1, -1)) + bb = mesh.bounding_box + assert isinstance(bb, openmc.BoundingBox) + np.testing.assert_array_equal(bb.lower_left, (-1, -1, -1)) + np.testing.assert_array_equal(bb.upper_right, (1, 1, 1)) + + # test with mesh at origin (3, 5, 7) + mesh.origin = (3, 5, 7) + np.testing.assert_array_equal(mesh.upper_right, (4, 6, 8)) + np.testing.assert_array_equal(mesh.lower_left, (2, 4, 6)) + bb = mesh.bounding_box + assert isinstance(bb, openmc.BoundingBox) + np.testing.assert_array_equal(bb.lower_left, (2, 4, 6)) + np.testing.assert_array_equal(bb.upper_right, (4, 6, 8)) def test_spherical_mesh_bounding_box(): @@ -69,7 +93,6 @@ def test_spherical_mesh_bounding_box(): def test_SphericalMesh_initiation(): - # test defaults mesh = openmc.SphericalMesh(r_grid=(0, 10)) assert (mesh.origin == np.array([0, 0, 0])).all() @@ -95,7 +118,6 @@ def test_SphericalMesh_initiation(): def test_CylindricalMesh_initiation(): - # test defaults mesh = openmc.CylindricalMesh(r_grid=(0, 10), z_grid=(0, 10)) assert (mesh.origin == np.array([0, 0, 0])).all()