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 | PoissonTransverseDifference |
| Transverse difference used at one face. More... | |
| struct | PoissonFaceGradient |
| Everything needed to evaluate the gradient flux through one face. More... | |
| struct | PoissonFaceMetrics |
Read-only face metric arrays: metric[n][b] is F_b on the n-faces. More... | |
Macros | |
| #define | POISSON_SOLID_THRESHOLD 0.1 |
Cells whose nvert exceeds this value are solid. | |
| #define | __FUNCT__ "AssemblePoissonOperator" |
| #define | __FUNCT__ "ComputePoissonRHS" |
| #define | __FUNCT__ "UpdatePressure" |
| #define | __FUNCT__ "ProjectVelocity" |
| #define | __FUNCT__ "PoissonMultigrid_Build" |
| #define | __FUNCT__ "PoissonSolver_Multigrid" |
Functions | |
| static PetscInt | PoissonOperator_StencilSlot (const PetscInt d[3]) |
| Maps the 19 stencil offsets to their slots; corners of the 3x3x3 block are -1. | |
| static 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 void | PoissonOperator_PeriodicAxes (const UserCtx *user, PetscBool periodic[3]) |
| Records which axes are periodic, from the negative face of each axis. | |
| static PoissonTransverseDifference | PoissonOperator_TransverseDifference (const PetscReal ***nvert, const PetscInt c[3], PetscInt n, PetscInt t, const PetscInt m[3], const PetscBool periodic[3]) |
Chooses the transverse difference along axis t at the face between cell c and c + e_n. | |
| static 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 PetscErrorCode | PoissonOperator_GetFaceMetrics (UserCtx *user, PoissonFaceMetrics *metrics) |
Borrows read access to the face metric arrays of user. | |
| static PetscErrorCode | PoissonOperator_RestoreFaceMetrics (UserCtx *user, PoissonFaceMetrics *metrics) |
| Returns the arrays borrowed by PoissonOperator_GetFaceMetrics(). | |
| 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 PoissonTransverseDifference |
Transverse difference used at one face.
The difference is weight * (sum of Phi on row hi - sum of Phi on row lo), where a row is the pair of cells on either side of the face, displaced by the given offset along the transverse axis.
| Data Fields | ||
|---|---|---|
| PetscInt | lo | Transverse offset of the subtracted row pair. |
| PetscInt | hi | Transverse offset of the added row pair. |
| PetscReal | weight | 0.25 central, 0.5 one-sided, 0 when no fluid side remains. |
| 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. |
| struct PoissonFaceMetrics |
| #define POISSON_SOLID_THRESHOLD 0.1 |
|
static |
Maps the 19 stencil offsets to their slots; corners of the 3x3x3 block are -1.
Definition at line 75 of file poisson.c.
|
inlinestatic |
|
static |
|
static |
Chooses the transverse difference along axis t at the face between cell c and c + e_n.
The central difference averages the two cells beside the face over rows -1 and +1. When the +1 row is a non-periodic boundary layer or touches a solid cell, the difference falls back to rows -1 and 0, and symmetrically to rows 0 and +1; with neither side available the transverse term vanishes.
Definition at line 108 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.
Definition at line 140 of file poisson.c.
|
static |
Borrows read access to the face metric arrays of user.
Definition at line 161 of file poisson.c.
|
static |
Returns the arrays borrowed by PoissonOperator_GetFaceMetrics().
Definition at line 178 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 198 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 214 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 251 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 353 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 416 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 438 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 533 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 596 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 613 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 691 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 751 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 793 of file poisson.c.
|
static |
Prepares the convergence monitor for one solve and opens its log file on rank 0.
The first step of a fresh run truncates the log; every other step appends, and the first step of a continued run records where it resumed.
Definition at line 902 of file poisson.c.
|
static |
Closes the log file opened by PoissonMultigrid_OpenConvergenceLog().
Definition at line 931 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 952 of file poisson.c.
|
static |
Offsets of the 19 stencil points, in the column order used to insert each row.
Definition at line 29 of file poisson.c.
|
static |
Field IDs of the face metric vectors, indexed as PoissonFaceMetrics.
Definition at line 65 of file poisson.c.
|
static |