Skip to content

Commit

Permalink
API Provide XSPlotReader.{energies,majorant}; prefer over metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
drewejohnson committed May 4, 2020
1 parent fd1b21f commit e040b80
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions serpentTools/parsers/xsplot.py
Expand Up @@ -34,19 +34,23 @@ class XSPlotReader(BaseReader):
Contains :class:`~serpentTools.objects.XSData` objects with keys
given by their names. There should be one XSData instance for each
isotope and material present in the problem.
energies : numpy.ndarray or None
Array of energy grids, shared across all XSData instances
majorant : numpy.ndarray or None
L-inf norm among all macroscopic cross sections used in the problem.
metadata: dict
Contains data pertinent to all XSData instances collected.
One particularly important entry is the 'egrid', which is a numpy array
of values that define the bin structure XS were recorded in by Serpent.
In addition, Serpent defines the 'majorant_xs', which is the L-inf norm
among all macroscopic cross sections used in the problem. This gets
used in the delta tracking routines usually.
Alias for accessing :attr:`energies` and :attr:`majorant`.
Attribute-based access is prefered, as this property will
likely be removed in the future
"""

def __init__(self, filePath):
BaseReader.__init__(self, filePath, 'xsplot')
super().__init__(filePath, 'xsplot')
self.xsections = {}
self.metadata = {}
self.energies = None
self.majorant = None

def __len__(self):
"""Number of xsdata objects stored"""
return len(self.xsections)
Expand Down Expand Up @@ -95,6 +99,15 @@ def get(self, key, default=None):
"""
return self.xsections.get(key, default)

@property
def metadata(self):
out = {}
if self.energies is not None:
out["egrid"] = self.energies
if self.majorant is not None:
out["majorant_xs"] = self.majorant
return out

def _read(self):
"""Read through the depletion file and store requested data."""
keys = ['E', r'i\d{4,5}', r'm\w']
Expand All @@ -107,12 +120,11 @@ def _read(self):
data = chunk[1:]
if lead.startswith("E = ["):
# The energy grid
self.metadata['egrid'] = array(data, dtype=float64)
self.energies = array(data, dtype=float64)

elif lead.endswith('majorant_xs = ['):
# L-inf norm on all XS on all materials
self.metadata['majorant_xs'] = array(data,
dtype=float64)
self.majorant = array(data, dtype=float64)

elif lead.endswith('_mt = ['):
xsname = lead[:lead.index("_mt")]
Expand Down

0 comments on commit e040b80

Please sign in to comment.