PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
poisson.h
Go to the documentation of this file.
1#ifndef POISSON_H
2#define POISSON_H
3
4#include "variables.h"
5#include "Boundaries.h"
6
7/**
8 * @file poisson.h
9 * @brief Pressure-Poisson projection: the multigrid pressure-correction solve, the
10 * pressure update, and the velocity correction that makes `Ucont` divergence-free.
11 *
12 * The discrete operator, the right-hand side, and the projection gradient are built from
13 * one face-gradient definition, so the Laplacian the solver inverts is exactly the
14 * divergence of the gradient the projection applies.
15 *
16 * Every masked operation reads the solid field from the `UserCtx` of the level it acts
17 * on (`lNvert`). Solid cells are excluded from the operator, the right-hand side, the
18 * projection, and the multigrid transfers; cells next to a solid face use one-sided
19 * transverse differences.
20 */
21
22/**
23 * @brief Solves the pressure-correction equation for every block with geometric multigrid.
24 *
25 * On the first call for a block, assembles the operator on every multigrid level and
26 * builds the outer Krylov solver with its `PCMG` preconditioner, grid transfers, level
27 * smoothers, coarse solve, and null space. The solver is kept in the finest level's
28 * `UserCtx::ksp` and reused on every later call; it is destroyed with the context.
29 *
30 * Each call refreshes the ghosted contravariant flux, forms the right-hand side, solves
31 * for `Phi` on the finest level, and appends the iteration history to
32 * `Poisson_Solver_Convergence_History_Block_<bi>.log` in the run's log directory.
33 *
34 * Solver controls are read from PETSc options under the `ps_` prefix
35 * (`-ps_ksp_*`, `-ps_mg_levels_N_*`, `-ps_mg_coarse_*`) when the solver is built.
36 *
37 * @param[in,out] usermg Multigrid hierarchy; the finest level's `Phi` receives the solution.
38 * @return PETSc error code. A non-finite residual or a preconditioner that could not be
39 * built stops the run with PETSC_ERR_NOT_CONVERGED.
40 */
41extern PetscErrorCode PoissonSolver_Multigrid(UserMG *usermg);
42
43/**
44 * @brief Assembles the pressure-correction operator on one multigrid level.
45 *
46 * Allocates `user->A` on the first call and reassembles its entries on later calls into
47 * the same nonzero structure. Fluid rows carry the 19-point curvilinear Laplacian;
48 * dummy rows on the domain boundary and solid rows are identities. Non-periodic faces
49 * are homogeneous Neumann; periodic faces wrap to the opposite interior layer.
50 *
51 * @param[in,out] user Level context supplying metrics, `lNvert`, and boundary types.
52 * @return PETSc error code.
53 */
54extern PetscErrorCode AssemblePoissonOperator(UserCtx *user);
55
56/**
57 * @brief Forms the right-hand side of the pressure-correction equation.
58 *
59 * Writes the scaled divergence of the ghosted contravariant flux `lUcont` into @p B,
60 * zero on dummy and solid cells, and stores its domain integral in
61 * `SimCtx::poissonSourceImbalance`.
62 *
63 * @param[in] user Finest-level context.
64 * @param[out] B Right-hand-side vector on `user->da`.
65 * @return PETSc error code.
66 */
67extern PetscErrorCode ComputePoissonRHS(UserCtx *user, Vec B);
68
69/**
70 * @brief Adds the pressure correction to the pressure, `P += Phi`, and refreshes both
71 * fields' periodic images and ghosts.
72 * @param[in,out] user Block context holding `P` and `Phi`.
73 * @return PETSc error code.
74 */
75extern PetscErrorCode UpdatePressure(UserCtx *user);
76
77/**
78 * @brief Corrects the contravariant flux with the gradient of `Phi`.
79 *
80 * Subtracts `dt / COEF_TIME_ACCURACY` times the face pressure-gradient flux from every
81 * fluid face of `Ucont`, then refreshes the periodic images, reconstructs the Cartesian
82 * velocity, and finalizes the cell fields that depend on it.
83 *
84 * @param[in,out] user Block context; reads the ghosted `lPhi`.
85 * @return PETSc error code.
86 */
87extern PetscErrorCode ProjectVelocity(UserCtx *user);
88
89#endif /* POISSON_H */
PetscErrorCode AssemblePoissonOperator(UserCtx *user)
Assembles the pressure-correction operator on one multigrid level.
Definition poisson.c:251
PetscErrorCode UpdatePressure(UserCtx *user)
Adds the pressure correction to the pressure, P += Phi, and refreshes both fields' periodic images an...
Definition poisson.c:416
PetscErrorCode ProjectVelocity(UserCtx *user)
Corrects the contravariant flux with the gradient of Phi.
Definition poisson.c:438
PetscErrorCode PoissonSolver_Multigrid(UserMG *usermg)
Solves the pressure-correction equation for every block with geometric multigrid.
Definition poisson.c:952
PetscErrorCode ComputePoissonRHS(UserCtx *user, Vec B)
Forms the right-hand side of the pressure-correction equation.
Definition poisson.c:353
Main header file for a complex fluid dynamics solver.
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1074
User-level context for managing the entire multigrid hierarchy.
Definition variables.h:735