Skip to content

Commit

Permalink
update to PIDTransientControl object idaholab#26742
Browse files Browse the repository at this point in the history
  • Loading branch information
jthano committed Feb 5, 2024
1 parent dc5a23c commit 972d3b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions framework/include/controls/PIDTransientControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class PIDTransientControl : public Control
const bool _reset_every_timestep;
/// Whether to reset the PID integral error when the error crosses 0, to avoid windup
const bool _reset_integral_windup;
/// Limiting maximum value for the output of the PID controller
const Real _maximum_output_value;
/// Limiting minimum value for the output of the PID controller
const Real _minimum_output_value;
/// Integral of the error
Real _integral;
/// Saved value of the integral at the beginning of a timestep, to recover from a failed solve
Expand Down
24 changes: 20 additions & 4 deletions framework/src/controls/PIDTransientControl.C
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ PIDTransientControl::validParams()
"Reset the PID integral when the error crosses zero and the integral is "
"larger than the error.");

params.addParam<Real>("maximum_output_value",
std::numeric_limits<Real>::max(),
"Can be used to limit the maximum value output by the PID controller.");
params.addParam<Real>("minimum_output_value",
-std::numeric_limits<Real>::max(),
"Can be used to limit the minimum value output by the PID controller.");

return params;
}

Expand All @@ -62,12 +69,19 @@ PIDTransientControl::PIDTransientControl(const InputParameters & parameters)
_stop_time(getParam<Real>("stop_time")),
_reset_every_timestep(getParam<bool>("reset_every_timestep")),
_reset_integral_windup(getParam<bool>("reset_integral_windup")),
_maximum_output_value(getParam<Real>("maximum_output_value")),
_minimum_output_value(getParam<Real>("minimum_output_value")),
_integral(0),
_integral_old(0),
_value_old(0),
_t_step_old(-1),
_old_delta(0)
{
if (!_fe_problem.isTransient())
mooseWarning("PIDTransientControl is only meant to be used when the problem is transient, for "
"example with a Transient Executioner. If using a Steady "
"Executioner, make sure to specify a minimum number of Picard iterations.");

if (isParamValid("parameter") && isParamValid("parameter_pp"))
paramError("parameter_pp",
"Either a controllable parameter or a postprocessor to control should be specified, "
Expand All @@ -78,10 +92,10 @@ PIDTransientControl::PIDTransientControl(const InputParameters & parameters)
paramError(
"reset_every_timestep",
"Resetting the PID every time step is only supported using controlled postprocessors");
if (!dynamic_cast<Transient *>(_app.getExecutioner()))
if (_maximum_output_value <= _minimum_output_value)
mooseError(
"PIDTransientControl is only supported by a Transient Executioner. If using a Steady "
"Executioner, add a minimum number of Picard iterations and comment this error.");
"The parameters maximum_output_value and minimum_output_value are inconsistent. The value "
"of maximum_output_value should be greater than the value of minimum_output_value.");
}

void
Expand Down Expand Up @@ -113,7 +127,7 @@ PIDTransientControl::execute()
// If there were coupling/Picard iterations during the transient and they failed,
// we need to reset the controlled value and the error integral to their initial value at the
// beginning of the coupling process
if (_app.getExecutioner()->picardSolve().numPicardIts() == 1)
if (_app.getExecutioner()->fixedPointSolve().numFixedPointIts() == 1)
{
_integral = _integral_old;
value = _value_old;
Expand All @@ -132,6 +146,8 @@ PIDTransientControl::execute()
if (_dt > 0)
value += _Kder * delta / _dt;

value = std::min(std::max(_minimum_output_value, value), _maximum_output_value);

// Set the new value of the postprocessor
if (isParamValid("parameter"))
setControllableValue<Real>("parameter", value);
Expand Down

0 comments on commit 972d3b7

Please sign in to comment.