diff --git a/openmc/filter_expansion.py b/openmc/filter_expansion.py index b9860846fda..f8e677578f1 100644 --- a/openmc/filter_expansion.py +++ b/openmc/filter_expansion.py @@ -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.