From 171cf8571af46dd4b96410932dec8c359457d8a2 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Fri, 18 Jul 2025 11:00:22 +0200 Subject: [PATCH 1/3] added-check-for-parnucfilter --- openmc/deplete/d1s.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openmc/deplete/d1s.py b/openmc/deplete/d1s.py index e9f8bfe79d6..99913ff5cd8 100644 --- a/openmc/deplete/d1s.py +++ b/openmc/deplete/d1s.py @@ -243,7 +243,9 @@ def prepare_tallies( for f in tally.filters: if isinstance(f, openmc.ParticleFilter): if list(f.bins) == ['photon']: - tally.filters.append(filter) - break - + for filter in tally.filters: + # avoid adding the ParentNuclideFilter multiple times + if isinstance(filter, openmc.ParentNuclideFilter): + break + tally.filters.append(filter) return nuclides From b48342c0371268007d259c639a3062715ad64823 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Fri, 18 Jul 2025 12:04:55 +0200 Subject: [PATCH 2/3] added test for parnucfil addition --- tests/unit_tests/test_d1s.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit_tests/test_d1s.py b/tests/unit_tests/test_d1s.py index 115759489aa..9410f2da2e0 100644 --- a/tests/unit_tests/test_d1s.py +++ b/tests/unit_tests/test_d1s.py @@ -84,6 +84,11 @@ def test_prepare_tallies(model): assert tally.contains_filter(openmc.ParentNuclideFilter) assert sorted(tally.filters[-1].bins) == sorted(radionuclides) + assert len(tally.filters) == 2 + # calling prepare_tallies twice should not add another ParentNuclideFilter + d1s.prepare_tallies(model, chain_file=CHAIN_PATH) + assert len(tally.filters) == 2 + def test_apply_time_correction(run_in_tmpdir): # Make simple sphere model with elemental Ni From c8d19d337db4b8423681875a05a23c889aa5f2cf Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 18 Jul 2025 21:03:05 +0700 Subject: [PATCH 3/3] Simplify logic --- openmc/deplete/d1s.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/openmc/deplete/d1s.py b/openmc/deplete/d1s.py index 99913ff5cd8..311bc2d69cd 100644 --- a/openmc/deplete/d1s.py +++ b/openmc/deplete/d1s.py @@ -243,9 +243,7 @@ def prepare_tallies( for f in tally.filters: if isinstance(f, openmc.ParticleFilter): if list(f.bins) == ['photon']: - for filter in tally.filters: - # avoid adding the ParentNuclideFilter multiple times - if isinstance(filter, openmc.ParentNuclideFilter): - break + if not tally.contains_filter(openmc.ParentNuclideFilter): tally.filters.append(filter) + break return nuclides