Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix expansion filter merging #2882

Merged
merged 2 commits into from
Feb 29, 2024
Merged
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
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
Loading