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
This commit is contained in:
Andrew Johnson 2019-08-08 08:50:32 -05:00
parent 5fb8ec2d7a
commit 3f42fc8505
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
3 changed files with 15 additions and 23 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)