updated mgxs tests

This commit is contained in:
Sam Shaner 2016-08-06 17:28:53 -04:00
parent b400045ded
commit d6ae522c2a
15 changed files with 1354 additions and 1045 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -328,16 +328,19 @@ class Library(object):
@delayed_groups.setter
def delayed_groups(self, delayed_groups):
cv.check_type('delayed groups', delayed_groups, list, int)
cv.check_greater_than('num delayed groups', len(delayed_groups), 0)
if delayed_groups != None:
# Check that the groups are within [1, MAX_DELAYED_GROUPS]
for group in delayed_groups:
cv.check_greater_than('delayed group', group, 0)
cv.check_less_than('delayed group', group,
openmc.mgxs.MAX_DELAYED_GROUPS, equality=True)
cv.check_type('delayed groups', delayed_groups, list, int)
cv.check_greater_than('num delayed groups', len(delayed_groups), 0)
self._delayed_groups = delayed_groups
# Check that the groups are within [1, MAX_DELAYED_GROUPS]
for group in delayed_groups:
cv.check_greater_than('delayed group', group, 0)
cv.check_less_than('delayed group', group,
openmc.mgxs.MAX_DELAYED_GROUPS,
equality=True)
self._delayed_groups = delayed_groups
@correction.setter
def correction(self, correction):
@ -508,7 +511,7 @@ class Library(object):
----------
domain : Material or Cell or Universe or Integral
The material, cell, or universe object of interest (or its ID)
mgxs_type : {'total', 'transport', 'nu-transport', 'absorption', 'capture', 'fission', 'nu-fission', 'kappa-fission', 'scatter', 'nu-scatter', 'scatter matrix', 'nu-scatter matrix', 'multiplicity matrix', 'nu-fission matrix', chi', 'chi-prompt', 'inverse-velocity', 'prompt-nu-fission'}
mgxs_type : {'total', 'transport', 'nu-transport', 'absorption', 'capture', 'fission', 'nu-fission', 'kappa-fission', 'scatter', 'nu-scatter', 'scatter matrix', 'nu-scatter matrix', 'multiplicity matrix', 'nu-fission matrix', chi', 'chi-prompt', 'inverse-velocity', 'prompt-nu-fission', 'delayed-nu-fission', 'chi-delayed', 'beta'}
The type of multi-group cross section object to return
Returns

View file

@ -14,6 +14,9 @@ import openmc
from openmc.mgxs import MGXS
import openmc.checkvalue as cv
if sys.version_info[0] >= 3:
basestring = str
# Supported cross section types
MDGXS_TYPES = ['delayed-nu-fission',
'chi-delayed',
@ -102,12 +105,12 @@ class MDGXS(MGXS):
are not specified by the user, all nuclides in the spatial domain
are included. This attribute is 'sum' if by_nuclide is false.
sparse : bool
Whether or not the MDGXS' tallies use SciPy's LIL sparse matrix format
Whether or not the MGXS' tallies use SciPy's LIL sparse matrix format
for compressed data storage
loaded_sp : bool
Whether or not a statepoint file has been loaded with tally data
derived : bool
Whether or not the MDGXS is merged from one or more other MDGXS
Whether or not the MGXS is merged from one or more other MGXS
hdf5_key : str
The key used to index multi-group cross sections in an HDF5 data store
@ -165,23 +168,25 @@ class MDGXS(MGXS):
@property
def num_delayed_groups(self):
if self.delayed_groups == None:
return 0
return 1
else:
return len(self.delayed_groups)
@delayed_groups.setter
def delayed_groups(self, delayed_groups):
cv.check_type('delayed groups', delayed_groups, list, int)
cv.check_greater_than('num delayed groups', len(delayed_groups), 0)
if delayed_groups != None:
# Check that the groups are within [1, MAX_DELAYED_GROUPS]
for group in delayed_groups:
cv.check_greater_than('delayed group', group, 0)
cv.check_less_than('delayed group', group, MAX_DELAYED_GROUPS,
equality=True)
cv.check_type('delayed groups', delayed_groups, list, int)
cv.check_greater_than('num delayed groups', len(delayed_groups), 0)
self._delayed_groups = delayed_groups
# Check that the groups are within [1, MAX_DELAYED_GROUPS]
for group in delayed_groups:
cv.check_greater_than('delayed group', group, 0)
cv.check_less_than('delayed group', group, MAX_DELAYED_GROUPS,
equality=True)
self._delayed_groups = delayed_groups
@property
def filters(self):
@ -251,12 +256,13 @@ class MDGXS(MGXS):
def get_xs(self, groups='all', subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing',
value='mean', delayed_groups='all', **kwargs):
value='mean', delayed_groups='all', squeeze=True, **kwargs):
"""Returns an array of multi-delayed-group cross sections.
This method constructs a 2D NumPy array for the requested
multi-delayed-group cross section data data for one or more energy
groups, delayed groups, and subdomains.
This method constructs a 4D NumPy array for the requested
multi-delayed-group cross section data for one or more
subdomains (1st dimension), delayed groups (2nd demension),
energy groups (3rd dimension), and nuclides (4th dimension).
Parameters
----------
@ -280,6 +286,10 @@ class MDGXS(MGXS):
A string for the type of value to return. Defaults to 'mean'.
delayed_groups : list of int or 'all'
Delayed groups of interest. Defaults to 'all'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array this is to be retured. Defaults to
True.
Returns
-------
@ -359,25 +369,36 @@ class MDGXS(MGXS):
if value == 'mean' or value == 'std_dev':
xs /= densities[np.newaxis, :, np.newaxis]
# Eliminate the trivial score dimension
xs = np.squeeze(xs, axis=len(xs.shape) - 1)
xs = np.nan_to_num(xs)
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
if delayed_groups == 'all':
num_delayed_groups = self.num_delayed_groups
else:
num_delayed_groups = len(delayed_groups)
# Reshape tally data array with separate axes for domain, energy groups,
# delayed groups, and nuclides
num_subdomains = int(xs.shape[0] / (num_groups * num_delayed_groups))
new_shape = (num_subdomains, num_delayed_groups, num_groups)
new_shape += xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
xs = xs[:, :, ::-1, :]
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] / num_groups)
new_shape = (num_subdomains, num_groups) + xs.shape[1:]
xs = np.reshape(xs, new_shape)
if squeeze:
xs = np.squeeze(xs)
xs = np.atleast_1d(xs)
# Reverse energies to align with increasing energy groups
xs = xs[:, ::-1, :]
# Eliminate trivial dimensions
xs = np.squeeze(xs)
xs = np.atleast_1d(xs)
return xs
def get_slice(self, nuclides=[], groups=[], delayed_groups=[]):
@ -467,11 +488,11 @@ class MDGXS(MGXS):
return slice_xs
def merge(self, other):
"""Merge another MDGXS with this one
"""Merge another MGXS with this one
MDGXS are only mergeable if their energy groups and nuclides are either
MGXS are only mergeable if their energy groups and nuclides are either
identical or mutually exclusive. If results have been loaded from a
statepoint, then MDGXS are only mergeable along one and only one of
statepoint, then MGXS are only mergeable along one and only one of
energy groups or nuclides.
Parameters
@ -718,9 +739,112 @@ class MDGXS(MGXS):
"""
if not isinstance(groups, basestring):
cv.check_iterable_type('groups', groups, Integral)
if nuclides != 'all' and nuclides != 'sum':
cv.check_iterable_type('nuclides', nuclides, basestring)
if not isinstance(delayed_groups, basestring):
cv.check_type('delayed groups', delayed_groups, list, int)
cv.check_value('xs_type', xs_type, ['macro', 'micro'])
# Get a Pandas DataFrame from the derived xs tally
if self.by_nuclide and nuclides == 'sum':
# Use tally summation to sum across all nuclides
query_nuclides = self.get_all_nuclides()
xs_tally = self.xs_tally.summation(nuclides=query_nuclides)
df = xs_tally.get_pandas_dataframe(
distribcell_paths=distribcell_paths)
# Remove nuclide column since it is homogeneous and redundant
if self.domain_type == 'mesh':
df.drop('nuclide', axis=1, level=0, inplace=True)
else:
df.drop('nuclide', axis=1, inplace=True)
# If the user requested a specific set of nuclides
elif self.by_nuclide and nuclides != 'all':
xs_tally = self.xs_tally.get_slice(nuclides=nuclides)
df = xs_tally.get_pandas_dataframe(
distribcell_paths=distribcell_paths)
# If the user requested all nuclides, keep nuclide column in dataframe
else:
df = self.xs_tally.get_pandas_dataframe(
distribcell_paths=distribcell_paths)
# Remove the score column since it is homogeneous and redundant
if self.domain_type == 'mesh':
df = df.drop('score', axis=1, level=0)
else:
df = df.drop('score', axis=1)
# Override energy groups bounds with indices
all_groups = np.arange(self.num_groups, 0, -1, dtype=np.int)
all_groups = np.repeat(all_groups, self.num_nuclides)
if 'energy low [MeV]' in df and 'energyout low [MeV]' in df:
df.rename(columns={'energy low [MeV]': 'group in'},
inplace=True)
in_groups = np.tile(all_groups, int(self.num_subdomains *
self.num_delayed_groups))
in_groups = np.repeat(in_groups, int(df.shape[0] / in_groups.size))
df['group in'] = in_groups
del df['energy high [MeV]']
df.rename(columns={'energyout low [MeV]': 'group out'},
inplace=True)
out_groups = np.tile(all_groups, int(df.shape[0] / all_groups.size))
df['group out'] = out_groups
del df['energyout high [MeV]']
columns = ['group in', 'group out']
elif 'energyout low [MeV]' in df:
df.rename(columns={'energyout low [MeV]': 'group out'},
inplace=True)
in_groups = np.tile(all_groups, int(df.shape[0] / all_groups.size))
df['group out'] = in_groups
del df['energyout high [MeV]']
columns = ['group out']
elif 'energy low [MeV]' in df:
df.rename(columns={'energy low [MeV]': 'group in'}, inplace=True)
in_groups = np.tile(all_groups, int(df.shape[0] / all_groups.size))
df['group in'] = in_groups
del df['energy high [MeV]']
columns = ['group in']
# Select out those groups the user requested
if not isinstance(groups, basestring):
if 'group in' in df:
df = df[df['group in'].isin(groups)]
if 'group out' in df:
df = df[df['group out'].isin(groups)]
# If user requested micro cross sections, divide out the atom densities
if xs_type == 'micro':
if self.by_nuclide:
densities = self.get_nuclide_densities(nuclides)
else:
densities = self.get_nuclide_densities('sum')
densities = np.repeat(densities, len(self.rxn_rate_tally.scores))
tile_factor = df.shape[0] / len(densities)
df['mean'] /= np.tile(densities, tile_factor)
df['std. dev.'] /= np.tile(densities, tile_factor)
# Sort the dataframe by domain type id (e.g., distribcell id) and
# energy groups such that data is from fast to thermal
if self.domain_type == 'mesh':
mesh_str = 'mesh {0}'.format(self.domain.id)
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'), \
(mesh_str, 'z')] + columns, inplace=True)
else:
df.sort_values(by=[self.domain_type] + columns, inplace=True)
return df
df = super(MDGXS, self).get_pandas_dataframe(groups, nuclides, xs_type,
distribcell_paths)
@ -744,7 +868,7 @@ class ChiDelayed(MDGXS):
domain are generated automatically via the :attr:`ChiDelayed.tallies`
property, which can then be appended to a :class:`openmc.Tallies` instance.
For post-processing, the :meth:`MDGXS.load_from_statepoint` will pull in the
For post-processing, the :meth:`MGXS.load_from_statepoint` will pull in the
necessary data to compute multi-group cross sections from a
:class:`openmc.StatePoint` instance. The derived multi-group cross
section can then be obtained from the :attr:`ChiDelayed.xs_tally` property.
@ -961,7 +1085,7 @@ class ChiDelayed(MDGXS):
# Slice nu-fission-out tally along energyout filter
delayed_nu_fission_out = slice_xs.tallies['delayed-nu-fission-out']
tally_slice = delayed_nu_fission_out.get_slice\
tally_slice = delayed_nu_fission_out.get_slice \
(filters=filters, filter_bins=filter_bins)
slice_xs._tallies['delayed-nu-fission-out'] = tally_slice
@ -980,8 +1104,8 @@ class ChiDelayed(MDGXS):
Parameters
----------
other : openmc.mdgxs.MDGXS
MDGXS to merge with this one
other : openmc.mdgxs.MGXS
MGXS to merge with this one
Returns
-------
@ -1030,12 +1154,13 @@ class ChiDelayed(MDGXS):
def get_xs(self, groups='all', subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing',
value='mean', delayed_groups='all', **kwargs):
value='mean', delayed_groups='all', squeeze=True, **kwargs):
"""Returns an array of the delayed fission spectrum.
This method constructs a 2D NumPy array for the requested multi-group
and multi-delayed group cross section data data for one or more energy
groups and subdomains.
This method constructs a 4D NumPy array for the requested
multi-delayed-group cross section data for one or more
subdomains (1st dimension), delayed groups (2nd demension),
energy groups (3rd dimension), and nuclides (4th dimension).
Parameters
----------
@ -1052,13 +1177,17 @@ class ChiDelayed(MDGXS):
cross section summed over all nuclides. Defaults to 'all'.
xs_type: {'macro', 'micro'}
This parameter is not relevant for chi but is included here to
mirror the parent MDGXS.get_xs(...) class method
mirror the parent MGXS.get_xs(...) class method
order_groups: {'increasing', 'decreasing'}
Return the cross section indexed according to increasing or
decreasing energy groups (decreasing or increasing energies).
Defaults to 'increasing'.
value : {'mean', 'std_dev', 'rel_err'}
A string for the type of value to return. Defaults to 'mean'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array this is to be retured. Defaults to
True.
Returns
-------
@ -1162,27 +1291,37 @@ class ChiDelayed(MDGXS):
xs = self.xs_tally.get_values(filters=filters,
filter_bins=filter_bins, value=value)
# Eliminate the trivial score dimension
xs = np.squeeze(xs, axis=len(xs.shape) - 1)
xs = np.nan_to_num(xs)
# Reshape tally data array with separate axes for domain and energy
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
if delayed_groups == 'all':
num_delayed_groups = self.num_delayed_groups
else:
num_delayed_groups = len(delayed_groups)
# Reshape tally data array with separate axes for domain, energy groups,
# delayed groups, and nuclides
num_subdomains = int(xs.shape[0] / (num_groups * num_delayed_groups))
new_shape = (num_subdomains, num_delayed_groups, num_groups)
new_shape += xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
xs = xs[:, :, ::-1, :]
# Reshape tally data array with separate axes for domain and energy
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
num_subdomains = int(xs.shape[0] / num_groups)
new_shape = (num_subdomains, num_groups) + xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse energies to align with increasing energy groups
xs = xs[:, ::-1, :]
# Eliminate trivial dimensions
if squeeze:
xs = np.squeeze(xs)
xs = np.atleast_1d(xs)
xs = np.nan_to_num(xs)
return xs
@ -1199,7 +1338,7 @@ class DelayedNuFissionXS(MDGXS):
:attr:`DelayedNuFissionXS.tallies` property, which can then be appended to a
:class:`openmc.Tallies` instance.
For post-processing, the :meth:`MDGXS.load_from_statepoint` will pull in the
For post-processing, the :meth:`MGXS.load_from_statepoint` will pull in the
necessary data to compute multi-group cross sections from a
:class:`openmc.StatePoint` instance. The derived multi-group cross section
can then be obtained from the :attr:`DelayedNuFissionXS.xs_tally` property.
@ -1315,7 +1454,7 @@ class Beta(MDGXS):
generated automatically via the :attr:`Beta.tallies` property, which can
then be appended to a :class:`openmc.Tallies` instance.
For post-processing, the :meth:`MDGXS.load_from_statepoint` will pull in the
For post-processing, the :meth:`MGXS.load_from_statepoint` will pull in the
necessary data to compute multi-group cross sections from a
:class:`openmc.StatePoint` instance. The derived multi-group cross section
can then be obtained from the :attr:`Beta.xs_tally` property.

View file

@ -724,11 +724,13 @@ class MGXS(object):
def get_xs(self, groups='all', subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing',
value='mean', **kwargs):
value='mean', squeeze=True, **kwargs):
r"""Returns an array of multi-group cross sections.
This method constructs a 2D NumPy array for the requested multi-group
cross section data data for one or more energy groups and subdomains.
This method constructs a 3D NumPy array for the requested
multi-group cross section data for one or more subdomains
(1st dimension), energy groups (2nd dimension), and nuclides
(3rd dimension).
Parameters
----------
@ -750,6 +752,10 @@ class MGXS(object):
Defaults to 'increasing'.
value : {'mean', 'std_dev', 'rel_err'}
A string for the type of value to return. Defaults to 'mean'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array this is to be retured. Defaults to
True.
Returns
-------
@ -819,25 +825,29 @@ class MGXS(object):
if value == 'mean' or value == 'std_dev':
xs /= densities[np.newaxis, :, np.newaxis]
# Eliminate the trivial score dimension
xs = np.squeeze(xs, axis=len(xs.shape) - 1)
xs = np.nan_to_num(xs)
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] / num_groups)
new_shape = (num_subdomains, num_groups) + xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] / num_groups)
new_shape = (num_subdomains, num_groups) + xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse energies to align with increasing energy groups
xs = xs[:, ::-1, :]
# Eliminate trivial dimensions
xs = np.squeeze(xs)
xs = np.atleast_1d(xs)
if squeeze:
xs = np.squeeze(xs)
xs = np.atleast_1d(xs)
return xs
def get_condensed_xs(self, coarse_groups):
@ -1350,8 +1360,6 @@ class MGXS(object):
std_dev = self.get_xs(subdomains=[subdomain], nuclides=[nuclide],
xs_type=xs_type, value='std_dev',
row_column=row_column)
average = average.squeeze()
std_dev = std_dev.squeeze()
# Add MGXS results data to the HDF5 group
nuclide_group.require_dataset('average', dtype=np.float64,
@ -1517,14 +1525,14 @@ class MGXS(object):
if 'energy low [MeV]' in df and 'energyout low [MeV]' in df:
df.rename(columns={'energy low [MeV]': 'group in'},
inplace=True)
in_groups = np.tile(all_groups, df.shape[0] / all_groups.size)
in_groups = np.repeat(in_groups, df.shape[0] / in_groups.size)
in_groups = np.tile(all_groups, int(self.num_subdomains))
in_groups = np.repeat(in_groups, int(df.shape[0] / in_groups.size))
df['group in'] = in_groups
del df['energy high [MeV]']
df.rename(columns={'energyout low [MeV]': 'group out'},
inplace=True)
out_groups = np.tile(all_groups, df.shape[0] / all_groups.size)
out_groups = np.tile(all_groups, int(df.shape[0] / all_groups.size))
df['group out'] = out_groups
del df['energyout high [MeV]']
columns = ['group in', 'group out']
@ -1532,14 +1540,14 @@ class MGXS(object):
elif 'energyout low [MeV]' in df:
df.rename(columns={'energyout low [MeV]': 'group out'},
inplace=True)
in_groups = np.tile(all_groups, df.shape[0] / all_groups.size)
in_groups = np.tile(all_groups, int(df.shape[0] / all_groups.size))
df['group out'] = in_groups
del df['energyout high [MeV]']
columns = ['group out']
elif 'energy low [MeV]' in df:
df.rename(columns={'energy low [MeV]': 'group in'}, inplace=True)
in_groups = np.tile(all_groups, df.shape[0] / all_groups.size)
in_groups = np.tile(all_groups, int(df.shape[0] / all_groups.size))
df['group in'] = in_groups
del df['energy high [MeV]']
columns = ['group in']
@ -1570,6 +1578,7 @@ class MGXS(object):
(mesh_str, 'z')] + columns, inplace=True)
else:
df.sort_values(by=[self.domain_type] + columns, inplace=True)
return df
def get_units(self, xs_type='macro'):
@ -1700,11 +1709,13 @@ class MatrixMGXS(MGXS):
def get_xs(self, in_groups='all', out_groups='all',
subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing',
row_column='inout', value='mean', **kwargs):
row_column='inout', value='mean', squeeze=True, **kwargs):
"""Returns an array of multi-group cross sections.
This method constructs a 2D NumPy array for the requested multi-group
matrix data for one or more energy groups and subdomains.
This method constructs a 4D NumPy array for the requested
multi-group cross section data for one or more subdomains
(1st dimension), energy groups in (2nd dimension), energy groups out
(3rd dimension), and nuclides (4th dimension).
Parameters
----------
@ -1733,6 +1744,10 @@ class MatrixMGXS(MGXS):
Defaults to 'inout'.
value : {'mean', 'std_dev', 'rel_err'}
A string for the type of value to return. Defaults to 'mean'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array this is to be retured. Defaults to
True.
Returns
-------
@ -1804,8 +1819,6 @@ class MatrixMGXS(MGXS):
filter_bins=filter_bins,
nuclides=query_nuclides, value=value)
xs = np.nan_to_num(xs)
# Divide by atom number densities for microscopic cross sections
if xs_type == 'micro':
if self.by_nuclide:
@ -1815,33 +1828,36 @@ class MatrixMGXS(MGXS):
if value == 'mean' or value == 'std_dev':
xs /= densities[np.newaxis, :, np.newaxis]
# Eliminate the trivial score dimension
xs = np.squeeze(xs, axis=len(xs.shape) - 1)
xs = np.nan_to_num(xs)
if in_groups == 'all':
num_in_groups = self.num_groups
else:
num_in_groups = len(in_groups)
if out_groups == 'all':
num_out_groups = self.num_groups
else:
num_out_groups = len(out_groups)
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] / (num_in_groups * num_out_groups))
new_shape = (num_subdomains, num_in_groups, num_out_groups)
new_shape += xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Transpose the matrix if requested by user
if row_column == 'outin':
xs = np.swapaxes(xs, 1, 2)
# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
if in_groups == 'all':
num_in_groups = self.num_groups
else:
num_in_groups = len(in_groups)
if out_groups == 'all':
num_out_groups = self.num_groups
else:
num_out_groups = len(out_groups)
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] /
(num_in_groups * num_out_groups))
new_shape = (num_subdomains, num_in_groups, num_out_groups)
new_shape += xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Transpose the matrix if requested by user
if row_column == 'outin':
xs = np.swapaxes(xs, 1, 2)
# Reverse energies to align with increasing energy groups
xs = xs[:, ::-1, ::-1, :]
# Eliminate trivial dimensions
if squeeze:
xs = np.squeeze(xs)
xs = np.atleast_2d(xs)
@ -3518,11 +3534,13 @@ class ScatterMatrixXS(MatrixMGXS):
def get_xs(self, in_groups='all', out_groups='all',
subdomains='all', nuclides='all', moment='all',
xs_type='macro', order_groups='increasing',
row_column='inout', value='mean'):
row_column='inout', value='mean', squeeze=True):
r"""Returns an array of multi-group cross sections.
This method constructs a 2D NumPy array for the requested scattering
matrix data data for one or more energy groups and subdomains.
This method constructs a 5D NumPy array for the requested
multi-group cross section data for one or more subdomains
(1st dimension), energy groups in (2nd dimension), energy groups out
(3rd dimension), nuclides (4th dimension), and moments (5th dimension).
NOTE: The scattering moments are not multiplied by the :math:`(2l+1)/2`
prefactor in the expansion of the scattering source into Legendre
@ -3558,6 +3576,10 @@ class ScatterMatrixXS(MatrixMGXS):
Defaults to 'inout'.
value : {'mean', 'std_dev', 'rel_err'}
A string for the type of value to return. Defaults to 'mean'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array this is to be retured. Defaults to
False.
Returns
-------
@ -3636,8 +3658,6 @@ class ScatterMatrixXS(MatrixMGXS):
filter_bins=filter_bins,
nuclides=query_nuclides, value=value)
xs = np.nan_to_num(xs)
# Divide by atom number densities for microscopic cross sections
if xs_type == 'micro':
if self.by_nuclide:
@ -3647,32 +3667,35 @@ class ScatterMatrixXS(MatrixMGXS):
if value == 'mean' or value == 'std_dev':
xs /= densities[np.newaxis, :, np.newaxis]
# Convert and nans to zero
xs = np.nan_to_num(xs)
if in_groups == 'all':
num_in_groups = self.num_groups
else:
num_in_groups = len(in_groups)
if out_groups == 'all':
num_out_groups = self.num_groups
else:
num_out_groups = len(out_groups)
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] / (num_in_groups * num_out_groups))
new_shape = (num_subdomains, num_in_groups, num_out_groups)
new_shape += xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Transpose the scattering matrix if requested by user
if row_column == 'outin':
xs = np.swapaxes(xs, 1, 2)
# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
if in_groups == 'all':
num_in_groups = self.num_groups
else:
num_in_groups = len(in_groups)
if out_groups == 'all':
num_out_groups = self.num_groups
else:
num_out_groups = len(out_groups)
# Reshape tally data array with separate axes for domain and energy
num_subdomains = int(xs.shape[0] / (num_in_groups * num_out_groups))
new_shape = (num_subdomains, num_in_groups, num_out_groups)
new_shape += xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Transpose the scattering matrix if requested by user
if row_column == 'outin':
xs = np.swapaxes(xs, 1, 2)
# Reverse energies to align with increasing energy groups
xs = xs[:, ::-1, ::-1, :]
# Eliminate trivial dimensions
if squeeze:
xs = np.squeeze(xs)
xs = np.atleast_2d(xs)
@ -3729,7 +3752,7 @@ class ScatterMatrixXS(MatrixMGXS):
if self.legendre_order > 0:
# Insert a column corresponding to the Legendre moments
moments = ['P{}'.format(i) for i in range(self.legendre_order+1)]
moments = np.tile(moments, df.shape[0] / len(moments))
moments = np.tile(moments, int(df.shape[0] / len(moments)))
df['moment'] = moments
# Place the moment column before the mean column
@ -4513,11 +4536,13 @@ class Chi(MGXS):
def get_xs(self, groups='all', subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing',
value='mean', **kwargs):
value='mean', squeeze=True, **kwargs):
"""Returns an array of the fission spectrum.
This method constructs a 2D NumPy array for the requested multi-group
cross section data data for one or more energy groups and subdomains.
This method constructs a 3D NumPy array for the requested
multi-group cross section data for one or more subdomains
(1st dimension), energy groups (2nd dimension), and nuclides
(3rd dimension).
Parameters
----------
@ -4539,6 +4564,10 @@ class Chi(MGXS):
Defaults to 'increasing'.
value : {'mean', 'std_dev', 'rel_err'}
A string for the type of value to return. Defaults to 'mean'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array this is to be retured. Defaults to
True.
Returns
-------
@ -4630,27 +4659,29 @@ class Chi(MGXS):
xs = self.xs_tally.get_values(filters=filters,
filter_bins=filter_bins, value=value)
# Eliminate the trivial score dimension
xs = np.squeeze(xs, axis=len(xs.shape) - 1)
xs = np.nan_to_num(xs)
# Reshape tally data array with separate axes for domain and energy
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
num_subdomains = int(xs.shape[0] / num_groups)
new_shape = (num_subdomains, num_groups) + xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
# Reshape tally data array with separate axes for domain and energy
if groups == 'all':
num_groups = self.num_groups
else:
num_groups = len(groups)
num_subdomains = int(xs.shape[0] / num_groups)
new_shape = (num_subdomains, num_groups) + xs.shape[1:]
xs = np.reshape(xs, new_shape)
# Reverse energies to align with increasing energy groups
xs = xs[:, ::-1, :]
# Eliminate trivial dimensions
if squeeze:
xs = np.squeeze(xs)
xs = np.atleast_1d(xs)
xs = np.nan_to_num(xs)
return xs
def get_pandas_dataframe(self, groups='all', nuclides='all',

View file

@ -9,6 +9,7 @@ from testing_harness import PyAPITestHarness
from input_set import PinCellInputSet
import openmc
import openmc.mgxs
import numpy as np
class MGXSTestHarness(PyAPITestHarness):
@ -24,7 +25,7 @@ class MGXSTestHarness(PyAPITestHarness):
20.])
# Initialize a six-delayed-group structure
delayed_groups = range(1,7)
delayed_groups = list(range(1,7))
# Initialize MGXS Library for a few cross section types
self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry)

View file

@ -9,6 +9,7 @@ from testing_harness import PyAPITestHarness
from input_set import AssemblyInputSet
import openmc
import openmc.mgxs
import numpy as np
class MGXSTestHarness(PyAPITestHarness):
@ -23,7 +24,7 @@ class MGXSTestHarness(PyAPITestHarness):
energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.])
# Initialize a six-delayed-group structure
delayed_groups = range(1,7)
delayed_groups = list(range(1,7))
# Initialize MGXS Library for a few cross section types
# for one material-filled cell in the geometry

View file

@ -25,7 +25,7 @@ class MGXSTestHarness(PyAPITestHarness):
20.])
# Initialize a six-delayed-group structure
delayed_groups = range(1,7)
delayed_groups = list(range(1,7))
# Initialize MGXS Library for a few cross section types
self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry)

View file

@ -8,6 +8,7 @@ sys.path.insert(0, os.pardir)
from testing_harness import PyAPITestHarness
import openmc
import openmc.mgxs
import numpy as np
class MGXSTestHarness(PyAPITestHarness):
@ -19,7 +20,7 @@ class MGXSTestHarness(PyAPITestHarness):
energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.])
# Initialize a six-delayed-group structure
delayed_groups = range(1,7)
delayed_groups = list(range(1,7))
# Initialize MGXS Library for a few cross section types
# for one material-filled cell in the geometry

View file

@ -29,49 +29,49 @@
1 10000 1 total 0.385188 0.026946
0 10000 2 total 0.412389 0.015425
material group in group out nuclide moment mean std. dev.
1 10000 1 1 total P0 0.016482 0.004502
3 10000 1 1 total P1 -0.010499 0.010438
5 10000 1 1 total P2 -0.000768 0.000768
7 10000 1 1 total P3 -0.000171 0.000172
9 10000 1 1 total P0 -0.000207 0.000149
11 10000 1 1 total P1 0.000234 0.000128
13 10000 1 1 total P2 0.051870 0.006983
15 10000 1 1 total P3 0.009478 0.002234
8 10000 1 2 total P0 0.000989 0.000482
10 10000 1 2 total P1 -0.000103 0.000184
12 10000 1 2 total P2 0.384199 0.027001
14 10000 1 2 total P3 0.020069 0.002846
1 10000 2 1 total P0 0.016482 0.004502
3 10000 2 1 total P1 -0.010499 0.010438
5 10000 2 1 total P2 -0.000768 0.000768
7 10000 2 1 total P3 -0.000171 0.000172
0 10000 2 2 total P0 0.411465 0.015245
2 10000 2 2 total P1 0.006371 0.010551
4 10000 2 2 total P2 0.000925 0.000925
6 10000 2 2 total P3 0.000494 0.000494
8 10000 2 2 total P0 0.000989 0.000482
10 10000 2 2 total P1 -0.000103 0.000184
12 10000 2 2 total P2 0.384199 0.027001
14 10000 2 2 total P3 0.020069 0.002846
material group in group out nuclide moment mean std. dev.
1 10000 1 1 total P0 0.016482 0.004502
3 10000 1 1 total P1 -0.010499 0.010438
5 10000 1 1 total P2 -0.000768 0.000768
7 10000 1 1 total P3 -0.000171 0.000172
9 10000 1 1 total P0 -0.000207 0.000149
11 10000 1 1 total P1 0.000234 0.000128
13 10000 1 1 total P2 0.051870 0.006983
15 10000 1 1 total P3 0.009478 0.002234
8 10000 1 2 total P0 0.000989 0.000482
10 10000 1 2 total P1 -0.000103 0.000184
12 10000 1 2 total P2 0.384199 0.027001
14 10000 1 2 total P3 0.020069 0.002846
1 10000 2 1 total P0 0.016482 0.004502
3 10000 2 1 total P1 -0.010499 0.010438
5 10000 2 1 total P2 -0.000768 0.000768
7 10000 2 1 total P3 -0.000171 0.000172
0 10000 2 2 total P0 0.411465 0.015245
2 10000 2 2 total P1 0.006371 0.010551
4 10000 2 2 total P2 0.000925 0.000925
6 10000 2 2 total P3 0.000494 0.000494
8 10000 2 2 total P0 0.000989 0.000482
10 10000 2 2 total P1 -0.000103 0.000184
12 10000 2 2 total P2 0.384199 0.027001
14 10000 2 2 total P3 0.020069 0.002846
material group in group out nuclide mean std. dev.
1 10000 1 1 total 1.0 1.414214
3 10000 1 1 total 1.0 0.078516
2 10000 1 2 total 1.0 0.687184
1 10000 2 1 total 1.0 1.414214
0 10000 2 2 total 1.0 0.041130
2 10000 2 2 total 1.0 0.687184
material group in group out nuclide mean std. dev.
1 10000 1 1 total 0.454366 0.027426
3 10000 1 1 total 0.020142 0.003149
2 10000 1 2 total 0.000000 0.000000
1 10000 2 1 total 0.454366 0.027426
0 10000 2 2 total 0.000000 0.000000
2 10000 2 2 total 0.000000 0.000000
material group out nuclide mean std. dev.
1 10000 1 total 1.0 0.046071
0 10000 2 total 0.0 0.000000
@ -154,49 +154,49 @@
1 10001 1 total 0.310121 0.033788
0 10001 2 total 0.296264 0.043792
material group in group out nuclide moment mean std. dev.
1 10001 1 1 total P0 -0.011214 0.016180
3 10001 1 1 total P1 -0.003270 0.007329
5 10001 1 1 total P2 0.000000 0.000000
7 10001 1 1 total P3 0.000000 0.000000
9 10001 1 1 total P0 0.000000 0.000000
11 10001 1 1 total P1 0.000000 0.000000
13 10001 1 1 total P2 0.038230 0.008484
15 10001 1 1 total P3 0.007964 0.003732
8 10001 1 2 total P0 0.000000 0.000000
10 10001 1 2 total P1 0.000000 0.000000
12 10001 1 2 total P2 0.310121 0.033788
14 10001 1 2 total P3 0.020745 0.004696
1 10001 2 1 total P0 -0.011214 0.016180
3 10001 2 1 total P1 -0.003270 0.007329
5 10001 2 1 total P2 0.000000 0.000000
7 10001 2 1 total P3 0.000000 0.000000
0 10001 2 2 total P0 0.296264 0.043792
2 10001 2 2 total P1 0.008837 0.011504
4 10001 2 2 total P2 0.000000 0.000000
6 10001 2 2 total P3 0.000000 0.000000
8 10001 2 2 total P0 0.000000 0.000000
10 10001 2 2 total P1 0.000000 0.000000
12 10001 2 2 total P2 0.310121 0.033788
14 10001 2 2 total P3 0.020745 0.004696
material group in group out nuclide moment mean std. dev.
1 10001 1 1 total P0 -0.011214 0.016180
3 10001 1 1 total P1 -0.003270 0.007329
5 10001 1 1 total P2 0.000000 0.000000
7 10001 1 1 total P3 0.000000 0.000000
9 10001 1 1 total P0 0.000000 0.000000
11 10001 1 1 total P1 0.000000 0.000000
13 10001 1 1 total P2 0.038230 0.008484
15 10001 1 1 total P3 0.007964 0.003732
8 10001 1 2 total P0 0.000000 0.000000
10 10001 1 2 total P1 0.000000 0.000000
12 10001 1 2 total P2 0.310121 0.033788
14 10001 1 2 total P3 0.020745 0.004696
1 10001 2 1 total P0 -0.011214 0.016180
3 10001 2 1 total P1 -0.003270 0.007329
5 10001 2 1 total P2 0.000000 0.000000
7 10001 2 1 total P3 0.000000 0.000000
0 10001 2 2 total P0 0.296264 0.043792
2 10001 2 2 total P1 0.008837 0.011504
4 10001 2 2 total P2 0.000000 0.000000
6 10001 2 2 total P3 0.000000 0.000000
8 10001 2 2 total P0 0.000000 0.000000
10 10001 2 2 total P1 0.000000 0.000000
12 10001 2 2 total P2 0.310121 0.033788
14 10001 2 2 total P3 0.020745 0.004696
material group in group out nuclide mean std. dev.
1 10001 1 1 total 0.0 0.000000
3 10001 1 1 total 1.0 0.108779
2 10001 1 2 total 0.0 0.000000
1 10001 2 1 total 0.0 0.000000
0 10001 2 2 total 1.0 0.142427
2 10001 2 2 total 0.0 0.000000
material group in group out nuclide mean std. dev.
1 10001 1 1 total 0.0 0.0
3 10001 1 1 total 0.0 0.0
2 10001 1 2 total 0.0 0.0
1 10001 2 1 total 0.0 0.0
0 10001 2 2 total 0.0 0.0
2 10001 2 2 total 0.0 0.0
material group out nuclide mean std. dev.
1 10001 1 total 0.0 0.0
0 10001 2 total 0.0 0.0
@ -279,49 +279,49 @@
1 10002 1 total 0.671269 0.026186
0 10002 2 total 2.035388 0.258060
material group in group out nuclide moment mean std. dev.
1 10002 1 1 total P0 0.509941 0.051236
3 10002 1 1 total P1 0.024988 0.008312
5 10002 1 1 total P2 0.000400 0.000401
7 10002 1 1 total P3 0.000214 0.000215
9 10002 1 1 total P0 0.008758 0.000926
11 10002 1 1 total P1 -0.003785 0.000817
13 10002 1 1 total P2 0.381167 0.016243
15 10002 1 1 total P3 0.009148 0.003889
8 10002 1 2 total P0 0.031368 0.001728
10 10002 1 2 total P1 -0.002568 0.001014
12 10002 1 2 total P2 0.639901 0.024709
14 10002 1 2 total P3 0.152392 0.008156
1 10002 2 1 total P0 0.509941 0.051236
3 10002 2 1 total P1 0.024988 0.008312
5 10002 2 1 total P2 0.000400 0.000401
7 10002 2 1 total P3 0.000214 0.000215
0 10002 2 2 total P0 2.034945 0.257800
2 10002 2 2 total P1 0.111175 0.013020
4 10002 2 2 total P2 0.000443 0.000445
6 10002 2 2 total P3 0.000320 0.000321
8 10002 2 2 total P0 0.031368 0.001728
10 10002 2 2 total P1 -0.002568 0.001014
12 10002 2 2 total P2 0.639901 0.024709
14 10002 2 2 total P3 0.152392 0.008156
material group in group out nuclide moment mean std. dev.
1 10002 1 1 total P0 0.509941 0.051236
3 10002 1 1 total P1 0.024988 0.008312
5 10002 1 1 total P2 0.000400 0.000401
7 10002 1 1 total P3 0.000214 0.000215
9 10002 1 1 total P0 0.008758 0.000926
11 10002 1 1 total P1 -0.003785 0.000817
13 10002 1 1 total P2 0.381167 0.016243
15 10002 1 1 total P3 0.009148 0.003889
8 10002 1 2 total P0 0.031368 0.001728
10 10002 1 2 total P1 -0.002568 0.001014
12 10002 1 2 total P2 0.639901 0.024709
14 10002 1 2 total P3 0.152392 0.008156
1 10002 2 1 total P0 0.509941 0.051236
3 10002 2 1 total P1 0.024988 0.008312
5 10002 2 1 total P2 0.000400 0.000401
7 10002 2 1 total P3 0.000214 0.000215
0 10002 2 2 total P0 2.034945 0.257800
2 10002 2 2 total P1 0.111175 0.013020
4 10002 2 2 total P2 0.000443 0.000445
6 10002 2 2 total P3 0.000320 0.000321
8 10002 2 2 total P0 0.031368 0.001728
10 10002 2 2 total P1 -0.002568 0.001014
12 10002 2 2 total P2 0.639901 0.024709
14 10002 2 2 total P3 0.152392 0.008156
material group in group out nuclide mean std. dev.
1 10002 1 1 total 1.0 1.414214
3 10002 1 1 total 1.0 0.038609
2 10002 1 2 total 1.0 0.067667
1 10002 2 1 total 1.0 1.414214
0 10002 2 2 total 1.0 0.135929
2 10002 2 2 total 1.0 0.067667
material group in group out nuclide mean std. dev.
1 10002 1 1 total 0.0 0.0
3 10002 1 1 total 0.0 0.0
2 10002 1 2 total 0.0 0.0
1 10002 2 1 total 0.0 0.0
0 10002 2 2 total 0.0 0.0
2 10002 2 2 total 0.0 0.0
material group out nuclide mean std. dev.
1 10002 1 total 0.0 0.0
0 10002 2 total 0.0 0.0

View file

@ -9,6 +9,7 @@ from testing_harness import PyAPITestHarness
from input_set import PinCellInputSet
import openmc
import openmc.mgxs
import numpy as np
class MGXSTestHarness(PyAPITestHarness):
@ -24,7 +25,7 @@ class MGXSTestHarness(PyAPITestHarness):
20.])
# Initialize a six-delayed-group structure
delayed_groups = range(1,7)
delayed_groups = list(range(1,7))
# Initialize MGXS Library for a few cross section types
self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry)

View file

@ -1 +1 @@
cb61db73f66b40ed1a59a59e6f4fd52678e9dc41c7bb8ad327989233c3b8d78a71d84c3cb8ad9bc8b1585b319e1f1d66a8667e7cad2ead4cc574f415f8f7a35d
8142ae4e107002a835999e4ace85c17376f262a7059fc224f3756a2de19aba6ca4c4fa14ca2085c87d7729aa8d6d6f78fdae21ac6dfe33ca303449c769076074

View file

@ -9,6 +9,7 @@ from testing_harness import PyAPITestHarness
from input_set import PinCellInputSet
import openmc
import openmc.mgxs
import numpy as np
class MGXSTestHarness(PyAPITestHarness):