Expression Builder
Build FParser expressions using C++ operator overloading
Mixing in the ExpressionBuilder
class into your MOOSE classes will allow you to build FParser expressions using familiar C++ syntax.
Introduction
EBTerm
Variables used in your expressions are of type EBTerm
. The following declares three variables that can be used in an expression:
EBFunction
Declare a function G
and define it:
Performing a substitution is as easy as:
Use the <<
io operator to output functions or terms. Or use explicit or implicit casts from EBFunction
to std::string
to pass a function to the FParser Parse method. FParser variables are built using the args()
method.
Example
To use ExpressionBuilder
inherit from it in addition to the base class your free energy material is based on. A common scenario is to inherit from DerivativeParsedMaterialHelper
and ExpressionBuilder
. The class definition would be:
The free energy expression would then be built in the constructor.
That's it. The functionParse
call will generate, optimize, and (if selected by the user through the enable_jit
config parameter) compile the function and its derivatives.
All named variables declared through EBTerm var("name")
will be substituted by the coupled variables of the same name
.
See also
Automatic Differentiation for MOOSE application developers
Just In Time Compilation of parsed functions for MOOSE application developers