85#define LOG(scope, level, fmt, ...) \
88 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
90 if ((int)(level) <= (int)get_log_level()) { \
92 PetscPrintf(comm, fmt, ##__VA_ARGS__); \
116#define LOG_DEFAULT(level, fmt, ...) \
119 MPI_Comm comm = MPI_COMM_WORLD; \
121 if ((int)(level) <= (int)get_log_level()) { \
123 PetscPrintf(comm, fmt, ##__VA_ARGS__); \
146#define LOG_SYNC(scope, level, fmt, ...) \
149 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
151 if ((int)(level) <= (int)get_log_level()) { \
153 PetscSynchronizedPrintf(comm, fmt, ##__VA_ARGS__); \
155 PetscSynchronizedFlush(comm, PETSC_STDOUT); \
179#define LOG_SYNC_DEFAULT(level, fmt, ...) \
181 if ((int)(level) <= (int)get_log_level()) { \
182 PetscSynchronizedPrintf(MPI_COMM_WORLD, fmt, ##__VA_ARGS__); \
183 PetscSynchronizedFlush(MPI_COMM_WORLD, PETSC_STDOUT); \
201#define LOG_ALLOW(scope, level, fmt, ...) \
203 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
204 if ((int)(level) <= (int)get_log_level() && is_function_allowed(__func__)) { \
205 PetscPrintf(comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
268#define LOG_ALLOW_SYNC(scope, level, fmt, ...) \
274 if ((scope) == LOCAL) _comm = MPI_COMM_SELF; \
275 else if ((scope) == GLOBAL) _comm = MPI_COMM_WORLD; \
277 fprintf(stderr, "LOG_ALLOW_SYNC ERROR: invalid scope (%d) at %s:%d\n", \
278 (scope), __FILE__, __LINE__); \
279 MPI_Abort(MPI_COMM_WORLD, 1); \
285 PetscBool _doPrint = \
286 is_function_allowed(__func__) && ((int)(level) <= (int)get_log_level()); \
289 PetscSynchronizedPrintf(_comm, "[%s] " fmt, __func__, ##__VA_ARGS__); \
295 PetscSynchronizedFlush(_comm, PETSC_STDOUT); \
313#define LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt, ...) \
315 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
316 if ((iterVar) % (interval) == 0) { \
317 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
318 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
319 __func__, #iterVar, (iterVar), ##__VA_ARGS__); \
349#define LOG_LOOP_ALLOW_EXACT(scope, level, var, val, fmt, ...) \
352 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
354 if ((var) == (val)) { \
355 MPI_Comm comm = ((scope) == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
357 PetscPrintf(comm, "[%s] [%s=%d] " fmt, \
358 __func__, #var, (var), ##__VA_ARGS__); \
378#define LOG_ARRAY_ELEMENT_ALLOW(scope,level, arr, length, idx, fmt) \
380 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
381 if ((idx) >= 0 && (idx) < (length)) { \
382 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
383 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", \
384 __func__, (idx), (arr)[idx]); \
402#define LOG_ARRAY_SUBRANGE_ALLOW(scope,level, arr, length, start, end, fmt) \
404 if (is_function_allowed(__func__) && (int)(level) <= (int)get_log_level()) { \
405 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
406 PetscInt _start = (start) < 0 ? 0 : (start); \
407 PetscInt _end = (end) >= (length) ? (length) - 1 : (end); \
408 for (PetscInt i = _start; i <= _end; i++) { \
409 PetscPrintf(comm, "[%s] arr[%d] = " fmt "\n", __func__, i, (arr)[i]); \
414#define LOG_PROFILE_MSG(scope, fmt, ...) \
416 if ((int)(LOG_PROFILE) <= (int)get_log_level()) { \
417 MPI_Comm comm = (scope == LOCAL) ? MPI_COMM_SELF : MPI_COMM_WORLD; \
418 PetscPrintf(comm, "[PROFILE] " fmt, ##__VA_ARGS__); \
624PetscErrorCode
DualKSPMonitor(KSP ksp, PetscInt it, PetscReal rnorm,
void *ctx);
674void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime);
731#define PROFILE_FUNCTION_BEGIN \
732 _ProfilingStart(__FUNCT__)
740#define PROFILE_FUNCTION_END \
741 _ProfilingEnd(__FUNCT__)
void set_allowed_functions(const char **functionList, int count)
Sets the global list of function names that are allowed to log.
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.
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.
const char * ParticleInitializationToString(PetscInt ParticleInitialization)
Helper function to convert ParticleInitialization to a string representation.
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.
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.
PetscErrorCode LOG_CELL_VERTICES(const Cell *cell, PetscMPIInt rank)
Prints the coordinates of a cell's vertices.
const char * LESFlagToString(PetscInt LESFlag)
Helper function to convert LES Flag to a string representation.
PetscErrorCode ProfilingResetTimestepCounters(void)
PetscErrorCode ProfilingLogTimestepSummary(PetscInt step)
Logs the performance summary for the current timestep and resets timers.
void _ProfilingStart(const char *func_name)
Context for a dual-purpose KSP monitor.
Main header file for a complex fluid dynamics solver.
BCType
Defines the general mathematical/physical category of a boundary.
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.
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.