PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Macros | 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.

Macros

#define __FUNCT__   "main"
 

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.

Macro Definition Documentation

◆ __FUNCT__

#define __FUNCT__   "main"

Definition at line 23 of 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 29 of file simulator.c.

30{
31 PetscErrorCode ierr;
32 SimCtx *simCtx = NULL; // The single, top-level context object
33
34 if (PicurvHandleVersionArgument(argc, argv, "simulator")) return 0;
35 // === I. INITIALIZE =======================================================
36 ierr = PetscInitialize(&argc, &argv, (char *)0, "PICurv Simulator"); CHKERRQ(ierr);
37 ierr = InitializeRuntimeSignalHandlers(); CHKERRQ(ierr);
38
39 // === II. CONFIGURE =======================================================
40 // Create and populate the entire simulation configuration from command line.
41 ierr = CreateSimulationContext(argc, argv, &simCtx); CHKERRQ(ierr);
42 // == IIB. SET EXECUTION MODE (SOLVER vs POST-PROCESSOR) =====
44 // == IIC. CONFIGURE SIMULATION ENVIRONMENT & DIRECTORIES =====
45 ierr = SetupSimulationEnvironment(simCtx); CHKERRQ(ierr);
46
47 // === III. SETUP ==========================================================
48 // Build the simulation environment step-by-step.
49
50 // 1. Setup the multi-grid hierarchy, DMs, and PETSc vectors/solvers.
51 ierr = SetupGridAndSolvers(simCtx); CHKERRQ(ierr);
52
53 // 2. Setup the boundary condition handlers for the flow solver.
54 ierr = SetupBoundaryConditions(simCtx); CHKERRQ(ierr);
55
56 // 3. Setup domain decomposition info needed for particle migration.
57 ierr = SetupDomainRankInfo(simCtx); CHKERRQ(ierr);
58
59 // 4. Setup Initial State of Eulerian Fields
60 ierr = InitializeEulerianState(simCtx); CHKERRQ(ierr);
61
62 // 5. If requested, initialize the Lagrangian Particle Swarm.
63 if (simCtx->np > 0) {
64 ierr = InitializeParticleSwarm(simCtx); CHKERRQ(ierr);
65 }
66
67 LOG_ALLOW(GLOBAL,LOG_INFO," Setup Completed.\n");
68
69
70 /*
71 * --- IBM/FSI FEATURE HOOK (Currently Inactive) ---
72 * The logic for initializing immersed bodies would be enabled here.
73 * The `-immersed` command-line flag would control this block.
74 *
75 if (simCtx->immersed) {
76 ierr = InitializeImmersedBoundary(simCtx); CHKERRQ(ierr);
77 }
78 */
79
80 // === IV. EXECUTE =========================================================
81 // Display a summary banner and run the main time-stepping loop.
82
83 ierr = DisplayBanner(simCtx); CHKERRQ(ierr);
84
85 if (!simCtx->OnlySetup) {
86 // This function will contain the main time loop, orchestrating
87 // the flow solve and particle advection steps.
88
89 if(simCtx->StartStep == 0){
90 if(simCtx->np>0){
91 ierr = PerformInitializedParticleSetup(simCtx); CHKERRQ(ierr);
92 }else{
93 ierr = WriteCheckpointBundle(simCtx, "initial"); CHKERRQ(ierr);
94 }
95 }else{
96 ierr = FinalizeRestartState(simCtx); CHKERRQ(ierr);
97 }
98
99 //********************PROFILING ROUTINES ****************************
100 // Before the first step, clear all counters accumulated during setup
101 // to ensure the Timestep 1 profile is clean.
102 ierr = ProfilingResetTimestepCounters(); CHKERRQ(ierr);
103 //*******************************************************************
104
105 if(simCtx->StepsToRun > 0){
106 ierr = AdvanceSimulation(simCtx); CHKERRQ(ierr);
107 }else{
108 LOG_ALLOW(GLOBAL,LOG_INFO,"Initial setup complete.No steps to run.Exiting!.\n");
109 }
110 }else{
111 LOG_ALLOW(GLOBAL,LOG_INFO,"SETUP ONLY MODE enabled. Skipping time loop.\n");
112 }
113
114 // == V. REPORT FIELDS ===========================
115 ierr = RuntimeMemoryLogSample(simCtx, simCtx->step, "Final", "Complete"); CHKERRQ(ierr);
116
117 // === V. FINALIZE =========================================================
118 // Cleanly destroy all objects and free all memory.
119
120 ierr = ProfilingFinalize(simCtx); CHKERRQ(ierr);
121 ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
122 ierr = PetscFinalize();
123
124 return ierr;
125}
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 DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2800
PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason)
Write and atomically publish one complete checkpoint bundle.
Definition io.c:2554
#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:200
PetscErrorCode ProfilingFinalize(SimCtx *simCtx)
the profiling excercise and build a profiling summary which is then printed to a log file.
Definition logging.c:2305
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:2195
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:31
PetscErrorCode ProfilingResetTimestepCounters(void)
Resets per-timestep profiling counters for the next solver step.
Definition logging.c:2083
PetscErrorCode InitializeRuntimeSignalHandlers(void)
Installs lightweight signal handlers for graceful shutdown requests.
Definition runloop.c:126
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition runloop.c:552
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
Definition runloop.c:511
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition runloop.c:364
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:3227
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:2001
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:1685
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:47
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:371
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:2678
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:4368
PetscInt StepsToRun
Definition variables.h:870
PetscInt np
Definition variables.h:990
PetscInt StartStep
Definition variables.h:869
PetscBool OnlySetup
Definition variables.h:875
PetscInt step
Definition variables.h:867
@ EXEC_MODE_SOLVER
Definition variables.h:832
ExecutionMode exec_mode
Definition variables.h:878
The master context for the entire simulation.
Definition variables.h:859
Here is the call graph for this function: