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. The user-facing keys these options come from are documented in 3. field_statistics.

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. Each resolved definition is reported at LOG_INFO through LOG_ALLOW, so it carries the usual dual gate and is surfaced by allow-listing the emitting function. Whether statistics were active at all is recorded unconditionally by the startup banner.

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

292{
293 PetscInt window_count = 0;
294 PetscBool found = PETSC_FALSE;
295
296 PetscFunctionBeginUser;
298 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "SimCtx cannot be NULL.");
299
300 PetscCall(PetscOptionsGetInt(NULL, NULL, "-statistics_console_output_freq",
301 &simCtx->statisticsConsoleOutputFreq, NULL));
302 PetscCall(PetscOptionsGetBool(NULL, NULL, "-field_statistics_enabled",
303 &simCtx->fieldStatisticsEnabled, NULL));
304 if (!simCtx->fieldStatisticsEnabled) {
305 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Field statistics are disabled.\n");
307 PetscFunctionReturn(0);
308 }
309
310 PetscCall(PetscOptionsGetInt(NULL, NULL, "-field_statistics_window_count", &window_count, &found));
311 PetscCheck(found && window_count > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
312 "Field statistics are enabled but no window is configured.");
313 PetscCall(PetscCalloc1((size_t)window_count, &simCtx->fieldStatisticsWindows));
314 simCtx->fieldStatisticsWindowCount = window_count;
315
316 for (PetscInt window_index = 0; window_index < window_count; ++window_index) {
317 PicurvWindowDefinition definition;
318 char option_name[STATISTICS_OPTION_NAME_LENGTH];
319
320 PetscCall(PetscMemzero(&definition, sizeof(definition)));
321 PetscCall(PetscSNPrintf(option_name, sizeof(option_name),
322 "-field_statistics_window_%" PetscInt_FMT "_name", window_index));
323 PetscCall(PetscOptionsGetString(NULL, NULL, option_name, definition.name,
324 sizeof(definition.name), &found));
325 PetscCheck(found && definition.name[0] != '\0', PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
326 "Statistics window %" PetscInt_FMT " has no name.", window_index);
327
328 /* A duplicate name would make two windows indistinguishable in the
329 * checkpoint, where window state is matched by name on restart. */
330 for (PetscInt prior = 0; prior < window_index; ++prior) {
331 PetscBool clash = PETSC_FALSE;
332
333 PetscCall(PetscStrcmp(simCtx->fieldStatisticsWindows[prior].definition.name,
334 definition.name, &clash));
335 PetscCheck(!clash, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
336 "Statistics window name '%s' is used more than once; names identify saved "
337 "state across a restart and must be unique.", definition.name);
338 }
339
340 PetscCall(ParseStatisticsWindowSchedule(window_index, &definition));
341 PetscCall(ParseStatisticsFields(window_index, &definition));
342 PetscCall(ParseStatisticsCovariances(window_index, &definition));
343 PetscCall(PicurvWindowInit(&simCtx->fieldStatisticsWindows[window_index], &definition));
344 PetscCall(LogResolvedWindow(&simCtx->fieldStatisticsWindows[window_index].definition));
345 }
346
347 LOG_ALLOW(GLOBAL, LOG_INFO, "Field statistics resolved %d window(s).\n", (int)window_count);
349 PetscFunctionReturn(0);
350}
#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
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:894
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:31
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
Definition logging.h:885
#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:939
PetscInt statisticsConsoleOutputFreq
Definition variables.h:941
PetscBool fieldStatisticsEnabled
Definition variables.h:938
struct PicurvWindow * fieldStatisticsWindows
Definition variables.h:940
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 358 of file statistics_config.c.

359{
360 PetscFunctionBeginUser;
361 if (!simCtx || !simCtx->fieldStatisticsWindows) PetscFunctionReturn(0);
362 PetscCall(PetscFree(simCtx->fieldStatisticsWindows));
363 simCtx->fieldStatisticsWindows = NULL;
364 simCtx->fieldStatisticsWindowCount = 0;
365 PetscFunctionReturn(0);
366}
Here is the caller graph for this function: