Cylindrical bb (#2621)

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 10:26:48 +01:00 committed by GitHub
parent c340d4b8ec
commit 75a5d84a5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 4 deletions

View file

@ -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 @@ class CylindricalMesh(StructuredMesh):
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__()

View file

@ -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()