Skip to content

Commit

Permalink
Apply suggestions from @paulromano code review
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
  • Loading branch information
yardasol and paulromano committed Jul 14, 2023
1 parent 2023006 commit e9cb99c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 68 deletions.
12 changes: 8 additions & 4 deletions openmc/model/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,14 @@ def rectangular_prism(width, height, axis='z', origin=(0., 0.),
args[x2 + '0'] = origin[1] + height/2 - corner_radius
x1_max_x2_max = cyl(name='{} max {} max'.format(x1, x2), **args)

x1_min = _plane(x1, 'min', -width/2 + origin[0] + corner_radius)
x1_max = _plane(x1, 'max', width/2 + origin[0] - corner_radius)
x2_min = _plane(x2, 'min', -height/2 + origin[1] + corner_radius)
x2_max = _plane(x2, 'max', height/2 + origin[1] - corner_radius)
x1_min = _plane(x1, 'min', -width/2 + origin[0] + corner_radius,
boundary_type=boundary_type)
x1_max = _plane(x1, 'max', width/2 + origin[0] - corner_radius,
boundary_type=boundary_type)
x2_min = _plane(x2, 'min', -height/2 + origin[1] + corner_radius,
boundary_type=boundary_type)
x2_max = _plane(x2, 'max', height/2 + origin[1] - corner_radius,
boundary_type=boundary_type)

corners = (+x1_min_x2_min & -x1_min & -x2_min) | \
(+x1_min_x2_max & -x1_min & +x2_max) | \
Expand Down
116 changes: 53 additions & 63 deletions openmc/model/surface_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ class RightCircularCylinder(CompositeSurface):
"""
_surface_names = ('cyl', 'bottom', 'top')

def __init__(self, center_base, height, radius, axis='z', upper_fillet_radius=0., lower_fillet_radius=0., **kwargs):
def __init__(self, center_base, height, radius, axis='z',
upper_fillet_radius=0., lower_fillet_radius=0., **kwargs):
cx, cy, cz = center_base
check_greater_than('cylinder height', height, 0.0)
check_greater_than('cylinder radius', radius, 0.0)
Expand Down Expand Up @@ -440,6 +441,45 @@ def __init__(self, center_base, height, radius, axis='z', upper_fillet_radius=0.
x1, x2 = 'x', 'y'
axcoord, axcoord1, axcoord2 = 2, 0, 1

def _create_fillet_objects(axis_args, height, center_base, radius, fillet_radius, pos='upper'):
axis, x1, x2, axcoord, axcoord1, axcoord2 = axis_args
fillet_ext = height / 2 - fillet_radius
sign = 1
if pos == 'lower':
sign = -1
coord = center_base[axcoord] + (height / 2) + sign * fillet_ext

# cylinder
cyl_name = f'{pos}_min'
cylinder_args = {
x1 + '0': center_base[axcoord1],
x2 + '0': center_base[axcoord2],
'r': radius - fillet_radius
}
cls = getattr(openmc, f'{axis.upper()}Cylinder')
cyl = cls(name=f'{cyl_name} {axis}', **cylinder_args)

#torus
tor_name = f'{axis} {pos}'
tor_args = {
'a': radius - fillet_radius,
'b': fillet_radius,
'c': fillet_radius,
x1 + '0': center_base[axcoord1],
x2 + '0': center_base[axcoord2],
axis + '0': coord
}
cls = getattr(openmc, f'{axis.upper()}Torus')
torus = cls(name=tor_name, **tor_args)

# plane
p_name = f'{pos} ext'
p_args = {axis + '0': coord}
cls = getattr(openmc, f'{axis.upper()}Plane')
plane = cls(name=p_name, **p_args)

return cyl, torus, plane

if upper_fillet_radius > 0. or lower_fillet_radius > 0.:
if 'boundary_type' in kwargs:
if kwargs['boundary_type'] == 'periodic':
Expand All @@ -448,78 +488,28 @@ def __init__(self, center_base, height, radius, axis='z', upper_fillet_radius=0.

axis_args = (axis, x1, x2, axcoord, axcoord1, axcoord2)
if upper_fillet_radius > 0.:
(upper_fillet_cylinder,
upper_fillet_torus,
upper_fillet_plane) = \
self._create_fillet_objects(axis_args,
height,
center_base,
radius,
upper_fillet_radius)
self.upper_fillet_cylinder = upper_fillet_cylinder
self.upper_fillet_torus = upper_fillet_torus
self.upper_fillet_plane = upper_fillet_plane
cylinder, torus, plane = _create_fillet_objects(
axis_args, height, center_base, radius, upper_fillet_radius)
self.upper_fillet_cylinder = cylinder
self.upper_fillet_torus = torus
self.upper_fillet_plane = plane
self._surface_names += ('upper_fillet_cylinder',
'upper_fillet_torus',
'upper_fillet_plane')

if lower_fillet_radius > 0.:
(lower_fillet_cylinder,
lower_fillet_torus,
lower_fillet_plane) = \
self._create_fillet_objects(axis_args,
height,
center_base,
radius,
lower_fillet_radius,
pos='lower')
self.lower_fillet_cylinder = lower_fillet_cylinder
self.lower_fillet_torus = lower_fillet_torus
self.lower_fillet_plane = lower_fillet_plane
cylinder, torus, plane = _create_fillet_objects(
axis_args, height, center_base, radius, lower_fillet_radius,
pos='lower'
)
self.lower_fillet_cylinder = cylinder
self.lower_fillet_torus = torus
self.lower_fillet_plane = plane

self._surface_names += ('lower_fillet_cylinder',
'lower_fillet_torus',
'lower_fillet_plane')

def _create_fillet_objects(self, axis_args, height, center_base, radius, fillet_radius, pos='upper'):
axis, x1, x2, axcoord, axcoord1, axcoord2 = axis_args
fillet_ext = height / 2 - fillet_radius
sign = 1
if pos == 'lower':
sign = -1
coord = center_base[axcoord] + (height / 2) + sign * fillet_ext

# cylinder
cyl_name = f'{pos}_min'
cylinder_args = {
x1 + '0': center_base[axcoord1],
x2 + '0': center_base[axcoord2],
'r': radius - fillet_radius
}
cls = getattr(openmc, f'{axis.upper()}Cylinder')
cyl = cls(name=f'{cyl_name} {axis}', **cylinder_args)

#torus
tor_name = f'{axis} {pos}'
tor_args = {
'a': radius - fillet_radius,
'b': fillet_radius,
'c': fillet_radius,
x1 + '0': center_base[axcoord1],
x2 + '0': center_base[axcoord2],
axis + '0': coord
}
cls = getattr(openmc, f'{axis.upper()}Torus')
torus = cls(name=tor_name, **tor_args)

# plane
p_name = f'{pos} ext'
p_args = {axis + '0': coord}
cls = getattr(openmc, f'{axis.upper()}Plane')
plane = cls(name=p_name, **p_args)

return cyl, torus, plane

def _get_fillet(self):
upper_fillet = self._get_upper_fillet()
lower_fillet = self._get_lower_fillet()
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
import openmc
import openmc.lib
import pytest


Expand Down

0 comments on commit e9cb99c

Please sign in to comment.