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

Cylindrical bb #2621

Merged
merged 8 commits into from
Aug 6, 2023
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.
caderache2014 marked this conversation as resolved.
Show resolved Hide resolved
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.
caderache2014 marked this conversation as resolved.
Show resolved Hide resolved
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))


caderache2014 marked this conversation as resolved.
Show resolved Hide resolved
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