Logging utilities and macros for PETSc-based applications. More...
#include <petsc.h>#include <stdlib.h>#include <string.h>#include <petscsys.h>#include <ctype.h>#include "variables.h"#include "statistics_window.h"#include "Boundaries.h"Go to the source code of this file.
Data Structures | |
| struct | DualMonitorCtx |
| Context for a dual-purpose KSP monitor. More... | |
Macros | |
| #define | LOCAL 0 |
| Logging scope definitions for controlling message output. | |
| #define | GLOBAL 1 |
| Scope for global logging across all processes. | |
| #define | LOG(scope, level, fmt, ...) |
| Logging macro for PETSc-based applications with scope control. | |
| #define | LOG_DEFAULT(level, fmt, ...) |
| Default logging macro for PETSc-based applications. | |
| #define | LOG_SYNC(scope, level, fmt, ...) |
| Logging macro for PETSc-based applications with scope control, using synchronized output across processes. | |
| #define | LOG_SYNC_DEFAULT(level, fmt, ...) |
| Default synchronized logging macro for PETSc-based applications. | |
| #define | LOG_LEVEL_ADMITS(level) ((int)(level) <= (int)get_log_level() && ((int)(level) <= (int)LOG_WARNING || is_function_allowed(__func__))) |
True when a code-level diagnostic at level prints from the calling function. | |
| #define | LOG_ALLOW(scope, level, fmt, ...) |
| Logging macro that checks both the log level and whether the calling function is in the allowed-function list before printing. | |
| #define | LOG_ALLOW_SYNC(scope, level, fmt, ...) |
| Synchronized logging macro that checks both the log level and whether the calling function is in the allow-list. | |
| #define | PARTICLE_LOG_VERBOSE_ENABLED() (PetscUnlikely((int)get_log_level() >= (int)LOG_VERBOSE) && is_function_allowed(__func__)) |
| True when the calling function's per-particle lines print for every particle (VERBOSE and allow-listed). | |
| #define | PARTICLE_IS_TRACED(simCtx, pid) ((PetscBool)(PetscUnlikely((simCtx)->nTracePIDs > 0) && ParticleIsTraced((simCtx), (pid)))) |
True when pid is traced (monitor.yml -> logging.trace_particles). | |
| #define | PARTICLE_LOG_ACTIVE(simCtx, pid) ((PetscBool)(PARTICLE_IS_TRACED((simCtx), (pid)) || PARTICLE_LOG_VERBOSE_ENABLED())) |
| True when LOG_PARTICLE() would print for this particle in the calling function. | |
| #define | LOG_PARTICLE(simCtx, pid, stage, fmt, ...) |
| Reports one particle at one stage of a step: the consolidated per-particle line. | |
| #define | LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt, ...) |
Logs a message inside a loop, but only every interval iterations. | |
| #define | LOG_LOOP_ALLOW_EXACT(scope, level, var, val, fmt, ...) |
| Logs a custom message if a variable equals a specific value. | |
| #define | LOG_ARRAY_ELEMENT_ALLOW(scope, level, arr, length, idx, fmt) |
| Logs a single element of an array, given an index. | |
| #define | LOG_ARRAY_SUBRANGE_ALLOW(scope, level, arr, length, start, end, fmt) |
| Logs a consecutive subrange of an array. | |
| #define | PROFILE_FUNCTION_BEGIN |
| Marks the beginning of a profiled function: an always-on aggregate timer. | |
| #define | PROFILE_HELPER_BEGIN |
| Marks the beginning of a profiled helper: timed only when enabled by name. | |
| #define | PROFILE_FUNCTION_END do { if (_picurv_profile_timed) (void)PetscLogEventEnd(_picurv_profile_event, 0, 0, 0, 0); } while (0) |
| Marks the end of a profiled code block. | |
| #define | PROFILE_HELPER_END PROFILE_FUNCTION_END |
| Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN. | |
Enumerations | |
| enum | LogLevel { LOG_ERROR = 0 , LOG_WARNING , LOG_INFO , LOG_DEBUG , LOG_TRACE , LOG_VERBOSE } |
| Enumeration of logging levels. More... | |
| enum | PicurvCsvLifecycle { PICURV_CSV_APPEND = 0 , PICURV_CSV_TRUNCATE_ON_FRESH } |
| What a run's first write does to an existing CSV record (see PicurvOpenRunCsv()). More... | |
Functions | |
| static PetscBool | ParticleIsTraced (const SimCtx *simCtx, PetscInt64 pid) |
True when pid is one of the run's traced particles (simCtx->tracePIDs, sorted). | |
| LogLevel | _ResolveLogLevel (void) |
Internal hook: read LOG_LEVEL from the environment and cache it, once. | |
| static LogLevel | get_log_level (void) |
Retrieves the current logging level from the environment variable LOG_LEVEL. | |
| PetscErrorCode | print_log_level (void) |
| Prints the current logging level to the console. | |
| void | set_allowed_functions (const char **functionList, int count) |
| Sets the global list of function names that are allowed to log. | |
| PetscBool | is_function_allowed (const char *functionName) |
| Checks if a given function is in the allow-list. | |
| PetscErrorCode | LOG_CELL_VERTICES (const Cell *cell, PetscMPIInt rank) |
| Prints the coordinates of a cell's vertices. | |
| PetscErrorCode | LOG_FACE_DISTANCES (PetscReal *d) |
| Prints the signed distances to each face of the cell. | |
| PetscErrorCode | LOG_PARTICLE_FIELDS (UserCtx *user, PetscInt printInterval) |
| Prints particle fields in a table that automatically adjusts its column widths. | |
| PetscBool | IsParticleConsoleSnapshotEnabled (const SimCtx *simCtx) |
| Returns whether periodic particle console snapshots are enabled. | |
| PetscBool | ShouldEmitPeriodicParticleConsoleSnapshot (const SimCtx *simCtx, PetscInt completed_step) |
| Returns whether a particle console snapshot should be emitted for the completed timestep. | |
| PetscErrorCode | EmitParticleConsoleSnapshot (UserCtx *user, SimCtx *simCtx, PetscInt step) |
| Emits one particle console snapshot into the main solver log. | |
| PetscBool | IsStatisticsConsoleSnapshotEnabled (const struct SimCtx *simCtx) |
| Reports whether the periodic statistics console snapshot is enabled. | |
| PetscBool | ShouldEmitPeriodicStatisticsConsoleSnapshot (const struct SimCtx *simCtx, PetscInt completed_step) |
| Reports whether a completed step falls on the console snapshot cadence. | |
| PetscErrorCode | EmitStatisticsConsoleSnapshot (UserCtx *user, const struct SimCtx *simCtx, PetscInt step) |
| Emits one console snapshot of window progress. | |
| PetscErrorCode | FreeAllowedFunctions (char **funcs, PetscInt n) |
| Free an array previously returned by LoadAllowedFunctionsFromFile(). | |
| PetscErrorCode | LoadAllowedFunctionsFromFile (const char filename[], char ***funcsOut, PetscInt *nOut) |
| Load function names from a text file. | |
| const char * | BCFaceToString (BCFace face) |
| Returns the canonical log token for a boundary-face enum value. | |
| const char * | ParticleInitializationToString (ParticleInitializationType ParticleInitialization) |
| Returns the canonical log token for a particle-initialization mode. | |
| const char * | LESModelToString (LESModelType LESFlag) |
| Returns the canonical log token for an LES model selector. | |
| const char * | LESFilterWidthModelToString (LESFilterWidthModel model) |
| Returns the user-facing name of an LES grid-filter-width model. | |
| const char * | LESTestFilterKernelToString (LESTestFilterKernel kernel) |
| Returns the user-facing name of an LES test-filter kernel. | |
| const char * | LESAveragingModeToString (LESAveragingMode mode) |
| Returns the user-facing name of an LES coefficient-averaging mode. | |
| const char * | LESClipModeToString (LESClipMode mode) |
| Returns the user-facing name of an LES coefficient-limiting mode. | |
| const char * | WallFunctionModelToString (WallFunctionModel model) |
| Returns the user-facing name of a wall-function model. | |
| const char * | MomentumSolverTypeToString (MomentumSolverType SolverFlag) |
| Returns the canonical log token for a momentum-solver selector. | |
| const char * | BCTypeToString (BCType type) |
| Returns the canonical log token for a boundary mathematical type. | |
| const char * | ParticleBoundaryPolicyToString (ParticleBoundaryPolicy policy) |
| Returns the configuration token for a particle boundary policy. | |
| const char * | InterpolationMethodToString (InterpolationMethod method) |
| Returns the display name of a grid-to-particle interpolation method. | |
| const char * | BCHandlerTypeToString (BCHandlerType handler_type) |
| Converts a BCHandlerType enum to its string representation. | |
| PetscErrorCode | DualKSPMonitor (KSP ksp, PetscInt it, PetscReal rnorm, void *ctx) |
| A custom KSP monitor that logs to a file and optionally to the console. | |
| PetscErrorCode | DualMonitorDestroy (void **ctx) |
| Destroys the DualMonitorCtx. | |
| PetscErrorCode | LOG_CONTINUITY_METRICS (UserCtx *user) |
| Logs continuity metrics for a single block to a file. | |
| PetscErrorCode | LOG_SOLUTION_CONVERGENCE (SimCtx *simCtx) |
| Logs physical solution-convergence metrics once per completed timestep. | |
| const char * | ParticleLocationStatusToString (ParticleLocationStatus level) |
| A function that outputs the name of the current level in the ParticleLocation enum. | |
| void | PrintProgressBar (PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime, PetscReal seconds_per_step, PetscInt64 lost_cumulative) |
| Prints a progress bar to the console. | |
| PetscErrorCode | ProfilingInitialize (SimCtx *simCtx) |
| Applies the profiling configuration from SimCtx to PICurv's PETSc log events. | |
| PetscErrorCode | ProfilingResetTimestepCounters (void) |
| Starts a new per-step profiling interval. | |
| PetscErrorCode | ProfilingLogTimestepSummary (SimCtx *simCtx, PetscInt step) |
| Logs the performance summary for the current timestep and resets timers. | |
| PetscErrorCode | RuntimeMemoryLogSample (SimCtx *simCtx, PetscInt step, const char *event, const char *reason) |
| Append a reduced runtime memory sample to the configured memory log. | |
| PetscErrorCode | ProfilingFinalize (SimCtx *simCtx) |
| Writes the end-of-run profiling summary across all ranks; collective on PETSC_COMM_WORLD. | |
| void | _ProfilingRegister (const char *func_name, PetscBool helper, PetscLogEvent *event) |
| Internal profiling hook: register a call site's function as a PETSc log event. | |
| PetscErrorCode | LOG_FIELD_MIN_MAX (UserCtx *user, FieldId field_id) |
| Computes and logs the local and global min/max values of a 3-component vector field. | |
| PetscErrorCode | LOG_FIELD_ANATOMY (UserCtx *user, FieldId field_id, const char *stage_name) |
| Logs the anatomy of a specified field at key boundary locations, respecting the solver's specific grid and variable architecture. | |
| PetscErrorCode | LOG_CORNER_FIELD_ANATOMY (UserCtx *user, FieldId corner_field_id, const char *stage_name) |
| Logs the node-layout anatomy of the transient center-to-corner interpolation field. | |
| PetscErrorCode | LOG_INTERPOLATION_ERROR (UserCtx *user) |
| Logs the interpolation error between the analytical and computed solutions. | |
| PetscErrorCode | LOG_SCATTER_METRICS (UserCtx *user) |
| Logs particle-to-grid scatter verification metrics for the prescribed scalar truth path. | |
| PetscErrorCode | ResetSearchMetrics (SimCtx *simCtx) |
| Resets the aggregate per-timestep search instrumentation counters. | |
| PetscErrorCode | CalculateAdvancedParticleMetrics (UserCtx *user) |
| Computes advanced particle statistics and stores them in SimCtx. | |
| PetscErrorCode | LOG_SEARCH_METRICS (UserCtx *user) |
| Writes compact runtime search metrics to CSV and optionally to console. | |
| PetscErrorCode | PicurvOpenRunCsv (SimCtx *simCtx, const char *dir, const char *filename, const char *header, PicurvCsvLifecycle lifecycle, PetscBool required, FILE **file) |
| Opens one of the run's CSV records (diagnostics, solver history, profiling) for writing. | |
| static PetscErrorCode | PicurvOpenDiagnosticsCsv (SimCtx *simCtx, const char *dir, const char *filename, const char *header, FILE **file) |
| Opens a per-step diagnostics CSV: PicurvOpenRunCsv() with the common settings. | |
Variables | |
| const LogLevel *const | _picurv_log_level |
| Read-only view of the cached logging level; -1 until the first get_log_level() call. | |
| const PetscBool *const | _picurv_profile_helpers_on |
Read-only view: whether profiling.helpers enables any helper timer. | |
Logging utilities and macros for PETSc-based applications.
This header defines logging levels, scopes, and macros for consistent logging throughout the application. It provides functions to retrieve the current logging level and macros to simplify logging with scope control.
Definition in file logging.h.
| struct DualMonitorCtx |
Context for a dual-purpose KSP monitor.
Holds the rank-0 history file the monitor writes one CSV row per iteration to, whether the true residual is computed and echoed to the console, and the workspaces that computation keeps.
| Data Fields | ||
|---|---|---|
| FILE * | file_handle | |
| PetscBool | log_to_console | |
| PetscBool | true_residual | |
| PetscReal | bnorm | |
| PetscInt | step | |
| PetscInt | block_id | |
| Vec | residual_work[2] | |
| #define LOCAL 0 |
| #define GLOBAL 1 |
| #define LOG | ( | scope, | |
| level, | |||
| fmt, | |||
| ... | |||
| ) |
Logging macro for PETSc-based applications with scope control.
This macro provides a convenient way to log messages with different scopes (LOCAL or GLOBAL) and severity levels. It utilizes PETSc's PetscPrintf function for message output.
| scope | Specifies the logging scope:
|
| level | The severity level of the message (e.g., LOG_INFO, LOG_ERROR). |
| fmt | The format string for the message (similar to printf). |
| ... | Additional arguments for the format string (optional). |
Example usage: LOG(LOCAL, LOG_ERROR, "An error occurred at index %ld.\n", idx); LOG(GLOBAL, LOG_INFO, "Grid size: %ld x %ld x %ld.\n", nx, ny, nz);
Definition at line 86 of file logging.h.
| #define LOG_DEFAULT | ( | level, | |
| fmt, | |||
| ... | |||
| ) |
Default logging macro for PETSc-based applications.
This macro simplifies logging by defaulting the scope to GLOBAL (i.e., MPI_COMM_WORLD) and providing a convenient interface for common logging needs.
| level | The severity level of the message (e.g., LOG_ERROR, LOG_INFO). |
| fmt | The format string for the log message (similar to printf). |
| ... | Additional arguments for the format string (optional). |
Example usage: LOG_DEFAULT(LOG_ERROR, "Error occurred at index %ld.\n", idx); LOG_DEFAULT(LOG_INFO, "Grid size: %ld x %ld x %ld.\n", nx, ny, nz);
MPI_COMM_WORLD.LOG macro.get_log_level(). Definition at line 117 of file logging.h.
| #define LOG_SYNC | ( | scope, | |
| level, | |||
| fmt, | |||
| ... | |||
| ) |
Logging macro for PETSc-based applications with scope control, using synchronized output across processes.
This macro uses PetscSynchronizedPrintf and PetscSynchronizedFlush to ensure messages from different ranks are printed in a synchronized (rank-by-rank) manner, preventing interleaved outputs.
| scope | Specifies the logging scope:
|
| level | The severity level of the message (e.g., LOG_INFO, LOG_ERROR). |
| fmt | The format string for the message (similar to printf). |
| ... | Additional arguments for the format string (optional). |
Example usage: LOG_SYNC(LOCAL, LOG_ERROR, "An error occurred at index %ld.\n", idx); LOG_SYNC(GLOBAL, LOG_INFO, "Synchronized info: rank = %ld.\n", rank);
Definition at line 147 of file logging.h.
| #define LOG_SYNC_DEFAULT | ( | level, | |
| fmt, | |||
| ... | |||
| ) |
Default synchronized logging macro for PETSc-based applications.
This macro simplifies logging by defaulting the scope to GLOBAL (i.e., MPI_COMM_WORLD) and provides synchronized output across all processes.
| level | The severity level of the message (e.g., LOG_ERROR, LOG_INFO). |
| fmt | The format string for the log message (similar to printf). |
| ... | Additional arguments for the format string (optional). |
Example usage: LOG_SYNC_DEFAULT(LOG_ERROR, "Error at index %ld.\n", idx); LOG_SYNC_DEFAULT(LOG_INFO, "Process rank: %ld.\n", rank);
MPI_COMM_WORLD.LOG_SYNC macro.get_log_level(). Definition at line 180 of file logging.h.
| #define LOG_LEVEL_ADMITS | ( | level | ) | ((int)(level) <= (int)get_log_level() && ((int)(level) <= (int)LOG_WARNING || is_function_allowed(__func__))) |
True when a code-level diagnostic at level prints from the calling function.
The level must be admitted by the run's verbosity. A warning or an error then prints from any function, since an operator running at WARNING must see it; INFO and below print only from allow-listed functions, so instrumenting one function does not drag in the others. The value is the same on every rank.
| #define LOG_ALLOW | ( | scope, | |
| level, | |||
| fmt, | |||
| ... | |||
| ) |
Logging macro that checks both the log level and whether the calling function is in the allowed-function list before printing.
Useful for selective, per-function logging. Warnings and errors ignore the allow-list (see LOG_LEVEL_ADMITS()).
| scope | Specifies the logging scope (LOCAL or GLOBAL). |
| level | The severity level of the message (e.g., LOG_INFO, LOG_ERROR). |
| fmt | The format string for the message (similar to printf). |
| ... | Additional arguments for the format string (optional). |
Example usage: LOG_ALLOW(LOCAL, LOG_DEBUG, "Debugging info in function: %s\n", func);
Definition at line 214 of file logging.h.
| #define LOG_ALLOW_SYNC | ( | scope, | |
| level, | |||
| fmt, | |||
| ... | |||
| ) |
Synchronized logging macro that checks both the log level and whether the calling function is in the allow-list.
This macro uses PetscSynchronizedPrintf and PetscSynchronizedFlush to ensure messages from different ranks are printed in a rank-ordered fashion (i.e., to avoid interleaving). It also filters out messages if the current function is not in the allow-list (is_function_allowed(__func__)) or the requested log level is higher than get_log_level().
With GLOBAL scope every rank prints its own line, in rank order, so the message should carry per-rank data; a value every rank shares belongs in LOG_ALLOW(GLOBAL, ...), which prints it once. The flush is collective over the scope's communicator and runs only when the message is enabled. The level and the allow-list are the same on every rank, so either every rank of the communicator flushes or none does: a disabled message costs no communication. Every rank of that communicator must still reach the call.
| scope | Either LOCAL (MPI_COMM_SELF) or GLOBAL (MPI_COMM_WORLD). |
| level | One of LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_TRACE, LOG_VERBOSE. |
| fmt | A printf-style format string (e.g., "Message: %ld\n"). |
| ... | Variadic arguments to fill in fmt. |
Example usage:
Definition at line 273 of file logging.h.
| #define PARTICLE_LOG_VERBOSE_ENABLED | ( | ) | (PetscUnlikely((int)get_log_level() >= (int)LOG_VERBOSE) && is_function_allowed(__func__)) |
| #define PARTICLE_IS_TRACED | ( | simCtx, | |
| pid | |||
| ) | ((PetscBool)(PetscUnlikely((simCtx)->nTracePIDs > 0) && ParticleIsTraced((simCtx), (pid)))) |
| #define PARTICLE_LOG_ACTIVE | ( | simCtx, | |
| pid | |||
| ) | ((PetscBool)(PARTICLE_IS_TRACED((simCtx), (pid)) || PARTICLE_LOG_VERBOSE_ENABLED())) |
True when LOG_PARTICLE() would print for this particle in the calling function.
For a stage whose line is costly to assemble (several fields): test this, build the text, then emit it with LOG_PARTICLE().
| #define LOG_PARTICLE | ( | simCtx, | |
| pid, | |||
| stage, | |||
| fmt, | |||
| ... | |||
| ) |
Reports one particle at one stage of a step: the consolidated per-particle line.
Each stage that processes particles (position update, location, interpolation, model update, removal) emits at most one such line per particle, carrying every value the stage computed for it. The line prints, on the rank holding the particle, when either
monitor.yml -> logging.trace_particles), whatever the log level and allow-list, prefixed [trace pid=<id> step=<n> <stage>]; or| simCtx | The simulation context (const SimCtx *). |
| pid | The particle ID (PetscInt64). |
| stage | A short stage label, such as "locate". |
| fmt | A printf-style format string ending in a newline. |
Definition at line 355 of file logging.h.
| #define LOG_LOOP_ALLOW | ( | scope, | |
| level, | |||
| iterVar, | |||
| interval, | |||
| fmt, | |||
| ... | |||
| ) |
Logs a message inside a loop, but only every interval iterations.
| scope | LOCAL or GLOBAL. |
| level | LOG_* level. |
| iterVar | The loop variable (e.g., i). |
| interval | Only log when (iterVar % interval == 0). |
| fmt | printf-style format string. |
| ... | Variadic arguments to include in the formatted message. |
Example: for (int i = 0; i < 100; i++) { LOG_LOOP_ALLOW(LOCAL, LOG_DEBUG, i, 10, "Value of i=%d\n", i); }
Definition at line 380 of file logging.h.
| #define LOG_LOOP_ALLOW_EXACT | ( | scope, | |
| level, | |||
| var, | |||
| val, | |||
| fmt, | |||
| ... | |||
| ) |
Logs a custom message if a variable equals a specific value.
This is a variadic macro for logging a single event when a condition is met. It is extremely useful for printing debug information at a specific iteration of a loop or when a state variable reaches a certain value.
| scope | Either LOCAL or GLOBAL. |
| level | The logging level. |
| var | The variable to check (e.g., a loop counter 'k'). |
| val | The value that triggers the log (e.g., 6). The log prints if var == val. |
| fmt | A printf-style format string. |
| ... | A printf-style format string and its corresponding arguments. |
Definition at line 405 of file logging.h.
| #define LOG_ARRAY_ELEMENT_ALLOW | ( | scope, | |
| level, | |||
| arr, | |||
| length, | |||
| idx, | |||
| fmt | |||
| ) |
Logs a single element of an array, given an index.
| scope | Either LOCAL or GLOBAL. |
| level | LOG_ERROR, LOG_WARNING, LOG_INFO, or LOG_DEBUG. |
| arr | Pointer to the array to log from. |
| length | The length of the array (to prevent out-of-bounds). |
| idx | The index of the element to print. |
| fmt | The printf-style format specifier (e.g. "%g", "%f", etc.). |
This macro only logs if: 1) The current function is in the allow-list (is_function_allowed(__func__)). 2) The requested logging level <= the current global get_log_level(). 3) The index idx is valid (0 <= idx < length).
Definition at line 434 of file logging.h.
| #define LOG_ARRAY_SUBRANGE_ALLOW | ( | scope, | |
| level, | |||
| arr, | |||
| length, | |||
| start, | |||
| end, | |||
| fmt | |||
| ) |
Logs a consecutive subrange of an array.
| scope | Either LOCAL or GLOBAL. |
| level | LOG_ERROR, LOG_WARNING, LOG_INFO, or LOG_DEBUG. |
| arr | Pointer to the array to log from. |
| length | Total length of the array. |
| start | Starting index of the subrange. |
| end | Ending index of the subrange (inclusive). |
| fmt | The printf-style format specifier (e.g., "%g", "%f"). |
This macro prints each element arr[i] for i in [start, end], bounded by [0, length-1].
Definition at line 458 of file logging.h.
| #define PROFILE_FUNCTION_BEGIN |
Marks the beginning of a profiled function: an always-on aggregate timer.
Place this macro at the very beginning of a function called once or a few times per step or solver pass. The function is a PETSc log event of class PICurv, named by __func__, registered on its first call and cached in a function-local static; it appears in the final profiling summary, the per-step output and log_view.
| #define PROFILE_HELPER_BEGIN |
Marks the beginning of a profiled helper: timed only when enabled by name.
For functions called per particle or per cell. The event (class PICurvHelper) is off unless profiling.helpers names it (or is all). With no helper enabled, a call costs one flag test; with some enabled, PETSc's per-event check decides. End it with PROFILE_FUNCTION_END (or its alias PROFILE_HELPER_END).
| #define PROFILE_FUNCTION_END do { if (_picurv_profile_timed) (void)PetscLogEventEnd(_picurv_profile_event, 0, 0, 0, 0); } while (0) |
Marks the end of a profiled code block.
Place this macro just before every return point in a function that starts with PROFILE_FUNCTION_BEGIN or PROFILE_HELPER_BEGIN. A missed one leaves the PETSc event open, and the function's later calls are then not recorded. It ends the event only if the BEGIN macro began it, and reads the state that macro declares, so it must sit in that macro's scope; a function that ends a timer it never began does not compile.
Definition at line 1029 of file logging.h.
| #define PROFILE_HELPER_END PROFILE_FUNCTION_END |
| enum LogLevel |
Enumeration of logging levels.
Defines various severity levels for logging messages.
Definition at line 28 of file logging.h.
| enum PicurvCsvLifecycle |
What a run's first write does to an existing CSV record (see PicurvOpenRunCsv()).
| Enumerator | |
|---|---|
| PICURV_CSV_APPEND | Every run appends: earlier runs' rows are kept. |
| PICURV_CSV_TRUNCATE_ON_FRESH | A fresh run's first write empties the file; a continued run appends. |
Definition at line 1144 of file logging.h.
|
inlinestatic |
True when pid is one of the run's traced particles (simCtx->tracePIDs, sorted).
| [in] | simCtx | The simulation context holding the traced IDs. |
| [in] | pid | The particle ID to test. |
Definition at line 306 of file logging.h.
| LogLevel _ResolveLogLevel | ( | void | ) |
Internal hook: read LOG_LEVEL from the environment and cache it, once.
Supported levels are "ERROR", "WARNING", "INFO", "DEBUG", "TRACE", and "VERBOSE". Unset or unrecognized values default to "ERROR". Call get_log_level() instead.
Internal hook: read LOG_LEVEL from the environment and cache it, once.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 101 of file logging.c.
|
inlinestatic |
Retrieves the current logging level from the environment variable LOG_LEVEL.
The first call reads LOG_LEVEL (see _ResolveLogLevel()); every later call returns the cached value.
Definition at line 496 of file logging.h.
| PetscErrorCode print_log_level | ( | void | ) |
Prints the current logging level to the console.
This function retrieves the log level using get_log_level() and prints the corresponding log level name. It helps verify the logging configuration at runtime. The log levels supported are:
LOG_ERROR (0) : Logs only critical errors.LOG_WARNING (1) : Logs warnings and errors.LOG_INFO (2) : Logs general information, warnings, and errors.LOG_DEBUG (3) : Logs debugging information, info, warnings, and errors.LOG_TRACE (4) : Logs fine-grained trace information.LOG_VERBOSE (5) : Logs very detailed developer output. If LOG_LEVEL is not set, it defaults to LOG_ERROR.
Prints the current logging level to the console.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 138 of file logging.c.
| void set_allowed_functions | ( | const char ** | functionList, |
| int | count | ||
| ) |
Sets the global list of function names that are allowed to log.
You can replace the entire list of allowed function names at runtime.
| functionList | Replacement array of permitted function names. |
| count | Number of entries in functionList. |
Sets the global list of function names that are allowed to log.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 176 of file logging.c.
| PetscBool is_function_allowed | ( | const char * | functionName | ) |
Checks if a given function is in the allow-list.
This helper is used internally by the LOG_ALLOW macro.
| functionName | Function name to query. |
Checks if a given function is in the allow-list.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 207 of file logging.c.
| PetscErrorCode LOG_CELL_VERTICES | ( | const Cell * | cell, |
| PetscMPIInt | rank | ||
| ) |
Prints the coordinates of a cell's vertices.
This function iterates through the eight vertices of a given cell and prints their coordinates. It is primarily used for debugging purposes to verify the correctness of cell vertex assignments.
| [in] | cell | Pointer to a Cell structure representing the cell, containing its vertices. |
| [in] | rank | MPI rank for identification (useful in parallel environments). |
cell pointer is not NULL before calling this function..Prints the coordinates of a cell's vertices.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 229 of file logging.c.
| PetscErrorCode LOG_FACE_DISTANCES | ( | PetscReal * | d | ) |
Prints the signed distances to each face of the cell.
This function iterates through the six signed distances from a point to each face of a given cell and prints their values. It is primarily used for debugging purposes to verify the correctness of distance calculations.
| [in] | d | An array of six PetscReal values representing the signed distances. The indices correspond to:
|
d array is correctly populated with signed distances before calling this function.Prints the signed distances to each face of the cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 256 of file logging.c.
| PetscErrorCode LOG_PARTICLE_FIELDS | ( | UserCtx * | user, |
| PetscInt | printInterval | ||
| ) |
Prints particle fields in a table that automatically adjusts its column widths.
Collective. A row is printed for each particle whose ID is a multiple of printInterval, at most PICURV_SNAPSHOT_ROWS_PER_RANK per rank, so successive snapshots show the same particles and the table's size does not grow with the swarm. Column widths are agreed across ranks; one header precedes every rank's rows, and a closing line states how many rows of how many particles were shown.
| [in] | user | Pointer to the UserCtx structure. |
| [in] | printInterval | Sampling interval on particle IDs (values below 1 mean every particle). |
Prints particle fields in a table that automatically adjusts its column widths.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 399 of file logging.c.
| PetscBool IsParticleConsoleSnapshotEnabled | ( | const SimCtx * | simCtx | ) |
Returns whether periodic particle console snapshots are enabled.
This checks only the reporting contract (particles exist, cadence is enabled, and the global log level is at least INFO).
| simCtx | Simulation context controlling the operation (NULL means disabled). |
Returns whether periodic particle console snapshots are enabled.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 484 of file logging.c.
| PetscBool ShouldEmitPeriodicParticleConsoleSnapshot | ( | const SimCtx * | simCtx, |
| PetscInt | completed_step | ||
| ) |
Returns whether a particle console snapshot should be emitted for the completed timestep.
True when snapshots are enabled (IsParticleConsoleSnapshotEnabled()) and the positive completed_step is a multiple of the snapshot cadence.
| simCtx | Simulation context controlling the operation. |
| completed_step | Completed step index used by the decision helper. |
Returns whether a particle console snapshot should be emitted for the completed timestep.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 501 of file logging.c.
Emits one particle console snapshot into the main solver log.
| user | Primary UserCtx input for the operation. |
| simCtx | Simulation context controlling the operation. |
| step | Step index associated with the operation. |
Emits one particle console snapshot into the main solver log.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 518 of file logging.c.
| PetscBool IsStatisticsConsoleSnapshotEnabled | ( | const struct SimCtx * | simCtx | ) |
Reports whether the periodic statistics console snapshot is enabled.
Mirrors the particle console gate: the subsystem must be active, the configured cadence positive, and the effective log level at least LOG_INFO.
| [in] | simCtx | Simulation context to inspect. |
PETSC_TRUE when snapshots should be emitted. | PetscBool ShouldEmitPeriodicStatisticsConsoleSnapshot | ( | const struct SimCtx * | simCtx, |
| PetscInt | completed_step | ||
| ) |
Reports whether a completed step falls on the console snapshot cadence.
| [in] | simCtx | Simulation context to inspect. |
| [in] | completed_step | Step that has just completed. |
PETSC_TRUE when a snapshot is due for this step. | PetscErrorCode EmitStatisticsConsoleSnapshot | ( | UserCtx * | user, |
| const struct SimCtx * | simCtx, | ||
| PetscInt | step | ||
| ) |
Emits one console snapshot of window progress.
Reports window-level scalars only; it never dumps field data.
| [in] | user | Finest-level block array supplying accumulator state. |
| [in] | simCtx | Simulation context carrying the window array. |
| [in] | step | Step the snapshot describes. |
| PetscErrorCode FreeAllowedFunctions | ( | char ** | funcs, |
| PetscInt | n | ||
| ) |
Free an array previously returned by LoadAllowedFunctionsFromFile().
| [in,out] | funcs | Array of strings to release (may be NULL). |
| [in] | n | Number of entries in funcs. Ignored if funcs is NULL. |
Free an array previously returned by LoadAllowedFunctionsFromFile().
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 619 of file logging.c.
| PetscErrorCode LoadAllowedFunctionsFromFile | ( | const char | filename[], |
| char *** | funcsOut, | ||
| PetscInt * | nOut | ||
| ) |
Load function names from a text file.
The file is expected to contain one identifier per line. Blank lines and lines whose first non‑blank character is a # are silently skipped so the file can include comments. Example:
The routine allocates memory as needed (growing an internal buffer with PetscRealloc()) and returns the resulting array and its length to the caller. Use FreeAllowedFunctions() to clean up when done.
| [in] | filename | Path of the configuration file to read. |
| [out] | funcsOut | On success, points to a freshly‑allocated array of char* (size nOut). |
| [out] | nOut | Number of valid entries in funcsOut. |
Load function names from a text file.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 561 of file logging.c.
| const char * BCFaceToString | ( | BCFace | face | ) |
Returns the canonical log token for a boundary-face enum value.
| [in] | face | The BCFace enum value. |
Returns the canonical log token for a boundary-face enum value.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 640 of file logging.c.
| const char * ParticleInitializationToString | ( | ParticleInitializationType | ParticleInitialization | ) |
Returns the canonical log token for a particle-initialization mode.
| [in] | ParticleInitialization | The ParticleInitialization enum value. |
Returns the canonical log token for a particle-initialization mode.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 662 of file logging.c.
| const char * LESModelToString | ( | LESModelType | LESFlag | ) |
Returns the canonical log token for an LES model selector.
| [in] | LESFlag | The LES flag value. |
Returns the canonical log token for an LES model selector.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 682 of file logging.c.
| const char * LESFilterWidthModelToString | ( | LESFilterWidthModel | model | ) |
Returns the user-facing name of an LES grid-filter-width model.
| [in] | model | The filter-width model selector. |
Returns the user-facing name of an LES grid-filter-width model.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 704 of file logging.c.
| const char * LESTestFilterKernelToString | ( | LESTestFilterKernel | kernel | ) |
Returns the user-facing name of an LES test-filter kernel.
| [in] | kernel | The test-filter kernel selector. |
Returns the user-facing name of an LES test-filter kernel.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 727 of file logging.c.
| const char * LESAveragingModeToString | ( | LESAveragingMode | mode | ) |
Returns the user-facing name of an LES coefficient-averaging mode.
| [in] | mode | The averaging mode selector. |
Returns the user-facing name of an LES coefficient-averaging mode.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 746 of file logging.c.
| const char * LESClipModeToString | ( | LESClipMode | mode | ) |
Returns the user-facing name of an LES coefficient-limiting mode.
| [in] | mode | The limiting mode selector. |
Returns the user-facing name of an LES coefficient-limiting mode.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 766 of file logging.c.
| const char * WallFunctionModelToString | ( | WallFunctionModel | model | ) |
Returns the user-facing name of a wall-function model.
| [in] | model | The wall-model selector. |
Returns the user-facing name of a wall-function model.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 786 of file logging.c.
| const char * MomentumSolverTypeToString | ( | MomentumSolverType | SolverFlag | ) |
Returns the canonical log token for a momentum-solver selector.
| [in] | SolverFlag | The Momentum Solver flag value. |
Returns the canonical log token for a momentum-solver selector.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 808 of file logging.c.
| const char * BCTypeToString | ( | BCType | type | ) |
Returns the canonical log token for a boundary mathematical type.
| [in] | type | The BCType enum value. |
Returns the canonical log token for a boundary mathematical type.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 828 of file logging.c.
| const char * ParticleBoundaryPolicyToString | ( | ParticleBoundaryPolicy | policy | ) |
Returns the configuration token for a particle boundary policy.
| [in] | policy | The ParticleBoundaryPolicy enum value. |
Returns the configuration token for a particle boundary policy.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 850 of file logging.c.
| const char * InterpolationMethodToString | ( | InterpolationMethod | method | ) |
Returns the display name of a grid-to-particle interpolation method.
| [in] | method | The InterpolationMethod enum value. |
Returns the display name of a grid-to-particle interpolation method.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 869 of file logging.c.
| const char * BCHandlerTypeToString | ( | BCHandlerType | handler_type | ) |
Converts a BCHandlerType enum to its string representation.
Provides a descriptive string for a specific boundary condition implementation strategy. This is crucial for logging the exact behavior configured for a face.
| handler_type | The BCHandlerType enum value (e.g., BC_HANDLER_WALL_NOSLIP). |
Converts a BCHandlerType enum to its string representation.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 888 of file logging.c.
| PetscErrorCode DualKSPMonitor | ( | KSP | ksp, |
| PetscInt | it, | ||
| PetscReal | rnorm, | ||
| void * | ctx | ||
| ) |
A custom KSP monitor that logs to a file and optionally to the console.
On rank 0 it writes one CSV row per iteration to the context's history file, when one is open, and prints the same values when log_to_console is set. When the context asks for the true residual it also computes the true and relative residual norms (collective).
| ksp | The Krylov subspace context. |
| it | The current iteration number. |
| rnorm | The preconditioned residual norm. |
| ctx | A pointer to the DualMonitorCtx structure. |
A custom KSP monitor that logs to a file and optionally to the console.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 955 of file logging.c.
| PetscErrorCode DualMonitorDestroy | ( | void ** | ctx | ) |
Destroys the DualMonitorCtx.
This function is passed to KSPMonitorSet so that, when the KSP is destroyed, rank 0 closes any open history file and the residual workspaces and the context are freed.
| ctx | a pointer to the context pointer to be destroyed |
Destroys the DualMonitorCtx.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 927 of file logging.c.
| PetscErrorCode LOG_CONTINUITY_METRICS | ( | UserCtx * | user | ) |
Logs continuity metrics for a single block to a file.
This function should be called for each block, once per timestep. Rank 0 appends one row per block to <log_dir>/Continuity_Metrics.csv (see PicurvOpenDiagnosticsCsv()); only block 0 may write a continued run's continuation marker, so the marker appears once.
| user | A pointer to the UserCtx for the specific block whose metrics are to be logged. The function accesses both global (SimCtx) and local (user->...) data. |
Logs continuity metrics for a single block to a file.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 1866 of file logging.c.
| PetscErrorCode LOG_SOLUTION_CONVERGENCE | ( | SimCtx * | simCtx | ) |
Logs physical solution-convergence metrics once per completed timestep.
This logger is intentionally separate from the detailed inner solver-health logs. Depending on the configured mode, it records deterministic step drift, periodic phase-aligned drift, or statistical window drift into <log_dir>/solution_convergence.csv.
The logger is solver-mode only and is intended to run after a completed flow-solve / projection step but before history vectors are shifted forward. Warmup rows are handled internally:
has_reference = 0Existing detailed inner logs remain the authoritative source for momentum, Poisson, and continuity health. This logger only summarizes physical solution-drift metrics.
| [in,out] | simCtx | Master simulation context controlling the logging mode and owning any supporting runtime buffers. |
Logs physical solution-convergence metrics once per completed timestep.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 1714 of file logging.c.
| const char * ParticleLocationStatusToString | ( | ParticleLocationStatus | level | ) |
A function that outputs the name of the current level in the ParticleLocation enum.
| level | The ParticleLocation enum value. |
A function that outputs the name of the current level in the ParticleLocation enum.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 1905 of file logging.c.
| void PrintProgressBar | ( | PetscInt | step, |
| PetscInt | startStep, | ||
| PetscInt | totalSteps, | ||
| PetscReal | currentTime, | ||
| PetscReal | seconds_per_step, | ||
| PetscInt64 | lost_cumulative | ||
| ) |
Prints a progress bar to the console.
This function should only be called by the root process (rank 0). It uses a carriage return \r to overwrite the same line in the terminal, creating a dynamic progress bar.
| step | The current step index from the loop (e.g., from 0 to N-1). |
| startStep | The global starting step number of the simulation. |
| totalSteps | The total number of steps to be run in this simulation instance. |
| currentTime | The current simulation time to display. |
| seconds_per_step | Mean wall seconds per completed step, with the time left at that rate; omitted when not positive. |
| lost_cumulative | Particles lost so far in the run; omitted when negative. |
Prints a progress bar to the console.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 2446 of file logging.c.
| PetscErrorCode ProfilingInitialize | ( | SimCtx * | simCtx | ) |
Applies the profiling configuration from SimCtx to PICurv's PETSc log events.
Records the per-step selected function list and the enabled helper timers (profiling.helpers), and switches each helper event registered so far on or off to match. Starts PETSc's default log handler if nothing has yet. Called once from CreateSimulationContext(), before the main time loop.
| simCtx | The master simulation context holding the profiling configuration; its name lists must outlive profiling. |
Applies the profiling configuration from SimCtx to PICurv's PETSc log events.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 2015 of file logging.c.
| PetscErrorCode ProfilingResetTimestepCounters | ( | void | ) |
Starts a new per-step profiling interval.
Records every PETSc event's running totals; the next ProfilingLogTimestepSummary() reports the difference. Cumulative totals are untouched.
Starts a new per-step profiling interval.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 2087 of file logging.c.
| PetscErrorCode ProfilingLogTimestepSummary | ( | SimCtx * | simCtx, |
| PetscInt | step | ||
| ) |
Logs the performance summary for the current timestep and resets timers.
Depending on the configured profiling timestep mode, rank 0 writes per-step profiling rows to <log_dir>/Profiling_Timestep_Summary.csv, opened at its first row (see PicurvOpenRunCsv()):
off: writes nothingselected: writes only functions marked for per-step reportingall: writes every instrumented function that ran in the timestepIt must be called once per timestep, typically at the end of the main loop. A step's values are the change in each PICurv event's PETSc running totals since the previous call (or ProfilingResetTimestepCounters()); an event still open, such as the enclosing time loop, adds its time only when it ends. Only rank 0 writes.
| simCtx | The simulation context holding profiling output settings. |
| step | The current simulation step number, for logging context. |
Logs the performance summary for the current timestep and resets timers.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 2100 of file logging.c.
| PetscErrorCode RuntimeMemoryLogSample | ( | SimCtx * | simCtx, |
| PetscInt | step, | ||
| const char * | event, | ||
| const char * | reason | ||
| ) |
Append a reduced runtime memory sample to the configured memory log.
The log is intentionally compact: every rank samples process/PETSc allocator memory, one max reduction summarizes the job, and rank 0 appends one CSV row to <log_dir>/Runtime_Memory.csv, which is appended to and never truncated.
| simCtx | The simulation context holding log directory and memory log settings. |
| step | The solver/post step associated with the sample. |
| event | Human-readable event label such as "Step", "Post", "Shutdown", or "Final". |
| reason | Human-readable reason, or NULL/"-" when not applicable. |
Append a reduced runtime memory sample to the configured memory log.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 2170 of file logging.c.
| PetscErrorCode ProfilingFinalize | ( | SimCtx * | simCtx | ) |
Writes the end-of-run profiling summary across all ranks; collective on PETSC_COMM_WORLD.
Two sections: PICurv's events (aggregates, and helpers that were enabled), then PETSc's own events, whose inclusive times nest inside PICurv's. In each, the names any rank recorded are united by name, each name's total time is reduced to its maximum and minimum (with the ranks holding them) and its mean over ranks, and its calls are summed and reduced to their minimum and maximum per rank (with ranks), so a time spread can be told apart from a call-count spread. Rank 0 writes ProfilingSummary_<mode>.csv (<mode> is Solver or PostProcessor), slowest rank first; a continued run appends its totals after a continuation marker. This is the profiler's only communication; the timed path stays local to each rank.
| simCtx | The Simulation Context Structure that can contains all the data regarding the simulation. |
Writes the end-of-run profiling summary across all ranks; collective on PETSC_COMM_WORLD.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 2380 of file logging.c.
| void _ProfilingRegister | ( | const char * | func_name, |
| PetscBool | helper, | ||
| PetscLogEvent * | event | ||
| ) |
Internal profiling hook: register a call site's function as a PETSc log event.
Called once per call site, on its first execution. Registers the PICurv event classes and starts PETSc's default log handler on the first call anywhere. A helper event is switched off as it registers unless its name is enabled (profiling.helpers). Before PetscInitialize, after PetscFinalize, or on failure, it registers nothing and the call site stays untimed, trying again on its next call.
| func_name | Function name (__func__), the event's name. |
| helper | PETSC_TRUE for a per-particle or per-cell helper, PETSC_FALSE for an aggregate. |
| event | Call site's cached event; set when registration succeeds, else left at -1. |
Internal profiling hook: register a call site's function as a PETSc log event.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 1984 of file logging.c.
Computes and logs the local and global min/max values of a 3-component vector field.
This utility function inspects a PETSc Vec associated with a DMDA and calculates the minimum and maximum values for each of its three components (e.g., x, y, z) both for the local data on the current MPI rank and for the entire global domain.
It uses the same "smart" logic as the flow solver, ignoring the padding nodes at the IM, JM, and KM boundaries of the grid. The results are printed to the standard output in a formatted, easy-to-read table.
| [in] | user | Pointer to the user-defined context. Used for grid information (IM, JM, KM) and MPI rank. |
| [in] | field_id | Typed identity of the field being analyzed. |
Computes and logs the local and global min/max values of a 3-component vector field.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 2501 of file logging.c.
Logs the anatomy of a specified field at key boundary locations, respecting the solver's specific grid and variable architecture.
This intelligent diagnostic function inspects a PETSc Vec and prints its values at critical boundary locations (-Xi/+Xi, -Eta/+Eta, -Zeta/+Zeta). It is "architecture-aware":
Cell i is stored at array index i+1. It labels the output to clearly distinguish between true physical values and ghost values.Csi/ICsi/IEta/IZet/Centx belong to the I-face family, with corresponding J- and K-face families.Node i is stored at index i.The output is synchronized across MPI ranks to ensure readability and focuses on a slice through the center of the domain to be concise.
| user | A pointer to the UserCtx structure containing the DMs and Vecs. |
| field_id | Typed identity of the persistent Eulerian field to log. |
| stage_name | A string identifier for the current simulation stage (e.g., "After Advection"). |
Logs the anatomy of a specified field at key boundary locations, respecting the solver's specific grid and variable architecture.
Definition at line 2903 of file logging.c.
| PetscErrorCode LOG_CORNER_FIELD_ANATOMY | ( | UserCtx * | user, |
| FieldId | corner_field_id, | ||
| const char * | stage_name | ||
| ) |
Logs the node-layout anatomy of the transient center-to-corner interpolation field.
| user | Context owning the corner-staging workspace. |
| corner_field_id | Which corner workspace the caller populated. |
| stage_name | Printable simulation stage. |
Logs the node-layout anatomy of the transient center-to-corner interpolation field.
Definition at line 2997 of file logging.c.
| PetscErrorCode LOG_INTERPOLATION_ERROR | ( | UserCtx * | user | ) |
Logs the interpolation error between the analytical and computed solutions.
| user | Primary UserCtx input for the operation. |
Logs the interpolation error between the analytical and computed solutions.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 3024 of file logging.c.
| PetscErrorCode LOG_SCATTER_METRICS | ( | UserCtx * | user | ) |
Logs particle-to-grid scatter verification metrics for the prescribed scalar truth path.
| user | Primary UserCtx input for the operation. |
Logs particle-to-grid scatter verification metrics for the prescribed scalar truth path.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 3101 of file logging.c.
| PetscErrorCode ResetSearchMetrics | ( | SimCtx * | simCtx | ) |
Resets the aggregate per-timestep search instrumentation counters.
| simCtx | Simulation context whose search metrics should be zeroed. |
Resets the aggregate per-timestep search instrumentation counters.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 3252 of file logging.c.
| PetscErrorCode CalculateAdvancedParticleMetrics | ( | UserCtx * | user | ) |
Computes advanced particle statistics and stores them in SimCtx.
This function calculates:
It requires that CalculateParticleCountPerCell() has been called prior to its execution. It uses collective MPI operations and must be called by all ranks.
| user | Pointer to the UserCtx. |
Computes advanced particle statistics and stores them in SimCtx.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 3484 of file logging.c.
| PetscErrorCode LOG_SEARCH_METRICS | ( | UserCtx * | user | ) |
Writes compact runtime search metrics to CSV and optionally to console.
The CSV artifact is always written for particle-enabled runs. Console output remains gated by normal logging level and function allow-listing.
| user | Pointer to the UserCtx. |
Writes compact runtime search metrics to CSV and optionally to console.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/logging.h.
Definition at line 3288 of file logging.c.
| PetscErrorCode PicurvOpenRunCsv | ( | SimCtx * | simCtx, |
| const char * | dir, | ||
| const char * | filename, | ||
| const char * | header, | ||
| PicurvCsvLifecycle | lifecycle, | ||
| PetscBool | required, | ||
| FILE ** | file | ||
| ) |
Opens one of the run's CSV records (diagnostics, solver history, profiling) for writing.
The record lives in dir: the run's analysis directory (simCtx->analysis_dir) or log directory (simCtx->log_dir). This owns the file's lifecycle; the caller owns the columns:
header (starting step, or section,) is written whenever the file is empty, so it appears once, at the top;PICURV_CSV_TRUNCATE_ON_FRESH record is emptied first unless the run is a continuation (simCtx->continueMode), and a continuation writes # Continuation from step <StartStep>, so a reader can tell a resumed run from a discontinuity in the data. Every other call appends.The run's first open is tracked here, by path, in simCtx->runCsvWritten, so a record written at the output cadence, from step 0, or by several calls in one step needs no flag of its own.
Call on rank 0 only - the file is a serial artifact, and a collective write to it would interleave. The caller closes the handle.
| [in,out] | simCtx | Simulation context supplying the continuation state and StartStep, and recording the files the run has opened. |
| [in] | dir | Directory of the file. |
| [in] | filename | Basename of the CSV, including the extension. |
| [in] | header | Column header written to an empty file, without a trailing newline. |
| [in] | lifecycle | Whether a fresh run's first write empties the file. |
| [in] | required | PETSC_TRUE: a file that cannot be opened is an error. PETSC_FALSE: it is a warning and *file is NULL, for a diagnostic whose loss must not stop or change the run. |
| [out] | file | Open handle positioned at the end of the file; NULL only when required is false and the file could not be opened. |
PETSC_ERR_FILE_OPEN if a required file cannot be opened.Opens one of the run's CSV records (diagnostics, solver history, profiling) for writing.
Full API contract is documented with the header declaration in include/logging.h.
Definition at line 3552 of file logging.c.
|
inlinestatic |
Opens a per-step diagnostics CSV: PicurvOpenRunCsv() with the common settings.
For a record written every step and kept across runs: PICURV_CSV_APPEND, and a file that cannot be opened is an error.
| [in,out] | simCtx | Simulation context, as PicurvOpenRunCsv() takes it. |
| [in] | dir | Directory of the file (simCtx->analysis_dir or simCtx->log_dir). |
| [in] | filename | Basename of the CSV, including the extension. |
| [in] | header | Column header written to an empty file, without a trailing newline. |
| [out] | file | Open append handle, never NULL on success. |
PETSC_ERR_FILE_OPEN if the file cannot be opened. Definition at line 1197 of file logging.h.
|
extern |
Read-only view of the cached logging level; -1 until the first get_log_level() call.
Only logging.c writes the level. The view lets get_log_level() be inlined into every logging macro, so a disabled message in a per-particle loop costs a load and a compare rather than a function call.
|
extern |
Read-only view: whether profiling.helpers enables any helper timer.
False until ProfilingInitialize() applies a non-empty list. While it is false every helper event is switched off, so PROFILE_HELPER_BEGIN skips PETSc's per-event check.