https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ArrayParsedAux.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 "ArrayParsedAux.h"
11#include "MooseApp.h"
12
14
17{
21 "Sets field array variable values to the evaluation of a parsed expression.");
22
23 params.addRequiredCustomTypeParam<std::string>(
24 "expression", "FunctionExpression", "Parsed function expression to compute");
25 params.addCoupledVar("coupled_variables", "Vector of coupled variable names.");
26 params.addCoupledVar("coupled_array_variables", "Vector of coupled array variable names.");
27
28 params.addParam<bool>(
29 "use_xyzt",
30 false,
31 "Make coordinate (x,y,z) and time (t) variables available in the function expression.");
32 params.addParam<std::vector<std::string>>(
33 "constant_names",
34 {},
35 "Vector of constants used in the parsed function (use this for kB etc.)");
36 params.addParam<std::vector<std::string>>(
37 "constant_expressions",
38 {},
39 "Vector of values for the constants in constant_names (can be an FParser expression)");
40
41 return params;
42}
43
45 : ArrayAuxKernel(parameters),
46 FunctionParserUtils(parameters),
47 _function(getParam<std::string>("expression")),
48 _n_vars(coupledComponents("coupled_variables")),
49 _n_array_vars(coupledComponents("coupled_array_variables")),
50 _vars(coupledValues("coupled_variables")),
51 _array_vars(coupledArrayValues("coupled_array_variables")),
52 _use_xyzt(getParam<bool>("use_xyzt"))
53{
54 // build variables argument
55 std::string variables;
56
57 // coupled field variables
58 for (const auto & i : make_range(_n_vars))
59 variables += (i == 0 ? "" : ",") + getFieldVar("coupled_variables", i)->name();
60 for (const auto & i : make_range(_n_array_vars))
61 {
62 const auto & var = *getArrayVar("coupled_array_variables", i);
63 if (var.count() != _var.count())
64 paramError("coupled_array_variables",
65 "The number of components in '",
66 _var.name(),
67 "' (",
68 _var.count(),
69 ") does not match the number of components in '",
70 var.name(),
71 "' (",
72 var.count(),
73 ").");
74 variables += (i == 0 && _n_vars == 0 ? "" : ",") + var.name();
75 }
76
77 // "system" variables
78 const std::vector<std::string> xyzt = {"x", "y", "z", "t"};
79 if (_use_xyzt)
80 for (auto & v : xyzt)
81 variables += (variables.empty() ? "" : ",") + v;
82
83 // Create parsed function
84 _func_F = std::make_shared<SymFunction>();
87 variables,
88 getParam<std::vector<std::string>>("constant_names"),
89 getParam<std::vector<std::string>>("constant_expressions"),
90 comm());
91
92 // reserve storage for parameter passing buffer
93 _func_params.resize(_n_vars + _n_array_vars + (_use_xyzt ? 4 : 0));
94}
95
96RealEigenVector
98{
99 // Returned value
100 RealEigenVector val(_var.count());
101
102 // Gather regular variable values
103 for (const auto & i : make_range(_n_vars))
104 _func_params[i] = (*_vars[i])[_qp];
105
106 // Gather xyzt values
107 if (_use_xyzt)
108 {
109 for (const auto j : make_range(Moose::dim))
111 isNodal() ? (*_current_node)(j) : _q_point[_qp](j);
113 }
114
115 // Loop through each component
116 for (const auto & c : make_range(_var.count()))
117 {
118 // Gather array variables
119 for (const auto & i : make_range(_n_array_vars))
120 _func_params[_n_vars + i] = (*_array_vars[i])[_qp](c);
121
122 // Evaluate the parsed expression
123 val(c) = evaluate(_func_F);
124 }
125
126 return val;
127}
registerMooseObject("MooseApp", ArrayParsedAux)
AuxKernel that evaluates a parsed function expression for each component of an array variable.
static InputParameters validParams()
const unsigned int _n_vars
Number of coupled regular variables.
virtual RealEigenVector computeValue() override
Compute and return the value of the aux variable.
std::string _function
Function expression.
ArrayParsedAux(const InputParameters &parameters)
const unsigned int _n_array_vars
Number of coupled array variables.
const std::vector< const VariableValue * > _vars
Regular variable values.
const bool _use_xyzt
Import coordinates and time.
SymFunctionPtr _func_F
Function parser object that is evaluated for setting aux-variable values.
const std::vector< const ArrayVariableValue * > _array_vars
Array variable values.
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition AuxKernel.h:28
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
MooseVariableField< ComputeValueType > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition AuxKernel.h:113
static InputParameters validParams()
Definition AuxKernel.C:27
const MooseVariableFieldBase * getFieldVar(const std::string &var_name, unsigned int comp) const
Definition Coupleable.C:307
ArrayMooseVariable * getArrayVar(const std::string &var_name, unsigned int comp)
Extract pointer to a coupled array variable.
Definition Coupleable.C:337
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void parsedFunctionSetup(SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
Performs setup steps on a SymFunction.
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 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.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one.
const Parallel::Communicator & comm() const
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165