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" // Provides definitions for UserCtx, UserMG, Vec, Mat, etc.
5#include "Metric.h" // Provides some primitives necessary.
6
7/*================================================================================*
8 * HIGH-LEVEL POISSON SOLVER *
9 *================================================================================*/
10
11/**
12 * @brief Solves the pressure-Poisson equation using a geometric multigrid method.
13 *
14 * This function orchestrates the entire multigrid V-cycle for the pressure
15 * correction equation. It assembles the Laplacian matrix on all grid levels,
16 * sets up the KSP solvers, smoothers, restriction/interpolation operators,
17 * and executes the solve.
18 *
19 * @param usermg The UserMG context containing the entire multigrid hierarchy.
20 * @return PetscErrorCode 0 on success.
21 */
22extern PetscErrorCode PoissonSolver_MG(UserMG *usermg);
23
24
25/*================================================================================*
26 * CORE COMPONENTS OF THE POISSON SOLVER *
27 *================================================================================*/
28
29/**
30 * @brief Assembles the Left-Hand-Side (LHS) matrix (Laplacian operator) for the
31 * Poisson equation on a single grid level.
32 *
33 * @param user The UserCtx for the grid level on which to assemble the matrix.
34 * @return PetscErrorCode 0 on success.
35 */
36extern PetscErrorCode PoissonLHSNew(UserCtx *user);
37
38/**
39 * @brief Computes the Right-Hand-Side (RHS) of the Poisson equation, which is
40 * the divergence of the intermediate velocity field.
41 *
42 * @param user The UserCtx for the grid level.
43 * @param B The PETSc Vec where the RHS result will be stored.
44 * @return PetscErrorCode 0 on success.
45 */
46extern PetscErrorCode PoissonRHS(UserCtx *user, Vec B);
47
48/**
49 * @brief Updates the pressure field `P` with the pressure correction `Phi`
50 * computed by the Poisson solver. (P = P + Phi)
51 *
52 * @param user The UserCtx containing the P and Phi vectors.
53 * @return PetscErrorCode 0 on success.
54 */
55extern PetscErrorCode UpdatePressure(UserCtx *user);
56
57/**
58 * @brief Corrects the contravariant velocity field `Ucont` to be divergence-free
59 * using the gradient of the pressure correction field `Phi`.
60 *
61 * @param user The UserCtx containing the Ucont and Phi vectors.
62 * @return PetscErrorCode 0 on success.
63 */
64extern PetscErrorCode Projection(UserCtx *user);
65
66
67/*================================================================================*
68 * MULTIGRID & NULL SPACE HELPERS *
69 *================================================================================*/
70
71/**
72 * @brief The callback function for PETSc's MatNullSpace object.
73 *
74 * This function removes the null space from the Poisson solution vector by
75 * ensuring the average pressure is zero, which is necessary for problems with
76 * pure Neumann boundary conditions.
77 *
78 * @param nullsp The MatNullSpace context.
79 * @param X The vector to be corrected.
80 * @param ctx A void pointer to the UserCtx.
81 * @return PetscErrorCode 0 on success.
82 */
83extern PetscErrorCode PoissonNullSpaceFunction(MatNullSpace nullsp, Vec X, void *ctx);
84
85/**
86 * @brief The callback function for the multigrid restriction operator (MatShell).
87 *
88 * Defines the fine-to-coarse grid transfer for the Poisson residual.
89 *
90 * @param A The shell matrix context.
91 * @param X The fine-grid source vector.
92 * @param F The coarse-grid destination vector.
93 * @return PetscErrorCode 0 on success.
94 */
95extern PetscErrorCode MyRestriction(Mat A, Vec X, Vec F);
96
97/**
98 * @brief The callback function for the multigrid interpolation operator (MatShell).
99 *
100 * Defines the coarse-to-fine grid transfer for the pressure correction.
101 *
102 * @param A The shell matrix context.
103 * @param X The coarse-grid source vector.
104 * @param F The fine-grid destination vector.
105 * @return PetscErrorCode 0 on success.
106 */
107extern PetscErrorCode MyInterpolation(Mat A, Vec X, Vec F);
108
109
110/*================================================================================*
111 * IMMERSED BOUNDARY RELATED HELPERS (Optional) *
112 *================================================================================*/
113
114// These functions are called by the Poisson solver but are specific to the
115// immersed boundary method. It is good practice to declare them here as they
116// are part of the Poisson module's dependencies.
117
118/**
119 * @brief Calculates the net flux across the immersed boundary surface.
120 * @param user The UserCtx for the grid level.
121 * @param ibm_Flux (Output) The calculated net flux.
122 * @param ibm_Area (Output) The total surface area of the IB.
123 * @param flg A flag controlling the correction behavior.
124 * @return PetscErrorCode 0 on success.
125 */
126extern PetscErrorCode VolumeFlux(UserCtx *user, PetscReal *ibm_Flux, PetscReal *ibm_Area, PetscInt flg);
127
128/**
129 * @brief A specialized version of VolumeFlux, likely for reversed normals.
130 * @param user The UserCtx for the grid level.
131 * @param ibm_Flux (Output) The calculated net flux.
132 * @param ibm_Area (Output) The total surface area of the IB.
133 * @param flg A flag controlling the correction behavior.
134 * @return PetscErrorCode 0 on success.
135 */
136extern PetscErrorCode VolumeFlux_rev(UserCtx *user, PetscReal *ibm_Flux, PetscReal *ibm_Area, PetscInt flg);
137
138
139#endif // POISSON_H
PetscErrorCode PoissonNullSpaceFunction(MatNullSpace nullsp, Vec X, void *ctx)
The callback function for PETSc's MatNullSpace object.
Definition poisson.c:1686
PetscErrorCode PoissonLHSNew(UserCtx *user)
Assembles the Left-Hand-Side (LHS) matrix (Laplacian operator) for the Poisson equation on a single g...
Definition poisson.c:2207
PetscErrorCode Projection(UserCtx *user)
Corrects the contravariant velocity field Ucont to be divergence-free using the gradient of the press...
Definition poisson.c:948
PetscErrorCode VolumeFlux_rev(UserCtx *user, PetscReal *ibm_Flux, PetscReal *ibm_Area, PetscInt flg)
A specialized version of VolumeFlux, likely for reversed normals.
Definition poisson.c:2891
PetscErrorCode MyRestriction(Mat A, Vec X, Vec F)
The callback function for the multigrid restriction operator (MatShell).
Definition poisson.c:2061
PetscErrorCode UpdatePressure(UserCtx *user)
Updates the pressure field P with the pressure correction Phi computed by the Poisson solver.
Definition poisson.c:1502
PetscErrorCode VolumeFlux(UserCtx *user, PetscReal *ibm_Flux, PetscReal *ibm_Area, PetscInt flg)
Calculates the net flux across the immersed boundary surface.
Definition poisson.c:3133
PetscErrorCode PoissonRHS(UserCtx *user, Vec B)
Computes the Right-Hand-Side (RHS) of the Poisson equation, which is the divergence of the intermedia...
Definition poisson.c:2810
PetscErrorCode MyInterpolation(Mat A, Vec X, Vec F)
The callback function for the multigrid interpolation operator (MatShell).
Definition poisson.c:1879
PetscErrorCode PoissonSolver_MG(UserMG *usermg)
Solves the pressure-Poisson equation using a geometric multigrid method.
Definition poisson.c:3959
Main header file for a complex fluid dynamics solver.
User-defined context containing data specific to a single computational grid level.
Definition variables.h:661
User-level context for managing the entire multigrid hierarchy.
Definition variables.h:433