29#define POISSON_SOLID_THRESHOLD 0.1
47 const PetscReal ***aj[3];
73 PetscInt b, PetscInt p, PetscInt n, PetscInt q)
75 return field[c[2] + (b == 2) * p + (n == 2) * q][c[1] + (b == 1) * p + (n == 1) * q][c[0] + (b == 0) * p + (n == 0) * q];
96 const PetscReal ***nvert,
const PetscInt c[3], PetscInt n, PetscInt t,
97 const PetscInt m[3],
const PetscBool periodic[3])
99 const PetscInt s = c[t];
100 const PetscReal solid_plus =
PoissonOperator_AtBN(nvert, c, t, 1, n, 0) +
PoissonOperator_AtBN(nvert, c, t, 1, n, 1);
101 const PetscReal solid_minus =
PoissonOperator_AtBN(nvert, c, t, -1, n, 0) +
PoissonOperator_AtBN(nvert, c, t, -1, n, 1);
127 const PetscReal ***nvert,
const PetscReal ***field,
const PetscInt c[3], PetscInt n, PetscInt t,
128 const PetscInt m[3],
const PetscBool periodic[3])
132 return (
PoissonOperator_AtBN(field, c, t, 0, n, 0) +
PoissonOperator_AtBN(field, c, t, 0, n, 1) -
133 PoissonOperator_AtBN(field, c, t, -1, n, 0) -
PoissonOperator_AtBN(field, c, t, -1, n, 1)) * 0.5;
135 return (
PoissonOperator_AtBN(field, c, t, 1, n, 0) +
PoissonOperator_AtBN(field, c, t, 1, n, 1) -
136 PoissonOperator_AtBN(field, c, t, 0, n, 0) -
PoissonOperator_AtBN(field, c, t, 0, n, 1)) * 0.5;
138 return (
PoissonOperator_AtBN(field, c, t, 1, n, 0) +
PoissonOperator_AtBN(field, c, t, 1, n, 1) -
139 PoissonOperator_AtBN(field, c, t, -1, n, 0) -
PoissonOperator_AtBN(field, c, t, -1, n, 1)) * 0.25;
163 const PoissonFaceMetrics *metrics,
const PetscReal ***nvert,
const PetscReal ***field,
164 const PetscInt c[3], PetscInt n,
const PetscInt m[3],
const PetscBool periodic[3])
166 const Cmpnts normal = metrics->
metric[n][n][c[2]][c[1]][c[0]];
167 const PetscReal aj = metrics->
aj[n][c[2]][c[1]][c[0]];
168 PetscReal dot[3], difference[3];
170 for (PetscInt b = 0; b < 3; b++) {
171 const Cmpnts base = metrics->
metric[n][b][c[2]][c[1]][c[0]];
172 dot[b] = base.
x * normal.
x + base.
y * normal.
y + base.
z * normal.
z;
177 return difference[0] * dot[0] * aj +
178 difference[1] * dot[1] * aj +
179 difference[2] * dot[2] * aj;
PetscErrorCode PoissonOperator_RestoreFaceMetrics(UserCtx *user, PoissonFaceMetrics *metrics)
Returns the arrays borrowed by PoissonOperator_GetFaceMetrics().
const PetscReal *** aj[3]
PetscReal weight
0.25 central, 0.5 one-sided, 0 when no fluid side remains.
const Cmpnts *** metric[3][3]
static PoissonTransverseKind PoissonOperator_TransverseKind(const PetscReal ***nvert, const PetscInt c[3], PetscInt n, PetscInt t, const PetscInt m[3], const PetscBool periodic[3])
Chooses the transverse stencil along axis t at the face between cell c and c + e_n.
PetscErrorCode AssemblePoissonOperator(UserCtx *user)
Assembles the pressure-correction operator on one multigrid level.
PoissonTransverseKind
The transverse stencils a face gradient can use; see PoissonOperator_TransverseKind().
@ POISSON_TRANSVERSE_NONE
Neither side available: the transverse term vanishes.
@ POISSON_TRANSVERSE_CENTRAL
Central over rows -1 and +1, weight 0.25.
@ POISSON_TRANSVERSE_LOWER
One-sided over rows -1 and 0, weight 0.5.
@ POISSON_TRANSVERSE_UPPER
One-sided over rows 0 and +1, weight 0.5.
PetscInt hi
Transverse offset of the added row pair.
static PetscReal PoissonOperator_FaceGradientFlux(const PoissonFaceMetrics *metrics, const PetscReal ***nvert, const PetscReal ***field, const PetscInt c[3], PetscInt n, const PetscInt m[3], const PetscBool periodic[3])
Gradient flux of a cell-centred field through the face between cell c and c + e_n: sum_b g_nb D_b(fie...
#define POISSON_SOLID_THRESHOLD
Cells whose nvert exceeds this value are solid.
PetscErrorCode PoissonOperator_GetFaceMetrics(UserCtx *user, PoissonFaceMetrics *metrics)
Borrows read access to the face metric arrays of user.
PetscErrorCode UpdatePressure(UserCtx *user)
Adds the pressure correction to the pressure, P += Phi, and refreshes both fields' periodic images an...
PetscErrorCode ProjectVelocity(UserCtx *user)
Corrects the contravariant flux with the gradient of Phi.
static PetscReal PoissonOperator_TransverseFieldDifference(const PetscReal ***nvert, const PetscReal ***field, const PetscInt c[3], PetscInt n, PetscInt t, const PetscInt m[3], const PetscBool periodic[3])
Transverse difference of field along axis t at the face between cell c and c + e_n: (sum of the row-p...
PetscErrorCode PoissonSolver_Multigrid(UserMG *usermg)
Solves the pressure-correction equation for every block with geometric multigrid.
PetscInt lo
Transverse offset of the subtracted row pair.
PetscErrorCode ComputePoissonRHS(UserCtx *user, Vec B)
Forms the right-hand side of the pressure-correction equation.
static PetscReal PoissonOperator_AtBN(const PetscReal ***field, const PetscInt c[3], PetscInt b, PetscInt p, PetscInt n, PetscInt q)
Value of a cell-centred array at c + p e_b + q e_n.
Read-only face metric arrays: metric[n][b] is F_b on the n-faces.
Transverse difference used at one face.
Main header file for a complex fluid dynamics solver.
#define PICURV_ALWAYS_INLINE
Forces inlining of a per-cell or per-face kernel whose size defeats the compiler's inlining heuristic...
A 3D point or vector with PetscScalar components.
User-defined context containing data specific to a single computational grid level.
User-level context for managing the entire multigrid hierarchy.