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 14947 : ParsedVectorRealReductionReporter::validParams() 16 : { 17 14947 : InputParameters params = ParsedReporterBase::validParams(); 18 29894 : params.addClassDescription( 19 : "Use a parsed function to iterate through a vector and reduce it to a scalar."); 20 59788 : params.addRequiredParam<ReporterName>("vector_reporter_name", 21 : "Reporter name with vector to reduce."); 22 44841 : 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 29894 : params.set<std::vector<std::string>>("vector_reporter_symbols") = {"reduction_value", 28 59788 : "indexed_value"}; 29 29894 : params.suppressParameter<std::vector<std::string>>("vector_reporter_symbols"); 30 14947 : params.suppressParameter<std::vector<std::string>>("scalar_reporter_symbols"); 31 : 32 14947 : return params; 33 44841 : } 34 : 35 84 : ParsedVectorRealReductionReporter::ParsedVectorRealReductionReporter( 36 84 : const InputParameters & parameters) 37 : : ParsedReporterBase(parameters), 38 84 : _initial_reduction_value(getParam<Real>("initial_reduction_value")), 39 84 : _vector_reporter_data( 40 168 : getReporterValueByName<std::vector<Real>>(getParam<ReporterName>("vector_reporter_name"))), 41 336 : _output_reporter(declareValueByName<Real>(getParam<std::string>("name"), REPORTER_MODE_ROOT)) 42 : { 43 : // parse function 44 168 : std::string function = getParam<std::string>("expression"); 45 : // make sure the expression has the two required variables, vi and vplus 46 168 : if (function.find("reduction_value") == std::string::npos || 47 84 : 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 84 : } 52 : 53 : void 54 48 : ParsedVectorRealReductionReporter::finalize() 55 : { 56 48 : Real reduction = _initial_reduction_value; 57 240 : for (const auto i : index_range(_vector_reporter_data)) 58 : { 59 192 : _func_params[0] = reduction; 60 192 : _func_params[1] = _vector_reporter_data[i]; 61 : 62 192 : if (_use_t) 63 0 : _func_params[2] = _t; 64 : 65 576 : reduction = evaluate(_func_F); 66 : } 67 48 : _output_reporter = reduction; 68 48 : }