Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/openmc_mcnp_adapter/openmc_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,17 @@ def flip_sense(surf):
a, b, c, d, e, f, g, h, j, k = coeffs
surf = openmc.Quadric(surface_id=s['id'], a=a, b=b, c=c, d=d, e=e,
f=f, g=g, h=h, j=j, k=k)
elif s['mnemonic'] == 'tx':
elif s['mnemonic'] in ('tx', 'ty', 'tz'):
x0, y0, z0, a, b, c = coeffs
surf = openmc.XTorus(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
elif s['mnemonic'] == 'ty':
x0, y0, z0, a, b, c = coeffs
surf = openmc.YTorus(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
elif s['mnemonic'] == 'tz':
x0, y0, z0, a, b, c = coeffs
surf = openmc.ZTorus(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
if isclose(a, 0.0, abs_tol=1e-12) and isclose(b, c):
warnings.warn(
f"Degenerate torus surface {s['id']} (A=0, B=C) converted "
f"to an openmc.Sphere of radius {b}."
)
surf = openmc.Sphere(surface_id=s['id'], x0=x0, y0=y0, z0=z0, r=b)
else:
cls = getattr(openmc, f"{s['mnemonic'][1].upper()}Torus")
surf = cls(surface_id=s['id'], x0=x0, y0=y0, z0=z0, a=a, b=b, c=c)
elif s['mnemonic'] in ('x', 'y', 'z'):
axis = s['mnemonic'].upper()
cls_plane = getattr(openmc, f'{axis}Plane')
Expand Down
10 changes: 9 additions & 1 deletion tests/test_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RectangularParallelepiped, RightCircularCylinder, ConicalFrustum, \
XConeOneSided, YConeOneSided, ZConeOneSided
from openmc_mcnp_adapter import mcnp_str_to_model, get_openmc_surfaces
from pytest import approx, mark, raises
from pytest import approx, mark, raises, warns


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


@mark.parametrize("mnemonic", ["tx", "ty", "tz"])
def test_torus_degenerate_sphere(mnemonic):
with warns(UserWarning, match="Degenerate torus"):
surf = convert_surface(mnemonic, (1.0, 2.0, 3.0, 0.0, 0.5, 0.5))
assert isinstance(surf, openmc.Sphere)
assert (surf.x0, surf.y0, surf.z0, surf.r) == approx((1.0, 2.0, 3.0, 0.5))


@mark.parametrize(
"mnemonic, params, expected_type, attr, value",
[
Expand Down
Loading