https://mooseframework.inl.gov
DelayControl.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 "DelayControl.h"
11 
12 registerMooseObject("ThermalHydraulicsApp", DelayControl);
13 
16 {
18  params.addRequiredParam<std::string>("input", "The name of the control data that we read in.");
19  params.addRequiredParam<Real>("tau", "Time period [s]");
20  params.addParam<Real>("initial_value", 0., "Initial value");
21  params.addClassDescription("Time delay control");
22  return params;
23 }
24 
26  : THMControl(parameters),
27  _initial_value(getParam<Real>("initial_value")),
28  _input(getControlData<Real>("input")),
29  _tau(getParam<Real>("tau")),
30  _value(declareComponentControlData<Real>("value")),
31  _input_time(declareRecoverableData<std::deque<Real>>("input_time")),
32  _input_vals(declareRecoverableData<std::deque<Real>>("input_vals"))
33 {
34  if (_tau < 0)
35  mooseError("Negative values of 'tau' are not allowed.");
36 
39 }
40 
41 void
42 DelayControl::addFnPoint(const Real & t, const Real & val)
43 {
44  _input_time.push_back(t);
45  _input_vals.push_back(val);
46 }
47 
48 void
50 {
53 
54  // remove values that are beyond the time window
55  while (_input_time[0] < (_t - _tau))
56  {
57  _input_time.pop_front();
58  _input_vals.pop_front();
59  }
60 }
61 
62 Real
63 DelayControl::sampleFunction(const Real & t) const
64 {
65  if (t <= _input_time.front())
66  return _input_vals.front();
67  if (t >= _input_time.back())
68  return _input_vals.back();
69 
70  for (unsigned int i = 0; i + 1 < _input_time.size(); ++i)
71  if (t >= _input_time[i] && t < _input_time[i + 1])
72  return _input_vals[i] + (_input_vals[i + 1] - _input_vals[i]) * (t - _input_time[i]) /
73  (_input_time[i + 1] - _input_time[i]);
74 
75  throw std::out_of_range("Unreachable");
76  return 0;
77 }
const Real & _initial_value
Initial value.
Definition: DelayControl.h:45
Real _tau
Time period.
Definition: DelayControl.h:49
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addFnPoint(const Real &t, const Real &val)
Add a node to linear interpolation.
Definition: DelayControl.C:42
void addRequiredParam(const std::string &name, const std::string &doc_string)
registerMooseObject("ThermalHydraulicsApp", DelayControl)
std::deque< Real > & _input_time
Times when &#39;input&#39; was sampled.
Definition: DelayControl.h:53
static InputParameters validParams()
Definition: THMControl.C:13
const Real & _input
Input data.
Definition: DelayControl.h:47
Real & _t
static InputParameters validParams()
Definition: DelayControl.C:15
Real & _value
Output value.
Definition: DelayControl.h:51
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
virtual void execute()
Definition: DelayControl.C:49
void addClassDescription(const std::string &doc_string)
std::deque< Real > & _input_vals
Values of &#39;input&#39; corresponding to _input_time.
Definition: DelayControl.h:55
DelayControl(const InputParameters &parameters)
Definition: DelayControl.C:25
Real sampleFunction(const Real &t) const
Linear interpolation.
Definition: DelayControl.C:63
Time delay control.
Definition: DelayControl.h:24