diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index fb638e5c21..3d4c93ac83 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -5,6 +5,7 @@ to run a full depletion simulation. """ from collections import namedtuple +from collections import defaultdict from collections.abc import Iterable import os from pathlib import Path @@ -376,14 +377,17 @@ class FissionYieldHelper(ABC): Attributes ---------- - constant_yields : dict of str to :class:`openmc.deplete.FissionYield` + constant_yields : collections.defaultdict Fission yields for all nuclides that only have one set of - fission yield data. Can be accessed as ``{parent: {product: yield}}`` + fission yield data. Dictionary of form ``{str: {str: float}}`` + representing yields for ``{parent: {product: yield}}``. Default + return object is an empty dictionary + """ def __init__(self, chain_nuclides): self._chain_nuclides = {} - self._constant_yields = {} + self._constant_yields = defaultdict(dict) # Get all nuclides with fission yield data for nuc in chain_nuclides: @@ -407,14 +411,16 @@ class FissionYieldHelper(ABC): Parameters ---------- local_mat_index : int - Index for material tracked on this process that - exists in :attr:`local_mat_index` and fits within - the first axis in :attr:`results` + Index for the material with requested fission yields. + Should correspond to the material represented in + ``mat_indexes[local_mat_index]`` during + :meth:`generate_tallies`. Returns ------- - library : dict - Dictionary of ``{parent: {product: fyield}}`` + library : collections.abc.Mapping + Dictionary-like object mapping ``{str: {str: float}``. + This reflects fission yields for ``{parent: {product: fyield}}``. """ @staticmethod diff --git a/openmc/deplete/helpers.py b/openmc/deplete/helpers.py index 56644a3bba..f6e6bb04da 100644 --- a/openmc/deplete/helpers.py +++ b/openmc/deplete/helpers.py @@ -5,6 +5,7 @@ from copy import deepcopy from itertools import product from numbers import Real import bisect +from collections import defaultdict from numpy import dot, zeros, newaxis @@ -179,9 +180,11 @@ class ConstantFissionYieldHelper(FissionYieldHelper): Attributes ---------- - constant_yields : dict of str to :class:`openmc.deplete.FissionYield` + constant_yields : collections.defaultdict Fission yields for all nuclides that only have one set of - fission yield data. Can be accessed as ``{parent: {product: yield}}`` + fission yield data. Dictionary of form ``{str: {str: float}}`` + representing yields for ``{parent: {product: yield}}``. Default + return object is an empty dictionary energy : float Energy of fission yield libraries. """ @@ -237,7 +240,7 @@ class ConstantFissionYieldHelper(FissionYieldHelper): Returns ------- - library : dict + library : collections.defaultdict Dictionary of ``{parent: {product: fyield}}`` """ return self.constant_yields @@ -282,6 +285,11 @@ class FissionYieldCutoffHelper(TalliedFissionYieldHelper): fast_yields : dict Dictionary of the form ``{parent: {product: yield}}`` with fast yields + constant_yields : collections.defaultdict + Fission yields for all nuclides that only have one set of + fission yield data. Dictionary of form ``{str: {str: float}}`` + representing yields for ``{parent: {product: yield}}``. Default + return object is an empty dictionary results : numpy.ndarray Array of fission rate fractions with shape ``(n_mats, 2, n_nucs)``. ``results[:, 0]`` @@ -417,7 +425,7 @@ class FissionYieldCutoffHelper(TalliedFissionYieldHelper): Returns ------- - library : dict + library : collections.defaultdict Dictionary of ``{parent: {product: fyield}}`` """ yields = self.constant_yields @@ -469,9 +477,11 @@ class AveragedFissionYieldHelper(TalliedFissionYieldHelper): Attributes ---------- - constant_yields : dict of str to :class:`openmc.deplete.FissionYield` + constant_yields : collections.defaultdict Fission yields for all nuclides that only have one set of - fission yield data. Can be accessed as ``{parent: {product: yield}}`` + fission yield data. Dictionary of form ``{str: {str: float}}`` + representing yields for ``{parent: {product: yield}}``. Default + return object is an empty dictionary results : None or numpy.ndarray If tallies have been generated and unpacked, then the array will have shape ``(n_mats, n_tnucs)``, where ``n_mats`` is the number @@ -569,12 +579,13 @@ class AveragedFissionYieldHelper(TalliedFissionYieldHelper): Returns ------- - library : dict - Dictionary of ``{parent: {product: fyield}}`` + library : collections.defaultdict + Dictionary of ``{parent: {product: fyield}}``. Default return + value is an empty dictionary """ if not self._tally_nucs: return self.constant_yields - mat_yields = {} + mat_yields = defaultdict(dict) average_energies = self.results[local_mat_index] for avg_e, nuc in zip(average_energies, self._tally_nucs): nuc_energies = nuc.yield_energies