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