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 // Write the initial Eulerian fields.
93 UserCtx *user = simCtx->usermg.mgctx[simCtx->usermg.mglevels-1].user;
94 for(PetscInt bi = 0; bi < simCtx->block_number; bi++){
95 ierr = WriteSimulationFields(&user[bi]);
96 }
97 }
98 }else{
99 ierr = FinalizeRestartState(simCtx); CHKERRQ(ierr);
100 }
101
102 //********************PROFILING ROUTINES ****************************
103 // Before the first step, clear all counters accumulated during setup
104 // to ensure the Timestep 1 profile is clean.
105 ierr = ProfilingResetTimestepCounters(); CHKERRQ(ierr);
106 //*******************************************************************
107
108 if(simCtx->StepsToRun > 0){
109 ierr = AdvanceSimulation(simCtx); CHKERRQ(ierr);
110 }else{
111 LOG_ALLOW(GLOBAL,LOG_INFO,"Initial setup complete.No steps to run.Exiting!.\n");
112 }
113 }else{
114 LOG_ALLOW(GLOBAL,LOG_INFO,"SETUP ONLY MODE enabled. Skipping time loop.\n");
115 }
116
117 // == V. REPORT FIELDS ===========================
118
119 // === V. FINALIZE =========================================================
120 // Cleanly destroy all objects and free all memory.
121
122 ierr = ProfilingFinalize(simCtx); CHKERRQ(ierr);
123 ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
124 ierr = PetscFinalize();
125
126 return ierr;
127}
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 WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
Definition io.c:1568
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2031
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:45
#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:199
PetscErrorCode ProfilingFinalize(SimCtx *simCtx)
the profiling excercise and build a profiling summary which is then printed to a log file.
Definition logging.c:1214
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:30
PetscErrorCode ProfilingResetTimestepCounters(void)
Resets per-timestep profiling counters for the next solver step.
Definition logging.c:1104
PetscErrorCode InitializeRuntimeSignalHandlers(void)
Installs lightweight signal handlers for graceful shutdown requests.
Definition runloop.c:123
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition runloop.c:572
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
Definition runloop.c:526
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition runloop.c:380
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:2174
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:1132
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:813
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:50
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:1633
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:3188
UserCtx * user
Definition variables.h:528
PetscInt block_number
Definition variables.h:712
UserMG usermg
Definition variables.h:764
PetscInt StepsToRun
Definition variables.h:654
PetscInt np
Definition variables.h:739
PetscInt StartStep
Definition variables.h:653
PetscBool OnlySetup
Definition variables.h:659
PetscInt mglevels
Definition variables.h:535
@ EXEC_MODE_SOLVER
Definition variables.h:616
MGCtx * mgctx
Definition variables.h:538
ExecutionMode exec_mode
Definition variables.h:662
The master context for the entire simulation.
Definition variables.h:643
User-defined context containing data specific to a single computational grid level.
Definition variables.h:811
Here is the call graph for this function: