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