From e360cb467e9b97412c4fcbfbc58c0ff4226b5014 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 6 Mar 2025 17:39:05 +0100 Subject: [PATCH] added stable and unstable nuclides to the Chain object (#3338) Co-authored-by: Paul Romano --- openmc/deplete/chain.py | 20 ++++++++++++++++++-- tests/unit_tests/test_deplete_chain.py | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index 2e81250dcf..4998a2c3d9 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -12,6 +12,7 @@ from collections import defaultdict, namedtuple from collections.abc import Mapping, Iterable from numbers import Real, Integral from warnings import warn +from typing import List import lxml.etree as ET import scipy.sparse as sp @@ -244,6 +245,10 @@ class Chain: Reactions that are tracked in the depletion chain nuclide_dict : dict of str to int Maps a nuclide name to an index in nuclides. + stable_nuclides : list of openmc.deplete.Nuclide + List of stable nuclides available in the chain. + unstable_nuclides : list of openmc.deplete.Nuclide + List of unstable nuclides available in the chain. fission_yields : None or iterable of dict List of effective fission yields for materials. Each dictionary should be of the form ``{parent: {product: yield}}`` with @@ -256,7 +261,7 @@ class Chain: """ def __init__(self): - self.nuclides = [] + self.nuclides: List[Nuclide] = [] self.reactions = [] self.nuclide_dict = {} self._fission_yields = None @@ -272,7 +277,18 @@ class Chain: """Number of nuclides in chain.""" return len(self.nuclides) - def add_nuclide(self, nuclide): + + @property + def stable_nuclides(self) -> List[Nuclide]: + """List of stable nuclides available in the chain""" + return [nuc for nuc in self.nuclides if nuc.half_life is None] + + @property + def unstable_nuclides(self) -> List[Nuclide]: + """List of unstable nuclides available in the chain""" + return [nuc for nuc in self.nuclides if nuc.half_life is not None] + + def add_nuclide(self, nuclide: Nuclide): """Add a nuclide to the depletion chain Parameters diff --git a/tests/unit_tests/test_deplete_chain.py b/tests/unit_tests/test_deplete_chain.py index 9753a53f73..13267cb051 100644 --- a/tests/unit_tests/test_deplete_chain.py +++ b/tests/unit_tests/test_deplete_chain.py @@ -86,6 +86,14 @@ def test_from_endf(endf_chain): assert nuc == chain[nuc.name] +def test_unstable_nuclides(simple_chain: Chain): + assert [nuc.name for nuc in simple_chain.unstable_nuclides] == ["A", "B"] + + +def test_stable_nuclides(simple_chain: Chain): + assert [nuc.name for nuc in simple_chain.stable_nuclides] == ["H1", "C"] + + def test_from_xml(simple_chain): """Read chain_test.xml and ensure all values are correct.""" # Unfortunately, this routine touches a lot of the code, but most of