Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
SmootherChainControl.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 "SmootherChainControl.h"
11 #include "MooseUtils.h"
12 
14 
17 {
19 
20  params.addClassDescription("Computes a moving average of the input control with a user-specified "
21  "number of points to average.");
22 
23  params.addRequiredParam<std::string>("input", "Control data value to smooth.");
24  params.addRequiredParam<unsigned int>("n_points",
25  "The number of points to use in the moving average.");
26 
27  return params;
28 }
29 
31  : ChainControl(parameters),
32  _input(getChainControlData<Real>("input")),
33  _n_points(getParam<unsigned int>("n_points")),
34  _output(declareChainControlData<Real>("value")),
35  _values(declareRestartableData<std::vector<Real>>("values")),
36  _previous_time(declareRestartableData<Real>("previous_time"))
37 {
39 }
40 
41 void
43 {
45  executeInner();
46 
48 }
49 
50 void
52 {
53  if (_values.size() == _n_points)
54  _values.erase(_values.begin());
55 
56  _values.push_back(_input);
57 
58  _output = std::accumulate(_values.begin(), _values.end(), 0.0) / _values.size();
59 }
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:372
Computes a moving average of the input control with a user-specified number of points to average...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
auto max(const L &left, const R &right)
std::vector< Real > & _values
Vector to store values.
Real & _previous_time
Previous time for which value was cached.
static InputParameters validParams()
Definition: ChainControl.C:14
SmootherChainControl(const InputParameters &parameters)
static InputParameters validParams()
registerMooseObject("MooseApp", SmootherChainControl)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real & _output
Output control value.
const Real & _input
Input data.
const unsigned int _n_points
The number of points to use in the moving average.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual void execute() override
Execute the control.
void executeInner()
Performs the main execution.
void ErrorVector unsigned int
Control that additionally provides the capability to produce/consume data values, to allow control op...
Definition: ChainControl.h:21