Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spherical bb #2620

Merged
merged 13 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

caderache2014 marked this conversation as resolved.
Show resolved Hide resolved
"""

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