LCOV - code coverage report
Current view: top level - src/controllogic - DelayControl.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 38 41 92.7 %
Date: 2026-05-29 20:41:18 Functions: 5 5 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 "DelayControl.h"
      11             : 
      12             : registerMooseObject("ThermalHydraulicsApp", DelayControl);
      13             : 
      14             : InputParameters
      15          18 : DelayControl::validParams()
      16             : {
      17          18 :   InputParameters params = THMControl::validParams();
      18          36 :   params.addRequiredParam<std::string>("input", "The name of the control data that we read in.");
      19          36 :   params.addRequiredParam<Real>("tau", "Time period [s]");
      20          36 :   params.addParam<Real>("initial_value", 0., "Initial value");
      21          18 :   params.addClassDescription("Time delay control");
      22          18 :   return params;
      23           0 : }
      24             : 
      25          10 : DelayControl::DelayControl(const InputParameters & parameters)
      26             :   : THMControl(parameters),
      27          10 :     _initial_value(getParam<Real>("initial_value")),
      28          10 :     _input(getControlData<Real>("input")),
      29          20 :     _tau(getParam<Real>("tau")),
      30          10 :     _value(declareComponentControlData<Real>("value")),
      31          10 :     _input_time(declareRecoverableData<std::deque<Real>>("input_time")),
      32          20 :     _input_vals(declareRecoverableData<std::deque<Real>>("input_vals"))
      33             : {
      34          10 :   if (_tau < 0)
      35           2 :     mooseError("Negative values of 'tau' are not allowed.");
      36             : 
      37           8 :   addFnPoint(_t, _initial_value);
      38           8 :   _value = _initial_value;
      39           8 : }
      40             : 
      41             : void
      42          86 : DelayControl::addFnPoint(const Real & t, const Real & val)
      43             : {
      44          86 :   _input_time.push_back(t);
      45          86 :   _input_vals.push_back(val);
      46          86 : }
      47             : 
      48             : void
      49          78 : DelayControl::execute()
      50             : {
      51          78 :   _value = sampleFunction(_t - _tau);
      52          78 :   addFnPoint(_t, _input);
      53             : 
      54             :   // remove values that are beyond the time window
      55         136 :   while (_input_time[0] < (_t - _tau))
      56             :   {
      57          58 :     _input_time.pop_front();
      58          58 :     _input_vals.pop_front();
      59             :   }
      60          78 : }
      61             : 
      62             : Real
      63          78 : DelayControl::sampleFunction(const Real & t) const
      64             : {
      65          78 :   if (t <= _input_time.front())
      66          28 :     return _input_vals.front();
      67          50 :   if (t >= _input_time.back())
      68           0 :     return _input_vals.back();
      69             : 
      70          66 :   for (unsigned int i = 0; i + 1 < _input_time.size(); ++i)
      71          66 :     if (t >= _input_time[i] && t < _input_time[i + 1])
      72          50 :       return _input_vals[i] + (_input_vals[i + 1] - _input_vals[i]) * (t - _input_time[i]) /
      73          50 :                                   (_input_time[i + 1] - _input_time[i]);
      74             : 
      75           0 :   throw std::out_of_range("Unreachable");
      76             :   return 0;
      77             : }

Generated by: LCOV version 1.14