PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
solvers.h File Reference
#include "variables.h"
#include "momentumsolvers.h"
#include "rhs.h"
#include "logging.h"
#include "poisson.h"
#include "setup.h"
#include "les.h"
Include dependency graph for solvers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PetscErrorCode FlowSolver (SimCtx *simCtx)
 Orchestrates a single time step of the Eulerian fluid solver.
 

Function Documentation

◆ FlowSolver()

PetscErrorCode FlowSolver ( SimCtx simCtx)

Orchestrates a single time step of the Eulerian fluid solver.

This is the refactored, high-level entry point for advancing the fluid state from time t_n to t_{n+1}. It takes the master SimCtx as its primary argument.

Parameters
simCtxThe master simulation context, containing all solver settings, multigrid structures, and data vectors.
Returns
PetscErrorCode 0 on success.

This function is the refactored, high-level entry point for advancing the fluid state from time t_n to t_{n+1}. It is a direct adaptation of the legacy FlowSolver, but it now takes the master SimCtx as its primary argument to eliminate dependencies on global variables.

The sequence of operations is:

  1. (Optional) Update turbulence models (RANS/LES) to compute eddy viscosity.
  2. Call the core momentum solver (explicit Runge-Kutta or an implicit scheme) to get an intermediate velocity field.
  3. Call the pressure-Poisson solver to compute the pressure correction.
  4. Call the projection step to correct the velocity field, ensuring it is divergence-free.
  5. Perform final state updates, diagnostics, and I/O.
Parameters
simCtxThe master simulation context, containing all solver settings, multigrid structures, and data vectors.
Returns
PetscErrorCode 0 on success.

Definition at line 26 of file solvers.c.

