84 PetscInt dim = 0, M = 0, N = 0, P = 0, m = 0, n = 0, p = 0, source_dof = 0, stencil_width = 0;
85 DMBoundaryType bx = DM_BOUNDARY_NONE, by = DM_BOUNDARY_NONE, bz = DM_BOUNDARY_NONE;
86 DMDAStencilType stencil_type = DMDA_STENCIL_BOX;
87 const PetscInt *lx = NULL, *ly = NULL, *lz = NULL;
89 PetscFunctionBeginUser;
91 PetscCheck(source != NULL && result != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
92 "Source DM and output pointer are required.");
93 PetscCheck(dof > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
94 "A compatible DM needs a positive degree of freedom, got %" PetscInt_FMT
".", dof);
96 ierr = DMDAGetInfo(source, &dim, &M, &N, &P, &m, &n, &p, &source_dof, &stencil_width,
97 &bx, &by, &bz, &stencil_type); CHKERRQ(ierr);
98 ierr = DMDAGetOwnershipRanges(source, &lx, &ly, &lz); CHKERRQ(ierr);
101 ierr = PetscSNPrintf(
object,
sizeof(
object),
"A %" PetscInt_FMT
"x%" PetscInt_FMT
"x%" PetscInt_FMT
102 " grid field of %" PetscInt_FMT
" components", M, N, P, dof); CHKERRQ(ierr);
103 ierr =
PicurvCheckPetscIntRange(PetscObjectComm((PetscObject)source), (PetscInt64)M * N * P * dof,
object); CHKERRQ(ierr);
105 ierr = DMDACreate3d(PetscObjectComm((PetscObject)source), bx, by, bz, stencil_type,
106 M, N, P, m, n, p, dof, stencil_width, lx, ly, lz, result); CHKERRQ(ierr);
107 ierr = DMSetUp(*result); CHKERRQ(ierr);
109 "Created a dof-%d DM mirroring the block decomposition (%dx%dx%d ranks).\n",
110 (
int)dof, (
int)m, (
int)n, (
int)p);
112 PetscFunctionReturn(0);
122 PetscInt ranks, PetscInt *l)
124 const PetscInt width = coarse_nodes / ranks, extras = coarse_nodes % ranks, cols = extras + 1;
125 PetscInt *worst = NULL;
126 PetscInt *wide = NULL;
128 PetscFunctionBeginUser;
130 PetscCall(PetscMalloc2(ranks * cols, &worst, ranks * cols, &wide));
131 #define PICURV_FINE_NODE(c) ((c) == 0 ? 0 : (refinements ? (((c) - 1) << refinements) + 1 : (c)))
132 for (PetscInt r = 0; r < ranks; ++r) {
133 for (PetscInt e = 0; e < cols; ++e) {
134 worst[r * cols + e] = PETSC_MAX_INT;
135 for (PetscInt w = 0; w <= e; ++w) {
136 const PetscInt before = e - w;
137 if (r == 0 ? before != 0 : worst[(r - 1) * cols + before] == PETSC_MAX_INT)
continue;
139 const PetscInt end = (r == ranks - 1) ? fine_cells :
PICURV_FINE_NODE((r + 1) * width + e);
140 const PetscInt share = PetscMax(end - start, r ? worst[(r - 1) * cols + before] : 0);
141 if (share < worst[r * cols + e]) { worst[r * cols + e] = share; wide[r * cols + e] = w; }
145 #undef PICURV_FINE_NODE
146 for (PetscInt r = ranks - 1, e = extras; r >= 0; --r) {
147 l[r] = width + wide[r * cols + e];
148 e -= wide[r * cols + e];
150 PetscCall(PetscFree2(worst, wide));
152 PetscFunctionReturn(0);
163 DMBoundaryType xperiod = (simCtx->
i_periodic) ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
164 DMBoundaryType yperiod = (simCtx->
j_periodic) ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
165 DMBoundaryType zperiod = (simCtx->
k_periodic) ? DM_BOUNDARY_PERIODIC : DM_BOUNDARY_NONE;
168 PetscInt *lx = NULL, *ly = NULL, *lz = NULL;
171 PetscFunctionBeginUser;
177 LOG_ALLOW_SYNC(
LOCAL,
LOG_DEBUG,
"Rank %d: [Aligning DM] for block %" PetscInt_FMT
" level %" PetscInt_FMT
" (size %" PetscInt_FMT
"x%" PetscInt_FMT
"x%" PetscInt_FMT
") with level %" PetscInt_FMT
"\n", simCtx->
rank, user->
_this, user->
thislevel, user->
IM, user->
JM, user->
KM, coarse_user->
thislevel);
179 DMDAGetInfo(coarse_user->
da, NULL, NULL, NULL, NULL, &m, &n, &p, NULL, NULL, NULL, NULL, NULL, NULL);
180 LOG_ALLOW_SYNC(
LOCAL,
LOG_TRACE,
"Rank %d: Coarse grid processor decomposition is %" PetscInt_FMT
" x %" PetscInt_FMT
" x %" PetscInt_FMT
"\n", simCtx->
rank, m, n, p);
183 PetscInt *lx_contrib, *ly_contrib, *lz_contrib;
184 ierr = PetscMalloc3(m, &lx_contrib, n, &ly_contrib, p, &lz_contrib); CHKERRQ(ierr);
185 ierr = PetscMemzero(lx_contrib, m *
sizeof(PetscInt)); CHKERRQ(ierr);
186 ierr = PetscMemzero(ly_contrib, n *
sizeof(PetscInt)); CHKERRQ(ierr);
187 ierr = PetscMemzero(lz_contrib, p *
sizeof(PetscInt)); CHKERRQ(ierr);
190 info = coarse_user->
info;
191 PetscInt xs = info.xs, xe = info.xs + info.xm, mx = info.mx;
192 PetscInt ys = info.ys, ye = info.ys + info.ym, my = info.my;
193 PetscInt zs = info.zs, ze = info.zs + info.zm, mz = info.mz;
197 PetscInt proc_i = rank % m;
198 PetscInt proc_j = (rank / m) % n;
199 PetscInt proc_k = rank / (m * n);
202 if (user->
isc) lx_contrib[proc_i] = (xe - xs);
204 if (m == 1) lx_contrib[0] = user->
IM + 1;
205 else if (xs == 0) lx_contrib[0] = 2 * xe - 1;
206 else if (xe == mx) lx_contrib[proc_i] = user->
IM + 1 - (2 * xs - 1);
207 else lx_contrib[proc_i] = (xe - xs) * 2;
211 if (user->
jsc) ly_contrib[proc_j] = (ye - ys);
213 if (n == 1) ly_contrib[0] = user->
JM + 1;
214 else if (ys == 0) ly_contrib[0] = 2 * ye - 1;
215 else if (ye == my) ly_contrib[proc_j] = user->
JM + 1 - (2 * ys - 1);
216 else ly_contrib[proc_j] = (ye - ys) * 2;
220 if (user->
ksc) lz_contrib[proc_k] = (ze - zs);
222 if (p == 1) lz_contrib[0] = user->
KM + 1;
223 else if (zs == 0) lz_contrib[0] = 2 * ze - 1;
224 else if (ze == mz) lz_contrib[proc_k] = user->
KM + 1 - (2 * zs - 1);
225 else lz_contrib[proc_k] = (ze - zs) * 2;
227 LOG_ALLOW_SYNC(
LOCAL,
LOG_VERBOSE,
"Rank %d: Calculated this rank's node contribution to fine grid: lx=%" PetscInt_FMT
", ly=%" PetscInt_FMT
", lz=%" PetscInt_FMT
"\n", simCtx->
rank, lx_contrib[proc_i], ly_contrib[proc_j], lz_contrib[proc_k]);
230 ierr = PetscMalloc3(m, &lx, n, &ly, p, &lz); CHKERRQ(ierr);
231 ierr = MPI_Allreduce(lx_contrib, lx, m, MPIU_INT, MPI_MAX, PETSC_COMM_WORLD); CHKERRQ(ierr);
232 ierr = MPI_Allreduce(ly_contrib, ly, n, MPIU_INT, MPI_MAX, PETSC_COMM_WORLD); CHKERRQ(ierr);
233 ierr = MPI_Allreduce(lz_contrib, lz, p, MPIU_INT, MPI_MAX, PETSC_COMM_WORLD); CHKERRQ(ierr);
235 ierr = PetscFree3(lx_contrib, ly_contrib, lz_contrib); CHKERRQ(ierr);
254 if (m > 0 && n > 0 && p > 0) {
257 ierr = PetscMalloc3(m, &lx, n, &ly, p, &lz); CHKERRQ(ierr);
269 ierr = PetscSNPrintf(
object,
sizeof(
object),
"The %" PetscInt_FMT
"x%" PetscInt_FMT
"x%" PetscInt_FMT
270 " grid's 3-component fields", user->
IM + 1, user->
JM + 1, user->
KM + 1); CHKERRQ(ierr);
272 object); CHKERRQ(ierr);
275 ierr = DMDACreate3d(PETSC_COMM_WORLD, xperiod, yperiod, zperiod, DMDA_STENCIL_BOX,
276 user->
IM + 1, user->
JM + 1, user->
KM + 1,
278 1, stencil_width, lx, ly, lz, &user->
da); CHKERRQ(ierr);
281 ierr = PetscFree3(lx, ly, lz); CHKERRQ(ierr);
285 ierr = DMSetUp(user->
da); CHKERRQ(ierr);
286 ierr = DMGetCoordinateDM(user->
da, &user->
fda); CHKERRQ(ierr);
293 ierr = DMDASetUniformCoordinates(user->
da, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0); CHKERRQ(ierr);
294 ierr = DMGetCoordinates(user->
da, &user->
Coor); CHKERRQ(ierr);
295 ierr = DMGetCoordinatesLocal(user->
da, &user->
lCoor); CHKERRQ(ierr);
296 ierr = DMDAGetLocalInfo(user->
da, &user->
info); CHKERRQ(ierr);
301 PetscFunctionReturn(0);
454 const char axis_names[3] = {
'X',
'Y',
'Z'};
455 const Cmpnts ***coor = NULL;
459 PetscFunctionBeginUser;
463 PetscCheck(lcoor != NULL, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
464 "Cannot validate periodic geometry before local coordinates are assigned.");
465 for (PetscInt axis = 0; axis < 3; axis++) {
466 const PetscBool neg_periodic =
468 const PetscBool pos_periodic =
470 PetscReal local_min[3] = {PETSC_MAX_REAL, PETSC_MAX_REAL, PETSC_MAX_REAL};
471 PetscReal local_max[3] = {-PETSC_MAX_REAL, -PETSC_MAX_REAL, -PETSC_MAX_REAL};
472 PetscReal global_min[3], global_max[3];
473 PetscInt local_count = 0, global_count = 0;
477 if (!neg_periodic && !pos_periodic)
continue;
479 PetscCheck(neg_periodic && pos_periodic, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
480 "Periodic geometry in the %c direction requires paired negative and positive faces.",
482 const PetscInt axis_size = axis == 0 ? info.mx : (axis == 1 ? info.my : info.mz);
483 PetscCheck(axis_size >= 5, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
484 "%c-periodic geometry on block %" PetscInt_FMT
" level %" PetscInt_FMT
" requires at least four physical "
485 "nodes in that direction; found %" PetscInt_FMT
".",
488 PetscCall(DMDAVecGetArrayRead(user->
fda, lcoor, &coor));
489 if (axis == 0 && info.xs == 0) {
490 for (PetscInt k = PetscMax(info.zs, 0); k < PetscMin(info.zs + info.zm, info.mz - 1); k++) {
491 for (PetscInt j = PetscMax(info.ys, 0); j < PetscMin(info.ys + info.ym, info.my - 1); j++) {
493 coor[k][j][-2].
x - coor[k][j][0].
x,
494 coor[k][j][-2].
y - coor[k][j][0].
y,
495 coor[k][j][-2].
z - coor[k][j][0].
z
497 for (PetscInt c = 0; c < 3; c++) {
504 }
else if (axis == 1 && info.ys == 0) {
505 for (PetscInt k = PetscMax(info.zs, 0); k < PetscMin(info.zs + info.zm, info.mz - 1); k++) {
506 for (PetscInt i = PetscMax(info.xs, 0); i < PetscMin(info.xs + info.xm, info.mx - 1); i++) {
508 coor[k][-2][i].
x - coor[k][0][i].
x,
509 coor[k][-2][i].
y - coor[k][0][i].
y,
510 coor[k][-2][i].
z - coor[k][0][i].
z
512 for (PetscInt c = 0; c < 3; c++) {
519 }
else if (axis == 2 && info.zs == 0) {
520 for (PetscInt j = PetscMax(info.ys, 0); j < PetscMin(info.ys + info.ym, info.my - 1); j++) {
521 for (PetscInt i = PetscMax(info.xs, 0); i < PetscMin(info.xs + info.xm, info.mx - 1); i++) {
523 coor[-2][j][i].
x - coor[0][j][i].
x,
524 coor[-2][j][i].
y - coor[0][j][i].
y,
525 coor[-2][j][i].
z - coor[0][j][i].
z
527 for (PetscInt c = 0; c < 3; c++) {
535 PetscCall(DMDAVecRestoreArrayRead(user->
fda, lcoor, &coor));
537 PetscCallMPI(MPI_Allreduce(local_min, global_min, 3, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD));
538 PetscCallMPI(MPI_Allreduce(local_max, global_max, 3, MPIU_REAL, MPI_MAX, PETSC_COMM_WORLD));
539 PetscCallMPI(MPI_Allreduce(&local_count, &global_count, 1, MPIU_INT, MPI_SUM, PETSC_COMM_WORLD));
540 PetscCheck(global_count > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
541 "No physical seam nodes were available to validate %c-periodic geometry.",
544 PetscReal translation[3];
545 PetscReal scale = 1.0;
546 PetscReal max_mismatch = 0.0;
547 for (PetscInt c = 0; c < 3; c++) {
548 translation[c] = 0.5 * (global_min[c] + global_max[c]);
549 scale = PetscMax(scale, PetscAbsReal(translation[c]));
550 max_mismatch = PetscMax(max_mismatch, global_max[c] - global_min[c]);
552 const PetscReal tolerance = 1.0e-9 * scale + 100.0 * PETSC_MACHINE_EPSILON;
553 const PetscReal magnitude = PetscSqrtReal(
554 PetscSqr(translation[0]) + PetscSqr(translation[1]) + PetscSqr(translation[2]));
556 PetscCheck(max_mismatch <= tolerance, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
557 "Unsupported %c-periodic geometry on block %" PetscInt_FMT
" level %" PetscInt_FMT
": opposite physical "
558 "surfaces are not related by one constant translation. Maximum component "
559 "mismatch is %.12e (tolerance %.12e).",
561 (
double)max_mismatch, (
double)tolerance);
562 PetscCheck(magnitude > tolerance, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
563 "Unsupported %c-periodic geometry on block %" PetscInt_FMT
" level %" PetscInt_FMT
": seam translation "
564 "magnitude %.12e is zero or too small.",
565 axis_names[axis], user->
_this, user->
thislevel, (
double)magnitude);
568 (
Cmpnts){translation[0], translation[1], translation[2]};
571 "Validated %c-periodic geometry for block %" PetscInt_FMT
" level %" PetscInt_FMT
" with translation "
572 "(%.12e, %.12e, %.12e).\n",
574 (
double)translation[0], (
double)translation[1], (
double)translation[2]);
578 PetscFunctionReturn(0);
724 PetscMPIInt rank = simCtx->
rank;
725 PetscInt block_index = user->
_this;
726 PetscInt IM = user->
IM, JM = user->
JM, KM = user->
KM;
730 PetscReal *gc = NULL;
732 PetscFunctionBeginUser;
736 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Reading interleaved coordinates from file for block %" PetscInt_FMT
"...\n",
737 simCtx->
rank, block_index);
741 PetscInt n_nodes = (IM) * (JM) * (KM);
742 ierr = PetscMalloc1(3 * n_nodes, &gc); CHKERRQ(ierr);
746 if (!fd) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Recieved a NULL file handle.\n");
749 for (PetscInt k = 0; k < KM; k++) {
750 for (PetscInt j = 0; j < JM; j++) {
751 for (PetscInt i = 0; i < IM; i++) {
752 PetscInt base_index = 3 * ((k * (JM) + j) * (IM) + i);
753 if (fscanf(fd,
"%le %le %le\n", &gc[base_index], &gc[base_index + 1], &gc[base_index + 2]) != 3) {
754 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Error reading coordinates for node (i,j,k)=(%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") in block %" PetscInt_FMT
"", i, j, k, block_index);
763 ierr = MPI_Bcast(gc, 3 * n_nodes, MPIU_REAL, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
768 ierr = VecSet(gCoor, 0.0); CHKERRQ(ierr);
769 ierr = DMDAVecGetArray(user->
fda, gCoor, &coor); CHKERRQ(ierr);
771 for (PetscInt k = info.zs; k < info.zs + info.zm; k++) {
772 for (PetscInt j = info.ys; j < info.ys + info.ym; j++) {
773 for (PetscInt i = info.xs; i < info.xs + info.xm; i++) {
774 if(k< KM && j < JM && i < IM){
775 PetscInt base_idx = 3 * ((k * (JM) + j) * (IM) + i);
776 coor[k][j][i].
x = gc[base_idx];
777 coor[k][j][i].
y = gc[base_idx + 1];
778 coor[k][j][i].
z = gc[base_idx + 2];
785 ierr = DMDAVecRestoreArray(user->
fda, gCoor, &coor); CHKERRQ(ierr);
786 ierr = PetscFree(gc); CHKERRQ(ierr);
790 PetscFunctionReturn(0);
799 Vec c_gCoor, f_lCoor;
802 DMDALocalInfo c_info;
805 PetscFunctionBeginUser;
809 LOG_ALLOW_SYNC(
LOCAL,
LOG_DEBUG,
"Rank %d: Restricting coords from level %" PetscInt_FMT
" to level %" PetscInt_FMT
" for block %" PetscInt_FMT
"\n",
812 c_info = coarse_user->
info;
814 c_gCoor = coarse_user->
Coor;
815 f_lCoor = fine_user->
lCoor;
817 ierr = VecSet(c_gCoor, 0.0); CHKERRQ(ierr);
818 ierr = DMDAVecGetArray(coarse_user->
fda, c_gCoor, &c_coor); CHKERRQ(ierr);
819 ierr = DMDAVecGetArrayRead(fine_user->
fda, f_lCoor, &f_coor); CHKERRQ(ierr);
822 PetscInt xs = c_info.xs, xe = c_info.xs + c_info.xm;
823 PetscInt ys = c_info.ys, ye = c_info.ys + c_info.ym;
824 PetscInt zs = c_info.zs, ze = c_info.zs + c_info.zm;
827 PetscInt mx = c_info.mx, my = c_info.my, mz = c_info.mz;
836 for (PetscInt k = zs; k < ze; k++) {
837 for (PetscInt j = ys; j < ye; j++) {
838 for (PetscInt i = xs; i < xe; i++) {
841 ih = coarse_user->
isc ? i : 2 * i;
842 jh = coarse_user->
jsc ? j : 2 * j;
843 kh = coarse_user->
ksc ? k : 2 * k;
847 c_coor[k][j][i] = f_coor[kh][jh][ih];
852 ierr = DMDAVecRestoreArray(coarse_user->
fda, c_gCoor, &c_coor); CHKERRQ(ierr);
853 ierr = DMDAVecRestoreArrayRead(fine_user->
fda, f_lCoor, &f_coor); CHKERRQ(ierr);
860 PetscFunctionReturn(0);
1212 Cmpnts *face_center, PetscReal *face_area)
1214 PetscErrorCode ierr;
1220 PetscReal local_sum[3] = {0.0, 0.0, 0.0};
1221 PetscReal localAreaSum = 0.0;
1222 PetscCount local_n_points = 0;
1227 PetscReal global_sum[3] = {0.0, 0.0, 0.0};
1228 PetscReal globalAreaSum = 0.0;
1229 PetscCount global_n_points = 0;
1237 PetscInt xs = info.xs, xe = info.xs + info.xm;
1238 PetscInt ys = info.ys, ye = info.ys + info.ym;
1239 PetscInt zs = info.zs, ze = info.zs + info.zm;
1242 PetscInt mx = info.mx, my = info.my, mz = info.mz;
1243 PetscInt IM = user->
IM;
1244 PetscInt JM = user->
JM;
1245 PetscInt KM = user->
KM;
1251 PetscInt lxs = xs;
if(xs == 0) lxs = xs + 1;
1252 PetscInt lxe = xe;
if(xe == mx) lxe = xe - 1;
1253 PetscInt lys = ys;
if(ys == 0) lys = ys + 1;
1254 PetscInt lye = ye;
if(ye == my) lye = ye - 1;
1255 PetscInt lzs = zs;
if(zs == 0) lzs = zs + 1;
1256 PetscInt lze = ze;
if(ze == mz) lze = ze - 1;
1262 PetscInt i_max = (xe == mx) ? mx - 1 : xe;
1263 PetscInt j_max = (ye == my) ? my - 1 : ye;
1264 PetscInt k_max = (ze == mz) ? mz - 1 : ze;
1271 Cmpnts ***csi, ***eta, ***zet;
1274 PetscFunctionBeginUser;
1280 PetscBool owns_face = PETSC_FALSE;
1286 lCoor = user->
lCoor;
1287 ierr = DMDAVecGetArrayRead(user->
fda, lCoor, &coor); CHKERRQ(ierr);
1288 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, &nvert); CHKERRQ(ierr);
1289 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
1290 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
1291 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
1308 for (PetscInt k = zs; k < k_max; k++) {
1309 for (PetscInt j = ys; j < j_max; j++) {
1311 local_sum[0] += coor[k][j][i].
x;
1312 local_sum[1] += coor[k][j][i].
y;
1313 local_sum[2] += coor[k][j][i].
z;
1321 for (PetscInt k = lzs; k < lze; k++) {
1322 for (PetscInt j = lys; j < lye; j++) {
1326 if (nvert[k][j][i+1] < 0.1) {
1329 localAreaSum += sqrt(csi[k][j][i].x * csi[k][j][i].x +
1330 csi[k][j][i].y * csi[k][j][i].y +
1331 csi[k][j][i].z * csi[k][j][i].z);
1343 PetscInt i = mx - 2;
1346 for (PetscInt k = zs; k < k_max; k++) {
1347 for (PetscInt j = ys; j < j_max; j++) {
1348 local_sum[0] += coor[k][j][i].
x;
1349 local_sum[1] += coor[k][j][i].
y;
1350 local_sum[2] += coor[k][j][i].
z;
1356 for (PetscInt k = lzs; k < lze; k++) {
1357 for (PetscInt j = lys; j < lye; j++) {
1361 if (nvert[k][j][i] < 0.1) {
1363 localAreaSum += sqrt(csi[k][j][i].x * csi[k][j][i].x +
1364 csi[k][j][i].y * csi[k][j][i].y +
1365 csi[k][j][i].z * csi[k][j][i].z);
1381 for (PetscInt k = zs; k < k_max; k++) {
1382 for (PetscInt i = xs; i < i_max; i++) {
1383 local_sum[0] += coor[k][j][i].
x;
1384 local_sum[1] += coor[k][j][i].
y;
1385 local_sum[2] += coor[k][j][i].
z;
1392 for (PetscInt k = lzs; k < lze; k++) {
1393 for (PetscInt i = lxs; i < lxe; i++) {
1395 if (nvert[k][j+1][i] < 0.1) {
1397 localAreaSum += sqrt(eta[k][j][i].x * eta[k][j][i].x +
1398 eta[k][j][i].y * eta[k][j][i].y +
1399 eta[k][j][i].z * eta[k][j][i].z);
1411 PetscInt j = my - 2;
1414 for (PetscInt k = zs; k < k_max; k++) {
1415 for (PetscInt i = xs; i < i_max; i++) {
1416 local_sum[0] += coor[k][j][i].
x;
1417 local_sum[1] += coor[k][j][i].
y;
1418 local_sum[2] += coor[k][j][i].
z;
1424 for (PetscInt k = lzs; k < lze; k++) {
1425 for (PetscInt i = lxs; i < lxe; i++) {
1427 if (nvert[k][j][i] < 0.1) {
1429 localAreaSum += sqrt(eta[k][j][i].x * eta[k][j][i].x +
1430 eta[k][j][i].y * eta[k][j][i].y +
1431 eta[k][j][i].z * eta[k][j][i].z);
1447 for (PetscInt j = ys; j < j_max; j++) {
1448 for (PetscInt i = xs; i < i_max; i++) {
1449 local_sum[0] += coor[k][j][i].
x;
1450 local_sum[1] += coor[k][j][i].
y;
1451 local_sum[2] += coor[k][j][i].
z;
1458 for (PetscInt j = lys; j < lye; j++) {
1459 for (PetscInt i = lxs; i < lxe; i++) {
1462 if (nvert[k+1][j][i] < 0.1) {
1464 localAreaSum += sqrt(zet[k][j][i].x * zet[k][j][i].x +
1465 zet[k][j][i].y * zet[k][j][i].y +
1466 zet[k][j][i].z * zet[k][j][i].z);
1478 PetscInt k = mz - 2;
1482 for (PetscInt j = ys; j < j_max; j++) {
1483 for (PetscInt i = xs; i < i_max; i++) {
1484 local_sum[0] += coor[k][j][i].
x;
1485 local_sum[1] += coor[k][j][i].
y;
1486 local_sum[2] += coor[k][j][i].
z;
1493 for (PetscInt j = lys; j < lye; j++) {
1494 for (PetscInt i = lxs; i < lxe; i++) {
1497 if (nvert[k][j][i] < 0.1) {
1499 localAreaSum += sqrt(zet[k][j][i].x * zet[k][j][i].x +
1500 zet[k][j][i].y * zet[k][j][i].y +
1501 zet[k][j][i].z * zet[k][j][i].z);
1509 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1510 "Unknown face_id %d in CalculateFaceCenterAndArea", face_id);
1516 ierr = DMDAVecRestoreArrayRead(user->
fda, lCoor, &coor); CHKERRQ(ierr);
1517 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, &nvert); CHKERRQ(ierr);
1518 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
1519 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
1520 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
1526 ierr = MPI_Allreduce(local_sum, global_sum, 3, MPI_DOUBLE, MPI_SUM,
1527 PETSC_COMM_WORLD); CHKERRQ(ierr);
1530 ierr = MPI_Allreduce(&local_n_points, &global_n_points, 1, MPI_COUNT, MPI_SUM,
1531 PETSC_COMM_WORLD); CHKERRQ(ierr);
1534 ierr = MPI_Allreduce(&localAreaSum, &globalAreaSum, 1, MPI_DOUBLE, MPI_SUM,
1535 PETSC_COMM_WORLD); CHKERRQ(ierr);
1540 if (global_n_points > 0) {
1541 face_center->
x = global_sum[0] / global_n_points;
1542 face_center->
y = global_sum[1] / global_n_points;
1543 face_center->
z = global_sum[2] / global_n_points;
1545 "Calculated center for Face %s: (x=%.4f, y=%.4f, z=%.4f) from %lld nodes\n",
1547 face_center->
x, face_center->
y, face_center->
z,
1548 (
long long)global_n_points);
1552 "WARNING: Face %s identified but no grid points found. Center not calculated.\n",
1554 face_center->
x = face_center->
y = face_center->
z = 0.0;
1560 *face_area = globalAreaSum;
1562 "Calculated area for Face %s: Area=%.6f\n",
1566 PetscFunctionReturn(0);