From 3f42fc8505a37af535cf5786e14c38891da3a034 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 8 Aug 2019 08:50:32 -0500 Subject: [PATCH] Remove FissionYieldHelper.libraries; Return from compute_yields Previously the yields were appended into the libraries attribute. Now, the yields are returned directly and not appended at all. It is up to the caller to place these yields in the correct location. The Operator maintains a list of of the libraries that is updated through the unpacking method, and then set onto the Chain after working through all local materials --- openmc/deplete/helpers.py | 26 ++++++++---------------- openmc/deplete/operator.py | 7 +++++-- tests/unit_tests/test_deplete_helpers.py | 5 +---- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/openmc/deplete/helpers.py b/openmc/deplete/helpers.py index 8f35fac433..ac81d0ac7a 100644 --- a/openmc/deplete/helpers.py +++ b/openmc/deplete/helpers.py @@ -163,7 +163,7 @@ class FissionYieldHelper(object): Parameters ---------- - chain_nuclides : iterable of openmc.deplete.nuclide + chain_nuclides : iterable of openmc.deplete.Nuclide Nuclides tracked in the depletion chain. Not necessary that all have yield data. n_bmats : int @@ -176,15 +176,9 @@ class FissionYieldHelper(object): results : numpy.ndarray Array of tally results for this process with shape ``(n_local_mat, n_energy, n_nucs)`` - libraries : list of dict - List of fission yield dictionaries of the form - ``{parent: {product: yield}}``. Populated in - :meth:`compute_yields` and reset during - :meth:`unpack`. """ def __init__(self, chain_nuclides, n_bmats): - self.libraries = [] self._chain_nuclides = {} self._chain_set = set() self._tally_map = {} @@ -245,7 +239,7 @@ class FissionYieldHelper(object): Parameters ---------- nuclides : iterable of str - nuclides with non-zero densities that are candidates + Nuclides with non-zero densities that are candidates for the fission tally. Not necessary that all are nuclides with fission yields, but at least one must be @@ -275,9 +269,6 @@ class FissionYieldHelper(object): def unpack(self): """Unpack fission rate tallies to produce :attr:`results` - - Resets :attr:`libraries` under the assumption this is called - during the :class:`openmc.deplete.Operator` unpacking process """ # if this process is not responsible for depleting anything # [more processes than burnable materials] @@ -285,9 +276,6 @@ class FissionYieldHelper(object): if self.local_indexes.size == 0: return - # clear old libraries - self.libraries = [] - # get view into tally results # new shape: [material, energy, parent nuclide] result_view = self._reaction_tally.results[..., 1].reshape( @@ -312,7 +300,7 @@ class FissionYieldHelper(object): def compute_yields(self, local_mat_index): """Compute single fission yields using :attr:`results` - Produces a new library in :attr:`self.libraries` + Produces a new library in :attr:`libraries` Parameters ---------- @@ -320,6 +308,11 @@ class FissionYieldHelper(object): Index for material tracked on this process that exists in :attr:`local_mat_index` and fits within the first axis in :attr:`results` + + Returns + ------- + library : dict + Dictionary of ``{parent: {product: fyield}}`` """ tally_results = self.results[local_mat_index] @@ -337,9 +330,8 @@ class FissionYieldHelper(object): initial_library[parent] += yield_data * fiss_frac # convert to dictionary that can be passed to Chain.form_matrix - # {parent: {product: yield}} library = {} for k, yield_obj in initial_library.items(): library[k.name] = dict(zip(yield_obj.products, yield_obj.yields)) - self.libraries.append(library) + return library diff --git a/openmc/deplete/operator.py b/openmc/deplete/operator.py index 0c8c72987b..d99c96f185 100644 --- a/openmc/deplete/operator.py +++ b/openmc/deplete/operator.py @@ -565,6 +565,9 @@ class Operator(TransportOperator): self._energy_helper.reset() self._fsn_yield_helper.unpack() + # Store fission yield dictionaries + fission_yields = [] + # Create arrays to store fission Q values, reaction rates, and nuclide # numbers, zeroed out in material iteration number = np.empty(rates.n_nuc) @@ -587,7 +590,7 @@ class Operator(TransportOperator): mat_index, nuc_ind, react_ind) # Compute fission yields for this material - self._fsn_yield_helper.compute_yields(i) + fission_yields.append(self._fsn_yield_helper.compute_yields(i)) # Accumulate energy from fission self._energy_helper.update(tally_rates[:, fission_ind], mat_index) @@ -603,7 +606,7 @@ class Operator(TransportOperator): rates *= power / energy # Store new fission yields on the chain - self.chain.fission_yields = self._fsn_yield_helper.libraries + self.chain.fission_yields = fission_yields return OperatorResult(k_combined, rates) diff --git a/tests/unit_tests/test_deplete_helpers.py b/tests/unit_tests/test_deplete_helpers.py index 5db979098b..15ae1550ed 100644 --- a/tests/unit_tests/test_deplete_helpers.py +++ b/tests/unit_tests/test_deplete_helpers.py @@ -91,9 +91,6 @@ def test_fission_yield_helper(): } } - assert len(helper.libraries) == 0 - helper.compute_yields(0) - assert len(helper.libraries) == 1 - act_library = helper.libraries[0] + act_library = helper.compute_yields(0) for parent, sub_yields in exp_lib.items(): assert act_library[parent] == pytest.approx(sub_yields)