[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2.1 Definition 2.2 Constants 2.3 Operators 2.4 Functions 2.5 Current values 2.6 Arguments 2.7 Registers 2.8 Fields 2.9 Loops and conditionals
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Expressions are the basic tool of GetDP. They cover a wide range of functional expressions, from constants to formal expressions containing functions (built-in or user-defined, depending on space and time, etc.), arguments, discrete quantities and their associated differential operators, etc. Note that `white space' (spaces, tabs, new line characters) is ignored inside expressions (as well as inside all GetDP objects).
Expressions are denoted by the metasyntactic variable expression (remember the definition of the syntactic rules in 1.2 Syntactic rules used in this document):
expression: ( expression ) | integer | real | constant-id | quantity | argument | current-value | register-value-set | register-value-get | operator-unary expression | expression operator-binary expression | expression operator-ternary-left expression operator-ternary-right expression | built-in-function-id [ < expression-list > ] < { expression-cst-list } > | function-id [ < expression-list > ] | < Real | Complex > [ expression ] | Dt [ expression ] | AtAnteriorTimeStep [ expression, integer ] | Order [ quantity ] | Trace [ expression, group-id ] | expression ##integer |
The following sections introduce the quantities that can appear in expressions, i.e. constant terminals (integer, real) and constant expression identifiers (constant-id, expression-cst-list), discretized fields (quantity), arguments (argument), current values (current-value), register values (register-value-set, register-value-get), operators (operator-unary, operator-binary, operator-ternary-left, operator-ternary-right) and built-in or user-defined functions (built-in-function-id, function-id). The last seven cases in this definition permit to cast an expression as real or complex, get the time derivative or evaluate an expression at an anterior time step, retrieve the interpolation order of a discretized quantity, evaluate the trace of an expression, and print the value of an expression for debugging purposes.
List of expressions are defined as:
expression-list: expression <,...> |
2.3 Operators 2.2 Constants 2.4 Functions 2.5 Current values 2.8 Fields
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The three constant types used in GetDP are integer, real and string. These types have the same meaning and syntax as in the C or C++ programming languages. Besides general expressions (expression), purely constant expressions, denoted by the metasyntactic variable expression-cst, are also used:
expression-cst: ( expression-cst ) | integer | real | constant-id | operator-unary expression-cst | expression-cst operator-binary expression-cst | expression-cst operator-ternary-left expression-cst operator-ternary-right expression-cst | math-function-id [ < expression-cst-list > ] |
List of constant expressions are defined as:
expression-cst-list: expression-cst-list-item <,...> |
with
expression-cst-list-item: expression-cst | expression-cst : expression-cst | expression-cst : expression-cst : expression-cst | constant-id {} | constant-id { expression-cst-list } | List[ constant-id ] | ListAlt[ constant-id, constant-id ] | LinSpace[ expression-cst, expression-cst, expression-cst ] | LogSpace[ expression-cst, expression-cst, expression-cst ] |
The second case in this last definition permits to create a list containing
the range of numbers comprised between the two expression-cst, with a
unit incrementation step. The third case also permits to create a list
containing the range of numbers comprised between the two
expression-cst, but with a positive or negative incrementation step
equal to the third expression-cst. The fourth and fifth cases permit
to reference constant identifiers (constant-ids) of lists of constants
and constant identifiers of sublists of constants (see below for the
definition of constant identifiers) . The sixth case is a synonym for the
fourth. The seventh case permits to create alternate lists: the arguments of
ListAlt
must be constant-ids of lists of constants of the same
dimension. The result is an alternate list of these constants: first
constant of argument 1, first constant of argument 2, second constant of
argument 1, etc. These kinds of lists of constants are for example often
used for function parameters (see section 2.4 Functions). The last two cases permit
to create linear and logarithmic lists of numbers, respectively.
Contrary to a general expression which is evaluated at runtime (thanks to an internal stack mechanism), an expression-cst is completely evaluated during the syntactic analysis of the problem (when GetDP reads the `.pro' file). The definition of such constants or lists of constants with identifiers can be made outside or inside any GetDP object. The syntax for the definition of constants is:
affectation: DefineConstant [ constant-id < = expression-cst > string-id < = "string" > <,...> ]; | constant-id = constant-def; | string-id = string-def; | Printf("string"); | Printf("string", expression-cst-list); | Read(constant-id); | Read(constant-id)[expression-cst]; |
with
constant-id: string | string ~ { expression-cst } constant-def: expression-cst-list-item | { expression-cst-list } | ListFromFile [ expression-char ] string-id: string | string ~ { expression-cst } string-def: "string" | Str[ expression-char ] | StrCat[ expression-char, expression-char ] |
Notes:
Pi
(3.1415926535897932),
0D
(0), 1D
(1), 2D
(2) and 3D
(3).
~{expression-cst}
is appended to a string string,
the result is a new string formed by the concatenation of string,
_
(an underscore) and the value of the expression-cst. This is
most useful in loops (see section 2.9 Loops and conditionals), where it permits to
define unique strings automatically. For example,
For i In {1:3} x~{i} = i; EndFor |
x_1 = 1; x_2 = 2; x_3 = 3; |
DefineConstant
(zero if no expression-cst is
given) is performed only if constant-id has not yet been defined. This
kind of explicit default definition mechanism is most useful in general
problem definition structures making use of a large number of generic
constants, functions or groups. When exploiting only a part of a complex
problem definition structure, the default definition mechanism allows to
define the quantities of interest only, the others being assigned a default
value (that will not be used during the processing but that avoids the error
messages produced when references to undefined quantities are made).
See 5.1 Constant expression examples, as well as 5.3 Function
examples, for
some examples.
Character expressions are defined as follows:
expression-char: "string" | string-id | StrCat[ expression-char , expression-char ] | Sprintf( expression-char ) | Sprintf( expression-char, expression-cst-list ) | Date |
The third case in this definition permits to concatenate two character expressions; the next two cases permit to print the value of variables using standard C formatting; the last case permits to access the current date.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2.3.1 Operator types 2.3.2 Evaluation order
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The operators in GetDP are similar to the corresponding operators in the C or C++ programming languages.
operator-unary:
-
!
operator-binary:
^
*
/\
/
%
+
-
==
!=
>
>=
<
<=
&&
||
||
is
evaluated even if the first one is true.
operator-ternary-left:
?
:
?
), which must result in a
scalar value. If it is true (non-zero) the second argument (located between
?
and :
) is evaluated and returned; otherwise the third
argument (located after :
) is evaluated and returned.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The evaluation priorities are summarized below (from stronger to weaker,
i.e. ^
has the highest evaluation priority). Parentheses
()
may be used anywhere to change the order of evaluation.
^
- (unary), !
/\
*, /, %
+, -
<, >, <=, >=
!=, ==
&&, ||
?:
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Two types of functions coexist in GetDP: user-defined functions
(function-id, see 3.2 Function
: defining global and piecewise expressions) and built-in functions
(built-in-function-id, defined in this section).
Both types of functions are always followed by a pair of brackets []
that can possibly contain arguments (see section 2.6 Arguments). This makes it
simple to distinguish a function-id or a built-in-function-id
from a constant-id. As shown below, built-in functions might also have
parameters, given between braces {}
, and which are completely
evaluated during the analysis of the syntax (since they are of
expression-cst-list type):
built-in-function-id [ < expression-list > ] < { expression-cst-list } > |
with
built-in-function-id: math-function-id | extended-math-function-id | green-function-id | type-function-id | coord-function-id | misc-function-id |
Notes:
Function
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Current values are a special kind of arguments (see section 2.6 Arguments) which return the current integer or floating point value of an internal GetDP variable:
$Time
$DTime
$Theta
$TimeStep
$Iteration
$EigenvalueReal
$EigenvalueImag
$X, $XS
$Y, $YS
$Z, $ZS
$A, $B, $C
OnGrid
PostOperation
(see section 4.10 Types for PostOperation
).
Note:
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function arguments can be used in expressions and have the following syntax (integer indicates the position of the argument in the expression-list of the function, starting from 1):
argument: $integer |
See 3.2 Function
: defining global and piecewise expressions, and 5.3 Function
examples, for more details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In many situations, identical parts of expressions are used more than once. If this is not a problem with constant expressions (since expression-csts are evaluated only once during the analysis of the problem definition structure, cf. 2.2 Constants), it may introduce some important overhead while evaluating complex expressions (which are evaluated at runtime, thanks to an internal stack mechanism). In order to circumvent this problem, the evaluation result of any part of an expression can be saved in a register: a memory location where this partial result will be accessible without any costly reevaluation of the partial expression.
Registers have the following syntax:
register-value-set: expression#integer register-value-get: #integer |
Thus, to store any part of an expression in the register 5, one
should add #5
directly after the expression. To reuse the value
stored in this register, one simply uses #5
instead of the expression
it should replace.
See 5.3 Function
examples, for an example.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A discretized quantity (defined in a function space, cf.
3.4 FunctionSpace
: building function spaces) is represented between braces {}
, and can only
appear in well-defined expressions in Formulation
(see section 3.7 Formulation
: building equations) and PostProcessing
(see section 3.9 PostProcessing
: exploiting computational results)
objects:
quantity: < quantity-dof > { < quantity-operator > quantity-id } | { < quantity-operator > quantity-id } [ expression-cst-list ] |
with
quantity-id: string | string ~ { expression-cst } |
and
quantity-dof:
Dof
D
egrees o
f
f
reedom), to be used only in Equation
terms of formulations to
define (elementary) matrices. Roughly said, the Dof
symbol in front
of a discrete quantity indicates that this quantity is an unknown quantity,
and should therefore not be considered as already computed.
BF
quantity-operator:
d
Grad
Curl
Rot
Div
dInv
GradInv
CurlInv
RotInv
DivInv
Notes:
Grad
, Curl
and Div
can be applied
to 0, 1 and 2-forms respectively, the exterior derivative operator d
is usually preferred with such fields.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Loops and conditionals are defined as follows, and can be imbricated:
loop:
For ( expression-cst : expression-cst )
For ( expression-cst
: expression-cst )
' and the matching EndFor
are executed.
For ( expression-cst : expression-cst : expression-cst )
For ( expression-cst : expression-cst :
expression-cst )
' and the matching EndFor
are executed.
For string In { expression-cst : expression-cst }
For string In {
expression-cst : expression-cst }
' and the matching EndFor
are
executed.
For string In { expression-cst : expression-cst : expression-cst }
For string In { expression-cst :
expression-cst : expression-cst }
' and the matching EndFor
are
executed.
EndFor
For
command.
If ( expression-cst )
If ( expression-cst )
' and the matching
Endif
is evaluated if expression-cst is non-zero.
EndIf
If
command.
Loops and conditionals can be used in any of the following objects: Group, Function, Constraint (as well as in a contraint-case), FunctionSpace, Formulation (as well as in the quantity and equation defintions), Resolution (as well as resolution-term, system defintion and operations), PostProcessing (in the definition of the PostQuantities) and PostOperation (as well as in the operation list).
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |