28 PetscFunctionBeginUser;
37 ierr = VecCopy(user->
Ucont, user->
Ucont_o); CHKERRQ(ierr);
43 ierr = VecCopy(user->
Ucat, user->
Ucat_o); CHKERRQ(ierr);
44 ierr = VecCopy(user->
P, user->
P_o); CHKERRQ(ierr);
48 ierr = VecCopy(user->
Nvert, user->
Nvert_o); CHKERRQ(ierr);
59 ierr = DMGlobalToLocalBegin(user->
fda, user->
Ucont_o, INSERT_VALUES, user->
lUcont_o); CHKERRQ(ierr);
60 ierr = DMGlobalToLocalEnd(user->
fda, user->
Ucont_o, INSERT_VALUES, user->
lUcont_o); CHKERRQ(ierr);
66 ierr = DMGlobalToLocalBegin(user->
da, user->
Nvert_o, INSERT_VALUES, user->
lNvert_o); CHKERRQ(ierr);
67 ierr = DMGlobalToLocalEnd(user->
da, user->
Nvert_o, INSERT_VALUES, user->
lNvert_o); CHKERRQ(ierr);
75 PetscFunctionReturn(0);
79#define __FUNCT__ "PerformInitialSetup"
102 PetscFunctionBeginUser;
107 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
142 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
157 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
163 PetscFunctionReturn(0);
167#define __FUNCT__ "PerformLoadedParticleSetup"
186 PetscFunctionBeginUser;
191 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
206 LOG(
GLOBAL,
LOG_DEBUG,
"[T=%.4f, Step=%d] Particle field states after locating loaded particles...\n", simCtx->
ti, simCtx->
step);
220 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
232 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
238 PetscFunctionReturn(0);
242#define __FUNCT__ "FinalizeRestartState"
264 PetscFunctionBeginUser;
270 if (simCtx->
np > 0) {
276 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Particle Mode 'load': Verifying particle locations and building grid links...\n");
282 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Particle Mode 'init': Running full initial setup for new particles in restarted flow.\n");
296 PetscFunctionReturn(0);
300#define __FUNCT__ "AdvanceSimulation"
331 const PetscInt StartStep = simCtx->
StartStep;
332 const PetscInt StepsToRun = simCtx->
StepsToRun;
333 const PetscInt OutputFreq = simCtx->
OutputFreq;
334 const PetscReal dt = simCtx->
dt;
338 PetscInt removed_local_lost, removed_global_lost;
340 PetscFunctionBeginUser;
343 StepsToRun, StartStep, simCtx->
StartTime, dt);
346 for (PetscInt step = StartStep; step < StartStep + StepsToRun; step++) {
353 simCtx->
step = step + 1;
354 simCtx->
ti += simCtx->
dt;
360 if (simCtx->
np > 0) {
373 ierr =
LOG_FIELD_ANATOMY(&user[0],
"Center-Coordinates",
"PreFlowSolver"); CHKERRQ(ierr);
374 ierr =
LOG_FIELD_ANATOMY(&user[0],
"X-Face-Centers",
"PreFlowSolver"); CHKERRQ(ierr);
375 ierr =
LOG_FIELD_ANATOMY(&user[0],
"Y-Face-Centers",
"PreFlowSolver"); CHKERRQ(ierr);
376 ierr =
LOG_FIELD_ANATOMY(&user[0],
"Z-Face-Centers",
"PreFlowSolver"); CHKERRQ(ierr);
388 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Eulerian Source 'analytical'. Updating Eulerian field via the Analytical Solution Engine ...\n");
409 if (simCtx->
np > 0) {
415 if (simCtx->
les || simCtx->
rans) {
416 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
428 ierr =
LOG_FIELD_ANATOMY(&user[0],
"Diffusivity",
"PostDiffusivityUpdate"); CHKERRQ(ierr);
440 if (removed_global_lost> 0) {
475 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
482 if (OutputFreq > 0 && (step + 1) % OutputFreq == 0) {
484 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
487 if (simCtx->
np > 0) {
502 if(simCtx->
rank == 0) {
510 if (simCtx->
rank == 0 && StepsToRun > 0) {
512 PetscPrintf(PETSC_COMM_SELF,
"\n");
518 PetscFunctionReturn(0);
PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx)
Dispatches to the appropriate analytical solution function based on simulation settings.
PetscErrorCode MigrateRestartParticlesUsingCellID(UserCtx *user)
Fast-path migration for restart particles using preloaded Cell IDs.
PetscErrorCode UpdateAllParticlePositions(UserCtx *user)
Loops over all local particles in the DMSwarm, updating their positions based on velocity and the glo...
PetscErrorCode LocateAllParticlesInGrid(UserCtx *user, BoundingBox *bboxlist)
Orchestrates the complete particle location and migration process for one timestep.
PetscErrorCode ResetAllParticleStatuses(UserCtx *user)
This function is designed to be called at the end of a full timestep, after all particle-based calcul...
PetscErrorCode ReinitializeParticlesOnInletSurface(UserCtx *user, PetscReal currentTime, PetscInt step)
Re-initializes the positions of particles currently on this rank if this rank owns part of the design...
PetscErrorCode CheckAndRemoveLostParticles(UserCtx *user, PetscInt *removedCountLocal, PetscInt *removedCountGlobal)
Removes particles that have been definitively flagged as LOST by the location algorithm.
PetscErrorCode UpdateAllParticleFields(UserCtx *user)
Orchestrates the update of all physical properties for particles.
PetscErrorCode CalculateParticleCountPerCell(UserCtx *user)
Counts particles in each cell of the DMDA 'da' and stores the result in user->ParticleCount.
PetscErrorCode ScatterAllParticleFieldsToEulerFields(UserCtx *user)
Scatters a predefined set of particle fields to their corresponding Eulerian fields.
PetscErrorCode InterpolateAllFieldsToSwarm(UserCtx *user)
Interpolates all relevant fields from the DMDA to the DMSwarm.
PetscErrorCode WriteAllSwarmFields(UserCtx *user)
Writes a predefined set of PETSc Swarm fields to files.
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
PetscErrorCode WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
PetscErrorCode LOG_PARTICLE_METRICS(UserCtx *user, const char *stageName)
Logs particle swarm metrics, adapting its behavior based on a boolean flag in SimCtx.
PetscBool is_function_allowed(const char *functionName)
Checks if a given function is in the allow-list.
#define LOCAL
Logging scope definitions for controlling message output.
PetscErrorCode LOG_INTERPOLATION_ERROR(UserCtx *user)
Logs the interpolation error between the analytical and computed solutions.
#define GLOBAL
Scope for global logging across all processes.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
#define LOG(scope, level, fmt,...)
Logging macro for PETSc-based applications with scope control.
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_PARTICLE_FIELDS(UserCtx *user, PetscInt printInterval)
Prints particle fields in a table that automatically adjusts its column widths.
PetscErrorCode CalculateAdvancedParticleMetrics(UserCtx *user)
Computes advanced particle statistics and stores them in SimCtx.
@ 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.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
PetscErrorCode ProfilingLogTimestepSummary(PetscInt step)
Logs the performance summary for the current timestep and resets timers.
PetscErrorCode ComputeEulerianDiffusivityGradient(UserCtx *user)
Computes the gradient of the scalar Diffusivity field (Drift Vector).
PetscErrorCode ComputeEulerianDiffusivity(UserCtx *user)
Computes the effective diffusivity scalar field ($\Gamma_{eff}$) on the Eulerian grid.
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the coupled Euler-Lagrange simulation.
PetscErrorCode UpdateSolverHistoryVectors(UserCtx *user)
Copies the current time step's solution fields into history vectors (e.g., U(t_n) -> U_o,...
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
PetscErrorCode PerformLoadedParticleSetup(SimCtx *simCtx)
Finalizes the simulation state after particle and fluid data have been loaded from a restart.
PetscErrorCode FlowSolver(SimCtx *simCtx)
Orchestrates a single time step of the Eulerian fluid solver.
PetscBool inletFaceDefined
SimCtx * simCtx
Back-pointer to the master simulation context.
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
@ PARTICLE_INIT_SURFACE_EDGES
Deterministic placement at inlet face edges.
PetscInt particlesLostLastStep
char particleRestartMode[16]
char eulerianSource[PETSC_MAX_PATH_LEN]
ParticleInitializationType ParticleInitialization
PetscInt LoggingFrequency
Defines a 3D axis-aligned bounding box.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.