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 "ParsedPostprocessor.h" 11 : 12 : registerMooseObject("MooseApp", ParsedPostprocessor); 13 : 14 : InputParameters 15 15605 : ParsedPostprocessor::validParams() 16 : { 17 15605 : InputParameters params = GeneralPostprocessor::validParams(); 18 15605 : params += FunctionParserUtils<false>::validParams(); 19 : 20 15605 : params.addRequiredCustomTypeParam<std::string>( 21 : "function", "FunctionExpression", "function expression"); 22 15605 : params.deprecateParam("function", "expression", "05/01/2025"); 23 : 24 15605 : params.addParam<std::vector<PostprocessorName>>("pp_names", {}, "Post-processors arguments"); 25 15605 : params.addParam<std::vector<std::string>>( 26 : "pp_symbols", {}, "Symbol associated with each post-processor argument"); 27 15605 : params.addParam<std::vector<std::string>>( 28 : "constant_names", 29 : {}, 30 : "Vector of constants used in the parsed function (use this for kB etc.)"); 31 15605 : params.addParam<std::vector<std::string>>( 32 : "constant_expressions", 33 : {}, 34 : "Vector of values for the constants in constant_names (can be an FParser expression)"); 35 46815 : params.addParam<bool>( 36 31210 : "use_t", false, "Make time (t) variable available in the function expression."); 37 : 38 15605 : params.addClassDescription("Computes a parsed expression with post-processors"); 39 15605 : return params; 40 0 : } 41 : 42 652 : ParsedPostprocessor::ParsedPostprocessor(const InputParameters & parameters) 43 : : GeneralPostprocessor(parameters), 44 : FunctionParserUtils(parameters), 45 652 : _n_pp(coupledPostprocessors("pp_names")), 46 652 : _use_t(getParam<bool>("use_t")), 47 1956 : _value(0.0) 48 : { 49 : // build postprocessors argument 50 652 : std::string postprocessors; 51 : 52 652 : const std::vector<std::string> pp_symbols = getParam<std::vector<std::string>>("pp_symbols"); 53 : // sanity checks 54 652 : if (!pp_symbols.empty() && (pp_symbols.size() != _n_pp)) 55 4 : paramError("pp_symbols", "pp_symbols must be the same length as pp_names."); 56 : 57 : // coupled postprocessors with capacity for symbol inputs 58 648 : std::vector<PostprocessorName> pp_names = getParam<std::vector<PostprocessorName>>("pp_names"); 59 648 : if (pp_symbols.empty()) 60 : { 61 1884 : for (std::size_t i = 0; i < _n_pp; ++i) 62 1248 : postprocessors += (i == 0 ? "" : ",") + pp_names[i]; 63 : } 64 : else 65 12 : postprocessors = MooseUtils::stringJoin(pp_symbols, ","); 66 : 67 : // add time if required 68 648 : if (_use_t) 69 24 : postprocessors += (postprocessors.empty() ? "" : ",") + std::string("t"); 70 : 71 : // Create parsed function 72 648 : _func_F = std::make_shared<SymFunction>(); 73 1296 : parsedFunctionSetup(_func_F, 74 648 : getParam<std::string>("expression"), 75 : postprocessors, 76 : getParam<std::vector<std::string>>("constant_names"), 77 : getParam<std::vector<std::string>>("constant_expressions"), 78 : comm()); 79 : 80 : // reserve storage for parameter passing buffer 81 648 : _func_params.resize(_n_pp + _use_t); 82 648 : _pp_values.resize(_n_pp); 83 1920 : for (unsigned int i = 0; i < _n_pp; i++) 84 1272 : _pp_values[i] = &getPostprocessorValue("pp_names", i); 85 648 : } 86 : 87 : void 88 4841 : ParsedPostprocessor::initialize() 89 : { 90 4841 : } 91 : 92 : void 93 4841 : ParsedPostprocessor::execute() 94 : { 95 4841 : } 96 : 97 : void 98 4841 : ParsedPostprocessor::finalize() 99 : { 100 13995 : for (unsigned int i = 0; i < _n_pp; i++) 101 9154 : _func_params[i] = *_pp_values[i]; 102 : 103 4841 : if (_use_t) 104 88 : _func_params[_n_pp] = _t; 105 : 106 4841 : _value = evaluate(_func_F); 107 4841 : } 108 : 109 : PostprocessorValue 110 4841 : ParsedPostprocessor::getValue() const 111 : { 112 4841 : return _value; 113 : }