From ef9494b0580ce508d52235529a507d9f7e61c8be Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Tue, 12 Sep 2023 15:17:48 -0400 Subject: [PATCH] Fix issue #514: Output correct block average values first time after restart --- src/BlockOutput.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/BlockOutput.h b/src/BlockOutput.h index 3adba2c9f..302a427a3 100644 --- a/src/BlockOutput.h +++ b/src/BlockOutput.h @@ -110,21 +110,15 @@ struct BlockAverages : OutputableBase { void InitVals(config_setup::EventSettings const &event) { stepsPerOut = event.frequency; invSteps = 1.0 / stepsPerOut; - if (startStep != 0) { + firstInvSteps = invSteps; + //Handle the case where we are restarting from a checkpoint and the first + //interval is smaller than expected because we create a checkpoint more + //often than the Block output frequency. + if (startStep != 0 && (startStep % stepsPerOut) != 0) { ulong diff; - if (stepsPerOut >= startStep) { - diff = stepsPerOut - startStep; - } else { - diff = startStep - stepsPerOut; - } - firstInvSteps = 1.0 / diff; - } else { - firstInvSteps = invSteps; + diff = stepsPerOut - (startStep % stepsPerOut); + firstInvSteps = 1.0/diff; } - // We only subtract the firstInvSteps on - // the first print with startStep != 0 - // invSteps - firstInvSteps = 1/(stepsPerOut-startStep) - // After the first print enableOut = event.enable; } void AllocBlocks(void);