diff --git a/docs/source/pythonapi/data.rst b/docs/source/pythonapi/data.rst index 6f5c006c2..287738774 100644 --- a/docs/source/pythonapi/data.rst +++ b/docs/source/pythonapi/data.rst @@ -61,6 +61,7 @@ Core Functions atomic_mass atomic_weight + decay_constant dose_coefficients gnd_name half_life diff --git a/openmc/data/data.py b/openmc/data/data.py index 3a3cf5826..71b93293e 100644 --- a/openmc/data/data.py +++ b/openmc/data/data.py @@ -3,7 +3,7 @@ import json import os import re from pathlib import Path -from math import sqrt +from math import sqrt, log from warnings import warn # Isotopic abundances from Meija J, Coplen T B, et al, "Isotopic compositions @@ -202,7 +202,7 @@ _GND_NAME_RE = re.compile(r'([A-Zn][a-z]*)(\d+)((?:_[em]\d+)?)') # Used in half_life function as a cache _HALF_LIFE = {} - +_LOG_TWO = log(2.0) def atomic_mass(isotope): """Return atomic mass of isotope in atomic mass units. @@ -283,6 +283,8 @@ def half_life(isotope): Half-life values are from the `ENDF/B-VIII.0 decay sublibrary `_. + .. versionadded:: 0.13.1 + Parameters ---------- isotope : str @@ -302,6 +304,35 @@ def half_life(isotope): return _HALF_LIFE.get(isotope.lower()) + +def decay_constant(isotope): + """Return decay constant of isotope in [s^-1] + + Decay constants are based on half-life values from the + :func:`~openmc.data.half_life` function. When the isotope is stable, a decay + constant of zero is returned. + + .. versionadded:: 0.13.1 + + Parameters + ---------- + isotope : str + Name of isotope, e.g., 'Pu239' + + Returns + ------- + float + Decay constant of isotope in [s^-1] + + See also + -------- + openmc.data.half_life + + """ + t = half_life(isotope) + return _LOG_TWO / t if t else 0.0 + + def water_density(temperature, pressure=0.1013): """Return the density of liquid water at a given temperature and pressure. diff --git a/openmc/material.py b/openmc/material.py index 1341746dc..e8285de7c 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -3,7 +3,6 @@ from collections.abc import Iterable from copy import deepcopy from numbers import Real from pathlib import Path -import math import re import warnings from xml.etree import ElementTree as ET @@ -145,20 +144,10 @@ class Material(IDManagerMixin): return string - @property def activity(self): """Returns the total activity of the material in Becquerels.""" - - atoms_per_barn_cm = self.get_nuclide_atom_densities() - total_activity = 0 - for key, value in atoms_per_barn_cm.items(): - half_life = openmc.data.half_life(key) - if half_life: - total_activity += value / half_life - total_activity *= math.log(2) * 1e24 * self.volume - - return total_activity + return sum(self.get_nuclide_activity().values()) @property def name(self): @@ -861,6 +850,23 @@ class Material(IDManagerMixin): return nuclides + def get_nuclide_activity(self): + """Return activity in [Bq] for each nuclide in the material + + .. versionadded:: 0.13.1 + + Returns + ------- + dict + Dictionary whose keys are nuclide names and values are activity in + [Bq]. + """ + activity = {} + for nuclide, atoms in self.get_nuclide_atoms().items(): + inv_seconds = openmc.data.decay_constant(nuclide) + activity[nuclide] = inv_seconds * atoms + return activity + def get_nuclide_atoms(self): """Return number of atoms of each nuclide in the material diff --git a/tests/unit_tests/test_data_misc.py b/tests/unit_tests/test_data_misc.py index 6a81fb1e0..c3f7e3cff 100644 --- a/tests/unit_tests/test_data_misc.py +++ b/tests/unit_tests/test_data_misc.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from collections.abc import Mapping +from math import log import os from pathlib import Path @@ -126,3 +126,14 @@ def test_zam(): assert openmc.data.zam('Am242_m10') == (95, 242, 10) with pytest.raises(ValueError): openmc.data.zam('garbage') + + +def test_half_life(): + assert openmc.data.half_life('H2') is None + assert openmc.data.half_life('U235') == pytest.approx(2.22102e16) + assert openmc.data.half_life('Am242') == pytest.approx(57672.0) + assert openmc.data.half_life('Am242_m1') == pytest.approx(4449622000.0) + assert openmc.data.decay_constant('H2') == 0.0 + assert openmc.data.decay_constant('U235') == pytest.approx(log(2.0)/2.22102e16) + assert openmc.data.decay_constant('Am242') == pytest.approx(log(2.0)/57672.0) + assert openmc.data.decay_constant('Am242_m1') == pytest.approx(log(2.0)/4449622000.0)