Skip to content

Commit db4892f

Browse files
committed
reviewer suggestion on m and lfs
1 parent f9194e3 commit db4892f

3 files changed

Lines changed: 32 additions & 16 deletions

File tree

openmc/deplete/chain.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ def _read_activation_products(evaluation):
134134
Returns
135135
-------
136136
dict
137-
``{mt: {(Z, A, lfs): yield_func}}`` where yield_func is a
137+
``{mt: {(Z, A, m): yield_func}}`` where yield_func is a
138138
:class:`openmc.data.Tabulated1D` giving the yield as a function of
139-
energy. lfs is the level number flag (0=ground, 1=first metastable,
140-
etc.)
139+
energy. m is the isomeric state number (0=ground, 1=first metastable,
140+
etc.), derived by sequentially numbering the excited states in order
141+
of increasing LFS.
141142
"""
142143
results = {}
143144

@@ -207,7 +208,22 @@ def _read_activation_products(evaluation):
207208
openmc.data.Tabulated1D(energy, yield_)
208209

209210
if products:
210-
results[mt] = products
211+
# Remap LFS level numbers to sequential isomeric state numbers.
212+
# LFS in MF9/MF10 refers to the energy level, not the isomeric
213+
# state number. Isomeric states are numbered sequentially:
214+
# ground (LFS=0) -> m=0, then m=1, m=2, ... for excited states
215+
# in order of increasing LFS.
216+
za_groups: dict[tuple[int, int], list[int]] = {}
217+
for (Z, A, lfs) in products:
218+
za_groups.setdefault((Z, A), []).append(lfs)
219+
220+
remapped = {}
221+
for (Z, A), lfs_values in za_groups.items():
222+
lfs_values.sort()
223+
for m, lfs in enumerate(lfs_values):
224+
remapped[(Z, A, m)] = products[(Z, A, lfs)]
225+
226+
results[mt] = remapped
211227

212228
return results
213229

@@ -230,7 +246,7 @@ def _add_isomeric_reactions(nuclide, rx_name, q_value, iso_products,
230246
q_value : float
231247
Q value of the reaction in [eV]
232248
iso_products : dict
233-
``{(Z, A, lfs): yield_func}`` from :func:`_read_activation_products`
249+
``{(Z, A, m): yield_func}`` from :func:`_read_activation_products`
234250
decay_data : dict
235251
Decay data keyed by nuclide name
236252
missing_rx_product : list
@@ -241,8 +257,8 @@ def _add_isomeric_reactions(nuclide, rx_name, q_value, iso_products,
241257
# Map product states to daughter names, filtering missing nuclides
242258
yield_funcs = {} # {daughter_name: yield_func}
243259
ground_state = None
244-
for (Z, A, lfs), yield_func in iso_products.items():
245-
daughter = gnds_name(Z, A, lfs)
260+
for (Z, A, m), yield_func in iso_products.items():
261+
daughter = gnds_name(Z, A, m)
246262

247263
if daughter not in decay_data:
248264
orig_daughter = daughter
@@ -251,15 +267,15 @@ def _add_isomeric_reactions(nuclide, rx_name, q_value, iso_products,
251267
missing_rx_product.append((parent, rx_name, orig_daughter))
252268
continue
253269

254-
# If multiple LFS map to same daughter, keep the one with
270+
# If multiple states map to same daughter, keep the one with
255271
# larger max yield (shouldn't normally happen)
256272
if daughter in yield_funcs:
257273
if np.max(yield_func.y) > np.max(yield_funcs[daughter].y):
258274
yield_funcs[daughter] = yield_func
259275
else:
260276
yield_funcs[daughter] = yield_func
261277

262-
if lfs == 0:
278+
if m == 0:
263279
ground_state = daughter
264280

265281
if not yield_funcs:

tests/unit_tests/test_deplete_chain.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,14 @@ def test_reduce(gnd_simple_chain, endf_chain):
598598
<isomeric_branching reaction="(n,gamma)">
599599
<energies>1e-5 0.0253 1e3 1e5 1e6 1e7</energies>
600600
<product nuclide="Am242">0.9 0.9 0.87 0.84 0.74 0.52</product>
601-
<product nuclide="Am242_m2">0.1 0.1 0.13 0.16 0.26 0.48</product>
601+
<product nuclide="Am242_m1">0.1 0.1 0.13 0.16 0.26 0.48</product>
602602
</isomeric_branching>
603603
</nuclide>
604604
<nuclide name="Am242" half_life="57672.0" decay_modes="1"
605605
decay_energy="0.0" reactions="0">
606606
<decay type="beta-" target="Cm242" branching_ratio="1.0"/>
607607
</nuclide>
608-
<nuclide name="Am242_m2" half_life="4449312000.0" decay_modes="1"
608+
<nuclide name="Am242_m1" half_life="4449312000.0" decay_modes="1"
609609
decay_energy="0.0" reactions="0">
610610
<decay type="IT" target="Am242" branching_ratio="1.0"/>
611611
</nuclide>
@@ -630,13 +630,13 @@ def test_isomeric_branching_chain_roundtrip():
630630
energies, products = am241.isomeric_branching['(n,gamma)']
631631
assert len(energies) == 6
632632
assert 'Am242' in products
633-
assert 'Am242_m2' in products
633+
assert 'Am242_m1' in products
634634

635635
# Check energy-dependent values
636636
assert np.isclose(products['Am242'][0], 0.9)
637637
assert np.isclose(products['Am242'][-1], 0.52)
638-
assert np.isclose(products['Am242_m2'][0], 0.1)
639-
assert np.isclose(products['Am242_m2'][-1], 0.48)
638+
assert np.isclose(products['Am242_m1'][0], 0.1)
639+
assert np.isclose(products['Am242_m1'][-1], 0.48)
640640

641641
# Write and re-read
642642
chain.export_to_xml('chain_iso_rt.xml')

tests/unit_tests/test_deplete_nuclide.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def test_isomeric_branching_xml_roundtrip():
360360
energies = np.array([1e-5, 0.0253, 1e3, 1e5, 1e6, 1e7])
361361
products = {
362362
"Am242": np.array([0.9, 0.9, 0.87, 0.84, 0.74, 0.52]),
363-
"Am242_m2": np.array([0.1, 0.1, 0.13, 0.16, 0.26, 0.48]),
363+
"Am242_m1": np.array([0.1, 0.1, 0.13, 0.16, 0.26, 0.48]),
364364
}
365365
nuc.isomeric_branching["(n,gamma)"] = (energies, products)
366366

@@ -374,7 +374,7 @@ def test_isomeric_branching_xml_roundtrip():
374374
assert iso_elems[0].find("energies") is not None
375375
product_elems = iso_elems[0].findall("product")
376376
assert len(product_elems) == 2
377-
assert {p.get("nuclide") for p in product_elems} == {"Am242", "Am242_m2"}
377+
assert {p.get("nuclide") for p in product_elems} == {"Am242", "Am242_m1"}
378378

379379
# Read back from XML
380380
nuc2 = nuclide.Nuclide.from_xml(elem)

0 commit comments

Comments
 (0)