Skip to content

Commit

Permalink
Merge commit 'b3f97c3de1cd29765c01cd10a71ed093907ad5c0'
Browse files Browse the repository at this point in the history
  • Loading branch information
moosetest committed Aug 5, 2024
2 parents c4b7775 + b3f97c3 commit 3aa88af
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/postprocessors/MultiPeriodAverager.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ MultiPeriodAverager::validParams()
InputParameters params = GeneralPostprocessor::validParams();
params.addClassDescription(
"Calculate the average value of a post processor over multiple periods");
params.addParam<Real>("number_of_periods", "The number of periods over which you are averaging");
params.addRangeCheckedParam<Real>("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.addParam<Real>(
params.addRequiredRangeCheckedParam<Real>(
"cycle_frequency",
"cycle_frequency > 0",
"The frequency of the process. Used to calculate the period over which you are integrating.");
return params;
}
Expand All @@ -41,8 +44,9 @@ MultiPeriodAverager::MultiPeriodAverager(const InputParameters & parameters)
void
MultiPeriodAverager::execute()
{
// lets check if we have reached the next period
if (std::abs(_t - _next_period_start) <= _dt * 1e-3)
// 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;
Expand Down
8 changes: 5 additions & 3 deletions src/postprocessors/PeriodicTimeIntegratedPostprocessor.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ PeriodicTimeIntegratedPostprocessor::validParams()
InputParameters params = MultipliedTimeIntegratedPostprocessor::validParams();
params.addClassDescription(
"Integrate a Postprocessor value over a period in time using trapezoidal rule.");
params.addParam<Real>(
params.addRangeCheckedParam<Real>(
"cycle_frequency",
"cycle_frequency > 0",
"The frequency of the process. Used to calculate the period over which you are integrating.");
return params;
}
Expand All @@ -38,8 +39,9 @@ PeriodicTimeIntegratedPostprocessor::execute()
{
// performing the integral
MultipliedTimeIntegratedPostprocessor::execute();
// checking if we are on the next period or not if so reset the integral
if (std::abs(_t - _next_period_start) <= _dt * 1e-3)
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
[GlobalParams]
cycle_frequency = 0.1
[]

[Postprocessors]
[a]
type = ElementIntegralVariablePostprocessor
Expand All @@ -66,7 +67,6 @@
[]
[]


[Executioner]
type = Transient
end_time = 41
Expand Down
25 changes: 21 additions & 4 deletions test/tests/postprocessors/multi_period_averaging/tests
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
[Tests]
[receiver]
design = 'MultiPeriodAverager.md'
issues = '#222 #253'
[averaging]
type = CSVDiff
input = multi_period_averager.i
csvdiff = multi_period_averager_out.csv
requirement = "Take the average value of a postprocesser over multiple periods"
design = 'MultiPeriodAverager.md'
issues = '#222'
requirement = "Take the average value of a postprocesser over multiple periods."
[]
[errors]
requirement = "The system shall report a reasonable error when the user provides an invalid"
[invalid_number_of_periods]
type = RunException
input = multi_period_averager.i
cli_args = 'Postprocessors/multi_period/number_of_periods=0'
expect_err = 'Range check failed for parameter Postprocessors/multi_period/number_of_period'
detail = 'number of periods.'
[]
[invalid_cycle_frequency]
type = RunException
input = multi_period_averager.i
cli_args = 'Postprocessors/multi_period/cycle_frequency=0'
expect_err = 'Range check failed for parameter Postprocessors/multi_period/cycle_frequency'
detail = 'cycle frequency.'
[]
[]
[]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Tests]
[receiver]
[test]
type = CSVDiff
input = multiplied_integral.i
csvdiff = multiplied_integral_out.csv
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Tests]
[receiver]
[test]
type = CSVDiff
input = periodic_modifier.i
csvdiff = periodic_modifier_out.csv
Expand Down
18 changes: 14 additions & 4 deletions test/tests/postprocessors/periodic_integration/tests
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
[Tests]
[receiver]
design = 'PeriodicTimeIntegratedPostprocessor.md'
issues = '#222 #253'
[test]
type = CSVDiff
input = periodic_integral.i
csvdiff = periodic_integral_out.csv
requirement = "Integrate a postprocesssor over a period of time specified by a frequency"
design = 'PeriodicTimeIntegratedPostprocessor.md'
issues = '#222'
requirement = "Integrate a postprocesssor over a period of time specified by a frequency."
[]
[errors]
requirement = "The system shall report a reasonable error when the user provides an invalid"
[invalid_cycle_frequency]
type = RunException
input = periodic_integral.i
cli_args = 'Postprocessors/periodic/cycle_frequency=0'
expect_err = 'Range check failed for parameter Postprocessors/periodic/cycle_frequency'
detail = 'cycle frequency.'
[]
[]
[]

0 comments on commit 3aa88af

Please sign in to comment.