PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
momentumsolvers.h
Go to the documentation of this file.
1#ifndef MOMENTUMSOLVERS_H
2#define MOMENTUMSOLVERS_H
3
4#include "variables.h" // Provides definitions for UserCtx, SimCtx, IBMNodes, etc.
5#include "logging.h"
6#include "rhs.h"
7#include "Boundaries.h"
8
9/*================================================================================*
10 * MOMENTUM EQUATION SOLVERS *
11 *================================================================================*/
12
13/**
14 * @brief Advances the momentum equations using an explicit 4th-order Runge-Kutta scheme.
15 * @param user Array of UserCtx structs for all blocks.
16 * @param ibm (Optional) Pointer to IBM data. Pass NULL if disabled.
17 * @param fsi (Optional) Pointer to FSI data. Pass NULL if disabled.
18 * @return PetscErrorCode 0 on success.
19 *
20 * @note Testing status:
21 * The explicit RK path remains on the near-term backlog for direct
22 * positive-path bespoke coverage; today it is weaker than the dual-time
23 * path in the test surface.
24 */
25extern PetscErrorCode MomentumSolver_Explicit_RungeKutta4(UserCtx *user, IBMNodes *ibm, FSInfo *fsi);
26
27/**
28 * @brief Solves one physical momentum step with matrix-free Newton--Krylov.
29 *
30 * Version one uses a finite-difference matrix-free Jacobian, GMRES, and no
31 * preconditioner. All PETSc solver objects are local to this call. Rows removed
32 * by legacy boundary residual enforcement are made explicit: conditioned normal
33 * rows use X-Uconditioned, untouched dummy/tangential rows use X, and periodic
34 * duplicates use Xdup-Xrepresentative. Unsupported masked, interface, and
35 * component-disabled rows are rejected before setup.
36 *
37 * @param user Single-block momentum context.
38 * @param ibm Must be NULL; immersed boundaries are not supported in version one.
39 * @param fsi Must be NULL; moving-body coupling is not supported in version one.
40 * @return 0 on convergence, PETSC_ERR_CONV_FAILED after rollback on nonconvergence.
41 */
42PetscErrorCode MomentumSolver_NewtonKrylov(UserCtx *user, IBMNodes *ibm, FSInfo *fsi);
43
44/**
45 * @brief Solves the momentum equations using dual-time Picard iteration with Jameson RK smoothing.
46 *
47 * =================================================================================================
48 * GLOSSARY & THEORETICAL BASIS
49 * =================================================================================================
50 * 1. METHODOLOGY: Dual-Time Stepping (Pseudo-Time Integration)
51 * We aim to solve the implicit BDF equation: R_spatial(U) + dU/dt_physical = 0.
52 * We do this by introducing a fictitious "Pseudo-Time" (tau) and iterating to steady state:
53 * dU/d(tau) = - [ R_spatial(U) + BDF_Terms(U) ]
54 * When dU/d(tau) -> 0, the physical time step is satisfied.
55 * 2. ALGORITHM: Fixed-Point Iteration with Explicit Runge-Kutta
56 * This is technically a Fixed-Point iteration on the operator:
57 * U_new = U_old + pseudo_dtau * alfa_stage * Total_Residual(U_old)
58 * where pseudo_dtau = pseudo_cfl / lambda_max is the spectral-radius-based pseudo-time step
59 * (lambda_max = global max convective spectral radius). This makes pseudo_cfl a true
60 * dimensionless Courant number, independent of the physical time step dt.
61 * We use a 4-Stage Explicit RK scheme (Jameson-Schmidt-Turkel coeffs) to smooth errors.
62 * 3. STABILITY: Adaptive Pseudo-CFL Trial Acceptance and Rollback
63 * If a pseudo-time trial causes excessive residual growth, the solver restores the
64 * previous accepted state, reduces the global pseudo-CFL, and retries.
65 * =================================================================================================
66 * VARIABLE MAPPING
67 * =================================================================================================
68 * -- Physics Variables (Legacy Names Kept) --
69 * ti : Physical Time Step Index.
70 * dt : Physical Time Step size (Delta t).
71 * st : Pseudo-Time Step size (Delta tau).
72 * alfa : Runge-Kutta stage coefficients {1/4, 1/3, 1/2, 1}.
73 * -- Convergence & Solver Control (Renamed) --
74 * pseudo_iter : Counter for the inner dual-time loop.
75 * pseudo_dtau : Adaptive pseudo-time step [physical time], = pseudo_cfl / lambda_max.
76 * lambda_max : Global max convective spectral radius [1/s] from the current field.
77 * delta_sol_norm : The L_inf norm of the change in solution (dU).
78 * resid_norm : The L_inf norm of the Total Residual (RHS).
79 * =================================================================================================
80 *
81 * @param user Primary `UserCtx` input for the operation.
82 * @param ibm Parameter `ibm` passed to `MomentumSolver_DualTime_Picard_JamesonRK()`.
83 * @param fsi Parameter `fsi` passed to `MomentumSolver_DualTime_Picard_JamesonRK()`.
84 * @return PetscErrorCode 0 on success.
85 *
86 * @note Testing status:
87 * This solver is covered primarily through runtime smoke and orchestration
88 * tests. A smaller direct invariant-style positive-path harness remains
89 * part of the next-gap backlog.
90 */
91PetscErrorCode MomentumSolver_DualTime_Picard_JamesonRK(UserCtx *user, IBMNodes *ibm, FSInfo *fsi);
92
93/** @deprecated Use MomentumSolver_DualTime_Picard_JamesonRK(). */
94#define MomentumSolver_DualTime_Picard_RK4 MomentumSolver_DualTime_Picard_JamesonRK
95
96/*================================================================================*
97 * SHARED PHYSICAL-TIME (BDF) COEFFICIENT PLUMBING *
98 *================================================================================*/
99
100/**
101 * @brief Returns whether the current physical step uses the BDF2 discretization.
102 *
103 * Single source of truth for the BDF1/BDF2 selection. The predicate is identical
104 * to the one historically inlined in ComputeTotalResidual():
105 * BDF2 when COEF_TIME_ACCURACY > 1.1 AND step != StartStep AND step != 1,
106 * otherwise BDF1 (startup step and the first step after a restart).
107 *
108 * @param simCtx Master simulation context (reads step, StartStep).
109 * @return PETSC_TRUE for BDF2, PETSC_FALSE for BDF1.
110 */
111PetscBool MomentumUsesBDF2(SimCtx *simCtx);
112
113/**
114 * @brief Returns the BDF physical-time coefficient a0 for the current step.
115 *
116 * a0 = 1.5 (== COEF_TIME_ACCURACY) for BDF2, a0 = 1.0 for BDF1. Used both as the
117 * leading coefficient of the physical-time term in the residual and as the
118 * additive temporal contribution lambda_t = a0/dt in the momentum stability
119 * estimate, keeping the two numerically consistent.
120 *
121 * @param simCtx Master simulation context.
122 * @return a0 in {1.0, 1.5}.
123 */
124PetscReal MomentumBDFCoefficient(SimCtx *simCtx);
125
126/**
127 * @brief Computes the shared spatial-plus-BDF momentum residual in user->Rhs.
128 * @param user Block context with an allocated Rhs vector.
129 * @return PetscErrorCode 0 on success.
130 */
131PetscErrorCode ComputeTotalResidual(UserCtx *user);
132
133/*================================================================================*
134 * MOMENTUM PSEUDO-TIME STABILITY ESTIMATE (SHADOW) *
135 *================================================================================*/
136
137/**
138 * @brief Convective-estimate candidate selector. See ComputeMomentumStabilityEstimate().
139 *
140 * B: six-face transport scale (f_c * Aj * sum|U_f| / 2).
141 * C: B + frozen-advector discrete-divergence diagonal term.
142 * D: C + nonlinear velocity-gradient row-norm term (lambda_grad_u).
143 */
149
150/**
151 * @brief Dominant stiffness contributor at the controlling cell.
152 */
158
159/**
160 * @brief Diagnostic report produced by ComputeMomentumStabilityEstimate().
161 *
162 * This is a PRACTICAL CONSERVATIVE STABILITY ESTIMATE (operator-scaled pseudo-time
163 * estimate), not a proven spectral radius. All lambda_* are global maxima in [1/s].
164 */
165typedef struct {
166 PetscReal lambda; /* selected-candidate global max estimate [1/s] */
167 PetscReal lambda_t; /* temporal term a0/dt (uniform across cells) */
168 PetscReal lambda_c; /* convective part at the controlling cell */
169 PetscReal lambda_v; /* viscous part at the controlling cell */
170 PetscReal lambda_B; /* global max of (lambda_t + lambda_c^B + lambda_v) */
171 PetscReal lambda_C; /* global max with candidate C convective term */
172 PetscReal lambda_D; /* global max with candidate D convective term */
173 PetscInt ci, cj, ck; /* controlling-cell global index (selected cand) */
174 PetscInt cblock; /* controlling-cell block */
175 PetscInt cclass; /* 0=interior, 1=physical-boundary, 2=IB-adjacent */
176 PetscInt one_sided; /* controlling cell used the one-sided viscous x2 */
177 PetscInt active_cells; /* global count of active (non-masked) cells */
178 PetscBool estimate_incomplete; /* true if Clark/RANS/vel-dependent force is active (uncovered) */
179 MomStabLimiter limiter; /* dominant contributor at the controlling cell */
181
182/**
183 * @brief Compute the momentum pseudo-time stability estimate (shadow/diagnostic).
184 *
185 * Conservative, operator-scaled estimate: lambda = max_cell (a0/dt + lambda_c + lambda_nu),
186 * over active, non-solid cells, blocks, and MPI ranks, where lambda_c already includes the
187 * per-direction QUICK scheme factors. Read-only; performs no halo exchange, but does perform
188 * global scalar collectives (see implementation). This is a PRACTICAL CONSERVATIVE estimate,
189 * not a proven spectral radius. See the Workstream-A design.
190 *
191 * Call-site preconditions (NOT enforced internally): lUcont, lUcat, lNu_t, lNvert
192 * must be fresh; lAj, face Jacobians and face metrics are static after grid init.
193 *
194 * @param[in] user Array of UserCtx (one per block).
195 * @param[in] block_number Number of blocks.
196 * @param[in] dt Physical time step.
197 * @param[in] candidate Convective candidate driving rep->lambda (B, C or D).
198 * @param[out] rep Filled diagnostic report (global maxima + breakdown).
199 * @return PetscErrorCode 0 on success.
200 */
201PetscErrorCode ComputeMomentumStabilityEstimate(UserCtx *user, PetscInt block_number,
202 PetscReal dt, MomStabCandidate candidate,
203 MomStabilityReport *rep);
204
205/**
206 * @brief Active staggered-momentum row mask for a cell (exposed for unit testing).
207 *
208 * Returns a 3-bit mask (xi=1, eta=2, zeta=4). A solid cell yields 0 (all inactive); a
209 * positive solid neighbour or a positive non-periodic physical face clears the corresponding
210 * normal row; TwoD (1/2/3) clears the homogeneous direction's row.
211 *
212 * @param nvert Local nvert array (ghosted).
213 * @param k Cell k index.
214 * @param j Cell j index.
215 * @param i Cell i index.
216 * @param mx Global x dimension.
217 * @param my Global y dimension.
218 * @param mz Global z dimension.
219 * @param np_x1 True if the positive-x face is non-periodic.
220 * @param np_y1 True if the positive-y face is non-periodic.
221 * @param np_z1 True if the positive-z face is non-periodic.
222 * @param twoD TwoD homogeneous-direction selector (0 none, 1 xi, 2 eta, 3 zeta).
223 * @return 3-bit active-row mask (0 when the location carries no active unknown).
224 */
225PetscInt MomCellActiveRows(PetscReal ***nvert, PetscInt k, PetscInt j, PetscInt i,
226 PetscInt mx, PetscInt my, PetscInt mz,
227 PetscBool np_x1, PetscBool np_y1, PetscBool np_z1, PetscInt twoD);
228
229#endif // MOMENTUMSOLVERS_H
Logging utilities and macros for PETSc-based applications.
PetscBool estimate_incomplete
PetscErrorCode MomentumSolver_DualTime_Picard_JamesonRK(UserCtx *user, IBMNodes *ibm, FSInfo *fsi)
Solves the momentum equations using dual-time Picard iteration with Jameson RK smoothing.
MomStabLimiter
Dominant stiffness contributor at the controlling cell.
@ MOM_STAB_LIMITER_CONVECTION
@ MOM_STAB_LIMITER_VISCOSITY
@ MOM_STAB_LIMITER_TIME
MomStabLimiter limiter
PetscBool MomentumUsesBDF2(SimCtx *simCtx)
Returns whether the current physical step uses the BDF2 discretization.
PetscReal MomentumBDFCoefficient(SimCtx *simCtx)
Returns the BDF physical-time coefficient a0 for the current step.
MomStabCandidate
Convective-estimate candidate selector.
@ MOM_STAB_CAND_B
@ MOM_STAB_CAND_C
@ MOM_STAB_CAND_D
PetscErrorCode ComputeTotalResidual(UserCtx *user)
Computes the shared spatial-plus-BDF momentum residual in user->Rhs.
PetscInt MomCellActiveRows(PetscReal ***nvert, PetscInt k, PetscInt j, PetscInt i, PetscInt mx, PetscInt my, PetscInt mz, PetscBool np_x1, PetscBool np_y1, PetscBool np_z1, PetscInt twoD)
Active staggered-momentum row mask for a cell (exposed for unit testing).
PetscErrorCode ComputeMomentumStabilityEstimate(UserCtx *user, PetscInt block_number, PetscReal dt, MomStabCandidate candidate, MomStabilityReport *rep)
Compute the momentum pseudo-time stability estimate (shadow/diagnostic).
PetscErrorCode MomentumSolver_Explicit_RungeKutta4(UserCtx *user, IBMNodes *ibm, FSInfo *fsi)
Advances the momentum equations using an explicit 4th-order Runge-Kutta scheme.
Diagnostic report produced by ComputeMomentumStabilityEstimate().
Main header file for a complex fluid dynamics solver.
Holds all data related to the state and motion of a body in FSI.
Definition variables.h:475
Represents a collection of nodes forming a surface for the IBM.
Definition variables.h:402
The master context for the entire simulation.
Definition variables.h:684
User-defined context containing data specific to a single computational grid level.
Definition variables.h:876