From 346f751deb61f7f3b373855d1f4b2e7a27ae8228 Mon Sep 17 00:00:00 2001 From: John Vincent Cauilan <64677361+johvincau@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:51:30 -0500 Subject: [PATCH] Adjust decay data reader to better handle non-normalized branching ratios (#3080) Co-authored-by: Paul Romano --- openmc/deplete/chain.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index 1d383498052..2e81250dcfb 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -386,24 +386,31 @@ def from_endf(cls, decay_files, fpy_files, neutron_files, if not data.nuclide['stable'] and data.half_life.nominal_value != 0.0: nuclide.half_life = data.half_life.nominal_value nuclide.decay_energy = data.decay_energy.nominal_value - sum_br = 0.0 - for i, mode in enumerate(data.modes): + branch_ratios = [] + branch_ids = [] + for mode in data.modes: type_ = ','.join(mode.modes) if mode.daughter in decay_data: target = mode.daughter else: print('missing {} {} {}'.format( - parent, ','.join(mode.modes), mode.daughter)) + parent, type_, mode.daughter)) target = replace_missing(mode.daughter, decay_data) - - # Write branching ratio, taking care to ensure sum is unity br = mode.branching_ratio.nominal_value - sum_br += br - if i == len(data.modes) - 1 and sum_br != 1.0: - br = 1.0 - sum(m.branching_ratio.nominal_value - for m in data.modes[:-1]) + branch_ratios.append(br) + branch_ids.append((type_, target)) + + if not math.isclose(sum(branch_ratios), 1.0): + max_br = max(branch_ratios) + max_index = branch_ratios.index(max_br) + + # Adjust maximum branching ratio so they sum to unity + new_br = max_br - sum(branch_ratios) + 1.0 + branch_ratios[max_index] = new_br + assert math.isclose(sum(branch_ratios), 1.0) - # Append decay mode + # Append decay modes + for br, (type_, target) in zip(branch_ratios, branch_ids): nuclide.add_decay_mode(type_, target, br) nuclide.sources = data.sources