84#define LOG(scope, level, fmt, ...) \
87 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
89 if ((int)(level) <= (int)get_log_level()) { \
91 PetscPrintf(comm, fmt, ##__VA_ARGS__); \
115#define LOG_DEFAULT(level, fmt, ...) \
118 MPI_Comm comm = MPI_COMM_WORLD; \
120 if ((int)(level) <= (int)get_log_level()) { \
122 PetscPrintf(comm, fmt, ##__VA_ARGS__); \
145#define LOG_SYNC(scope, level, fmt, ...) \
148 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
150 if ((int)(level) <= (int)get_log_level()) { \
152 PetscSynchronizedPrintf(comm, fmt, ##__VA_ARGS__); \
154 PetscSynchronizedFlush(comm, PETSC_STDOUT); \
178#define LOG_SYNC_DEFAULT(level, fmt, ...) \
180 if ((int)(level) <= (int)get_log_level()) { \
181 PetscSynchronizedPrintf(MPI_COMM_WORLD, fmt, ##__VA_ARGS__); \
182 PetscSynchronizedFlush(MPI_COMM_WORLD, PETSC_STDOUT); \
200#define LOG_ALLOW(scope, level, fmt, ...) \
202 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
203 if ((int)(level) <= (int)get_log_level() && is_function_allowed(__func__)) { \
204 PetscPrintf(comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
253#define LOG_ALLOW_SYNC(scope, level, fmt, ...) \
259 if ((scope) == LOCAL) _comm = MPI_COMM_SELF; \
260 else if ((scope) == GLOBAL) _comm = MPI_COMM_WORLD; \
262 fprintf(stderr, "LOG_ALLOW_SYNC ERROR: invalid scope (%d) at %s:%d\n", \
263 (scope), __FILE__, __LINE__); \
264 MPI_Abort(MPI_COMM_WORLD, 1); \
270 PetscBool _doPrint = \
271 is_function_allowed(__func__) && ((int)(level) <= (int)get_log_level()); \
274 PetscSynchronizedPrintf(_comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
280 PetscSynchronizedFlush(_comm, PETSC_STDOUT); \
298#define LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt, ...) \
300 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
301 if ((iterVar) % (interval) == 0) { \
302 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
303 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
304 __func__, #iterVar, (iterVar), ##__VA_ARGS__); \
335#define LOG_LOOP_ALLOW_EXACT(scope, level, var, val, fmt, ...) \
338 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
340 if ((var) == (val)) { \
341 MPI_Comm comm = ((scope) == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
343 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
344 __func__, #var, (var), ##__VA_ARGS__); \
364#define LOG_ARRAY_ELEMENT_ALLOW(scope,level, arr, length, idx, fmt) \
366 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
367 if ((idx) >= 0 && (idx) < (length)) { \
368 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
369 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", \
370 __func__, (idx), (arr)[idx]); \
388#define LOG_ARRAY_SUBRANGE_ALLOW(scope,level, arr, length, start, end, fmt) \
390 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
391 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
392 PetscInt _start = (start) < 0 ? 0 : (start); \
393 PetscInt _end = (end) >= (length) ? (length) - 1 : (end); \
394 for (PetscInt i = _start; i <= _end; i++) { \
395 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", __func__, i, (arr)[i]); \
718PetscErrorCode
DualKSPMonitor(KSP ksp, PetscInt it, PetscReal rnorm,
void *ctx);
794void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime);
885#define PROFILE_FUNCTION_BEGIN \
886 _ProfilingStart(__FUNCT__)
894#define PROFILE_FUNCTION_END \
895 _ProfilingEnd(__FUNCT__)
1040 const char *header, FILE **file);
FieldId
Compile-time identity for a catalogued Eulerian field.
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.
const char * LESTestFilterKernelToString(LESTestFilterKernel kernel)
Returns the user-facing name of an LES test-filter kernel.
void set_allowed_functions(const char **functionList, int count)
Sets the global list of function names that are allowed to log.
PetscErrorCode LOG_PARTICLE_METRICS(UserCtx *user, const char *stageName)
Logs particle swarm metrics, adapting its behavior based on a boolean flag in SimCtx.
PetscBool ShouldEmitPeriodicStatisticsConsoleSnapshot(const struct SimCtx *simCtx, PetscInt completed_step)
Reports whether a completed step falls on the console snapshot cadence.
const char * BCHandlerTypeToString(BCHandlerType handler_type)
Converts a BCHandlerType enum to its string representation.
PetscBool is_function_allowed(const char *functionName)
Checks if a given function is in the allow-list.
PetscErrorCode DualMonitorDestroy(void **ctx)
Destroys the DualMonitorCtx.
PetscBool IsStatisticsConsoleSnapshotEnabled(const struct SimCtx *simCtx)
Reports whether the periodic statistics console snapshot is enabled.
PetscErrorCode LOG_INTERPOLATION_ERROR(UserCtx *user)
Logs the interpolation error between the analytical and computed solutions.
PetscBool ShouldEmitPeriodicParticleConsoleSnapshot(const SimCtx *simCtx, PetscInt completed_step)
Returns whether a particle console snapshot should be emitted for the.
const char * BCFaceToString(BCFace face)
Returns the canonical log token for a boundary-face enum value.
PetscErrorCode FreeAllowedFunctions(char **funcs, PetscInt n)
Free an array previously returned by LoadAllowedFunctionsFromFile().
PetscBool IsParticleConsoleSnapshotEnabled(const SimCtx *simCtx)
Returns whether periodic particle console snapshots are enabled.
PetscErrorCode print_log_level(void)
Prints the current logging level to the console.
PetscErrorCode EmitParticleConsoleSnapshot(UserCtx *user, SimCtx *simCtx, PetscInt step)
Emits one particle console snapshot into the main solver log.
PetscErrorCode ProfilingFinalize(SimCtx *simCtx)
the profiling excercise and build a profiling summary which is then printed to a log file.
PetscErrorCode LoadAllowedFunctionsFromFile(const char filename[], char ***funcsOut, PetscInt *nOut)
Load function names from a text file.
PetscErrorCode EmitStatisticsConsoleSnapshot(UserCtx *user, const struct SimCtx *simCtx, PetscInt step)
Emits one console snapshot of window progress.
void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime)
Prints a progress bar to the console.
const char * WallFunctionModelToString(WallFunctionModel model)
Returns the user-facing name of a wall-function model.
PetscErrorCode RuntimeMemoryLogSample(SimCtx *simCtx, PetscInt step, const char *event, const char *reason)
Append a reduced runtime memory sample to the configured memory log.
LogLevel get_log_level()
Retrieves the current logging level from the environment variable LOG_LEVEL.
PetscErrorCode ProfilingLogTimestepSummary(SimCtx *simCtx, PetscInt step)
Logs the performance summary for the current timestep and resets timers.
const char * LESFilterWidthModelToString(LESFilterWidthModel model)
Returns the user-facing name of an LES grid-filter-width model.
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.
void _ProfilingEnd(const char *func_name)
Internal profiling hook invoked by PROFILE_FUNCTION_END.
const char * BCTypeToString(BCType type)
Returns the canonical log token for a boundary mathematical type.
PetscErrorCode CalculateAdvancedParticleMetrics(UserCtx *user)
Computes advanced particle statistics and stores them in SimCtx.
const char * ParticleLocationStatusToString(ParticleLocationStatus level)
A function that outputs the name of the current level in the ParticleLocation enum.
PetscErrorCode LOG_SCATTER_METRICS(UserCtx *user)
Logs particle-to-grid scatter verification metrics for the prescribed scalar truth path.
PetscErrorCode LOG_SOLUTION_CONVERGENCE(SimCtx *simCtx)
Logs physical solution-convergence metrics once per completed timestep.
const char * FlowDirectionToString(FlowDirection fd)
Convert a FlowDirection enum value to its YAML token string.
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 LOG_CONTINUITY_METRICS(UserCtx *user)
Logs continuity metrics for a single block to a file.
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.
const char * LESAveragingModeToString(LESAveragingMode mode)
Returns the user-facing name of an LES coefficient-averaging mode.
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 gri...
PetscErrorCode LOG_SEARCH_METRICS(UserCtx *user)
Writes compact runtime search metrics to CSV and optionally to console.
const char * InitialConditionModeToString(InitialConditionMode mode)
Convert an initial-condition mode to a string representation.
PetscErrorCode ProfilingInitialize(SimCtx *simCtx)
Initializes the custom profiling system using configuration from SimCtx.
LogLevel
Enumeration of logging levels.
@ LOG_ERROR
Critical errors that may halt the program.
@ LOG_TRACE
Very fine-grained tracing information for in-depth debugging.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
const char * LESModelToString(LESModelType LESFlag)
Returns the canonical log token for an LES model selector.
PetscErrorCode LOG_CELL_VERTICES(const Cell *cell, PetscMPIInt rank)
Prints the coordinates of a cell's vertices.
PetscErrorCode ProfilingResetTimestepCounters(void)
Resets per-timestep profiling counters for the next solver step.
PetscErrorCode ResetSearchMetrics(SimCtx *simCtx)
Resets the aggregate per-timestep search instrumentation counters.
const char * LESClipModeToString(LESClipMode mode)
Returns the user-facing name of an LES coefficient-limiting mode.
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Returns the canonical log token for a momentum-solver selector.
PetscErrorCode PicurvOpenDiagnosticsCsv(const SimCtx *simCtx, const char *filename, const char *header, FILE **file)
Opens a per-run diagnostics CSV in the run's analysis directory for appending.
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Returns the canonical log token for a particle-initialization mode.
void _ProfilingStart(const char *func_name)
Internal profiling hook invoked by PROFILE_FUNCTION_BEGIN.
Context for a dual-purpose KSP monitor.
Window lifecycle, scheduling, and weighting for the field-statistics pipeline.
Main header file for a complex fluid dynamics solver.
LESModelType
Identifies the subgrid-scale closure evaluated during a timestep.
BCType
Defines the general mathematical/physical Category of a boundary.
ParticleInitializationType
Enumerator to identify the particle initialization strategy.
ParticleLocationStatus
Defines the state of a particle with respect to its location and migration status during the iterativ...
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
LESClipMode
Selects the admissible range imposed on the dynamic model coefficient.
LESTestFilterKernel
Selects the discrete test-filter kernel used by the dynamic procedure.
WallFunctionModel
Selects the wall model applied on WALL faces.
MomentumSolverType
Enumerator to identify the implemented momentum solver strategies.
LESAveragingMode
Selects the set over which the Germano contractions are averaged.
FlowDirection
Primary flow direction for streamwise IC and Poiseuille modes.
InitialConditionMode
Selects the algorithm used to populate a fresh Eulerian velocity field.
LESFilterWidthModel
Selects how a cell's grid filter width is derived from its metrics.
BCFace
Identifies the six logical faces of a structured computational block.
Defines the vertices of a single hexahedral grid cell.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.