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)
 

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 
)

Definition at line 24 of file simulator.c.

25{
26 PetscErrorCode ierr;
27 SimCtx *simCtx = NULL; // The single, top-level context object
28
29 // === I. INITIALIZE =======================================================
30 ierr = PetscInitialize(&argc, &argv, (char *)0, "PICurv Simulator"); CHKERRQ(ierr);
31
32 // === II. CONFIGURE =======================================================
33 // Create and populate the entire simulation configuration from command line.
34 ierr = CreateSimulationContext(argc, argv, &simCtx); CHKERRQ(ierr);
35 // == IIB. SET EXECUTION MODE (SOLVER vs POST-PROCESSOR) =====
37 // == IIC. CONFIGURE SIMULATION ENVIRONMENT & DIRECTORIES =====
38 ierr = SetupSimulationEnvironment(simCtx); CHKERRQ(ierr);
39
40 // === III. SETUP ==========================================================
41 // Build the simulation environment step-by-step.
42
43 // 1. Setup the multi-grid hierarchy, DMs, and PETSc vectors/solvers.
44 ierr = SetupGridAndSolvers(simCtx); CHKERRQ(ierr);
45
46 // 2. Setup the boundary condition handlers for the flow solver.
47 ierr = SetupBoundaryConditions(simCtx); CHKERRQ(ierr);
48
49 // 3. Setup domain decomposition info needed for particle migration.
50 ierr = SetupDomainRankInfo(simCtx); CHKERRQ(ierr);
51
52 // 4. Setup Initial State of Eulerian Fields
53 ierr = InitializeEulerianState(simCtx); CHKERRQ(ierr);
54
55 // 5. If requested, initialize the Lagrangian Particle Swarm.
56 if (simCtx->np > 0) {
57 ierr = InitializeParticleSwarm(simCtx); CHKERRQ(ierr);
58 }
59
60 LOG_ALLOW(GLOBAL,LOG_INFO," Setup Completed.\n");
61
62
63 /*
64 * --- IBM/FSI FEATURE HOOK (Currently Inactive) ---
65 * The logic for initializing immersed bodies would be enabled here.
66 * The `-immersed` command-line flag would control this block.
67 *
68 if (simCtx->immersed) {
69 ierr = InitializeImmersedBoundary(simCtx); CHKERRQ(ierr);
70 }
71 */
72
73 // === IV. EXECUTE =========================================================
74 // Display a summary banner and run the main time-stepping loop.
75
76 ierr = DisplayBanner(simCtx); CHKERRQ(ierr);
77
78 if (!simCtx->OnlySetup) {
79 // This function will contain the main time loop, orchestrating
80 // the flow solve and particle advection steps.
81
82 if(simCtx->StartStep == 0){
83 if(simCtx->np>0){
84 ierr = PerformInitializedParticleSetup(simCtx); CHKERRQ(ierr);
85 }else{
86 // Write the initial Eulerian fields.
87 UserCtx *user = simCtx->usermg.mgctx[simCtx->usermg.mglevels-1].user;
88 for(PetscInt bi = 0; bi < simCtx->block_number; bi++){
89 ierr = WriteSimulationFields(&user[bi]);
90 }
91 }
92 }else{
93 ierr = FinalizeRestartState(simCtx); CHKERRQ(ierr);
94 }
95
96 //********************PROFILING ROUTINES ****************************
97 // Before the first step, clear all counters accumulated during setup
98 // to ensure the Timestep 1 profile is clean.
99 ierr = ProfilingResetTimestepCounters(); CHKERRQ(ierr);
100 //*******************************************************************
101
102 if(simCtx->StepsToRun > 0){
103 ierr = AdvanceSimulation(simCtx); CHKERRQ(ierr);
104 }else{
105 LOG_ALLOW(GLOBAL,LOG_INFO,"Initial setup complete.No steps to run.Exiting!.\n");
106 }
107 }else{
108 LOG_ALLOW(GLOBAL,LOG_INFO,"SETUP ONLY MODE enabled. Skipping time loop.\n");
109 }
110
111 // == V. REPORT FIELDS ===========================
112
113 // === V. FINALIZE =========================================================
114 // Cleanly destroy all objects and free all memory.
115
116 ierr = ProfilingFinalize(simCtx); CHKERRQ(ierr);
117 ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
118 ierr = PetscFinalize();
119
120 return ierr;
121}
PetscErrorCode InitializeParticleSwarm(SimCtx *simCtx)
Perform particle swarm initialization, particle-grid interaction, and related operations.
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:1829
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:2375
#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:1172
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:30
PetscErrorCode ProfilingResetTimestepCounters(void)
Definition logging.c:1075
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition runloop.c:323
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
Definition runloop.c:258
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition runloop.c:95
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:2108
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:946
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Verifies and prepares the complete I/O environment for a simulation run.
Definition setup.c:645
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:44
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:1464
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Main cleanup function for the entire simulation context.
Definition setup.c:3245
UserCtx * user
Definition variables.h:476
PetscInt block_number
Definition variables.h:656
UserMG usermg
Definition variables.h:705
PetscInt StepsToRun
Definition variables.h:602
PetscInt np
Definition variables.h:683
PetscInt StartStep
Definition variables.h:601
PetscBool OnlySetup
Definition variables.h:607
PetscInt mglevels
Definition variables.h:483
@ EXEC_MODE_SOLVER
Definition variables.h:564
MGCtx * mgctx
Definition variables.h:486
ExecutionMode exec_mode
Definition variables.h:609
The master context for the entire simulation.
Definition variables.h:591
User-defined context containing data specific to a single computational grid level.
Definition variables.h:738
Here is the call graph for this function: