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

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

#include "variables.h"
Include dependency graph for statistics_config.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PetscErrorCode ParseFieldStatisticsConfig (SimCtx *simCtx)
 Resolves field-statistics configuration from the control file.
 
PetscErrorCode DestroyFieldStatisticsConfig (SimCtx *simCtx)
 Releases the window definitions resolved by ParseFieldStatisticsConfig().
 

Detailed Description

Control ingress for the field-statistics pipeline.

Resolves the generated master control into the window definitions the rest of the pipeline consumes, per Field Statistics Phase 2 Implementation Specification section 8.

A window list is variable arity, so its option names are constructed rather than literal. Every constructed name belongs to a family declared in the ingress audit manifest, which is what keeps the audit's guarantee intact rather than opening a hole in it.

This module owns only configuration. It creates no PETSc vectors: the accumulator factory runs later and sizes itself from the definitions resolved here.

Definition in file statistics_config.h.

Function Documentation

◆ ParseFieldStatisticsConfig()

PetscErrorCode ParseFieldStatisticsConfig ( SimCtx simCtx)

Resolves field-statistics configuration from the control file.

Reads the option families, resolves every field name through the typed catalog, validates each definition through PicurvWindowInit, and stores the resulting windows on the context. Reports every resolved definition at LOG_INFO so a run's log records exactly what was accumulated.

Leaves the context untouched when statistics are disabled or no window is configured, so a run that does not ask for statistics allocates nothing.

Must run before CreateAndInitializeAllVectors, which sizes the per-window accumulators from the window count resolved here.

Parameters
[in,out]simCtxSimulation context to populate.
Returns
Zero on success, or a PETSc error for a malformed or inconsistent configuration. Python validation rejects these earlier with better messages; these checks guard a hand-written control file.

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 289 of file statistics_config.c.

290{
291 PetscInt window_count = 0;
292 PetscBool found = PETSC_FALSE;
293
294 PetscFunctionBeginUser;
295 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx cannot be NULL.");
296
297 PetscCall(PetscOptionsGetInt(NULL, NULL, "-statistics_console_output_freq",
298 &simCtx->statisticsConsoleOutputFreq, NULL));
299 PetscCall(PetscOptionsGetBool(NULL, NULL, "-field_statistics_enabled",
300 &simCtx->fieldStatisticsEnabled, NULL));
301 if (!simCtx->fieldStatisticsEnabled) {
302 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Field statistics are disabled.\n");
303 PetscFunctionReturn(0);
304 }
305
306 PetscCall(PetscOptionsGetInt(NULL, NULL, "-field_statistics_window_count", &window_count, &found));
307 PetscCheck(found && window_count > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
308 "Field statistics are enabled but no window is configured.");
309 PetscCall(PetscCalloc1((size_t)window_count, &simCtx->fieldStatisticsWindows));
310 simCtx->fieldStatisticsWindowCount = window_count;
311
312 for (PetscInt window_index = 0; window_index < window_count; ++window_index) {
313 PicurvWindowDefinition definition;
314 char option_name[STATISTICS_OPTION_NAME_LENGTH];
315
316 PetscCall(PetscMemzero(&definition, sizeof(definition)));
317 PetscCall(PetscSNPrintf(option_name, sizeof(option_name),
318 "-field_statistics_window_%" PetscInt_FMT "_name", window_index));
319 PetscCall(PetscOptionsGetString(NULL, NULL, option_name, definition.name,
320 sizeof(definition.name), &found));
321 PetscCheck(found && definition.name[0] != '\0', PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
322 "Statistics window %" PetscInt_FMT " has no name.", window_index);
323
324 /* A duplicate name would make two windows indistinguishable in the
325 * checkpoint, where window state is matched by name on restart. */
326 for (PetscInt prior = 0; prior < window_index; ++prior) {
327 PetscBool clash = PETSC_FALSE;
328
329 PetscCall(PetscStrcmp(simCtx->fieldStatisticsWindows[prior].definition.name,
330 definition.name, &clash));
331 PetscCheck(!clash, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
332 "Statistics window name '%s' is used more than once; names identify saved "
333 "state across a restart and must be unique.", definition.name);
334 }
335
336 PetscCall(ParseStatisticsWindowSchedule(window_index, &definition));
337 PetscCall(ParseStatisticsFields(window_index, &definition));
338 PetscCall(ParseStatisticsCovariances(window_index, &definition));
339 PetscCall(PicurvWindowInit(&simCtx->fieldStatisticsWindows[window_index], &definition));
340 PetscCall(LogResolvedWindow(&simCtx->fieldStatisticsWindows[window_index].definition));
341 }
342
343 LOG_ALLOW(GLOBAL, LOG_INFO, "Field statistics resolved %d window(s).\n", (int)window_count);
344 PetscFunctionReturn(0);
345}
#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:200
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:31
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
#define STATISTICS_OPTION_NAME_LENGTH
Longest constructed option name this module builds.
static PetscErrorCode LogResolvedWindow(const PicurvWindowDefinition *definition)
Internal helper: reports one resolved window definition to the log.
static PetscErrorCode ParseStatisticsCovariances(PetscInt window, 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 ParseStatisticsFields(PetscInt window, PicurvWindowDefinition *definition)
Internal helper: reads one window's field 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:770
PetscInt statisticsConsoleOutputFreq
Definition variables.h:772
PetscBool fieldStatisticsEnabled
Definition variables.h:769
struct PicurvWindow * fieldStatisticsWindows
Definition variables.h:771
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DestroyFieldStatisticsConfig()

PetscErrorCode DestroyFieldStatisticsConfig ( SimCtx simCtx)

Releases the window definitions resolved by ParseFieldStatisticsConfig().

Parameters
[in,out]simCtxSimulation context to clear; safe when nothing was resolved.
Returns
Zero on success.

Releases the window definitions resolved by ParseFieldStatisticsConfig().

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

See also
DestroyFieldStatisticsConfig()

Definition at line 353 of file statistics_config.c.

354{
355 PetscFunctionBeginUser;
356 if (!simCtx || !simCtx->fieldStatisticsWindows) PetscFunctionReturn(0);
357 PetscCall(PetscFree(simCtx->fieldStatisticsWindows));
358 simCtx->fieldStatisticsWindows = NULL;
359 simCtx->fieldStatisticsWindowCount = 0;
360 PetscFunctionReturn(0);
361}
Here is the caller graph for this function: