diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index ca95be58ad..b79780ffc2 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -691,11 +691,11 @@ class MGXS(object): # Find, slice and store Tallies from StatePoint # The tally slicing is needed if tally merging was used for tally_type, tally in self.tallies.items(): - sp_tally = statepoint.get_tally(tally.scores, tally.filters, - tally.nuclides, - estimator=tally.estimator) - sp_tally = sp_tally.get_slice(tally.scores, filters, - filter_bins, tally.nuclides) + sp_tally = statepoint.get_tally( + tally.scores, tally.filters, tally.nuclides, + estimator=tally.estimator, exact=True) + sp_tally = sp_tally.get_slice( + tally.scores, filters, filter_bins, tally.nuclides) sp_tally.sparse = self.sparse self.tallies[tally_type] = sp_tally diff --git a/openmc/statepoint.py b/openmc/statepoint.py index d5dd7bc1e7..83dd148fe7 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -497,13 +497,17 @@ class StatePoint(object): self.tallies[tally_id].sparse = self.sparse def get_tally(self, scores=[], filters=[], nuclides=[], - name=None, id=None, estimator=None): + name=None, id=None, estimator=None, exact=False): """Finds and returns a Tally object with certain properties. This routine searches the list of Tallies and returns the first Tally found which satisfies all of the input parameters. - NOTE: The input parameters do not need to match the complete Tally - specification and may only represent a subset of the Tally's properties. + + NOTE: If the "exact" parameter is False (default), the input parameters + do not need to match the complete Tally specification and may only + represent a subset of the Tally's properties. If the "exact" parameter + is True then the scores, filters, nuclides and estimator parameters + must precisely match those of any matching Tally. Parameters ---------- @@ -519,6 +523,9 @@ class StatePoint(object): The id specified for the Tally (default is None). estimator: str, optional The type of estimator ('tracklength', 'analog'; default is None). + exact : bool + Whether to strictly enforce the match between the parameters and + the returned tally Returns ------- @@ -547,9 +554,18 @@ class StatePoint(object): continue # Determine if Tally has queried estimator - if estimator and not estimator == test_tally.estimator: + if (estimator or exact) and estimator != test_tally.estimator: continue + # The number of filters, nuclides and scores must exactly match + if exact: + if len(scores) != test_tally.num_scores: + continue + if len(nuclides) != test_tally.num_nuclides: + continue + if len(filters) != test_tally.num_filters: + continue + # Determine if Tally has the queried score(s) if scores: contains_scores = True