PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
rhs.c
Go to the documentation of this file.
1#include "rhs.h"
2#include "les.h" /* SymTensor kernels for the gradient (Clark) closure term */
3
4/** @brief Velocity at `c + p e_b + q e_n`, the Cartesian counterpart of PoissonOperator_AtBN(). */
5static PICURV_ALWAYS_INLINE Cmpnts RHSVelocityAtBN(const Cmpnts ***ucat, const PetscInt c[3],
6 PetscInt b, PetscInt p, PetscInt n, PetscInt q)
7{
8 return ucat[c[2] + (b == 2) * p + (n == 2) * q][c[1] + (b == 1) * p + (n == 1) * q][c[0] + (b == 0) * p + (n == 0) * q];
9}
10
11/** @brief Cartesian velocity at cell @p c displaced by @p d along axis @p n. */
12static inline Cmpnts RHSVelocityAt(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n, PetscInt d)
13{
14 return RHSVelocityAtBN(ucat, c, n, d, n, 0);
15}
16
17/**
18 * @brief QUICK flux through the face between cell @p c and `c + e_n`, upwinded by the sign of
19 * @p ucon. @p m1 and @p p2 are the offsets used for the far upwind cells, -1 and +2 in
20 * the interior; a one-sided face substitutes 0 or +1 for the side it cannot reach.
21 */
22static inline Cmpnts RHSQuickFlux(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n,
23 PetscReal ucon, PetscInt m1, PetscInt p2)
24{
25 const PetscReal coef = 0.125;
26 const PetscReal up = ucon + fabs(ucon), um = ucon - fabs(ucon);
27 const Cmpnts u0 = RHSVelocityAt(ucat, c, n, 0), u1 = RHSVelocityAt(ucat, c, n, 1);
28 const Cmpnts um1 = RHSVelocityAt(ucat, c, n, m1), up2 = RHSVelocityAt(ucat, c, n, p2);
29 Cmpnts f;
30
31 f.x = um * (coef * (-up2.x -2. * u1.x +3. * u0.x) +u1.x) +
32 up * (coef * (-um1.x -2. * u0.x +3. * u1.x) +u0.x);
33 f.y = um * (coef * (-up2.y -2. * u1.y +3. * u0.y) +u1.y) +
34 up * (coef * (-um1.y -2. * u0.y +3. * u1.y) +u0.y);
35 f.z = um * (coef * (-up2.z -2. * u1.z +3. * u0.z) +u1.z) +
36 up * (coef * (-um1.z -2. * u0.z +3. * u1.z) +u0.z);
37 return f;
38}
39
40/** @brief Central flux through the face between cell @p c and `c + e_n`. */
41static inline Cmpnts RHSCentralFlux(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n, PetscReal ucon)
42{
43 const Cmpnts u0 = RHSVelocityAt(ucat, c, n, 0), u1 = RHSVelocityAt(ucat, c, n, 1);
44 Cmpnts f;
45
46 f.x = ucon * ( u0.x + u1.x );
47 f.y = ucon * ( u0.y + u1.y );
48 f.z = ucon * ( u0.z + u1.z );
49 return f;
50}
51
52/**
53 * @brief Convective flux of Cartesian momentum through the face between cell @p c and
54 * `c + e_n`, carried by half the contravariant flux on that face.
55 *
56 * Interior faces use the central flux when @p central (central differencing or LES) and QUICK
57 * otherwise; with central differencing the two end faces of an axis are central as well. A face
58 * at the low end of an axis or behind a solid cell is QUICK one-sided toward +n, and one at the
59 * high end or ahead of a solid cell one-sided toward -n, except across a periodic seam, which
60 * keeps the full stencil. A face meeting none of these carries no flux.
61 */
62static inline Cmpnts RHSConvectiveFaceFlux(const Cmpnts ***ucat, const PetscReal ***nvert,
63 const PetscInt c[3], PetscInt n, PetscReal ucon,
64 PetscInt m, PetscBool periodic, PetscBool central)
65{
66 const PetscInt s = c[n];
67 const PetscReal nv_0 = nvert[c[2]][c[1]][c[0]];
68 const PetscReal nv_p = nvert[c[2] + (n == 2)][c[1] + (n == 1)][c[0] + (n == 0)];
69 const Cmpnts zero = {0.0, 0.0, 0.0};
70 /* The cell below exists in the local array everywhere but at s = 0 on a bounded axis. */
71 const PetscBool has_m = (PetscBool)(s > 0 || periodic);
72 const PetscReal nv_m = has_m ? nvert[c[2] - (n == 2)][c[1] - (n == 1)][c[0] - (n == 0)] : 0.0;
73 const PetscBool full_seam = (PetscBool)(periodic && nv_m < POISSON_SOLID_THRESHOLD && nv_p < POISSON_SOLID_THRESHOLD);
74
75 if (s > 0 && s < m - 2 && RHSConvectsAsFluid(nv_p) && RHSConvectsAsFluid(nv_m)) {
76 return central ? RHSCentralFlux(ucat, c, n, ucon) : RHSQuickFlux(ucat, c, n, ucon, -1, 2);
77 }
78 if (central && (s == 0 || s == m - 2) && RHSConvectsAsFluid(nv_p) && RHSConvectsAsFluid(nv_0)) {
79 return RHSCentralFlux(ucat, c, n, ucon);
80 }
81 if (s < m - 2 && (s == 0 || nv_m > POISSON_SOLID_THRESHOLD)) {
82 return RHSQuickFlux(ucat, c, n, ucon, (full_seam && s == 0) ? -1 : 0, 2);
83 }
84 if (s > 0 && (s == m - 2 || nv_p > POISSON_SOLID_THRESHOLD)) {
85 return RHSQuickFlux(ucat, c, n, ucon, -1, (full_seam && s == m - 2) ? 2 : 1);
86 }
87 return zero;
88}
89
90/**
91 * @brief Implementation of \ref ComputeConvection().
92 * @details Full API contract (arguments, ownership, side effects) is documented with
93 * the header declaration in `include/rhs.h`.
94 * @see ComputeConvection()
95 */
96PetscErrorCode ComputeConvection(UserCtx *user, Vec Ucont, Vec Ucat, Vec Conv)
97{
98 const SimCtx *simCtx = user->simCtx;
99 const DMDALocalInfo *info = &user->info;
100 const PetscInt m[3] = {info->mx, info->my, info->mz};
101 const PetscBool central = (PetscBool)(simCtx->les || simCtx->central);
102 PetscBool periodic[3];
103 PetscInt lo[3], hi[3];
104 Vec Fp[3];
105 Cmpnts ***fp[3], ***conv;
106 const Cmpnts ***ucont, ***ucat;
107 const PetscReal ***nvert;
108
109 PetscFunctionBeginUser;
111 GetOwnedInteriorCellBounds(info, lo, hi);
112 GetPeriodicAxes(user->simCtx, periodic);
113 PetscCall(PreparePeriodicQuickStencilFields(user, Ucat, user->lNvert));
114 PetscCall(VecSet(Conv, 0.0));
115 /* Face fluxes per axis, from fda's pool and zeroed as fresh vectors would be: faces that
116 carry no flux must read as zero. */
117 for (PetscInt n = 0; n < 3; n++) {
118 PetscCall(DMGetLocalVector(user->fda, &Fp[n]));
119 PetscCall(VecZeroEntries(Fp[n]));
120 PetscCall(DMDAVecGetArray(user->fda, Fp[n], &fp[n]));
121 }
122 PetscCall(DMDAVecGetArrayRead(user->fda, Ucont, (void *)&ucont));
123 PetscCall(DMDAVecGetArrayRead(user->fda, Ucat, (void *)&ucat));
124 PetscCall(DMDAVecGetArrayRead(user->da, user->lNvert, (void *)&nvert));
125 PetscCall(DMDAVecGetArray(user->fda, Conv, &conv));
126
127 /* Fluxes on every face of the owned cells: along n, from the face below the first cell. */
128 for (PetscInt n = 0; n < 3; n++) {
129 PetscInt flo[3] = {lo[0], lo[1], lo[2]};
130
131 flo[n] -= 1;
132 for (PetscInt k = flo[2]; k < hi[2]; k++) {
133 for (PetscInt j = flo[1]; j < hi[1]; j++) {
134 for (PetscInt i = flo[0]; i < hi[0]; i++) {
135 const PetscInt c[3] = {i, j, k};
136 const PetscReal ucon = (&ucont[k][j][i].x)[n] * 0.5;
137
138 fp[n][k][j][i] = RHSConvectiveFaceFlux(ucat, (const PetscReal ***)nvert, c, n, ucon,
139 m[n], periodic[n], central);
140 }
141 }
142 }
143 }
144
145 /* Convective term in Cartesian components: the net flux out of each cell. */
146 for (PetscInt k = lo[2]; k < hi[2]; k++) {
147 for (PetscInt j = lo[1]; j < hi[1]; j++) {
148 for (PetscInt i = lo[0]; i < hi[0]; i++) {
149 conv[k][j][i].x =
150 fp[0][k][j][i].x - fp[0][k][j][i-1].x +
151 fp[1][k][j][i].x - fp[1][k][j-1][i].x +
152 fp[2][k][j][i].x - fp[2][k-1][j][i].x;
153 conv[k][j][i].y =
154 fp[0][k][j][i].y - fp[0][k][j][i-1].y +
155 fp[1][k][j][i].y - fp[1][k][j-1][i].y +
156 fp[2][k][j][i].y - fp[2][k-1][j][i].y;
157 conv[k][j][i].z =
158 fp[0][k][j][i].z - fp[0][k][j][i-1].z +
159 fp[1][k][j][i].z - fp[1][k][j-1][i].z +
160 fp[2][k][j][i].z - fp[2][k-1][j][i].z;
161 }
162 }
163 }
164
165 PetscCall(DMDAVecRestoreArray(user->fda, Conv, &conv));
166 PetscCall(DMDAVecRestoreArrayRead(user->da, user->lNvert, (void *)&nvert));
167 PetscCall(DMDAVecRestoreArrayRead(user->fda, Ucat, (void *)&ucat));
168 PetscCall(DMDAVecRestoreArrayRead(user->fda, Ucont, (void *)&ucont));
169 for (PetscInt n = 0; n < 3; n++) {
170 PetscCall(DMDAVecRestoreArray(user->fda, Fp[n], &fp[n]));
171 PetscCall(DMRestoreLocalVector(user->fda, &Fp[n]));
172 }
173 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Convective term calculated.\n");
175 PetscFunctionReturn(0);
176}
177
178
179/** @brief `(u(c+hi e_b+e_n) + u(c+hi e_b) - u(c+lo e_b+e_n) - u(c+lo e_b)) * weight`, for @p diff's rows and weight. */
180static PICURV_ALWAYS_INLINE Cmpnts RHSTransverseVelocityDifference(const Cmpnts ***ucat, const PetscInt c[3],
181 PetscInt n, PetscInt b,
183{
184 const Cmpnts a1 = RHSVelocityAtBN(ucat, c, b, diff.hi, n, 1), a0 = RHSVelocityAtBN(ucat, c, b, diff.hi, n, 0);
185 const Cmpnts b1 = RHSVelocityAtBN(ucat, c, b, diff.lo, n, 1), b0 = RHSVelocityAtBN(ucat, c, b, diff.lo, n, 0);
186 Cmpnts d;
187
188 d.x = (a1.x + a0.x - b1.x - b0.x) * diff.weight;
189 d.y = (a1.y + a0.y - b1.y - b0.y) * diff.weight;
190 d.z = (a1.z + a0.z - b1.z - b0.z) * diff.weight;
191 return d;
192}
193
194/**
195 * @brief Velocity difference along transverse axis @p b on the face between cell @p c and
196 * `c + e_n`: the average over the two cells beside the face, one-sided away from a
197 * blanked solid cell. Each branch has constant offsets once @p n and @p b are constants.
198 */
199static PICURV_ALWAYS_INLINE Cmpnts RHSTransverseFaceDifference(const Cmpnts ***ucat, const PetscReal ***nvert,
200 const PetscInt c[3], PetscInt n, PetscInt b)
201{
202 static const PoissonTransverseDifference lower = {-1, 0, 0.5}, upper = {0, 1, 0.5}, central = {-1, 1, 0.25};
203
204 if (RHSIsBlankedSolid(PoissonOperator_AtBN(nvert, c, b, 1, n, 0)) || RHSIsBlankedSolid(PoissonOperator_AtBN(nvert, c, b, 1, n, 1)))
205 return RHSTransverseVelocityDifference(ucat, c, n, b, lower);
206 if (RHSIsBlankedSolid(PoissonOperator_AtBN(nvert, c, b, -1, n, 0)) || RHSIsBlankedSolid(PoissonOperator_AtBN(nvert, c, b, -1, n, 1)))
207 return RHSTransverseVelocityDifference(ucat, c, n, b, upper);
208 return RHSTransverseVelocityDifference(ucat, c, n, b, central);
209}
210
211/**
212 * @brief Velocity differences on the face between cell @p c and `c + e_n`, one per
213 * computational direction: across the face along n, and along each transverse axis.
214 */
215static PICURV_ALWAYS_INLINE void RHSFaceVelocityDifferences(const Cmpnts ***ucat, const PetscReal ***nvert,
216 const PetscInt c[3], PetscInt n, Cmpnts d[3])
217{
218 const Cmpnts u0 = RHSVelocityAtBN(ucat, c, n, 0, n, 0), u1 = RHSVelocityAtBN(ucat, c, n, 0, n, 1);
219
220 d[n].x = u1.x - u0.x; d[n].y = u1.y - u0.y; d[n].z = u1.z - u0.z;
221 d[(n + 1) % 3] = RHSTransverseFaceDifference(ucat, nvert, c, n, (n + 1) % 3);
222 d[(n + 2) % 3] = RHSTransverseFaceDifference(ucat, nvert, c, n, (n + 2) % 3);
223}
224
225/**
226 * @brief Viscous stress through the face between cell @p c and `c + e_n`, in Cartesian
227 * components, from the face differences @p d and the face metrics.
228 *
229 * With F_b the contravariant base vectors on the face and N = F_n its normal, the flux of each
230 * velocity component U is `(sum_b (F_b . N) dU/dxi_b + sum_c (sum_b dU_c/dxi_b F_b) . e_U N_c)
231 * aj`: the full stress, gradient plus transpose. The eddy viscosity @p nu_t carries it when
232 * LES is on, and the molecular viscosity @p nu is added; with the gradient (Clark) model the
233 * tensor `sum_b d_b d_b^T` contracted with N, over 12, is subtracted.
234 */
236 const PetscInt c[3], PetscInt n, PetscReal nu,
237 PetscReal nu_t, PetscBool les, PetscBool clark)
238{
239 const Cmpnts F0 = metrics->metric[n][0][c[2]][c[1]][c[0]];
240 const Cmpnts F1 = metrics->metric[n][1][c[2]][c[1]][c[0]];
241 const Cmpnts F2 = metrics->metric[n][2][c[2]][c[1]][c[0]];
242 const Cmpnts N = (n == 0) ? F0 : (n == 1) ? F1 : F2;
243 const PetscReal ajc = metrics->aj[n][c[2]][c[1]][c[0]];
244 const PetscReal g0 = F0.x * N.x + F0.y * N.y + F0.z * N.z;
245 const PetscReal g1 = F1.x * N.x + F1.y * N.y + F1.z * N.z;
246 const PetscReal g2 = F2.x * N.x + F2.y * N.y + F2.z * N.z;
247 /* r_<velocity component><Cartesian axis> = sum_b dU/dxi_b F_b[axis] */
248 const PetscReal r11 = d[0].x * F0.x + d[1].x * F1.x + d[2].x * F2.x;
249 const PetscReal r21 = d[0].y * F0.x + d[1].y * F1.x + d[2].y * F2.x;
250 const PetscReal r31 = d[0].z * F0.x + d[1].z * F1.x + d[2].z * F2.x;
251 const PetscReal r12 = d[0].x * F0.y + d[1].x * F1.y + d[2].x * F2.y;
252 const PetscReal r22 = d[0].y * F0.y + d[1].y * F1.y + d[2].y * F2.y;
253 const PetscReal r32 = d[0].z * F0.y + d[1].z * F1.y + d[2].z * F2.y;
254 const PetscReal r13 = d[0].x * F0.z + d[1].x * F1.z + d[2].x * F2.z;
255 const PetscReal r23 = d[0].y * F0.z + d[1].y * F1.z + d[2].y * F2.z;
256 const PetscReal r33 = d[0].z * F0.z + d[1].z * F1.z + d[2].z * F2.z;
257 const PetscReal ex = g0 * d[0].x + g1 * d[1].x + g2 * d[2].x + r11 * N.x + r21 * N.y + r31 * N.z;
258 const PetscReal ey = g0 * d[0].y + g1 * d[1].y + g2 * d[2].y + r12 * N.x + r22 * N.y + r32 * N.z;
259 const PetscReal ez = g0 * d[0].z + g1 * d[1].z + g2 * d[2].z + r13 * N.x + r23 * N.y + r33 * N.z;
260 Cmpnts f = {0.0, 0.0, 0.0};
261
262 if (les) {
263 f.x = ex * ajc * (nu_t);
264 f.y = ey * ajc * (nu_t);
265 f.z = ez * ajc * (nu_t);
266 }
267 f.x += ex * ajc * (nu);
268 f.y += ey * ajc * (nu);
269 f.z += ez * ajc * (nu);
270 if (clark) {
271 /* d_b is the velocity difference between neighbouring cells along direction b, so it
272 already carries that direction's spacing: sum_b d_b d_b^T is Delta_k^2 du_i/dx_k
273 du_j/dx_k as it stands, and no further cell extent belongs in it. */
274 const SymTensor gradient_tensor =
275 SymTensorCombine(1.0, SymTensorSelfOuter(d[0]), 1.0,
277 1.0, SymTensorSelfOuter(d[2])));
278 const Cmpnts gradient_flux = SymTensorTimesVector(gradient_tensor, N);
279
280 f.x -= gradient_flux.x / 12.;
281 f.y -= gradient_flux.y / 12.;
282 f.z -= gradient_flux.z / 12.;
283 }
284 return f;
285}
286
287/**
288 * @brief Viscous stresses on every face of orientation @p n of the owned cells, from the face
289 * below the first cell; @p n is a constant at each call, so each expands to its own loop.
290 */
292 const Cmpnts ***ucat, const PetscReal ***nvert,
293 const PetscReal ***lnu_t, const Cmpnts ***lwall_stress,
294 const PetscInt lo[3], const PetscInt hi[3],
295 const PetscInt m[3], PetscInt n, PetscBool les,
296 PetscBool clark, Cmpnts ***fp)
297{
298 const PetscBool wall_lo = BoundaryFaceHasWallShear(&user->boundary_faces[2 * n]);
299 const PetscBool wall_hi = BoundaryFaceHasWallShear(&user->boundary_faces[2 * n + 1]);
300 const PetscReal ren = user->simCtx->ren;
301 PetscInt flo[3] = {lo[0], lo[1], lo[2]};
302 PetscInt across[3] = {0, 0, 0};
303
304 flo[n] -= 1;
305 across[n] = 1;
306 for (PetscInt k = flo[2]; k < hi[2]; k++) {
307 for (PetscInt j = flo[1]; j < hi[1]; j++) {
308 for (PetscInt i = flo[0]; i < hi[0]; i++) {
309 const PetscInt c[3] = {i, j, k};
310 PetscReal nu = 1./ren, nu_t = 0;
311 Cmpnts d[3];
312
313 if ((wall_lo && c[n] == 0) || (wall_hi && c[n] == m[n] - 2)) {
314 /* A wall-modelled face carries the modelled stress itself, already
315 oriented as this face's flux and stored in the face's dummy cell
316 (ApplyWallFunction), times the face area: the law, not a gradient
317 across the resolved first cell, sets the wall shear. A wall-resolved
318 face keeps the molecular gradient flux; the subgrid stress vanishes at
319 a wall, so the eddy viscosity there is zero. */
320 if (lwall_stress) {
321 const Cmpnts N = metrics->metric[n][n][k][j][i];
322 const PetscReal area = PetscSqrtReal(N.x * N.x + N.y * N.y + N.z * N.z);
323 PetscInt w[3] = {i, j, k};
324 w[n] = (c[n] == 0) ? 0 : m[n] - 1;
325 fp[k][j][i].x = lwall_stress[w[2]][w[1]][w[0]].x * area;
326 fp[k][j][i].y = lwall_stress[w[2]][w[1]][w[0]].y * area;
327 fp[k][j][i].z = lwall_stress[w[2]][w[1]][w[0]].z * area;
328 continue;
329 }
330 } else if (les) {
331 nu_t = 0.5 * (lnu_t[k][j][i] + lnu_t[k + across[2]][j + across[1]][i + across[0]]);
332 }
333 RHSFaceVelocityDifferences(ucat, nvert, c, n, d);
334 fp[k][j][i] = RHSViscousFaceFlux(metrics, d, c, n, nu, nu_t, les, clark);
335 }
336 }
337 }
338}
339
340/**
341 * @brief Implementation of \ref ComputeViscous().
342 * @details Full API contract (arguments, ownership, side effects) is documented with
343 * the header declaration in `include/rhs.h`.
344 * @see ComputeViscous()
345 */
346PetscErrorCode ComputeViscous(UserCtx *user, Vec Ucat, Vec Visc)
347{
348 const SimCtx *simCtx = user->simCtx;
349 const DMDALocalInfo *info = &user->info;
350 const PetscInt m[3] = {info->mx, info->my, info->mz};
351 const PetscBool les = (PetscBool)(simCtx->les != 0);
352 const PetscBool clark = (PetscBool)(simCtx->les_gradient_model != 0);
353 PetscInt lo[3], hi[3];
354 PoissonFaceMetrics metrics;
355 Vec Fp[3];
356 Cmpnts ***fp[3], ***visc;
357 const Cmpnts ***ucat;
358 const PetscReal ***nvert, ***lnu_t = NULL;
359 const Cmpnts ***lwall_stress = NULL;
360
361 PetscFunctionBeginUser;
363 GetOwnedInteriorCellBounds(info, lo, hi);
364 PetscCall(VecSet(Visc, 0.0));
365 for (PetscInt n = 0; n < 3; n++) {
366 PetscCall(DMGetLocalVector(user->fda, &Fp[n]));
367 PetscCall(VecZeroEntries(Fp[n]));
368 PetscCall(DMDAVecGetArray(user->fda, Fp[n], &fp[n]));
369 }
370 PetscCall(PoissonOperator_GetFaceMetrics(user, &metrics));
371 PetscCall(DMDAVecGetArrayRead(user->fda, Ucat, (void *)&ucat));
372 PetscCall(DMDAVecGetArrayRead(user->da, user->lNvert, (void *)&nvert));
373 if (les) PetscCall(DMDAVecGetArrayRead(user->da, user->lNu_t, (void *)&lnu_t));
374 /* A wall model supplies its own face's flux: the modelled stress, in place of the
375 gradient flux across the resolved first cell. */
376 if (simCtx->wallfunction) PetscCall(DMDAVecGetArrayRead(user->fda, user->lWall_Stress, (void *)&lwall_stress));
377 PetscCall(DMDAVecGetArray(user->fda, Visc, &visc));
378
379 /* Stresses on every face of the owned cells, one constant direction per call. */
380 RHSViscousFluxesAlong(user, &metrics, ucat, nvert, lnu_t, lwall_stress, lo, hi, m, 0, les, clark, fp[0]);
381 RHSViscousFluxesAlong(user, &metrics, ucat, nvert, lnu_t, lwall_stress, lo, hi, m, 1, les, clark, fp[1]);
382 RHSViscousFluxesAlong(user, &metrics, ucat, nvert, lnu_t, lwall_stress, lo, hi, m, 2, les, clark, fp[2]);
383
384 /* Viscous term in Cartesian components: the net stress out of each cell. */
385 for (PetscInt k = lo[2]; k < hi[2]; k++) {
386 for (PetscInt j = lo[1]; j < hi[1]; j++) {
387 for (PetscInt i = lo[0]; i < hi[0]; i++) {
388 visc[k][j][i].x =
389 (fp[0][k][j][i].x - fp[0][k][j][i-1].x +
390 fp[1][k][j][i].x - fp[1][k][j-1][i].x +
391 fp[2][k][j][i].x - fp[2][k-1][j][i].x);
392 visc[k][j][i].y =
393 (fp[0][k][j][i].y - fp[0][k][j][i-1].y +
394 fp[1][k][j][i].y - fp[1][k][j-1][i].y +
395 fp[2][k][j][i].y - fp[2][k-1][j][i].y);
396 visc[k][j][i].z =
397 (fp[0][k][j][i].z - fp[0][k][j][i-1].z +
398 fp[1][k][j][i].z - fp[1][k][j-1][i].z +
399 fp[2][k][j][i].z - fp[2][k-1][j][i].z);
400 }
401 }
402 }
403
404 PetscCall(DMDAVecRestoreArray(user->fda, Visc, &visc));
405 if (lwall_stress) PetscCall(DMDAVecRestoreArrayRead(user->fda, user->lWall_Stress, (void *)&lwall_stress));
406 if (lnu_t) PetscCall(DMDAVecRestoreArrayRead(user->da, user->lNu_t, (void *)&lnu_t));
407 PetscCall(DMDAVecRestoreArrayRead(user->da, user->lNvert, (void *)&nvert));
408 PetscCall(DMDAVecRestoreArrayRead(user->fda, Ucat, (void *)&ucat));
409 PetscCall(PoissonOperator_RestoreFaceMetrics(user, &metrics));
410 for (PetscInt n = 0; n < 3; n++) {
411 PetscCall(DMDAVecRestoreArray(user->fda, Fp[n], &fp[n]));
412 PetscCall(DMRestoreLocalVector(user->fda, &Fp[n]));
413 }
414 LOG_ALLOW(GLOBAL, LOG_DEBUG, "Viscous terms calculated.\n");
416 PetscFunctionReturn(0);
417}
418
419/**
420 * @brief Implementation of \ref ComputeBodyForces().
421 * @details A body force added here follows the contract in include/BodyForces.h: this runs once
422 * per residual evaluation, not once per step, so a force that carries state across calls
423 * (a filter, ramp, moving average, or integral term) gates its update on `simCtx->step`.
424 * @see ComputeBodyForces()
425 */
426PetscErrorCode ComputeBodyForces(UserCtx *user, Vec Rct)
427{
428 PetscFunctionBeginUser;
430 /* The driven channel/pipe momentum source; it does nothing unless a driven face is active. */
431 PetscCall(ComputeDrivenChannelFlowSource(user, Rct));
433 PetscFunctionReturn(0);
434}
435
436/**
437 * @brief Contravariant cell-centre components of the spatial terms, Rct = aj F_n . (Visc - Conv),
438 * with each base vector F_n averaged from its two faces to the cell centre.
439 */
440static PetscErrorCode RHSContravariantSpatialTerms(UserCtx *user, Vec Conv, Vec Visc, Vec Rct)
441{
442 PetscInt lo[3], hi[3];
443 const Cmpnts ***csi, ***eta, ***zet, ***conv, ***visc;
444 const PetscReal ***aj;
445 Cmpnts ***rct;
446
447 PetscFunctionBeginUser;
449 GetOwnedInteriorCellBounds(&user->info, lo, hi);
450 PetscCall(DMDAVecGetArrayRead(user->fda, user->lCsi, (void *)&csi));
451 PetscCall(DMDAVecGetArrayRead(user->fda, user->lEta, (void *)&eta));
452 PetscCall(DMDAVecGetArrayRead(user->fda, user->lZet, (void *)&zet));
453 PetscCall(DMDAVecGetArrayRead(user->da, user->lAj, (void *)&aj));
454 PetscCall(DMDAVecGetArrayRead(user->fda, Conv, (void *)&conv));
455 PetscCall(DMDAVecGetArrayRead(user->fda, Visc, (void *)&visc));
456 PetscCall(DMDAVecGetArray(user->fda, Rct, &rct));
457 for (PetscInt k = lo[2]; k < hi[2]; k++) {
458 for (PetscInt j = lo[1]; j < hi[1]; j++) {
459 for (PetscInt i = lo[0]; i < hi[0]; i++) {
460 const Cmpnts rc = {visc[k][j][i].x - conv[k][j][i].x,
461 visc[k][j][i].y - conv[k][j][i].y,
462 visc[k][j][i].z - conv[k][j][i].z};
463 rct[k][j][i].x = aj[k][j][i] *
464 (0.5 * (csi[k][j][i].x + csi[k][j][i-1].x) * rc.x +
465 0.5 * (csi[k][j][i].y + csi[k][j][i-1].y) * rc.y +
466 0.5 * (csi[k][j][i].z + csi[k][j][i-1].z) * rc.z);
467 rct[k][j][i].y = aj[k][j][i] *
468 (0.5 * (eta[k][j][i].x + eta[k][j-1][i].x) * rc.x +
469 0.5 * (eta[k][j][i].y + eta[k][j-1][i].y) * rc.y +
470 0.5 * (eta[k][j][i].z + eta[k][j-1][i].z) * rc.z);
471 rct[k][j][i].z = aj[k][j][i] *
472 (0.5 * (zet[k][j][i].x + zet[k-1][j][i].x) * rc.x +
473 0.5 * (zet[k][j][i].y + zet[k-1][j][i].y) * rc.y +
474 0.5 * (zet[k][j][i].z + zet[k-1][j][i].z) * rc.z);
475 }
476 }
477 }
478 PetscCall(DMDAVecRestoreArray(user->fda, Rct, &rct));
479 PetscCall(DMDAVecRestoreArrayRead(user->fda, Visc, (void *)&visc));
480 PetscCall(DMDAVecRestoreArrayRead(user->fda, Conv, (void *)&conv));
481 PetscCall(DMDAVecRestoreArrayRead(user->da, user->lAj, (void *)&aj));
482 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->lZet, (void *)&zet));
483 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->lEta, (void *)&eta));
484 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->lCsi, (void *)&csi));
486 PetscFunctionReturn(0);
487}
488
489/** @brief Face residual of component @p n at cell @p c: the two-cell average of @p rct less
490 * the pressure-gradient flux through the face. */
491static PICURV_ALWAYS_INLINE PetscReal RHSFaceTerm(const PoissonFaceMetrics *metrics, const PetscReal ***nvert,
492 const PetscReal ***p, const Cmpnts ***rct, const PetscInt c[3],
493 PetscInt n, const PetscInt m[3], const PetscBool periodic[3])
494{
495 const PetscReal *own = &rct[c[2]][c[1]][c[0]].x;
496 const PetscReal *next = &rct[c[2] + (n == 2)][c[1] + (n == 1)][c[0] + (n == 0)].x;
497
498 return 0.5 * (own[n] + next[n]) - PoissonOperator_FaceGradientFlux(metrics, nvert, p, c, n, m, periodic);
499}
500
501/**
502 * @brief Face residual from the ghosted cell-centre terms: the average of @p Rct over the two
503 * cells beside each face, less the pressure-gradient flux through it.
504 *
505 * The flux is the projection's face gradient (PoissonOperator_FaceGradientFlux()) applied to
506 * `P`. Every interior face is set, and on a periodic axis also the seam face at index 0.
507 */
508static PetscErrorCode RHSFaceTermsWithPressureGradient(UserCtx *user, Vec Rct, Vec Rhs)
509{
510 const DMDALocalInfo *info = &user->info;
511 const PetscInt m[3] = {info->mx, info->my, info->mz};
512 const PetscInt start[3] = {info->xs, info->ys, info->zs};
513 PetscBool periodic[3];
514 PetscInt interior_lo[3], interior_hi[3];
515 PoissonFaceMetrics metrics;
516 const PetscReal ***nvert, ***p;
517 const Cmpnts ***rct;
518 Cmpnts ***rhs;
519
520 PetscFunctionBeginUser;
522 GetOwnedInteriorCellBounds(info, interior_lo, interior_hi);
523 GetPeriodicAxes(user->simCtx, periodic);
524 PetscCall(PoissonOperator_GetFaceMetrics(user, &metrics));
525 PetscCall(DMDAVecGetArrayRead(user->da, user->lNvert, (void *)&nvert));
526 PetscCall(DMDAVecGetArrayRead(user->da, user->lP, (void *)&p));
527 PetscCall(DMDAVecGetArrayRead(user->fda, Rct, (void *)&rct));
528 PetscCall(DMDAVecGetArray(user->fda, Rhs, &rhs));
529 /* One pass over the owned cells sets all three face components; with each direction a
530 constant, every call below compiles to its own straight-line stencil. */
531 for (PetscInt k = interior_lo[2]; k < interior_hi[2]; k++) {
532 for (PetscInt j = interior_lo[1]; j < interior_hi[1]; j++) {
533 for (PetscInt i = interior_lo[0]; i < interior_hi[0]; i++) {
534 const PetscInt c[3] = {i, j, k};
535
536 rhs[k][j][i].x = RHSFaceTerm(&metrics, nvert, p, rct, c, 0, m, periodic);
537 rhs[k][j][i].y = RHSFaceTerm(&metrics, nvert, p, rct, c, 1, m, periodic);
538 rhs[k][j][i].z = RHSFaceTerm(&metrics, nvert, p, rct, c, 2, m, periodic);
539 }
540 }
541 }
542 /* On a periodic axis the seam face at index 0 also carries an unknown. */
543 if (periodic[0] && start[0] == 0) {
544 for (PetscInt k = interior_lo[2]; k < interior_hi[2]; k++)
545 for (PetscInt j = interior_lo[1]; j < interior_hi[1]; j++) {
546 const PetscInt c[3] = {0, j, k};
547 rhs[k][j][0].x = RHSFaceTerm(&metrics, nvert, p, rct, c, 0, m, periodic);
548 }
549 }
550 if (periodic[1] && start[1] == 0) {
551 for (PetscInt k = interior_lo[2]; k < interior_hi[2]; k++)
552 for (PetscInt i = interior_lo[0]; i < interior_hi[0]; i++) {
553 const PetscInt c[3] = {i, 0, k};
554 rhs[k][0][i].y = RHSFaceTerm(&metrics, nvert, p, rct, c, 1, m, periodic);
555 }
556 }
557 if (periodic[2] && start[2] == 0) {
558 for (PetscInt j = interior_lo[1]; j < interior_hi[1]; j++)
559 for (PetscInt i = interior_lo[0]; i < interior_hi[0]; i++) {
560 const PetscInt c[3] = {i, j, 0};
561 rhs[0][j][i].z = RHSFaceTerm(&metrics, nvert, p, rct, c, 2, m, periodic);
562 }
563 }
564 PetscCall(DMDAVecRestoreArray(user->fda, Rhs, &rhs));
565 PetscCall(DMDAVecRestoreArrayRead(user->fda, Rct, (void *)&rct));
566 PetscCall(DMDAVecRestoreArrayRead(user->da, user->lP, (void *)&p));
567 PetscCall(DMDAVecRestoreArrayRead(user->da, user->lNvert, (void *)&nvert));
568 PetscCall(PoissonOperator_RestoreFaceMetrics(user, &metrics));
570 PetscFunctionReturn(0);
571}
572
573/**
574 * @brief Zeroes the residual rows that carry no unknown: the component a 2D run disables, every
575 * component of a solid cell, and each face component whose far cell is solid.
576 */
577static PetscErrorCode RHSZeroInactiveRows(UserCtx *user, Vec Rhs)
578{
579 const PetscInt two_d = user->simCtx->TwoD;
580 PetscInt lo[3], hi[3];
581 const PetscReal ***nvert;
582 Cmpnts ***rhs;
583
584 PetscFunctionBeginUser;
586 GetOwnedInteriorCellBounds(&user->info, lo, hi);
587 PetscCall(DMDAVecGetArrayRead(user->da, user->lNvert, (void *)&nvert));
588 PetscCall(DMDAVecGetArray(user->fda, Rhs, &rhs));
589 for (PetscInt k = lo[2]; k < hi[2]; k++) {
590 for (PetscInt j = lo[1]; j < hi[1]; j++) {
591 for (PetscInt i = lo[0]; i < hi[0]; i++) {
592 if (two_d == 1) rhs[k][j][i].x = 0.0;
593 else if (two_d == 2) rhs[k][j][i].y = 0.0;
594 else if (two_d == 3) rhs[k][j][i].z = 0.0;
595 if (nvert[k][j][i] > POISSON_SOLID_THRESHOLD) {
596 rhs[k][j][i].x = 0.0; rhs[k][j][i].y = 0.0; rhs[k][j][i].z = 0.0;
597 }
598 if (nvert[k][j][i+1] > POISSON_SOLID_THRESHOLD) rhs[k][j][i].x = 0.0;
599 if (nvert[k][j+1][i] > POISSON_SOLID_THRESHOLD) rhs[k][j][i].y = 0.0;
600 if (nvert[k+1][j][i] > POISSON_SOLID_THRESHOLD) rhs[k][j][i].z = 0.0;
601 }
602 }
603 }
604 PetscCall(DMDAVecRestoreArray(user->fda, Rhs, &rhs));
605 PetscCall(DMDAVecRestoreArrayRead(user->da, user->lNvert, (void *)&nvert));
607 PetscFunctionReturn(0);
608}
609
610/**
611 * @brief Implementation of \ref ComputeRHS().
612 * @details Full API contract (arguments, ownership, side effects) is documented with
613 * the header declaration in `include/rhs.h`.
614 * @see ComputeRHS()
615 */
616PetscErrorCode ComputeRHS(UserCtx *user, Vec Rhs)
617{
618 const FieldId cell_fields[] = {FIELD_ID_UCAT};
619 Vec Conv, Visc, Rct;
620
621 PetscFunctionBeginUser;
623 LOG_ALLOW(LOCAL, LOG_DEBUG, "Rank %d, Block %" PetscInt_FMT ": Computing RHS...\n",
624 user->simCtx->rank, user->_this);
625 /* Work vectors from fda's pool: the residual is evaluated many times per step, and
626 allocating them each time costs more than zeroing them. ComputeConvection() and
627 ComputeViscous() zero their own outputs; the rest are zeroed here, as fresh vectors
628 would be. */
629 PetscCall(DMGetLocalVector(user->fda, &Conv));
630 PetscCall(DMGetLocalVector(user->fda, &Visc));
631 PetscCall(DMGetLocalVector(user->fda, &Rct)); PetscCall(VecZeroEntries(Rct));
632
633 /* Cartesian velocity, with its periodic copies and ghosts, from the contravariant flux. */
634 PetscCall(Contra2Cart(user));
635 PetscCall(SynchronizePeriodicCellFields(user, 1, cell_fields));
636 PetscCall(UpdateLocalGhosts(user, FIELD_ID_UCAT));
637
638 /* Spatial terms in Cartesian components at cell centres, then contravariant. */
639 LOG_ALLOW(LOCAL, LOG_DEBUG, " Calculating convective terms...\n");
640 PetscCall(ComputeConvection(user, user->lUcont, user->lUcat, Conv));
641 if (!user->simCtx->invicid) {
642 LOG_ALLOW(LOCAL, LOG_DEBUG, " Calculating viscous terms...\n");
643 PetscCall(ComputeViscous(user, user->lUcat, Visc));
644 } else {
645 PetscCall(VecZeroEntries(Visc));
646 }
647 LOG_ALLOW(LOCAL, LOG_DEBUG, " Converting Cartesian RHS to Contravariant RHS...\n");
648 PetscCall(RHSContravariantSpatialTerms(user, Conv, Visc, Rct));
649 PetscCall(ComputeBodyForces(user, Rct));
650 PetscCall(SynchronizePeriodicLocalStaggeredField(user, Rct));
651
652 /* Face residual: averaged spatial terms less the pressure gradient, then inactive rows. */
653 LOG_ALLOW(LOCAL, LOG_DEBUG, " Adding pressure gradient term to RHS...\n");
654 PetscCall(RHSFaceTermsWithPressureGradient(user, Rct, Rhs));
655 PetscCall(RHSZeroInactiveRows(user, Rhs));
656
657 PetscCall(DMRestoreLocalVector(user->fda, &Rct));
658 PetscCall(DMRestoreLocalVector(user->fda, &Visc));
659 PetscCall(DMRestoreLocalVector(user->fda, &Conv));
660 LOG_ALLOW(LOCAL, LOG_DEBUG, "Rank %d, Block %" PetscInt_FMT ": RHS computation complete.\n",
661 user->simCtx->rank, user->_this);
663 PetscFunctionReturn(0);
664}
PetscErrorCode ComputeDrivenChannelFlowSource(UserCtx *user, Vec Rct)
Applies a momentum source term to drive flow in a periodic channel or pipe.
Definition BodyForces.c:38
PetscErrorCode PreparePeriodicQuickStencilFields(UserCtx *user, Vec local_vector_field, Vec local_scalar_field)
Repairs the outer adjacent periodic ghosts used by QUICK cell stencils.
PetscBool BoundaryFaceHasWallShear(const BoundaryFaceConfig *face)
Reports whether a boundary face is a wall that exerts shear on the flow.
Definition Boundaries.c:9
PetscErrorCode SynchronizePeriodicLocalStaggeredField(UserCtx *user, Vec local_field)
Synchronizes one local-only component-staggered periodic work field.
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_UCAT
SymTensor SymTensorCombine(PetscReal a, SymTensor x, PetscReal b, SymTensor y)
Forms the linear combination a*x + b*y.
Definition les.c:151
SymTensor SymTensorSelfOuter(Cmpnts v)
Forms a symmetric tensor from a vector's outer product with itself.
Definition les.c:132
static Cmpnts SymTensorTimesVector(SymTensor t, Cmpnts v)
Applies a symmetric tensor to a vector, returning t_ij v_j.
Definition les.h:82
#define LOCAL
Logging scope definitions for controlling message output.
Definition logging.h:45
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:46
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
Definition logging.h:214
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:1029
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
Definition logging.h:1000
PetscErrorCode PoissonOperator_RestoreFaceMetrics(UserCtx *user, PoissonFaceMetrics *metrics)
Returns the arrays borrowed by PoissonOperator_GetFaceMetrics().
Definition poisson.c:171
const PetscReal *** aj[3]
Definition poisson.h:47
PetscReal weight
0.25 central, 0.5 one-sided, 0 when no fluid side remains.
Definition poisson.h:41
const Cmpnts *** metric[3][3]
Definition poisson.h:46
PetscInt hi
Transverse offset of the added row pair.
Definition poisson.h:40
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...
Definition poisson.h:162
#define POISSON_SOLID_THRESHOLD
Cells whose nvert exceeds this value are solid.
Definition poisson.h:29
PetscErrorCode PoissonOperator_GetFaceMetrics(UserCtx *user, PoissonFaceMetrics *metrics)
Borrows read access to the face metric arrays of user.
Definition poisson.c:147
PetscInt lo
Transverse offset of the subtracted row pair.
Definition poisson.h:39
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.
Definition poisson.h:72
Read-only face metric arrays: metric[n][b] is F_b on the n-faces.
Definition poisson.h:45
Transverse difference used at one face.
Definition poisson.h:38
PetscErrorCode ComputeBodyForces(UserCtx *user, Vec Rct)
Implementation of ComputeBodyForces().
Definition rhs.c:426
static PetscErrorCode RHSZeroInactiveRows(UserCtx *user, Vec Rhs)
Zeroes the residual rows that carry no unknown: the component a 2D run disables, every component of a...
Definition rhs.c:577
static PICURV_ALWAYS_INLINE Cmpnts RHSTransverseFaceDifference(const Cmpnts ***ucat, const PetscReal ***nvert, const PetscInt c[3], PetscInt n, PetscInt b)
Velocity difference along transverse axis b on the face between cell c and c + e_n: the average over ...
Definition rhs.c:199
static PICURV_ALWAYS_INLINE void RHSFaceVelocityDifferences(const Cmpnts ***ucat, const PetscReal ***nvert, const PetscInt c[3], PetscInt n, Cmpnts d[3])
Velocity differences on the face between cell c and c + e_n, one per computational direction: across ...
Definition rhs.c:215
PetscErrorCode ComputeConvection(UserCtx *user, Vec Ucont, Vec Ucat, Vec Conv)
Implementation of ComputeConvection().
Definition rhs.c:96
static Cmpnts RHSQuickFlux(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n, PetscReal ucon, PetscInt m1, PetscInt p2)
QUICK flux through the face between cell c and c + e_n, upwinded by the sign of ucon.
Definition rhs.c:22
static PetscErrorCode RHSContravariantSpatialTerms(UserCtx *user, Vec Conv, Vec Visc, Vec Rct)
Contravariant cell-centre components of the spatial terms, Rct = aj F_n .
Definition rhs.c:440
static PICURV_ALWAYS_INLINE Cmpnts RHSViscousFaceFlux(const PoissonFaceMetrics *metrics, const Cmpnts d[3], const PetscInt c[3], PetscInt n, PetscReal nu, PetscReal nu_t, PetscBool les, PetscBool clark)
Viscous stress through the face between cell c and c + e_n, in Cartesian components,...
Definition rhs.c:235
static Cmpnts RHSCentralFlux(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n, PetscReal ucon)
Central flux through the face between cell c and c + e_n.
Definition rhs.c:41
static PICURV_ALWAYS_INLINE PetscReal RHSFaceTerm(const PoissonFaceMetrics *metrics, const PetscReal ***nvert, const PetscReal ***p, const Cmpnts ***rct, const PetscInt c[3], PetscInt n, const PetscInt m[3], const PetscBool periodic[3])
Face residual of component n at cell c: the two-cell average of rct less the pressure-gradient flux t...
Definition rhs.c:491
static PICURV_ALWAYS_INLINE Cmpnts RHSVelocityAtBN(const Cmpnts ***ucat, const PetscInt c[3], PetscInt b, PetscInt p, PetscInt n, PetscInt q)
Velocity at c + p e_b + q e_n, the Cartesian counterpart of PoissonOperator_AtBN().
Definition rhs.c:5
static Cmpnts RHSConvectiveFaceFlux(const Cmpnts ***ucat, const PetscReal ***nvert, const PetscInt c[3], PetscInt n, PetscReal ucon, PetscInt m, PetscBool periodic, PetscBool central)
Convective flux of Cartesian momentum through the face between cell c and c + e_n,...
Definition rhs.c:62
PetscErrorCode ComputeViscous(UserCtx *user, Vec Ucat, Vec Visc)
Implementation of ComputeViscous().
Definition rhs.c:346
static PICURV_ALWAYS_INLINE Cmpnts RHSTransverseVelocityDifference(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n, PetscInt b, PoissonTransverseDifference diff)
(u(c+hi e_b+e_n) + u(c+hi e_b) - u(c+lo e_b+e_n) - u(c+lo e_b)) * weight, for diff's rows and weight.
Definition rhs.c:180
static PetscErrorCode RHSFaceTermsWithPressureGradient(UserCtx *user, Vec Rct, Vec Rhs)
Face residual from the ghosted cell-centre terms: the average of Rct over the two cells beside each f...
Definition rhs.c:508
static Cmpnts RHSVelocityAt(const Cmpnts ***ucat, const PetscInt c[3], PetscInt n, PetscInt d)
Cartesian velocity at cell c displaced by d along axis n.
Definition rhs.c:12
static PICURV_ALWAYS_INLINE void RHSViscousFluxesAlong(const UserCtx *user, const PoissonFaceMetrics *metrics, const Cmpnts ***ucat, const PetscReal ***nvert, const PetscReal ***lnu_t, const Cmpnts ***lwall_stress, const PetscInt lo[3], const PetscInt hi[3], const PetscInt m[3], PetscInt n, PetscBool les, PetscBool clark, Cmpnts ***fp)
Viscous stresses on every face of orientation n of the owned cells, from the face below the first cel...
Definition rhs.c:291
PetscErrorCode ComputeRHS(UserCtx *user, Vec Rhs)
Implementation of ComputeRHS().
Definition rhs.c:616
static PetscBool RHSIsBlankedSolid(PetscReal nvert)
Whether a cell is a blanked solid cell, which ComputeViscous()'s transverse differences avoid with a ...
Definition rhs.h:30
static PetscBool RHSConvectsAsFluid(PetscReal nvert)
Whether a cell takes part in convection: fluid, or a blanked inner-body cell.
Definition rhs.h:19
static void GetOwnedInteriorCellBounds(const DMDALocalInfo *info, PetscInt lo[3], PetscInt hi[3])
Index bounds of the interior cells this rank owns in the solver's cell-centred layout: the owned rang...
Definition setup.h:378
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
Definition setup.c:3313
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
Definition setup.c:2593
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
Definition setup.h:361
#define PICURV_ALWAYS_INLINE
Forces inlining of a per-cell or per-face kernel whose size defeats the compiler's inlining heuristic...
Definition variables.h:65
PetscInt TwoD
Definition variables.h:951
PetscMPIInt rank
Definition variables.h:919
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:1182
Vec lNvert
Definition variables.h:1197
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:1160
PetscReal ren
Definition variables.h:965
PetscInt _this
Definition variables.h:1175
PetscScalar x
Definition variables.h:145
PetscInt invicid
Definition variables.h:951
Vec lNu_t
Definition variables.h:1259
PetscInt les_gradient_model
Add the Clark gradient (tensor-diffusivity) term to the viscous flux.
Definition variables.h:1045
PetscScalar z
Definition variables.h:145
PetscInt wallfunction
Enable wall functions on WALL faces.
Definition variables.h:1042
Vec lWall_Stress
Definition variables.h:1193
PetscInt central
Definition variables.h:963
Vec lUcont
Definition variables.h:1197
DMDALocalInfo info
Definition variables.h:1169
Vec lUcat
Definition variables.h:1197
PetscScalar y
Definition variables.h:145
PetscInt les
Active LES closure; an LESModelType value.
Definition variables.h:1041
A 3D point or vector with PetscScalar components.
Definition variables.h:144
The master context for the entire simulation.
Definition variables.h:916
A symmetric second-order tensor stored by its six independent components.
Definition variables.h:161
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)