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