Pressure-Poisson projection: operator, right-hand side, multigrid solve, pressure update, and velocity correction. More...
Go to the source code of this file.
Data Structures | |
| struct | PoissonFaceGradient |
| Everything needed to evaluate the gradient flux through one face. More... | |
Functions | |
| static PICURV_ALWAYS_INLINE PetscReal | PoissonOperator_At (const PetscReal ***field, const PetscInt c[3], const PetscInt d[3]) |
Value of a cell-centred array at cell c displaced by d. | |
| static PICURV_ALWAYS_INLINE PoissonTransverseDifference | PoissonOperator_TransverseDifference (const PetscReal ***nvert, const PetscInt c[3], PetscInt n, PetscInt t, const PetscInt m[3], const PetscBool periodic[3]) |
The rows and weight of the transverse difference along axis t at the face between cell c and c + e_n, for operator assembly; PoissonOperator_TransverseKind() chooses. | |
| static PICURV_ALWAYS_INLINE PoissonFaceGradient | PoissonOperator_FaceGradientStencil (const PoissonFaceMetrics *metrics, const PetscReal ***nvert, const PetscInt c[3], PetscInt n, const PetscInt m[3], const PetscBool periodic[3]) |
Gathers the metric coefficients and transverse differences of the gradient flux through the face between cell c and c + e_n. | |
| static PetscInt | PoissonOperator_StencilSlot (const PetscInt d[3]) |
| Maps the 19 stencil offsets to their slots; corners of the 3x3x3 block are -1. | |
| PetscErrorCode | PoissonOperator_GetFaceMetrics (UserCtx *user, PoissonFaceMetrics *metrics) |
| Implementation of PoissonOperator_GetFaceMetrics(). | |
| PetscErrorCode | PoissonOperator_RestoreFaceMetrics (UserCtx *user, PoissonFaceMetrics *metrics) |
| Implementation of PoissonOperator_RestoreFaceMetrics(). | |
| static PetscInt | PoissonOperator_NeighborIndex (PetscInt v, PetscInt d, PetscInt m, PetscBool periodic) |
Index of the neighbour at offset d (-1, 0, +1) from v on an axis of m points, wrapping between the interior layers 1 and m-2 when periodic. | |
| static void | PoissonOperator_AddFaceFlux (const PoissonFaceGradient *face, const PetscInt own[3], PetscInt n, PetscReal sign, PetscScalar coefficients[19]) |
| Adds the signed gradient flux through one face to a row's stencil coefficients. | |
| PetscErrorCode | AssemblePoissonOperator (UserCtx *user) |
| Implementation of AssemblePoissonOperator(). | |
| PetscErrorCode | ComputePoissonRHS (UserCtx *user, Vec B) |
| Implementation of ComputePoissonRHS(). | |
| PetscErrorCode | UpdatePressure (UserCtx *user) |
| Implementation of UpdatePressure(). | |
| PetscErrorCode | ProjectVelocity (UserCtx *user) |
| Implementation of ProjectVelocity(). | |
| static PetscErrorCode | PoissonMultigrid_RemoveNullSpace (MatNullSpace nullsp, Vec X, void *ctx) |
| Removes the null space of the Neumann pressure problem from a level vector. | |
| static void | PoissonMultigrid_InterpolationParent (PetscInt f, PetscInt m, PetscInt semi, PetscInt *coarse, PetscInt *direction) |
Coarse cell and interpolation direction along one axis for fine index f. | |
| static PetscErrorCode | PoissonMultigrid_Interpolate (Mat P, Vec X, Vec F) |
| Prolongs a coarse-level correction to the next finer level (MatShell multiply). | |
| static PetscErrorCode | PoissonMultigrid_Restrict (Mat R, Vec X, Vec F) |
| Restricts a fine-level residual to the next coarser level (MatShell multiply). | |
| static PetscErrorCode | PoissonMultigrid_ShiftBlockFactors (KSP level_ksp) |
| Gives each block factor of a block-Jacobi level solver a small diagonal shift, so the factorization of a nearly singular Neumann block does not fail on a zero pivot. | |
| static PetscErrorCode | PoissonMultigrid_Build (UserMG *usermg, PetscInt bi) |
Builds the multigrid solver for block bi and stores it in the finest level. | |
| static PetscErrorCode | PoissonMultigrid_OpenConvergenceLog (KSP ksp, SimCtx *simCtx, PetscInt bi) |
| Prepares the convergence monitor for one solve and opens its log file on rank 0. | |
| static PetscErrorCode | PoissonMultigrid_CloseConvergenceLog (KSP ksp) |
| Closes the log file opened by PoissonMultigrid_OpenConvergenceLog(). | |
| PetscErrorCode | PoissonSolver_Multigrid (UserMG *usermg) |
| Implementation of PoissonSolver_Multigrid(). | |
Variables | |
| static const PetscInt | POISSON_STENCIL_OFFSETS [19][3] |
| Offsets of the 19 stencil points, in the column order used to insert each row. | |
| static const FieldId | POISSON_FACE_METRIC_FIELDS [3][3] |
| Field IDs of the face metric vectors, indexed as PoissonFaceMetrics. | |
| static const FieldId | POISSON_FACE_AJ_FIELDS [3] = {FIELD_ID_IAJ, FIELD_ID_JAJ, FIELD_ID_KAJ} |
Pressure-Poisson projection: operator, right-hand side, multigrid solve, pressure update, and velocity correction.
Grid layout. Cell-centred quantities live at DMDA indices 1..m-2 on each axis; indices 0 and m-1 are dummy layers that carry no unknown. On a periodic axis the interior wraps from m-2 to 1. The contravariant flux Ucont[k][j][i].x sits on the face between cells i and i+1, and likewise for the other two components.
Face gradient. The flux of grad(Phi) through the face between cell c and c + e_n is
sum_b g_nb D_b(Phi), g_nb = (F_b . F_n) * aj_n,
where F_b are the contravariant base vectors stored on the n-faces, aj_n is the inverse Jacobian there, D_n is the difference across the face, and D_b (b != n) is the transverse difference chosen by PoissonOperator_TransverseDifference(). The operator assembles the divergence of this flux, and the projection subtracts it from Ucont, so the two are consistent by construction.
Definition in file poisson.c.
| struct PoissonFaceGradient |
Everything needed to evaluate the gradient flux through one face.
| Data Fields | ||
|---|---|---|
| PetscReal | dot[3] |
F_b . F_n on the face, b = 0..2. |
| PetscReal | aj | Inverse Jacobian on the face. |
| PoissonTransverseDifference | diff[3] | Transverse differences; diff[n] is unused. |
|
static |
Value of a cell-centred array at cell c displaced by d.
| [in] | field | Ghosted cell-centred array, indexed [k][j][i]. |
| [in] | c | Cell (i, j, k). |
| [in] | d | Displacement (di, dj, dk). |
c + d. Definition at line 60 of file poisson.c.
|
static |
The rows and weight of the transverse difference along axis t at the face between cell c and c + e_n, for operator assembly; PoissonOperator_TransverseKind() chooses.
| [in] | nvert | Ghosted solid field. |
| [in] | c | Cell on the low side of the face. |
| [in] | n | Face orientation (0, 1, 2 for i, j, k). |
| [in] | t | Transverse axis, not n. |
| [in] | m | Grid sizes (mx, my, mz). |
| [in] | periodic | Whether each axis is periodic. |
Definition at line 78 of file poisson.c.
|
static |
Gathers the metric coefficients and transverse differences of the gradient flux through the face between cell c and c + e_n.
| [in] | metrics | Face metric arrays from PoissonOperator_GetFaceMetrics(). |
| [in] | nvert | Ghosted solid field. |
| [in] | c | Cell on the low side of the face. |
| [in] | n | Face orientation (0, 1, 2 for i, j, k). |
| [in] | m | Grid sizes (mx, my, mz). |
| [in] | periodic | Whether each axis is periodic. |
Definition at line 105 of file poisson.c.
|
static |
Maps the 19 stencil offsets to their slots; corners of the 3x3x3 block are -1.
Definition at line 128 of file poisson.c.
| PetscErrorCode PoissonOperator_GetFaceMetrics | ( | UserCtx * | user, |
| PoissonFaceMetrics * | metrics | ||
| ) |
Implementation of PoissonOperator_GetFaceMetrics().
Borrows read access to the face metric arrays of user.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 147 of file poisson.c.
| PetscErrorCode PoissonOperator_RestoreFaceMetrics | ( | UserCtx * | user, |
| PoissonFaceMetrics * | metrics | ||
| ) |
Implementation of PoissonOperator_RestoreFaceMetrics().
Returns the arrays borrowed by PoissonOperator_GetFaceMetrics().
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 171 of file poisson.c.
|
inlinestatic |
Index of the neighbour at offset d (-1, 0, +1) from v on an axis of m points, wrapping between the interior layers 1 and m-2 when periodic.
Definition at line 193 of file poisson.c.
|
static |
Adds the signed gradient flux through one face to a row's stencil coefficients.
| [in] | face | Face gradient from PoissonOperator_FaceGradientStencil(). |
| [in] | own | Offset of the face's lower cell from the row cell. |
| [in] | n | Normal axis of the face. |
| [in] | sign | +1 for the row's upper face on the axis, -1 for its lower face. |
| [in,out] | coefficients | The row's 19 coefficients. |
Definition at line 209 of file poisson.c.
| PetscErrorCode AssemblePoissonOperator | ( | UserCtx * | user | ) |
Implementation of AssemblePoissonOperator().
Assembles the pressure-correction operator on one multigrid level.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 244 of file poisson.c.
| PetscErrorCode ComputePoissonRHS | ( | UserCtx * | user, |
| Vec | B | ||
| ) |
Implementation of ComputePoissonRHS().
Forms the right-hand side of the pressure-correction equation.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 344 of file poisson.c.
| PetscErrorCode UpdatePressure | ( | UserCtx * | user | ) |
Implementation of UpdatePressure().
Adds the pressure correction to the pressure, P += Phi, and refreshes both fields' periodic images and ghosts.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 405 of file poisson.c.
| PetscErrorCode ProjectVelocity | ( | UserCtx * | user | ) |
Implementation of ProjectVelocity().
Corrects the contravariant flux with the gradient of Phi.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 425 of file poisson.c.
|
static |
Removes the null space of the Neumann pressure problem from a level vector.
PETSc first removes the global constant. This callback then subtracts the mean over the interior fluid cells and zeroes the dummy layers and solid cells, which carry no unknown.
Definition at line 496 of file poisson.c.
|
static |
Coarse cell and interpolation direction along one axis for fine index f.
Each fine cell takes 3/4 of its parent coarse cell and 1/4 of the coarse neighbour on the side it lies towards. The first and last interior cells and semi-coarsened axes use the parent only, as does a neighbour that is solid on the coarse grid.
Definition at line 561 of file poisson.c.
|
static |
Prolongs a coarse-level correction to the next finer level (MatShell multiply).
The shell context is the fine-level UserCtx.
Definition at line 578 of file poisson.c.
|
static |
Restricts a fine-level residual to the next coarser level (MatShell multiply).
Each coarse cell averages the eight fine cells it covers, weighting each by its fluid fraction; coarse dummy and solid cells receive zero. The shell context is the coarse-level UserCtx.
Definition at line 658 of file poisson.c.
|
static |
Gives each block factor of a block-Jacobi level solver a small diagonal shift, so the factorization of a nearly singular Neumann block does not fail on a zero pivot.
Does nothing for any other preconditioner.
Definition at line 720 of file poisson.c.
|
static |
Builds the multigrid solver for block bi and stores it in the finest level.
Assembles the operator on every level, then configures the outer ps_ Krylov solver with a multiplicative V-cycle PCMG: shell restriction and interpolation between levels, block-Jacobi smoothers by default, a coarse solve limited to 40 iterations at relative tolerance 1e-8, and the Neumann null space on every level. PETSc options override these defaults.
Each smoother runs pre_sweeps iterations before the coarse correction and post_sweeps after it. When the two differ, the post-smoother is a separate solver that starts as a copy of the configured pre-smoother and reads further options under ps_mg_levels_N_up_. Everything built here depends only on the grid metrics, the solid field, and the boundary types; calling it again after one of those changes rebuilds the solver.
Definition at line 762 of file poisson.c.
|
static |
Prepares the convergence monitor for one solve and opens its log file on rank 0.
A fresh run's first open, which may be the initial condition's projection at step 0, truncates the log; every later open appends, and a continued run's first open records where it resumed.
Definition at line 872 of file poisson.c.
|
static |
Closes the log file opened by PoissonMultigrid_OpenConvergenceLog().
Definition at line 901 of file poisson.c.
| PetscErrorCode PoissonSolver_Multigrid | ( | UserMG * | usermg | ) |
Implementation of PoissonSolver_Multigrid().
Solves the pressure-correction equation for every block with geometric multigrid.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/poisson.h.
Definition at line 922 of file poisson.c.
|
static |
Offsets of the 19 stencil points, in the column order used to insert each row.
Definition at line 27 of file poisson.c.
|
static |
Field IDs of the face metric vectors, indexed as PoissonFaceMetrics.
Definition at line 38 of file poisson.c.
|
static |