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 "ParsedVectorAux.h" 11 : #include "MooseApp.h" 12 : 13 : registerMooseObject("MooseApp", ParsedVectorAux); 14 : 15 : InputParameters 16 14346 : ParsedVectorAux::validParams() 17 : { 18 14346 : InputParameters params = VectorAuxKernel::validParams(); 19 14346 : params += FunctionParserUtils<false>::validParams(); 20 14346 : params.addClassDescription( 21 : "Sets a field vector variable value to the evaluation of a parsed expression."); 22 : 23 14346 : params.addRequiredCustomTypeParam<std::string>( 24 : "expression_x", 25 : "FunctionExpression", 26 : "Parsed function expression to compute the x component"); 27 14346 : params.addCustomTypeParam<std::string>("expression_y", 28 : "0", 29 : "FunctionExpression", 30 : "Parsed function expression to compute the y component"); 31 : if constexpr (LIBMESH_DIM >= 3) 32 14346 : params.addCustomTypeParam<std::string>("expression_z", 33 : "0", 34 : "FunctionExpression", 35 : "Parsed function expression to compute the z component"); 36 14346 : params.addCoupledVar("coupled_variables", "Vector of coupled variable names"); 37 14346 : params.addCoupledVar("coupled_vector_variables", "Vector of coupled variable names"); 38 : 39 43038 : params.addParam<bool>( 40 : "use_xyzt", 41 28692 : false, 42 : "Make coordinate (x,y,z) and time (t) variables available in the function expression."); 43 14346 : params.addParam<std::vector<std::vector<std::string>>>( 44 : "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)"); 45 14346 : params.addParam<std::vector<std::vector<std::string>>>( 46 : "constant_expressions", 47 : "Vector of values for the constants in constant_names (can be an FParser expression)"); 48 : 49 14346 : return params; 50 0 : } 51 : 52 42 : ParsedVectorAux::ParsedVectorAux(const InputParameters & parameters) 53 : : VectorAuxKernel(parameters), 54 : FunctionParserUtils(parameters), 55 168 : _function({getParam<std::string>("expression_x"), 56 : getParam<std::string>("expression_y"), 57 : getParam<std::string>("expression_z")}), 58 42 : _nargs(coupledComponents("coupled_variables")), 59 42 : _n_vector_args(coupledComponents("coupled_vector_variables")), 60 42 : _args(coupledValues("coupled_variables")), 61 42 : _vector_args(coupledVectorValues("coupled_vector_variables")), 62 84 : _use_xyzt(getParam<bool>("use_xyzt")) 63 : { 64 42 : _func_F.resize(LIBMESH_DIM); 65 42 : _function.resize(LIBMESH_DIM); 66 : 67 168 : for (const auto i : make_range(Moose::dim)) 68 : { 69 : // build variables argument 70 126 : std::string variables; 71 : 72 : // coupled regular field variables 73 252 : for (const auto i : make_range(_nargs)) 74 126 : variables += (i == 0 ? "" : ",") + getFieldVar("coupled_variables", i)->name(); 75 : 76 : // coupled vector field variables 77 294 : for (const auto i : make_range(_n_vector_args)) 78 : variables += 79 168 : (variables.empty() ? "" : ",") + getFieldVar("coupled_vector_variables", i)->name(); 80 : 81 : // "system" variables 82 630 : const std::vector<std::string> xyzt = {"x", "y", "z", "t"}; 83 126 : if (_use_xyzt) 84 420 : for (auto & v : xyzt) 85 336 : variables += (variables.empty() ? "" : ",") + v; 86 : 87 : // base function object 88 126 : _func_F[i] = std::make_shared<SymFunction>(); 89 : 90 : // add the constant expressions 91 252 : auto constant_names = isParamValid("constant_names") 92 126 : ? getParam<std::vector<std::vector<std::string>>>("constant_names") 93 126 : : std::vector<std::vector<std::string>>{}; 94 : auto constant_expressions = 95 252 : isParamValid("constant_expressions") 96 126 : ? getParam<std::vector<std::vector<std::string>>>("constant_expressions") 97 126 : : std::vector<std::vector<std::string>>{}; 98 126 : if (constant_names.size() && i > constant_names.size()) 99 0 : paramError("constant_names", 100 : "Constant names must be specified for each component. Use ';' for outer-indexing " 101 : "of double-indexed vector of constants."); 102 126 : if (constant_expressions.size() && i > constant_expressions.size()) 103 0 : paramError("constant_expressions", 104 : "Constant expressions must be specified for each component. Use ';' for " 105 : "outer-indexing of double-indexed vector of constants."); 106 126 : const std::vector<std::string> empty_vec{}; 107 126 : const auto names = constant_names.size() ? constant_names[i] : empty_vec; 108 126 : const auto expressions = constant_expressions.size() ? constant_expressions[i] : empty_vec; 109 : 110 : // Create parsed function for the component 111 126 : parsedFunctionSetup(_func_F[i], _function[i], variables, names, expressions, comm()); 112 126 : } 113 : // reserve storage for parameter passing buffer 114 42 : _func_params.resize(_nargs + _n_vector_args + (_use_xyzt ? 4 : 0)); 115 378 : } 116 : 117 : RealVectorValue 118 4131 : ParsedVectorAux::computeValue() 119 : { 120 4131 : RealVectorValue value; 121 16524 : for (const auto i : make_range(Moose::dim)) 122 : { 123 24786 : for (const auto j : make_range(_nargs)) 124 12393 : _func_params[j] = (*_args[j])[_qp]; 125 : 126 34479 : for (const auto j : make_range(_n_vector_args)) 127 22086 : _func_params[_nargs + j] = (*_vector_args[j])[_qp](i); 128 : 129 12393 : if (_use_xyzt) 130 : { 131 44172 : for (const auto j : make_range(Moose::dim)) 132 33129 : _func_params[_nargs + _n_vector_args + j] = 133 33129 : isNodal() ? (*_current_node)(j) : _q_point[_qp](j); 134 11043 : _func_params[_nargs + _n_vector_args + 3] = _t; 135 : } 136 12393 : value(i) = evaluate(_func_F[i]); 137 : } 138 4131 : return value; 139 : }