Made MGXS subclasses call compute_xs from load_from_statepint

This commit is contained in:
Will Boyd 2015-10-28 11:42:19 -04:00
parent 370c942977
commit 4c18f5b826
5 changed files with 109 additions and 157 deletions

File diff suppressed because one or more lines are too long

View file

@ -312,11 +312,6 @@ class Library(object):
mgxs = self.get_mgxs(domain, mgxs_type)
mgxs.load_from_statepoint(statepoint)
if isinstance(mgxs, openmc.mgxs.ScatterMatrixXS):
mgxs.compute_xs(correction=self.correction)
else:
mgxs.compute_xs()
def get_mgxs(self, domain, mgxs_type):
"""Return the MGXS object for some domain and reaction rate type.
@ -478,7 +473,7 @@ class Library(object):
return subdomain_avg_library
def build_hdf5_store(self, filename='mgxs', directory='mgxs',
def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs',
subdomains='all', nuclides='all', xs_type='macro'):
"""Export the multi-group cross section library to an HDF5 binary file.
@ -494,7 +489,7 @@ class Library(object):
Parameters
----------
filename : str
Filename for the HDF5 file. Defaults to 'mgxs'.
Filename for the HDF5 file. Defaults to 'mgxs.h5'.
directory : str
Directory for the HDF5 file. Defaults to 'mgxs'.
subdomains : {'all', 'avg'}
@ -536,7 +531,7 @@ class Library(object):
os.makedirs(directory)
# Add an attribute for the number of energy groups to the HDF5 file
full_filename = os.path.join(directory, filename + '.h5')
full_filename = os.path.join(directory, filename)
full_filename = full_filename.replace(' ', '-')
f = h5py.File(full_filename, 'w')
f.attrs["# groups"] = self.num_groups

View file

@ -41,7 +41,7 @@ DOMAIN_TYPES = ['cell',
# Supported domain classes
# TODO: Implement Mesh domains
DOMAINS = [openmc.Cell,
_DOMAINS = [openmc.Cell,
openmc.Universe,
openmc.Material]
@ -90,6 +90,17 @@ class MGXS(object):
xs_tally : Tally
Derived tally for the multi-group cross section. This attribute
is None unless the multi-group cross section has been computed.
num_sumbdomains : Integral
The number of subdomains is unity for 'material', 'cell' and 'universe'
domain types. When the This is equal to the number of cell instances
for 'distribcell' domain types (it is equal to unity prior to loading
tally data from a statepoint file).
num_nuclides : Integral
The number of nuclides for which the multi-group cross section is
being tracked. This is unity if the by_nuclide attribute is False.
nuclides : list of str or 'sum'
A list of nuclide string names (e.g., 'U-238', 'O-16') when by_nuclide
is True and 'sum' when by_nuclide is False.
"""
@ -556,6 +567,9 @@ class MGXS(object):
filter_bins, tally.nuclides)
self.tallies[tally_type] = sp_tally
# Compute the cross section from the tallies
self.compute_xs()
def get_xs(self, groups='all', subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing', value='mean'):
"""Returns an array of multi-group cross sections.
@ -926,7 +940,7 @@ class MGXS(object):
print(string)
def build_hdf5_store(self, filename='mgxs', directory='mgxs',
def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs',
subdomains='all', nuclides='all',
xs_type='macro', append=True):
"""Export the multi-group cross section data to an HDF5 binary file.
@ -942,7 +956,7 @@ class MGXS(object):
Parameters
----------
filename : str
Filename for the HDF5 file. Defaults to 'mgxs'.
Filename for the HDF5 file. Defaults to 'mgxs.h5'.
directory : str
Directory for the HDF5 file. Defaults to 'mgxs'.
subdomains : Iterable of Integral or 'all'
@ -957,7 +971,7 @@ class MGXS(object):
xs_type: {'macro', 'micro'}
Store the macro or micro cross section in units of cm^-1 or barns.
Defaults to 'macro'.
append : boolean
append : bool
If true, appends to an existing HDF5 file with the same filename
directory (if one exists). Defaults to True.
@ -982,7 +996,7 @@ class MGXS(object):
if not os.path.exists(directory):
os.makedirs(directory)
filename = os.path.join(directory, filename + '.h5')
filename = os.path.join(directory, filename)
filename = filename.replace(' ', '-')
if append and os.path.isfile(filename):
@ -1338,40 +1352,15 @@ class TransportXS(MGXS):
return super(TransportXS, self).tallies
def load_from_statepoint(self, statepoint):
"""Extracts tallies in an OpenMC StatePoint with the data needed to
compute multi-group cross sections.
This method is needed to compute cross section data from tallies
in an OpenMC StatePoint object.
NOTE: The statepoint must first be linked with an OpenMC Summary object.
Parameters
----------
statepoint : openmc.StatePoint
An OpenMC StatePoint object with tally data
Raises
------
ValueError
When this method is called with a statepoint that has not been
linked with a summary object.
"""
# Load the tallies from the statepoint using the parent class method
super(TransportXS, self).load_from_statepoint(statepoint)
def compute_xs(self):
"""Computes the multi-group transport cross sections using OpenMC
tally arithmetic."""
# Use tally slicing to remove scatter-P0 data from scatter-P1 tally
scatter_p1 = self.tallies['scatter-P1']
self.tallies['scatter-P1'] = scatter_p1.get_slice(scores=['scatter-P1'])
self.tallies['scatter-P1'].filters[-1].type = 'energy'
def compute_xs(self):
"""Computes the multi-group transport cross sections using OpenMC
tally arithmetic."""
self._xs_tally = self.tallies['total'] - self.tallies['scatter-P1']
self._xs_tally /= self.tallies['flux']
super(TransportXS, self).compute_xs()
@ -1424,7 +1413,14 @@ class AbsorptionXS(MGXS):
class CaptureXS(MGXS):
"""A capture multi-group cross section."""
"""A capture multi-group cross section.
The Neutron capture reaction rate is defined as the difference between
OpenMC's 'absorption' and 'fission' reaction rate score types. This includes
not only radiative capture, but all forms of neutron disappearance aside
from fission (e.g., MT > 100).
"""
def __init__(self, domain=None, domain_type=None,
groups=None, by_nuclide=False, name=''):

View file

@ -1185,7 +1185,6 @@ class SettingsFile(object):
self._eigenvalue_subelement = None
self._source_element = None
self._create_eigenvalue_subelement()
self._create_source_subelement()
self._create_output_subelement()

View file

@ -1,9 +0,0 @@
<?xml version="1.0"?>
<VTKFile type="PPolyData" version="0.1" byte_order="LittleEndian" compressor="vtkZLibDataCompressor">
<PPolyData GhostLevel="0">
<PPoints>
<PDataArray type="Float32" Name="Points" NumberOfComponents="3"/>
</PPoints>
<Piece Source="poly_0.vtp"/>
</PPolyData>
</VTKFile>