LCOV - code coverage report
Current view: top level - src/controllogic - PIDControl.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 29 30 96.7 %
Date: 2025-07-30 13:02:48 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14