Skip to content

Commit e360cb4

Browse files
shimwellpaulromano
andauthored
added stable and unstable nuclides to the Chain object (#3338)
Co-authored-by: Paul Romano <[email protected]>
1 parent e12c65d commit e360cb4

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

openmc/deplete/chain.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from collections.abc import Mapping, Iterable
1313
from numbers import Real, Integral
1414
from warnings import warn
15+
from typing import List
1516

1617
import lxml.etree as ET
1718
import scipy.sparse as sp
@@ -244,6 +245,10 @@ class Chain:
244245
Reactions that are tracked in the depletion chain
245246
nuclide_dict : dict of str to int
246247
Maps a nuclide name to an index in nuclides.
248+
stable_nuclides : list of openmc.deplete.Nuclide
249+
List of stable nuclides available in the chain.
250+
unstable_nuclides : list of openmc.deplete.Nuclide
251+
List of unstable nuclides available in the chain.
247252
fission_yields : None or iterable of dict
248253
List of effective fission yields for materials. Each dictionary
249254
should be of the form ``{parent: {product: yield}}`` with
@@ -256,7 +261,7 @@ class Chain:
256261
"""
257262

258263
def __init__(self):
259-
self.nuclides = []
264+
self.nuclides: List[Nuclide] = []
260265
self.reactions = []
261266
self.nuclide_dict = {}
262267
self._fission_yields = None
@@ -272,7 +277,18 @@ def __len__(self):
272277
"""Number of nuclides in chain."""
273278
return len(self.nuclides)
274279

275-
def add_nuclide(self, nuclide):
280+
281+
@property
282+
def stable_nuclides(self) -> List[Nuclide]:
283+
"""List of stable nuclides available in the chain"""
284+
return [nuc for nuc in self.nuclides if nuc.half_life is None]
285+
286+
@property
287+
def unstable_nuclides(self) -> List[Nuclide]:
288+
"""List of unstable nuclides available in the chain"""
289+
return [nuc for nuc in self.nuclides if nuc.half_life is not None]
290+
291+
def add_nuclide(self, nuclide: Nuclide):
276292
"""Add a nuclide to the depletion chain
277293
278294
Parameters

tests/unit_tests/test_deplete_chain.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ def test_from_endf(endf_chain):
8686
assert nuc == chain[nuc.name]
8787

8888

89+
def test_unstable_nuclides(simple_chain: Chain):
90+
assert [nuc.name for nuc in simple_chain.unstable_nuclides] == ["A", "B"]
91+
92+
93+
def test_stable_nuclides(simple_chain: Chain):
94+
assert [nuc.name for nuc in simple_chain.stable_nuclides] == ["H1", "C"]
95+
96+
8997
def test_from_xml(simple_chain):
9098
"""Read chain_test.xml and ensure all values are correct."""
9199
# Unfortunately, this routine touches a lot of the code, but most of

0 commit comments

Comments
 (0)