83#define LOG(scope, level, fmt, ...) \
86 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
88 if ((int)(level) <= (int)get_log_level()) { \
90 PetscPrintf(comm, fmt, ##__VA_ARGS__); \
114#define LOG_DEFAULT(level, fmt, ...) \
117 MPI_Comm comm = MPI_COMM_WORLD; \
119 if ((int)(level) <= (int)get_log_level()) { \
121 PetscPrintf(comm, fmt, ##__VA_ARGS__); \
144#define LOG_SYNC(scope, level, fmt, ...) \
147 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
149 if ((int)(level) <= (int)get_log_level()) { \
151 PetscSynchronizedPrintf(comm, fmt, ##__VA_ARGS__); \
153 PetscSynchronizedFlush(comm, PETSC_STDOUT); \
177#define LOG_SYNC_DEFAULT(level, fmt, ...) \
179 if ((int)(level) <= (int)get_log_level()) { \
180 PetscSynchronizedPrintf(MPI_COMM_WORLD, fmt, ##__VA_ARGS__); \
181 PetscSynchronizedFlush(MPI_COMM_WORLD, PETSC_STDOUT); \
199#define LOG_ALLOW(scope, level, fmt, ...) \
201 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
202 if ((int)(level) <= (int)get_log_level() && is_function_allowed(__func__)) { \
203 PetscPrintf(comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
252#define LOG_ALLOW_SYNC(scope, level, fmt, ...) \
258 if ((scope) == LOCAL) _comm = MPI_COMM_SELF; \
259 else if ((scope) == GLOBAL) _comm = MPI_COMM_WORLD; \
261 fprintf(stderr, "LOG_ALLOW_SYNC ERROR: invalid scope (%d) at %s:%d\n", \
262 (scope), __FILE__, __LINE__); \
263 MPI_Abort(MPI_COMM_WORLD, 1); \
269 PetscBool _doPrint = \
270 is_function_allowed(__func__) && ((int)(level) <= (int)get_log_level()); \
273 PetscSynchronizedPrintf(_comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
279 PetscSynchronizedFlush(_comm, PETSC_STDOUT); \
297#define LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt, ...) \
299 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
300 if ((iterVar) % (interval) == 0) { \
301 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
302 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
303 __func__, #iterVar, (iterVar), ##__VA_ARGS__); \
334#define LOG_LOOP_ALLOW_EXACT(scope, level, var, val, fmt, ...) \
337 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
339 if ((var) == (val)) { \
340 MPI_Comm comm = ((scope) == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
342 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
343 __func__, #var, (var), ##__VA_ARGS__); \
363#define LOG_ARRAY_ELEMENT_ALLOW(scope,level, arr, length, idx, fmt) \
365 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
366 if ((idx) >= 0 && (idx) < (length)) { \
367 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
368 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", \
369 __func__, (idx), (arr)[idx]); \
387#define LOG_ARRAY_SUBRANGE_ALLOW(scope,level, arr, length, start, end, fmt) \
389 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
390 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
391 PetscInt _start = (start) < 0 ? 0 : (start); \
392 PetscInt _end = (end) >= (length) ? (length) - 1 : (end); \
393 for (PetscInt i = _start; i <= _end; i++) { \
394 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", __func__, i, (arr)[i]); \
644PetscErrorCode
DualKSPMonitor(KSP ksp, PetscInt it, PetscReal rnorm,
void *ctx);
694void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime);
770#define PROFILE_FUNCTION_BEGIN \
771 _ProfilingStart(__FUNCT__)
779#define PROFILE_FUNCTION_END \
780 _ProfilingEnd(__FUNCT__)
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.
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.
const char * FieldInitializationToString(PetscInt FieldInitialization)
Helper function to convert FieldInitialization to a string representation.
PetscErrorCode DualMonitorDestroy(void **ctx)
Destroys the DualMonitorCtx.
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)
Helper function to convert BCFace enum to a string representation.
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 LOG_FIELD_MIN_MAX(UserCtx *user, const char *fieldName)
Computes and logs the local and global min/max values of a 3-component vector field.
void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime)
Prints a progress bar to the console.
PetscErrorCode LOG_FIELD_ANATOMY(UserCtx *user, const char *field_name, const char *stage_name)
Logs the anatomy of a specified field at key boundary locations, respecting the solver's specific gri...
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.
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)
Helper function to convert BCType enum to a string representation.
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 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_SEARCH_METRICS(UserCtx *user)
Writes compact runtime search metrics to CSV and optionally to console.
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)
Helper function to convert LES Flag to a string representation.
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 * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Helper function to convert Momentum Solver flag to a string representation.
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Helper function to convert ParticleInitialization to a string representation.
void _ProfilingStart(const char *func_name)
Internal profiling hook invoked by PROFILE_FUNCTION_BEGIN.
Context for a dual-purpose KSP monitor.
Main header file for a complex fluid dynamics solver.
LESModelType
Identifies the six logical faces of a structured computational block.
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.
MomentumSolverType
Enumerator to identify the implemented momentum solver strategies.
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.