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 // === 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 // == IIC. CONFIGURE SIMULATION ENVIRONMENT & DIRECTORIES =====
44 ierr = SetupSimulationEnvironment(simCtx); CHKERRQ(ierr);
45
46 // === III. SETUP ==========================================================
47 // Build the simulation environment step-by-step.
48
49 // 1. Setup the multi-grid hierarchy, DMs, and PETSc vectors/solvers.
50 ierr = SetupGridAndSolvers(simCtx); CHKERRQ(ierr);
51
52 // 2. Setup the boundary condition handlers for the flow solver.
53 ierr = SetupBoundaryConditions(simCtx); CHKERRQ(ierr);
54
55 // 3. Setup domain decomposition info needed for particle migration.
56 ierr = SetupDomainRankInfo(simCtx); CHKERRQ(ierr);
57
58 // 4. Setup Initial State of Eulerian Fields
59 ierr = InitializeEulerianState(simCtx); CHKERRQ(ierr);
60
61 // 5. If requested, initialize the Lagrangian Particle Swarm.
62 if (simCtx->np > 0) {
63 ierr = InitializeParticleSwarm(simCtx); CHKERRQ(ierr);
64 }
65
66 LOG_ALLOW(GLOBAL,LOG_INFO," Setup Completed.\n");
67
68
69 /*
70 * --- IBM/FSI FEATURE HOOK (Currently Inactive) ---
71 * The logic for initializing immersed bodies would be enabled here.
72 * The `-immersed` command-line flag would control this block.
73 *
74 if (simCtx->immersed) {
75 ierr = InitializeImmersedBoundary(simCtx); CHKERRQ(ierr);
76 }
77 */
78
79 // === IV. EXECUTE =========================================================
80 // Display a summary banner and run the main time-stepping loop.
81
82 ierr = DisplayBanner(simCtx); CHKERRQ(ierr);
83
84 if (!simCtx->OnlySetup) {
85 // This function will contain the main time loop, orchestrating
86 // the flow solve and particle advection steps.
87
88 if(simCtx->StartStep == 0){
89 if(simCtx->np>0){
90 ierr = PerformInitializedParticleSetup(simCtx); CHKERRQ(ierr);
91 }else{
92 ierr = WriteCheckpointBundle(simCtx, "initial"); CHKERRQ(ierr);
93 }
94 }else{
95 ierr = FinalizeRestartState(simCtx); CHKERRQ(ierr);
96 }
97
98 //********************PROFILING ROUTINES ****************************
99 // Before the first step, clear all counters accumulated during setup
100 // to ensure the Timestep 1 profile is clean.
101 ierr = ProfilingResetTimestepCounters(); CHKERRQ(ierr);
102 //*******************************************************************
103
104 if(simCtx->StepsToRun > 0){
105 ierr = AdvanceSimulation(simCtx); CHKERRQ(ierr);
106 }else{
107 LOG_ALLOW(GLOBAL,LOG_INFO,"Initial setup complete.No steps to run.Exiting!.\n");
108 }
109 }else{
110 LOG_ALLOW(GLOBAL,LOG_INFO,"SETUP ONLY MODE enabled. Skipping time loop.\n");
111 }
112
113 // == V. REPORT FIELDS ===========================
114 ierr = RuntimeMemoryLogSample(simCtx, simCtx->step, "Final", "Complete"); CHKERRQ(ierr);
115
116 // === V. FINALIZE =========================================================
117 // Cleanly destroy all objects and free all memory.
118
119 ierr = ProfilingFinalize(simCtx); CHKERRQ(ierr);
120 ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
121 ierr = PetscFinalize();
122
123 return ierr;
124}
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:2776
PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason)
Write and atomically publish one complete checkpoint bundle.
Definition io.c:2530
#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:2196
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:2086
@ 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:1988
PetscErrorCode InitializeRuntimeSignalHandlers(void)
Installs lightweight signal handlers for graceful shutdown requests.
Definition runloop.c:118
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition runloop.c:544
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
Definition runloop.c:503
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition runloop.c:365
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:2576
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:1364
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:1063
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:160
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:2027
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:3721
PetscInt StepsToRun
Definition variables.h:706
PetscInt np
Definition variables.h:827
PetscInt StartStep
Definition variables.h:705
PetscBool OnlySetup
Definition variables.h:711
PetscInt step
Definition variables.h:703
@ EXEC_MODE_SOLVER
Definition variables.h:668
ExecutionMode exec_mode
Definition variables.h:714
The master context for the entire simulation.
Definition variables.h:695
Here is the call graph for this function: