Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added decay_neutron_energy function to match existing decay_photon_energy #3065

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions openmc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import warnings

from openmc.data import DataLibrary
from openmc.data.decay import _DECAY_ENERGY, _DECAY_PHOTON_ENERGY
from openmc.data.decay import _DECAY_ENERGY, _DECAY_PARTICLE_ENERGY

__all__ = ["config"]

Expand All @@ -25,8 +25,8 @@ def __delitem__(self, key):
del os.environ['OPENMC_MG_CROSS_SECTIONS']
elif key == 'chain_file':
del os.environ['OPENMC_CHAIN_FILE']
# Reset photon source data since it relies on chain file
_DECAY_PHOTON_ENERGY.clear()
# Reset particle source data since it relies on chain file
_DECAY_PARTICLE_ENERGY = {"photon": {}, "neutron": {}}

def __setitem__(self, key, value):
if key == 'cross_sections':
Expand All @@ -39,8 +39,8 @@ def __setitem__(self, key, value):
elif key == 'chain_file':
self._set_path(key, value)
os.environ['OPENMC_CHAIN_FILE'] = str(value)
# Reset photon source data since it relies on chain file
_DECAY_PHOTON_ENERGY.clear()
# Reset particle source data since it relies on chain file
_DECAY_PARTICLE_ENERGY = {"photon": {}, "neutron": {}}
_DECAY_ENERGY.clear()
else:
raise KeyError(f'Unrecognized config key: {key}. Acceptable keys '
Expand Down
78 changes: 63 additions & 15 deletions openmc/data/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
11: 'neutrino'
}

# used to cache values, populated when decay data is loaded
_DECAY_PARTICLE_ENERGY = {"photon": {}, "neutron": {}}
_DECAY_ENERGY = {}


def get_decay_modes(value):
"""Return sequence of decay modes given an ENDF RTYP value.
Expand Down Expand Up @@ -575,32 +579,31 @@ def sources(self):
self._sources = merged_sources
return self._sources


_DECAY_PHOTON_ENERGY = {}


def decay_photon_energy(nuclide: str) -> Optional[Univariate]:
def decay_particle_energy(nuclide: str, particle: str) -> Optional[Univariate]:
"""Get photon energy distribution resulting from the decay of a nuclide

This function relies on data stored in a depletion chain. Before calling it
for the first time, you need to ensure that a depletion chain has been
specified in openmc.config['chain_file'].

.. versionadded:: 0.13.2
.. versionadded:: 0.15.1

Parameters
----------
nuclide : str
Name of nuclide, e.g., 'Co58'
particle : str
Type of particle, e.g., 'photon' or 'neutron'

Returns
-------
openmc.stats.Univariate or None
Distribution of energies in [eV] of photons emitted from decay, or None
if no photon source exists. Note that the probabilities represent
Distribution of energies in [eV] of particle emitted from decay, or None
if no particle source exists. Note that the probabilities represent
intensities, given as [Bq].
"""
if not _DECAY_PHOTON_ENERGY:

if not _DECAY_PARTICLE_ENERGY[particle]:
chain_file = openmc.config.get('chain_file')
if chain_file is None:
raise DataError(
Expand All @@ -611,18 +614,63 @@ def decay_photon_energy(nuclide: str) -> Optional[Univariate]:
from openmc.deplete import Chain
chain = Chain.from_xml(chain_file)
for nuc in chain.nuclides:
if 'photon' in nuc.sources:
_DECAY_PHOTON_ENERGY[nuc.name] = nuc.sources['photon']
if particle in nuc.sources:
_DECAY_PARTICLE_ENERGY[particle][nuc.name] = nuc.sources[particle]

# If the chain file contained no sources at all, warn the user
if not _DECAY_PHOTON_ENERGY:
warn(f"Chain file '{chain_file}' does not have any decay photon "
if not _DECAY_PARTICLE_ENERGY[particle]:
warn(f"Chain file '{chain_file}' does not have any decay {particle} "
"sources listed.")

return _DECAY_PHOTON_ENERGY.get(nuclide)
return _DECAY_PARTICLE_ENERGY[particle].get(nuclide)


_DECAY_ENERGY = {}
def decay_photon_energy(nuclide: str) -> Optional[Univariate]:
"""Get photon energy distribution resulting from the decay of a nuclide

This function relies on data stored in a depletion chain. Before calling it
for the first time, you need to ensure that a depletion chain has been
specified in openmc.config['chain_file'].

.. versionadded:: 0.13.2

Parameters
----------
nuclide : str
Name of nuclide, e.g., 'Co58'

Returns
-------
openmc.stats.Univariate or None
Distribution of energies in [eV] of photons emitted from decay, or None
if no photon source exists. Note that the probabilities represent
intensities, given as [Bq].
"""
return decay_particle_energy(nuclide=nuclide, particle="photon")


def decay_neutron_energy(nuclide: str) -> Optional[Univariate]:
"""Get neutron energy distribution resulting from the decay of a nuclide

This function relies on data stored in a depletion chain. Before calling it
for the first time, you need to ensure that a depletion chain has been
specified in openmc.config['chain_file'].

.. versionadded:: 0.15.1

Parameters
----------
nuclide : str
Name of nuclide, e.g., 'N17'

Returns
-------
openmc.stats.Univariate or None
Distribution of energies in [eV] of neutrons emitted from decay, or None
if no neutron source exists. Note that the probabilities represent
intensities, given as [Bq].
"""
return decay_particle_energy(nuclide=nuclide, particle="neutron")


def decay_energy(nuclide: str):
Expand Down