27{
28 PetscErrorCode ierr;
29 UserMG *usermg = &simCtx->usermg;
30 PetscInt level = usermg->mglevels - 1;
31 UserCtx *user = usermg->mgctx[level].user;
32
33 PetscFunctionBeginUser;
35 LOG_ALLOW(GLOBAL, LOG_INFO, "[Step %d] Entering orchestrator...\n", simCtx->step);
36
37 /*
38 // ========================================================================
39 // SECTION: O-Grid Specific Force Calculations (Legacy Feature)
40 // ========================================================================
41 // This was a specialized calculation for non-immersed O-grid cases.
42 if (simCtx->Ogrid && !simCtx->immersed) {
43 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Calculating O-grid forces...\n");
44 // Calc_forces_Ogrid(&user[0], simCtx->step, 0);
45 }
46 */
47
48
49
50 // ========================================================================
51 // SECTION: Turbulence Models (RANS/LES)
52 // ========================================================================
53 // These models compute the turbulent eddy viscosity (Nu_t) which is then
54 // used by the momentum solver in the diffusion term.
55
56 /*
57 if (simCtx->rans) {
58 LOG_ALLOW(GLOBAL, LOG_INFO, "Updating RANS (k-omega) model...\n");
59 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
60 K_Omega_Set_Constant(&user[bi]);
61 if (simCtx->step == simCtx->StartStep) {
62 LOG_ALLOW(LOCAL, LOG_DEBUG, " Initializing K-Omega field for block %d.\n", bi);
63 K_Omega_IC(&user[bi]);
64 }
65 // In a full implementation, the K-Omega transport equations would be solved here.
66 // Solve_K_Omega(&user[bi]);
67 }
68 }
69 */
70
71 if (simCtx->les) {
72 LOG_ALLOW(GLOBAL, LOG_INFO, "Updating LES (Smagorinsky) model...\n");
73 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
74 // LES models require Cartesian velocity to compute strain rates
75 ierr = UpdateLocalGhosts(&user[bi], "Ucont");
76 ierr = Contra2Cart(&user[bi]); CHKERRQ(ierr);
77 ierr = UpdateLocalGhosts(&user[bi], "Ucat");
78 if(simCtx->les == CONSTANT_SMAGORINSKY) {
79 LOG_ALLOW(LOCAL, LOG_INFO, " Using constant Smagorinsky model for block %d.\n", bi);
80 // Constant Smagorinsky does not require dynamic computation
81 if(simCtx->step == simCtx->StartStep + 1){ // since step is updated before flowsolver call.
82 ierr = ComputeSmagorinskyConstant(&user[bi]); CHKERRQ(ierr);
83 }
84 } else if(simCtx->les == DYNAMIC_SMAGORINSKY) {
85 if (simCtx->step % simCtx->dynamic_freq == 0) {
86 LOG_ALLOW(LOCAL, LOG_DEBUG, " Computing Smagorinsky constant for block %d.\n", bi);
87 ierr = ComputeSmagorinskyConstant(&user[bi]);
88 }
89 }
90 // LOG_ALLOW(LOCAL, LOG_DEBUG, " Computing eddy viscosity for block %d.\n", bi);
91 ierr = ComputeEddyViscosityLES(&user[bi]);
92 }
93 }
94
95
96 // ========================================================================
97 // SECTION: Momentum Equation Solver
98 // ========================================================================
99 // This is the core of the time step. It computes an intermediate velocity
100 // field by solving the momentum equations.
101
102 LOG_ALLOW(GLOBAL, LOG_INFO, "Beginning momentum step solve (Solver = %s)...\n", MomentumSolverTypeToString(simCtx->mom_solver_type));
103
104 // Since IBM is disabled, we pass NULL for ibm and fsi arguments.
105 // ierr = ImpRK(user, NULL, NULL); CHKERRQ(ierr);
107 ierr = MomentumSolver_DualTime_Picard_RK4(user,NULL,NULL); CHKERRQ(ierr);
108 } else if(simCtx->mom_solver_type == MOMENTUM_SOLVER_EXPLICIT_RK) {
109 // Since IBM is disabled, we pass NULL for ibm and fsi arguments.
110 ierr = MomentumSolver_Explicit_RungeKutta4(user, NULL, NULL); CHKERRQ(ierr);
111 } else {
112 LOG_ALLOW(GLOBAL, LOG_WARNING, "Momentum solver type %d is not currently enabled.\n", simCtx->mom_solver_type);
113 }
114// ========================================================================
115// SECTION: Pressure-Poisson Solver
116// ========================================================================
117// This step enforces the continuity equation (incompressibility) by solving
118// for a pressure correction field.
119
120 LOG_ALLOW(GLOBAL, LOG_INFO, "Beginning pressure-Poisson solve (Poisson Flag = %d)...\n", simCtx->poisson);
121
122 if (simCtx->poisson == 0) {
123 ierr = PoissonSolver_MG(usermg); CHKERRQ(ierr);
124 } else {
125 // Logic for other Poisson solvers (e.g., Hypre) would go here.
126 LOG_ALLOW(GLOBAL, LOG_WARNING, "Poisson solver type %d is not currently enabled.\n", simCtx->poisson);
127 }
128
129 // ========================================================================
130 // SECTION: Velocity Correction (Projection)
131 // ========================================================================
132 // The pressure correction is used to update the pressure field and project
133 // the intermediate velocity onto a divergence-free space.
134
135 LOG_ALLOW(GLOBAL, LOG_INFO, "Applying velocity correction/projection step...\n");
136 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
137 ierr = UpdatePressure(&user[bi]); CHKERRQ(ierr);
138 LOG_ALLOW(GLOBAL,LOG_INFO," Pressure Updated for Block %d.\n",bi);
139
140 ierr = Projection(&user[bi]); CHKERRQ(ierr);
141
142 LOG_ALLOW(GLOBAL,LOG_INFO," Velocity corrected for Block %d.\n",bi);
143
144 // Ensure local ghost cells for the final pressure field are correct
145 ierr = UpdateLocalGhosts(&user[bi],"P");
146 }
147
148 // ========================================================================
149
150 // ========================================================================
151 // SECTION: Final Diagnostics and I/O
152 // ========================================================================
153
154 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
155 LOG_ALLOW(GLOBAL, LOG_INFO, "Finalizing state & Diagnostics for block %d...\n", bi);
156
157 // --- Perform Divergence Check ---
158 // This is a diagnostic to verify the quality of the velocity correction.
159 ierr = ComputeDivergence(&user[bi]); CHKERRQ(ierr);
160
161 // -- Log Continuity metrics ----
162 ierr = LOG_CONTINUITY_METRICS(&user[bi]);
163 /*
164 // --- Immersed Boundary Interpolation (Post-Correction) ---
165 // This step would update the velocity values AT the IB nodes to match the
166 // newly corrected fluid field. Important for the next time step.
167 if (simCtx->immersed) {
168 for (PetscInt ibi = 0; ibi < simCtx->NumberOfBodies; ibi++) {
169 ibm_interpolation_advanced(&user[bi], &simCtx->ibm[ibi], ibi, 1);
170 }
171 }
172 */
173
174 // --- Averaging and Statistics (if enabled) ---
175 /*
176 if (simCtx->averaging) {
177 LOG_ALLOW(LOCAL, LOG_DEBUG, "Performing statistical averaging for block %d.\n", bi);
178 Do_averaging(&user[bi]);
179 }
180 */
181
182 // }
183 }
184
185 LOG_ALLOW(GLOBAL, LOG_INFO, "orchestrator finished for step %d.\n", simCtx->step);
187 PetscFunctionReturn(0);
188}
PetscErrorCode ComputeEddyViscosityLES(UserCtx *user)
Computes the turbulent eddy viscosity (Nu_t) for the LES model.
Definition les.c:301
PetscErrorCode ComputeSmagorinskyConstant(UserCtx *user)
Computes the dynamic Smagorinsky constant (Cs) for the LES model.
Definition les.c:23
#define LOCAL
Logging scope definitions for controlling message output.
Definition logging.h:45
#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
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:746
PetscErrorCode LOG_CONTINUITY_METRICS(UserCtx *user)
Logs continuity metrics for a single block to a file.
Definition logging.c:879
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:31
@ LOG_WARNING
Non-critical issues that warrant attention.
Definition logging.h:29
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
Definition logging.h:737
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Helper function to convert Momentum Solver flag to a string representation.
Definition logging.c:706
PetscErrorCode MomentumSolver_DualTime_Picard_RK4(UserCtx *user, IBMNodes *ibm, FSInfo *fsi)
Solves the Momentum Equations using Dual-Time Stepping with a Fixed-Point RK4 Smoother.
PetscErrorCode MomentumSolver_Explicit_RungeKutta4(UserCtx *user, IBMNodes *ibm, FSInfo *fsi)
Advances the momentum equations using an explicit 4th-order Runge-Kutta scheme.
PetscErrorCode Projection(UserCtx *user)
Corrects the contravariant velocity field Ucont to be divergence-free using the gradient of the press...
Definition poisson.c:368
PetscErrorCode UpdatePressure(UserCtx *user)
Updates the pressure field P with the pressure correction Phi computed by the Poisson solver.
Definition poisson.c:915
PetscErrorCode PoissonSolver_MG(UserMG *usermg)
Solves the pressure-Poisson equation using a geometric multigrid method.
Definition poisson.c:3372
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
Definition setup.c:2177
PetscErrorCode ComputeDivergence(UserCtx *user)
Definition setup.c:2470
PetscErrorCode UpdateLocalGhosts(UserCtx *user, const char *fieldName)
Updates the local vector (including ghost points) from its corresponding global vector.
Definition setup.c:1157
@ DYNAMIC_SMAGORINSKY
Definition variables.h:450
@ CONSTANT_SMAGORINSKY
Definition variables.h:449
UserCtx * user
Definition variables.h:474
PetscInt block_number
Definition variables.h:649
UserMG usermg
Definition variables.h:698
PetscInt StartStep
Definition variables.h:595
@ MOMENTUM_SOLVER_EXPLICIT_RK
Definition variables.h:458
@ MOMENTUM_SOLVER_DUALTIME_PICARD_RK4
Definition variables.h:459
PetscInt poisson
Definition variables.h:628
PetscInt mglevels
Definition variables.h:481
PetscInt dynamic_freq
Definition variables.h:670
PetscInt step
Definition variables.h:593
PetscInt les
Definition variables.h:669
MGCtx * mgctx
Definition variables.h:484
MomentumSolverType mom_solver_type
Definition variables.h:624
User-defined context containing data specific to a single computational grid level.
Definition variables.h:728
User-level context for managing the entire multigrid hierarchy.
Definition variables.h:480
Here is the call graph for this function:
Here is the caller graph for this function: