PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Functions
simulator.c File Reference

Main driver for the unified CFD and Lagrangian particle solver. More...

#include "runloop.h"
Include dependency graph for simulator.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Entry point for the solver executable.
 

Detailed Description

Main driver for the unified CFD and Lagrangian particle solver.

This version focuses on establishing the core architecture for a particle-coupled flow simulation. It initializes the grid, solver objects, and a DMSwarm of Lagrangian particles. Hooks for the Immersed Boundary Method (IBM) are present but are currently inactive to allow for iterative development.

ARCHITECTURE:

  1. A central SimulationContext (simCtx) holds all simulation-wide configuration.
  2. CreateSimulationContext() handles all command-line parsing.
  3. The main() function provides a high-level workflow for the simulation.

Definition in file simulator.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Entry point for the solver executable.

Initializes PETSc, builds the solver runtime, executes the configured workflow, and finalizes runtime resources before exit.

Definition at line 27 of file simulator.c.

28{
29 PetscErrorCode ierr;
30 SimCtx *simCtx = NULL; // The single, top-level context object
31
32 if (PicurvHandleVersionArgument(argc, argv, "simulator")) return 0;
33 if (PicurvCheckLinkedPetscIndexWidth(argc, argv, "simulator")) return 1;
34 // === I. INITIALIZE =======================================================
35 ierr = PetscInitialize(&argc, &argv, (char *)0, "PICurv Simulator"); CHKERRQ(ierr);
36 ierr = InitializeRuntimeSignalHandlers(); CHKERRQ(ierr);
37
38 // === II. CONFIGURE =======================================================
39 // Create and populate the entire simulation configuration from command line.
40 ierr = CreateSimulationContext(argc, argv, &simCtx); CHKERRQ(ierr);
41 // == IIB. SET EXECUTION MODE (SOLVER vs POST-PROCESSOR) =====
43 // A restart check needs only the configuration and the checkpoint manifest, so it stops
44 // before any directory, grid, or field is created.
45 {
46 PetscBool restart_check = PETSC_FALSE;
47 ierr = PetscOptionsGetBool(NULL, NULL, "-restart_check_only", &restart_check, NULL); CHKERRQ(ierr);
48 if (restart_check) {
50 ierr = RestoreFieldStatisticsState(simCtx, simCtx->StartStep); CHKERRQ(ierr);
51 ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
52 return PetscFinalize();
53 }
54 }
55 // == IIC. CONFIGURE SIMULATION ENVIRONMENT & DIRECTORIES =====
56 ierr = SetupSimulationEnvironment(simCtx); CHKERRQ(ierr);
57
58 // === III. SETUP ==========================================================
59 // Build the simulation environment step-by-step.
60
61 // 1. Setup the multi-grid hierarchy, DMs, and PETSc vectors/solvers.
62 ierr = SetupGridAndSolvers(simCtx); CHKERRQ(ierr);
63
64 // 2. Setup the boundary condition handlers for the flow solver.
65 ierr = SetupBoundaryConditions(simCtx); CHKERRQ(ierr);
66
67 // 3. Setup domain decomposition info needed for particle migration.
68 ierr = SetupDomainRankInfo(simCtx); CHKERRQ(ierr);
69
70 // 4. Setup Initial State of Eulerian Fields
71 ierr = InitializeEulerianState(simCtx); CHKERRQ(ierr);
72
73 // 5. If requested, initialize the Lagrangian Particle Swarm.
74 if (ParticlesEnabled(simCtx)) {
75 ierr = InitializeParticleSwarm(simCtx); CHKERRQ(ierr);
76 }
77
78 LOG_ALLOW(GLOBAL,LOG_INFO," Setup Completed.\n");
79
80
81 /*
82 * --- IBM/FSI FEATURE HOOK (Currently Inactive) ---
83 * The logic for initializing immersed bodies would be enabled here.
84 * The `-immersed` command-line flag would control this block.
85 *
86 if (simCtx->immersed) {
87 ierr = InitializeImmersedBoundary(simCtx); CHKERRQ(ierr);
88 }
89 */
90
91 // === IV. EXECUTE =========================================================
92 // Display a summary banner and run the main time-stepping loop.
93
94 ierr = DisplayBanner(simCtx); CHKERRQ(ierr);
95
96 if (!simCtx->OnlySetup) {
97 // This function will contain the main time loop, orchestrating
98 // the flow solve and particle advection steps.
99
100 if(simCtx->StartStep == 0){
101 if(ParticlesEnabled(simCtx)){
102 ierr = PerformInitializedParticleSetup(simCtx); CHKERRQ(ierr);
103 }else{
104 ierr = WriteCheckpointBundle(simCtx, "initial"); CHKERRQ(ierr);
105 }
106 }else{
107 ierr = FinalizeRestartState(simCtx); CHKERRQ(ierr);
108 }
109
110 //********************PROFILING ROUTINES ****************************
111 // Before the first step, clear all counters accumulated during setup
112 // to ensure the Timestep 1 profile is clean.
113 ierr = ProfilingResetTimestepCounters(); CHKERRQ(ierr);
114 //*******************************************************************
115
116 if(simCtx->StepsToRun > 0){
117 ierr = AdvanceSimulation(simCtx); CHKERRQ(ierr);
118 }else{
119 LOG_ALLOW(GLOBAL,LOG_INFO,"Initial setup complete.No steps to run.Exiting!.\n");
120 }
121 }else{
122 LOG_ALLOW(GLOBAL,LOG_INFO,"SETUP ONLY MODE enabled. Skipping time loop.\n");
123 }
124
125 // == V. REPORT FIELDS ===========================
126 ierr = RuntimeMemoryLogSample(simCtx, simCtx->step, "Final", "Complete"); CHKERRQ(ierr);
127
128 // === V. FINALIZE =========================================================
129 // Cleanly destroy all objects and free all memory.
130
131 ierr = ProfilingFinalize(simCtx); CHKERRQ(ierr);
132 ierr = FlowSolver_Destroy(simCtx); CHKERRQ(ierr);
133 ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
134 ierr = PetscFinalize();
135
136 return ierr;
137}
PetscErrorCode InitializeParticleSwarm(SimCtx *simCtx)
High-level particle initialization orchestrator for a simulation run.
PetscErrorCode InitializeEulerianState(SimCtx *simCtx)
High-level orchestrator to set the complete initial state of the Eulerian solver.
PetscErrorCode RestoreFieldStatisticsState(SimCtx *simCtx, PetscInt ti)
Restores field-statistics window state and accumulators from a checkpoint.
Definition io.c:1604
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2635
PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason)
Write and atomically publish one complete checkpoint bundle.
Definition io.c:2501
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:46
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
Definition logging.h:214
PetscErrorCode ProfilingFinalize(SimCtx *simCtx)
Writes the end-of-run profiling summary across all ranks; collective on PETSC_COMM_WORLD.
Definition logging.c:2380
PetscErrorCode RuntimeMemoryLogSample(SimCtx *simCtx, PetscInt step, const char *event, const char *reason)
Append a reduced runtime memory sample to the configured memory log.
Definition logging.c:2170
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:31
PetscErrorCode ProfilingResetTimestepCounters(void)
Starts a new per-step profiling interval.
Definition logging.c:2087
PetscErrorCode InitializeRuntimeSignalHandlers(void)
Installs lightweight signal handlers for graceful shutdown requests.
Definition runloop.c:165
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition runloop.c:603
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
Definition runloop.c:562
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition runloop.c:426
int PicurvCheckLinkedPetscIndexWidth(int argc, char **argv, const char *executable_name)
Refuse to start when the loaded libpetsc's PetscInt width differs from this build's.
Definition setup.c:79
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:3242
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:2066
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:1728
int PicurvHandleVersionArgument(int argc, char **argv, const char *executable_name)
Print the shared native build identity when a version flag is present.
Definition setup.c:119
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:453
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:2755
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:4137
PetscErrorCode FlowSolver_Destroy(SimCtx *simCtx)
Releases the solver objects FlowSolver() keeps for the run.
Definition solvers.c:202
PetscInt StepsToRun
Definition variables.h:927
static PetscBool ParticlesEnabled(const SimCtx *simCtx)
Whether the run carries particles: a seeded or restored population, or inlets that inject them.
Definition variables.h:1143
PetscInt StartStep
Definition variables.h:926
PetscBool OnlySetup
Definition variables.h:934
PetscInt step
Definition variables.h:924
@ EXEC_MODE_SOLVER
Definition variables.h:888
@ EXEC_MODE_RESTART_CHECK
Definition variables.h:890
ExecutionMode exec_mode
Definition variables.h:937
The master context for the entire simulation.
Definition variables.h:916
Here is the call graph for this function: