From a917fd94c15bde5fddff8a72f74e5f2ada17f882 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 18 Jul 2022 14:47:37 -0500 Subject: [PATCH] Add decay_photon_source property on Material --- openmc/data/decay.py | 43 ++++++++++++++++++++++++++++++++++++++++++- openmc/material.py | 12 ++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/openmc/data/decay.py b/openmc/data/decay.py index 2c2505bf5..c372b72e4 100644 --- a/openmc/data/decay.py +++ b/openmc/data/decay.py @@ -1,15 +1,19 @@ from collections.abc import Iterable from io import StringIO from math import log +from pathlib import Path import re from warnings import warn +from xml.etree import ElementTree as ET import numpy as np from uncertainties import ufloat, UFloat +import openmc import openmc.checkvalue as cv +from openmc.exceptions import DataError from openmc.mixin import EqualityMixin -from openmc.stats import Discrete, Tabular, combine_distributions +from openmc.stats import Discrete, Tabular, Univariate, combine_distributions from .data import ATOMIC_SYMBOL, ATOMIC_NUMBER from .function import INTERPOLATION_SCHEME from .endf import Evaluation, get_head_record, get_list_record, get_tab1_record @@ -570,3 +574,40 @@ class Decay(EqualityMixin): self._sources = merged_sources return self._sources + + +_DECAY_PHOTON_SOURCE = {} + + +def decay_photon_source(nuclide): + """Get photon source 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']. + + Parameters + ---------- + nuclide : str + Name of nuclide, e.g., 'Co58' + + Returns + ------- + openmc.stats.Univariate + Distribution of energies in [eV] of photons emitted from decay + """ + if not _DECAY_PHOTON_SOURCE: + chain_file = openmc.config.get('chain_file') + if chain_file is None: + raise DataError( + "A depletion chain file must be specified with " + "openmc.config['chain_file'] in order to load decay data." + ) + + from openmc.deplete import Chain + chain = Chain.from_xml(chain_file) + for nuc in chain.nuclides: + if 'photon' in nuc.sources: + _DECAY_PHOTON_SOURCE[nuc.name] = nuc.sources['photon'] + + return _DECAY_PHOTON_SOURCE.get(nuclide) diff --git a/openmc/material.py b/openmc/material.py index 1b2b46a73..b5c9d70f9 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -255,6 +255,18 @@ class Material(IDManagerMixin): / openmc.data.AVOGADRO return density*self.volume + @property + def decay_photon_source(self): + atoms = self.get_nuclide_atoms() + dists = [] + probs = [] + for nuc, num_atoms in atoms.items(): + source_per_atom = openmc.data.decay_photon_source(nuc) + if source_per_atom is not None: + dists.append(source_per_atom) + probs.append(num_atoms) + return openmc.data.combine_distributions(dists, probs) + @classmethod def from_hdf5(cls, group: h5py.Group): """Create material from HDF5 group