www.mooseframework.org
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
FunctionParserUtils Class Reference

#include <FunctionParserUtils.h>

Inheritance diagram for FunctionParserUtils:
[legend]

Public Types

typedef FunctionParserADBase< Real > ADFunction
 Shorthand for an autodiff function parser object. More...
 
typedef std::shared_ptr< ADFunctionADFunctionPtr
 Shorthand for an smart pointer to an autodiff function parser object. More...
 

Public Member Functions

 FunctionParserUtils (const InputParameters &parameters)
 
void setParserFeatureFlags (ADFunctionPtr &)
 apply input paramters to internal feature flags of the parser object More...
 

Protected Member Functions

Real evaluate (ADFunctionPtr &)
 Evaluate FParser object and check EvalError. More...
 
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 More...
 

Protected Attributes

const Real _nan
 appropriate not a number value to return More...
 
std::vector< Real > _func_params
 Array to stage the parameters passed to the functions when calling Eval. More...
 
bool _enable_jit
 
bool _enable_ad_cache
 
bool _disable_fpoptimizer
 
bool _enable_auto_optimize
 
bool _fail_on_evalerror
 

Static Protected Attributes

static const char * _eval_error_msg []
 table of FParser eval error codes More...
 

Detailed Description

Definition at line 35 of file FunctionParserUtils.h.

Member Typedef Documentation

typedef FunctionParserADBase<Real> FunctionParserUtils::ADFunction

Shorthand for an autodiff function parser object.

Definition at line 41 of file FunctionParserUtils.h.

Shorthand for an smart pointer to an autodiff function parser object.

Definition at line 44 of file FunctionParserUtils.h.

Constructor & Destructor Documentation

FunctionParserUtils::FunctionParserUtils ( const InputParameters parameters)

Definition at line 59 of file FunctionParserUtils.C.

60  : _enable_jit(parameters.isParamValid("enable_jit") && parameters.get<bool>("enable_jit")),
61  _enable_ad_cache(parameters.get<bool>("enable_ad_cache")),
62  _disable_fpoptimizer(parameters.get<bool>("disable_fpoptimizer")),
63  _enable_auto_optimize(parameters.get<bool>("enable_auto_optimize") && !_disable_fpoptimizer),
64  _fail_on_evalerror(parameters.get<bool>("fail_on_evalerror")),
65  _nan(std::numeric_limits<Real>::quiet_NaN())
66 {
67 }
const Real _nan
appropriate not a number value to return
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

Member Function Documentation

void FunctionParserUtils::addFParserConstants ( ADFunctionPtr parser,
const std::vector< std::string > &  constant_names,
const std::vector< std::string > &  constant_expressions 
)
protected

add constants (which can be complex expressions) to the parser object

Definition at line 102 of file FunctionParserUtils.C.

Referenced by ParsedAddSideset::ParsedAddSideset(), ParsedAux::ParsedAux(), ParsedODEKernel::ParsedODEKernel(), and ParsedSubdomainMeshModifier::ParsedSubdomainMeshModifier().

105 {
106  // check constant vectors
107  unsigned int nconst = constant_expressions.size();
108  if (nconst != constant_expressions.size())
109  mooseError("The parameter vectors constant_names and constant_values must have equal length.");
110 
111  // previously evaluated constant_expressions may be used in following constant_expressions
112  std::vector<Real> constant_values(nconst);
113 
114  for (unsigned int i = 0; i < nconst; ++i)
115  {
116  ADFunctionPtr expression = ADFunctionPtr(new ADFunction());
117 
118  // set FParser internal feature flags
119  setParserFeatureFlags(expression);
120 
121  // add previously evaluated constants
122  for (unsigned int j = 0; j < i; ++j)
123  if (!expression->AddConstant(constant_names[j], constant_values[j]))
124  mooseError("Invalid constant name in ParsedMaterialHelper");
125 
126  // build the temporary comnstant expression function
127  if (expression->Parse(constant_expressions[i], "") >= 0)
128  mooseError("Invalid constant expression\n",
129  constant_expressions[i],
130  "\n in parsed function object.\n",
131  expression->ErrorMsg());
132 
133  constant_values[i] = expression->Eval(NULL);
134 
135  if (!parser->AddConstant(constant_names[i], constant_values[i]))
136  mooseError("Invalid constant name in parsed function object");
137  }
138 }
FunctionParserADBase< Real > ADFunction
Shorthand for an autodiff function parser object.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::shared_ptr< ADFunction > ADFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
void setParserFeatureFlags(ADFunctionPtr &)
apply input paramters to internal feature flags of the parser object
Real FunctionParserUtils::evaluate ( ADFunctionPtr parser)
protected

