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 38 : DelayControl::validParams() 16 : { 17 38 : InputParameters params = THMControl::validParams(); 18 76 : params.addRequiredParam<std::string>("input", "The name of the control data that we read in."); 19 76 : params.addRequiredParam<Real>("tau", "Time period [s]"); 20 76 : params.addParam<Real>("initial_value", 0., "Initial value"); 21 38 : params.addClassDescription("Time delay control"); 22 38 : return params; 23 0 : } 24 : 25 20 : DelayControl::DelayControl(const InputParameters & parameters) 26 : : THMControl(parameters), 27 20 : _initial_value(getParam<Real>("initial_value")), 28 20 : _input(getControlData<Real>("input")), 29 40 : _tau(getParam<Real>("tau")), 30 20 : _value(declareComponentControlData<Real>("value")), 31 20 : _input_time(declareRecoverableData<std::deque<Real>>("input_time")), 32 40 : _input_vals(declareRecoverableData<std::deque<Real>>("input_vals")) 33 : { 34 20 : if (_tau < 0) 35 2 : mooseError("Negative values of 'tau' are not allowed."); 36 : 37 18 : addFnPoint(_t, _initial_value); 38 18 : _value = _initial_value; 39 18 : } 40 : 41 : void 42 166 : DelayControl::addFnPoint(const Real & t, const Real & val) 43 : { 44 166 : _input_time.push_back(t); 45 166 : _input_vals.push_back(val); 46 166 : } 47 : 48 : void 49 148 : DelayControl::execute() 50 : { 51 148 : _value = sampleFunction(_t - _tau); 52 148 : addFnPoint(_t, _input); 53 : 54 : // remove values that are beyond the time window 55 262 : while (_input_time[0] < (_t - _tau)) 56 : { 57 114 : _input_time.pop_front(); 58 114 : _input_vals.pop_front(); 59 : } 60 148 : } 61 : 62 : Real 63 148 : DelayControl::sampleFunction(const Real & t) const 64 : { 65 148 : if (t <= _input_time.front()) 66 52 : return _input_vals.front(); 67 96 : if (t >= _input_time.back()) 68 0 : return _input_vals.back(); 69 : 70 132 : for (unsigned int i = 0; i + 1 < _input_time.size(); ++i) 71 132 : if (t >= _input_time[i] && t < _input_time[i + 1]) 72 96 : return _input_vals[i] + (_input_vals[i + 1] - _input_vals[i]) * (t - _input_time[i]) / 73 96 : (_input_time[i + 1] - _input_time[i]); 74 : 75 0 : throw std::out_of_range("Unreachable"); 76 : return 0; 77 : }