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
42 changes: 42 additions & 0 deletions openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,12 @@ 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

"""

Expand Down Expand Up @@ -1282,6 +1288,42 @@ def indices(self):
for p in range(1, np + 1)
for r in range(1, nr + 1))


@property
def lower_left(self):
return (self.origin[0]-self.r_grid[-1], self.origin[1]-self.r_grid[-1], self.origin[2]-self.z_grid[-1])

@lower_left.setter
def lower_left(self, lower_left):
cv.check_type('mesh lower_left', lower_left, Iterable, Real)
cv.check_length('mesh lower_left', lower_left, 1, 3)
self._lower_left = lower_left

if self.upper_right is not None and any(np.isclose(self.upper_right, lower_left)):
raise ValueError("Mesh cannot have zero thickness in any dimension")

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

@upper_right.setter
def upper_right(self, upper_right):
cv.check_type('mesh upper_right', upper_right, Iterable, Real)
cv.check_length('mesh upper_right', upper_right, 1, 3)
self._upper_right = upper_right

if self._width is not None:
self._width = None
warnings.warn("Unsetting width attribute.")

if self.lower_left is not None and any(np.isclose(self.lower_left, upper_right)):
raise ValueError("Mesh cannot have zero thickness in any dimension")
caderache2014 marked this conversation as resolved.
Show resolved Hide resolved

@property
def bounding_box(self):
return openmc.BoundingBox(
np.array(self.lower_left), np.array(self.upper_right)
)
def __repr__(self):
fmt = '{0: <16}{1}{2}\n'
string = super().__repr__()
Expand Down
33 changes: 33 additions & 0 deletions tests/unit_tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def test_raises_error_when_flat(val_left, val_right):
mesh.lower_left = [-25, -25, val_left]


def test_mesh_regular_bounding_box():
mesh = openmc.RegularMesh()
mesh.lower_left = [-2, -3 ,-5]
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]))

def test_mesh_bounding_box():
mesh = openmc.RegularMesh()
mesh.lower_left = [-2, -3 ,-5]
Expand All @@ -44,3 +53,27 @@ def test_mesh_bounding_box():
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]))

def test_mesh_clyindrical_bounding_box():


caderache2014 marked this conversation as resolved.
Show resolved Hide resolved
mesh = openmc.ClyindricalMesh()
shimwell marked this conversation as resolved.
Show resolved Hide resolved
mesh.r_grid = np.array([0.1, 0.2, 0.5, 1.])
mesh.z_grid = np.array([0.1, 0.2, 0.4, 0.6, 1.])

#test with mesh at origin 0, 0, 0
mesh.origin = (0, 0, 0)
assert mesh.upper_right == (1, 1, 1)
assert mesh.lower_left == (-1, -1, -1)
bb = mesh.bounding_box
assert isinstance(bb, openmc.BoundingBox)
np.testing.assert_array_equal(bb.lower_left, np.array([-1, -1, -1]))
np.testing.assert_array_equal(bb.upper_right, np.array([1, 1, 1]))

# test with mesh at origin 3, 5, 7
mesh.origin = (3, 5, 7)
assert mesh.upper_right == (4, 6, 8)
assert mesh.lower_left == (2, 4, 6)
bb = mesh.bounding_box
assert isinstance(bb, openmc.BoundingBox)
np.testing.assert_array_equal(bb.lower_left, np.array([2, 4, 6]))
np.testing.assert_array_equal(bb.upper_right, np.array([4, 6, 8]))
caderache2014 marked this conversation as resolved.
Show resolved Hide resolved
Loading