PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
picsolver.c
Go to the documentation of this file.
1/**
2 * @file main.c
3 * @brief Main driver for the unified CFD and Lagrangian particle solver.
4 *
5 * This version focuses on establishing the core architecture for a particle-coupled
6 * flow simulation. It initializes the grid, solver objects, and a DMSwarm of
7 * Lagrangian particles. Hooks for the Immersed Boundary Method (IBM) are present
8 * but are currently inactive to allow for iterative development.
9 *
10 * ARCHITECTURE:
11 * 1. A central `SimulationContext` (simCtx) holds all simulation-wide configuration.
12 * 2. `CreateSimulationContext()` handles all command-line parsing.
13 * 3. The `main()` function provides a high-level workflow for the simulation.
14 */
15
16#include "simulation.h" // The new, unified header file
17
18/*================================================================================*
19 * MAIN FUNCTION *
20 *================================================================================*/
21
22#undef __FUNCT__
23#define __FUNCT__ "main"
24int main(int argc, char **argv)
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, "PIC-Solver"); 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
38 // === III. SETUP ==========================================================
39 // Build the simulation environment step-by-step.
40
41 // 1. Setup the multi-grid hierarchy, DMs, and PETSc vectors/solvers.
42 ierr = SetupGridAndSolvers(simCtx); CHKERRQ(ierr);
43
44 // 2. Setup the boundary condition handlers for the flow solver.
45 ierr = SetupBoundaryConditions(simCtx); CHKERRQ(ierr);
46
47 // 3. Setup domain decomposition info needed for particle migration.
48 ierr = SetupDomainRankInfo(simCtx); CHKERRQ(ierr);
49
50 // 4. Setup Initial State of Eulerian Fields
51 ierr = InitializeEulerianState(simCtx); CHKERRQ(ierr);
52
53 // 5. If requested, initialize the Lagrangian Particle Swarm.
54 if (simCtx->np > 0) {
55 ierr = InitializeParticleSwarm(simCtx); CHKERRQ(ierr);
56 }
57
58 LOG_ALLOW(GLOBAL,LOG_INFO," Setup Completed.\n");
59
60
61 /*
62 * --- IBM/FSI FEATURE HOOK (Currently Inactive) ---
63 * The logic for initializing immersed bodies would be enabled here.
64 * The `-immersed` command-line flag would control this block.
65 *
66 if (simCtx->immersed) {
67 ierr = InitializeImmersedBoundary(simCtx); CHKERRQ(ierr);
68 }
69 */
70
71 // === IV. EXECUTE =========================================================
72 // Display a summary banner and run the main time-stepping loop.
73
74 ierr = DisplayBanner(simCtx); CHKERRQ(ierr);
75
76 if (!simCtx->OnlySetup) {
77 // This function will contain the main time loop, orchestrating
78 // the flow solve and particle advection steps.
79
80 if(simCtx->StartStep == 0){
81 if(simCtx->np>0){
82 ierr = PerformInitialSetup(simCtx); CHKERRQ(ierr);
83 }
84 }else{
85
86 // Restart logic
87 LOG_ALLOW(GLOBAL,LOG_INFO," Restart from Time step %d.\n",simCtx->StartStep);
88 }
89
90 if(simCtx->StepsToRun > 0){
91 ierr = AdvanceSimulation(simCtx); CHKERRQ(ierr);
92 }else{
93 LOG_ALLOW(GLOBAL,LOG_INFO,"Initial setup complete.No steps to run.Exiting!.\n");
94 }
95
96 }else{
97 LOG_ALLOW(GLOBAL,LOG_INFO,"SETUP ONLY MODE enabled. Skipping time loop.\n");
98 }
99
100 // === V. FINALIZE =========================================================
101 // Cleanly destroy all objects and free all memory.
102
103 ierr = ProfilingFinalize(); CHKERRQ(ierr);
104 // ierr = FinalizeSimulation(simCtx); CHKERRQ(ierr);
105 ierr = PetscFinalize();
106
107 return ierr;
108}
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 DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
Definition io.c:1807
#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:207
PetscErrorCode ProfilingFinalize(void)
Prints the final, cumulative performance summary and cleans up resources.
Definition logging.c:1046
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:32
int main(int argc, char **argv)
Definition picsolver.c:24
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Sets up the full rank communication infrastructure, including neighbor ranks and bounding box exchang...
Definition setup.c:1687
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
The main orchestrator for setting up all grid-related components.
Definition setup.c:577
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Allocates and populates the master SimulationContext object.
Definition setup.c:41
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
(Orchestrator) Sets up all boundary conditions for the simulation.
Definition setup.c:1035
PetscErrorCode PerformInitialSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition simulation.c:95
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition simulation.c:181
PetscInt StepsToRun
Definition variables.h:524
PetscInt np
Definition variables.h:585
PetscInt StartStep
Definition variables.h:523
PetscBool OnlySetup
Definition variables.h:529
@ EXEC_MODE_SOLVER
Definition variables.h:496
ExecutionMode exec_mode
Definition variables.h:532
The master context for the entire simulation.
Definition variables.h:513