Evaluate FParser object and check EvalError.

Definition at line 77 of file FunctionParserUtils.C.

Referenced by ParsedODEKernel::computeQpJacobian(), ParsedODEKernel::computeQpOffDiagJacobian(), ParsedODEKernel::computeQpResidual(), ParsedAux::computeValue(), ParsedAddSideset::modify(), and ParsedSubdomainMeshModifier::modify().

78 {
79  // null pointer is a shortcut for vanishing derivatives, see functionsOptimize()
80  if (parser == NULL)
81  return 0.0;
82 
83  // evaluate expression
84  Real result = parser->Eval(_func_params.data());
85 
86  // fetch fparser evaluation error
87  int error_code = parser->EvalError();
88 
89  // no error
90  if (error_code == 0)
91  return result;
92 
93  // hard fail or return not a number
95  mooseError("DerivativeParsedMaterial function evaluation encountered an error: ",
96  _eval_error_msg[(error_code < 0 || error_code > 5) ? 0 : error_code]);
97 
98  return _nan;
99 }
static const char * _eval_error_msg[]
table of FParser eval error codes
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
const Real _nan
appropriate not a number value to return
std::vector< Real > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void FunctionParserUtils::setParserFeatureFlags ( ADFunctionPtr parser)

apply input paramters to internal feature flags of the parser object

Definition at line 70 of file FunctionParserUtils.C.

Referenced by addFParserConstants(), ParsedAddSideset::ParsedAddSideset(), ParsedAux::ParsedAux(), ParsedODEKernel::ParsedODEKernel(), and ParsedSubdomainMeshModifier::ParsedSubdomainMeshModifier().

71 {
72  parser->SetADFlags(ADFunction::ADCacheDerivatives, _enable_ad_cache);
73  parser->SetADFlags(ADFunction::ADAutoOptimize, _enable_auto_optimize);
74 }

Member Data Documentation

bool FunctionParserUtils::_disable_fpoptimizer
protected

Definition at line 61 of file FunctionParserUtils.h.

Referenced by ParsedAux::ParsedAux(), and ParsedODEKernel::ParsedODEKernel().

bool FunctionParserUtils::_enable_ad_cache
protected

Definition at line 60 of file FunctionParserUtils.h.

Referenced by setParserFeatureFlags().

bool FunctionParserUtils::_enable_auto_optimize
protected

Definition at line 62 of file FunctionParserUtils.h.

Referenced by setParserFeatureFlags().

bool FunctionParserUtils::_enable_jit
protected

Definition at line 59 of file FunctionParserUtils.h.

Referenced by ParsedAux::ParsedAux(), and ParsedODEKernel::ParsedODEKernel().

const char * FunctionParserUtils::_eval_error_msg
staticprotected
Initial value:
= {
"Unknown",
"Division by zero",
"Square root of a negative value",
"Logarithm of negative value",
"Trigonometric error (asin or acos of illegal value)",
"Maximum recursion level reached"}

table of FParser eval error codes

Definition at line 70 of file FunctionParserUtils.h.

Referenced by evaluate(), and validParams< FunctionParserUtils >().

bool FunctionParserUtils::_fail_on_evalerror
protected

Definition at line 63 of file FunctionParserUtils.h.

Referenced by evaluate().

std::vector<Real> FunctionParserUtils::_func_params
protected
const Real FunctionParserUtils::_nan
protected

appropriate not a number value to return

Definition at line 67 of file FunctionParserUtils.h.

Referenced by evaluate().


The documentation for this class was generated from the following files: