6 PetscInt b, PetscInt p, PetscInt n, PetscInt q)
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];
23 PetscReal ucon, PetscInt m1, PetscInt p2)
25 const PetscReal coef = 0.125;
26 const PetscReal up = ucon + fabs(ucon), um = ucon - fabs(ucon);
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);
46 f.
x = ucon * ( u0.
x + u1.x );
47 f.
y = ucon * ( u0.
y + u1.y );
48 f.
z = ucon * ( u0.
z + u1.z );
63 const PetscInt c[3], PetscInt n, PetscReal ucon,
64 PetscInt m, PetscBool periodic, PetscBool central)
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};
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;
82 return RHSQuickFlux(ucat, c, n, ucon, (full_seam && s == 0) ? -1 : 0, 2);
85 return RHSQuickFlux(ucat, c, n, ucon, -1, (full_seam && s == m - 2) ? 2 : 1);
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];
106 const Cmpnts ***ucont, ***ucat;
107 const PetscReal ***nvert;
109 PetscFunctionBeginUser;
114 PetscCall(VecSet(Conv, 0.0));
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]));
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));
128 for (PetscInt n = 0; n < 3; n++) {
129 PetscInt flo[3] = {lo[0], lo[1], lo[2]};
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;
139 m[n], periodic[n], central);
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++) {
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;
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;
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;
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]));
175 PetscFunctionReturn(0);
181 PetscInt n, PetscInt b,
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);
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;
200 const PetscInt c[3], PetscInt n, PetscInt b)
204 if (
RHSIsBlankedSolid(
PoissonOperator_AtBN(nvert, c, b, 1, n, 0)) ||
RHSIsBlankedSolid(
PoissonOperator_AtBN(nvert, c, b, 1, n, 1)))
206 if (
RHSIsBlankedSolid(
PoissonOperator_AtBN(nvert, c, b, -1, n, 0)) ||
RHSIsBlankedSolid(
PoissonOperator_AtBN(nvert, c, b, -1, n, 1)))
216 const PetscInt c[3], PetscInt n,
Cmpnts d[3])
218 const Cmpnts u0 =
RHSVelocityAtBN(ucat, c, n, 0, n, 0), u1 =
RHSVelocityAtBN(ucat, c, n, 0, n, 1);
220 d[n].
x = u1.x - u0.
x; d[n].
y = u1.y - u0.
y; d[n].
z = u1.z - u0.
z;
236 const PetscInt c[3], PetscInt n, PetscReal nu,
237 PetscReal
nu_t, PetscBool les, PetscBool clark)
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;
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};
263 f.
x = ex * ajc * (
nu_t);
264 f.
y = ey * ajc * (
nu_t);
265 f.
z = ez * ajc * (
nu_t);
267 f.
x += ex * ajc * (nu);
268 f.
y += ey * ajc * (nu);
269 f.
z += ez * ajc * (nu);
280 f.
x -= gradient_flux.
x / 12.;
281 f.
y -= gradient_flux.
y / 12.;
282 f.
z -= gradient_flux.
z / 12.;
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)
301 PetscInt flo[3] = {lo[0], lo[1], lo[2]};
302 PetscInt across[3] = {0, 0, 0};
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;
313 if ((wall_lo && c[n] == 0) || (wall_hi && c[n] == m[n] - 2)) {
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;
331 nu_t = 0.5 * (lnu_t[k][j][i] + lnu_t[k + across[2]][j + across[1]][i + across[0]]);
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);
353 PetscInt lo[3], hi[3];
358 const PetscReal ***nvert, ***lnu_t = NULL;
359 const Cmpnts ***lwall_stress = NULL;
361 PetscFunctionBeginUser;
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]));
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));
377 PetscCall(DMDAVecGetArray(user->
fda, Visc, &visc));
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]);
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++) {
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);
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);
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);
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));
410 for (PetscInt n = 0; n < 3; n++) {
411 PetscCall(DMDAVecRestoreArray(user->
fda, Fp[n], &fp[n]));
412 PetscCall(DMRestoreLocalVector(user->
fda, &Fp[n]));
416 PetscFunctionReturn(0);
428 PetscFunctionBeginUser;
433 PetscFunctionReturn(0);
442 PetscInt lo[3], hi[3];
443 const Cmpnts ***csi, ***eta, ***zet, ***conv, ***visc;
444 const PetscReal ***aj;
447 PetscFunctionBeginUser;
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);
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);
492 const PetscReal ***p,
const Cmpnts ***rct,
const PetscInt c[3],
493 PetscInt n,
const PetscInt m[3],
const PetscBool periodic[3])
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;
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];
516 const PetscReal ***nvert, ***p;
520 PetscFunctionBeginUser;
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));
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};
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);
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);
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);
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);
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));
570 PetscFunctionReturn(0);
580 PetscInt lo[3], hi[3];
581 const PetscReal ***nvert;
584 PetscFunctionBeginUser;
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;
596 rhs[k][j][i].
x = 0.0; rhs[k][j][i].
y = 0.0; rhs[k][j][i].
z = 0.0;
604 PetscCall(DMDAVecRestoreArray(user->
fda, Rhs, &rhs));
605 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
void *)&nvert));
607 PetscFunctionReturn(0);
621 PetscFunctionBeginUser;
629 PetscCall(DMGetLocalVector(user->
fda, &Conv));
630 PetscCall(DMGetLocalVector(user->
fda, &Visc));
631 PetscCall(DMGetLocalVector(user->
fda, &Rct)); PetscCall(VecZeroEntries(Rct));
645 PetscCall(VecZeroEntries(Visc));
657 PetscCall(DMRestoreLocalVector(user->
fda, &Rct));
658 PetscCall(DMRestoreLocalVector(user->
fda, &Visc));
659 PetscCall(DMRestoreLocalVector(user->
fda, &Conv));
663 PetscFunctionReturn(0);
PetscErrorCode ComputeDrivenChannelFlowSource(UserCtx *user, Vec Rct)
Applies a momentum source term to drive flow in a periodic channel or pipe.
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.
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.
SymTensor SymTensorCombine(PetscReal a, SymTensor x, PetscReal b, SymTensor y)
Forms the linear combination a*x + b*y.
SymTensor SymTensorSelfOuter(Cmpnts v)
Forms a symmetric tensor from a vector's outer product with itself.
static Cmpnts SymTensorTimesVector(SymTensor t, Cmpnts v)
Applies a symmetric tensor to a vector, returning t_ij v_j.
#define LOCAL
Logging scope definitions for controlling message output.
#define GLOBAL
Scope for global logging across all processes.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
@ LOG_DEBUG
Detailed debugging information.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
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]
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.
PetscInt lo
Transverse offset of the subtracted row pair.
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.
PetscErrorCode ComputeBodyForces(UserCtx *user, Vec Rct)
Implementation of ComputeBodyForces().
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...
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 ...
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 ...
PetscErrorCode ComputeConvection(UserCtx *user, Vec Ucont, Vec Ucat, Vec Conv)
Implementation of ComputeConvection().
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.
static PetscErrorCode RHSContravariantSpatialTerms(UserCtx *user, Vec Conv, Vec Visc, Vec Rct)
Contravariant cell-centre components of the spatial terms, Rct = aj F_n .
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,...
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.
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...
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().
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,...
PetscErrorCode ComputeViscous(UserCtx *user, Vec Ucat, Vec Visc)
Implementation of ComputeViscous().
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.
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...
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.
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...
PetscErrorCode ComputeRHS(UserCtx *user, Vec Rhs)
Implementation of ComputeRHS().
static PetscBool RHSIsBlankedSolid(PetscReal nvert)
Whether a cell is a blanked solid cell, which ComputeViscous()'s transverse differences avoid with a ...
static PetscBool RHSConvectsAsFluid(PetscReal nvert)
Whether a cell takes part in convection: fluid, or a blanked inner-body cell.
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...
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
#define PICURV_ALWAYS_INLINE
Forces inlining of a per-cell or per-face kernel whose size defeats the compiler's inlining heuristic...
BoundaryFaceConfig boundary_faces[6]
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscInt les_gradient_model
Add the Clark gradient (tensor-diffusivity) term to the viscous flux.
PetscInt wallfunction
Enable wall functions on WALL faces.
PetscInt les
Active LES closure; an LESModelType value.
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
A symmetric second-order tensor stored by its six independent components.
User-defined context containing data specific to a single computational grid level.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)