From f787057c931cf921cb21a3680b0231ddc2996477 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 1 Apr 2022 16:13:00 -0500 Subject: [PATCH 01/20] Added Octagon composite surface --- openmc/model/surface_composite.py | 142 ++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 09a3c0170f..31b6222a84 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -50,6 +50,148 @@ class CompositeSurface(ABC): def __neg__(self): """Return the negative half-space of the composite surface.""" +class Octagon(CompositeSurface): + """Infinite octogonal prism composite surface + + An octagonal prism is composed of eight surfaces. The prism is parallel to + the x, y, or z axis; two pars of surfaces are perpendicualr to the z and y, + x and z, or y and x axes, respectively. + + This class + acts as a proper surface, meaning that unary `+` and `-` operators applied + to it will produce a half-space. The negative side is defined to be the + region inside of the octogonal prism. + + Parameters + ---------- + center : 2-tuple + (q1,q2) coordinate for the center of the octagon. (q1,q2) pairs are + (x,y), (x,z), or (x,z). + r1 : float + Half-width of octagon across axis-perpendicualr sides + r2 : float + Half-width of octagon across off-axis sides + axis : {'x', 'y', 'z'} + Central axis of ocatgon. Defaults to 'z' + **kwargs + Keyword arguments passed to underlying cylinder and plane classes + + Attributes + ---------- + top : openmc.ZPlane or openmc.XPlane + Top planar surface of octagon + bottom : openmc.ZPlane or openmc.XPlane + Bottom planar surface of octagon + right: openmc.YPlane or openmc.ZPlane + Right planaer surface of octagon + left: openmc.YPlane or openmc.ZPlane + Left planar surface of octagon + upper_right : openmc.Plane + Upper right planar surface of octagon + lower_right : openmc.Plane + Lower right planar surface of octagon + lower_left : openmc.Plane + Lower left planar surface of octagon + upper_left : openmc.Plane + Upper left planar surface of octagon + + """ + + _surface_names = ('top', 'bottom', + 'upper_right', 'lower_left', + 'right', 'left', + 'lower_right', 'upper_left') + + def __init__(self, center, r1, r2, axis='z', **kwargs): + self._axis = axis + q1c, q2c = center + + # Coords for axis-perpendicular planes + ctop = q1c+r1 + cbottom = q1c-r1 + + cright= q2c+r1 + cleft = q2c-r1 + + # Side lengths + L_perp_ax1 = (r2 * np.sqrt(2) - r1) * 2 + L_perp_ax2 = (r1 * np.sqrt(2) - r2) * 2 + + # Coords for quadrant planes + p1_ur = [L_perp_ax1/2, r1, 0] + p2_ur = [r1, L_perp_ax1/2, 0] + p3_ur = [r1, L_perp_ax1/2, 1] + + p1_lr = [r1, -L_perp_ax1/2, 0] + p2_lr = [L_perp_ax1/2, -r1, 0] + p3_lr = [L_perp_ax1/2, -r1, 1] + + points = [p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr] + + # Orientation specific variables + if axis == 'z': + coord_map = [0,1,2] + self.top = openmc.YPlane(y0=ctop, **kwargs) + self.bottom = openmc.YPlane(y0=cbottom, **kwargs) + self.right = openmc.XPlane(x0=cright, **kwargs) + self.left = openmc.XPlane(x0=cleft, **kwargs) + elif axis == 'y': + coord_map = [0,2,1] + self.top = openmc.ZPlane(z0=ctop, **kwargs) + self.bottom = openmc.ZPlane(z0=cbottom, **kwargs) + self.right = openmc.XPlane(x0=cright, **kwargs) + self.left = openmc.XPlane(x0=cleft, **kwargs) + elif axis == 'x': + coord_map = [2,0,1] + self.top = openmc.ZPlane(z0=ctop, **kwargs) + self.bottom = openmc.ZPlane(z0=cbottom, **kwargs) + self.right = openmc.YPlane(y0=cright, **kwargs) + self.left = openmc.YPlane(y0=cleft, **kwargs) + + # Put our coordinates in (x,y,z) order + calibrated_points = [] + for p in points: + p_temp = [] + for i in coord_map: + p_temp += [p[i]] + calibrated_points += [np.array(p_temp)] + + p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points + + upper_right_params = _plane_from_points(p1_ur, p2_ur, p3_ur) + lower_right_params = _plane_from_points(p1_lr, p2_lr, p3_lr) + lower_left_params = _plane_from_points(-p1_ur, -p2_ur, -p3_ur) + upper_left_params = _plane_from_points(-p1_lr, -p2_lr, -p3_lr) + + self.upper_right = openmc.Plane(*tuple(upper_right_params), **kwargs) + self.lower_right = openmc.Plane(*tuple(lower_right_params), **kwargs) + self.lower_left = openmc.Plane(*tuple(lower_left_params), **kwargs) + self.upper_left = openmc.Plane(*tuple(upper_left_params), **kwargs) + + + def __neg__(self): + reg = -self.top & +self.bottom & -self.right & +self.left + if self._axis == 'y': + reg = reg & -self.upper_right & -self.lower_right & \ + +self.lower_left & +self.upper_left + else: + reg = reg & +self.upper_right & +self.lower_right & \ + -self.lower_left & -self.upper_left + + return reg + + + def __pos__(self): + reg = +self.top | -self.bottom | +self.right | -self.left + if self._axis == 'y': + reg = reg | +self.upper_right | +self.lower_right | \ + -self.lower_left | -self.upper_left + else: + reg = reg | -self.upper_right | -self.lower_right | \ + +self.lower_left | +self.upper_left + + return reg + class RightCircularCylinder(CompositeSurface): """Right circular cylinder composite surface From f266740bf0a6a99fc602f8f9384841d837b1b20d Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 12:27:45 -0500 Subject: [PATCH 02/20] added numpy imports, plane helper function --- openmc/model/surface_composite.py | 33 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 31b6222a84..deb8e9846d 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -3,7 +3,18 @@ from copy import copy import openmc from openmc.checkvalue import check_greater_than, check_value +from numpy import sqrt, cross, dot, array +def _plane_from_points(p1, p2, p3): + # get plane from points p1, p2, p3 + n = cross(p2 - p1, p3 - p1) + n0 = -p1 + A = n[0] + B = n[1] + C = n[2] + D = dot(n, n0) + + return [A, B, C, -D] class CompositeSurface(ABC): """Multiple primitive surfaces combined into a composite surface""" @@ -114,8 +125,8 @@ class Octagon(CompositeSurface): cleft = q2c-r1 # Side lengths - L_perp_ax1 = (r2 * np.sqrt(2) - r1) * 2 - L_perp_ax2 = (r1 * np.sqrt(2) - r2) * 2 + L_perp_ax1 = (r2 * sqrt(2) - r1) * 2 + L_perp_ax2 = (r1 * sqrt(2) - r2) * 2 # Coords for quadrant planes p1_ur = [L_perp_ax1/2, r1, 0] @@ -154,7 +165,7 @@ class Octagon(CompositeSurface): p_temp = [] for i in coord_map: p_temp += [p[i]] - calibrated_points += [np.array(p_temp)] + calibrated_points += [array(p_temp)] p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points @@ -170,27 +181,27 @@ class Octagon(CompositeSurface): def __neg__(self): - reg = -self.top & +self.bottom & -self.right & +self.left + region1 = -self.top & +self.bottom & -self.right & +self.left if self._axis == 'y': - reg = reg & -self.upper_right & -self.lower_right & \ + region2 = -self.upper_right & -self.lower_right & \ +self.lower_left & +self.upper_left else: - reg = reg & +self.upper_right & +self.lower_right & \ + region2 = +self.upper_right & +self.lower_right & \ -self.lower_left & -self.upper_left - return reg + return region1 & region2 def __pos__(self): - reg = +self.top | -self.bottom | +self.right | -self.left + region1 = +self.top | -self.bottom | +self.right | -self.left if self._axis == 'y': - reg = reg | +self.upper_right | +self.lower_right | \ + region2 = +self.upper_right | +self.lower_right | \ -self.lower_left | -self.upper_left else: - reg = reg | -self.upper_right | -self.lower_right | \ + region2 = -self.upper_right | -self.lower_right | \ +self.lower_left | +self.upper_left - return reg + return region1 | region2 class RightCircularCylinder(CompositeSurface): From 1648b854a4f91a1efefd203620cfb19abf3e7d68 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 12:27:58 -0500 Subject: [PATCH 03/20] Added unit test for Octagon --- tests/unit_tests/test_surface_composite.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index a1a218311d..d3ec10cf4a 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -150,3 +150,75 @@ def test_cone_one_sided(axis, point_pos, point_neg, ll_true): # Make sure repr works repr(s) + + +@pytest.mark.parametrize( + "axis, plane_tb, plane_lr, axis_idx", [ + ("x", "Z", "Y", 0), + ("y", "Z", "X", 1), + ("z", "Y", "X", 2), + ] +) +def test_octagon(axis, plane_tb, plane_lr, axis_idx): + center = np.array([0.,0.]) + point_pos = np.array([0.8,0.8]) + point_neg = np.array([0.7,0.7]) + r1 = 1. + r2 = 1. + plane_top_bottom = getattr(openmc, plane_tb + "Plane") + plane_left_right = getattr(openmc, plane_lr + "Plane") + s = openmc.model.Octagon(center, r1, r2, axis=axis) + assert isinstance(s.top, plane_top_bottom) + assert isinstance(s.bottom, plane_top_bottom) + assert isinstance(s.right, plane_left_right) + assert isinstance(s.left, plane_left_right) + assert isinstance(s.upper_right, openmc.Plane) + assert isinstance(s.lower_right, openmc.Plane) + assert isinstance(s.upper_left, openmc.Plane) + assert isinstance(s.lower_left, openmc.Plane) + + # Make sure boundary condition propagates + s.boundary_type = 'reflective' + assert s.boundary_type == 'reflective' + assert s.top.boundary_type == 'reflective' + assert s.bottom.boundary_type == 'reflective' + assert s.right.boundary_type == 'reflective' + assert s.left.boundary_type == 'reflective' + assert s.upper_right.boundary_type == 'reflective' + assert s.lower_right.boundary_type == 'reflective' + assert s.lower_left.boundary_type == 'reflective' + assert s.upper_left.boundary_type == 'reflective' + + # Check bounding box + center = np.insert(center, axis_idx, np.inf) + xmax,ymax,zmax = center + r1 + coord_min = center - r1 + coord_min[axis_idx] *= -1 + xmin,ymin,zmin = coord_min + ll, ur = (+s).bounding_box + assert np.all(np.isinf(ll)) + assert np.all(np.isinf(ur)) + ll, ur = (-s).bounding_box + assert ur == pytest.approx((xmax, ymax, zmax)) + assert ll == pytest.approx((xmin, ymin, zmin)) + + # __contains__ on associated half-spaces + point_pos = np.insert(point_pos, axis_idx, 0) + point_neg = np.insert(point_neg, axis_idx, 0) + assert point_pos in +s + assert point_pos not in -s + assert point_neg in -s + assert point_neg not in +s + + # translate method + t = uniform(-5.0, 5.0) + s_t = s.translate((t, t, t)) + ll_t, ur_t = (-s_t).bounding_box + assert ur_t == pytest.approx(ur + t) + assert ll_t == pytest.approx(ll + t) + + # Make sure repr works + repr(s) + + + From 020ebb9374f65590b3094fd3eb14fe603f61ce08 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 12:47:23 -0500 Subject: [PATCH 04/20] fix typos in docstring for Octagon --- openmc/model/surface_composite.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index deb8e9846d..be57367940 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -64,38 +64,37 @@ class CompositeSurface(ABC): class Octagon(CompositeSurface): """Infinite octogonal prism composite surface - An octagonal prism is composed of eight surfaces. The prism is parallel to - the x, y, or z axis; two pars of surfaces are perpendicualr to the z and y, - x and z, or y and x axes, respectively. + An octagonal prism is composed of eight planar surfaces. The prism is + parallel to the x, y, or z axis; two pars of surfaces are perpendicular to + the y and z, x and z, or x and y axes, respectively. - This class - acts as a proper surface, meaning that unary `+` and `-` operators applied - to it will produce a half-space. The negative side is defined to be the - region inside of the octogonal prism. + This class acts as a proper surface, meaning that unary `+` and `-` + operators applied to it will produce a half-space. The negative side is + defined to be the region inside of the octogonal prism. Parameters ---------- - center : 2-tuple - (q1,q2) coordinate for the center of the octagon. (q1,q2) pairs are - (x,y), (x,z), or (x,z). + center : iterable of float + (q1,q2) coordinate for the central axis of the octagon. (q1,q2) pairs + are (y,z), (x,z), or (x,y). r1 : float - Half-width of octagon across axis-perpendicualr sides + Half-width of octagon across axis-pendicular sides r2 : float Half-width of octagon across off-axis sides axis : {'x', 'y', 'z'} - Central axis of ocatgon. Defaults to 'z' + Central axis of octagon. Defaults to 'z' **kwargs Keyword arguments passed to underlying cylinder and plane classes Attributes ---------- - top : openmc.ZPlane or openmc.XPlane + top : openmc.ZPlane or openmc.YPlane Top planar surface of octagon - bottom : openmc.ZPlane or openmc.XPlane + bottom : openmc.ZPlane or openmc.YPlane Bottom planar surface of octagon - right: openmc.YPlane or openmc.ZPlane + right: openmc.YPlane or openmc.XPlane Right planaer surface of octagon - left: openmc.YPlane or openmc.ZPlane + left: openmc.YPlane or openmc.XPlane Left planar surface of octagon upper_right : openmc.Plane Upper right planar surface of octagon From 71e76b251e1f9724fab1461d7ff824ff18aaabd2 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 12:47:44 -0500 Subject: [PATCH 05/20] Add reference to Octagon in the Sphinx docs --- docs/source/pythonapi/model.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pythonapi/model.rst b/docs/source/pythonapi/model.rst index a6c89be7cd..2fc27d40e2 100644 --- a/docs/source/pythonapi/model.rst +++ b/docs/source/pythonapi/model.rst @@ -30,6 +30,7 @@ Composite Surfaces openmc.model.XConeOneSided openmc.model.YConeOneSided openmc.model.ZConeOneSided + openmc.model.Octagon TRISO Fuel Modeling ------------------- From f7d304f7955e47a8d98aa52004225dccee8fa344 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 13:02:32 -0500 Subject: [PATCH 06/20] use existing openmc function instead of custom one for plane_from_points --- openmc/model/surface_composite.py | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index be57367940..02022fa3cf 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -3,18 +3,8 @@ from copy import copy import openmc from openmc.checkvalue import check_greater_than, check_value -from numpy import sqrt, cross, dot, array - -def _plane_from_points(p1, p2, p3): - # get plane from points p1, p2, p3 - n = cross(p2 - p1, p3 - p1) - n0 = -p1 - A = n[0] - B = n[1] - C = n[2] - D = dot(n, n0) - - return [A, B, C, -D] +import openmc.Plane.from_points as plane_from_points +from numpy import sqrt class CompositeSurface(ABC): """Multiple primitive surfaces combined into a composite surface""" @@ -164,19 +154,14 @@ class Octagon(CompositeSurface): p_temp = [] for i in coord_map: p_temp += [p[i]] - calibrated_points += [array(p_temp)] + calibrated_points += [p_temp] p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points - upper_right_params = _plane_from_points(p1_ur, p2_ur, p3_ur) - lower_right_params = _plane_from_points(p1_lr, p2_lr, p3_lr) - lower_left_params = _plane_from_points(-p1_ur, -p2_ur, -p3_ur) - upper_left_params = _plane_from_points(-p1_lr, -p2_lr, -p3_lr) - - self.upper_right = openmc.Plane(*tuple(upper_right_params), **kwargs) - self.lower_right = openmc.Plane(*tuple(lower_right_params), **kwargs) - self.lower_left = openmc.Plane(*tuple(lower_left_params), **kwargs) - self.upper_left = openmc.Plane(*tuple(upper_left_params), **kwargs) + self.upper_right = plane_from_points(p1_ur, p2_ur, p3_ur, **kwargs) + self.lower_right = plane_from_points(p1_lr, p2_lr, p3_lr, **kwargs) + self.lower_left = plane_from_points(-p1_ur, -p2_ur, -p3_ur, **kwargs) + self.upper_left = plane_from_points(-p1_lr, -p2_lr, -p3_lr, **kwargs) def __neg__(self): From ab0fcc7ca4e8ef9241fd41e2746239541f0b3a91 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 13:03:12 -0500 Subject: [PATCH 07/20] put Octagon in alphabetical order --- docs/source/pythonapi/model.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/pythonapi/model.rst b/docs/source/pythonapi/model.rst index 2fc27d40e2..6c707cbdc3 100644 --- a/docs/source/pythonapi/model.rst +++ b/docs/source/pythonapi/model.rst @@ -25,12 +25,12 @@ Composite Surfaces :nosignatures: :template: myclass.rst + openmc.model.Octagon openmc.model.RectangularParallelepiped openmc.model.RightCircularCylinder openmc.model.XConeOneSided openmc.model.YConeOneSided openmc.model.ZConeOneSided - openmc.model.Octagon TRISO Fuel Modeling ------------------- From f4e96453ab10fa1000dcd8e3969ebee70410e11e Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 14:24:49 -0500 Subject: [PATCH 08/20] changed Octagon to IsogonalOctagon --- docs/source/pythonapi/model.rst | 2 +- openmc/model/surface_composite.py | 41 ++++++++++++++-------- tests/unit_tests/test_surface_composite.py | 4 +-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/docs/source/pythonapi/model.rst b/docs/source/pythonapi/model.rst index 6c707cbdc3..145330127d 100644 --- a/docs/source/pythonapi/model.rst +++ b/docs/source/pythonapi/model.rst @@ -25,7 +25,7 @@ Composite Surfaces :nosignatures: :template: myclass.rst - openmc.model.Octagon + openmc.model.IsogonalOctagon openmc.model.RectangularParallelepiped openmc.model.RightCircularCylinder openmc.model.XConeOneSided diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 02022fa3cf..897ff08819 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -3,7 +3,6 @@ from copy import copy import openmc from openmc.checkvalue import check_greater_than, check_value -import openmc.Plane.from_points as plane_from_points from numpy import sqrt class CompositeSurface(ABC): @@ -51,12 +50,15 @@ class CompositeSurface(ABC): def __neg__(self): """Return the negative half-space of the composite surface.""" -class Octagon(CompositeSurface): - """Infinite octogonal prism composite surface +class IsogonalOctagon(CompositeSurface): + """Infinite isogonal octagon composite surface - An octagonal prism is composed of eight planar surfaces. The prism is - parallel to the x, y, or z axis; two pars of surfaces are perpendicular to - the y and z, x and z, or x and y axes, respectively. + An isogonal octagon is composed of eight planar surfaces. The prism is + parallel to the x, y, or z axis. The remaining two axes (y and z, x and z, + or x and y) serve as a basis for constructing the surfaces. Two surfaces + are parallel to the first basis axis, two surfaces are parallel + to the second basis axis, and the remaining four surfaces intersect both + basis axes at 45 degree angles. This class acts as a proper surface, meaning that unary `+` and `-` operators applied to it will produce a half-space. The negative side is @@ -65,16 +67,18 @@ class Octagon(CompositeSurface): Parameters ---------- center : iterable of float - (q1,q2) coordinate for the central axis of the octagon. (q1,q2) pairs - are (y,z), (x,z), or (x,y). + Coordinate for the central axis of the octagon in the + (y, z), (x, z), or (x, y) basis. r1 : float - Half-width of octagon across axis-pendicular sides + Half-width of octagon across its basis axis-parallel sides in units + of cm r2 : float - Half-width of octagon across off-axis sides + Half-width of octagon across its basis axis intersecting sides in + units of cm. Must be less than :math:`\sqrt{2} r_1`. axis : {'x', 'y', 'z'} Central axis of octagon. Defaults to 'z' **kwargs - Keyword arguments passed to underlying cylinder and plane classes + Keyword arguments passed to underlying plane classes Attributes ---------- @@ -114,6 +118,9 @@ class Octagon(CompositeSurface): cleft = q2c-r1 # Side lengths + if (r2 > r1 * sqrt(2)): + raise ValueError(f'r2 must be less than {sqrt(2) * r1}') + L_perp_ax1 = (r2 * sqrt(2) - r1) * 2 L_perp_ax2 = (r1 * sqrt(2) - r2) * 2 @@ -158,10 +165,14 @@ class Octagon(CompositeSurface): p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points - self.upper_right = plane_from_points(p1_ur, p2_ur, p3_ur, **kwargs) - self.lower_right = plane_from_points(p1_lr, p2_lr, p3_lr, **kwargs) - self.lower_left = plane_from_points(-p1_ur, -p2_ur, -p3_ur, **kwargs) - self.upper_left = plane_from_points(-p1_lr, -p2_lr, -p3_lr, **kwargs) + self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, + **kwargs) + self.lower_right = openmc.Plane.from_points(p1_lr, p2_lr, p3_lr, + **kwargs) + self.lower_left = openmc.Plane.from_points(-p1_ur, -p2_ur, -p3_ur, + **kwargs) + self.upper_left = openmc.Plane.from_points(-p1_lr, -p2_lr, -p3_lr, + **kwargs) def __neg__(self): diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index d3ec10cf4a..c2620a92ab 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -159,7 +159,7 @@ def test_cone_one_sided(axis, point_pos, point_neg, ll_true): ("z", "Y", "X", 2), ] ) -def test_octagon(axis, plane_tb, plane_lr, axis_idx): +def test_isogonal_octagon(axis, plane_tb, plane_lr, axis_idx): center = np.array([0.,0.]) point_pos = np.array([0.8,0.8]) point_neg = np.array([0.7,0.7]) @@ -167,7 +167,7 @@ def test_octagon(axis, plane_tb, plane_lr, axis_idx): r2 = 1. plane_top_bottom = getattr(openmc, plane_tb + "Plane") plane_left_right = getattr(openmc, plane_lr + "Plane") - s = openmc.model.Octagon(center, r1, r2, axis=axis) + s = openmc.model.IsogonalOctagon(center, r1, r2, axis=axis) assert isinstance(s.top, plane_top_bottom) assert isinstance(s.bottom, plane_top_bottom) assert isinstance(s.right, plane_left_right) From 0518bdcb7bb08a80f45829c2396c90ffc2fc059a Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 14:32:14 -0500 Subject: [PATCH 09/20] fix plane point calculation --- openmc/model/surface_composite.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 897ff08819..38b3800fa0 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -3,7 +3,7 @@ from copy import copy import openmc from openmc.checkvalue import check_greater_than, check_value -from numpy import sqrt +from numpy import sqrt, array class CompositeSurface(ABC): """Multiple primitive surfaces combined into a composite surface""" @@ -161,18 +161,14 @@ class IsogonalOctagon(CompositeSurface): p_temp = [] for i in coord_map: p_temp += [p[i]] - calibrated_points += [p_temp] + calibrated_points += [array(p_temp)] p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points - self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, - **kwargs) - self.lower_right = openmc.Plane.from_points(p1_lr, p2_lr, p3_lr, - **kwargs) - self.lower_left = openmc.Plane.from_points(-p1_ur, -p2_ur, -p3_ur, - **kwargs) - self.upper_left = openmc.Plane.from_points(-p1_lr, -p2_lr, -p3_lr, - **kwargs) + self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, **kwargs) + self.lower_right = openmc.Plane.from_points(p1_lr, p2_lr, p3_lr, **kwargs) + self.lower_left = openmc.Plane.from_points(-p1_ur, -p2_ur, -p3_ur, **kwargs) + self.upper_left = openmc.Plane.from_points(-p1_lr, -p2_lr, -p3_lr, **kwargs) def __neg__(self): From ded546802c13706203ade8b9a08b0c523736c5b9 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 16:33:12 -0500 Subject: [PATCH 10/20] fix import statements; relax the error to a warning --- openmc/model/surface_composite.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 38b3800fa0..ba26a21571 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -1,9 +1,10 @@ from abc import ABC, abstractmethod from copy import copy +from math import sqrt +from numpy import array import openmc from openmc.checkvalue import check_greater_than, check_value -from numpy import sqrt, array class CompositeSurface(ABC): """Multiple primitive surfaces combined into a composite surface""" @@ -74,7 +75,7 @@ class IsogonalOctagon(CompositeSurface): of cm r2 : float Half-width of octagon across its basis axis intersecting sides in - units of cm. Must be less than :math:`\sqrt{2} r_1`. + units of cm. Assumed to be less than :math:`r_1\sqrt{2}`. axis : {'x', 'y', 'z'} Central axis of octagon. Defaults to 'z' **kwargs @@ -87,7 +88,7 @@ class IsogonalOctagon(CompositeSurface): bottom : openmc.ZPlane or openmc.YPlane Bottom planar surface of octagon right: openmc.YPlane or openmc.XPlane - Right planaer surface of octagon + Right planar surface of octagon left: openmc.YPlane or openmc.XPlane Left planar surface of octagon upper_right : openmc.Plane @@ -119,7 +120,8 @@ class IsogonalOctagon(CompositeSurface): # Side lengths if (r2 > r1 * sqrt(2)): - raise ValueError(f'r2 must be less than {sqrt(2) * r1}') + raise Warning(f'r2 is greater than {sqrt(2) * r1}. Octagon may' + 'be erroneous.') L_perp_ax1 = (r2 * sqrt(2) - r1) * 2 L_perp_ax2 = (r1 * sqrt(2) - r2) * 2 From 24f4ceb132a44d3cf86adcf05543aeec6fb897ca Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 4 Apr 2022 17:10:11 -0500 Subject: [PATCH 11/20] fix warnings, syntax errors --- openmc/model/surface_composite.py | 51 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index ba26a21571..ac53a6e729 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -4,6 +4,7 @@ from math import sqrt from numpy import array import openmc +import warnings from openmc.checkvalue import check_greater_than, check_value class CompositeSurface(ABC): @@ -72,7 +73,7 @@ class IsogonalOctagon(CompositeSurface): (y, z), (x, z), or (x, y) basis. r1 : float Half-width of octagon across its basis axis-parallel sides in units - of cm + of cm. Assumed to be less than :math:`r_2\sqrt{2}`. r2 : float Half-width of octagon across its basis axis intersecting sides in units of cm. Assumed to be less than :math:`r_1\sqrt{2}`. @@ -109,31 +110,34 @@ class IsogonalOctagon(CompositeSurface): def __init__(self, center, r1, r2, axis='z', **kwargs): self._axis = axis - q1c, q2c = center + c1, c2 = center # Coords for axis-perpendicular planes - ctop = q1c+r1 - cbottom = q1c-r1 + ctop = c1 + r1 + cbottom = c1 - r1 - cright= q2c+r1 - cleft = q2c-r1 + cright = c2 + r1 + cleft = c2 - r1 # Side lengths - if (r2 > r1 * sqrt(2)): - raise Warning(f'r2 is greater than {sqrt(2) * r1}. Octagon may' - 'be erroneous.') + if r2 > r1 * sqrt(2): + warnings.warn(f'r2 is greater than sqrt(2) * r1. Octagon may' + \ + ' be erroneous.') + if r1 > r2 * sqrt(2): + warnings.warn(f'r1 is greater than sqrt(2) * r2. Octagon may' + \ + ' be erroneous.') L_perp_ax1 = (r2 * sqrt(2) - r1) * 2 L_perp_ax2 = (r1 * sqrt(2) - r2) * 2 # Coords for quadrant planes - p1_ur = [L_perp_ax1/2, r1, 0] - p2_ur = [r1, L_perp_ax1/2, 0] - p3_ur = [r1, L_perp_ax1/2, 1] + p1_ur = array([L_perp_ax1/2, r1, 0.]) + p2_ur = array([r1, L_perp_ax1/2, 0.]) + p3_ur = array([r1, L_perp_ax1/2, 1.]) - p1_lr = [r1, -L_perp_ax1/2, 0] - p2_lr = [L_perp_ax1/2, -r1, 0] - p3_lr = [L_perp_ax1/2, -r1, 1] + p1_lr = array([r1, -L_perp_ax1/2, 0.]) + p2_lr = array([L_perp_ax1/2, -r1, 0.]) + p3_lr = array([L_perp_ax1/2, -r1, 1.]) points = [p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr] @@ -160,17 +164,18 @@ class IsogonalOctagon(CompositeSurface): # Put our coordinates in (x,y,z) order calibrated_points = [] for p in points: - p_temp = [] - for i in coord_map: - p_temp += [p[i]] - calibrated_points += [array(p_temp)] + calibrated_points += [p[coord_map]] p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points - self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, **kwargs) - self.lower_right = openmc.Plane.from_points(p1_lr, p2_lr, p3_lr, **kwargs) - self.lower_left = openmc.Plane.from_points(-p1_ur, -p2_ur, -p3_ur, **kwargs) - self.upper_left = openmc.Plane.from_points(-p1_lr, -p2_lr, -p3_lr, **kwargs) + self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, + **kwargs) + self.lower_right = openmc.Plane.from_points(p1_lr, p2_lr, p3_lr, + **kwargs) + self.lower_left = openmc.Plane.from_points(-p1_ur, -p2_ur, -p3_ur, + **kwargs) + self.upper_left = openmc.Plane.from_points(-p1_lr, -p2_lr, -p3_lr, + **kwargs) def __neg__(self): From a3ae1c254abcc1e798fcd17072ea2361fb1bdbca Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 5 Apr 2022 09:50:41 -0500 Subject: [PATCH 12/20] apply @paulromano's suggestions --- openmc/model/surface_composite.py | 38 ++++++++++------------ tests/unit_tests/test_surface_composite.py | 7 ++-- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index ac53a6e729..7a92a69ef3 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -52,6 +52,7 @@ class CompositeSurface(ABC): def __neg__(self): """Return the negative half-space of the composite surface.""" + class IsogonalOctagon(CompositeSurface): """Infinite isogonal octagon composite surface @@ -143,30 +144,29 @@ class IsogonalOctagon(CompositeSurface): # Orientation specific variables if axis == 'z': - coord_map = [0,1,2] - self.top = openmc.YPlane(y0=ctop, **kwargs) - self.bottom = openmc.YPlane(y0=cbottom, **kwargs) - self.right = openmc.XPlane(x0=cright, **kwargs) - self.left = openmc.XPlane(x0=cleft, **kwargs) + coord_map = [0, 1, 2] + self.top = openmc.YPlane(ctop, **kwargs) + self.bottom = openmc.YPlane(cbottom, **kwargs) + self.right = openmc.XPlane(cright, **kwargs) + self.left = openmc.XPlane(cleft, **kwargs) elif axis == 'y': - coord_map = [0,2,1] - self.top = openmc.ZPlane(z0=ctop, **kwargs) - self.bottom = openmc.ZPlane(z0=cbottom, **kwargs) - self.right = openmc.XPlane(x0=cright, **kwargs) - self.left = openmc.XPlane(x0=cleft, **kwargs) + coord_map = [0, 2, 1] + self.top = openmc.ZPlane(ctop, **kwargs) + self.bottom = openmc.ZPlane(cbottom, **kwargs) + self.right = openmc.XPlane(cright, **kwargs) + self.left = openmc.XPlane(cleft, **kwargs) elif axis == 'x': - coord_map = [2,0,1] - self.top = openmc.ZPlane(z0=ctop, **kwargs) - self.bottom = openmc.ZPlane(z0=cbottom, **kwargs) - self.right = openmc.YPlane(y0=cright, **kwargs) - self.left = openmc.YPlane(y0=cleft, **kwargs) + coord_map = [2, 0, 1] + self.top = openmc.ZPlane(ctop, **kwargs) + self.bottom = openmc.ZPlane(cbottom, **kwargs) + self.right = openmc.YPlane(cright, **kwargs) + self.left = openmc.YPlane(cleft, **kwargs) # Put our coordinates in (x,y,z) order - calibrated_points = [] for p in points: - calibrated_points += [p[coord_map]] + p[:] = p[coord_map] - p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points + #p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, **kwargs) @@ -177,7 +177,6 @@ class IsogonalOctagon(CompositeSurface): self.upper_left = openmc.Plane.from_points(-p1_lr, -p2_lr, -p3_lr, **kwargs) - def __neg__(self): region1 = -self.top & +self.bottom & -self.right & +self.left if self._axis == 'y': @@ -189,7 +188,6 @@ class IsogonalOctagon(CompositeSurface): return region1 & region2 - def __pos__(self): region1 = +self.top | -self.bottom | +self.right | -self.left if self._axis == 'y': diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index c2620a92ab..0668e82acb 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -160,9 +160,9 @@ def test_cone_one_sided(axis, point_pos, point_neg, ll_true): ] ) def test_isogonal_octagon(axis, plane_tb, plane_lr, axis_idx): - center = np.array([0.,0.]) - point_pos = np.array([0.8,0.8]) - point_neg = np.array([0.7,0.7]) + center = np.array([0., 0.]) + point_pos = np.array([0.8, 0.8]) + point_neg = np.array([0.7, 0.7]) r1 = 1. r2 = 1. plane_top_bottom = getattr(openmc, plane_tb + "Plane") @@ -221,4 +221,3 @@ def test_isogonal_octagon(axis, plane_tb, plane_lr, axis_idx): repr(s) - From 0a3ac3dea129574fc0d360bf79260de6bafa4977 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 5 Apr 2022 10:11:41 -0500 Subject: [PATCH 13/20] switch ordering of coord_map in the y-axis case, remove unneeded if-statements, update docstring --- openmc/model/surface_composite.py | 46 ++++++++++++------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 7a92a69ef3..25033ac4b4 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -57,7 +57,7 @@ class IsogonalOctagon(CompositeSurface): """Infinite isogonal octagon composite surface An isogonal octagon is composed of eight planar surfaces. The prism is - parallel to the x, y, or z axis. The remaining two axes (y and z, x and z, + parallel to the x, y, or z axis. The remaining two axes (y and z, z and x, or x and y) serve as a basis for constructing the surfaces. Two surfaces are parallel to the first basis axis, two surfaces are parallel to the second basis axis, and the remaining four surfaces intersect both @@ -71,7 +71,7 @@ class IsogonalOctagon(CompositeSurface): ---------- center : iterable of float Coordinate for the central axis of the octagon in the - (y, z), (x, z), or (x, y) basis. + (y, z), (z, x), or (x, y) basis. r1 : float Half-width of octagon across its basis axis-parallel sides in units of cm. Assumed to be less than :math:`r_2\sqrt{2}`. @@ -85,13 +85,13 @@ class IsogonalOctagon(CompositeSurface): Attributes ---------- - top : openmc.ZPlane or openmc.YPlane + top : openmc.ZPlane, openmc.XPlane, or openmc.YPlane Top planar surface of octagon - bottom : openmc.ZPlane or openmc.YPlane + bottom : openmc.ZPlane, openmc.XPlane, or openmc.YPlane Bottom planar surface of octagon - right: openmc.YPlane or openmc.XPlane + right: openmc.YPlane, openmc.ZPlane, or openmc.XPlane Right planar surface of octagon - left: openmc.YPlane or openmc.XPlane + left: openmc.YPlane, openmc.ZPlane, or openmc.XPlane Left planar surface of octagon upper_right : openmc.Plane Upper right planar surface of octagon @@ -150,11 +150,11 @@ class IsogonalOctagon(CompositeSurface): self.right = openmc.XPlane(cright, **kwargs) self.left = openmc.XPlane(cleft, **kwargs) elif axis == 'y': - coord_map = [0, 2, 1] - self.top = openmc.ZPlane(ctop, **kwargs) - self.bottom = openmc.ZPlane(cbottom, **kwargs) - self.right = openmc.XPlane(cright, **kwargs) - self.left = openmc.XPlane(cleft, **kwargs) + coord_map = [1, 2, 0] + self.top = openmc.XPlane(ctop, **kwargs) + self.bottom = openmc.XPlane(cbottom, **kwargs) + self.right = openmc.ZPlane(cright, **kwargs) + self.left = openmc.ZPlane(cleft, **kwargs) elif axis == 'x': coord_map = [2, 0, 1] self.top = openmc.ZPlane(ctop, **kwargs) @@ -178,26 +178,14 @@ class IsogonalOctagon(CompositeSurface): **kwargs) def __neg__(self): - region1 = -self.top & +self.bottom & -self.right & +self.left - if self._axis == 'y': - region2 = -self.upper_right & -self.lower_right & \ - +self.lower_left & +self.upper_left - else: - region2 = +self.upper_right & +self.lower_right & \ - -self.lower_left & -self.upper_left - - return region1 & region2 + return -self.top & +self.bottom & -self.right & +self.left & \ + +self.upper_right & +self.lower_right & -self.lower_left & \ + -self.upper_left def __pos__(self): - region1 = +self.top | -self.bottom | +self.right | -self.left - if self._axis == 'y': - region2 = +self.upper_right | +self.lower_right | \ - -self.lower_left | -self.upper_left - else: - region2 = -self.upper_right | -self.lower_right | \ - +self.lower_left | +self.upper_left - - return region1 | region2 + return +self.top | -self.bottom | +self.right | -self.left | \ + -self.upper_right | -self.lower_right | +self.lower_left | \ + +self.upper_left class RightCircularCylinder(CompositeSurface): From a289cb73977abdbd15b9f50202f78d59ffd24025 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 5 Apr 2022 10:14:50 -0500 Subject: [PATCH 14/20] change warnings to exceptions; remove cruft comment --- openmc/model/surface_composite.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 25033ac4b4..6ecdd31527 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -4,7 +4,6 @@ from math import sqrt from numpy import array import openmc -import warnings from openmc.checkvalue import check_greater_than, check_value class CompositeSurface(ABC): @@ -74,10 +73,10 @@ class IsogonalOctagon(CompositeSurface): (y, z), (z, x), or (x, y) basis. r1 : float Half-width of octagon across its basis axis-parallel sides in units - of cm. Assumed to be less than :math:`r_2\sqrt{2}`. + of cm. Must be less than :math:`r_2\sqrt{2}`. r2 : float Half-width of octagon across its basis axis intersecting sides in - units of cm. Assumed to be less than :math:`r_1\sqrt{2}`. + units of cm. Must be less than than :math:`r_1\sqrt{2}`. axis : {'x', 'y', 'z'} Central axis of octagon. Defaults to 'z' **kwargs @@ -122,11 +121,11 @@ class IsogonalOctagon(CompositeSurface): # Side lengths if r2 > r1 * sqrt(2): - warnings.warn(f'r2 is greater than sqrt(2) * r1. Octagon may' + \ - ' be erroneous.') + raise ValueError(f'r2 is greater than sqrt(2) * r1. Octagon' + \ + ' may be erroneous.') if r1 > r2 * sqrt(2): - warnings.warn(f'r1 is greater than sqrt(2) * r2. Octagon may' + \ - ' be erroneous.') + raise ValueError(f'r1 is greater than sqrt(2) * r2. Octagon' + \ + ' may be erroneous.') L_perp_ax1 = (r2 * sqrt(2) - r1) * 2 L_perp_ax2 = (r1 * sqrt(2) - r2) * 2 @@ -166,8 +165,6 @@ class IsogonalOctagon(CompositeSurface): for p in points: p[:] = p[coord_map] - #p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr = calibrated_points - self.upper_right = openmc.Plane.from_points(p1_ur, p2_ur, p3_ur, **kwargs) self.lower_right = openmc.Plane.from_points(p1_lr, p2_lr, p3_lr, From c1008a0d0fdc250b86b3906b50cdcb06c3643ade Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 5 Apr 2022 10:16:11 -0500 Subject: [PATCH 15/20] update unit test to match new basis for y case --- tests/unit_tests/test_surface_composite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index 0668e82acb..3595c59e67 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -155,7 +155,7 @@ def test_cone_one_sided(axis, point_pos, point_neg, ll_true): @pytest.mark.parametrize( "axis, plane_tb, plane_lr, axis_idx", [ ("x", "Z", "Y", 0), - ("y", "Z", "X", 1), + ("y", "X", "Z", 1), ("z", "Y", "X", 2), ] ) From 5cbf23b48617c444b252bc54229fbdc5cbd7f17c Mon Sep 17 00:00:00 2001 From: yardasol <45364492+yardasol@users.noreply.github.com> Date: Tue, 5 Apr 2022 10:25:37 -0500 Subject: [PATCH 16/20] Remove unneeded attribute --- openmc/model/surface_composite.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index 6ecdd31527..c61d3a3f95 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -109,7 +109,6 @@ class IsogonalOctagon(CompositeSurface): 'lower_right', 'upper_left') def __init__(self, center, r1, r2, axis='z', **kwargs): - self._axis = axis c1, c2 = center # Coords for axis-perpendicular planes From 60608ade3c89c295eeb97e258be143aaabb4a2fd Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 7 Apr 2022 10:12:01 -0500 Subject: [PATCH 17/20] apply @paulromano's suggestions --- openmc/model/surface_composite.py | 21 ++++++++++----------- tests/unit_tests/test_surface_composite.py | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index c61d3a3f95..aef379d225 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from copy import copy from math import sqrt -from numpy import array +import numpy as np import openmc from openmc.checkvalue import check_greater_than, check_value @@ -88,9 +88,9 @@ class IsogonalOctagon(CompositeSurface): Top planar surface of octagon bottom : openmc.ZPlane, openmc.XPlane, or openmc.YPlane Bottom planar surface of octagon - right: openmc.YPlane, openmc.ZPlane, or openmc.XPlane + right : openmc.YPlane, openmc.ZPlane, or openmc.XPlane Right planar surface of octagon - left: openmc.YPlane, openmc.ZPlane, or openmc.XPlane + left : openmc.YPlane, openmc.ZPlane, or openmc.XPlane Left planar surface of octagon upper_right : openmc.Plane Upper right planar surface of octagon @@ -126,17 +126,16 @@ class IsogonalOctagon(CompositeSurface): raise ValueError(f'r1 is greater than sqrt(2) * r2. Octagon' + \ ' may be erroneous.') - L_perp_ax1 = (r2 * sqrt(2) - r1) * 2 - L_perp_ax2 = (r1 * sqrt(2) - r2) * 2 + L_perp_ax1 = (r2 * sqrt(2) - r1) # Coords for quadrant planes - p1_ur = array([L_perp_ax1/2, r1, 0.]) - p2_ur = array([r1, L_perp_ax1/2, 0.]) - p3_ur = array([r1, L_perp_ax1/2, 1.]) + p1_ur = np.array([L_perp_ax1, r1, 0.]) + p2_ur = np.array([r1, L_perp_ax1, 0.]) + p3_ur = np.array([r1, L_perp_ax1, 1.]) - p1_lr = array([r1, -L_perp_ax1/2, 0.]) - p2_lr = array([L_perp_ax1/2, -r1, 0.]) - p3_lr = array([L_perp_ax1/2, -r1, 1.]) + p1_lr = np.array([r1, -L_perp_ax1, 0.]) + p2_lr = np.array([L_perp_ax1, -r1, 0.]) + p3_lr = np.array([L_perp_ax1, -r1, 1.]) points = [p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr] diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index 3595c59e67..20670efcdb 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -191,10 +191,10 @@ def test_isogonal_octagon(axis, plane_tb, plane_lr, axis_idx): # Check bounding box center = np.insert(center, axis_idx, np.inf) - xmax,ymax,zmax = center + r1 + xmax, ymax, zmax = center + r1 coord_min = center - r1 coord_min[axis_idx] *= -1 - xmin,ymin,zmin = coord_min + xmin, ymin, zmin = coord_min ll, ur = (+s).bounding_box assert np.all(np.isinf(ll)) assert np.all(np.isinf(ur)) From 018296d463dc8d0da0d34e760181bdca270a4f90 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 7 Apr 2022 10:16:03 -0500 Subject: [PATCH 18/20] added unit test for checking invalud r1,r2 combos --- tests/unit_tests/test_surface_composite.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index 20670efcdb..0b19431375 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -217,6 +217,12 @@ def test_isogonal_octagon(axis, plane_tb, plane_lr, axis_idx): assert ur_t == pytest.approx(ur + t) assert ll_t == pytest.approx(ll + t) + # Check invalid r1, r2 combinations + with pytest.raises(ValueError): + openmc.model.IsogonalOctagon(center, r1=1.0, r2=10.) + with pytest.rasies(ValueError): + openmc.model.IsogonalOctagon(center, r1=10., r2=1.) + # Make sure repr works repr(s) From 16b894ffd84dd7dd4b7195396f94d4eff21cadf5 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 7 Apr 2022 10:16:16 -0500 Subject: [PATCH 19/20] rename internal variable --- openmc/model/surface_composite.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index aef379d225..a34ce98cc9 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -126,16 +126,16 @@ class IsogonalOctagon(CompositeSurface): raise ValueError(f'r1 is greater than sqrt(2) * r2. Octagon' + \ ' may be erroneous.') - L_perp_ax1 = (r2 * sqrt(2) - r1) + L_basis_ax = (r2 * sqrt(2) - r1) # Coords for quadrant planes - p1_ur = np.array([L_perp_ax1, r1, 0.]) - p2_ur = np.array([r1, L_perp_ax1, 0.]) - p3_ur = np.array([r1, L_perp_ax1, 1.]) + p1_ur = np.array([L_basis_ax, r1, 0.]) + p2_ur = np.array([r1, L_basis_ax, 0.]) + p3_ur = np.array([r1, L_basis_ax, 1.]) - p1_lr = np.array([r1, -L_perp_ax1, 0.]) - p2_lr = np.array([L_perp_ax1, -r1, 0.]) - p3_lr = np.array([L_perp_ax1, -r1, 1.]) + p1_lr = np.array([r1, -L_basis_ax, 0.]) + p2_lr = np.array([L_basis_ax, -r1, 0.]) + p3_lr = np.array([L_basis_ax, -r1, 1.]) points = [p1_ur, p2_ur, p3_ur, p1_lr, p2_lr, p3_lr] From aa233c80ddcec7df01c4883c3e54f11465e9a4e3 Mon Sep 17 00:00:00 2001 From: yardasol <45364492+yardasol@users.noreply.github.com> Date: Thu, 7 Apr 2022 11:15:25 -0500 Subject: [PATCH 20/20] fix typo in new unit test --- tests/unit_tests/test_surface_composite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_surface_composite.py b/tests/unit_tests/test_surface_composite.py index 0b19431375..14a7c8d3dd 100644 --- a/tests/unit_tests/test_surface_composite.py +++ b/tests/unit_tests/test_surface_composite.py @@ -220,7 +220,7 @@ def test_isogonal_octagon(axis, plane_tb, plane_lr, axis_idx): # Check invalid r1, r2 combinations with pytest.raises(ValueError): openmc.model.IsogonalOctagon(center, r1=1.0, r2=10.) - with pytest.rasies(ValueError): + with pytest.raises(ValueError): openmc.model.IsogonalOctagon(center, r1=10., r2=1.) # Make sure repr works