Skip to content

Commit

Permalink
fix expansion filter merging (#2882)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
  • Loading branch information
gridley and paulromano committed Feb 29, 2024
1 parent a8f7a61 commit 02c0a09
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions openmc/filter_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ def from_xml_element(cls, elem, **kwargs):
order = int(elem.find('order').text)
return cls(order, filter_id=filter_id)

def merge(self, other):
"""Merge this filter with another.
This overrides the behavior of the parent Filter class, since its
merging technique is to take the union of the set of bins of each
filter. That technique does not apply to expansion filters, since the
argument should be the maximum filter order rather than the list of all
bins.
Parameters
----------
other : openmc.Filter
Filter to merge with
Returns
-------
merged_filter : openmc.Filter
Filter resulting from the merge
"""

if not self.can_merge(other):
msg = f'Unable to merge "{type(self)}" with "{type(other)}"'
raise ValueError(msg)

# Create a new filter with these bins and a new auto-generated ID
return type(self)(max(self.order, other.order))


class LegendreFilter(ExpansionFilter):
r"""Score Legendre expansion moments up to specified order.
Expand Down

0 comments on commit 02c0a09

Please sign in to comment.