Skip to content

Commit

Permalink
Cylindrical bb (#2621)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Shimwell <[email protected]>
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
3 people committed Aug 6, 2023
1 parent c340d4b commit 75a5d84
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
30 changes: 30 additions & 0 deletions openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down Expand Up @@ -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__()
Expand Down
30 changes: 26 additions & 4 deletions tests/unit_tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand 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()
Expand Down

0 comments on commit 75a5d84

Please sign in to comment.