|
Neko 1.99.7
A portable framework for high-order spectral element flow simulations
|
Evaluation of mathematical expressions given as strings in the case file. More...
Data Types | |
| type | expression_t |
| A compiled mathematical expression. More... | |
| type | parser_t |
| State of the recursive descent parser. More... | |
| type | token_t |
| A single token of an expression. More... | |
Functions/Subroutines | |
| subroutine | expression_init (this, str) |
| Compile an expression. | |
| subroutine | parser_free (p) |
| Release the memory held by the parser state. | |
| subroutine | expression_free (this) |
| Destructor. | |
| subroutine | expression_eval (this, res, n, x, y, z, t, dt) |
Evaluate the expression in n points. | |
| subroutine, public | expression_eval_static (str, res, n, x, y, z, usage) |
| Compile an expression and evaluate it in a set of points, in a context where there is no time state. | |
| subroutine, public | expression_check_finite (str, res, n, usage) |
| Abort if an expression did not evaluate to a finite value everywhere. | |
| subroutine | expr_tokenize (p) |
| Split the source string into a stream of tokens. | |
| subroutine | push_token (p, kind, pos) |
| Append a token to the token stream. | |
| recursive subroutine | parse_expr (p) |
| Parse an additive expression. | |
| recursive subroutine | parse_term (p) |
| Parse a multiplicative expression. | |
| recursive subroutine | parse_factor (p) |
Parse a possibly signed factor. Unary minus binds looser than ^, so -x^2 is -(x^2), as in Fortran. | |
| recursive subroutine | parse_power (p) |
Parse an exponentiation. Right associative, so 2^3^2 is 2^(3^2). | |
| recursive subroutine | parse_primary (p) |
| Parse a literal, a symbol, a function call or a parenthesised expression. | |
| subroutine | parse_symbol (p, k) |
| Resolve a bare identifier into either a variable opcode or a literal. | |
| integer function | func_op (name, nargs) |
| Look up the opcode of a function. | |
| subroutine | emit (p, op, val) |
| Append an opcode, keeping track of how deep the evaluation stack gets. | |
| subroutine | expr_error (p, msg, pos) |
| Abort with a message pointing at the offending part of the expression. | |
| pure logical function | is_digit (c) |
True if c is a decimal digit. | |
| pure logical function | is_alpha (c) |
True if c is a letter. | |
An expression_t is compiled once, from a string such as "6*U_b*y*(H - y)/H^2", into a stream of stack machine opcodes. It can then be evaluated over an arbitrary set of points, with x, y and z bound to the point coordinates and t, dt bound to the time state.
Any identifier which is not a coordinate, a time variable or the constant pi is looked up in the neko_const_registry when the expression is compiled, and folded into a literal. This is the same mechanism as the one used by json_get_or_lookup, so constants declared under case.constants in the case file can be used directly in the expressions.
|
private |
| [in,out] | p | The parser state. |
| [in] | op | The opcode to append. |
| [in] | val | The literal operand, only meaningful for OP_LIT. |
Definition at line 943 of file expression.f90.

|
private |
| [in] | p | The parser state. |
| [in] | msg | What is wrong with the expression. |
| [in] | pos | Position in the source string to point at. |
Definition at line 973 of file expression.f90.

|
private |
| [in,out] | p | The parser state, whose src holds the expression. |
Definition at line 514 of file expression.f90.


| subroutine, public expression::expression_check_finite | ( | character(len=*), intent(in) | str, |
| real(kind=rp), dimension(n), intent(in) | res, | ||
| integer, intent(in) | n, | ||
| character(len=*), intent(in) | usage | ||
| ) |
Split out of expression_eval_static so that the boundary conditions, which compile and evaluate their expressions themselves, can apply the same check. A non-finite value typically means a division by zero or the square root of a negative number somewhere.
| [in] | str | The expression, used in the error message. |
| [in] | res | The values to check. |
| [in] | n | The number of values. |
| [in] | usage | What the expression configures, used in error messages. |
Definition at line 492 of file expression.f90.


