openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

Allow zero bins in tally triggers #2928

Closed tjlaboss closed 16 hours ago

tjlaboss commented 1 month ago

Resolve https://github.com/openmc-dev/openmc/issues/2899

Description

Add the ability to ignore tally bins with zero scores when evaluating tally triggers.

Checklist

Questions and Discussion

OpenMC's tally trigger behavior

After OpenMC completes inactive batches, it runs a few active batches to begin gathering tally statistics. Then, tally triggers are evaluated.

This can present a problem with the new 'allow_zero' option. When triggers are evaluated this early, tally bins may not yet have any scores. Normally, this sets the error metric to infinity, but when allow_zero == True, the trigger can "fire" prematurely if none of the tally bins have any hits yet. This can happen for rare events, such as shielding problems and small-xs reactions.

Currently, this check is performed immediately after those initial active batches are performed, regardless of the user's tally trigger 'trigger_batch_interval' setting; let's call this "interval 0". In commit 29b07827f8d48c4e8eb5385f58c777a1f8441787, check_triggers() is changed to skip "interval 0", so that the check is only performed after each full interval. This way, users can ensure a minimum number of active batches and avoid false positives when zero-score bins are allowed.

This does change the default tally trigger behavior. Since the default 'trigger_batch_interval' is 1, this will add 1 additional batch before checking tally triggers even if they do not enable allow_zero on any tallies. I think this is the best balance between straightforwardly addressing the problem and being unobtrusive to existing tally trigger users, but let's discuss.

Alternatives

Testing

Is the single unit test sufficient, or is a regression test necessary as well?

Bool

How do we want to handle Booleans in the XML, without using eval (unsafe) or distutils (deprecated)? Here, I just check if a lowercase string is in ("true", "1"), or ("false", "0"), and otherwise crash. This is similar to how bools are handled in settings.py, but with the inconsistency that an unrecognized string (e.g., "rtue" or "yes") won't default to False.

tjlaboss commented 1 month ago

Triggers unsatisfied, max unc./thresh. is 1.0000000000000002 for (n,p) in tally 3

~Wonder if this is floating point issue or a data library difference vs. the ENDF and JEFF libraries I tested on. Marking as draft...~

...reproduced this using the NNDC data. Added more particles, and now the triggers are satisfied early as expected.

tjlaboss commented 6 days ago

This makes sense to me. I'll rename the parameter to ignore_zeros, revert 29b07827f8d48c4e8eb5385f58c777a1f8441787, make a note in the documentation, and add more particles to the test case.

paulromano commented 6 days ago

Thanks @tjlaboss! Please ping me when the PR is ready for another look

tjlaboss commented 3 days ago

@paulromano, thanks for the review. The requested changes have been made and the CI tests have passed.