Skip to content

Commit

Permalink
Changing types to help with comparison of counters
Browse files Browse the repository at this point in the history
addresses shannon-lab#253
  • Loading branch information
gsgall committed Aug 6, 2024
1 parent df9b9b7 commit 644c527
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
12 changes: 6 additions & 6 deletions include/postprocessors/MultiPeriodAverager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
37 changes: 19 additions & 18 deletions src/postprocessors/MultiPeriodAverager.C
Original file line number Diff line number Diff line change
Expand Up @@ -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<Real>("number_of_periods",
params.addRangeCheckedParam<uint>("number_of_periods",
"number_of_periods > 0",
"The number of periods over which you are averaging");
params.addParam<PostprocessorName>(
Expand All @@ -33,10 +33,11 @@ MultiPeriodAverager::MultiPeriodAverager(const InputParameters & parameters)
: GeneralPostprocessor(parameters),
_value(0),
_temp_value(0),
_period_count(0),
_period(1.0 / getParam<Real>("cycle_frequency")),
_num_periods(getParam<Real>("number_of_periods")),
_pps_value_old(getPostprocessorValueOld("value"))
_pps_value_old(getPostprocessorValueOld("value")),
_period_count(0),
_cyclic_period_count(0),
_num_periods(getParam<uint>("number_of_periods"))
{
_next_period_start = _period;
}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/postprocessors/PeriodicTimeIntegratedPostprocessor.C
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 644c527

Please sign in to comment.