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__); \
267#define LOG_ALLOW_SYNC(scope, level, fmt, ...) \
273 if ((scope) == LOCAL) _comm = MPI_COMM_SELF; \
274 else if ((scope) == GLOBAL) _comm = MPI_COMM_WORLD; \
276 fprintf(stderr, "LOG_ALLOW_SYNC ERROR: invalid scope (%d) at %s:%d\n", \
277 (scope), __FILE__, __LINE__); \
278 MPI_Abort(MPI_COMM_WORLD, 1); \
284 PetscBool _doPrint = \
285 is_function_allowed(__func__) && ((int)(level) <= (int)get_log_level()); \
288 PetscSynchronizedPrintf(_comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
294 PetscSynchronizedFlush(_comm, PETSC_STDOUT); \
312#define LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt, ...) \
314 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
315 if ((iterVar) % (interval) == 0) { \
316 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
317 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
318 __func__, #iterVar, (iterVar), ##__VA_ARGS__); \
348#define LOG_LOOP_ALLOW_EXACT(scope, level, var, val, fmt, ...) \
351 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
353 if ((var) == (val)) { \
354 MPI_Comm comm = ((scope) == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
356 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
357 __func__, #var, (var), ##__VA_ARGS__); \
377#define LOG_ARRAY_ELEMENT_ALLOW(scope,level, arr, length, idx, fmt) \
379 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
380 if ((idx) >= 0 && (idx) < (length)) { \
381 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
382 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", \
383 __func__, (idx), (arr)[idx]); \
401#define LOG_ARRAY_SUBRANGE_ALLOW(scope,level, arr, length, start, end, fmt) \
403 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
404 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
405 PetscInt _start = (start) < 0 ? 0 : (start); \
406 PetscInt _end = (end) >= (length) ? (length) - 1 : (end); \
407 for (PetscInt i = _start; i <= _end; i++) { \
408 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", __func__, i, (arr)[i]); \
413#define LOG_PROFILE_MSG(scope, fmt, ...) \
415 if ((int)(LOG_PROFILE) <= (int)get_log_level()) { \
416 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
417 PetscPrintf(comm, "[PROFILE] " fmt, ##__VA_ARGS__); \
630PetscErrorCode
DualKSPMonitor(KSP ksp, PetscInt it, PetscReal rnorm,
void *ctx);
680void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime);
737#define PROFILE_FUNCTION_BEGIN \
738 _ProfilingStart(__FUNCT__)
746#define PROFILE_FUNCTION_END \
747 _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.
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().
PetscErrorCode print_log_level(void)
Prints the current logging level to the console.
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 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)
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 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 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_PROFILE
Exclusive log level for performance timing and profiling.
@ 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)
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Helper function to convert Momentum Solver flag to a string representation.
PetscErrorCode ProfilingLogTimestepSummary(PetscInt step)
Logs the performance summary for the current timestep and resets timers.
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Helper function to convert ParticleInitialization to a string representation.
void _ProfilingStart(const char *func_name)
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 various momentumsolvers.
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.