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 "ParsedReporterBase.h" 11 : 12 : // registerMooseObject("OptimizationApp", ParsedReporterBase); 13 : 14 : InputParameters 15 852 : ParsedReporterBase::validParams() 16 : { 17 852 : InputParameters params = GeneralReporter::validParams(); 18 852 : params += FunctionParserUtils<false>::validParams(); 19 1704 : params.addRequiredCustomTypeParam<std::string>( 20 : "expression", "FunctionExpression", "function expression"); 21 1704 : params.addParam<std::string>("name", "result", "Name of output reporter."); 22 1704 : params.addRequiredParam<std::vector<std::string>>("reporter_symbols", 23 : "Expression symbol for each reporter"); 24 1704 : params.addParam<std::vector<std::string>>( 25 : "constant_names", 26 : {}, 27 : "Vector of constants used in the parsed function (use this for kB etc.)"); 28 1704 : params.addParam<std::vector<std::string>>( 29 : "constant_expressions", 30 : {}, 31 : "Vector of values for the constants in constant_names (can be an FParser expression)"); 32 1704 : params.addParam<bool>( 33 1704 : "use_t", false, "Make time (t) variables available in the function expression."); 34 852 : return params; 35 0 : } 36 : 37 426 : ParsedReporterBase::ParsedReporterBase(const InputParameters & parameters) 38 : : GeneralReporter(parameters), 39 : FunctionParserUtils(parameters), 40 426 : _use_t(getParam<bool>("use_t")), 41 1704 : _reporter_symbols(getParam<std::vector<std::string>>("reporter_symbols")) 42 : { 43 : // build reporters argument 44 : std::string symbol_str; 45 1315 : for (const auto i : index_range(_reporter_symbols)) 46 2241 : symbol_str += (i == 0 ? "" : ",") + _reporter_symbols[i]; 47 : 48 : // add time if required 49 426 : if (_use_t) 50 0 : symbol_str += (symbol_str.empty() ? "" : ",") + std::string("t"); 51 : 52 : // Create parsed function 53 426 : _func_F = std::make_shared<SymFunction>(); 54 1704 : parsedFunctionSetup(_func_F, 55 852 : getParam<std::string>("expression"), 56 : symbol_str, 57 : getParam<std::vector<std::string>>("constant_names"), 58 : getParam<std::vector<std::string>>("constant_expressions"), 59 : comm()); 60 : 61 : // reserve storage for parameter passing buffer 62 426 : _func_params.resize(_reporter_symbols.size() + _use_t); 63 426 : }