mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Fix test_tally_slice_merge
This commit is contained in:
parent
de84f3989b
commit
60c14046a5
4 changed files with 22 additions and 21 deletions
|
|
@ -620,7 +620,8 @@ class AggregateFilter(object):
|
|||
|
||||
def __init__(self, aggregate_filter=None, bins=None, aggregate_op=None):
|
||||
|
||||
self._type = '{0}({1})'.format(aggregate_op, aggregate_filter.type)
|
||||
self._type = '{0}({1})'.format(aggregate_op,
|
||||
aggregate_filter.short_name.lower())
|
||||
self._bins = None
|
||||
self._stride = None
|
||||
|
||||
|
|
|
|||
|
|
@ -664,8 +664,8 @@ class EnergyFilter(Filter):
|
|||
hi_bins = np.tile(hi_bins, tile_factor)
|
||||
|
||||
# Add the new energy columns to the DataFrame.
|
||||
df.loc[:, self.type + ' low [MeV]'] = lo_bins
|
||||
df.loc[:, self.type + ' high [MeV]'] = hi_bins
|
||||
df.loc[:, self.short_name.lower() + ' low [MeV]'] = lo_bins
|
||||
df.loc[:, self.short_name.lower() + ' high [MeV]'] = hi_bins
|
||||
|
||||
return df
|
||||
|
||||
|
|
@ -885,7 +885,7 @@ class DistribcellFilter(Filter):
|
|||
filter_bins = np.repeat(filter_bins, self.stride)
|
||||
tile_factor = data_size / len(filter_bins)
|
||||
filter_bins = np.tile(filter_bins, tile_factor)
|
||||
df = pd.DataFrame({self.type : filter_bins})
|
||||
df = pd.DataFrame({self.short_name.lower() : filter_bins})
|
||||
|
||||
# If OpenCG level info DataFrame was created, concatenate
|
||||
# with DataFrame of distribcell instance IDs
|
||||
|
|
|
|||
|
|
@ -2974,11 +2974,13 @@ class Tally(object):
|
|||
|
||||
for filter_bin in filter_bins[i]:
|
||||
bin_index = find_filter.get_bin_index(filter_bin)
|
||||
if filter_type in ['energy', 'energyout']:
|
||||
if filter_type in [openmc.filter.EnergyFilter,
|
||||
openmc.filter.EnergyoutFilter]:
|
||||
bin_indices.extend([bin_index])
|
||||
bin_indices.extend([bin_index, bin_index+1])
|
||||
num_bins += 1
|
||||
elif filter_type in ['distribcell', 'mesh']:
|
||||
elif filter_type in [openmc.filter.DistribcellFilter,
|
||||
openmc.filter.MeshFilter]:
|
||||
bin_indices = [0]
|
||||
num_bins = find_filter.num_bins
|
||||
else:
|
||||
|
|
@ -3010,9 +3012,8 @@ class Tally(object):
|
|||
scores : list of str
|
||||
A list of one or more score strings to sum across
|
||||
(e.g., ['absorption', 'nu-fission']; default is [])
|
||||
filter_type : str
|
||||
A filter type string (e.g., 'cell', 'energy') corresponding to the
|
||||
filter bins to sum across
|
||||
filter_type : openmc.filter.FilterMeta
|
||||
Type of the filter, e.g. MeshFilter
|
||||
filter_bins : Iterable of int or tuple
|
||||
A list of the filter bins corresponding to the filter_type parameter
|
||||
Each bin in the list is the integer ID for 'material', 'surface',
|
||||
|
|
@ -3050,14 +3051,14 @@ class Tally(object):
|
|||
std_dev = self.get_reshaped_data(value='std_dev')
|
||||
|
||||
# Sum across any filter bins specified by the user
|
||||
if filter_type in _FILTER_TYPES:
|
||||
if isinstance(filter_type, openmc.filter.FilterMeta):
|
||||
find_filter = self.find_filter(filter_type)
|
||||
|
||||
# If user did not specify filter bins, sum across all bins
|
||||
if len(filter_bins) == 0:
|
||||
bin_indices = np.arange(find_filter.num_bins)
|
||||
|
||||
if filter_type == 'distribcell':
|
||||
if isinstance(find_filter, openmc.filter.DistribcellFilter):
|
||||
filter_bins = np.arange(find_filter.num_bins)
|
||||
else:
|
||||
num_bins = find_filter.num_bins
|
||||
|
|
@ -3071,7 +3072,7 @@ class Tally(object):
|
|||
|
||||
# Sum across the bins in the user-specified filter
|
||||
for i, self_filter in enumerate(self.filters):
|
||||
if self_filter.type == filter_type:
|
||||
if isinstance(self_filter, filter_type):
|
||||
mean = np.take(mean, indices=bin_indices, axis=i)
|
||||
std_dev = np.take(std_dev, indices=bin_indices, axis=i)
|
||||
mean = np.sum(mean, axis=i, keepdims=True)
|
||||
|
|
@ -3158,9 +3159,8 @@ class Tally(object):
|
|||
scores : list of str
|
||||
A list of one or more score strings to average across
|
||||
(e.g., ['absorption', 'nu-fission']; default is [])
|
||||
filter_type : str
|
||||
A filter type string (e.g., 'cell', 'energy') corresponding to the
|
||||
filter bins to average across
|
||||
filter_type : openmc.filter.FilterMeta
|
||||
Type of the filter, e.g. MeshFilter
|
||||
filter_bins : Iterable of int or tuple
|
||||
A list of the filter bins corresponding to the filter_type parameter
|
||||
Each bin in the list is the integer ID for 'material', 'surface',
|
||||
|
|
@ -3198,14 +3198,14 @@ class Tally(object):
|
|||
std_dev = self.get_reshaped_data(value='std_dev')
|
||||
|
||||
# Average across any filter bins specified by the user
|
||||
if filter_type in _FILTER_TYPES:
|
||||
if isinstnace(filter_type, openmc.filter.FilterMeta):
|
||||
find_filter = self.find_filter(filter_type)
|
||||
|
||||
# If user did not specify filter bins, average across all bins
|
||||
if len(filter_bins) == 0:
|
||||
bin_indices = np.arange(find_filter.num_bins)
|
||||
|
||||
if filter_type == 'distribcell':
|
||||
if isinstance(find_filter, openmc.filter.DistribcellFilter):
|
||||
filter_bins = np.arange(find_filter.num_bins)
|
||||
else:
|
||||
num_bins = find_filter.num_bins
|
||||
|
|
|
|||
|
|
@ -144,10 +144,10 @@ class TallySliceMergeTestHarness(PyAPITestHarness):
|
|||
distribcell_tally = sp.get_tally(name='distribcell tally')
|
||||
|
||||
# Sum up a few subdomains from the distribcell tally
|
||||
sum1 = distribcell_tally.summation(filter_type='distribcell',
|
||||
sum1 = distribcell_tally.summation(filter_type=openmc.DistribcellFilter,
|
||||
filter_bins=[0,100,2000,30000])
|
||||
# Sum up a few subdomains from the distribcell tally
|
||||
sum2 = distribcell_tally.summation(filter_type='distribcell',
|
||||
sum2 = distribcell_tally.summation(filter_type=openmc.DistribcellFilter,
|
||||
filter_bins=[500,5000,50000])
|
||||
|
||||
# Merge the distribcell tally slices
|
||||
|
|
@ -161,10 +161,10 @@ class TallySliceMergeTestHarness(PyAPITestHarness):
|
|||
mesh_tally = sp.get_tally(name='mesh tally')
|
||||
|
||||
# Sum up a few subdomains from the mesh tally
|
||||
sum1 = mesh_tally.summation(filter_type='mesh',
|
||||
sum1 = mesh_tally.summation(filter_type=openmc.MeshFilter,
|
||||
filter_bins=[(1,1,1), (1,2,1)])
|
||||
# Sum up a few subdomains from the mesh tally
|
||||
sum2 = mesh_tally.summation(filter_type='mesh',
|
||||
sum2 = mesh_tally.summation(filter_type=openmc.MeshFilter,
|
||||
filter_bins=[(2,1,1), (2,2,1)])
|
||||
|
||||
# Merge the mesh tally slices
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue