Skip to content

Commit

Permalink
SurfaceFilter accept CompositeSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeprieto committed Oct 15, 2024
1 parent c418c32 commit 9f03bcc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
24 changes: 22 additions & 2 deletions openmc/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def from_xml_element(cls, elem, **kwargs):
return cls(cell_instances, filter_id=filter_id)


class SurfaceFilter(WithIDFilter):
class SurfaceFilter(Filter):
"""Filters particles by surface crossing
Parameters
Expand All @@ -728,7 +728,27 @@ class SurfaceFilter(WithIDFilter):
The number of filter bins
"""
expected_type = Surface


def __init__(self, bins, filter_id=None):
if(type(bins)==list or isinstance(bins, np.ndarray)):
bins = np.atleast_1d(bins)
else:
bins = np.atleast_1d(bins.component_surfaces)

# Make sure bins are either integers or appropriate objects
cv.check_iterable_type('filter bins', bins,
(Integral, Surface))

# Extract ID values
bins = np.array([b if isinstance(b, Integral) else b.id
for b in bins])
super().__init__(bins, filter_id)

def check_bins(self, bins):
# Check the bin values.
for edge in bins:
cv.check_greater_than('filter bin', edge, 0, equality=True)


class ParticleFilter(Filter):
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def test_SurfaceFilter_CompositeSurface(run_in_tmpdir, box_model):
box_model.geometry.root_universe = openmc.Universe(cells=[c])

tally = openmc.Tally()
tally.filters = [openmc.SurfaceFilter(box.get_surfaces())]
tally.filters = [openmc.SurfaceFilter(box)]
tally.scores = ['current']

box_model.tallies = [tally]
Expand All @@ -316,14 +316,14 @@ def test_SurfaceFilter_CompositeSurface(run_in_tmpdir, box_model):
with openmc.StatePoint(sp_name) as sp:
current = sp.tallies[tally.id]
assert len(current.get_pandas_dataframe()['surface']) == 4
assert np.all(current.get_pandas_dataframe()['surface'] == box.get_id_surfaces())
assert np.all(current.get_pandas_dataframe()['surface'] == box.component_surface_ids)

box = openmc.model.RectangularParallelepiped(*[-10, 10]*3, boundary_type='vacuum')
c = openmc.Cell(fill=m, region=-box)
box_model.geometry.root_universe = openmc.Universe(cells=[c])

tally = openmc.Tally()
tally.filters = [openmc.SurfaceFilter(box.get_surfaces())]
tally.filters = [openmc.SurfaceFilter(box)]
tally.scores = ['current']

box_model.tallies = [tally]
Expand All @@ -333,4 +333,4 @@ def test_SurfaceFilter_CompositeSurface(run_in_tmpdir, box_model):
with openmc.StatePoint(sp_name) as sp:
current = sp.tallies[tally.id]
assert len(current.get_pandas_dataframe()['surface']) == 6
assert np.all(current.get_pandas_dataframe()['surface'] == box.get_id_surfaces())
assert np.all(current.get_pandas_dataframe()['surface'] == box.component_surface_ids)

0 comments on commit 9f03bcc

Please sign in to comment.