Avoid adding ParentNuclideFilter twice when calling prepare_tallies (#3506)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Jonathan Shimwell 2025-07-18 18:23:02 +02:00 committed by GitHub
parent 8be65513b7
commit a649d7bc69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -243,7 +243,7 @@ def prepare_tallies(
for f in tally.filters:
if isinstance(f, openmc.ParticleFilter):
if list(f.bins) == ['photon']:
tally.filters.append(filter)
if not tally.contains_filter(openmc.ParentNuclideFilter):
tally.filters.append(filter)
break
return nuclides

View file

@ -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