Add Material.get_nuclide_activity method and decay_constant function

This commit is contained in:
Paul Romano 2022-06-28 09:45:38 -05:00
parent 3c20b1e415
commit 7723ea492c
4 changed files with 64 additions and 15 deletions

View file

@ -61,6 +61,7 @@ Core Functions
atomic_mass
atomic_weight
decay_constant
dose_coefficients
gnd_name
half_life

View file

@ -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
<https://www.nndc.bnl.gov/endf-b8.0/download.html>`_.
.. 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.

View file

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

View file

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