expression
The expression
command can be used to define mathematical expressions that can be later used to customise relevant
material models.
The expression
command essentially parses a block of plain text into mathematical expressions.
The parsing and evaluation functionalities are powered by exprtk
.
The exprtk
generates an AST from the input text. The evaluation of the expression has an on par performance with
the native C++ code.
But a customisable expression allows for more flexibility and it is easier to experiment different functions.
Syntax
Simple Scalar-valued Expression
Text Only | |
---|---|
This evaluates a scalar-valued function "x_1|2|x_2"
represents two variables: 1)
This form supports automatic computation of derivatives. Thus, it can be used in models that require automatic computation of derivatives.
Simple Vector-valued Expression
Text Only | |
---|---|
This evaluates a vector-valued function
This form does support automatic computation of derivatives. Thus, it cannot be used in models that require automatic computation of derivatives.
Remarks
- The variables in the expression need to be explicitly given as the arguments.
It can be either unquoted or quoted by
"
. - Multiple variables must be separated by vertical bar
|
. - The expression can be given as a string or as a file name. The program tries to load the file first. If the file does not exist, the program tries to parse the string as an expression.
- No whitespace (',', ' ', etc.) is allowed in any arguments.
exprtk
provides very powerful functionalities. It is possible to apply logics and control flows in the expression.
Example
Say, for example, one is going to define a uniaxial nonlinear elastic model that uses the following stress-strain relationship:
Then the expression can be defined as
Text Only | |
---|---|
Here, we use x
as the free variable and the corresponding expression is x^3+x
.
For the unixial nonlienar elastic model, the input is strain, which maps to x
, the output maps to stress.
Alternatively, the expression can be stored in a file and loaded by the program.
Then the expression can be defined as
Text Only | |
---|---|
For complex expressions, it is convenient to use the file format.
To use the expression, here, CustomElastic1D
is used.
Text Only | |
---|---|
The response can be tested by material tester.