From ddabe1c8c557b3d1228a6f5cb661bac5bb6582e4 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Sat, 30 May 2026 05:25:22 +0200 Subject: [PATCH] Avoid storing inconsistent sum/sum_sq on summed D1S tallies (#3949) Co-authored-by: shimwell Co-authored-by: Paul Romano --- openmc/deplete/d1s.py | 11 ++++++----- tests/unit_tests/test_d1s.py | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/openmc/deplete/d1s.py b/openmc/deplete/d1s.py index bc99fc42d..d85d2e8a7 100644 --- a/openmc/deplete/d1s.py +++ b/openmc/deplete/d1s.py @@ -186,8 +186,6 @@ def apply_time_correction( # Apply TCF, broadcasting to the correct dimensions tcf.shape = (1, -1, 1, 1, 1) - new_tally._sum = tally_sum * tcf - new_tally._sum_sq = tally_sum_sq * (tcf*tcf) new_tally._mean = tally_mean * tcf new_tally._std_dev = tally_std_dev * tcf @@ -196,6 +194,8 @@ def apply_time_correction( if sum_nuclides: # Sum over parent nuclides (note that when combining different bins for # parent nuclide, we can't work directly on sum_sq) + new_tally._sum = None + new_tally._sum_sq = None new_tally._mean = new_tally.mean.sum(axis=1).reshape(shape) new_tally._std_dev = np.linalg.norm(new_tally.std_dev, axis=1).reshape(shape) new_tally._derived = True @@ -203,9 +203,10 @@ def apply_time_correction( # Remove ParentNuclideFilter new_tally.filters.pop(i_filter) else: - # Change shape back to (filter combinations, nuclides, scores) - new_tally._sum.shape = shape - new_tally._sum_sq.shape = shape + # Apply TCF and change shape back to (filter combinations, nuclides, + # scores) + new_tally._sum = (tally_sum * tcf).reshape(shape) + new_tally._sum_sq = (tally_sum_sq * (tcf*tcf)).reshape(shape) new_tally._mean.shape = shape new_tally._std_dev.shape = shape diff --git a/tests/unit_tests/test_d1s.py b/tests/unit_tests/test_d1s.py index 8f3b62f40..49c1b3049 100644 --- a/tests/unit_tests/test_d1s.py +++ b/tests/unit_tests/test_d1s.py @@ -150,3 +150,7 @@ def test_apply_time_correction(run_in_tmpdir): result_summed.get_reshaped_data() result.get_pandas_dataframe() result_summed.get_pandas_dataframe() + + # The summed tally is derived, so sum/sum_sq are None + assert result_summed.sum is None + assert result_summed.sum_sq is None