The expression language shared by every configured field, and the keyed hashes its random draws and other reproducible draws are built from. More...
Go to the source code of this file.
Data Structures | |
| struct | PicurvExpressionDrawKey |
| What a random draw is keyed on, besides the particle and its stream. More... | |
| struct | PicurvVelocitySource |
| A prescribed velocity, for any target: one compiled expression per value, the frame they are in, and the bulk velocity it is scaled to, if any. More... | |
| struct | PicurvSourceFaceSlots |
| What a source reads at each boundary-face slot this rank owns, gathered once. More... | |
Typedefs | |
| typedef struct PicurvExpression | PicurvExpression |
| A compiled expression: postfix code for a small stack evaluator. | |
Functions | |
| uint64_t | PicurvMix64 (uint64_t z) |
| splitmix64 finalizer: a bijective mix of 64 bits. | |
| PetscReal | PicurvUnitFromHash (uint64_t hash) |
| Uniform on [0, 1) from the top 53 bits of a hash. | |
| uint64_t | PicurvParticleDrawHash (PetscInt64 seed, PicurvDrawSpace space, uint64_t stream, PetscInt64 pid, PetscInt64 salt) |
| Hash that keys a particle draw: a pure function of its arguments, so a draw does not depend on the rank a particle lives on, the order particles are visited, or what was drawn before it. | |
| PetscErrorCode | PicurvExpressionCompile (const char *text, const char *const *names, PetscInt name_count, PetscBool allow_random, PicurvExpression **expression) |
| Compile one expression against a list of variable names. | |
| PetscErrorCode | PicurvExpressionEvaluate (const PicurvExpression *expression, const PetscReal *values, const PicurvExpressionDrawKey *key, PetscReal *result) |
| Evaluate a compiled expression. | |
| PetscErrorCode | PicurvExpressionDestroy (PicurvExpression **expression) |
| Free a compiled expression. | |
| PetscErrorCode | PicurvExpressionUsesVariable (const PicurvExpression *expression, PetscInt index, PetscBool *uses) |
| Whether a compiled expression reads one of its variables. | |
| PetscErrorCode | PicurvVelocitySourceCreate (const char *prefix, PetscBool on_face, PetscBool has_data, PicurvVelocitySource *source) |
| Read and compile a velocity source from the options database. | |
| PetscErrorCode | PicurvVelocitySourceBulkFactor (const PicurvVelocitySource *source, PetscReal physical_time, const PetscReal local[3], const char *where, PetscReal *factor) |
| Factor on a source's expressions that makes a target's whole mean equal its bulk velocity. | |
| static void | PicurvSourceSetVariables (PetscReal *values, Cmpnts point, Cmpnts fraction, Cmpnts length, PetscReal L_ref) |
| Fill a source's position and grid-line variables at one point. | |
| PetscErrorCode | PicurvSourceFaceSlotsCreate (UserCtx *user, BCFace face_id, Vec fraction, Vec length, PicurvSourceFaceSlots *slots) |
| Gather each owned slot of a boundary face: face-centre position, the grid-line fractions and lengths of the interior cell behind it, and its directions. | |
| PetscErrorCode | PicurvSourceFaceSlotsDestroy (PicurvSourceFaceSlots *slots) |
| Release what PicurvSourceFaceSlotsCreate() allocated. | |
| PetscErrorCode | PicurvVelocitySourceEvaluate (const PicurvVelocitySource *source, const PetscReal *values, const Cmpnts edges[3], Cmpnts *value) |
| Evaluate a source at one point. | |
| PetscErrorCode | PicurvSourceSetCellPressure (UserCtx *user, const PicurvExpression *pressure, Vec fraction, Vec length, PetscReal physical_time) |
| Set a block's pressure at every interior cell centre from an expression in Pa. | |
| PetscErrorCode | PicurvSourceCellBulkFactor (UserCtx *user, const PicurvVelocitySource *source, Vec fraction, Vec length, PetscReal physical_time, PetscReal *factor) |
| Factor on a source's expressions that makes the volume mean of the whole field, along the source's own direction at each cell, equal its bulk velocity. | |
| PetscErrorCode | PicurvSourceAddFluxes (UserCtx *user, const PicurvVelocitySource *source, Vec fraction, Vec length, PetscReal physical_time, PetscReal factor, PetscBool boundary_faces) |
| Add a source's flux to every owned face of Ucont, evaluating it at each face centre. | |
| PetscErrorCode | PicurvVelocitySourceDestroy (PicurvVelocitySource *source) |
| Free a source's compiled expressions and bulk velocity. | |
Variables | |
| const char *const | kPicurvSourceVariableNames [PICURV_SOURCE_VAR_COUNT] |
| Names of PicurvSourceVariable, in order. | |
The expression language shared by every configured field, and the keyed hashes its random draws and other reproducible draws are built from.
Callers compile an expression against their own list of variable names and supply the values in that order at evaluation. generators/ic.gen validates the same language; tests/fixtures/expression_conformance.txt holds cases both implementations must agree on.
Definition in file expression.h.
| struct PicurvExpressionDrawKey |
What a random draw is keyed on, besides the particle and its stream.
Definition at line 67 of file expression.h.
| Data Fields | ||
|---|---|---|
| PetscInt64 | seed |
Run seed (-particle_random_seed). |
| PetscInt64 | pid | Particle identity; draws are pure functions of it. |
| PetscInt64 | salt | Event that produced the particle: 0 for the t=0 population. |
| PetscInt64 | field | Field whose expression draws, the default stream's namespace. |
| struct PicurvVelocitySource |
A prescribed velocity, for any target: one compiled expression per value, the frame they are in, and the bulk velocity it is scaled to, if any.
A target differs only in the points it evaluates the source at and the weight it takes a mean with.
Definition at line 155 of file expression.h.
| Data Fields | ||
|---|---|---|
| PicurvSourceFrame | frame | |
| PetscInt | count | 1 for the normal frame, otherwise 3; 0 for staged data alone. |
| PicurvExpression * | component[3] | |
| PetscBool | time_dependent |
Some component reads t. |
| PicurvExpression * | bulk |
Target mean speed [m/s] in t, or NULL. |
| PetscBool | bulk_time_dependent | |
| PetscBool | bulk_is_flow_rate |
bulk is a volumetric flow rate [m^3/s] through a face instead. |
| struct PicurvSourceFaceSlots |
What a source reads at each boundary-face slot this rank owns, gathered once.
Definition at line 221 of file expression.h.
| Data Fields | ||
|---|---|---|
| PetscInt | normal | Logical axis of the face normal. |
| PetscInt | a | |
| PetscInt | b | The two tangential axes. |
| PetscInt | layer | Index along the normal of the face's metric and flux. |
| PetscInt | lo[2] | First tangential indices of the owned slots. |
| PetscInt | n[2] | Owned slots along the two tangential axes; 0 off the face. |
| PetscReal(* | values)[PICURV_SOURCE_VAR_COUNT] |
Variables per slot; t is the caller's. |
| Cmpnts(* | edges)[3] | Directions per slot, for the curvilinear frame. |
| typedef struct PicurvExpression PicurvExpression |
A compiled expression: postfix code for a small stack evaluator.
Definition at line 64 of file expression.h.
| enum PicurvDrawSpace |
Disjoint key spaces of the keyed particle draws, so draws made for different purposes never coincide for one particle.
Definition at line 27 of file expression.h.
| enum PicurvSourceVariable |
Variables a prescribed velocity source may use, in the order of values[].
Definition at line 126 of file expression.h.
| enum PicurvSourceFrame |
How a source's values are read.
Definition at line 143 of file expression.h.
| uint64_t PicurvMix64 | ( | uint64_t | z | ) |
splitmix64 finalizer: a bijective mix of 64 bits.
| [in] | z | Bits to mix. |
splitmix64 finalizer: a bijective mix of 64 bits.
Definition at line 587 of file expression.c.
| PetscReal PicurvUnitFromHash | ( | uint64_t | hash | ) |
Uniform on [0, 1) from the top 53 bits of a hash.
| [in] | hash | Mixed bits. |
Uniform on [0, 1) from the top 53 bits of a hash.
Definition at line 599 of file expression.c.
| uint64_t PicurvParticleDrawHash | ( | PetscInt64 | seed, |
| PicurvDrawSpace | space, | ||
| uint64_t | stream, | ||
| PetscInt64 | pid, | ||
| PetscInt64 | salt | ||
| ) |
Hash that keys a particle draw: a pure function of its arguments, so a draw does not depend on the rank a particle lives on, the order particles are visited, or what was drawn before it.
| [in] | seed | Run seed (-particle_random_seed). |
| [in] | space | Purpose of the draw. |
| [in] | stream | Stream within the space. |
| [in] | pid | Particle identity. |
| [in] | salt | Event that distinguishes repeated draws for one particle. |
Hash that keys a particle draw: a pure function of its arguments, so a draw does not depend on the rank a particle lives on, the order particles are visited, or what was drawn before it.
Definition at line 608 of file expression.c.
| PetscErrorCode PicurvExpressionCompile | ( | const char * | text, |
| const char *const * | names, | ||
| PetscInt | name_count, | ||
| PetscBool | allow_random, | ||
| PicurvExpression ** | expression | ||
| ) |
Compile one expression against a list of variable names.
The grammar is Python's expression syntax restricted to numbers, the given names, pi, arithmetic (+ - * / % **), comparisons (chained ones included), and/or/not, and the functions abs atan2 cos cosh erf exp floor log maximum minimum sin sinh sqrt tan tanh where, plus uniform and normal when allow_random is true. Comparisons and logical operators yield 1 or 0; % takes the sign of the divisor; ** binds tighter than a unary minus on its left and groups to the right.
| [in] | text | Expression text. |
| [in] | names | Variable names, in the order evaluation supplies their values. |
| [in] | name_count | Number of names. |
| [in] | allow_random | Whether uniform and normal may be called. |
| [out] | expression | Compiled expression, owned by the caller. |
PETSC_ERR_ARG_WRONG for a syntax error or an unknown name or function, with the offending position in the message.Compile one expression against a list of variable names.
Definition at line 549 of file expression.c.
| PetscErrorCode PicurvExpressionEvaluate | ( | const PicurvExpression * | expression, |
| const PetscReal * | values, | ||
| const PicurvExpressionDrawKey * | key, | ||
| PetscReal * | result | ||
| ) |
Evaluate a compiled expression.
| [in] | expression | Compiled expression. |
| [in] | values | One value per compiled name, in compile order. |
| [in] | key | Draw key, required when the expression draws; may be NULL otherwise. |
| [out] | result | Value of the expression; may be non-finite, which the caller judges. |
Evaluate a compiled expression.
Definition at line 695 of file expression.c.
| PetscErrorCode PicurvExpressionDestroy | ( | PicurvExpression ** | expression | ) |
Free a compiled expression.
| [in,out] | expression | Expression to free; set to NULL. |
Free a compiled expression.
Definition at line 789 of file expression.c.
| PetscErrorCode PicurvExpressionUsesVariable | ( | const PicurvExpression * | expression, |
| PetscInt | index, | ||
| PetscBool * | uses | ||
| ) |
Whether a compiled expression reads one of its variables.
| [in] | expression | Compiled expression. |
| [in] | index | Position of the variable in the compile-time name list. |
| [out] | uses | True when some instruction loads that variable. |
Whether a compiled expression reads one of its variables.
Definition at line 805 of file expression.c.
| PetscErrorCode PicurvVelocitySourceCreate | ( | const char * | prefix, |
| PetscBool | on_face, | ||
| PetscBool | has_data, | ||
| PicurvVelocitySource * | source | ||
| ) |
Read and compile a velocity source from the options database.
Reads -<prefix>_frame (cartesian, curvilinear, on a face normal, otherwise contravariant), one expression per value, -<prefix>_expr_<c>, written in physical units over the names of PicurvSourceVariable, and the optional -<prefix>_bulk_velocity, an expression in t. Random draws are not available.
| [in] | prefix | Option prefix without its dash, e.g. ic_source or face_source_0. |
| [in] | on_face | Whether the target is a face, where the normal frame means something. |
| [in] | has_data | Whether the target also has staged data, which makes the expressions optional; without a frame, data on a face is a normal speed. |
| [out] | source | Compiled source; release it with PicurvVelocitySourceDestroy(). |
PETSC_ERR_USER_INPUT for a missing option or unknown frame, PETSC_ERR_ARG_WRONG for a malformed expression.Read and compile a velocity source from the options database.
Definition at line 830 of file expression.c.
| PetscErrorCode PicurvVelocitySourceBulkFactor | ( | const PicurvVelocitySource * | source, |
| PetscReal | physical_time, | ||
| const PetscReal | local[3], | ||
| const char * | where, | ||
| PetscReal * | factor | ||
| ) |
Factor on a source's expressions that makes a target's whole mean equal its bulk velocity.
Solves factor * expressions + data = bulk, over the target's points and weight. Collective.
| [in] | source | Source with a bulk velocity. |
| [in] | physical_time | Time the bulk velocity is read at [s]. |
| [in] | local | This rank's weighted sums, physical: the expressions' speed, the staged data's speed along it, and the weight, an area [m^2] for a flow rate. |
| [in] | where | The target, for the error messages. |
| [out] | factor | Factor on the expressions. |
PETSC_ERR_ARG_WRONGSTATE for no weight or a zero mean.Factor on a source's expressions that makes a target's whole mean equal its bulk velocity.
Definition at line 882 of file expression.c.
|
inlinestatic |
Fill a source's position and grid-line variables at one point.
| [out] | values | Array of PICURV_SOURCE_VAR_COUNT; t is left to the caller. |
| [in] | point | Solver-unit position. |
| [in] | fraction | Grid-line fractions there, from ComputeGridLineFractions(). |
| [in] | length | Solver-unit grid-line lengths there. |
| [in] | L_ref | Length reference [m]. |
Definition at line 206 of file expression.h.
| PetscErrorCode PicurvSourceFaceSlotsCreate | ( | UserCtx * | user, |
| BCFace | face_id, | ||
| Vec | fraction, | ||
| Vec | length, | ||
| PicurvSourceFaceSlots * | slots | ||
| ) |
Gather each owned slot of a boundary face: face-centre position, the grid-line fractions and lengths of the interior cell behind it, and its directions.
A curvilinear component is the speed through the grid face, as on every target, so along the face's own axis the direction follows the face metric rather than the cell's edge.
| [in] | user | Block with current metric and face-centre ghosts. |
| [in] | face_id | Face. |
| [in] | fraction | Grid-line fractions, from ComputeGridLineFractions(). |
| [in] | length | Grid-line lengths, from ComputeGridLineFractions(). |
| [out] | slots | The slots; release with PicurvSourceFaceSlotsDestroy(). |
Gather each owned slot of a boundary face: face-centre position, the grid-line fractions and lengths of the interior cell behind it, and its directions.
Definition at line 1124 of file expression.c.
| PetscErrorCode PicurvSourceFaceSlotsDestroy | ( | PicurvSourceFaceSlots * | slots | ) |
Release what PicurvSourceFaceSlotsCreate() allocated.
| [in,out] | slots | The slots. |
Release what PicurvSourceFaceSlotsCreate() allocated.
Definition at line 1203 of file expression.c.
| PetscErrorCode PicurvVelocitySourceEvaluate | ( | const PicurvVelocitySource * | source, |
| const PetscReal * | values, | ||
| const Cmpnts | edges[3], | ||
| Cmpnts * | value | ||
| ) |
Evaluate a source at one point.
| [in] | source | Compiled source. |
| [in] | values | One value per PicurvSourceVariable. |
| [in] | edges | Cell edge vectors along xi, eta, zeta (any length); read only in the curvilinear frame. |
| [out] | value | Physical Cartesian velocity, or for the normal frame the speed in x. |
PETSC_ERR_FP for a non-finite value.Evaluate a source at one point.
Definition at line 907 of file expression.c.
| PetscErrorCode PicurvSourceSetCellPressure | ( | UserCtx * | user, |
| const PicurvExpression * | pressure, | ||
| Vec | fraction, | ||
| Vec | length, | ||
| PetscReal | physical_time | ||
| ) |
Set a block's pressure at every interior cell centre from an expression in Pa.
Dummy cells are left to the caller's boundary pass.
| [in] | user | Block with current cell centres. |
| [in] | pressure | Expression over the cell variables, physical. |
| [in] | fraction | Grid-line fractions, from ComputeGridLineFractions(). |
| [in] | length | Grid-line lengths, from ComputeGridLineFractions(). |
| [in] | physical_time | Time [s]. |
Set a block's pressure at every interior cell centre from an expression in Pa.
Definition at line 1086 of file expression.c.
| PetscErrorCode PicurvSourceCellBulkFactor | ( | UserCtx * | user, |
| const PicurvVelocitySource * | source, | ||
| Vec | fraction, | ||
| Vec | length, | ||
| PetscReal | physical_time, | ||
| PetscReal * | factor | ||
| ) |
Factor on a source's expressions that makes the volume mean of the whole field, along the source's own direction at each cell, equal its bulk velocity.
Collective.
| [in] | user | Block; its Ucat holds whatever is staged. |
| [in] | source | Source with a bulk velocity. |
| [in] | fraction | Grid-line fractions, from ComputeGridLineFractions(). |
| [in] | length | Grid-line lengths, from ComputeGridLineFractions(). |
| [in] | physical_time | Time [s]. |
| [out] | factor | Factor on the expressions. |
Factor on a source's expressions that makes the volume mean of the whole field, along the source's own direction at each cell, equal its bulk velocity.
Definition at line 944 of file expression.c.
| PetscErrorCode PicurvSourceAddFluxes | ( | UserCtx * | user, |
| const PicurvVelocitySource * | source, | ||
| Vec | fraction, | ||
| Vec | length, | ||
| PetscReal | physical_time, | ||
| PetscReal | factor, | ||
| PetscBool | boundary_faces | ||
| ) |
Add a source's flux to every owned face of Ucont, evaluating it at each face centre.
A Cartesian velocity is dotted with the face metric; a curvilinear component is the speed through the face, times its area; a contravariant component is the flux itself.
| [in,out] | user | Block whose Ucont receives the fluxes. |
| [in] | source | Source with expressions. |
| [in] | fraction | Grid-line fractions, from ComputeGridLineFractions(). |
| [in] | length | Grid-line lengths, from ComputeGridLineFractions(). |
| [in] | physical_time | Time [s]. |
| [in] | factor | Factor on the expressions. |
| [in] | boundary_faces | Whether the boundary - faces are set too; each cell's + face always is. |
Add a source's flux to every owned face of Ucont, evaluating it at each face centre.
Definition at line 998 of file expression.c.
| PetscErrorCode PicurvVelocitySourceDestroy | ( | PicurvVelocitySource * | source | ) |
Free a source's compiled expressions and bulk velocity.
| [in,out] | source | Source to release; left empty. |
Free a source's compiled expressions and bulk velocity.
Definition at line 1216 of file expression.c.
|
extern |
Names of PicurvSourceVariable, in order.
Definition at line 821 of file expression.c.