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 "SmootherChainControl.h" 11 : #include "MooseUtils.h" 12 : 13 : registerMooseObject("MooseApp", SmootherChainControl); 14 : 15 : InputParameters 16 14291 : SmootherChainControl::validParams() 17 : { 18 14291 : InputParameters params = ChainControl::validParams(); 19 : 20 14291 : params.addClassDescription("Computes a moving average of the input control with a user-specified " 21 : "number of points to average."); 22 : 23 14291 : params.addRequiredParam<std::string>("input", "Control data value to smooth."); 24 14291 : params.addRequiredParam<unsigned int>("n_points", 25 : "The number of points to use in the moving average."); 26 : 27 14291 : return params; 28 0 : } 29 : 30 13 : SmootherChainControl::SmootherChainControl(const InputParameters & parameters) 31 : : ChainControl(parameters), 32 13 : _input(getChainControlData<Real>("input")), 33 13 : _n_points(getParam<unsigned int>("n_points")), 34 13 : _output(declareChainControlData<Real>("value")), 35 13 : _values(declareRestartableData<std::vector<Real>>("values")), 36 26 : _previous_time(declareRestartableData<Real>("previous_time")) 37 : { 38 13 : _previous_time = std::numeric_limits<Real>::max(); 39 13 : } 40 : 41 : void 42 49 : SmootherChainControl::execute() 43 : { 44 49 : if (!MooseUtils::absoluteFuzzyEqual(_t, _previous_time)) 45 48 : executeInner(); 46 : 47 49 : _previous_time = _t; 48 49 : } 49 : 50 : void 51 48 : SmootherChainControl::executeInner() 52 : { 53 48 : if (_values.size() == _n_points) 54 12 : _values.erase(_values.begin()); 55 : 56 48 : _values.push_back(_input); 57 : 58 48 : _output = std::accumulate(_values.begin(), _values.end(), 0.0) / _values.size(); 59 48 : }