From e286940f8eb3e86ac318fdfe146eec6e23deed9a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 6 Aug 2019 17:00:41 -0500 Subject: [PATCH] Pass prev_res onto TransportOperator.__init__ Document that this attribute will either be a ResultsList or None, both on TransportOperator and Operator. --- openmc/deplete/abc.py | 19 +++++++++++++------ openmc/deplete/operator.py | 16 ++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index 25c45b75cc..f074864c68 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -17,6 +17,7 @@ from numpy import nonzero, empty from openmc.data import DataLibrary, JOULE_PER_EV from openmc.checkvalue import check_type, check_greater_than from .chain import Chain +from .results_list import ResultsList OperatorResult = namedtuple('OperatorResult', ['k', 'rates']) OperatorResult.__doc__ = """\ @@ -61,6 +62,8 @@ class TransportOperator(ABC): in initial condition to ensure they exist in the decay chain. Only done for nuclides with reaction rates. Defaults to 1.0e3. + prev_results : ResultsList, optional + Results from a previous depletion calculation. Attributes ---------- @@ -68,8 +71,12 @@ class TransportOperator(ABC): Initial atom density [atoms/cm^3] to add for nuclides that are zero in initial condition to ensure they exist in the decay chain. Only done for nuclides with reaction rates. + prev_res : ResultsList or None + Results from a previous depletion calculation. ``None`` if no + results are to be used. """ - def __init__(self, chain_file=None, fission_q=None, dilute_initial=1.0e3): + def __init__(self, chain_file=None, fission_q=None, dilute_initial=1.0e3, + prev_results=None): self.dilute_initial = dilute_initial self.output_dir = '.' @@ -93,6 +100,11 @@ class TransportOperator(ABC): "of adding depletion_chain to OPENMC_CROSS_SECTIONS", FutureWarning) self.chain = Chain.from_xml(chain_file, fission_q) + if prev_results is None: + self.prev_res = None + else: + check_type("previous results", prev_results, ResultsList) + self.prev_results = prev_res @property def dilute_initial(self): @@ -122,7 +134,6 @@ class TransportOperator(ABC): Eigenvalue and reaction rates resulting from transport operator """ - pass def __enter__(self): # Save current directory and move to specific output directory @@ -157,8 +168,6 @@ class TransportOperator(ABC): Total density for initial conditions. """ - pass - @abstractmethod def get_results_info(self): """Returns volume list, cell lists, and nuc lists. @@ -175,8 +184,6 @@ class TransportOperator(ABC): All burnable materials in the geometry. """ - pass - def finalize(self): pass diff --git a/openmc/deplete/operator.py b/openmc/deplete/operator.py index f60a4a2d4f..f3c432a346 100644 --- a/openmc/deplete/operator.py +++ b/openmc/deplete/operator.py @@ -112,28 +112,24 @@ class Operator(TransportOperator): Initial heavy metal inventory local_mats : list of str All burnable material IDs being managed by a single process - prev_res : ResultsList - Results from a previous depletion calculation + prev_res : ResultsList or None + Results from a previous depletion calculation. ``None`` if no + results are to be used. diff_burnable_mats : bool Whether to differentiate burnable materials with multiple instances """ def __init__(self, geometry, settings, chain_file=None, prev_results=None, diff_burnable_mats=False, fission_q=None, dilute_initial=1.0e3): - super().__init__(chain_file, fission_q, dilute_initial) + super().__init__(chain_file, fission_q, dilute_initial, prev_results) self.round_number = False self.settings = settings self.geometry = geometry self.diff_burnable_mats = diff_burnable_mats - if prev_results is not None: + if self.prev_res is not None: # Reload volumes into geometry - prev_results[-1].transfer_volumes(geometry) - - # Store previous results in operator - self.prev_res = prev_results - else: - self.prev_res = None + self.prev_results[-1].transfer_volumes(geometry) # Differentiate burnable materials with multiple instances if self.diff_burnable_mats: