https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ParsedVectorAux.C
Go to the documentation of this file.
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
14
17{
21 "Sets a field vector variable value to the evaluation of a parsed expression.");
22
23 params.addRequiredCustomTypeParam<std::string>(
24 "expression_x",
25 "FunctionExpression",
26 "Parsed function expression to compute the x component");
27 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 params.addCustomTypeParam<std::string>("expression_z",
33 "0",
34 "FunctionExpression",
35 "Parsed function expression to compute the z component");
36 params.addCoupledVar("coupled_variables", "Vector of coupled variable names");
37 params.addCoupledVar("coupled_vector_variables", "Vector of coupled variable names");
38
39 params.addParam<bool>(
40 "use_xyzt",
41 false,
42 "Make coordinate (x,y,z) and time (t) variables available in the function expression.");
43 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 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 return params;
50}
51
53 : VectorAuxKernel(parameters),
54 FunctionParserUtils(parameters),
55 _function({getParam<std::string>("expression_x"),
56 getParam<std::string>("expression_y"),
57 getParam<std::string>("expression_z")}),
58 _nargs(coupledComponents("coupled_variables")),
59 _n_vector_args(coupledComponents("coupled_vector_variables")),
60 _args(coupledValues("coupled_variables")),
61 _vector_args(coupledVectorValues("coupled_vector_variables")),
62 _use_xyzt(getParam<bool>("use_xyzt"))
63{
64 _func_F.resize(LIBMESH_DIM);
65 _function.resize(LIBMESH_DIM);
66
67 for (const auto i : make_range(Moose::dim))
68 {
69 // build variables argument
70 std::string variables;
71
72 // coupled regular field variables
73 for (const auto i : make_range(_nargs))
74 variables += (i == 0 ? "" : ",") + getFieldVar("coupled_variables", i)->name();
75
76 // coupled vector field variables
77 for (const auto i : make_range(_n_vector_args))
78 variables +=
79 (variables.empty() ? "" : ",") + getFieldVar("coupled_vector_variables", i)->name();
80
81 // "system" variables
82 const std::vector<std::string> xyzt = {"x", "y", "z", "t"};
83 if (_use_xyzt)
84 for (auto & v : xyzt)
85 variables += (variables.empty() ? "" : ",") + v;
86
87 // base function object
88 _func_F[i] = std::make_shared<SymFunction>();
89
90 // add the constant expressions
91 auto constant_names = isParamValid("constant_names")
92 ? getParam<std::vector<std::vector<std::string>>>("constant_names")
93 : std::vector<std::vector<std::string>>{};
94 auto constant_expressions =
95 isParamValid("constant_expressions")
96 ? getParam<std::vector<std::vector<std::string>>>("constant_expressions")
97 : std::vector<std::vector<std::string>>{};
98 if (constant_names.size() && i > constant_names.size())
99 paramError("constant_names",
100 "Constant names must be specified for each component. Use ';' for outer-indexing "
101 "of double-indexed vector of constants.");
102 if (constant_expressions.size() && i > constant_expressions.size())
103 paramError("constant_expressions",
104 "Constant expressions must be specified for each component. Use ';' for "
105 "outer-indexing of double-indexed vector of constants.");
106 const std::vector<std::string> empty_vec{};
107 const auto names = constant_names.size() ? constant_names[i] : empty_vec;
108 const auto expressions = constant_expressions.size() ? constant_expressions[i] : empty_vec;
109
110 // Create parsed function for the component
111 parsedFunctionSetup(_func_F[i], _function[i], variables, names, expressions, comm());
112 }
113 // reserve storage for parameter passing buffer
114 _func_params.resize(_nargs + _n_vector_args + (_use_xyzt ? 4 : 0));
115}
116
119{
120 RealVectorValue value;
121 for (const auto i : make_range(Moose::dim))
122 {
123 for (const auto j : make_range(_nargs))
124 _func_params[j] = (*_args[j])[_qp];
125
126 for (const auto j : make_range(_n_vector_args))
127 _func_params[_nargs + j] = (*_vector_args[j])[_qp](i);
128
129 if (_use_xyzt)
130 {
131 for (const auto j : make_range(Moose::dim))
133 isNodal() ? (*_current_node)(j) : _q_point[_qp](j);
135 }
136 value(i) = evaluate(_func_F[i]);
137 }
138 return value;
139}
registerMooseObject("MooseApp", ParsedVectorAux)
unsigned int dim
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
const MooseArray< Point > & _q_point
Active quadrature points.
Definition AuxKernel.h:125
unsigned int _qp
Quadrature point index.
Definition AuxKernel.h:155
static InputParameters validParams()
Definition AuxKernel.C:27
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addCustomTypeParam(const std::string &name, const T &value, const std::string &custom_type, const std::string &doc_string)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
These methods add an option parameter and with a customer type to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
virtual const OutputTools< T >::VariableValue & value()
The value of the variable this object is operating on.
AuxKernel that evaluates a parsed function expression for every component.
ParsedVectorAux(const InputParameters &parameters)
const std::vector< const VariableValue * > _args
virtual RealVectorValue computeValue() override
Compute and return the value of the aux variable.
const unsigned int _nargs
coupled variables NOTE: a potential optimization would be to have different number of arguments per c...
const unsigned int _n_vector_args
std::vector< SymFunctionPtr > _func_F
function parser object
std::vector< const VectorVariableValue * > _vector_args
static InputParameters validParams()
const bool _use_xyzt
import coordinates and time
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
VectorValue< Real > RealVectorValue
Definition SubProblem.h:34