Skip to content

Commit

Permalink
Spherical bb (#2620)
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 f9c17dd commit cce80fe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
26 changes: 26 additions & 0 deletions openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ class RegularMesh(StructuredMesh):
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.BoundingBox
Axis-aligned bounding box of the cell defined by the upper-right and lower-
left coordinates
width : Iterable of float
The width of mesh cells in each direction.
indices : Iterable of tuple
Expand Down Expand Up @@ -1549,6 +1552,15 @@ class SphericalMesh(StructuredMesh):
indices : Iterable of tuple
An iterable of mesh indices for each mesh element, e.g. [(1, 1, 1),
(2, 1, 1), ...]
lower_left : numpy.ndarray
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 : numpy.ndarray
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.BoundingBox
Axis-aligned bounding box of the cell defined by the upper-right and lower-
left coordinates
"""

Expand Down Expand Up @@ -1629,6 +1641,20 @@ def indices(self):
for t in range(1, nt + 1)
for r in range(1, nr + 1))

@property
def lower_left(self):
r = self.r_grid[-1]
return np.array((self.origin[0] - r, self.origin[1] - r, self.origin[2] - r))

@property
def upper_right(self):
r = self.r_grid[-1]
return np.array((self.origin[0] + r, self.origin[1] + r, self.origin[2] + r))

@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
22 changes: 21 additions & 1 deletion tests/unit_tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_raises_error_when_flat(val_left, val_right):
mesh.lower_left = [-25, -25, val_left]


def test_mesh_bounding_box():
def test_regular_mesh_bounding_box():
mesh = openmc.RegularMesh()
mesh.lower_left = [-2, -3, -5]
mesh.upper_right = [2, 3, 5]
Expand All @@ -48,6 +48,26 @@ def test_mesh_bounding_box():
np.testing.assert_array_equal(bb.upper_right, np.array([2, 3, 5]))


def test_spherical_mesh_bounding_box():
# test with mesh at origin (0, 0, 0)
mesh = openmc.SphericalMesh([0.1, 0.2, 0.5, 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_SphericalMesh_initiation():

# test defaults
Expand Down

0 comments on commit cce80fe

Please sign in to comment.