www.mooseframework.org
ParsedAux.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "ParsedAux.h"
16 
17 template <>
20 {
23  params.addClassDescription("Parsed function AuxKernel.");
24 
25  params.addRequiredCustomTypeParam<std::string>(
26  "function", "FunctionExpression", "function expression");
27  params.addCoupledVar("args", "coupled variables");
28  params.addParam<std::vector<std::string>>(
29  "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
30  params.addParam<std::vector<std::string>>(
31  "constant_expressions",
32  "Vector of values for the constants in constant_names (can be an FParser expression)");
33 
34  return params;
35 }
36 
38  : AuxKernel(parameters),
39  FunctionParserUtils(parameters),
40  _function(getParam<std::string>("function")),
41  _nargs(coupledComponents("args")),
42  _args(_nargs)
43 {
44  // build variables argument
45  std::string variables;
46  for (unsigned int i = 0; i < _nargs; ++i)
47  {
48  variables += (i == 0 ? "" : ",") + getVar("args", i)->name();
49  _args[i] = &coupledValue("args", i);
50  }
51 
52  // base function object
54 
55  // set FParser interneal feature flags
57 
58  // add the constant expressions
60  getParam<std::vector<std::string>>("constant_names"),
61  getParam<std::vector<std::string>>("constant_expressions"));
62 
63  // parse function
64  if (_func_F->Parse(_function, variables) >= 0)
65  mooseError(
66  "Invalid function\n", _function, "\nin ParsedAux ", name(), ".\n", _func_F->ErrorMsg());
67 
68  // optimize
70  _func_F->Optimize();
71 
72  // just-in-time compile
73  if (_enable_jit)
74  _func_F->JITCompile();
75 
76  // reserve storage for parameter passing bufefr
77  _func_params.resize(_nargs);
78 }
79 
80 Real
82 {
83  for (unsigned int j = 0; j < _nargs; ++j)
84  _func_params[j] = (*_args[j])[_qp];
85 
86  return evaluate(_func_F);
87 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
Real evaluate(ADFunctionPtr &)
Evaluate FParser object and check EvalError.
void addFParserConstants(ADFunctionPtr &parser, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions)
add constants (which can be complex expressions) to the parser object
FunctionParserADBase< Real > ADFunction
Shorthand for an autodiff function parser object.
unsigned int _nargs
coupled variables
Definition: ParsedAux.h:42
ADFunctionPtr _func_F
function parser object for the resudual and on-diagonal Jacobian
Definition: ParsedAux.h:46
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::shared_ptr< ADFunction > ADFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
Extract pointer to a coupled variable.
Definition: Coupleable.C:117
std::vector< const VariableValue * > _args
Definition: ParsedAux.h:43
const std::string & name() const
Get the variable name.
std::string _function
function expression
Definition: ParsedAux.h:39
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:30
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:192
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:51
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0)
Returns value of a coupled variable.
Definition: Coupleable.C:167
InputParameters validParams< FunctionParserUtils >()
InputParameters validParams< ParsedAux >()
Definition: ParsedAux.C:19
std::vector< Real > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void setParserFeatureFlags(ADFunctionPtr &)
apply input paramters to internal feature flags of the parser 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 mooseError(Args &&...args) const
Definition: MooseObject.h:80
ParsedAux(const InputParameters &parameters)
Definition: ParsedAux.C:37
virtual Real computeValue() override
Definition: ParsedAux.C:81