Skip to content

Commit

Permalink
Merge pull request #255 from gsgall/devel
Browse files Browse the repository at this point in the history
Changing types to help with comparison of counters
  • Loading branch information
lindsayad authored Aug 6, 2024
2 parents b3f97c3 + fa2a859 commit cd1fedc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 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
unsigned int _period_count;
/// The counter for how many periods have passed since we last updated
unsigned int _cyclic_period_count;
/// the number of periods over which we are averaging
unsigned int _num_periods;
};
5 changes: 4 additions & 1 deletion include/postprocessors/PeriodicTimeIntegratedPostprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class PeriodicTimeIntegratedPostprocessor : public MultipliedTimeIntegratedPostp
virtual void execute() override;

protected:
/// the period of time over which to integrate
const Real _period;
Real _period_count;
/// the total number of periods that have occured
unsigned int _period_count;
/// the point in the time when the next period begins
Real _next_period_start;
};
41 changes: 21 additions & 20 deletions src/postprocessors/MultiPeriodAverager.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ 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",
"number_of_periods > 0",
"The number of periods over which you are averaging");
params.addRangeCheckedParam<unsigned int>("number_of_periods",
"number_of_periods > 0",
"The number of periods over which you are averaging");
params.addParam<PostprocessorName>(
"value", "The name of the postprocessor you would like to average over multiple periods");
params.addRequiredRangeCheckedParam<Real>(
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 cd1fedc

Please sign in to comment.