Per-window PETSc accumulator storage and pointwise application. More...
#include "statistics_accumulator.h"#include "statistics_moments.h"#include "statistics_target.h"#include "field_catalog.h"#include "io.h"#include "logging.h"#include <stddef.h>Go to the source code of this file.
Macros | |
| #define | STATISTICS_DERIVED_OUTPUT_LENGTH 256 |
| Longest output list a recipe may request. | |
| #define | __FUNCT__ "PicurvWindowStorageCreate" |
| #define | __FUNCT__ "PicurvWindowDerive" |
| #define | __FUNCT__ "PicurvWindowSpatialMean" |
| #define | __FUNCT__ "PicurvWindowValidFractionRange" |
| #define | __FUNCT__ "PicurvWindowAccumulate" |
Enumerations | |
| enum | DerivedKind { DERIVED_MEAN = 0 , DERIVED_REYNOLDS_STRESS , DERIVED_RMS , DERIVED_TKE , DERIVED_FLUX , DERIVED_KIND_COUNT } |
| Output kinds a postprocessing recipe may request, in enumeration order. More... | |
Functions | |
| static PetscInt | ProductDiagonalIndex (PetscInt component) |
| Internal helper: the product index carrying one component's own variance. | |
| static PetscErrorCode | ProductComponentLabel (PetscInt index, char *out, size_t size) |
| Internal helper: writes the two-axis label of one product component. | |
| PetscErrorCode | PicurvProductComponentCount (PetscInt dof, PetscInt *count) |
| Implementation of PicurvProductComponentCount(). | |
| PetscErrorCode | PicurvCovarianceComponentCount (PetscInt dof_a, PetscInt dof_b, PetscInt *count) |
| Implementation of PicurvCovarianceComponentCount(). | |
| PetscErrorCode | PicurvStatisticsComponentDM (UserCtx *user, PetscInt components, DM *dm) |
| Implementation of PicurvStatisticsComponentDM(). | |
| PetscErrorCode | PicurvWindowStorageCreate (UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage) |
| Implementation of PicurvWindowStorageCreate(). | |
| PetscErrorCode | PicurvWindowStorageDestroy (PicurvWindowStorage *storage) |
| Implementation of PicurvWindowStorageDestroy(). | |
| static PetscErrorCode | FindFieldSlot (const PicurvWindowDefinition *definition, PetscInt field_id, PetscInt *slot) |
| Internal helper: locates the storage slot holding one field's running mean. | |
| PetscErrorCode | PicurvWindowStoragePayloadCount (const PicurvWindowStorage *storage, PetscInt *count) |
| Implementation of PicurvWindowStoragePayloadCount(). | |
| PetscErrorCode | PicurvWindowStoragePayload (UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, PetscInt index, PicurvStatisticsPayload *payload) |
| Implementation of PicurvWindowStoragePayload(). | |
| static PetscErrorCode | ParseDerivedKinds (const char *outputs, PetscBool wanted[DERIVED_KIND_COUNT]) |
| Internal helper: reports which output kinds a recipe requested. | |
| static PetscErrorCode | DerivedKindExtent (const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, DerivedKind kind, PetscInt *count) |
| Internal helper: counts the derived fields each kind contributes. | |
| PetscErrorCode | PicurvWindowDerivedCount (const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, const char *outputs, PetscInt *count) |
| Implementation of PicurvWindowDerivedCount(). | |
| static PetscErrorCode | SafeStandardDeviation (PetscReal variance, const char *label, PetscReal *result) |
| Internal helper: takes a square root of a variance that may be barely negative. | |
| static PetscErrorCode | ResolveDerivedIndex (const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, const PetscBool wanted[DERIVED_KIND_COUNT], PetscInt index, DerivedKind *kind, PetscInt *offset) |
| Internal helper: resolves which kind and member one derived index selects. | |
| PetscErrorCode | PicurvWindowDerive (UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, const char *outputs, PetscInt index, Vec scalar_target, Vec vector_target, PicurvDerivedField *field) |
| Implementation of PicurvWindowDerive(). | |
| PetscErrorCode | PicurvWindowSpatialMean (UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, Vec field, PetscReal *mean) |
| Implementation of PicurvWindowSpatialMean(). | |
| PetscErrorCode | PicurvWindowValidFractionRange (UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, PetscInt sample_count, PetscReal *minimum, PetscReal *maximum) |
| Implementation of PicurvWindowValidFractionRange(). | |
| PetscErrorCode | PicurvWindowAccumulate (UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage, PetscReal weight) |
| Implementation of PicurvWindowAccumulate(). | |
Variables | |
| static const PetscInt | kProductFirst [6] = {0, 0, 0, 1, 1, 2} |
| Upper-triangular row-major component pairs for a three-vector self-product. | |
| static const PetscInt | kProductSecond [6] = {0, 1, 2, 1, 2, 2} |
| static const char *const | kAxisName [3] = {"x", "y", "z"} |
| Axis labels indexing the pair table above. | |
| static const char *const | kDerivedKindName [DERIVED_KIND_COUNT] |
| Recipe spellings of the output kinds. | |
| static const PetscInt | kDerivedKindScaleExponent [DERIVED_KIND_COUNT] |
| Power of the source field's reference scale each derived kind carries. | |
Per-window PETSc accumulator storage and pointwise application.
Full API contract is documented with the declarations in include/statistics_accumulator.h.
Definition in file statistics_accumulator.c.
| #define STATISTICS_DERIVED_OUTPUT_LENGTH 256 |
Longest output list a recipe may request.
Definition at line 19 of file statistics_accumulator.c.
| #define __FUNCT__ "PicurvWindowStorageCreate" |
Definition at line 135 of file statistics_accumulator.c.
| #define __FUNCT__ "PicurvWindowDerive" |
Definition at line 135 of file statistics_accumulator.c.
| #define __FUNCT__ "PicurvWindowSpatialMean" |
Definition at line 135 of file statistics_accumulator.c.
| #define __FUNCT__ "PicurvWindowValidFractionRange" |
Definition at line 135 of file statistics_accumulator.c.
| #define __FUNCT__ "PicurvWindowAccumulate" |
Definition at line 135 of file statistics_accumulator.c.
| enum DerivedKind |
Output kinds a postprocessing recipe may request, in enumeration order.
| Enumerator | |
|---|---|
| DERIVED_MEAN | |
| DERIVED_REYNOLDS_STRESS | |
| DERIVED_RMS | |
| DERIVED_TKE | |
| DERIVED_FLUX | |
| DERIVED_KIND_COUNT | |
Definition at line 380 of file statistics_accumulator.c.
|
static |
Internal helper: the product index carrying one component's own variance.
Local to this translation unit. Found by searching the pair table for the entry pairing a component with itself, so the diagonal cannot be stated separately from the order it belongs to.
Definition at line 56 of file statistics_accumulator.c.
|
static |
Internal helper: writes the two-axis label of one product component.
Local to this translation unit. Built from the pair table, so "xy" and the slot it names can never refer to different pairs.
Definition at line 69 of file statistics_accumulator.c.
| PetscErrorCode PicurvProductComponentCount | ( | PetscInt | dof, |
| PetscInt * | count | ||
| ) |
Implementation of PicurvProductComponentCount().
Reports how many symmetric product components a field's second moment needs.
Definition at line 83 of file statistics_accumulator.c.
| PetscErrorCode PicurvCovarianceComponentCount | ( | PetscInt | dof_a, |
| PetscInt | dof_b, | ||
| PetscInt * | count | ||
| ) |
Implementation of PicurvCovarianceComponentCount().
Reports how many components a covariance between two fields needs.
Definition at line 97 of file statistics_accumulator.c.
| PetscErrorCode PicurvStatisticsComponentDM | ( | UserCtx * | user, |
| PetscInt | components, | ||
| DM * | dm | ||
| ) |
Implementation of PicurvStatisticsComponentDM().
Resolves the DM carrying a given number of accumulator components.
Definition at line 115 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStorageCreate | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| PicurvWindowStorage * | storage | ||
| ) |
Implementation of PicurvWindowStorageCreate().
Allocates the accumulator state one window owns on one block.
Definition at line 140 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStorageDestroy | ( | PicurvWindowStorage * | storage | ) |
Implementation of PicurvWindowStorageDestroy().
Releases accumulator state previously created for one window.
Definition at line 220 of file statistics_accumulator.c.
|
static |
Internal helper: locates the storage slot holding one field's running mean.
Local to this translation unit. A covariance member must also appear in the window's field list, because the co-moment update needs that field's running mean; this is where that requirement is enforced.
Definition at line 249 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStoragePayloadCount | ( | const PicurvWindowStorage * | storage, |
| PetscInt * | count | ||
| ) |
Implementation of PicurvWindowStoragePayloadCount().
Reports how many checkpointable vectors one window's storage holds.
Definition at line 268 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStoragePayload | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| const PicurvWindowStorage * | storage, | ||
| PetscInt | index, | ||
| PicurvStatisticsPayload * | payload | ||
| ) |
Implementation of PicurvWindowStoragePayload().
Resolves one enumerated payload of a window's storage.
Definition at line 286 of file statistics_accumulator.c.
|
static |
Internal helper: reports which output kinds a recipe requested.
Local to this translation unit.
Definition at line 417 of file statistics_accumulator.c.
|
static |
Internal helper: counts the derived fields each kind contributes.
Local to this translation unit. A kind contributes nothing when the state it needs was never accumulated, so a recipe may name every output without having to know which window carries which moment.
Definition at line 455 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowDerivedCount | ( | const PicurvWindowDefinition * | definition, |
| const PicurvWindowStorage * | storage, | ||
| const char * | outputs, | ||
| PetscInt * | count | ||
| ) |
Implementation of PicurvWindowDerivedCount().
Reports how many derived fields a requested output set produces.
Definition at line 501 of file statistics_accumulator.c.
|
static |
Internal helper: takes a square root of a variance that may be barely negative.
Local to this translation unit. Centered accumulation can leave a variance a few ulps below zero when the signal is nearly constant. Clamping is confined to this one place, applies only under a root, and never touches stored state; a genuinely negative variance is a defect and is reported.
Definition at line 529 of file statistics_accumulator.c.
|
static |
Internal helper: resolves which kind and member one derived index selects.
Local to this translation unit. Walks the same order DerivedKindExtent counts, so the enumeration and the count cannot disagree.
Definition at line 548 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowDerive | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| const PicurvWindowStorage * | storage, | ||
| const char * | outputs, | ||
| PetscInt | index, | ||
| Vec | scalar_target, | ||
| Vec | vector_target, | ||
| PicurvDerivedField * | field | ||
| ) |
Implementation of PicurvWindowDerive().
Derives one output field from centered accumulator state.
Definition at line 576 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowSpatialMean | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| const PicurvWindowStorage * | storage, | ||
| Vec | field, | ||
| PetscReal * | mean | ||
| ) |
Implementation of PicurvWindowSpatialMean().
Reports the spatial mean of a derived field over the points a window sampled.
Definition at line 793 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowValidFractionRange | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| const PicurvWindowStorage * | storage, | ||
| PetscInt | sample_count, | ||
| PetscReal * | minimum, | ||
| PetscReal * | maximum | ||
| ) |
Implementation of PicurvWindowValidFractionRange().
Reports the range of per-point valid fraction across a window's domain.
Definition at line 828 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowAccumulate | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| PicurvWindowStorage * | storage, | ||
| PetscReal | weight | ||
| ) |
Implementation of PicurvWindowAccumulate().
Applies one accepted completed state to a window's accumulators.
Definition at line 884 of file statistics_accumulator.c.
|
static |
Upper-triangular row-major component pairs for a three-vector self-product.
This pair table is the single definition of the symmetric component order. The diagonal positions and the two-axis component labels are both derived from it rather than restated, because accumulation reads the table while derivation reads what follows from it: a hand-written copy that drifted would mislabel every Reynolds stress and take the root of the wrong component, with nothing failing.
Definition at line 30 of file statistics_accumulator.c.
|
static |
Definition at line 31 of file statistics_accumulator.c.
|
static |
Axis labels indexing the pair table above.
Definition at line 48 of file statistics_accumulator.c.
|
static |
Recipe spellings of the output kinds.
Definition at line 390 of file statistics_accumulator.c.
|
static |
Power of the source field's reference scale each derived kind carries.
A first moment and a standard deviation have the field's own units; a covariance, its trace, and a co-moment flux are quadratic in it. This is what the per-field scaling table alone cannot express, and why derived statistics were previously left non-dimensional rather than scaled by a velocity that would have been wrong for three of the five kinds.
Definition at line 403 of file statistics_accumulator.c.