diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 7b75ac767b..6c8af88a7c 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -1,5 +1,6 @@ import sys import re +import os import numpy as np import openmc @@ -14,6 +15,14 @@ class StatePoint(object): of a given batch). Statepoints can be used to analyze tally results as well as restart a simulation. + Parameters + ---------- + filename : str + Path to file to load + autolink : bool, optional + Whether to automatically link in metadata from a summary.h5 + file. Defaults to True. + Attributes ---------- cmfd_on : bool @@ -93,7 +102,7 @@ class StatePoint(object): """ - def __init__(self, filename): + def __init__(self, filename, autolink=True): import h5py self._f = h5py.File(filename, 'r') @@ -116,10 +125,17 @@ class StatePoint(object): # Set flags for what data has been read self._meshes_read = False self._tallies_read = False - self._summary = False + self._summary = None self._global_tallies = None self._sparse = False + # Automatically link in a summary file if one exists + if autolink: + path_summary = os.path.join(os.path.dirname(filename), 'summary.h5') + if os.path.exists(path_summary): + su = openmc.Summary(path_summary) + self.link_with_summary(su) + def close(self): self._f.close() @@ -606,12 +622,17 @@ class StatePoint(object): Raises ------ + RuntimeError + If a Summary object has already been linked. ValueError An error when the argument passed to the 'summary' parameter is not an openmc.Summary object. """ + if self.summary is not None: + raise RuntimeError('A Summary object has already been linked.') + if not isinstance(summary, openmc.summary.Summary): msg = 'Unable to link statepoint with "{0}" which ' \ 'is not a Summary object'.format(summary)