diff --git a/include/postprocessors/MultiPeriodAverager.h b/include/postprocessors/MultiPeriodAverager.h index 9b198bb8f5c6..0a4436ce6ab7 100644 --- a/include/postprocessors/MultiPeriodAverager.h +++ b/include/postprocessors/MultiPeriodAverager.h @@ -29,16 +29,16 @@ class MultiPeriodAverager : public GeneralPostprocessor Real _value; /// Where we are going to be storing the next average while we calculate it Real _temp_value; - /// The number of periods that have passed - Real _period_count; /// The time when the next period starts Real _next_period_start; - /// The counter for how many periods have passed since we last updated - Real _cyclic_period_count; /// inverse of the frequency const Real _period; - /// the number of periods over which we are averaging - Real _num_periods; /// The previous post process value of the post processor we are averaging over several periods const PostprocessorValue & _pps_value_old; + /// The number of periods that have passed + uint _period_count; + /// The counter for how many periods have passed since we last updated + uint _cyclic_period_count; + /// the number of periods over which we are averaging + uint _num_periods; }; diff --git a/src/postprocessors/MultiPeriodAverager.C b/src/postprocessors/MultiPeriodAverager.C index d191fd02ec8e..261aa73dd9a9 100644 --- a/src/postprocessors/MultiPeriodAverager.C +++ b/src/postprocessors/MultiPeriodAverager.C @@ -17,7 +17,7 @@ MultiPeriodAverager::validParams() InputParameters params = GeneralPostprocessor::validParams(); params.addClassDescription( "Calculate the average value of a post processor over multiple periods"); - params.addRangeCheckedParam("number_of_periods", + params.addRangeCheckedParam("number_of_periods", "number_of_periods > 0", "The number of periods over which you are averaging"); params.addParam( @@ -33,10 +33,11 @@ MultiPeriodAverager::MultiPeriodAverager(const InputParameters & parameters) : GeneralPostprocessor(parameters), _value(0), _temp_value(0), - _period_count(0), _period(1.0 / getParam("cycle_frequency")), - _num_periods(getParam("number_of_periods")), - _pps_value_old(getPostprocessorValueOld("value")) + _pps_value_old(getPostprocessorValueOld("value")), + _period_count(0), + _cyclic_period_count(0), + _num_periods(getParam("number_of_periods")) { _next_period_start = _period; } @@ -46,21 +47,21 @@ MultiPeriodAverager::execute() { // lets check if we will be reaching the next period on the next // time step - if ((_t + _dt - _next_period_start) / _next_period_start >= 1e-6) - { - _period_count += 1; - _cyclic_period_count += 1; - _next_period_start = (_period_count + 1) * _period; - _temp_value += _pps_value_old / _num_periods; + if ((_t + _dt - _next_period_start) / _next_period_start < 1e-6) + return; + + _period_count += 1; + _cyclic_period_count += 1; + _next_period_start = (_period_count + 1) * _period; + _temp_value += _pps_value_old / _num_periods; + + /// if its time to update the average reset the temporary values + if (_cyclic_period_count != _num_periods) + return; - /// if its time to update the average reset the temporary values - if (_cyclic_period_count == _num_periods) - { - _value = _temp_value; - _cyclic_period_count = 0; - _temp_value = 0; - } - } + _value = _temp_value; + _cyclic_period_count = 0; + _temp_value = 0; } Real diff --git a/src/postprocessors/PeriodicTimeIntegratedPostprocessor.C b/src/postprocessors/PeriodicTimeIntegratedPostprocessor.C index 1651c0f9b603..127a966a1507 100644 --- a/src/postprocessors/PeriodicTimeIntegratedPostprocessor.C +++ b/src/postprocessors/PeriodicTimeIntegratedPostprocessor.C @@ -41,10 +41,10 @@ PeriodicTimeIntegratedPostprocessor::execute() MultipliedTimeIntegratedPostprocessor::execute(); // lets check if we will be reaching the next period on the next // time step - if ((_t + _dt - _next_period_start) / _next_period_start >= 1e-6) - { - _period_count++; - _next_period_start = (_period_count + 1) * _period; - this->_value = 0; - } + if ((_t + _dt - _next_period_start) / _next_period_start < 1e-6) + return; + + _period_count++; + _next_period_start = (_period_count + 1) * _period; + this->_value = 0; }