Skip to content

Commit 8168125

Browse files
Convert degenerate torus (A=0, B=C) to sphere (#63)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 243a994 commit 8168125

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/openmc_mcnp_adapter/openmc_conversion.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,17 @@ def flip_sense(surf):
301301
a, b, c, d, e, f, g, h, j, k = coeffs
302302
surf = openmc.Quadric(surface_id=s['id'], a=a, b=b, c=c, d=d, e=e,
303303
f=f, g=g, h=h, j=j, k=k)
304-
elif s['mnemonic'] == 'tx':
304+
elif s['mnemonic'] in ('tx', 'ty', 'tz'):
305305
x0, y0, z0, a, b, c = coeffs
306-
surf = openmc.XTorus(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
307-
elif s['mnemonic'] == 'ty':
308-
x0, y0, z0, a, b, c = coeffs
309-
surf = openmc.YTorus(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
310-
elif s['mnemonic'] == 'tz':
311-
x0, y0, z0, a, b, c = coeffs
312-
surf = openmc.ZTorus(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
306+
if isclose(a, 0.0, abs_tol=1e-12) and isclose(b, c):
307+
warnings.warn(
308+
f"Degenerate torus surface {s['id']} (A=0, B=C) converted "
309+
f"to an openmc.Sphere of radius {b}."
310+
)
311+
surf = openmc.Sphere(surface_id=s['id'], x0=x0, y0=y0, z0=z0, r=b)
312+
else:
313+
cls = getattr(openmc, f"{s['mnemonic'][1].upper()}Torus")
314+
surf = cls(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
313315
elif s['mnemonic'] in ('x', 'y', 'z'):
314316
axis = s['mnemonic'].upper()
315317
cls_plane = getattr(openmc, f'{axis}Plane')

tests/test_surfaces.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
RectangularParallelepiped, RightCircularCylinder, ConicalFrustum, \
88
XConeOneSided, YConeOneSided, ZConeOneSided
99
from openmc_mcnp_adapter import mcnp_str_to_model, get_openmc_surfaces
10-
from pytest import approx, mark, raises
10+
from pytest import approx, mark, raises, warns
1111

1212

1313
def convert_surface(mnemonic: str, params: Sequence[float]) -> openmc.Surface:
@@ -323,6 +323,14 @@ def test_torus(mnemonic, expected_type):
323323
assert getattr(surf, name) == approx(val)
324324

325325

326+
@mark.parametrize("mnemonic", ["tx", "ty", "tz"])
327+
def test_torus_degenerate_sphere(mnemonic):
328+
with warns(UserWarning, match="Degenerate torus"):
329+
surf = convert_surface(mnemonic, (1.0, 2.0, 3.0, 0.0, 0.5, 0.5))
330+
assert isinstance(surf, openmc.Sphere)
331+
assert (surf.x0, surf.y0, surf.z0, surf.r) == approx((1.0, 2.0, 3.0, 0.5))
332+
333+
326334
@mark.parametrize(
327335
"mnemonic, params, expected_type, attr, value",
328336
[

0 commit comments

Comments
 (0)