PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
Functions
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.

Orchestrates a single time step of the Eulerian fluid solver.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/solvers.h.

See also
FlowSolver()

Definition at line 11 of file solvers.c.

12{
13 PetscErrorCode ierr;
14 UserMG *usermg = NULL;
15 PetscInt level;
16 UserCtx *user = NULL;
17
18 PetscFunctionBeginUser;
20
24 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
25 "Unknown momentum solver type %d. Supported values are EXPLICIT_RK, DUALTIME_PICARD_JAMESON_RK, and NEWTON_KRYLOV.",
26 simCtx->mom_solver_type);
27 }
28
29 usermg = &simCtx->usermg;
30 level = usermg->mglevels - 1;
31 user = usermg->mgctx[level].user;
32 LOG_ALLOW(GLOBAL, LOG_INFO, "[Step %d] Entering orchestrator...\n", simCtx->step);
33
34 /*
35 // ========================================================================
36 // SECTION: O-Grid Specific Force Calculations (Legacy Feature)
37 // ========================================================================
38 // This was a specialized calculation for non-immersed O-grid cases.
39 if (simCtx->Ogrid && !simCtx->immersed) {
40 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Calculating O-grid forces...\n");
41 // Calc_forces_Ogrid(&user[0], simCtx->step, 0);
42 }
43 */
44
45
46
47 // ========================================================================
48 // SECTION: Turbulence Models (RANS/LES)
49 // ========================================================================
50 // These models compute the turbulent eddy viscosity (Nu_t) which is then
51 // used by the momentum solver in the diffusion term.
52
53 /*
54 if (simCtx->rans) {
55 LOG_ALLOW(GLOBAL, LOG_INFO, "Updating RANS (k-omega) model...\n");
56 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
57 K_Omega_Set_Constant(&user[bi]);
58 if (simCtx->step == simCtx->StartStep) {
59 LOG_ALLOW(LOCAL, LOG_DEBUG, " Initializing K-Omega field for block %d.\n", bi);
60 K_Omega_IC(&user[bi]);
61 }
62 // In a full implementation, the K-Omega transport equations would be solved here.
63 // Solve_K_Omega(&user[bi]);
64 }
65 }
66 */
67
68 if (simCtx->les) {
69 LOG_ALLOW(GLOBAL, LOG_INFO, "Updating LES (Smagorinsky) model...\n");
70 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
71 // LES models require Cartesian velocity to compute strain rates
72 const char *staggered_fields[] = {"Ucont"};
73 ierr = SynchronizePeriodicStaggeredFields(&user[bi], 1, staggered_fields); CHKERRQ(ierr);
74 ierr = Contra2Cart(&user[bi]); CHKERRQ(ierr);
75 {
76 const char *cell_fields[] = {"Ucat"};
77 ierr = SynchronizePeriodicCellFields(&user[bi], 1, cell_fields); CHKERRQ(ierr);
78 }
79 ierr = UpdateLocalGhosts(&user[bi], "Ucat"); CHKERRQ(ierr);
80 if(simCtx->les == CONSTANT_SMAGORINSKY) {
81 LOG_ALLOW(LOCAL, LOG_INFO, " Using constant Smagorinsky model for block %d.\n", bi);
82 // Constant Smagorinsky does not require dynamic computation
83 if(simCtx->step == simCtx->StartStep + 1){ // since step is updated before flowsolver call.
84 ierr = ComputeSmagorinskyConstant(&user[bi]); CHKERRQ(ierr);
85 }
86 } else if(simCtx->les == DYNAMIC_SMAGORINSKY) {
87 if (simCtx->step % simCtx->dynamic_freq == 0) {
88 LOG_ALLOW(LOCAL, LOG_DEBUG, " Computing Smagorinsky constant for block %d.\n", bi);
89 ierr = ComputeSmagorinskyConstant(&user[bi]);
90 }
91 }
92 // LOG_ALLOW(LOCAL, LOG_DEBUG, " Computing eddy viscosity for block %d.\n", bi);
93 ierr = ComputeEddyViscosityLES(&user[bi]);
94 }
95 }
96
97
98 // ========================================================================
99 // SECTION: Momentum Equation Solver
100 // ========================================================================
101 // This is the core of the time step. It computes an intermediate velocity
102 // field by solving the momentum equations.
103
104 LOG_ALLOW(GLOBAL, LOG_INFO, "Beginning momentum step solve (Solver = %s)...\n", MomentumSolverTypeToString(simCtx->mom_solver_type));
105
106 // Since IBM is disabled, we pass NULL for ibm and fsi arguments.
107 // ierr = ImpRK(user, NULL, NULL); CHKERRQ(ierr);
108 // Add new momentum solver types here only after wiring the enum, parser, docs, and tests.
110 ierr = MomentumSolver_DualTime_Picard_JamesonRK(user,NULL,NULL); CHKERRQ(ierr);
111 } else if(simCtx->mom_solver_type == MOMENTUM_SOLVER_EXPLICIT_RK) {
112 // Since IBM is disabled, we pass NULL for ibm and fsi arguments.
113 ierr = MomentumSolver_Explicit_RungeKutta4(user, NULL, NULL); CHKERRQ(ierr);
114 } else if (simCtx->mom_solver_type == MOMENTUM_SOLVER_NEWTON_KRYLOV) {
115 ierr = MomentumSolver_NewtonKrylov(user, NULL, NULL); CHKERRQ(ierr);
116 }
117// ========================================================================
118// SECTION: Pressure-Poisson Solver
119// ========================================================================
120// This step enforces the continuity equation (incompressibility) by solving
121// for a pressure correction field.
122
123 LOG_ALLOW(GLOBAL, LOG_INFO, "Beginning pressure-Poisson solve (Poisson Flag = %d)...\n", simCtx->poisson);
124
125 if (simCtx->poisson == 0) {
126 ierr = PoissonSolver_MG(usermg); CHKERRQ(ierr);
127 } else {
128 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
129 "Unsupported Poisson solver type %d. The current runtime supports only the multigrid path (poisson = 0).",
130 simCtx->poisson);
131 }
132
133 // ========================================================================
134 // SECTION: Velocity Correction (Projection)
135 // ========================================================================
136 // The pressure correction is used to update the pressure field and project
137 // the intermediate velocity onto a divergence-free space.
138
139 LOG_ALLOW(GLOBAL, LOG_INFO, "Applying velocity correction/projection step...\n");
140 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
141 ierr = UpdatePressure(&user[bi]); CHKERRQ(ierr);
142 LOG_ALLOW(GLOBAL,LOG_INFO," Pressure Updated for Block %d.\n",bi);
143
144 ierr = Projection(&user[bi]); CHKERRQ(ierr);
145
146 LOG_ALLOW(GLOBAL,LOG_INFO," Velocity corrected for Block %d.\n",bi);
147
148 // Ensure local ghost cells for the final pressure field are correct
149 ierr = UpdateLocalGhosts(&user[bi],"P");
150 }
151
152 // ========================================================================
153
154 // ========================================================================
155 // SECTION: Final Diagnostics and I/O
156 // ========================================================================
157
158 for (PetscInt bi = 0; bi < simCtx->block_number; bi++) {
159 LOG_ALLOW(GLOBAL, LOG_INFO, "Finalizing state & Diagnostics for block %d...\n", bi);
160
161 // --- Perform Divergence Check ---
162 // This is a diagnostic to verify the quality of the velocity correction.
163 ierr = ComputeDivergence(&user[bi]); CHKERRQ(ierr);
164
165 // -- Log Continuity metrics ----
166 ierr = LOG_CONTINUITY_METRICS(&user[bi]);
167 /*
168 // --- Immersed Boundary Interpolation (Post-Correction) ---
169 // This step would update the velocity values AT the IB nodes to match the
170 // newly corrected fluid field. Important for the next time step.
171 if (simCtx->immersed) {
172 for (PetscInt ibi = 0; ibi < simCtx->NumberOfBodies; ibi++) {
173 ibm_interpolation_advanced(&user[bi], &simCtx->ibm[ibi], ibi, 1);
174 }
175 }
176 */
177
178 // --- Averaging and Statistics (if enabled) ---
179 /*
180 if (simCtx->averaging) {
181 LOG_ALLOW(LOCAL, LOG_DEBUG, "Performing statistical averaging for block %d.\n", bi);
182 Do_averaging(&user[bi]);
183 }
184 */
185
186 // }
187 }
188
189 LOG_ALLOW(GLOBAL, LOG_INFO, "orchestrator finished for step %d.\n", simCtx->step);
191 PetscFunctionReturn(0);
192}
PetscErrorCode SynchronizePeriodicStaggeredFields(UserCtx *user, PetscInt num_fields, const char *field_names[])
Synchronizes persistent component-staggered vector fields.
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const char *field_names[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
PetscErrorCode ComputeEddyViscosityLES(UserCtx *user)
Computes the turbulent eddy viscosity (Nu_t) for the LES model.
Definition les.c:327
PetscErrorCode ComputeSmagorinskyConstant(UserCtx *user)
Computes the dynamic Smagorinsky constant (Cs) for the LES model.
Definition les.c:42
#define LOCAL
Logging scope definitions for controlling message output.
Definition logging.h:44
#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
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:827
PetscErrorCode LOG_CONTINUITY_METRICS(UserCtx *user)
Logs continuity metrics for a single block to a file.
Definition logging.c:1794
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:30
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:31
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
Definition logging.h:818
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Helper function to convert Momentum Solver flag to a string representation.
Definition logging.c:756
PetscErrorCode MomentumSolver_DualTime_Picard_JamesonRK(UserCtx *user, IBMNodes *ibm, FSInfo *fsi)
Solves the momentum equations using dual-time Picard iteration with Jameson RK smoothing.
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:328
PetscErrorCode UpdatePressure(UserCtx *user)
Updates the pressure field P with the pressure correction Phi computed by the Poisson solver.
Definition poisson.c:855
PetscErrorCode PoissonSolver_MG(UserMG *usermg)
Solves the pressure-Poisson equation using a geometric multigrid method.
Definition poisson.c:3149
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
Definition setup.c:2746
PetscErrorCode ComputeDivergence(UserCtx *user)
Computes the discrete divergence of the contravariant velocity field.
Definition setup.c:3135
PetscErrorCode UpdateLocalGhosts(UserCtx *user, const char *fieldName)
Updates the local vector (including ghost points) from its corresponding global vector.
Definition setup.c:1755
@ DYNAMIC_SMAGORINSKY
Definition variables.h:521
@ CONSTANT_SMAGORINSKY
Definition variables.h:520
UserCtx * user
Definition variables.h:569
PetscInt block_number
Definition variables.h:768
UserMG usermg
Definition variables.h:821
PetscInt StartStep
Definition variables.h:694
@ MOMENTUM_SOLVER_DUALTIME_PICARD_JAMESON_RK
Definition variables.h:534
@ MOMENTUM_SOLVER_EXPLICIT_RK
Definition variables.h:533
@ MOMENTUM_SOLVER_NEWTON_KRYLOV
Definition variables.h:535
PetscInt poisson
Definition variables.h:728
PetscInt mglevels
Definition variables.h:576
PetscInt dynamic_freq
Definition variables.h:790
PetscInt step
Definition variables.h:692
PetscInt les
Definition variables.h:789
MGCtx * mgctx
Definition variables.h:579
MomentumSolverType mom_solver_type
Definition variables.h:724
User-defined context containing data specific to a single computational grid level.
Definition variables.h:876
User-level context for managing the entire multigrid hierarchy.
Definition variables.h:575
Here is the call graph for this function:
Here is the caller graph for this function: