Spherical bb (#2620)

Co-authored-by: Jonathan Shimwell <drshimwell@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Christopher Billingham 2023-08-06 01:31:38 +01:00 committed by GitHub
parent f9c17dd82f
commit cce80fe7da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View file

@ -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
@ -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
"""
@ -1629,6 +1641,20 @@ class SphericalMesh(StructuredMesh):
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__()

View file

@ -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]
@ -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