From a5c51aa71532297afca8c0f9577bac2bf8153664 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Wed, 3 Feb 2016 17:20:12 -0500 Subject: [PATCH] Added slice method to ScatterMatrixXS along with new Tally.contains_filter(...) --- openmc/mgxs/mgxs.py | 54 +++++++++++++++++++++++++++++++++++++++++++-- openmc/tallies.py | 26 ++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index b199933863..d4d949d1b2 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -930,8 +930,11 @@ class MGXS(object): # Slice each of the tallies across nuclides and energy groups for tally_type, tally in slice_xs.tallies.items(): slice_nuclides = [nuc for nuc in nuclides if nuc in tally.nuclides] - tally_slice = tally.get_slice(filters=filters, - filter_bins=filter_bins, nuclides=slice_nuclides) + if len(groups) != 0 and tally.contains_filter('energy'): + tally_slice = tally.get_slice(filters=filters, + filter_bins=filter_bins, nuclides=slice_nuclides) + else: + tally_slice = tally.get_slice(nuclides=slice_nuclides) slice_xs.tallies[tally_type] = tally_slice # Assign sliced energy group structure to sliced MGXS @@ -1822,6 +1825,53 @@ class ScatterMatrixXS(MGXS): cv.check_value('correction', correction, ('P0', None)) self._correction = correction + def get_slice(self, nuclides=[], groups=[]): + """Build a sliced MGXS for the specified nuclides and energy groups. + + This method constructs a new MGXS to encapsulate a subset of the data + represented by this MGXS. The subset of data to include in the tally + slice is determined by the nuclides and energy groups specified in + the input parameters. + + Parameters + ---------- + nuclides : list of str + A list of nuclide name strings + (e.g., ['U-235', 'U-238']; default is []) + groups : list of Integral + A list of energy group indices starting at 1 for the high energies + (e.g., [1, 2, 3]; default is []) + + Returns + ------- + MGXS + A new tally which encapsulates the subset of data requested for the + nuclide(s) and/or energy group(s) requested in the parameters. + + """ + + slice_xs = super(ScatterMatrixXS, self).get_slice(nuclides, groups) + slice_xs._rxn_rate_tally = None + slice_xs._xs_tally = None + + # Build lists of filters and filter bins to slice + if len(groups) != 0: + filter_bins = [] + for group in groups: + group_bounds = self.energy_groups.get_group_bounds(group) + filter_bins.append(group_bounds) + filter_bins = [tuple(filter_bins)] + + # Slice each of the tallies across nuclides and energy groups + for tally_type, tally in slice_xs.tallies.items(): + if tally.contains_filter('energyout'): + tally_slice = tally.get_slice(filters=['energyout'], + filter_bins=filter_bins) + slice_xs.tallies[tally_type] = tally_slice + + slice_xs.sparse = self.sparse + return slice_xs + def get_xs(self, in_groups='all', out_groups='all', subdomains='all', nuclides='all', xs_type='macro', order_groups='increasing', value='mean'): diff --git a/openmc/tallies.py b/openmc/tallies.py index 1ad62e33ab..66b99cb00c 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -846,6 +846,32 @@ class Tally(object): return element + def contains_filter(self, filter_type): + """Looks for a filter in the tally that matches a specified type + + Parameters + ---------- + filter_type : str + Type of the filter, e.g. 'mesh' + + Returns + ------- + filter_found : bool + True if the tally contains a filter of the requested type; + otherwise false + + """ + + filter_found = False + + # Look through all of this Tally's Filters for the type requested + for test_filter in self.filters: + if test_filter.type == filter_type: + filter_found = True + break + + return filter_found + def find_filter(self, filter_type): """Return a filter in the tally that matches a specified type