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 "ParsedVectorRealReductionReporter.h" 11 : 12 : registerMooseObject("MooseApp", ParsedVectorRealReductionReporter); 13 : 14 : InputParameters 15 3229 : ParsedVectorRealReductionReporter::validParams() 16 : { 17 3229 : InputParameters params = ParsedReporterBase::validParams(); 18 6458 : params.addClassDescription( 19 : "Use a parsed function to iterate through a vector and reduce it to a scalar."); 20 12916 : params.addRequiredParam<ReporterName>("vector_reporter_name", 21 : "Reporter name with vector to reduce."); 22 9687 : params.addRequiredParam<Real>("initial_reduction_value", 23 : "Value to intialize the reduction with."); 24 : 25 : // reporter_symbols are the two symbols for reduction value and current value for the reduction 26 : // operation, these symbols are enforced in the constructor with a mooseError 27 6458 : params.set<std::vector<std::string>>("vector_reporter_symbols") = {"reduction_value", 28 12916 : "indexed_value"}; 29 6458 : params.suppressParameter<std::vector<std::string>>("vector_reporter_symbols"); 30 3229 : params.suppressParameter<std::vector<std::string>>("scalar_reporter_symbols"); 31 : 32 3229 : return params; 33 9687 : } 34 : 35 72 : ParsedVectorRealReductionReporter::ParsedVectorRealReductionReporter( 36 72 : const InputParameters & parameters) 37 : : ParsedReporterBase(parameters), 38 72 : _initial_reduction_value(getParam<Real>("initial_reduction_value")), 39 72 : _vector_reporter_data( 40 144 : getReporterValueByName<std::vector<Real>>(getParam<ReporterName>("vector_reporter_name"))), 41 288 : _output_reporter(declareValueByName<Real>(getParam<std::string>("name"), REPORTER_MODE_ROOT)) 42 : { 43 : // parse function 44 144 : std::string function = getParam<std::string>("expression"); 45 : // make sure the expression has the two required variables, vi and vplus 46 144 : if (function.find("reduction_value") == std::string::npos || 47 72 : function.find("indexed_value") == std::string::npos) 48 0 : paramError( 49 : "expression", 50 : "Parsed function must contain the two symbols 'reduction_value' and 'indexed_value'."); 51 72 : } 52 : 53 : void 54 44 : ParsedVectorRealReductionReporter::finalize() 55 : { 56 44 : Real reduction = _initial_reduction_value; 57 220 : for (const auto i : index_range(_vector_reporter_data)) 58 : { 59 176 : _func_params[0] = reduction; 60 176 : _func_params[1] = _vector_reporter_data[i]; 61 : 62 176 : if (_use_t) 63 0 : _func_params[2] = _t; 64 : 65 528 : reduction = evaluate(_func_F); 66 : } 67 44 : _output_reporter = reduction; 68 44 : }