Skip to content

Commit fefe825

Browse files
authored
Handle reflex angles in CylinderSector (#3303)
1 parent 6ae2001 commit fefe825

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

openmc/model/surface_composite.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ def __init__(self,
135135
if theta2 <= theta1:
136136
raise ValueError('theta2 must be greater than theta1.')
137137

138+
# Determine whether the angle between theta1 and theta2 is a reflex
139+
# angle, in which case we need to use a union between the planar
140+
# half-spaces
141+
self._reflex = (theta2 - theta1 > 180.0)
142+
138143
phi1 = pi / 180 * theta1
139144
phi2 = pi / 180 * theta2
140145

@@ -169,6 +174,9 @@ def __init__(self,
169174
**kwargs)
170175
self.plane2 = openmc.Plane.from_points(p1, p2_plane2, p3_plane2,
171176
**kwargs)
177+
if axis == 'y':
178+
self.plane1.flip_normal()
179+
self.plane2.flip_normal()
172180

173181
@classmethod
174182
def from_theta_alpha(cls,
@@ -223,17 +231,11 @@ def from_theta_alpha(cls,
223231
return cls(r1, r2, theta1, theta2, center=center, axis=axis, **kwargs)
224232

225233
def __neg__(self):
226-
if isinstance(self.inner_cyl, openmc.YCylinder):
227-
return -self.outer_cyl & +self.inner_cyl & +self.plane1 & -self.plane2
234+
if self._reflex:
235+
return -self.outer_cyl & +self.inner_cyl & (-self.plane1 | +self.plane2)
228236
else:
229237
return -self.outer_cyl & +self.inner_cyl & -self.plane1 & +self.plane2
230238

231-
def __pos__(self):
232-
if isinstance(self.inner_cyl, openmc.YCylinder):
233-
return +self.outer_cyl | -self.inner_cyl | -self.plane1 | +self.plane2
234-
else:
235-
return +self.outer_cyl | -self.inner_cyl | +self.plane1 | -self.plane2
236-
237239

238240
class IsogonalOctagon(CompositeSurface):
239241
r"""Infinite isogonal octagon composite surface

tests/unit_tests/test_surface_composite.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ def test_cylinder_sector(axis, indices, center):
207207
assert point_neg[indices] in -s
208208
assert point_neg[indices] not in +s
209209

210+
# Check __contains__ for sector with reflex angle
211+
s_reflex = openmc.model.CylinderSector(
212+
r1, r2, 0., 270., center=center, axis=axis.lower())
213+
points = [
214+
np.array([c1 + r1 + d, c2 + 0.01, 0.]),
215+
np.array([c1, c2 + r1 + d, 0.]),
216+
np.array([c1 - r1 - d, c2, 0.]),
217+
np.array([c1 - 0.01, c2 - r1 - d, 0.])
218+
]
219+
for point_neg in points:
220+
assert point_neg[indices] in -s_reflex
221+
assert point_neg[indices] not in +s_reflex
222+
210223
# translate method
211224
t = uniform(-5.0, 5.0)
212225
s_t = s.translate((t, t, t))

0 commit comments

Comments
 (0)