|
private |
Not thread safe. The evaluation stack is a component of the expression, so two concurrent calls on the same object corrupt each other's intermediate values. A caller inside an OpenMP parallel region must evaluate on one thread only.
| [in,out] | res | The result, one value per point. |
| [in] | n | The number of points. |
| [in] | x | The x-coordinates of the points. |
| [in] | y | The y-coordinates of the points. |
| [in] | z | The z-coordinates of the points. |
| [in] | t | The current time, required if the expression uses t. |
| [in] | dt | The current timestep, required if the expression uses dt. |
Definition at line 226 of file expression.f90.
| subroutine, public expression::expression_eval_static | ( | character(len=*), intent(in) | str, |
| real(kind=rp), dimension(n), intent(inout) | res, | ||
| integer, intent(in) | n, | ||
| real(kind=rp), dimension(n), intent(in) | x, | ||
| real(kind=rp), dimension(n), intent(in) | y, | ||
| real(kind=rp), dimension(n), intent(in) | z, | ||
| character(len=*), intent(in) | usage | ||
| ) |
Convenience routine for initial conditions and other setup-time uses of an expression. The expression is rejected if it is empty, if it depends on time, or if it does not evaluate to a finite value in every point, the latter typically meaning a division by zero or the square root of a negative number somewhere in the domain.
| [in] | str | The expression. |
| [in,out] | res | The result, one value per point. |
| [in] | n | The number of points. |
| [in] | x | The x-coordinates of the points. |
| [in] | y | The y-coordinates of the points. |
| [in] | z | The z-coordinates of the points. |
| [in] | usage | What the expression configures, used in error messages. |
Definition at line 455 of file expression.f90.

|
private |
Definition at line 201 of file expression.f90.
| subroutine expression::expression_init | ( | class(expression_t), intent(inout) | this, |
| character(len=*), intent(in) | str | ||
| ) |
| [in] | str | The expression, e.g. "6*U_b*y*(H - y)/H^2". |
Definition at line 146 of file expression.f90.

|
private |
| [in] | name | The name of the function. |
| [in] | nargs | The number of arguments it was called with. |
Definition at line 877 of file expression.f90.

| [in] | c | The character to test. |
Definition at line 997 of file expression.f90.

| [in] | c | The character to test. |
Definition at line 987 of file expression.f90.

|
private |
| [in,out] | p | The parser state. |
Definition at line 665 of file expression.f90.


|
private |
| [in,out] | p | The parser state. |
Definition at line 710 of file expression.f90.


|
private |
| [in,out] | p | The parser state. |
Definition at line 736 of file expression.f90.


|
private |
| [in,out] | p | The parser state. |
Definition at line 769 of file expression.f90.


|
private |
Coordinates and time variables take precedence over anything else. Everything that is left is looked up in the neko_const_registry and folded into a literal, so the value it had when the expression was compiled is the value that is used.
| [in,out] | p | The parser state. |
| [in] | k | Index of the identifier token to resolve. |
Definition at line 830 of file expression.f90.


|
private |
| [in,out] | p | The parser state. |
Definition at line 687 of file expression.f90.


|
private |
| [in,out] | p | The parser state. |
Definition at line 183 of file expression.f90.

|
private |
| [in,out] | p | The parser state. |
| [in] | kind | The kind of the token, one of the TK_ constants. |
| [in] | pos | Position of the token in the source string. |
Definition at line 642 of file expression.f90.

Definition at line 63 of file expression.f90.
Definition at line 58 of file expression.f90.
Definition at line 55 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 80 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 70 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 70 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 81 of file expression.f90.
Definition at line 70 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 74 of file expression.f90.
Definition at line 73 of file expression.f90.
Definition at line 70 of file expression.f90.
Definition at line 70 of file expression.f90.
Definition at line 70 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.
Definition at line 87 of file expression.f90.