Fix restart k-effective accumulation when generations_per_batch > 1 - #4101
Open
GuySten wants to merge 1 commit into
Open
Fix restart k-effective accumulation when generations_per_batch > 1#4101GuySten wants to merge 1 commit into
GuySten wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix restart k-effective accumulation when
generations_per_batch > 1Description
restart_set_keff()insrc/state_point.cppmixes batch indices and generationindices.
simulation::k_generationcontains one entry per generation, but theaccumulation loop runs over batch indices:
The normalization
nis already a generation count, so the numerator and thedenominator only agree when
gen_per_batch == 1— which is why this has goneunnoticed. With
gen_per_batch > 1the loop sumsrestart_batch - n_inactiveentries taken from the inactive part of
k_generationand then divides bygen_per_batch * n_realizations.For the reported case (
batches = 300,inactive = 100,generations_per_batch = 5), the loop sumsk_generation[100:300]— 200generations that all fall inside the inactive region — and divides by 1000,
giving a restart
simulation::keffof about 0.26 against a true active-batchk-effective of about 1.3.
Two consequences:
simulation::keffnormalizes fission site production, so a k-effective thatis ~5x too low produces ~5x too many fission sites on the first restart
generations. The shared fission bank overflows and OpenMC repeatedly emits
WARNING: The shared fission bank is full. Additional fission sites created in this generation will not be banked. Results may be non-deterministic.k_sum[0]/k_sum[1]values are carried intocalculate_average_keff(), so the mean and standard deviation reported forthe continued active batches are computed from generations that were never
supposed to be part of the active tally.
Fix
Index
k_generationby generation, consistent withcalculate_average_keff(),which accumulates one entry per active generation and normalizes by
gen_per_batch * n_realizations + current_gen:The loop now contributes exactly
gen_per_batch * (restart_batch - n_inactive)terms, matching the
gen_per_batch * n_realizationsdenominator. Thegen_per_batch == 1path is bit-for-bit unchanged, so existing restart resultsare unaffected.
Reproducing
Run an eigenvalue model with
generations_per_batch = 5,inactive = 100,batches = 300, then restart fromstatepoint.300.h5withbatches = 500.Before the fix, the restart begins with a source-normalization k-effective far
from the converged value and the fission bank fills immediately; after the fix,
the restarted run picks up at the statepoint's active-batch k-effective and the
warnings disappear.
Test
tests/unit_tests/test_restart_keff.pyruns a short eigenvalue calculation tobatch 8, restarts from that statepoint for two more batches, and checks the
running average k-effective reported for every restarted generation against the
mean over all active generations simulated so far, taken from the restarted
run's own statepoint. The comparison is exact to the precision of the printed
value. It also asserts that no fission-bank-full warning is emitted, so the
reported symptom has its own assertion.
The test is parametrized over
generations_per_batchof 1 and 5. The secondcase fails on
develop-- the reported average is low by about a factor offive and the bank warning fires on every generation -- while the first guards
the unchanged single-generation path.
The obvious stronger test, asserting that a restarted run reproduces the
uninterrupted run bit-for-bit, is not currently possible:
openmc_statepoint_load()restores the seed and stride but notsimulation::total_gen, which enters the per-particle seed alongsideoverall_generation(). A restarted run therefore draws a different randomstream than the original run would have at the same generation. Making restart
bit-reproducible would change the results of every restart run and seems worth
a separate discussion.
Credit
Reported and diagnosed by @A_Bohemian on the OpenMC forum:
https://openmc.discourse.group/t/possible-restart-bug-with-generations-per-batch-1-fission-bank-fills-after-loading-statepoint/6456
Checklist
I have run clang-format (version 18) on any C++ source files (if applicable)I have made corresponding changes to the documentation (if applicable)