https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PIDChainControl.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "PIDChainControl.h"
11#include "MooseUtils.h"
12
14
17{
19
20 params.addClassDescription("Implements a proportional-integral-derivative (PID) controller.");
21
22 params.addRequiredParam<std::string>("input", "Input control data");
23 params.addRequiredParam<std::string>("set_point", "Set point control data");
24 params.addParam<Real>("initial_integral", 0.0, "Initial value for the integral component");
25 params.addRequiredParam<Real>("K_p", "Coefficient for the proportional term");
26 params.addRequiredParam<Real>("K_i", "Coefficient for the integral term");
27 params.addRequiredParam<Real>("K_d", "Coefficient for the derivative term");
28
29 return params;
30}
31
33 : ChainControl(parameters),
34 _input(getChainControlData<Real>("input")),
35 _set_point(getChainControlData<Real>("set_point")),
36 _K_p(getParam<Real>("K_p")),
37 _K_i(getParam<Real>("K_i")),
38 _K_d(getParam<Real>("K_d")),
39 _error(declareChainControlData<Real>("error")),
40 _error_old(getChainControlDataOldByName<Real>(fullControlDataName("error"))),
41 _proportional(declareChainControlData<Real>("proportional")),
42 _integral(declareChainControlData<Real>("integral")),
43 _integral_old(getChainControlDataOldByName<Real>(fullControlDataName("integral"))),
44 _derivative(declareChainControlData<Real>("derivative")),
45 _output(declareChainControlData<Real>("value")),
46 _previous_time(declareRestartableData<Real>("previous_time"))
47{
48 _integral = getParam<Real>("initial_integral");
49 _previous_time = std::numeric_limits<Real>::max();
50}
51
52void
54{
55 if (!MooseUtils::absoluteFuzzyEqual(_t, _previous_time))
57
59}
60
61void
63{
65
68 if (MooseUtils::absoluteFuzzyEqual(_dt, 0.0))
69 _derivative = 0.0;
70 else
72
74}
registerMooseObject("MooseApp", PIDChainControl)
Control that additionally provides the capability to produce/consume data values, to allow control op...
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Implements a proportional-integral-derivative (PID) controller.
const Real & _K_p
The coefficient for the proportional term.
const Real & _K_d
The coefficient for the derivative term.
Real & _previous_time
Previous time for which value was computed.
static InputParameters validParams()
Real & _derivative
The derivative component.
const Real & _input
input data
const Real & _integral_old
The old value of _integral.
const Real & _set_point
set point
void updateValues()
Updates all control data values.
virtual void execute() override
Execute the control.
Real & _output
The output computed by the PID controller.
Real & _error
The current value of the error.
const Real & _error_old
The old value of the error.
Real & _integral
The integral component.
const Real & _K_i
The coefficient for the integral term.
Real & _proportional
The proportional component.
PIDChainControl(const InputParameters &parameters)
Real & _dt
Time step size.