Line data Source code
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 "PIDControl.h" 11 : 12 : registerMooseObject("ThermalHydraulicsApp", PIDControl); 13 : 14 : InputParameters 15 24 : PIDControl::validParams() 16 : { 17 24 : InputParameters params = THMControl::validParams(); 18 48 : params.addRequiredParam<std::string>("input", "The name of the control data that we read in."); 19 48 : params.addRequiredParam<std::string>("set_point", 20 : "The name of the control data with the set point."); 21 48 : params.addRequiredParam<Real>("initial_value", "The initial value for the integral part."); 22 48 : params.addRequiredParam<Real>("K_p", "The coefficient for the proportional term."); 23 48 : params.addRequiredParam<Real>("K_i", "The coefficient for the integral term."); 24 48 : params.addRequiredParam<Real>("K_d", "The coefficient for the derivative term."); 25 24 : params.addClassDescription("Declares a control data named 'output' and uses Proportional " 26 : "Integral Derivative logic on the 'value' control data to set it."); 27 24 : return params; 28 0 : } 29 : 30 12 : PIDControl::PIDControl(const InputParameters & parameters) 31 : : THMControl(parameters), 32 12 : _value(getControlData<Real>("input")), 33 12 : _set_point(getControlData<Real>("set_point")), 34 24 : _K_p(getParam<Real>("K_p")), 35 24 : _K_i(getParam<Real>("K_i")), 36 24 : _K_d(getParam<Real>("K_d")), 37 12 : _output(declareComponentControlData<Real>("output")), 38 24 : _initial_value(getParam<Real>("initial_value")), 39 12 : _integral(declareComponentControlData<Real>("integral")), 40 12 : _integral_old(getComponentControlDataOld<Real>("integral")), 41 12 : _error(declareComponentControlData<Real>("error")), 42 24 : _error_old(getComponentControlDataOld<Real>("error")) 43 : { 44 12 : _integral = _initial_value; 45 12 : } 46 : 47 : void 48 428 : PIDControl::execute() 49 : { 50 428 : _error = _set_point - _value; 51 428 : _integral = _integral_old + _K_i * (_error * _dt); 52 428 : _output = _K_p * _error + _integral + _K_d * (_error - _error_old) / _dt; 53 428 : }