Per-window PETSc accumulator storage and pointwise application. More...
#include "statistics_accumulator.h"#include "statistics_moments.h"#include "statistics_target.h"#include "interpolation.h"#include "ParticleMotion.h"#include "particle_field_catalog.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. | |
Enumerations | |
| enum | SampleSet { SAMPLE_SET_ALL = 0 , SAMPLE_SET_OCCUPIED } |
| The sample set a field or pair is measured over. More... | |
| enum | DerivedKind { DERIVED_MEAN = 0 , DERIVED_REYNOLDS_STRESS , DERIVED_RMS , DERIVED_TKE , DERIVED_FLUX , DERIVED_POINT_VARIANCE , 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(). | |
| static PetscErrorCode | FindFieldSlot (const PicurvWindowDefinition *definition, PetscInt field_id, PetscInt *slot) |
| Internal helper: locates the storage slot holding one field's running mean. | |
| static PetscBool | FieldIsParticleSampled (PetscInt field_id) |
| Internal helper: whether a catalogued field is measured only where particles are. | |
| static SampleSet | RequestSampleSet (const PicurvWindowDefinition *definition, PetscInt slot, PetscInt pair) |
| Internal helper: the sample set one field slot, or one covariance pair, uses. | |
| static void | SampleSetOccupancy (const PicurvWindowStorage *storage, SampleSet set, Vec *count, Vec *weight, Vec *weight_sq) |
| Internal helper: the occupancy vectors of one sample set. | |
| static Vec | SampleSetMean (const PicurvWindowStorage *storage, SampleSet set, PetscInt slot) |
| Internal helper: the mean a field slot is centred on within one sample set. | |
| PetscErrorCode | PicurvWindowStorageCreate (UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage) |
| Implementation of PicurvWindowStorageCreate(). | |
| PetscErrorCode | PicurvWindowStorageDestroy (PicurvWindowStorage *storage) |
| Implementation of PicurvWindowStorageDestroy(). | |
| 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(). | |
| static void | ProductComponents (PetscBool self, PetscInt dof_a, PetscInt dof_b, PetscInt components, PetscInt first[6], PetscInt second[6]) |
| Internal helper: the component pairs one stored product carries. | |
| static PetscErrorCode | AccumulateParticleCentredProducts (UserCtx *user, ParticleFieldId field_a, ParticleFieldId field_b, DM dm_a, Vec mean_a, DM dm_b, Vec mean_b, PetscInt components, const PetscInt first[6], const PetscInt second[6], DM product_dm, Vec product) |
| Internal helper: adds every particle's centred product into its cell. | |
| PetscErrorCode | PicurvWindowStorageFromParticles (UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage) |
| Implementation of PicurvWindowStorageFromParticles(). | |
| static PetscErrorCode | ReduceSampleSetMean (UserCtx *user, const SpatialTargetPlan *plan, DM dm, PetscInt dof, Vec point_mean, Vec weight, const PetscBool average_direction[3], Vec slot_mean) |
| Internal helper: merges one point-mean field into its slot means over a sample set. | |
| PetscErrorCode | PicurvWindowStorageReduce (UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, const PetscBool average_direction[3], PicurvWindowStorage *reduced) |
| Implementation of PicurvWindowStorageReduce(). | |
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 22 of file statistics_accumulator.c.
| enum SampleSet |
The sample set a field or pair is measured over.
| Enumerator | |
|---|---|
| SAMPLE_SET_ALL | Every accepted state at the point. |
| SAMPLE_SET_OCCUPIED | The accepted states in which the cell held particles. |
Definition at line 151 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_POINT_VARIANCE | |
| DERIVED_KIND_COUNT | |
Definition at line 526 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 59 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 74 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 90 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 106 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 126 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 366 of file statistics_accumulator.c.
|
static |
Internal helper: whether a catalogued field is measured only where particles are.
Local to this translation unit.
Definition at line 160 of file statistics_accumulator.c.
|
static |
Internal helper: the sample set one field slot, or one covariance pair, uses.
Local to this translation unit. A pair is measured where both members are, so it is occupied when either member is particle-sampled.
| [in] | definition | Window definition. |
| [in] | slot | Field slot, or -1 to select pair instead. |
| [in] | pair | Covariance pair, when slot is -1. |
Definition at line 178 of file statistics_accumulator.c.
|
static |
Internal helper: the occupancy vectors of one sample set.
Local to this translation unit.
Definition at line 192 of file statistics_accumulator.c.
|
static |
Internal helper: the mean a field slot is centred on within one sample set.
Local to this translation unit. An ordinary field in an occupied pair is centred on its mean over the occupied states; every other request uses the field's own mean.
Definition at line 208 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 223 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStorageDestroy | ( | PicurvWindowStorage * | storage | ) |
Implementation of PicurvWindowStorageDestroy().
Releases accumulator state previously created for one window.
Definition at line 328 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 386 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 409 of file statistics_accumulator.c.
|
static |
Internal helper: reports which output kinds a recipe requested.
Local to this translation unit.
Definition at line 565 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 605 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 654 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 684 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 706 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 735 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 961 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 994 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 1048 of file statistics_accumulator.c.
|
static |
Internal helper: the component pairs one stored product carries.
Local to this translation unit. A self-product walks the symmetric pair table; a vector-scalar covariance pairs each vector component with the scalar's only one, as PicurvWindowAccumulate does.
Definition at line 1276 of file statistics_accumulator.c.
|
static |
Internal helper: adds every particle's centred product into its cell.
Local to this translation unit. The second pass of the two-pass ensemble: each particle contributes (a - mean_a)(b - mean_b) for every component pair, against its own cell's mean read from the ghosted copies. Sums go to the ghosted patch and are then added onto their owners into product, the way AccumulateParticleField sums go.
Definition at line 1295 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStorageFromParticles | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| PicurvWindowStorage * | storage | ||
| ) |
Implementation of PicurvWindowStorageFromParticles().
Fills a window's storage from the particles sampling each cell at one instant.
Definition at line 1357 of file statistics_accumulator.c.
|
static |
Internal helper: merges one point-mean field into its slot means over a sample set.
Local to this translation unit. The slot mean is the weighted average of the point means, written to every point; a point that set never sampled is excluded, never averaged in as a zero.
Definition at line 1434 of file statistics_accumulator.c.
| PetscErrorCode PicurvWindowStorageReduce | ( | UserCtx * | user, |
| const PicurvWindowDefinition * | definition, | ||
| const PicurvWindowStorage * | storage, | ||
| const PetscBool | average_direction[3], | ||
| PicurvWindowStorage * | reduced | ||
| ) |
Implementation of PicurvWindowStorageReduce().
Merges a window's pointwise state over homogeneous directions.
Definition at line 1467 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 33 of file statistics_accumulator.c.
|
static |
Definition at line 34 of file statistics_accumulator.c.
|
static |
Axis labels indexing the pair table above.
Definition at line 51 of file statistics_accumulator.c.
|
static |
Recipe spellings of the output kinds.
Definition at line 537 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 550 of file statistics_accumulator.c.