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