1+ from __future__ import annotations
2+
13import itertools
24import json
35import os
46import re
57from pathlib import Path
68from math import sqrt , log
9+ from typing import TYPE_CHECKING , Literal
710from warnings import warn
811
912from endf .data import (ATOMIC_NUMBER , ATOMIC_SYMBOL , ELEMENT_SYMBOL ,
1013 EV_PER_MEV , K_BOLTZMANN , gnds_name , zam )
1114
15+ import openmc
16+ from openmc .checkvalue import PathLike
17+
18+ if TYPE_CHECKING :
19+ from openmc .deplete import Chain
20+
1221gnds_name .__module__ = __name__
1322zam .__module__ = __name__
1423
@@ -296,25 +305,47 @@ def atomic_weight(element):
296305 raise ValueError (f"No naturally-occurring isotopes for element '{ element } '." )
297306
298307
299- def half_life (isotope ):
308+ def half_life (
309+ isotope : str ,
310+ chain_file : Literal [False ] | None | PathLike | Chain = False
311+ ) -> float | None :
300312 """Return half-life of isotope in seconds or None if isotope is stable
301313
302- Half-life values are from the `ENDF/B-VIII.0 decay sublibrary
303- <https://www.nndc.bnl.gov/endf-b8.0/download.html>`_.
314+ By default, half-life values are from the `ENDF/B-VIII.0 decay sublibrary
315+ <https://www.nndc.bnl.gov/endf-b8.0/download.html>`_. A depletion chain can
316+ also be used as the source of half-life values.
304317
305318 .. versionadded:: 0.13.1
306319
320+ .. versionchanged:: 0.15.4
321+ Added the ``chain_file`` argument.
322+
307323 Parameters
308324 ----------
309325 isotope : str
310326 Name of isotope, e.g., 'Pu239'
327+ chain_file : False, None, PathLike, or openmc.deplete.Chain, optional
328+ Source of half-life values. If ``False``, only ENDF/B-VIII.0 data is
329+ used. If ``None``, the chain specified by
330+ ``openmc.config['chain_file']`` is used when available. If a path or
331+ :class:`openmc.deplete.Chain` is given, that chain is used. For ``None``
332+ or an explicit chain, nuclides absent from the chain fall back to
333+ ENDF/B-VIII.0 data.
311334
312335 Returns
313336 -------
314- float
315- Half-life of isotope in [s]
337+ float or None
338+ Half-life of isotope in [s], or None if the isotope is stable
316339
317340 """
341+ if chain_file is not False :
342+ if chain_file is not None or openmc .config .get ('chain_file' ) is not None :
343+ # Local import avoids a circular dependency
344+ from openmc .deplete .chain import _get_chain
345+ chain = _get_chain (chain_file )
346+ if isotope in chain :
347+ return chain [isotope ].half_life
348+
318349 global _HALF_LIFE
319350 if not _HALF_LIFE :
320351 # Load ENDF/B-VIII.0 data from JSON file
@@ -324,7 +355,10 @@ def half_life(isotope):
324355 return _HALF_LIFE .get (isotope .lower ())
325356
326357
327- def decay_constant (isotope ):
358+ def decay_constant (
359+ isotope : str ,
360+ chain_file : Literal [False ] | None | PathLike | Chain = False
361+ ) -> float :
328362 """Return decay constant of isotope in [s^-1]
329363
330364 Decay constants are based on half-life values from the
@@ -333,10 +367,20 @@ def decay_constant(isotope):
333367
334368 .. versionadded:: 0.13.1
335369
370+ .. versionchanged:: 0.15.4
371+ Added the ``chain_file`` argument.
372+
336373 Parameters
337374 ----------
338375 isotope : str
339376 Name of isotope, e.g., 'Pu239'
377+ chain_file : False, None, PathLike, or openmc.deplete.Chain, optional
378+ Source of half-life values. If ``False``, only ENDF/B-VIII.0 data is
379+ used. If ``None``, the chain specified by
380+ ``openmc.config['chain_file']`` is used when available. If a path or
381+ :class:`openmc.deplete.Chain` is given, that chain is used. For ``None``
382+ or an explicit chain, nuclides absent from the chain fall back to
383+ ENDF/B-VIII.0 data.
340384
341385 Returns
342386 -------
@@ -348,7 +392,7 @@ def decay_constant(isotope):
348392 openmc.data.half_life
349393
350394 """
351- t = half_life (isotope )
395+ t = half_life (isotope , chain_file )
352396 return _LOG_TWO / t if t else 0.0
353397
354398
@@ -496,5 +540,3 @@ def isotopes(element: str) -> list[tuple[str, float]]:
496540 result .append (kv )
497541
498542 return result
499-
500-
0 commit comments