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 "SmootherControl.h" 11 : 12 : registerMooseObject("ThermalHydraulicsApp", SmootherControl); 13 : 14 : InputParameters 15 38 : SmootherControl::validParams() 16 : { 17 38 : InputParameters params = THMControl::validParams(); 18 76 : params.addRequiredParam<std::string>("input", "Control data value to smooth."); 19 76 : params.addRequiredParam<unsigned int>("n_points", 20 : "The number of points to use in the moving average."); 21 38 : params.addClassDescription("Computes a moving average value of the input control " 22 : "with a user-specified number of points to average. " 23 : "The output control value is named 'name:value', " 24 : "where 'name' is the name of the control object."); 25 38 : return params; 26 0 : } 27 : 28 19 : SmootherControl::SmootherControl(const InputParameters & parameters) 29 : : THMControl(parameters), 30 19 : _input(getControlData<Real>("input")), 31 38 : _n_points(getParam<unsigned int>("n_points")), 32 19 : _output(declareComponentControlData<Real>("value")), 33 57 : _values(declareRestartableData<std::vector<Real>>("values")) 34 : { 35 19 : } 36 : 37 : void 38 89 : SmootherControl::execute() 39 : { 40 89 : if (_fe_problem.getCurrentExecuteOnFlag() == EXEC_TIMESTEP_BEGIN) 41 : { 42 70 : if (_values.size() == _n_points) 43 : _values.erase(_values.begin()); 44 : 45 70 : _values.push_back(_input); 46 : 47 140 : _output = std::accumulate(_values.begin(), _values.end(), 0.0) / _values.size(); 48 : } 49 89 : }