Math Expressions
Mathematical expressions {math-expr}
are permitted on different arguments of the
configuration options. They consist of a string
that when interpreted and evaluated returns a numeric value. Such expressions may contain typical math
operations such as +
, -
, *
, sin
, tan
, sqrt
, etc.
The example below initializes the variable u
with and sets its diffusion coefficient to .
[model.scalar_value.u]
initial.expression = 1.0 + 2e-10
cross_diffusion.u.expression = sqrt(2e-10)
Note how the contents of these arguments need to be understood by a suitable math interpreter.
The exact syntax permitted within math expressions {math-expr}
depends on the parser type used to interpret
the expression. Every expression may be instructed to be interpreted with a different parser by setting [*.]parser_type={enum}
. The possible parsers are:
'ExprTk'
'ExprTk'
The C++ Mathematical Expression Toolkit Library. Focuses in functionality and performance.
'MuParser'
'MuParser'
A fast math parser library. Available in most package managers.
'SymEngine'
'SymEngine'
A symbolic manipulation library. Best known for its python bindings: SymPy
.
'SymEngineSBML'
'SymEngineSBML'
A SBML flavored syntax of the 'SymEngine'
parser.
Some parsers may not be available depending on how dune-copasi
is compiled. To see the available parsers use the --parser-list
command.
Every expression in {math-expr}
is compiled independently. This means that different parser types may be used in the same model definition. This is helful when the syntax of one parser is more convenient to write one expression. For example, the
ExprTk
parser allows the usage of ternary conditional operator cond ? expr1 : expr2
whereas SymEngine
does not:
[parser_context.pulse]
type = function
expression = t, t0, dt: abs(t-t0) < dt ? 1 : 0
parser_type = ExprTk
[model.scalar_value.u]
reaction.expression = 1e10 + pulse(time, 10, 1)
reaction.parser_type = SymEngine
Keywords
Math expressions may be evaluated in many different contextual environments, such as, in the initialization of variables, a coefficient interpretation, or as an aid to define the cells that belong to a comartment. Depending on the context, several keywords are defined in order to help expressing the desired mathematical model. These keywords are declared and defined in the following way:
Contextual Transient Keywordβ
Whenever the context of the evaluation is transient, the time
keyword will evaluate to the corresponding simulation time .
In other words,
Contextual Domain Keywordsβ
Whenever an expression is evaluated at a position then this position is also available within the {math-expr}
. Such position is made available through the position_[x|y|z]
keywords such that
where is the extension of into .
We assume that the domain is covered by a mesh consisting of elements which are closed sets satisfying
The nonempty intersections of codimension 1 form the interior skeleton . Each intersection is equipped with a unit normal vector pointing from to . The intersections of an element with the domain boundary form the set of boundary intersections . Each boundary intersection is equipped with a unit normal vector which coincides with the unit outer normal to the domain.
Furthermore, the contextual domain evaluation is always associated to a grid element . Its properties are also expossed within the parser as: