PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Macros | Functions
statistics_config.c File Reference

Control ingress for the field-statistics pipeline. More...

#include "statistics_config.h"
#include "statistics_window.h"
#include "field_catalog.h"
#include "particle_field_catalog.h"
#include "logging.h"
#include "io.h"
Include dependency graph for statistics_config.c:

Go to the source code of this file.

Macros

#define STATISTICS_OPTION_NAME_LENGTH   128
 Longest constructed option name this module builds.
 
#define STATISTICS_OPTION_VALUE_LENGTH   256
 Longest option value this module reads, sized for a moment or pair list.
 

Functions

static PetscErrorCode ResolveStatisticsField (const char *window_name, const char *field_name, PetscBool particle_source, PetscInt *field_id)
 Internal helper: resolves one field name against the typed catalog.
 
static PetscErrorCode SplitStatisticsList (char *value, char **tokens, PetscInt capacity, PetscInt *count)
 Internal helper: splits a comma-separated value into trimmed tokens.
 
static PetscErrorCode ParseStatisticsFields (const char *kind, PetscInt window, PetscBool particle_source, PicurvWindowDefinition *definition)
 Internal helper: reads one window's field list into its definition.
 
static PetscErrorCode ParseStatisticsCovariances (const char *kind, PetscInt window, PetscBool particle_source, PicurvWindowDefinition *definition)
 Internal helper: reads one window's covariance list into its definition.
 
static PetscErrorCode ParseStatisticsWindowSchedule (PetscInt window, PicurvWindowDefinition *definition)
 Internal helper: reads one window's scheduling and weighting properties.
 
static PetscErrorCode LogResolvedWindow (const PicurvWindowDefinition *definition)
 Internal helper: reports one resolved window definition to the log.
 
PetscErrorCode ParsePostStatisticsEnsembles (SimCtx *simCtx)
 Implementation of ParsePostStatisticsEnsembles().
 
PetscErrorCode ParseFieldStatisticsConfig (SimCtx *simCtx)
 Implementation of ParseFieldStatisticsConfig().
 
PetscErrorCode DestroyFieldStatisticsConfig (SimCtx *simCtx)
 Implementation of DestroyFieldStatisticsConfig().
 

Detailed Description

Control ingress for the field-statistics pipeline.

Full API contract is documented with the declarations in include/statistics_config.h.

Definition in file statistics_config.c.

Macro Definition Documentation

◆ STATISTICS_OPTION_NAME_LENGTH

#define STATISTICS_OPTION_NAME_LENGTH   128

Longest constructed option name this module builds.

Definition at line 17 of file statistics_config.c.

◆ STATISTICS_OPTION_VALUE_LENGTH

#define STATISTICS_OPTION_VALUE_LENGTH   256

Longest option value this module reads, sized for a moment or pair list.

Definition at line 20 of file statistics_config.c.

Function Documentation

◆ ResolveStatisticsField()

static PetscErrorCode ResolveStatisticsField ( const char *  window_name,
const char *  field_name,
PetscBool  particle_source,
PetscInt *  field_id 
)
static

Internal helper: resolves one field name against the typed catalog.

Local to this translation unit. The error names the window so a hand-written control file reports the same context Python would.

Definition at line 27 of file statistics_config.c.

29{
30 FieldId resolved = FIELD_ID_UCAT;
31
32 PetscFunctionBeginUser;
34 PetscCheck(field_name != NULL && field_name[0] != '\0', PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
35 "Statistics window '%s' names an empty field.", window_name);
36 if (particle_source) {
37 /* A particle field is accumulated onto the Eulerian field it scatters to,
38 * which fixes its layout and the names its outputs carry. */
40 const ParticleFieldDescriptor *descriptor = NULL;
41
42 PetscCall(ParticleFieldIdFromName(field_name, &particle));
43 PetscCall(ParticleFieldGetDescriptor(particle, &descriptor));
45 PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
46 "Statistics ensemble '%s' names particle field '%s', which has no Eulerian "
47 "scatter target to accumulate onto.", window_name, field_name);
48 resolved = descriptor->eulerian_scatter_target;
49 } else {
50 PetscCall(FieldIdFromName(field_name, &resolved));
51 }
52 *field_id = (PetscInt)resolved;
54 PetscFunctionReturn(0);
55}
PetscErrorCode FieldIdFromName(const char *field_name, FieldId *field_id)
Resolve a user-facing field name once into its typed identity.
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_UCAT
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:1029
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
Definition logging.h:1000
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_INVALID
PetscErrorCode ParticleFieldIdFromName(const char *field_name, ParticleFieldId *field_id)
Resolve a canonical name or registered alias at a text-ingress boundary.
@ PARTICLE_FIELD_CAPABILITY_EULERIAN_SCATTER
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.
Immutable metadata for one persistent particle field.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SplitStatisticsList()

static PetscErrorCode SplitStatisticsList ( char *  value,
char **  tokens,
PetscInt  capacity,
PetscInt *  count 
)
static

Internal helper: splits a comma-separated value into trimmed tokens.

Local to this translation unit. Rewrites value in place, so callers pass a mutable buffer they own.

Definition at line 62 of file statistics_config.c.

64{
65 char *cursor = value;
66
67 PetscFunctionBeginUser;
69 *count = 0;
70 while (cursor && *cursor) {
71 char *comma = strchr(cursor, ',');
72
73 if (comma) *comma = '\0';
74 TrimWhitespace(cursor);
75 if (cursor[0] != '\0') {
76 PetscCheck(*count < capacity, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
77 "A statistics list holds at most %" PetscInt_FMT " entries.", capacity);
78 tokens[(*count)++] = cursor;
79 }
80 cursor = comma ? comma + 1 : NULL;
81 }
83 PetscFunctionReturn(0);
84}
void TrimWhitespace(char *str)
Removes leading and trailing ASCII whitespace from a mutable string.
Definition io.c:486
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseStatisticsFields()

static PetscErrorCode ParseStatisticsFields ( const char *  kind,
PetscInt  window,
PetscBool  particle_source,
PicurvWindowDefinition *  definition 
)
static

Internal helper: reads one window's field list into its definition.

Local to this translation unit.

Definition at line 90 of file statistics_config.c.

92{
94 PetscBool found = PETSC_FALSE;
95
96 PetscFunctionBeginUser;
98 PetscCall(PetscSNPrintf(name, sizeof(name),
99 "-field_statistics_%s_%" PetscInt_FMT "_field_count", kind, window));
100 PetscCall(PetscOptionsGetInt(NULL, NULL, name, &definition->field_count, &found));
101 PetscCheck(found && definition->field_count > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
102 "Statistics window '%s' requests no field.", definition->name);
103 PetscCheck(definition->field_count <= PICURV_WINDOW_MAX_REQUESTS, PETSC_COMM_WORLD,
104 PETSC_ERR_ARG_OUTOFRANGE,
105 "Statistics window '%s' requests %" PetscInt_FMT " fields; at most %d are supported.",
106 definition->name, definition->field_count, PICURV_WINDOW_MAX_REQUESTS);
107
108 for (PetscInt field_index = 0; field_index < definition->field_count; ++field_index) {
109 char field_name[STATISTICS_OPTION_VALUE_LENGTH];
110 char moments[STATISTICS_OPTION_VALUE_LENGTH];
111 char *tokens[4];
112 PetscInt token_count = 0;
113
114 PetscCall(PetscSNPrintf(name, sizeof(name),
115 "-field_statistics_%s_%" PetscInt_FMT "_field_%" PetscInt_FMT "_name",
116 kind, window, field_index));
117 PetscCall(PetscOptionsGetString(NULL, NULL, name, field_name, sizeof(field_name), &found));
118 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
119 "Statistics window '%s' field %" PetscInt_FMT " has no name.",
120 definition->name, field_index);
121 PetscCall(ResolveStatisticsField(definition->name, field_name, particle_source,
122 &definition->fields[field_index].field_id));
123
124 PetscCall(PetscSNPrintf(name, sizeof(name),
125 "-field_statistics_%s_%" PetscInt_FMT "_field_%" PetscInt_FMT "_moments",
126 kind, window, field_index));
127 PetscCall(PetscOptionsGetString(NULL, NULL, name, moments, sizeof(moments), &found));
128 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
129 "Statistics window '%s' field '%s' requests no moment.", definition->name, field_name);
130 PetscCall(SplitStatisticsList(moments, tokens, 4, &token_count));
131 PetscCheck(token_count > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
132 "Statistics window '%s' field '%s' requests no moment.", definition->name, field_name);
133
134 definition->fields[field_index].want_second = PETSC_FALSE;
135 for (PetscInt t = 0; t < token_count; ++t) {
136 if (!strcmp(tokens[t], "first")) continue;
137 if (!strcmp(tokens[t], "second")) {
138 definition->fields[field_index].want_second = PETSC_TRUE;
139 continue;
140 }
141 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
142 "Statistics window '%s' field '%s' requests unknown moment '%s'; "
143 "the accumulable moments are 'first' and 'second'.",
144 definition->name, field_name, tokens[t]);
145 }
146 }
148 PetscFunctionReturn(0);
149}
static PetscErrorCode ResolveStatisticsField(const char *window_name, const char *field_name, PetscBool particle_source, PetscInt *field_id)
Internal helper: resolves one field name against the typed catalog.
#define STATISTICS_OPTION_NAME_LENGTH
Longest constructed option name this module builds.
#define STATISTICS_OPTION_VALUE_LENGTH
Longest option value this module reads, sized for a moment or pair list.
static PetscErrorCode SplitStatisticsList(char *value, char **tokens, PetscInt capacity, PetscInt *count)
Internal helper: splits a comma-separated value into trimmed tokens.
PicurvWindowFieldRequest fields[16]
PetscBool want_second
Also keep the centered second moment.
PetscInt field_id
Catalogued Eulerian field identity.
#define PICURV_WINDOW_MAX_REQUESTS
Maximum fields or covariance pairs one window may request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseStatisticsCovariances()

static PetscErrorCode ParseStatisticsCovariances ( const char *  kind,
PetscInt  window,
PetscBool  particle_source,
PicurvWindowDefinition *  definition 
)
static

Internal helper: reads one window's covariance list into its definition.

Local to this translation unit.

Definition at line 155 of file statistics_config.c.

157{
159 PetscBool found = PETSC_FALSE;
160
161 PetscFunctionBeginUser;
163 PetscCall(PetscSNPrintf(name, sizeof(name),
164 "-field_statistics_%s_%" PetscInt_FMT "_covariance_count", kind, window));
165 PetscCall(PetscOptionsGetInt(NULL, NULL, name, &definition->covariance_count, &found));
166 if (!found) definition->covariance_count = 0;
167 PetscCheck(definition->covariance_count >= 0 &&
169 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
170 "Statistics window '%s' requests %" PetscInt_FMT " covariances; at most %d are supported.",
171 definition->name, definition->covariance_count, PICURV_WINDOW_MAX_REQUESTS);
172
173 for (PetscInt pair_index = 0; pair_index < definition->covariance_count; ++pair_index) {
175 char *tokens[4];
176 PetscInt token_count = 0;
177 PetscBool first_present = PETSC_FALSE;
178 PetscBool second_present = PETSC_FALSE;
179
180 PetscCall(PetscSNPrintf(name, sizeof(name),
181 "-field_statistics_%s_%" PetscInt_FMT "_covariance_%" PetscInt_FMT,
182 kind, window, pair_index));
183 PetscCall(PetscOptionsGetString(NULL, NULL, name, pair, sizeof(pair), &found));
184 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
185 "Statistics window '%s' covariance %" PetscInt_FMT " has no members.",
186 definition->name, pair_index);
187 PetscCall(SplitStatisticsList(pair, tokens, 4, &token_count));
188 PetscCheck(token_count == 2, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
189 "Statistics window '%s' covariance %" PetscInt_FMT " needs exactly two members.",
190 definition->name, pair_index);
191 PetscCall(ResolveStatisticsField(definition->name, tokens[0], particle_source, &definition->covariances[pair_index].first));
192 PetscCall(ResolveStatisticsField(definition->name, tokens[1], particle_source, &definition->covariances[pair_index].second));
193 PetscCheck(definition->covariances[pair_index].first != definition->covariances[pair_index].second,
194 PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
195 "Statistics window '%s' pairs '%s' with itself; that is the self-product already "
196 "requested through moments: [second].", definition->name, tokens[0]);
197
198 /* Both members must carry a running mean, because a co-moment centers
199 * against them. This is the C-side guard behind the same Python rule. */
200 for (PetscInt field_index = 0; field_index < definition->field_count; ++field_index) {
201 if (definition->fields[field_index].field_id == definition->covariances[pair_index].first) first_present = PETSC_TRUE;
202 if (definition->fields[field_index].field_id == definition->covariances[pair_index].second) second_present = PETSC_TRUE;
203 }
204 PetscCheck(first_present && second_present, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
205 "Statistics window '%s' pairs '%s' with '%s', but both must also appear in its "
206 "field list so their means exist to center against.",
207 definition->name, tokens[0], tokens[1]);
208 }
210 PetscFunctionReturn(0);
211}
PetscInt first
First member; must also appear in the field list.
PetscInt second
Second member; must also appear in the field list.
PicurvWindowCovarianceRequest covariances[16]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseStatisticsWindowSchedule()

static PetscErrorCode ParseStatisticsWindowSchedule ( PetscInt  window,
PicurvWindowDefinition *  definition 
)
static

Internal helper: reads one window's scheduling and weighting properties.

Local to this translation unit.

Definition at line 217 of file statistics_config.c.

218{
220 char weighting[STATISTICS_OPTION_VALUE_LENGTH];
221 PetscBool found = PETSC_FALSE;
222 PetscBool step_found = PETSC_FALSE;
223 PetscBool time_found = PETSC_FALSE;
224
225 PetscFunctionBeginUser;
227 PetscCall(PetscSNPrintf(name, sizeof(name),
228 "-field_statistics_window_%" PetscInt_FMT "_start_time", window));
229 PetscCall(PetscOptionsGetReal(NULL, NULL, name, &definition->start_time, &found));
230 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
231 "Statistics window '%s' has no start time.", definition->name);
232
233 /* An absent end time is what makes a window open ended, so its absence is
234 * meaningful rather than a defaulted value. */
235 PetscCall(PetscSNPrintf(name, sizeof(name),
236 "-field_statistics_window_%" PetscInt_FMT "_end_time", window));
237 PetscCall(PetscOptionsGetReal(NULL, NULL, name, &definition->end_time, &definition->bounded));
238
239 PetscCall(PetscSNPrintf(name, sizeof(name),
240 "-field_statistics_window_%" PetscInt_FMT "_weighting", window));
241 PetscCall(PetscOptionsGetString(NULL, NULL, name, weighting, sizeof(weighting), &found));
242 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
243 "Statistics window '%s' has no weighting.", definition->name);
244 if (!strcmp(weighting, "sample")) {
246 } else if (!strcmp(weighting, "physical_time")) {
248 } else {
249 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
250 "Statistics window '%s' has weighting '%s'; only 'sample' and 'physical_time' exist.",
251 definition->name, weighting);
252 }
253
254 PetscCall(PetscSNPrintf(name, sizeof(name),
255 "-field_statistics_window_%" PetscInt_FMT "_step_cadence", window));
256 PetscCall(PetscOptionsGetInt(NULL, NULL, name, &definition->step_cadence, &step_found));
257 PetscCall(PetscSNPrintf(name, sizeof(name),
258 "-field_statistics_window_%" PetscInt_FMT "_time_cadence", window));
259 PetscCall(PetscOptionsGetReal(NULL, NULL, name, &definition->time_cadence, &time_found));
260 PetscCheck(step_found != time_found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
261 "Statistics window '%s' must select exactly one of step_cadence and time_cadence.",
262 definition->name);
263 definition->cadence_kind = step_found ? PICURV_CADENCE_STEP : PICURV_CADENCE_TIME;
265 PetscFunctionReturn(0);
266}
PetscReal time_cadence
Used when cadence_kind is time; must be positive.
PetscReal end_time
Requested end; ignored when bounded is false.
PicurvCadenceKind cadence_kind
PetscInt step_cadence
Used when cadence_kind is step; must be positive.
PetscBool bounded
False for an open-ended window.
PetscReal start_time
Requested start.
@ PICURV_WEIGHTING_PHYSICAL_TIME
Weight is the represented interval.
@ PICURV_WEIGHTING_SAMPLE
Equal weight per accepted state.
@ PICURV_CADENCE_TIME
First state at or past each nominal time target.
@ PICURV_CADENCE_STEP
Every n completed steps from activation.
Here is the caller graph for this function:

◆ LogResolvedWindow()

static PetscErrorCode LogResolvedWindow ( const PicurvWindowDefinition *  definition)
static

Internal helper: reports one resolved window definition to the log.

Local to this translation unit. Runs once per window at startup, so a run's log records exactly what it accumulated without having to be cross-referenced against the configuration that produced it.

Definition at line 274 of file statistics_config.c.

275{
276 char fields[STATISTICS_OPTION_VALUE_LENGTH] = "";
277 size_t used = 0;
278
279 PetscFunctionBeginUser;
281 for (PetscInt field_index = 0; field_index < definition->field_count; ++field_index) {
282 PetscCall(PetscStrlen(fields, &used));
283 PetscCall(PetscSNPrintf(fields + used, sizeof(fields) - used, "%s%s%s",
284 field_index ? " " : "",
285 FieldCanonicalName((FieldId)definition->fields[field_index].field_id),
286 definition->fields[field_index].want_second ? "(1,2)" : "(1)"));
287 }
288 if (definition->cadence_kind == PICURV_CADENCE_STEP) {
290 "Statistics window '%s': t=[%.6g,%s] weighting=%s every %d step(s), fields: %s, "
291 "%d covariance(s).\n",
292 definition->name, (double)definition->start_time,
293 definition->bounded ? "bounded" : "open",
294 definition->weighting == PICURV_WEIGHTING_SAMPLE ? "sample" : "physical_time",
295 (int)definition->step_cadence, fields, (int)definition->covariance_count);
296 } else {
298 "Statistics window '%s': t=[%.6g,%s] weighting=%s every %.6g of time, fields: %s, "
299 "%d covariance(s).\n",
300 definition->name, (double)definition->start_time,
301 definition->bounded ? "bounded" : "open",
302 definition->weighting == PICURV_WEIGHTING_SAMPLE ? "sample" : "physical_time",
303 (double)definition->time_cadence, fields, (int)definition->covariance_count);
304 }
305 if (definition->bounded) {
306 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Statistics window '%s' ends at t=%.6g.\n",
307 definition->name, (double)definition->end_time);
308 }
310 PetscFunctionReturn(0);
311}
const char * FieldCanonicalName(FieldId field_id)
Return the canonical printable name for an ID.
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:46
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
Definition logging.h:214
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:31
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParsePostStatisticsEnsembles()

PetscErrorCode ParsePostStatisticsEnsembles ( SimCtx *  simCtx)

Implementation of ParsePostStatisticsEnsembles().

Resolves the statistics ensembles a post-processing recipe defines.

See also
ParsePostStatisticsEnsembles()

Definition at line 317 of file statistics_config.c.

318{
319 PostProcessParams *pps = NULL;
320 PetscInt count = 0;
321 PetscBool found = PETSC_FALSE;
322
323 PetscFunctionBeginUser;
325 PetscCheck(simCtx != NULL && simCtx->pps != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
326 "SimCtx and its post-processing parameters are required.");
327 pps = simCtx->pps;
328 PetscCall(PetscOptionsGetInt(NULL, NULL, "-field_statistics_ensemble_count", &count, &found));
329 if (!found || count <= 0) { PROFILE_FUNCTION_END; PetscFunctionReturn(0); }
330 PetscCall(PetscCalloc2((size_t)count, &pps->field_statistics_ensembles,
331 (size_t)count, &pps->field_statistics_ensemble_from_particles));
333
334 for (PetscInt index = 0; index < count; ++index) {
335 PicurvWindowDefinition definition;
336 char option_name[STATISTICS_OPTION_NAME_LENGTH];
338 PetscBool from_particles = PETSC_FALSE;
339
340 PetscCall(PetscMemzero(&definition, sizeof(definition)));
341 PetscCall(PetscSNPrintf(option_name, sizeof(option_name),
342 "-field_statistics_ensemble_%" PetscInt_FMT "_name", index));
343 PetscCall(PetscOptionsGetString(NULL, NULL, option_name, definition.name,
344 sizeof(definition.name), &found));
345 PetscCheck(found && definition.name[0] != '\0', PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
346 "Statistics ensemble %" PetscInt_FMT " has no name.", index);
347 /* Ensembles and run windows write to the same file names. */
348 for (PetscInt w = 0; w < simCtx->fieldStatisticsWindowCount; ++w) {
349 PetscBool clash = PETSC_FALSE;
350
351 PetscCall(PetscStrcmp(simCtx->fieldStatisticsWindows[w].definition.name, definition.name, &clash));
352 PetscCheck(!clash, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
353 "Statistics ensemble '%s' has the name of a run window.", definition.name);
354 }
355 for (PetscInt prior = 0; prior < index; ++prior) {
356 PetscBool clash = PETSC_FALSE;
357
358 PetscCall(PetscStrcmp(pps->field_statistics_ensembles[prior].definition.name, definition.name, &clash));
359 PetscCheck(!clash, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
360 "Statistics ensemble name '%s' is used more than once.", definition.name);
361 }
362
363 PetscCall(PetscSNPrintf(option_name, sizeof(option_name),
364 "-field_statistics_ensemble_%" PetscInt_FMT "_source", index));
365 PetscCall(PetscOptionsGetString(NULL, NULL, option_name, source, sizeof(source), &found));
366 PetscCheck(found && (!strcmp(source, "particles") || !strcmp(source, "eulerian")),
367 PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
368 "Statistics ensemble '%s' needs source 'particles' or 'eulerian'.", definition.name);
369 from_particles = (PetscBool)!strcmp(source, "particles");
370
371 /* An ensemble is one instant, so it has no schedule of its own; the unit step
372 * cadence only satisfies the window validation it shares. */
375 definition.step_cadence = 1;
376 PetscCall(ParseStatisticsFields("ensemble", index, from_particles, &definition));
377 PetscCall(ParseStatisticsCovariances("ensemble", index, from_particles, &definition));
378 PetscCall(PicurvWindowInit(&pps->field_statistics_ensembles[index], &definition));
379 pps->field_statistics_ensemble_from_particles[index] = from_particles;
380 LOG_ALLOW(GLOBAL, LOG_INFO, "Statistics ensemble '%s' from %s: %d field(s), %d covariance(s).\n",
381 definition.name, source, (int)definition.field_count, (int)definition.covariance_count);
382 }
384 PetscFunctionReturn(0);
385}
static PetscErrorCode ParseStatisticsFields(const char *kind, PetscInt window, PetscBool particle_source, PicurvWindowDefinition *definition)
Internal helper: reads one window's field list into its definition.
static PetscErrorCode ParseStatisticsCovariances(const char *kind, PetscInt window, PetscBool particle_source, PicurvWindowDefinition *definition)
Internal helper: reads one window's covariance list into its definition.
PetscErrorCode PicurvWindowInit(PicurvWindow *window, const PicurvWindowDefinition *definition)
Validates a definition and initializes a window to the pending state.
PicurvWindowDefinition definition
The scientifically immutable definition of one window.
PetscInt fieldStatisticsWindowCount
Definition variables.h:989
struct PicurvWindow * field_statistics_ensembles
Definition variables.h:835
struct PicurvWindow * fieldStatisticsWindows
Definition variables.h:990
PetscBool * field_statistics_ensemble_from_particles
Whether each ensemble samples the particles in a cell rather than the cell's state.
Definition variables.h:837
PetscInt field_statistics_ensemble_count
Recipe-defined single-instant windows, derived at every processed step.
Definition variables.h:834
PostProcessParams * pps
Definition variables.h:1131
Holds all configuration parameters for a post-processing run.
Definition variables.h:793
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseFieldStatisticsConfig()

PetscErrorCode ParseFieldStatisticsConfig ( SimCtx *  simCtx)

Implementation of ParseFieldStatisticsConfig().

Resolves field-statistics configuration from the control file.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/statistics_config.h.

See also
ParseFieldStatisticsConfig()

Definition at line 393 of file statistics_config.c.

394{
395 PetscInt window_count = 0;
396 PetscBool found = PETSC_FALSE;
397
398 PetscFunctionBeginUser;
400 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx cannot be NULL.");
401
402 PetscCall(PetscOptionsGetInt(NULL, NULL, "-statistics_console_output_freq",
403 &simCtx->statisticsConsoleOutputFreq, NULL));
404 PetscCall(PetscOptionsGetBool(NULL, NULL, "-field_statistics_enabled",
405 &simCtx->fieldStatisticsEnabled, NULL));
406 if (!simCtx->fieldStatisticsEnabled) {
407 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Field statistics are disabled.\n");
409 PetscFunctionReturn(0);
410 }
411
412 PetscCall(PetscOptionsGetInt(NULL, NULL, "-field_statistics_window_count", &window_count, &found));
413 PetscCheck(found && window_count > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
414 "Field statistics are enabled but no window is configured.");
415 PetscCall(PetscCalloc1((size_t)window_count, &simCtx->fieldStatisticsWindows));
416 simCtx->fieldStatisticsWindowCount = window_count;
417
418 for (PetscInt window_index = 0; window_index < window_count; ++window_index) {
419 PicurvWindowDefinition definition;
420 char option_name[STATISTICS_OPTION_NAME_LENGTH];
421
422 PetscCall(PetscMemzero(&definition, sizeof(definition)));
423 PetscCall(PetscSNPrintf(option_name, sizeof(option_name),
424 "-field_statistics_window_%" PetscInt_FMT "_name", window_index));
425 PetscCall(PetscOptionsGetString(NULL, NULL, option_name, definition.name,
426 sizeof(definition.name), &found));
427 PetscCheck(found && definition.name[0] != '\0', PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
428 "Statistics window %" PetscInt_FMT " has no name.", window_index);
429
430 /* A duplicate name would make two windows indistinguishable in the
431 * checkpoint, where window state is matched by name on restart. */
432 for (PetscInt prior = 0; prior < window_index; ++prior) {
433 PetscBool clash = PETSC_FALSE;
434
435 PetscCall(PetscStrcmp(simCtx->fieldStatisticsWindows[prior].definition.name,
436 definition.name, &clash));
437 PetscCheck(!clash, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
438 "Statistics window name '%s' is used more than once; names identify saved "
439 "state across a restart and must be unique.", definition.name);
440 }
441
442 PetscCall(ParseStatisticsWindowSchedule(window_index, &definition));
443 PetscCall(ParseStatisticsFields("window", window_index, PETSC_FALSE, &definition));
444 PetscCall(ParseStatisticsCovariances("window", window_index, PETSC_FALSE, &definition));
445 PetscCall(PicurvWindowInit(&simCtx->fieldStatisticsWindows[window_index], &definition));
446 PetscCall(LogResolvedWindow(&simCtx->fieldStatisticsWindows[window_index].definition));
447 }
448
449 LOG_ALLOW(GLOBAL, LOG_INFO, "Field statistics resolved %d window(s).\n", (int)window_count);
451 PetscFunctionReturn(0);
452}
static PetscErrorCode LogResolvedWindow(const PicurvWindowDefinition *definition)
Internal helper: reports one resolved window definition to the log.
static PetscErrorCode ParseStatisticsWindowSchedule(PetscInt window, PicurvWindowDefinition *definition)
Internal helper: reads one window's scheduling and weighting properties.
PetscInt statisticsConsoleOutputFreq
Definition variables.h:991
PetscBool fieldStatisticsEnabled
Definition variables.h:988
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DestroyFieldStatisticsConfig()

PetscErrorCode DestroyFieldStatisticsConfig ( SimCtx *  simCtx)

Implementation of DestroyFieldStatisticsConfig().

Releases the window definitions resolved by ParseFieldStatisticsConfig() and the ensembles resolved by ParsePostStatisticsEnsembles().

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/statistics_config.h.

See also
DestroyFieldStatisticsConfig()

Definition at line 460 of file statistics_config.c.

461{
462 PetscFunctionBeginUser;
464 if (!simCtx) { PROFILE_HELPER_END; PetscFunctionReturn(0); }
465 if (simCtx->pps && simCtx->pps->field_statistics_ensembles) {
466 PetscCall(PetscFree2(simCtx->pps->field_statistics_ensembles,
469 }
470 if (!simCtx->fieldStatisticsWindows) { PROFILE_HELPER_END; PetscFunctionReturn(0); }
471 PetscCall(PetscFree(simCtx->fieldStatisticsWindows));
472 simCtx->fieldStatisticsWindows = NULL;
473 simCtx->fieldStatisticsWindowCount = 0;
475 PetscFunctionReturn(0);
476}
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
Definition logging.h:1014
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
Definition logging.h:1033
Here is the caller graph for this function: