PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
#include "logging.h"
Go to the source code of this file.
Data Structures | |
struct | ProfiledFunction |
Macros | |
#define | TMP_BUF_SIZE 128 |
#define | __FUNCT__ "DualKSPMonitor" |
A custom KSP monitor that logs the true residual to a file and optionally to the console. | |
#define | __FUNCT__ "LOG_CONTINUITY_METRICS" |
A custom KSP monitor that logs the true residual to a file and optionally to the console. | |
Functions | |
LogLevel | get_log_level () |
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 the given function name 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. | |
static void | IntToStr (int value, char *buf, size_t bufsize) |
static void | Int64ToStr (PetscInt64 value, char *buf, size_t bufsize) |
static void | CellToStr (const PetscInt *cell, char *buf, size_t bufsize) |
static void | TripleRealToStr (const PetscReal *arr, char *buf, size_t bufsize) |
static PetscErrorCode | ComputeMaxColumnWidths (PetscInt nParticles, const PetscMPIInt *ranks, const PetscInt64 *pids, const PetscInt *cellIDs, const PetscReal *positions, const PetscReal *velocities, const PetscReal *weights, int *wRank, int *wPID, int *wCell, int *wPos, int *wVel, int *wWt) |
static void | BuildRowFormatString (PetscMPIInt wRank, PetscInt wPID, PetscInt wCell, PetscInt wPos, PetscInt wVel, PetscInt wWt, char *fmtStr, size_t bufSize) |
static void | BuildHeaderString (char *headerStr, size_t bufSize, PetscMPIInt wRank, PetscInt wPID, PetscInt wCell, PetscInt wPos, PetscInt wVel, PetscInt wWt) |
PetscErrorCode | LOG_PARTICLE_FIELDS (UserCtx *user, PetscInt printInterval) |
Prints particle fields in a table that automatically adjusts its column widths. | |
static void | trim (char *s) |
PetscErrorCode | LoadAllowedFunctionsFromFile (const char filename[], char ***funcsOut, PetscInt *nOut) |
Load function names from a text file. | |
PetscErrorCode | FreeAllowedFunctions (char **funcs, PetscInt n) |
Free an array previously returned by LoadAllowedFunctionsFromFile(). | |
const char * | BCFaceToString (BCFace face) |
Helper function to convert BCFace enum to a string representation. | |
const char * | BCTypeToString (BCType type) |
Helper function to convert BCType enum to a string representation. | |
const char * | BCHandlerTypeToString (BCHandlerType handler_type) |
Converts a BCHandlerType enum to its string representation. | |
PetscErrorCode | DualMonitorDestroy (void **ctx) |
Destroys the DualMonitorCtx. | |
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. | |
const char * | ParticleLocationStatusToString (ParticleLocationStatus level) |
A function that outputs the name of the current level in the ParticleLocation enum. | |
static PetscErrorCode | _FindOrCreateEntry (const char *func_name, PetscInt *idx) |
PetscErrorCode | ProfilingInitialize (SimCtx *simCtx) |
Initializes the custom profiling system using configuration from SimCtx. | |
void | _ProfilingStart (const char *func_name) |
void | _ProfilingEnd (const char *func_name) |
PetscErrorCode | ProfilingLogTimestepSummary (PetscInt step) |
Logs the performance summary for the current timestep and resets timers. | |
static int | _CompareProfiledFunctions (const void *a, const void *b) |
PetscErrorCode | ProfilingFinalize (void) |
Prints the final, cumulative performance summary and cleans up resources. | |
Variables | |
static LogLevel | current_log_level = -1 |
Static variable to cache the current logging level. | |
static char ** | gAllowedFunctions = NULL |
Global/static array of function names allowed to log. | |
static int | gNumAllowed = 0 |
Number of entries in the gAllowedFunctions array. | |
PetscLogEvent | EVENT_Individualwalkingsearch = 0 |
PetscLogEvent | EVENT_walkingsearch = 0 |
PetscLogEvent | EVENT_GlobalParticleLocation = 0 |
PetscLogEvent | EVENT_IndividualLocation = 0 |
static ProfiledFunction * | g_profiler_registry = NULL |
static PetscInt | g_profiler_count = 0 |
static PetscInt | g_profiler_capacity = 0 |
struct ProfiledFunction |
#define __FUNCT__ "DualKSPMonitor" |
A custom KSP monitor that logs the true residual to a file and optionally to the console.
Logs continuity metrics for a single block to a file.
This function replicates the behavior of KSPMonitorTrueResidualNorm by calculating the true residual norm ||b - Ax|| itself. It unconditionally logs to a file viewer and conditionally logs to the console based on a flag in the context.
ksp | The Krylov subspace context. |
it | The current iteration number. |
rnorm | The preconditioned residual norm (ignored, we compute our own). |
ctx | A pointer to the DualMonitorCtx structure. |
This function should be called for each block, once per timestep. It opens a central log file in append mode. To ensure the header is written only once, it checks if it is processing block 0 on the simulation's start step.
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. |
#define __FUNCT__ "LOG_CONTINUITY_METRICS" |
A custom KSP monitor that logs the true residual to a file and optionally to the console.
Logs continuity metrics for a single block to a file.
This function replicates the behavior of KSPMonitorTrueResidualNorm by calculating the true residual norm ||b - Ax|| itself. It unconditionally logs to a file viewer and conditionally logs to the console based on a flag in the context.
ksp | The Krylov subspace context. |
it | The current iteration number. |
rnorm | The preconditioned residual norm (ignored, we compute our own). |
ctx | A pointer to the DualMonitorCtx structure. |
This function should be called for each block, once per timestep. It opens a central log file in append mode. To ensure the header is written only once, it checks if it is processing block 0 on the simulation's start step.
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. |
LogLevel get_log_level | ( | ) |
Retrieves the current logging level from the environment variable LOG_LEVEL
.
The function checks the LOG_LEVEL
environment variable and sets the logging level accordingly. Supported levels are "DEBUG", "INFO", "WARNING", and defaults to "ERROR" if not set or unrecognized. The log level is cached after the first call to avoid repeated environment variable checks.
Definition at line 49 of file logging.c.
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.
LOG_LEVEL
environment variable. If LOG_LEVEL
is not set, it defaults to LOG_INFO
.Definition at line 86 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.
functionList | An array of function name strings (e.g., {"foo", "bar"}). |
count | The number of entries in the array. |
The existing allow-list is cleared and replaced by the new one. If you pass an empty list (count = 0), then no function will be allowed unless you change it later.
Definition at line 124 of file logging.c.
PetscBool is_function_allowed | ( | const char * | functionName | ) |
Checks if the given function name is in the allow-list.
Checks if a given function is in the allow-list.
functionName | The name of the function to check. |
If no functions are in the list, nothing is allowed by default. You can reverse this logic if you prefer to allow everything unless specified otherwise.
Definition at line 159 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.. Definition at line 189 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. Definition at line 229 of file logging.c.
|
static |
|
static |
|
static |
|
static |
|
static |
Definition at line 301 of file logging.c.
|
static |
Definition at line 365 of file logging.c.
|
static |
Definition at line 378 of file logging.c.
PetscErrorCode LOG_PARTICLE_FIELDS | ( | UserCtx * | user, |
PetscInt | printInterval | ||
) |
Prints particle fields in a table that automatically adjusts its column widths.
This function retrieves data from the particle swarm and prints a table where the width of each column is determined by the maximum width needed to display the data. Only every 'printInterval'-th particle is printed.
[in] | user | Pointer to the UserCtx structure. |
[in] | printInterval | Only every printInterval‑th particle is printed. |
Definition at line 402 of file logging.c.
|
static |
Definition at line 524 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 . |
Definition at line 568 of file logging.c.
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 . |
Definition at line 627 of file logging.c.
const char * BCFaceToString | ( | BCFace | face | ) |
Helper function to convert BCFace enum to a string representation.
[in] | face | The BCFace enum value. |
Definition at line 645 of file logging.c.
const char * BCTypeToString | ( | BCType | type | ) |
Helper function to convert BCType enum to a string representation.
[in] | type | The BCType enum value. |
Definition at line 662 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). |
Definition at line 689 of file logging.c.
PetscErrorCode DualMonitorDestroy | ( | void ** | ctx | ) |
Destroys the DualMonitorCtx.
This function is passed to KSPMonitorSet to ensure the viewer is properly destroyed and the context memory is freed when the KSP is destroyed.
Ctx | a pointer to the context pointer to be destroyed |
Definition at line 727 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.
This function unconditionally calls the standard true residual monitor to log to a file viewer provided in the context. It also checks a flag in the context and, if true, calls the monitor again to log to standard output.
ksp | The Krylov subspace context. |
it | The current iteration number. |
rnorm | The preconditioned residual norm. |
ctx | A pointer to the DualMonitorCtx structure. |
Definition at line 759 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. It opens a central log file in append mode. To ensure the header is written only once, it checks if it is processing block 0 on the simulation's start step.
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. |
Definition at line 819 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. |
Definition at line 878 of file logging.c.
|
static |
Definition at line 909 of file logging.c.
PetscErrorCode ProfilingInitialize | ( | SimCtx * | simCtx | ) |
Initializes the custom profiling system using configuration from SimCtx.
This function sets up the internal data structures for tracking function performance. It reads the list of "critical functions" from the provided SimCtx and marks them for per-step logging at LOG_INFO level.
It should be called once at the beginning of the application, after CreateSimulationContext() but before the main time loop.
simCtx | The master simulation context, which contains the list of critical function names to always log. |
Definition at line 955 of file logging.c.
void _ProfilingStart | ( | const char * | func_name | ) |
Definition at line 972 of file logging.c.
void _ProfilingEnd | ( | const char * | func_name | ) |
PetscErrorCode ProfilingLogTimestepSummary | ( | PetscInt | step | ) |
Logs the performance summary for the current timestep and resets timers.
Depending on the current log level, this function will print:
It must be called once per timestep, typically at the end of the main loop. After logging, it resets the per-step counters and timers.
step | The current simulation step number, for logging context. |
Definition at line 994 of file logging.c.
|
static |
PetscErrorCode ProfilingFinalize | ( | void | ) |
Prints the final, cumulative performance summary and cleans up resources.
This should be called once at the end of the simulation, before PetscFinalize(). It prints a table with total time, call count, and average time per call for every function that was profiled. This summary is only printed if the log level is LOG_PROFILE.
Definition at line 1046 of file logging.c.
|
static |
|
static |
|
static |
|
static |