26 PetscInt i,PetscInt j,PetscInt k,
30 PetscFunctionBeginUser;
31 for (PetscInt c = 0; c < 8; ++c) {
32 PetscInt ii = i + ((c & 1) ? 1 : 0);
33 PetscInt jj = j + ((c & 2) ? 1 : 0);
34 PetscInt kk = k + ((c & 4) ? 1 : 0);
38 PetscFunctionReturn(0);
51 const PetscReal edge1_x = v2.
x - v1.
x, edge1_y = v2.
y - v1.
y, edge1_z = v2.
z - v1.
z;
52 const PetscReal edge2_x = v4.
x - v1.
x, edge2_y = v4.
y - v1.
y, edge2_z = v4.
z - v1.
z;
53 PetscReal normal_x = edge1_y * edge2_z - edge1_z * edge2_y;
54 PetscReal normal_y = edge1_z * edge2_x - edge1_x * edge2_z;
55 PetscReal normal_z = edge1_x * edge2_y - edge1_y * edge2_x;
56 const PetscReal normal_magnitude = sqrt(normal_x * normal_x + normal_y * normal_y + normal_z * normal_z);
57 PetscBool ambiguous = PETSC_FALSE;
62 *degenerate = (PetscBool)(normal_magnitude < 1.0e-12);
65 const PetscReal dot_prod_orientation = normal_x * (cell_centroid.
x - plane->
centroid.
x) +
66 normal_y * (cell_centroid.
y - plane->
centroid.
y) +
67 normal_z * (cell_centroid.
z - plane->
centroid.
z);
68 if (dot_prod_orientation > 1.0e-9) {
69 normal_x = -normal_x; normal_y = -normal_y; normal_z = -normal_z;
70 }
else if (dot_prod_orientation == 0.0) {
71 ambiguous = PETSC_TRUE;
73 normal_x /= normal_magnitude;
74 normal_y /= normal_magnitude;
75 normal_z /= normal_magnitude;
89 Cmpnts centroid = {0.0, 0.0, 0.0};
91 for (
int v = 0; v < 8; ++v) {
112 static const int face_vertices[
NUM_FACES][4] = {
113 [
LEFT] = {0, 7, 4, 3}, [
RIGHT] = {1, 2, 5, 6}, [
BOTTOM] = {0, 1, 6, 7},
114 [
TOP] = {3, 4, 5, 2}, [
FRONT] = {4, 7, 6, 5}, [
BACK] = {0, 3, 2, 1}};
119 const int *v = face_vertices[f];
120 PetscBool degenerate;
122 cell_centroid, &planes->
face[f], °enerate)) {
123 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"Face %d: dot product for normal orientation is zero; keeping the (v2-v1)x(v4-v1) direction.\n", f);
125 if (degenerate) mask |= (PetscInt)1 << f;
163 PetscFunctionBeginUser;
170 PetscFunctionReturn(0);
178 PetscInt i, PetscInt j, PetscInt k,
Cell *hex)
210 const DMDALocalInfo *info = &user->
info;
211 const PetscInt gs[3] = {info->gxs, info->gys, info->gzs};
212 const PetscInt ge[3] = {info->gxs + info->gxm, info->gys + info->gym, info->gzs + info->gzm};
214 const PetscScalar *src_flat[2] = {NULL, NULL};
216 PetscReal *size = NULL;
218 PetscFunctionBeginUser;
223 Vec *global = NULL, *local = NULL;
225 PetscCall(DMCreateGlobalVector(dm, global));
226 PetscCall(DMCreateLocalVector(dm, local));
227 PetscCall(VecSet(*local, 0.0));
229 for (
int which = 0; which < 2; ++which) {
230 for (
int f = 0; f < 6; ++f) {
233 PetscCall(VecGetArray(view.
local_vec, (PetscScalar **)&out[which][f]));
239 PetscCall(VecGetArrayRead(Coor, &src_flat[0]));
240 PetscCall(VecGetArrayRead(user->
lCent, &src_flat[1]));
241 PetscBool periodic[3];
243 const PetscInt mx[3] = {info->mx, info->my, info->mz};
244 PetscInt n_ambiguous = 0, first_ambiguous[4] = {-1, -1, -1, -1};
245 for (
int which = 0; which < 2; ++which) {
251 PetscInt lo[3], hi[3];
252 for (
int a = 0; a < 3; ++a) {
253 lo[a] = PetscMax(gs[a], (which && !periodic[a]) ? 1 : 0);
254 hi[a] = PetscMin(ge[a] - 1, (which && periodic[a]) ? mx[a] - 1 : mx[a] - 2);
256 #define PICURV_AT(i, j, k) X[MetricCellFacePlanesIndex(info, (i), (j), (k))]
257 for (PetscInt k = gs[2]; k < ge[2]; ++k) {
258 for (PetscInt j = gs[1]; j < ge[1]; ++j) {
259 for (PetscInt i = gs[0]; i < ge[0]; ++i) {
260 const PetscInt o[3] = {i, j, k};
261 for (PetscInt a = 0; a < 3; ++a) {
262 const PetscInt b = (a + 1) % 3, c = (a + 2) % 3;
265 if (o[b] < lo[b] || o[b] + 1 > hi[b] || o[c] < lo[c] || o[c] + 1 > hi[c])
continue;
266 PetscInt cell[3] = {i, j, k};
267 PetscBool above = (PetscBool)(o[a] >= lo[a] && o[a] + 1 <= hi[a]);
269 if (o[a] - 1 < lo[a] || o[a] > hi[a])
continue;
276 PetscInt e1[3] = {0, 0, 0}, e2[3] = {0, 0, 0};
277 if (a == 0) { e1[2] = 1; e2[1] = 1; }
278 else if (a == 1) { e1[0] = 1; e2[2] = 1; }
279 else { e1[1] = 1; e2[0] = 1; }
281 PetscBool degenerate;
283 PICURV_AT(i + e1[0] + e2[0], j + e1[1] + e2[1], k + e1[2] + e2[2]),
284 PICURV_AT(i + e2[0], j + e2[1], k + e2[2]), centroid, &plane, °enerate)) {
285 if (n_ambiguous++ == 0) { first_ambiguous[0] = a; first_ambiguous[1] = i; first_ambiguous[2] = j; first_ambiguous[3] = k; }
287 if (degenerate)
continue;
289 const PetscReal sign = above ? -1.0 : 1.0;
290 const PetscInt *sh = which ? (
const PetscInt[3]){0, 0, 0} :
kPrimalFaceShift[a];
292 out[which][a][at].
x = sign * plane.
normal.
x;
293 out[which][a][at].
y = sign * plane.
normal.
y;
294 out[which][a][at].
z = sign * plane.
normal.
z;
295 out[which][3 + a][at] = plane.
centroid;
297 if (which == 0 && i >= lo[0] && i + 1 <= hi[0] && j >= lo[1] && j + 1 <= hi[1] && k >= lo[2] && k + 1 <= hi[2]) {
307 PetscCall(VecRestoreArrayRead(user->
lCent, &src_flat[1]));
308 PetscCall(VecRestoreArrayRead(Coor, &src_flat[0]));
309 if (n_ambiguous > 0) {
310 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"Rank %d: %" PetscInt_FMT
" particle face plane(s) had an ambiguous orientation and keep the (v2-v1)x(v4-v1) direction; first: face family %" PetscInt_FMT
" at (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
").\n",
311 (
int)user->
simCtx->
rank, n_ambiguous, first_ambiguous[0], first_ambiguous[1], first_ambiguous[2], first_ambiguous[3]);
318 for (
int which = 0; which < 2; ++which) {
319 for (
int f = 0; f < 6; ++f) {
322 PetscCall(VecRestoreArray(view.
local_vec, (PetscScalar **)&out[which][f]));
327 const PetscScalar *local = NULL;
328 PetscScalar *global = NULL;
332 PetscCall(VecGetArrayRead(view.
local_vec, &local));
333 PetscCall(VecGetArray(view.
global_vec, &global));
334 for (PetscInt k = info->zs, g = 0; k < info->zs + info->zm; ++k) {
335 for (PetscInt j = info->ys; j < info->ys + info->ym; ++j) {
336 for (PetscInt i = info->xs; i < info->xs + info->xm; ++i, ++g) {
341 PetscCall(VecRestoreArray(view.
global_vec, &global));
342 PetscCall(VecRestoreArrayRead(view.
local_vec, &local));
346 PetscFunctionReturn(0);
357 PetscFunctionBeginUser;
361 Vec *global = NULL, *local = NULL;
363 PetscCall(VecDestroy(global));
364 PetscCall(VecDestroy(local));
367 PetscFunctionReturn(0);
378 Vec normals[3], centroids[3];
380 PetscFunctionBeginUser;
381 PetscCheck(user->
lSearchCellSize, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
382 "Particle face planes are not built: MetricComputeFacePlanes() runs in CalculateAllGridMetrics() "
383 "for a particle run, collectively, once the grid is final.");
386 for (
int a = 0; a < 3; ++a) {
387 PetscCall(VecGetArrayRead(normals[a], (
const PetscScalar **)&arrays->
normal[a]));
388 PetscCall(VecGetArrayRead(centroids[a], (
const PetscScalar **)&arrays->
centroid[a]));
392 PetscFunctionReturn(0);
403 Vec normals[3], centroids[3];
405 PetscFunctionBeginUser;
407 for (
int a = 0; a < 3; ++a) {
408 PetscCall(VecRestoreArrayRead(normals[a], (
const PetscScalar **)&arrays->
normal[a]));
409 PetscCall(VecRestoreArrayRead(centroids[a], (
const PetscScalar **)&arrays->
centroid[a]));
412 PetscFunctionReturn(0);
424 static const PetscInt dual_shift[3] = {0, 0, 0};
428 for (PetscInt a = 0; a < 3; ++a) {
430 for (
int side = 0; side < 2; ++side) {
432 j + sh[1] + (a == 1 ? side : 0), k + sh[2] + (a == 2 ? side : 0));
433 const Face f = side ? plus_face[a] : minus_face[a];
440 if (n.
x == 0.0 && n.
y == 0.0 && n.
z == 0.0) planes->
degenerate |= (PetscInt)1 << f;
452 PetscReal xi,PetscReal eta,PetscReal zta,
455 PetscReal x=0,y=0,z=0;
456 for (PetscInt c=0;c<8;++c) {
457 PetscReal N = ((c&1)?xi : 1.0-xi ) *
458 ((c&2)?eta: 1.0-eta) *
459 ((c&4)?zta: 1.0-zta);
464 Xp->
x = x; Xp->
y = y; Xp->
z = z;
477 PetscInt i,PetscInt j,PetscInt k,
478 PetscReal xi,PetscReal eta,PetscReal zta,
483 PetscFunctionBeginUser;
492 PetscFunctionReturn(0);
504 PetscInt i,PetscInt j,PetscInt k,
505 PetscReal xi,PetscReal eta,PetscReal zta,
506 PetscReal J[3][3], PetscReal *detJ)
510 PetscFunctionBeginUser;
517 PetscReal dN_dXi[8], dN_dEta[8], dN_dZta[8];
518 for (PetscInt c=0;c<8;++c) {
519 PetscReal sx = (c & 1) ? 1.0 : -1.0;
520 PetscReal sy = (c & 2) ? 1.0 : -1.0;
521 PetscReal sz = (c & 4) ? 1.0 : -1.0;
522 dN_dXi [c] = sx * ( (c&2?eta:1-eta) ) * ( (c&4?zta:1-zta) );
523 dN_dEta[c] = sy * ( (c&1?xi :1-xi ) ) * ( (c&4?zta:1-zta) );
524 dN_dZta[c] = sz * ( (c&1?xi :1-xi ) ) * ( (c&2?eta:1-eta) );
528 PetscReal x_xi=0,y_xi=0,z_xi=0,
529 x_eta=0,y_eta=0,z_eta=0,
530 x_zta=0,y_zta=0,z_zta=0;
531 for (PetscInt c=0;c<8;++c) {
532 x_xi += dN_dXi [c]*V[c].
x; y_xi += dN_dXi [c]*V[c].
y; z_xi += dN_dXi [c]*V[c].
z;
533 x_eta += dN_dEta[c]*V[c].
x; y_eta += dN_dEta[c]*V[c].
y; z_eta += dN_dEta[c]*V[c].
z;
534 x_zta += dN_dZta[c]*V[c].
x; y_zta += dN_dZta[c]*V[c].
y; z_zta += dN_dZta[c]*V[c].
z;
537 J[0][0]=x_xi; J[0][1]=x_eta; J[0][2]=x_zta;
538 J[1][0]=y_xi; J[1][1]=y_eta; J[1][2]=y_zta;
539 J[2][0]=z_xi; J[2][1]=z_eta; J[2][2]=z_zta;
542 *detJ = x_xi*(y_eta*z_zta - y_zta*z_eta)
543 - x_eta*(y_xi*z_zta - y_zta*z_xi)
544 + x_zta*(y_xi*z_eta - y_eta*z_xi);
549 PetscFunctionReturn(0);
561 const PetscReal u[3], PetscReal uc[3])
563 PetscFunctionBeginUser;
568 PetscReal gxi[3] = { J[1][1]*J[2][2]-J[1][2]*J[2][1],
569 -J[0][1]*J[2][2]+J[0][2]*J[2][1],
570 J[0][1]*J[1][2]-J[0][2]*J[1][1] };
571 PetscReal geta[3] = { -J[1][0]*J[2][2]+J[1][2]*J[2][0],
572 J[0][0]*J[2][2]-J[0][2]*J[2][0],
573 -J[0][0]*J[1][2]+J[0][2]*J[1][0] };
574 PetscReal gzta[3] = { J[1][0]*J[2][1]-J[1][1]*J[2][0],
575 -J[0][0]*J[2][1]+J[0][1]*J[2][0],
576 J[0][0]*J[1][1]-J[0][1]*J[1][0] };
578 PetscReal invDet = 1.0 / detJ;
579 for (
int d=0; d<3; ++d) { gxi[d] *= invDet; geta[d] *= invDet; gzta[d] *= invDet; }
581 uc[0] = gxi [0]*u[0] + gxi [1]*u[1] + gxi [2]*u[2];
582 uc[1] = geta[0]*u[0] + geta[1]*u[1] + geta[2]*u[2];
583 uc[2] = gzta[0]*u[0] + gzta[1]*u[1] + gzta[2]*u[2];
587 PetscFunctionReturn(0);
597 PetscFunctionBeginUser;
600 const double a11=covariantTensor[0][0], a12=covariantTensor[0][1], a13=covariantTensor[0][2];
601 const double a21=covariantTensor[1][0], a22=covariantTensor[1][1], a23=covariantTensor[1][2];
602 const double a31=covariantTensor[2][0], a32=covariantTensor[2][1], a33=covariantTensor[2][2];
604 double det = a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
613 const double row_scale = sqrt(a11*a11 + a12*a12 + a13*a13) *
614 sqrt(a21*a21 + a22*a22 + a23*a23) *
615 sqrt(a31*a31 + a32*a32 + a33*a33);
617 if (row_scale <= 0.0 || fabs(det) <= 1.0e-10 * row_scale) {
618 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_MAT_LU_ZRPVT,
619 "Matrix is singular: |det| = %g is degenerate against the rows' own scale "
620 "%g (ratio %g); the rows are coplanar or one of them vanishes.",
621 (
double)fabs(det), (
double)row_scale,
622 (
double)(row_scale > 0.0 ? fabs(det)/row_scale : 0.0));
625 contravariantTensor[0][0] = (a33*a22-a32*a23)/det;
626 contravariantTensor[0][1] = -(a33*a12-a32*a13)/det;
627 contravariantTensor[0][2] = (a23*a12-a22*a13)/det;
628 contravariantTensor[1][0] = -(a33*a21-a31*a23)/det;
629 contravariantTensor[1][1] = (a33*a11-a31*a13)/det;
630 contravariantTensor[1][2] = -(a23*a11-a21*a13)/det;
631 contravariantTensor[2][0] = (a32*a21-a31*a22)/det;
632 contravariantTensor[2][1] = -(a32*a11-a31*a12)/det;
633 contravariantTensor[2][2] = (a22*a11-a21*a12)/det;
636 PetscFunctionReturn(0);
646 PetscFunctionBeginUser;
651 g[0][0]=csi.
x, g[0][1]=csi.
y, g[0][2]=csi.
z;
652 g[1][0]=eta.
x, g[1][1]=eta.
y, g[1][2]=eta.
z;
653 g[2][0]=zet.
x, g[2][1]=zet.
y, g[2][2]=zet.
z;
656 double xcsi=G[0][0], ycsi=G[1][0], zcsi=G[2][0];
657 double xeta=G[0][1], yeta=G[1][1], zeta=G[2][1];
658 double xzet=G[0][2], yzet=G[1][2], zzet=G[2][2];
660 double nx_i = xcsi, ny_i = ycsi, nz_i = zcsi;
661 double nx_j = xeta, ny_j = yeta, nz_j = zeta;
662 double nx_k = xzet, ny_k = yzet, nz_k = zzet;
664 double sum_i=sqrt(nx_i*nx_i+ny_i*ny_i+nz_i*nz_i);
665 double sum_j=sqrt(nx_j*nx_j+ny_j*ny_j+nz_j*nz_j);
666 double sum_k=sqrt(nx_k*nx_k+ny_k*ny_k+nz_k*nz_k);
668 *Ai = sqrt( g[0][0]*g[0][0] + g[0][1]*g[0][1] + g[0][2]*g[0][2] );
669 *Aj = sqrt( g[1][0]*g[1][0] + g[1][1]*g[1][1] + g[1][2]*g[1][2] );
670 *Ak =sqrt( g[2][0]*g[2][0] + g[2][1]*g[2][1] + g[2][2]*g[2][2] );
672 nx_i /= sum_i, ny_i /= sum_i, nz_i /= sum_i;
673 nx_j /= sum_j, ny_j /= sum_j, nz_j /= sum_j;
674 nx_k /= sum_k, ny_k /= sum_k, nz_k /= sum_k;
676 ni[0] = nx_i, ni[1] = ny_i, ni[2] = nz_i;
677 nj[0] = nx_j, nj[1] = ny_j, nj[2] = nz_j;
678 nk[0] = nx_k, nk[1] = ny_k, nk[2] = nz_k;
681 PetscFunctionReturn(0);
690 PetscFunctionBeginUser;
692 double ni[3], nj[3], nk[3];
703 *dx = fabs( Li * ni[0] + Lj * nj[0] + Lk * nk[0] );
704 *dy = fabs( Li * ni[1] + Lj * nj[1] + Lk * nk[1] );
705 *dz = fabs( Li * ni[2] + Lj * nj[2] + Lk * nk[2] );
708 PetscFunctionReturn(0);
718 double *l_xi,
double *l_eta,
double *l_zeta)
720 const double area_xi = sqrt(csi.
x*csi.
x + csi.
y*csi.
y + csi.
z*csi.
z);
721 const double area_eta = sqrt(eta.
x*eta.
x + eta.
y*eta.
y + eta.
z*eta.
z);
722 const double area_zeta = sqrt(zet.
x*zet.
x + zet.
y*zet.
y + zet.
z*zet.
z);
724 PetscFunctionBeginUser;
726 PetscCheck(ajc > 0.0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
727 "Cell Jacobian must be positive to define cell extents; received %g.", (
double)ajc);
728 PetscCheck(area_xi > 0.0 && area_eta > 0.0 && area_zeta > 0.0, PETSC_COMM_SELF,
729 PETSC_ERR_ARG_OUTOFRANGE,
730 "A cell face has zero area (%g, %g, %g), so the cell has no extent across it.",
731 area_xi, area_eta, area_zeta);
736 *l_xi = (1.0/ajc)/area_xi;
737 *l_eta = (1.0/ajc)/area_eta;
738 *l_zeta = (1.0/ajc)/area_zeta;
740 PetscFunctionReturn(0);
752 PetscFunctionBeginUser;
754 PetscCheck(ajc > 0.0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
755 "Cell Jacobian must be positive to define cell edges; received %g.", (
double)ajc);
759 edges[0].
x = ajc * (eta.
y*zet.
z - eta.
z*zet.
y);
760 edges[0].
y = ajc * (eta.
z*zet.
x - eta.
x*zet.
z);
761 edges[0].
z = ajc * (eta.
x*zet.
y - eta.
y*zet.
x);
762 edges[1].
x = ajc * (zet.
y*csi.
z - zet.
z*csi.
y);
763 edges[1].
y = ajc * (zet.
z*csi.
x - zet.
x*csi.
z);
764 edges[1].
z = ajc * (zet.
x*csi.
y - zet.
y*csi.
x);
765 edges[2].
x = ajc * (csi.
y*eta.
z - csi.
z*eta.
y);
766 edges[2].
y = ajc * (csi.
z*eta.
x - csi.
x*eta.
z);
767 edges[2].
z = ajc * (csi.
x*eta.
y - csi.
y*eta.
x);
769 PetscFunctionReturn(0);
781 PetscReal aj_min, aj_max;
784 PetscFunctionBeginUser;
791 ierr = VecMin(user->
Aj, NULL, &aj_min); CHKERRQ(ierr);
792 ierr = VecMax(user->
Aj, NULL, &aj_max); CHKERRQ(ierr);
795 "[orientation] Global Aj range: [%.3e , %.3e]\n",
796 (
double)aj_min, (
double)aj_max);
799 if (aj_min < 0.0 && aj_max > 0.0)
800 SETERRABORT(PETSC_COMM_WORLD, PETSC_ERR_USER,
801 "Mixed Jacobian signs detected – grid is topologically inconsistent.");
807 PetscInt orientation = +1;
809 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER,
810 "The grid is left-handed: every cell Jacobian is negative, as a mirrored or "
811 "oddly permuted grid is. The solver needs right-handed logical axes. Renumber "
812 "one logical axis (grid.gen: append reverse:axis=i|j|k to the transforms); "
813 "that axis's two faces trade names.");
824 PetscFunctionReturn(0);
834 DMDALocalInfo info = user->
info;
835 PetscInt xs = info.xs, xe = info.xs + info.xm;
836 PetscInt ys = info.ys, ye = info.ys + info.ym;
837 PetscInt zs = info.zs, ze = info.zs + info.zm;
838 PetscInt mx = info.mx, my = info.my, mz = info.mz;
842 PetscFunctionBeginUser;
850 for (PetscInt axis = 0; axis < 3; axis++) {
853 "Periodic cell-centre correction on axis %d needs the validated seam translation.", (
int)axis);
856 ierr = DMDAVecGetArray(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
857 ierr = DMDAVecGetArray(user->
fda, user->
lCent, &lcent); CHKERRQ(ierr);
858 for (PetscInt k = zs; k < ze; k++) {
859 for (PetscInt j = ys; j < ye; j++) {
860 for (PetscInt i = xs; i < xe; i++) {
861 const PetscInt idx[3] = {i, j, k}, n[3] = {mx, my, mz};
862 PetscInt src_i = i, src_j = j, src_k = k;
864 if (idx[axis] == 0) sign = -1.0;
865 else if (idx[axis] == n[axis] - 1) sign = 1.0;
869 if (axis == 0) src_i = (sign < 0.0) ? -2 : mx + 1;
870 if (axis == 1) src_j = (sign < 0.0) ? -2 : my + 1;
871 if (axis == 2) src_k = (sign < 0.0) ? -2 : mz + 1;
872 cent[k][j][i].
x = lcent[src_k][src_j][src_i].
x + sign * T.
x;
873 cent[k][j][i].
y = lcent[src_k][src_j][src_i].
y + sign * T.
y;
874 cent[k][j][i].
z = lcent[src_k][src_j][src_i].
z + sign * T.
z;
878 ierr = DMDAVecRestoreArray(user->
fda, user->
lCent, &lcent); CHKERRQ(ierr);
879 ierr = DMDAVecRestoreArray(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
883 PetscFunctionReturn(0);
894 PetscFunctionBeginUser;
898 PetscFunctionReturn(0);
910 PetscFunctionBeginUser;
914 PetscFunctionReturn(0);
926 PetscFunctionBeginUser;
930 PetscFunctionReturn(0);
941 Cmpnts ***csi_arr, ***eta_arr, ***zet_arr;
942 Cmpnts ***nodal_coords_arr;
943 Vec localCoords_from_dm;
945 PetscFunctionBeginUser;
954 localCoords_from_dm = user->
lCoor;
955 if (!localCoords_from_dm) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"user->lCoor is NULL: grid coordinates are not set up.\n");
956 ierr = DMDAVecGetArrayRead(user->
fda, localCoords_from_dm, &nodal_coords_arr); CHKERRQ(ierr);
959 ierr = DMDAVecGetArray(user->
fda, user->
Csi, &csi_arr); CHKERRQ(ierr);
960 ierr = DMDAVecGetArray(user->
fda, user->
Eta, &eta_arr); CHKERRQ(ierr);
961 ierr = DMDAVecGetArray(user->
fda, user->
Zet, &zet_arr); CHKERRQ(ierr);
964 PetscInt xs = info.xs, xe = info.xs + info.xm;
965 PetscInt ys = info.ys, ye = info.ys + info.ym;
966 PetscInt zs = info.zs, ze = info.zs + info.zm;
969 PetscInt mx = info.mx;
970 PetscInt my = info.my;
971 PetscInt mz = info.mz;
975 PetscInt k_loop_start = (zs == 0) ? zs + 1 : zs;
976 PetscInt j_loop_start = (ys == 0) ? ys + 1 : ys;
977 PetscInt i_loop_start = (xs == 0) ? xs + 1 : xs;
983 for (PetscInt k_node = k_loop_start; k_node < ze; ++k_node) {
984 for (PetscInt j_node = j_loop_start; j_node < ye; ++j_node) {
985 for (PetscInt i_node = xs; i_node < xe; ++i_node) {
987 PetscReal dx_deta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node-1][j_node][i_node].
x - nodal_coords_arr[k_node][j_node-1][i_node].
x - nodal_coords_arr[k_node-1][j_node-1][i_node].
x);
988 PetscReal dy_deta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node-1][j_node][i_node].
y - nodal_coords_arr[k_node][j_node-1][i_node].
y - nodal_coords_arr[k_node-1][j_node-1][i_node].
y);
989 PetscReal dz_deta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node-1][j_node][i_node].
z - nodal_coords_arr[k_node][j_node-1][i_node].
z - nodal_coords_arr[k_node-1][j_node-1][i_node].
z);
990 PetscReal dx_dzeta = 0.5 * (nodal_coords_arr[k_node][j_node-1][i_node].
x + nodal_coords_arr[k_node][j_node][i_node].
x - nodal_coords_arr[k_node-1][j_node-1][i_node].
x - nodal_coords_arr[k_node-1][j_node][i_node].
x);
991 PetscReal dy_dzeta = 0.5 * (nodal_coords_arr[k_node][j_node-1][i_node].
y + nodal_coords_arr[k_node][j_node][i_node].
y - nodal_coords_arr[k_node-1][j_node-1][i_node].
y - nodal_coords_arr[k_node-1][j_node][i_node].
y);
992 PetscReal dz_dzeta = 0.5 * (nodal_coords_arr[k_node][j_node-1][i_node].
z + nodal_coords_arr[k_node][j_node][i_node].
z - nodal_coords_arr[k_node-1][j_node-1][i_node].
z - nodal_coords_arr[k_node-1][j_node][i_node].
z);
994 csi_arr[k_node][j_node][i_node].
x = dy_deta * dz_dzeta - dz_deta * dy_dzeta;
995 csi_arr[k_node][j_node][i_node].
y = dz_deta * dx_dzeta - dx_deta * dz_dzeta;
996 csi_arr[k_node][j_node][i_node].
z = dx_deta * dy_dzeta - dy_deta * dx_dzeta;
1002 for (PetscInt k_node = k_loop_start; k_node < ze; ++k_node) {
1003 for (PetscInt j_node = ys; j_node < ye; ++j_node) {
1004 for (PetscInt i_node = i_loop_start; i_node < xe; ++i_node) {
1006 PetscReal dx_dxi = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node-1][j_node][i_node].
x - nodal_coords_arr[k_node][j_node][i_node-1].
x - nodal_coords_arr[k_node-1][j_node][i_node-1].
x);
1007 PetscReal dy_dxi = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node-1][j_node][i_node].
y - nodal_coords_arr[k_node][j_node][i_node-1].
y - nodal_coords_arr[k_node-1][j_node][i_node-1].
y);
1008 PetscReal dz_dxi = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node-1][j_node][i_node].
z - nodal_coords_arr[k_node][j_node][i_node-1].
z - nodal_coords_arr[k_node-1][j_node][i_node-1].
z);
1009 PetscReal dx_dzeta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node][j_node][i_node-1].
x - nodal_coords_arr[k_node-1][j_node][i_node].
x - nodal_coords_arr[k_node-1][j_node][i_node-1].
x);
1010 PetscReal dy_dzeta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node][j_node][i_node-1].
y - nodal_coords_arr[k_node-1][j_node][i_node].
y - nodal_coords_arr[k_node-1][j_node][i_node-1].
y);
1011 PetscReal dz_dzeta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node][j_node][i_node-1].
z - nodal_coords_arr[k_node-1][j_node][i_node].
z - nodal_coords_arr[k_node-1][j_node][i_node-1].
z);
1013 eta_arr[k_node][j_node][i_node].
x = dy_dzeta * dz_dxi - dz_dzeta * dy_dxi;
1014 eta_arr[k_node][j_node][i_node].
y = dz_dzeta * dx_dxi - dx_dzeta * dz_dxi;
1015 eta_arr[k_node][j_node][i_node].
z = dx_dzeta * dy_dxi - dy_dzeta * dx_dxi;
1021 for (PetscInt k_node = zs; k_node < ze; ++k_node) {
1022 for (PetscInt j_node = j_loop_start; j_node < ye; ++j_node) {
1023 for (PetscInt i_node = i_loop_start; i_node < xe; ++i_node) {
1025 PetscReal dx_dxi = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node][j_node-1][i_node].
x - nodal_coords_arr[k_node][j_node][i_node-1].
x - nodal_coords_arr[k_node][j_node-1][i_node-1].
x);
1026 PetscReal dy_dxi = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node][j_node-1][i_node].
y - nodal_coords_arr[k_node][j_node][i_node-1].
y - nodal_coords_arr[k_node][j_node-1][i_node-1].
y);
1027 PetscReal dz_dxi = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node][j_node-1][i_node].
z - nodal_coords_arr[k_node][j_node][i_node-1].
z - nodal_coords_arr[k_node][j_node-1][i_node-1].
z);
1028 PetscReal dx_deta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node][j_node][i_node-1].
x - nodal_coords_arr[k_node][j_node-1][i_node].
x - nodal_coords_arr[k_node][j_node-1][i_node-1].
x);
1029 PetscReal dy_deta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node][j_node][i_node-1].
y - nodal_coords_arr[k_node][j_node-1][i_node].
y - nodal_coords_arr[k_node][j_node-1][i_node-1].
y);
1030 PetscReal dz_deta = 0.5 * (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node][j_node][i_node-1].
z - nodal_coords_arr[k_node][j_node-1][i_node].
z - nodal_coords_arr[k_node][j_node-1][i_node-1].
z);
1032 zet_arr[k_node][j_node][i_node].
x = dy_dxi * dz_deta - dz_dxi * dy_deta;
1033 zet_arr[k_node][j_node][i_node].
y = dz_dxi * dx_deta - dx_dxi * dz_deta;
1034 zet_arr[k_node][j_node][i_node].
z = dx_dxi * dy_deta - dy_dxi * dx_deta;
1041 PetscInt i_bnd, j_bnd, k_bnd;
1045 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1046 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1047 if (i_bnd + 1 < mx) {
1048 eta_arr[k_bnd][j_bnd][i_bnd] = eta_arr[k_bnd][j_bnd][i_bnd+1];
1049 zet_arr[k_bnd][j_bnd][i_bnd] = zet_arr[k_bnd][j_bnd][i_bnd+1];
1056 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1057 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1058 if (i_bnd - 1 >= 0) {
1059 eta_arr[k_bnd][j_bnd][i_bnd] = eta_arr[k_bnd][j_bnd][i_bnd-1];
1060 zet_arr[k_bnd][j_bnd][i_bnd] = zet_arr[k_bnd][j_bnd][i_bnd-1];
1067 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1068 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1069 if (j_bnd + 1 < my) {
1070 csi_arr[k_bnd][j_bnd][i_bnd] = csi_arr[k_bnd][j_bnd+1][i_bnd];
1071 zet_arr[k_bnd][j_bnd][i_bnd] = zet_arr[k_bnd][j_bnd+1][i_bnd];
1078 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1079 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1080 if (j_bnd - 1 >= 0) {
1081 csi_arr[k_bnd][j_bnd][i_bnd] = csi_arr[k_bnd][j_bnd-1][i_bnd];
1082 zet_arr[k_bnd][j_bnd][i_bnd] = zet_arr[k_bnd][j_bnd-1][i_bnd];
1089 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1090 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1091 if (k_bnd + 1 < mz) {
1092 csi_arr[k_bnd][j_bnd][i_bnd] = csi_arr[k_bnd+1][j_bnd][i_bnd];
1093 eta_arr[k_bnd][j_bnd][i_bnd] = eta_arr[k_bnd+1][j_bnd][i_bnd];
1100 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1101 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1102 if (k_bnd - 1 >= 0) {
1103 csi_arr[k_bnd][j_bnd][i_bnd] = csi_arr[k_bnd-1][j_bnd][i_bnd];
1104 eta_arr[k_bnd][j_bnd][i_bnd] = eta_arr[k_bnd-1][j_bnd][i_bnd];
1110 if (info.xs==0 && info.ys==0 && info.zs==0) {
1111 PetscReal dot = zet_arr[0][0][0].
z;
1116 ierr = DMDAVecRestoreArrayRead(user->
fda, localCoords_from_dm, &nodal_coords_arr); CHKERRQ(ierr);
1117 ierr = DMDAVecRestoreArray(user->
fda, user->
Csi, &csi_arr); CHKERRQ(ierr);
1118 ierr = DMDAVecRestoreArray(user->
fda, user->
Eta, &eta_arr); CHKERRQ(ierr);
1119 ierr = DMDAVecRestoreArray(user->
fda, user->
Zet, &zet_arr); CHKERRQ(ierr);
1123 ierr = VecAssemblyBegin(user->
Csi); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
Csi); CHKERRQ(ierr);
1124 ierr = VecAssemblyBegin(user->
Eta); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
Eta); CHKERRQ(ierr);
1125 ierr = VecAssemblyBegin(user->
Zet); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
Zet); CHKERRQ(ierr);
1137 PetscFunctionReturn(0);
1149 PetscErrorCode ierr;
1151 PetscScalar ***aj_arr;
1152 Cmpnts ***nodal_coords_arr;
1153 Vec localCoords_from_dm;
1155 PetscFunctionBeginUser;
1160 localCoords_from_dm = user->
lCoor;
1161 ierr = DMDAVecGetArrayRead(user->
fda, localCoords_from_dm, &nodal_coords_arr); CHKERRQ(ierr);
1163 ierr = DMDAVecGetArray(user->
da, user->
Aj, &aj_arr); CHKERRQ(ierr);
1166 PetscInt xs = info.xs, xe = info.xs + info.xm;
1167 PetscInt ys = info.ys, ye = info.ys + info.ym;
1168 PetscInt zs = info.zs, ze = info.zs + info.zm;
1171 PetscInt mx = info.mx;
1172 PetscInt my = info.my;
1173 PetscInt mz = info.mz;
1177 PetscInt k_start_node = (zs == 0) ? zs + 1 : zs;
1178 PetscInt j_start_node = (ys == 0) ? ys + 1 : ys;
1179 PetscInt i_start_node = (xs == 0) ? xs + 1 : xs;
1181 PetscInt k_end_node = (ze == mz) ? ze - 1 : ze;
1182 PetscInt j_end_node = (ye == my) ? ye - 1 : ye;
1183 PetscInt i_end_node = (xe == mx) ? xe - 1 : xe;
1185 for (PetscInt k_node = k_start_node; k_node < k_end_node; ++k_node) {
1186 for (PetscInt j_node = j_start_node; j_node < j_end_node; ++j_node) {
1187 for (PetscInt i_node = i_start_node; i_node < i_end_node; ++i_node) {
1189 PetscReal dx_dxi = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node][j_node-1][i_node].
x + nodal_coords_arr[k_node-1][j_node][i_node].
x + nodal_coords_arr[k_node-1][j_node-1][i_node].
x) - (nodal_coords_arr[k_node][j_node][i_node-1].x + nodal_coords_arr[k_node][j_node-1][i_node-1].x + nodal_coords_arr[k_node-1][j_node][i_node-1].x + nodal_coords_arr[k_node-1][j_node-1][i_node-1].x) );
1191 PetscReal dy_dxi = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node][j_node-1][i_node].
y + nodal_coords_arr[k_node-1][j_node][i_node].
y + nodal_coords_arr[k_node-1][j_node-1][i_node].
y) - (nodal_coords_arr[k_node][j_node][i_node-1].y + nodal_coords_arr[k_node][j_node-1][i_node-1].y + nodal_coords_arr[k_node-1][j_node][i_node-1].y + nodal_coords_arr[k_node-1][j_node-1][i_node-1].y) );
1193 PetscReal dz_dxi = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node][j_node-1][i_node].
z + nodal_coords_arr[k_node-1][j_node][i_node].
z + nodal_coords_arr[k_node-1][j_node-1][i_node].
z) - (nodal_coords_arr[k_node][j_node][i_node-1].z + nodal_coords_arr[k_node][j_node-1][i_node-1].z + nodal_coords_arr[k_node-1][j_node][i_node-1].z + nodal_coords_arr[k_node-1][j_node-1][i_node-1].z) );
1195 PetscReal dx_deta = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node][j_node][i_node-1].
x + nodal_coords_arr[k_node-1][j_node][i_node].
x + nodal_coords_arr[k_node-1][j_node][i_node-1].
x) - (nodal_coords_arr[k_node][j_node-1][i_node].x + nodal_coords_arr[k_node][j_node-1][i_node-1].x + nodal_coords_arr[k_node-1][j_node-1][i_node].x + nodal_coords_arr[k_node-1][j_node-1][i_node-1].x) );
1197 PetscReal dy_deta = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node][j_node][i_node-1].
y + nodal_coords_arr[k_node-1][j_node][i_node].
y + nodal_coords_arr[k_node-1][j_node][i_node-1].
y) - (nodal_coords_arr[k_node][j_node-1][i_node].y + nodal_coords_arr[k_node][j_node-1][i_node-1].y + nodal_coords_arr[k_node-1][j_node-1][i_node].y + nodal_coords_arr[k_node-1][j_node-1][i_node-1].y) );
1199 PetscReal dz_deta = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node][j_node][i_node-1].
z + nodal_coords_arr[k_node-1][j_node][i_node].
z + nodal_coords_arr[k_node-1][j_node][i_node-1].
z) - (nodal_coords_arr[k_node][j_node-1][i_node].z + nodal_coords_arr[k_node][j_node-1][i_node-1].z + nodal_coords_arr[k_node-1][j_node-1][i_node].z + nodal_coords_arr[k_node-1][j_node-1][i_node-1].z) );
1201 PetscReal dx_dzeta = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
x + nodal_coords_arr[k_node][j_node-1][i_node].
x + nodal_coords_arr[k_node][j_node][i_node-1].
x + nodal_coords_arr[k_node][j_node-1][i_node-1].
x) - (nodal_coords_arr[k_node-1][j_node][i_node].x + nodal_coords_arr[k_node-1][j_node-1][i_node].x + nodal_coords_arr[k_node-1][j_node][i_node-1].x + nodal_coords_arr[k_node-1][j_node-1][i_node-1].x) );
1203 PetscReal dy_dzeta = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
y + nodal_coords_arr[k_node][j_node-1][i_node].
y + nodal_coords_arr[k_node][j_node][i_node-1].
y + nodal_coords_arr[k_node][j_node-1][i_node-1].
y) - (nodal_coords_arr[k_node-1][j_node][i_node].y + nodal_coords_arr[k_node-1][j_node-1][i_node].y + nodal_coords_arr[k_node-1][j_node][i_node-1].y + nodal_coords_arr[k_node-1][j_node-1][i_node-1].y) );
1205 PetscReal dz_dzeta = 0.25 * ( (nodal_coords_arr[k_node][j_node][i_node].
z + nodal_coords_arr[k_node][j_node-1][i_node].
z + nodal_coords_arr[k_node][j_node][i_node-1].
z + nodal_coords_arr[k_node][j_node-1][i_node-1].
z) - (nodal_coords_arr[k_node-1][j_node][i_node].z + nodal_coords_arr[k_node-1][j_node-1][i_node].z + nodal_coords_arr[k_node-1][j_node][i_node-1].z + nodal_coords_arr[k_node-1][j_node-1][i_node-1].z) );
1207 PetscReal jacobian_det = dx_dxi * (dy_deta * dz_dzeta - dz_deta * dy_dzeta) - dy_dxi * (dx_deta * dz_dzeta - dz_deta * dx_dzeta) + dz_dxi * (dx_deta * dy_dzeta - dy_deta * dx_dzeta);
1208 if (PetscAbsReal(jacobian_det) < 1.0e-18) { SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FLOP_COUNT,
"Jacobian is near zero..."); }
1209 aj_arr[k_node][j_node][i_node] = 1.0 / jacobian_det;
1216 PetscInt i_bnd, j_bnd, k_bnd;
1220 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1221 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1222 if (i_bnd + 1 < mx) aj_arr[k_bnd][j_bnd][i_bnd] = aj_arr[k_bnd][j_bnd][i_bnd+1];
1228 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1229 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1230 if (i_bnd - 1 >= 0) aj_arr[k_bnd][j_bnd][i_bnd] = aj_arr[k_bnd][j_bnd][i_bnd-1];
1237 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1238 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1239 if (j_bnd + 1 < my) aj_arr[k_bnd][j_bnd][i_bnd] = aj_arr[k_bnd][j_bnd+1][i_bnd];
1245 for (k_bnd = zs; k_bnd < ze; ++k_bnd) {
1246 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1247 if (j_bnd - 1 >= 0) aj_arr[k_bnd][j_bnd][i_bnd] = aj_arr[k_bnd][j_bnd-1][i_bnd];
1253 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1254 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1255 if (k_bnd + 1 < mz) aj_arr[k_bnd][j_bnd][i_bnd] = aj_arr[k_bnd+1][j_bnd][i_bnd];
1261 for (j_bnd = ys; j_bnd < ye; ++j_bnd) {
1262 for (i_bnd = xs; i_bnd < xe; ++i_bnd) {
1263 if (k_bnd - 1 >= 0) aj_arr[k_bnd][j_bnd][i_bnd] = aj_arr[k_bnd-1][j_bnd][i_bnd];
1269 ierr = DMDAVecRestoreArrayRead(user->
fda, localCoords_from_dm, &nodal_coords_arr); CHKERRQ(ierr);
1270 ierr = DMDAVecRestoreArray(user->
da, user->
Aj, &aj_arr); CHKERRQ(ierr);
1274 ierr = VecAssemblyBegin(user->
Aj); CHKERRQ(ierr);
1275 ierr = VecAssemblyEnd(user->
Aj); CHKERRQ(ierr);
1283 PetscFunctionReturn(0);
1293 PetscErrorCode ierr;
1298 PetscInt xs,ys,zs,xe,ye,ze,mx,my,mz;
1300 PetscFunctionBeginUser;
1307 lCoords = user->
lCoor;
1308 ierr = DMDAVecGetArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1310 ierr = DMDAVecGetArray(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
1312 xs = info.xs; xe = info.xs + info.xm;
1313 ys = info.ys; ye = info.ys + info.ym;
1314 zs = info.zs; ze = info.zs + info.zm;
1315 mx = info.mx; my = info.my; mz = info.mz;
1317 PetscInt k_start_node = (zs == 0) ? zs + 1 : zs;
1318 PetscInt j_start_node = (ys == 0) ? ys + 1 : ys;
1319 PetscInt i_start_node = (xs == 0) ? xs + 1 : xs;
1321 PetscInt k_end_node = (ze == mz) ? ze - 1 : ze;
1322 PetscInt j_end_node = (ye == my) ? ye - 1 : ye;
1323 PetscInt i_end_node = (xe == mx) ? xe - 1 : xe;
1326 for (PetscInt k=k_start_node; k<k_end_node; k++) {
1327 for (PetscInt j=j_start_node; j<j_end_node; j++) {
1328 for (PetscInt i=i_start_node; i<i_end_node; i++) {
1330 cent[k][j][i].
x = 0.125 * (coor[k][j][i].
x + coor[k][j-1][i].
x + coor[k-1][j][i].
x + coor[k-1][j-1][i].
x + coor[k][j][i-1].
x + coor[k][j-1][i-1].
x + coor[k-1][j][i-1].
x + coor[k-1][j-1][i-1].
x);
1331 cent[k][j][i].
y = 0.125 * (coor[k][j][i].
y + coor[k][j-1][i].
y + coor[k-1][j][i].
y + coor[k-1][j-1][i].
y + coor[k][j][i-1].
y + coor[k][j-1][i-1].
y + coor[k-1][j][i-1].
y + coor[k-1][j-1][i-1].
y);
1332 cent[k][j][i].
z = 0.125 * (coor[k][j][i].
z + coor[k][j-1][i].
z + coor[k-1][j][i].
z + coor[k-1][j-1][i].
z + coor[k][j][i-1].
z + coor[k][j-1][i-1].
z + coor[k-1][j][i-1].
z + coor[k-1][j-1][i-1].
z);
1337 ierr = DMDAVecRestoreArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1338 ierr = DMDAVecRestoreArray(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
1341 ierr = VecAssemblyBegin(user->
Cent); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
Cent); CHKERRQ(ierr);
1347 ierr = VecAssemblyBegin(user->
Cent); CHKERRQ(ierr);
1348 ierr = VecAssemblyEnd(user->
Cent); CHKERRQ(ierr);
1353 PetscFunctionReturn(0);
1364 const DMDALocalInfo *info = &user->
info;
1365 const PetscInt start[3] = {info->xs, info->ys, info->zs}, nodes[3] = {info->mx, info->my, info->mz};
1366 PetscInt lo[3], hi[3];
1367 const Cmpnts ***csi, ***eta, ***zet;
1368 const PetscReal ***aj;
1371 PetscFunctionBeginUser;
1374 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi));
1375 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta));
1376 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet));
1377 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lAj, &aj));
1378 PetscCall(DMDAVecGetArray(user->
fda, fraction, &frac));
1379 PetscCall(DMDAVecGetArray(user->
fda, length, &len));
1381 for (PetscInt axis = 0; axis < 3; ++axis) {
1384 const PetscInt a = (axis + 1) % 3, b = (axis + 2) % 3;
1385 const PetscInt na = hi[a] - lo[a], nb = hi[b] - lo[b], n_lines = PetscMax(0, na) * PetscMax(0, nb);
1386 PetscReal *segment, *before, *total;
1388 PetscMPIInt line_rank;
1390 PetscCall(PetscCalloc3(n_lines, &segment, n_lines, &before, n_lines, &total));
1391 for (PetscInt pass = 0; pass < 2; ++pass) {
1392 for (PetscInt ib = lo[b]; ib < hi[b]; ++ib)
1393 for (PetscInt ia = lo[a]; ia < hi[a]; ++ia) {
1394 const PetscInt line = (ia - lo[a]) + na * (ib - lo[b]);
1395 PetscReal s = before[line];
1396 for (PetscInt n = lo[axis]; n < hi[axis]; ++n) {
1399 idx[axis] = n; idx[a] = ia; idx[b] = ib;
1400 const PetscInt i = idx[0], j = idx[1], k = idx[2];
1402 const PetscReal ds = PetscSqrtReal(edges[axis].x * edges[axis].x + edges[axis].y * edges[axis].y +
1403 edges[axis].z * edges[axis].z);
1404 if (pass == 0) { segment[line] += ds;
continue; }
1406 const PetscReal f = (s + 0.5 * ds) / total[line];
1408 if (axis == 0) { frac[k][j][i].
x = f; len[k][j][i].
x = total[line]; }
1409 if (axis == 1) { frac[k][j][i].
y = f; len[k][j][i].
y = total[line]; }
1410 if (axis == 2) { frac[k][j][i].
z = f; len[k][j][i].
z = total[line]; }
1413 if (pass == 1)
break;
1414 PetscCallMPI(MPI_Comm_split(PETSC_COMM_WORLD, (PetscMPIInt)(start[a] + nodes[a] * start[b]),
1415 (PetscMPIInt)start[axis], &line_comm));
1416 PetscCallMPI(MPI_Exscan(segment, before, (PetscMPIInt)n_lines, MPIU_REAL, MPI_SUM, line_comm));
1417 PetscCallMPI(MPI_Comm_rank(line_comm, &line_rank));
1418 if (line_rank == 0) PetscCall(PetscArrayzero(before, n_lines));
1419 PetscCallMPI(MPI_Allreduce(segment, total, (PetscMPIInt)n_lines, MPIU_REAL, MPI_SUM, line_comm));
1420 PetscCallMPI(MPI_Comm_free(&line_comm));
1422 PetscCall(PetscFree3(segment, before, total));
1425 PetscCall(DMDAVecRestoreArray(user->
fda, length, &len));
1426 PetscCall(DMDAVecRestoreArray(user->
fda, fraction, &frac));
1427 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lAj, &aj));
1428 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet));
1429 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta));
1430 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi));
1432 PetscFunctionReturn(0);
1441 PetscErrorCode ierr;
1446 const Cmpnts ***centx_const;
1447 Cmpnts ***icsi, ***ieta, ***izet;
1449 PetscReal dxdc, dydc, dzdc, dxde, dyde, dzde, dxdz, dydz, dzdz;
1451 PetscFunctionBeginUser;
1458 PetscInt xs = info.xs, xe = info.xs + info.xm, mx = info.mx;
1459 PetscInt ys = info.ys, ye = info.ys + info.ym, my = info.my;
1460 PetscInt zs = info.zs, ze = info.zs + info.zm, mz = info.mz;
1462 PetscInt lys = ys; PetscInt lye = ye;
1463 PetscInt lzs = zs; PetscInt lze = ze;
1465 if (ys==0) lys = ys+1;
1466 if (zs==0) lzs = zs+1;
1468 if (xe==mx) lxe=xe-1;
1469 if (ye==my) lye=ye-1;
1470 if (ze==mz) lze=ze-1;
1473 lCoords = user->
lCoor;
1474 ierr = DMDAVecGetArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1475 ierr = DMDAVecGetArray(user->
fda, user->
Centx, ¢x); CHKERRQ(ierr);
1481 for (PetscInt k = PetscMax(zs, 1); k < PetscMin(ze, mz - 1); k++) {
1482 for (PetscInt j = PetscMax(ys, 1); j < PetscMin(ye, my - 1); j++) {
1483 for (PetscInt i = xs; i < PetscMin(xe, mx - 1); i++) {
1492 centx[k][j][i].
x = 0.25 * (coor[k][j][i].
x + coor[k-1][j][i].
x + coor[k][j-1][i].
x + coor[k-1][j-1][i].
x);
1493 centx[k][j][i].
y = 0.25 * (coor[k][j][i].
y + coor[k-1][j][i].
y + coor[k][j-1][i].
y + coor[k-1][j-1][i].
y);
1494 centx[k][j][i].
z = 0.25 * (coor[k][j][i].
z + coor[k-1][j][i].
z + coor[k][j-1][i].
z + coor[k-1][j-1][i].
z);
1525 ierr = DMDAVecRestoreArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1526 ierr = DMDAVecRestoreArray(user->
fda, user->
Centx, ¢x); CHKERRQ(ierr);
1537 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCentx, ¢x_const); CHKERRQ(ierr);
1538 ierr = DMDAVecGetArray(user->
fda, user->
ICsi, &icsi); CHKERRQ(ierr);
1539 ierr = DMDAVecGetArray(user->
fda, user->
IEta, &ieta); CHKERRQ(ierr);
1540 ierr = DMDAVecGetArray(user->
fda, user->
IZet, &izet); CHKERRQ(ierr);
1541 ierr = DMDAVecGetArray(user->
da, user->
IAj, &iaj); CHKERRQ(ierr);
1544 for (PetscInt k=lzs; k<lze; k++) {
1545 for (PetscInt j=lys; j<lye; j++) {
1546 for (PetscInt i=xs; i<lxe; i++) {
1551 dxdc = centx_const[k][j][i+1].
x - centx_const[k][j][i].
x;
1552 dydc = centx_const[k][j][i+1].
y - centx_const[k][j][i].
y;
1553 dzdc = centx_const[k][j][i+1].
z - centx_const[k][j][i].
z;
1556 dxdc = centx_const[k][j][i].
x - centx_const[k][j][i-1].
x;
1557 dydc = centx_const[k][j][i].
y - centx_const[k][j][i-1].
y;
1558 dzdc = centx_const[k][j][i].
z - centx_const[k][j][i-1].
z;
1560 dxdc = 0.5 * (centx_const[k][j][i+1].
x - centx_const[k][j][i-1].
x);
1561 dydc = 0.5 * (centx_const[k][j][i+1].
y - centx_const[k][j][i-1].
y);
1562 dzdc = 0.5 * (centx_const[k][j][i+1].
z - centx_const[k][j][i-1].
z);
1568 dxde = centx_const[k][j+1][i].
x - centx_const[k][j][i].
x;
1569 dyde = centx_const[k][j+1][i].
y - centx_const[k][j][i].
y;
1570 dzde = centx_const[k][j+1][i].
z - centx_const[k][j][i].
z;
1573 dxde = centx_const[k][j][i].
x - centx_const[k][j-1][i].
x;
1574 dyde = centx_const[k][j][i].
y - centx_const[k][j-1][i].
y;
1575 dzde = centx_const[k][j][i].
z - centx_const[k][j-1][i].
z;
1577 dxde = 0.5 * (centx_const[k][j+1][i].
x - centx_const[k][j-1][i].
x);
1578 dyde = 0.5 * (centx_const[k][j+1][i].
y - centx_const[k][j-1][i].
y);
1579 dzde = 0.5 * (centx_const[k][j+1][i].
z - centx_const[k][j-1][i].
z);
1585 dxdz = centx_const[k+1][j][i].
x - centx_const[k][j][i].
x;
1586 dydz = centx_const[k+1][j][i].
y - centx_const[k][j][i].
y;
1587 dzdz = centx_const[k+1][j][i].
z - centx_const[k][j][i].
z;
1590 dxdz = centx_const[k][j][i].
x - centx_const[k-1][j][i].
x;
1591 dydz = centx_const[k][j][i].
y - centx_const[k-1][j][i].
y;
1592 dzdz = centx_const[k][j][i].
z - centx_const[k-1][j][i].
z;
1594 dxdz = 0.5 * (centx_const[k+1][j][i].
x - centx_const[k-1][j][i].
x);
1595 dydz = 0.5 * (centx_const[k+1][j][i].
y - centx_const[k-1][j][i].
y);
1596 dzdz = 0.5 * (centx_const[k+1][j][i].
z - centx_const[k-1][j][i].
z);
1600 icsi[k][j][i].
x = dyde * dzdz - dzde * dydz;
1601 icsi[k][j][i].
y = -dxde * dzdz + dzde * dxdz;
1602 icsi[k][j][i].
z = dxde * dydz - dyde * dxdz;
1604 ieta[k][j][i].
x = dydz * dzdc - dzdz * dydc;
1605 ieta[k][j][i].
y = -dxdz * dzdc + dzdz * dxdc;
1606 ieta[k][j][i].
z = dxdz * dydc - dydz * dxdc;
1608 izet[k][j][i].
x = dydc * dzde - dzdc * dyde;
1609 izet[k][j][i].
y = -dxdc * dzde + dzdc * dxde;
1610 izet[k][j][i].
z = dxdc * dyde - dydc * dxde;
1612 iaj[k][j][i] = dxdc * icsi[k][j][i].
x + dydc * icsi[k][j][i].
y + dzdc * icsi[k][j][i].
z;
1613 if (PetscAbsScalar(iaj[k][j][i]) > 1e-12) {
1614 iaj[k][j][i] = 1.0 / iaj[k][j][i];
1620 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCentx, ¢x_const); CHKERRQ(ierr);
1621 ierr = DMDAVecRestoreArray(user->
fda, user->
ICsi, &icsi); CHKERRQ(ierr);
1622 ierr = DMDAVecRestoreArray(user->
fda, user->
IEta, &ieta); CHKERRQ(ierr);
1623 ierr = DMDAVecRestoreArray(user->
fda, user->
IZet, &izet); CHKERRQ(ierr);
1624 ierr = DMDAVecRestoreArray(user->
da, user->
IAj, &iaj); CHKERRQ(ierr);
1627 ierr = VecAssemblyBegin(user->
ICsi); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
ICsi); CHKERRQ(ierr);
1628 ierr = VecAssemblyBegin(user->
IEta); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
IEta); CHKERRQ(ierr);
1629 ierr = VecAssemblyBegin(user->
IZet); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
IZet); CHKERRQ(ierr);
1630 ierr = VecAssemblyBegin(user->
IAj); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
IAj); CHKERRQ(ierr);
1639 PetscFunctionReturn(0);
1648 PetscErrorCode ierr;
1653 const Cmpnts ***centy_const;
1654 Cmpnts ***jcsi, ***jeta, ***jzet;
1656 PetscReal dxdc, dydc, dzdc, dxde, dyde, dzde, dxdz, dydz, dzdz;
1658 PetscFunctionBeginUser;
1665 PetscInt xs = info.xs, xe = info.xs + info.xm, mx = info.mx;
1666 PetscInt ys = info.ys, ye = info.ys + info.ym, my = info.my;
1667 PetscInt zs = info.zs, ze = info.zs + info.zm, mz = info.mz;
1668 PetscInt lxs = xs; PetscInt lxe = xe;
1670 PetscInt lzs = zs; PetscInt lze = ze;
1672 if (xs==0) lxs = xs+1;
1673 if (zs==0) lzs = zs+1;
1675 if (xe==mx) lxe=xe-1;
1676 if (ye==my) lye=ye-1;
1677 if (ze==mz) lze=ze-1;
1680 lCoords = user->
lCoor;
1681 ierr = DMDAVecGetArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1682 ierr = DMDAVecGetArray(user->
fda, user->
Centy, ¢y); CHKERRQ(ierr);
1684 for (PetscInt k = PetscMax(zs, 1); k < PetscMin(ze, mz - 1); k++) {
1685 for (PetscInt j = ys; j < PetscMin(ye, my - 1); j++) {
1686 for (PetscInt i = PetscMax(xs, 1); i < PetscMin(xe, mx - 1); i++) {
1687 centy[k][j][i].
x = 0.25 * (coor[k][j][i].
x + coor[k-1][j][i].
x + coor[k][j][i-1].
x + coor[k-1][j][i-1].
x);
1688 centy[k][j][i].
y = 0.25 * (coor[k][j][i].
y + coor[k-1][j][i].
y + coor[k][j][i-1].
y + coor[k-1][j][i-1].
y);
1689 centy[k][j][i].
z = 0.25 * (coor[k][j][i].
z + coor[k-1][j][i].
z + coor[k][j][i-1].
z + coor[k-1][j][i-1].
z);
1717 ierr = DMDAVecRestoreArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1718 ierr = DMDAVecRestoreArray(user->
fda, user->
Centy, ¢y); CHKERRQ(ierr);
1728 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCenty, ¢y_const); CHKERRQ(ierr);
1729 ierr = DMDAVecGetArray(user->
fda, user->
JCsi, &jcsi); CHKERRQ(ierr);
1730 ierr = DMDAVecGetArray(user->
fda, user->
JEta, &jeta); CHKERRQ(ierr);
1731 ierr = DMDAVecGetArray(user->
fda, user->
JZet, &jzet); CHKERRQ(ierr);
1732 ierr = DMDAVecGetArray(user->
da, user->
JAj, &jaj); CHKERRQ(ierr);
1735 for (PetscInt k=lzs; k<lze; k++) {
1736 for (PetscInt j=ys; j<lye; j++) {
1737 for (PetscInt i=lxs; i<lxe; i++) {
1742 dxdc = centy_const[k][j][i+1].
x - centy_const[k][j][i].
x;
1743 dydc = centy_const[k][j][i+1].
y - centy_const[k][j][i].
y;
1744 dzdc = centy_const[k][j][i+1].
z - centy_const[k][j][i].
z;
1747 dxdc = centy_const[k][j][i].
x - centy_const[k][j][i-1].
x;
1748 dydc = centy_const[k][j][i].
y - centy_const[k][j][i-1].
y;
1749 dzdc = centy_const[k][j][i].
z - centy_const[k][j][i-1].
z;
1751 dxdc = 0.5 * (centy_const[k][j][i+1].
x - centy_const[k][j][i-1].
x);
1752 dydc = 0.5 * (centy_const[k][j][i+1].
y - centy_const[k][j][i-1].
y);
1753 dzdc = 0.5 * (centy_const[k][j][i+1].
z - centy_const[k][j][i-1].
z);
1759 dxde = centy_const[k][j+1][i].
x - centy_const[k][j][i].
x;
1760 dyde = centy_const[k][j+1][i].
y - centy_const[k][j][i].
y;
1761 dzde = centy_const[k][j+1][i].
z - centy_const[k][j][i].
z;
1764 dxde = centy_const[k][j][i].
x - centy_const[k][j-1][i].
x;
1765 dyde = centy_const[k][j][i].
y - centy_const[k][j-1][i].
y;
1766 dzde = centy_const[k][j][i].
z - centy_const[k][j-1][i].
z;
1768 dxde = 0.5 * (centy_const[k][j+1][i].
x - centy_const[k][j-1][i].
x);
1769 dyde = 0.5 * (centy_const[k][j+1][i].
y - centy_const[k][j-1][i].
y);
1770 dzde = 0.5 * (centy_const[k][j+1][i].
z - centy_const[k][j-1][i].
z);
1776 dxdz = centy_const[k+1][j][i].
x - centy_const[k][j][i].
x;
1777 dydz = centy_const[k+1][j][i].
y - centy_const[k][j][i].
y;
1778 dzdz = centy_const[k+1][j][i].
z - centy_const[k][j][i].
z;
1781 dxdz = centy_const[k][j][i].
x - centy_const[k-1][j][i].
x;
1782 dydz = centy_const[k][j][i].
y - centy_const[k-1][j][i].
y;
1783 dzdz = centy_const[k][j][i].
z - centy_const[k-1][j][i].
z;
1785 dxdz = 0.5 * (centy_const[k+1][j][i].
x - centy_const[k-1][j][i].
x);
1786 dydz = 0.5 * (centy_const[k+1][j][i].
y - centy_const[k-1][j][i].
y);
1787 dzdz = 0.5 * (centy_const[k+1][j][i].
z - centy_const[k-1][j][i].
z);
1791 jcsi[k][j][i].
x = dyde * dzdz - dzde * dydz;
1792 jcsi[k][j][i].
y = -dxde * dzdz + dzde * dxdz;
1793 jcsi[k][j][i].
z = dxde * dydz - dyde * dxdz;
1795 jeta[k][j][i].
x = dydz * dzdc - dzdz * dydc;
1796 jeta[k][j][i].
y = -dxdz * dzdc + dzdz * dxdc;
1797 jeta[k][j][i].
z = dxdz * dydc - dydz * dxdc;
1799 jzet[k][j][i].
x = dydc * dzde - dzdc * dyde;
1800 jzet[k][j][i].
y = -dxdc * dzde + dzdc * dxde;
1801 jzet[k][j][i].
z = dxdc * dyde - dydc * dxde;
1803 jaj[k][j][i] = dxdc * jcsi[k][j][i].
x + dydc * jcsi[k][j][i].
y + dzdc * jcsi[k][j][i].
z;
1804 if (PetscAbsScalar(jaj[k][j][i]) > 1e-12) {
1805 jaj[k][j][i] = 1.0 / jaj[k][j][i];
1811 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCenty, ¢y_const); CHKERRQ(ierr);
1812 ierr = DMDAVecRestoreArray(user->
fda, user->
JCsi, &jcsi); CHKERRQ(ierr);
1813 ierr = DMDAVecRestoreArray(user->
fda, user->
JEta, &jeta); CHKERRQ(ierr);
1814 ierr = DMDAVecRestoreArray(user->
fda, user->
JZet, &jzet); CHKERRQ(ierr);
1815 ierr = DMDAVecRestoreArray(user->
da, user->
JAj, &jaj); CHKERRQ(ierr);
1818 ierr = VecAssemblyBegin(user->
JCsi); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
JCsi); CHKERRQ(ierr);
1819 ierr = VecAssemblyBegin(user->
JEta); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
JEta); CHKERRQ(ierr);
1820 ierr = VecAssemblyBegin(user->
JZet); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
JZet); CHKERRQ(ierr);
1821 ierr = VecAssemblyBegin(user->
JAj); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
JAj); CHKERRQ(ierr);
1830 PetscFunctionReturn(0);
1839 PetscErrorCode ierr;
1844 const Cmpnts ***centz_const;
1845 Cmpnts ***kcsi, ***keta, ***kzet;
1847 PetscReal dxdc, dydc, dzdc, dxde, dyde, dzde, dxdz, dydz, dzdz;
1849 PetscFunctionBeginUser;
1856 PetscInt xs = info.xs, xe = info.xs + info.xm, mx = info.mx;
1857 PetscInt ys = info.ys, ye = info.ys + info.ym, my = info.my;
1858 PetscInt zs = info.zs, ze = info.zs + info.zm, mz = info.mz;
1859 PetscInt lxs = xs; PetscInt lxe = xe;
1860 PetscInt lys = ys; PetscInt lye = ye;
1863 if (xs==0) lxs = xs+1;
1864 if (ys==0) lys = ys+1;
1866 if (xe==mx) lxe=xe-1;
1867 if (ye==my) lye=ye-1;
1868 if (ze==mz) lze=ze-1;
1871 lCoords = user->
lCoor;
1872 ierr = DMDAVecGetArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1873 ierr = DMDAVecGetArray(user->
fda, user->
Centz, ¢z); CHKERRQ(ierr);
1875 for (PetscInt k = zs; k < PetscMin(ze, mz - 1); k++) {
1876 for (PetscInt j = PetscMax(ys, 1); j < PetscMin(ye, my - 1); j++) {
1877 for (PetscInt i = PetscMax(xs, 1); i < PetscMin(xe, mx - 1); i++) {
1878 centz[k][j][i].
x = 0.25 * (coor[k][j][i].
x + coor[k][j-1][i].
x + coor[k][j][i-1].
x + coor[k][j-1][i-1].
x);
1879 centz[k][j][i].
y = 0.25 * (coor[k][j][i].
y + coor[k][j-1][i].
y + coor[k][j][i-1].
y + coor[k][j-1][i-1].
y);
1880 centz[k][j][i].
z = 0.25 * (coor[k][j][i].
z + coor[k][j-1][i].
z + coor[k][j][i-1].
z + coor[k][j-1][i-1].
z);
1908 ierr = DMDAVecRestoreArrayRead(user->
fda, lCoords, &coor); CHKERRQ(ierr);
1909 ierr = DMDAVecRestoreArray(user->
fda, user->
Centz, ¢z); CHKERRQ(ierr);
1919 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCentz, ¢z_const); CHKERRQ(ierr);
1920 ierr = DMDAVecGetArray(user->
fda, user->
KCsi, &kcsi); CHKERRQ(ierr);
1921 ierr = DMDAVecGetArray(user->
fda, user->
KEta, &keta); CHKERRQ(ierr);
1922 ierr = DMDAVecGetArray(user->
fda, user->
KZet, &kzet); CHKERRQ(ierr);
1923 ierr = DMDAVecGetArray(user->
da, user->
KAj, &kaj); CHKERRQ(ierr);
1926 for (PetscInt k=zs; k<lze; k++) {
1927 for (PetscInt j=lys; j<lye; j++) {
1928 for (PetscInt i=lxs; i<lxe; i++) {
1933 dxdc = centz_const[k][j][i+1].
x - centz_const[k][j][i].
x;
1934 dydc = centz_const[k][j][i+1].
y - centz_const[k][j][i].
y;
1935 dzdc = centz_const[k][j][i+1].
z - centz_const[k][j][i].
z;
1938 dxdc = centz_const[k][j][i].
x - centz_const[k][j][i-1].
x;
1939 dydc = centz_const[k][j][i].
y - centz_const[k][j][i-1].
y;
1940 dzdc = centz_const[k][j][i].
z - centz_const[k][j][i-1].
z;
1942 dxdc = 0.5 * (centz_const[k][j][i+1].
x - centz_const[k][j][i-1].
x);
1943 dydc = 0.5 * (centz_const[k][j][i+1].
y - centz_const[k][j][i-1].
y);
1944 dzdc = 0.5 * (centz_const[k][j][i+1].
z - centz_const[k][j][i-1].
z);
1950 dxde = centz_const[k][j+1][i].
x - centz_const[k][j][i].
x;
1951 dyde = centz_const[k][j+1][i].
y - centz_const[k][j][i].
y;
1952 dzde = centz_const[k][j+1][i].
z - centz_const[k][j][i].
z;
1955 dxde = centz_const[k][j][i].
x - centz_const[k][j-1][i].
x;
1956 dyde = centz_const[k][j][i].
y - centz_const[k][j-1][i].
y;
1957 dzde = centz_const[k][j][i].
z - centz_const[k][j-1][i].
z;
1959 dxde = 0.5 * (centz_const[k][j+1][i].
x - centz_const[k][j-1][i].
x);
1960 dyde = 0.5 * (centz_const[k][j+1][i].
y - centz_const[k][j-1][i].
y);
1961 dzde = 0.5 * (centz_const[k][j+1][i].
z - centz_const[k][j-1][i].
z);
1967 dxdz = centz_const[k+1][j][i].
x - centz_const[k][j][i].
x;
1968 dydz = centz_const[k+1][j][i].
y - centz_const[k][j][i].
y;
1969 dzdz = centz_const[k+1][j][i].
z - centz_const[k][j][i].
z;
1972 dxdz = centz_const[k][j][i].
x - centz_const[k-1][j][i].
x;
1973 dydz = centz_const[k][j][i].
y - centz_const[k-1][j][i].
y;
1974 dzdz = centz_const[k][j][i].
z - centz_const[k-1][j][i].
z;
1976 dxdz = 0.5 * (centz_const[k+1][j][i].
x - centz_const[k-1][j][i].
x);
1977 dydz = 0.5 * (centz_const[k+1][j][i].
y - centz_const[k-1][j][i].
y);
1978 dzdz = 0.5 * (centz_const[k+1][j][i].
z - centz_const[k-1][j][i].
z);
1982 kcsi[k][j][i].
x = dyde * dzdz - dzde * dydz;
1983 kcsi[k][j][i].
y = -dxde * dzdz + dzde * dxdz;
1984 kcsi[k][j][i].
z = dxde * dydz - dyde * dxdz;
1986 keta[k][j][i].
x = dydz * dzdc - dzdz * dydc;
1987 keta[k][j][i].
y = -dxdz * dzdc + dzdz * dxdc;
1988 keta[k][j][i].
z = dxdz * dydc - dydz * dxdc;
1990 kzet[k][j][i].
x = dydc * dzde - dzdc * dyde;
1991 kzet[k][j][i].
y = -dxdc * dzde + dzdc * dxde;
1992 kzet[k][j][i].
z = dxdc * dyde - dydc * dxde;
1994 kaj[k][j][i] = dxdc * kcsi[k][j][i].
x + dydc * kcsi[k][j][i].
y + dzdc * kcsi[k][j][i].
z;
1995 if (PetscAbsScalar(kaj[k][j][i]) > 1e-12) {
1996 kaj[k][j][i] = 1.0 / kaj[k][j][i];
2002 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCentz, ¢z_const); CHKERRQ(ierr);
2003 ierr = DMDAVecRestoreArray(user->
fda, user->
KCsi, &kcsi); CHKERRQ(ierr);
2004 ierr = DMDAVecRestoreArray(user->
fda, user->
KEta, &keta); CHKERRQ(ierr);
2005 ierr = DMDAVecRestoreArray(user->
fda, user->
KZet, &kzet); CHKERRQ(ierr);
2006 ierr = DMDAVecRestoreArray(user->
da, user->
KAj, &kaj); CHKERRQ(ierr);
2009 ierr = VecAssemblyBegin(user->
KCsi); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
KCsi); CHKERRQ(ierr);
2010 ierr = VecAssemblyBegin(user->
KEta); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
KEta); CHKERRQ(ierr);
2011 ierr = VecAssemblyBegin(user->
KZet); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
KZet); CHKERRQ(ierr);
2012 ierr = VecAssemblyBegin(user->
KAj); CHKERRQ(ierr); ierr = VecAssemblyEnd(user->
KAj); CHKERRQ(ierr);
2021 PetscFunctionReturn(0);
2027static PetscInt
Gidx(PetscInt i, PetscInt j, PetscInt k,
UserCtx *user)
2030 DMDALocalInfo info = user->
info;
2032 PetscInt mx = info.mx, my = info.my;
2035 DMDAGetAO(user->
da, &ao);
2036 nidx=i+j*mx+k*mx*my;
2038 AOApplicationToPetsc(ao,1,&nidx);
2049 DM da = user->
da, fda = user->
fda;
2050 DMDALocalInfo info = user->
info;
2051 PetscInt xs = info.xs, xe = info.xs + info.xm;
2052 PetscInt ys = info.ys, ye = info.ys + info.ym;
2053 PetscInt zs = info.zs, ze = info.zs + info.zm;
2054 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2055 PetscInt lxs, lys, lzs, lxe, lye, lze;
2058 PetscReal ***div, ***aj;
2059 Cmpnts ***csi, ***eta, ***zet;
2062 PetscFunctionBeginUser;
2070 if (xs == 0) lxs = xs + 1;
2071 if (ys == 0) lys = ys + 1;
2072 if (zs == 0) lzs = zs + 1;
2074 if (xe == mx) lxe = xe - 1;
2075 if (ye == my) lye = ye - 1;
2076 if (ze == mz) lze = ze - 1;
2078 DMDAVecGetArray(fda, user->
lCsi, &csi);
2079 DMDAVecGetArray(fda, user->
lEta, &eta);
2080 DMDAVecGetArray(fda, user->
lZet, &zet);
2081 DMDAVecGetArray(da, user->
lAj, &aj);
2083 VecDuplicate(user->
P, &Div);
2085 DMDAVecGetArray(da, Div, &div);
2087 for (k = lzs; k < lze; k++) {
2088 for (j = lys; j < lye; j++) {
2089 for (i = lxs; i < lxe; i++) {
2090 PetscReal divergence = (csi[k][j][i].
x - csi[k][j][i-1].
x +
2091 eta[k][j][i].
x - eta[k][j-1][i].
x +
2092 zet[k][j][i].
x - zet[k-1][j][i].
x +
2093 csi[k][j][i].
y - csi[k][j][i-1].
y +
2094 eta[k][j][i].
y - eta[k][j-1][i].
y +
2095 zet[k][j][i].
y - zet[k-1][j][i].
y +
2096 csi[k][j][i].
z - csi[k][j][i-1].
z +
2097 eta[k][j][i].
z - eta[k][j-1][i].
z +
2098 zet[k][j][i].
z - zet[k-1][j][i].
z) * aj[k][j][i];
2099 div[k][j][i] = fabs(divergence);
2104 DMDAVecRestoreArray(da, Div, &div);
2106 PetscInt MaxFlatIndex = -1;
2107 VecMax(Div, &MaxFlatIndex, &maxdiv);
2108 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"The Maximum Metric Divergence is %e at flat index %" PetscInt_FMT
".\n",maxdiv,MaxFlatIndex);
2110 for (k=zs; k<ze; k++) {
2111 for (j=ys; j<ye; j++) {
2112 for (i=xs; i<xe; i++) {
2113 if (
Gidx(i,j,k,user) == MaxFlatIndex) {
2114 LOG_ALLOW(
LOCAL,
LOG_INFO,
"The Maximum Metric Divergence(%e) is at location [%d][%d][%d]. \n", maxdiv,(
int)k,(
int)j,(
int)i);
2121 DMDAVecRestoreArray(fda, user->
lCsi, &csi);
2122 DMDAVecRestoreArray(fda, user->
lEta, &eta);
2123 DMDAVecRestoreArray(fda, user->
lZet, &zet);
2124 DMDAVecRestoreArray(da, user->
lAj, &aj);
2130 PetscFunctionReturn(0);
2140 DMDALocalInfo info = user->
info;
2141 PetscInt xs = info.xs, xe = info.xs + info.xm;
2142 PetscInt ys = info.ys, ye = info.ys + info.ym;
2143 PetscInt zs = info.zs, ze = info.zs + info.zm;
2146 PetscFunctionBeginUser;
2150 PetscReal CsiMax, EtaMax, ZetMax;
2151 PetscReal ICsiMax, IEtaMax, IZetMax;
2152 PetscReal JCsiMax, JEtaMax, JZetMax;
2153 PetscReal KCsiMax, KEtaMax, KZetMax;
2154 PetscReal AjMax, IAjMax, JAjMax, KAjMax;
2156 PetscInt CsiMaxArg, EtaMaxArg, ZetMaxArg;
2157 PetscInt ICsiMaxArg, IEtaMaxArg, IZetMaxArg;
2158 PetscInt JCsiMaxArg, JEtaMaxArg, JZetMaxArg;
2159 PetscInt KCsiMaxArg, KEtaMaxArg, KZetMaxArg;
2160 PetscInt AjMaxArg, IAjMaxArg, JAjMaxArg, KAjMaxArg;
2163 VecMax(user->
lCsi,&CsiMaxArg,&CsiMax);
2164 VecMax(user->
lEta,&EtaMaxArg,&EtaMax);
2165 VecMax(user->
lZet,&ZetMaxArg,&ZetMax);
2167 VecMax(user->
lICsi,&ICsiMaxArg,&ICsiMax);
2168 VecMax(user->
lIEta,&IEtaMaxArg,&IEtaMax);
2169 VecMax(user->
lIZet,&IZetMaxArg,&IZetMax);
2171 VecMax(user->
lJCsi,&JCsiMaxArg,&JCsiMax);
2172 VecMax(user->
lJEta,&JEtaMaxArg,&JEtaMax);
2173 VecMax(user->
lJZet,&JZetMaxArg,&JZetMax);
2175 VecMax(user->
lKCsi,&KCsiMaxArg,&KCsiMax);
2176 VecMax(user->
lKEta,&KEtaMaxArg,&KEtaMax);
2177 VecMax(user->
lKZet,&KZetMaxArg,&KZetMax);
2179 VecMax(user->
lAj,&AjMaxArg,&AjMax);
2180 VecMax(user->
lIAj,&IAjMaxArg,&IAjMax);
2181 VecMax(user->
lJAj,&JAjMaxArg,&JAjMax);
2182 VecMax(user->
lKAj,&KAjMaxArg,&KAjMax);
2184 VecMax(user->
lAj,&AjMaxArg,&AjMax);
2185 VecMax(user->
lIAj,&IAjMaxArg,&IAjMax);
2186 VecMax(user->
lJAj,&JAjMaxArg,&JAjMax);
2187 VecMax(user->
lKAj,&KAjMaxArg,&KAjMax);
2191 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"The Max Metric Values are: CsiMax = %le, EtaMax = %le, ZetMax = %le.\n",CsiMax,EtaMax,ZetMax);
2192 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"The Max Metric Values are: ICsiMax = %le, IEtaMax = %le, IZetMax = %le.\n",ICsiMax,IEtaMax,IZetMax);
2193 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"The Max Metric Values are: JCsiMax = %le, JEtaMax = %le, JZetMax = %le.\n",JCsiMax,JEtaMax,JZetMax);
2194 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"The Max Metric Values are: KCsiMax = %le, KEtaMax = %le, KZetMax = %le.\n",KCsiMax,KEtaMax,KZetMax);
2195 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"The Max Volumes(Inverse) are: Aj = %le, IAj = %le, JAj = %le, KAj = %le.\n",AjMax,IAjMax,JAjMax,KAjMax);
2197 for (k=zs; k<ze; k++) {
2198 for (j=ys; j<ye; j++) {
2199 for (i=xs; i<xe; i++) {
2200 if (
Gidx(i,j,k,user) == CsiMaxArg) {
2201 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max Csi = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", CsiMax,k,j,i);
2203 if (
Gidx(i,j,k,user) == EtaMaxArg) {
2204 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max Eta = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", EtaMax,k,j,i);
2206 if (
Gidx(i,j,k,user) == ZetMaxArg) {
2207 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max Zet = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", ZetMax,k,j,i);
2209 if (
Gidx(i,j,k,user) == ICsiMaxArg) {
2210 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max ICsi = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", ICsiMax,k,j,i);
2212 if (
Gidx(i,j,k,user) == IEtaMaxArg) {
2213 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max IEta = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", IEtaMax,k,j,i);
2215 if (
Gidx(i,j,k,user) == IZetMaxArg) {
2216 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max IZet = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", IZetMax,k,j,i);
2218 if (
Gidx(i,j,k,user) == JCsiMaxArg) {
2219 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max JCsi = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", JCsiMax,k,j,i);
2221 if (
Gidx(i,j,k,user) == JEtaMaxArg) {
2222 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max JEta = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", JEtaMax,k,j,i);
2224 if (
Gidx(i,j,k,user) == JZetMaxArg) {
2225 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max JZet = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", JZetMax,k,j,i);
2227 if (
Gidx(i,j,k,user) == KCsiMaxArg) {
2228 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max KCsi = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", KCsiMax,k,j,i);
2230 if (
Gidx(i,j,k,user) == KEtaMaxArg) {
2231 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max KEta = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", KEtaMax,k,j,i);
2233 if (
Gidx(i,j,k,user) == KZetMaxArg) {
2234 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max KZet = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", KZetMax,k,j,i);
2236 if (
Gidx(i,j,k,user) == AjMaxArg) {
2237 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max Aj = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", AjMax,k,j,i);
2239 if (
Gidx(i,j,k,user) == IAjMaxArg) {
2240 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max IAj = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", IAjMax,k,j,i);
2242 if (
Gidx(i,j,k,user) == JAjMaxArg) {
2243 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max JAj = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", JAjMax,k,j,i);
2245 if (
Gidx(i,j,k,user) == KAjMaxArg) {
2246 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Max KAj = %le is at [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] \n", KAjMax,k,j,i);
2260 PetscFunctionReturn(0);
2269 PetscErrorCode ierr;
2274 PetscFunctionBeginUser;
2281 for (PetscInt level = usermg->
mglevels -1 ; level >=0; level--) {
2282 for (PetscInt bi = 0; bi < nblk; bi++) {
2300 if (level == usermg->
mglevels - 1) {
2308 for (PetscInt bi = 0; bi < nblk; bi++) {
2318 PetscFunctionReturn(0);
PetscErrorCode ApplyMetricsPeriodicBCs(UserCtx *user)
(Orchestrator) Updates all metric-related fields in the local ghost cell regions for periodic boundar...
PetscErrorCode SynchronizePeriodicFaceFields(UserCtx *user, char face_direction, PetscInt num_fields, const FieldId field_ids[])
Synchronizes persistent fields belonging to one face family.
PetscErrorCode ComputeCellEdgeVectors(PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, Cmpnts edges[3])
Implementation of ComputeCellEdgeVectors().
#define PICURV_AT(i, j, k)
PetscErrorCode MetricRestoreFacePlaneArrays(UserCtx *user, FacePlaneArrays *arrays)
Implementation of MetricRestoreFacePlaneArrays().
PetscErrorCode CalculateAllGridMetrics(SimCtx *simCtx)
Implementation of CalculateAllGridMetrics().
static const PetscInt kPrimalFaceShift[3][3]
Offset from a face's lower-corner origin to where its family stores it (see Metric....
static const FieldId kFacePlaneFields[]
The catalogued fields MetricComputeFacePlanes() owns.
PetscErrorCode MetricJacobian(UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, PetscReal J[3][3], PetscReal *detJ)
Implementation of MetricJacobian().
PetscErrorCode ComputeCellCenters(UserCtx *user)
Implementation of ComputeCellCenters().
PetscBool MetricFacePlane(const Cmpnts v1, const Cmpnts v2, const Cmpnts v3, const Cmpnts v4, const Cmpnts cell_centroid, FacePlane *plane, PetscBool *degenerate)
Implementation of MetricFacePlane().
PetscErrorCode InvertCovariantMetricTensor(double covariantTensor[3][3], double contravariantTensor[3][3])
Implementation of InvertCovariantMetricTensor().
static PetscErrorCode FacePlaneFieldSlots(UserCtx *user, FieldId id, DM *dm, Vec **global, Vec **local)
Where a face-plane field's vectors live in user, and its DM.
PetscErrorCode ComputeMetricNorms(UserCtx *user)
Implementation of ComputeMetricNorms().
static void TrilinearBlend(const Cmpnts V[8], PetscReal xi, PetscReal eta, PetscReal zta, Cmpnts *Xp)
Blend eight corner values at the supplied trilinear reference coordinates.
static const FieldId kFacePlaneVectorFields[2][2][3]
The plane fields by family: [dual][normal = 0, centroid = 1][axis].
static PetscInt Gidx(PetscInt i, PetscInt j, PetscInt k, UserCtx *user)
Convert logical cell indices into the flattened global cell identifier.
PetscErrorCode CheckAndFixGridOrientation(UserCtx *user)
Implementation of CheckAndFixGridOrientation().
PetscErrorCode MetricGetCellVertices(UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, Cmpnts V[8])
Implementation of MetricGetCellVertices().
void MetricGatherCellFacePlanes(const FacePlaneArrays *arrays, const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k, CellFacePlanes *planes)
Implementation of MetricGatherCellFacePlanes().
PetscErrorCode ComputeJFaceMetrics(UserCtx *user)
Implementation of ComputeJFaceMetrics().
PetscErrorCode MetricDestroyFacePlanes(UserCtx *user)
Implementation of MetricDestroyFacePlanes().
PetscErrorCode ComputeMetricsDivergence(UserCtx *user)
Implementation of ComputeMetricsDivergence().
PetscErrorCode MetricComputeFacePlanes(UserCtx *user)
Implementation of MetricComputeFacePlanes().
PetscErrorCode MetricGetFacePlaneArrays(UserCtx *user, PetscBool dual, FacePlaneArrays *arrays)
Implementation of MetricGetFacePlaneArrays().
PetscErrorCode ComputeGridLineFractions(UserCtx *user, Vec fraction, Vec length)
Implementation of ComputeGridLineFractions().
PetscErrorCode ComputeFaceMetrics(UserCtx *user)
Implementation of ComputeFaceMetrics().
PetscErrorCode ComputeCellCharacteristicLengthScale(PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *dx, double *dy, double *dz)
Implementation of ComputeCellCharacteristicLengthScale().
PetscErrorCode CalculateFaceNormalAndArea(Cmpnts csi, Cmpnts eta, Cmpnts zet, double ni[3], double nj[3], double nk[3], double *Ai, double *Aj, double *Ak)
Implementation of CalculateFaceNormalAndArea().
PetscErrorCode ApplyPeriodicCorrectionsToIFaceCenter(UserCtx *user)
Implementation of ApplyPeriodicCorrectionsToIFaceCenter().
void MetricBuildCellFacePlanes(const Cell *cell, CellFacePlanes *planes)
Implementation of MetricBuildCellFacePlanes().
PetscErrorCode ComputeCellCenteredJacobianInverse(UserCtx *user)
Implementation of ComputeCellCenteredJacobianInverse().
PetscErrorCode ComputeKFaceMetrics(UserCtx *user)
Implementation of ComputeKFaceMetrics().
PetscErrorCode ApplyPeriodicCorrectionsToJFaceCenter(UserCtx *user)
Implementation of ApplyPeriodicCorrectionsToJFaceCenter().
PetscErrorCode ComputeCellDirectionalExtents(PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *l_xi, double *l_eta, double *l_zeta)
Implementation of ComputeCellDirectionalExtents().
static Cmpnts MetricHexCentroid(const Cell *cell)
Centroid of a hexahedral cell: the mean of its eight vertices.
static void MetricGatherHexVertices(const Cmpnts *X, const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k, Cell *hex)
The eight vertices of the cell whose origin node is (i, j, k), in RetrieveCurrentCell() order,...
static void MetricFacePlaneLocals(const UserCtx *user, PetscBool dual, Vec normals[3], Vec centroids[3])
The local vectors of the primal or the dual planes, as MetricGetFacePlaneArrays() reads them.
PetscErrorCode MetricLogicalToPhysical(UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, Cmpnts *Xp)
Implementation of MetricLogicalToPhysical().
PetscErrorCode ComputeIFaceMetrics(UserCtx *user)
Implementation of ComputeIFaceMetrics().
PetscErrorCode ApplyPeriodicCorrectionsToCellCenters(UserCtx *user)
Implementation of ApplyPeriodicCorrectionsToCellCenters().
PetscErrorCode ApplyPeriodicCorrectionsToKFaceCenter(UserCtx *user)
Implementation of ApplyPeriodicCorrectionsToKFaceCenter().
PetscErrorCode MetricVelocityContravariant(const PetscReal J[3][3], PetscReal detJ, const PetscReal u[3], PetscReal uc[3])
Implementation of MetricVelocityContravariant().
const Cmpnts * normal[3]
Unit normals toward +i, +j, +k; zero where there is no plane.
const Cmpnts * centroid[3]
Face vertex means.
static PetscInt MetricCellFacePlanesIndex(const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k)
Index of point (i, j, k) in a block's ghosted local arrays (coordinates, lCent, planes).
const PetscReal * size
Grid-cell sizes; NULL for dual cells.
PetscBool dual
Dual-cell planes (from lCent) rather than grid-cell planes.
Read-only flat arrays of one family of face planes (grid cells or dual cells).
const FieldDescriptor * descriptor
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_DUAL_PLANE_CENTROID_I
@ FIELD_ID_PLANE_NORMAL_J
@ FIELD_ID_PLANE_CENTROID_I
@ FIELD_ID_PLANE_NORMAL_K
@ FIELD_ID_PLANE_CENTROID_K
@ FIELD_ID_PLANE_NORMAL_I
@ FIELD_ID_DUAL_PLANE_CENTROID_J
@ FIELD_ID_DUAL_PLANE_CENTROID_K
@ FIELD_ID_PLANE_CENTROID_J
@ FIELD_ID_DUAL_PLANE_NORMAL_I
@ FIELD_ID_DUAL_PLANE_NORMAL_J
@ FIELD_ID_DUAL_PLANE_NORMAL_K
@ FIELD_ID_SEARCH_CELL_SIZE
Immutable metadata for one field identity.
Non-owning runtime objects resolved for one field and UserCtx.
#define LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt,...)
Logs a message inside a loop, but only every interval iterations.
#define LOG_ALLOW_SYNC(scope, level, fmt,...)
Synchronized logging macro that checks both the log level and whether the calling function is in the ...
#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_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
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 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.
Cmpnts normal
Unit outward normal of (v2 - v1) x (v4 - v1); unnormalised when degenerate.
BoundaryFaceConfig boundary_faces[6]
Cmpnts centroid
Mean of the face's four vertices.
SimCtx * simCtx
Back-pointer to the master simulation context.
static PetscBool ParticlesEnabled(const SimCtx *simCtx)
Whether the run carries particles: a seeded or restored population, or inlets that inject them.
PetscReal size
Mean edge length (GetCellCharacteristicSize()); 0 where unused.
PetscInt degenerate
Bit f set when face f's normal magnitude is below 1e-12.
Cmpnts periodic_translation[3]
Face
Enumerates the six faces of a cubic cell for distance calculations.
PetscBool periodic_translation_valid[3]
FacePlane face[NUM_FACES]
Face planes in LEFT..BACK order.
Cmpnts vertices[8]
Coordinates of the eight vertices of the cell.
BCFace
Identifies the six logical faces of a structured computational block.
Defines the vertices of a single hexahedral grid cell.
The six face planes of one hexahedron, indexed by Face, and its characteristic size.
A 3D point or vector with PetscScalar components.
One cell face as the particle search tests against it: a plane through the vertex mean.
Context for Multigrid operations.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
User-level context for managing the entire multigrid hierarchy.
PetscErrorCode GetCellCharacteristicSize(const Cell *cell, PetscReal *cellSize)
Estimates a characteristic length of the cell for threshold scaling.