https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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{
38 _previous_time = std::numeric_limits<Real>::max();
39}
40
41void
43{
44 if (!MooseUtils::absoluteFuzzyEqual(_t, _previous_time))
46
48}
49
50void
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}
registerMooseObject("MooseApp", SmootherChainControl)
void ErrorVector unsigned int
Control that additionally provides the capability to produce/consume data values, to allow control op...
static InputParameters validParams()
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...
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.
Computes a moving average of the input control with a user-specified number of points to average.
virtual void execute() override
Execute the control.
SmootherChainControl(const InputParameters &parameters)
const Real & _input
Input data.
static InputParameters validParams()
const unsigned int _n_points
The number of points to use in the moving average.
Real & _output
Output control value.
std::vector< Real > & _values
Vector to store values.
void executeInner()
Performs the main execution.
Real & _previous_time
Previous time for which value was cached.