/* Code for manipulating distributed regular 3d arrays in parallel. File created by Peter Mell 7/14/95 */ #include /*I "petscdmda.h" I*/ #include #undef __FUNCT__ #define __FUNCT__ "DMView_DA_3d" static PetscErrorCode DMView_DA_3d(DM da,PetscViewer viewer) { PetscErrorCode ierr; PetscMPIInt rank; PetscBool iascii,isdraw,isbinary; DM_DA *dd = (DM_DA*)da->data; #if defined(PETSC_HAVE_MATLAB_ENGINE) PetscBool ismatlab; #endif PetscFunctionBegin; ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)da),&rank);CHKERRQ(ierr); ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr); ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); #if defined(PETSC_HAVE_MATLAB_ENGINE) ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERMATLAB,&ismatlab);CHKERRQ(ierr); #endif if (iascii) { PetscViewerFormat format; ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); if (format != PETSC_VIEWER_ASCII_VTK && format != PETSC_VIEWER_ASCII_VTK_CELL) { DMDALocalInfo info; ierr = DMDAGetLocalInfo(da,&info);CHKERRQ(ierr); ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Processor [%d] M %D N %D P %D m %D n %D p %D w %D s %D\n",rank,dd->M,dd->N,dd->P,dd->m,dd->n,dd->p,dd->w,dd->s);CHKERRQ(ierr); ierr = PetscViewerASCIISynchronizedPrintf(viewer,"X range of indices: %D %D, Y range of indices: %D %D, Z range of indices: %D %D\n", info.xs,info.xs+info.xm,info.ys,info.ys+info.ym,info.zs,info.zs+info.zm);CHKERRQ(ierr); #if !defined(PETSC_USE_COMPLEX) if (da->coordinates) { PetscInt last; const PetscReal *coors; ierr = VecGetArrayRead(da->coordinates,&coors);CHKERRQ(ierr); ierr = VecGetLocalSize(da->coordinates,&last);CHKERRQ(ierr); last = last - 3; ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Lower left corner %g %g %g : Upper right %g %g %g\n",(double)coors[0],(double)coors[1],(double)coors[2],(double)coors[last],(double)coors[last+1],(double)coors[last+2]);CHKERRQ(ierr); ierr = VecRestoreArrayRead(da->coordinates,&coors);CHKERRQ(ierr); } #endif ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr); } else { ierr = DMView_DA_VTK(da,viewer);CHKERRQ(ierr); } } else if (isdraw) { PetscDraw draw; PetscReal ymin = -1.0,ymax = (PetscReal)dd->N; PetscReal xmin = -1.0,xmax = (PetscReal)((dd->M+2)*dd->P),x,y,ycoord,xcoord; PetscInt k,plane,base; const PetscInt *idx; char node[10]; PetscBool isnull; ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); ierr = PetscDrawClear(draw);CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);CHKERRQ(ierr); ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); /* first processor draw all node lines */ if (!rank) { for (k=0; kP; k++) { ymin = 0.0; ymax = (PetscReal)(dd->N - 1); for (xmin=(PetscReal)(k*(dd->M+1)); xmin<(PetscReal)(dd->M+(k*(dd->M+1))); xmin++) { ierr = PetscDrawLine(draw,xmin,ymin,xmin,ymax,PETSC_DRAW_BLACK);CHKERRQ(ierr); } xmin = (PetscReal)(k*(dd->M+1)); xmax = xmin + (PetscReal)(dd->M - 1); for (ymin=0; ymin<(PetscReal)dd->N; ymin++) { ierr = PetscDrawLine(draw,xmin,ymin,xmax,ymin,PETSC_DRAW_BLACK);CHKERRQ(ierr); } } } ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); /*Go through and draw for each plane*/ for (k=0; kP; k++) { if ((k >= dd->zs) && (k < dd->ze)) { /* draw my box */ ymin = dd->ys; ymax = dd->ye - 1; xmin = dd->xs/dd->w + (dd->M+1)*k; xmax =(dd->xe-1)/dd->w + (dd->M+1)*k; ierr = PetscDrawLine(draw,xmin,ymin,xmax,ymin,PETSC_DRAW_RED);CHKERRQ(ierr); ierr = PetscDrawLine(draw,xmin,ymin,xmin,ymax,PETSC_DRAW_RED);CHKERRQ(ierr); ierr = PetscDrawLine(draw,xmin,ymax,xmax,ymax,PETSC_DRAW_RED);CHKERRQ(ierr); ierr = PetscDrawLine(draw,xmax,ymin,xmax,ymax,PETSC_DRAW_RED);CHKERRQ(ierr); xmin = dd->xs/dd->w; xmax =(dd->xe-1)/dd->w; /* identify which processor owns the box */ ierr = PetscSNPrintf(node,sizeof(node),"%d",(int)rank);CHKERRQ(ierr); ierr = PetscDrawString(draw,xmin+(dd->M+1)*k+.2,ymin+.3,PETSC_DRAW_RED,node);CHKERRQ(ierr); /* put in numbers*/ base = (dd->base+(dd->xe-dd->xs)*(dd->ye-dd->ys)*(k-dd->zs))/dd->w; for (y=ymin; y<=ymax; y++) { for (x=xmin+(dd->M+1)*k; x<=xmax+(dd->M+1)*k; x++) { ierr = PetscSNPrintf(node,sizeof(node),"%d",(int)base++);CHKERRQ(ierr); ierr = PetscDrawString(draw,x,y,PETSC_DRAW_BLACK,node);CHKERRQ(ierr); } } } } ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); for (k=0-dd->s; kP+dd->s; k++) { /* Go through and draw for each plane */ if ((k >= dd->Zs) && (k < dd->Ze)) { /* overlay ghost numbers, useful for error checking */ base = (dd->Xe-dd->Xs)*(dd->Ye-dd->Ys)*(k-dd->Zs)/dd->w; ierr = ISLocalToGlobalMappingGetBlockIndices(da->ltogmap,&idx);CHKERRQ(ierr); plane=k; /* Keep z wrap around points on the drawing */ if (k<0) plane=dd->P+k; if (k>=dd->P) plane=k-dd->P; ymin = dd->Ys; ymax = dd->Ye; xmin = (dd->M+1)*plane*dd->w; xmax = (dd->M+1)*plane*dd->w+dd->M*dd->w; for (y=ymin; yXs; xXe; x+=dd->w) { sprintf(node,"%d",(int)(idx[base])); ycoord = y; /*Keep y wrap around points on drawing */ if (y<0) ycoord = dd->N+y; if (y>=dd->N) ycoord = y-dd->N; xcoord = x; /* Keep x wrap points on drawing */ if (x=xmax) xcoord = xmin + (x-xmax); ierr = PetscDrawString(draw,xcoord/dd->w,ycoord,PETSC_DRAW_BLUE,node);CHKERRQ(ierr); base++; } } ierr = ISLocalToGlobalMappingRestoreBlockIndices(da->ltogmap,&idx);CHKERRQ(ierr); } } ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawSave(draw);CHKERRQ(ierr); } else if (isbinary) { ierr = DMView_DA_Binary(da,viewer);CHKERRQ(ierr); #if defined(PETSC_HAVE_MATLAB_ENGINE) } else if (ismatlab) { ierr = DMView_DA_Matlab(da,viewer);CHKERRQ(ierr); #endif } PetscFunctionReturn(0); } #undef __FUNCT__ #define __FUNCT__ "DMSetUp_DA_3D" PetscErrorCode DMSetUp_DA_3D(DM da) { DM_DA *dd = (DM_DA*)da->data; const PetscInt M = dd->M; const PetscInt N = dd->N; const PetscInt P = dd->P; PetscInt m = dd->m; PetscInt n = dd->n; PetscInt p = dd->p; const PetscInt dof = dd->w; const PetscInt s = dd->s; DMBoundaryType bx = dd->bx; DMBoundaryType by = dd->by; DMBoundaryType bz = dd->bz; DMDAStencilType stencil_type = dd->stencil_type; PetscInt *lx = dd->lx; PetscInt *ly = dd->ly; PetscInt *lz = dd->lz; MPI_Comm comm; PetscMPIInt rank,size; PetscInt xs = 0,xe,ys = 0,ye,zs = 0,ze,x = 0,y = 0,z = 0; PetscInt Xs,Xe,Ys,Ye,Zs,Ze,IXs,IXe,IYs,IYe,IZs,IZe,pm; PetscInt left,right,up,down,bottom,top,i,j,k,*idx,nn; PetscInt n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n14; PetscInt n15,n16,n17,n18,n19,n20,n21,n22,n23,n24,n25,n26; PetscInt *bases,*ldims,base,x_t,y_t,z_t,s_t,count,s_x,s_y,s_z; PetscInt sn0 = 0,sn1 = 0,sn2 = 0,sn3 = 0,sn5 = 0,sn6 = 0,sn7 = 0; PetscInt sn8 = 0,sn9 = 0,sn11 = 0,sn15 = 0,sn24 = 0,sn25 = 0,sn26 = 0; PetscInt sn17 = 0,sn18 = 0,sn19 = 0,sn20 = 0,sn21 = 0,sn23 = 0; Vec local,global; VecScatter gtol; IS to,from; PetscBool twod; PetscErrorCode ierr; PetscFunctionBegin; if (stencil_type == DMDA_STENCIL_BOX && (bx == DM_BOUNDARY_MIRROR || by == DM_BOUNDARY_MIRROR || bz == DM_BOUNDARY_MIRROR)) SETERRQ(PetscObjectComm((PetscObject)da),PETSC_ERR_SUP,"Mirror boundary and box stencil"); ierr = PetscObjectGetComm((PetscObject) da, &comm);CHKERRQ(ierr); #if !defined(PETSC_USE_64BIT_INDICES) if (((Petsc64bitInt) M)*((Petsc64bitInt) N)*((Petsc64bitInt) P)*((Petsc64bitInt) dof) > (Petsc64bitInt) PETSC_MPI_INT_MAX) SETERRQ3(comm,PETSC_ERR_INT_OVERFLOW,"Mesh of %D by %D by %D (dof) is too large for 32 bit indices",M,N,dof); #endif ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); if (m != PETSC_DECIDE) { if (m < 1) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Non-positive number of processors in X direction: %D",m); else if (m > size) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many processors in X direction: %D %d",m,size); } if (n != PETSC_DECIDE) { if (n < 1) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Non-positive number of processors in Y direction: %D",n); else if (n > size) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many processors in Y direction: %D %d",n,size); } if (p != PETSC_DECIDE) { if (p < 1) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Non-positive number of processors in Z direction: %D",p); else if (p > size) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many processors in Z direction: %D %d",p,size); } if ((m > 0) && (n > 0) && (p > 0) && (m*n*p != size)) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"m %D * n %D * p %D != size %d",m,n,p,size); /* Partition the array among the processors */ if (m == PETSC_DECIDE && n != PETSC_DECIDE && p != PETSC_DECIDE) { m = size/(n*p); } else if (m != PETSC_DECIDE && n == PETSC_DECIDE && p != PETSC_DECIDE) { n = size/(m*p); } else if (m != PETSC_DECIDE && n != PETSC_DECIDE && p == PETSC_DECIDE) { p = size/(m*n); } else if (m == PETSC_DECIDE && n == PETSC_DECIDE && p != PETSC_DECIDE) { /* try for squarish distribution */ m = (int)(0.5 + PetscSqrtReal(((PetscReal)M)*((PetscReal)size)/((PetscReal)N*p))); if (!m) m = 1; while (m > 0) { n = size/(m*p); if (m*n*p == size) break; m--; } if (!m) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"bad p value: p = %D",p); if (M > N && m < n) {PetscInt _m = m; m = n; n = _m;} } else if (m == PETSC_DECIDE && n != PETSC_DECIDE && p == PETSC_DECIDE) { /* try for squarish distribution */ m = (int)(0.5 + PetscSqrtReal(((PetscReal)M)*((PetscReal)size)/((PetscReal)P*n))); if (!m) m = 1; while (m > 0) { p = size/(m*n); if (m*n*p == size) break; m--; } if (!m) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"bad n value: n = %D",n); if (M > P && m < p) {PetscInt _m = m; m = p; p = _m;} } else if (m != PETSC_DECIDE && n == PETSC_DECIDE && p == PETSC_DECIDE) { /* try for squarish distribution */ n = (int)(0.5 + PetscSqrtReal(((PetscReal)N)*((PetscReal)size)/((PetscReal)P*m))); if (!n) n = 1; while (n > 0) { p = size/(m*n); if (m*n*p == size) break; n--; } if (!n) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"bad m value: m = %D",n); if (N > P && n < p) {PetscInt _n = n; n = p; p = _n;} } else if (m == PETSC_DECIDE && n == PETSC_DECIDE && p == PETSC_DECIDE) { /* try for squarish distribution */ n = (PetscInt)(0.5 + PetscPowReal(((PetscReal)N*N)*((PetscReal)size)/((PetscReal)P*M),(PetscReal)(1./3.))); if (!n) n = 1; while (n > 0) { pm = size/n; if (n*pm == size) break; n--; } if (!n) n = 1; m = (PetscInt)(0.5 + PetscSqrtReal(((PetscReal)M)*((PetscReal)size)/((PetscReal)P*n))); if (!m) m = 1; while (m > 0) { p = size/(m*n); if (m*n*p == size) break; m--; } if (M > P && m < p) {PetscInt _m = m; m = p; p = _m;} } else if (m*n*p != size) SETERRQ(PetscObjectComm((PetscObject)da),PETSC_ERR_ARG_OUTOFRANGE,"Given Bad partition"); if (m*n*p != size) SETERRQ(PetscObjectComm((PetscObject)da),PETSC_ERR_PLIB,"Could not find good partition"); if (M < m) SETERRQ2(PetscObjectComm((PetscObject)da),PETSC_ERR_ARG_OUTOFRANGE,"Partition in x direction is too fine! %D %D",M,m); if (N < n) SETERRQ2(PetscObjectComm((PetscObject)da),PETSC_ERR_ARG_OUTOFRANGE,"Partition in y direction is too fine! %D %D",N,n); if (P < p) SETERRQ2(PetscObjectComm((PetscObject)da),PETSC_ERR_ARG_OUTOFRANGE,"Partition in z direction is too fine! %D %D",P,p); /* Determine locally owned region [x, y, or z]s is the first local node number, [x, y, z] is the number of local nodes */ if (!lx) { ierr = PetscMalloc1(m, &dd->lx);CHKERRQ(ierr); lx = dd->lx; for (i=0; i (i % m)); } x = lx[rank % m]; xs = 0; for (i=0; i<(rank%m); i++) xs += lx[i]; if ((x < s) && ((m > 1) || (bx == DM_BOUNDARY_PERIODIC))) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Local x-width of domain x %D is smaller than stencil width s %D",x,s); if (!ly) { ierr = PetscMalloc1(n, &dd->ly);CHKERRQ(ierr); ly = dd->ly; for (i=0; i (i % n)); } y = ly[(rank % (m*n))/m]; if ((y < s) && ((n > 1) || (by == DM_BOUNDARY_PERIODIC))) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Local y-width of domain y %D is smaller than stencil width s %D",y,s); ys = 0; for (i=0; i<(rank % (m*n))/m; i++) ys += ly[i]; if (!lz) { ierr = PetscMalloc1(p, &dd->lz);CHKERRQ(ierr); lz = dd->lz; for (i=0; i (i % p)); } z = lz[rank/(m*n)]; /* note this is different than x- and y-, as we will handle as an important special case when p=P=1 and DM_BOUNDARY_PERIODIC and s > z. This is to deal with 2D problems in a 3D code. Additional code for this case is noted with "2d case" comments */ twod = PETSC_FALSE; if (P == 1) twod = PETSC_TRUE; else if ((z < s) && ((p > 1) || (bz == DM_BOUNDARY_PERIODIC))) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Local z-width of domain z %D is smaller than stencil width s %D",z,s); zs = 0; for (i=0; i<(rank/(m*n)); i++) zs += lz[i]; ye = ys + y; xe = xs + x; ze = zs + z; /* determine ghost region (Xs) and region scattered into (IXs) */ if (xs-s > 0) { Xs = xs - s; IXs = xs - s; } else { if (bx) Xs = xs - s; else Xs = 0; IXs = 0; } if (xe+s <= M) { Xe = xe + s; IXe = xe + s; } else { if (bx) { Xs = xs - s; Xe = xe + s; } else Xe = M; IXe = M; } if (bx == DM_BOUNDARY_PERIODIC || bx == DM_BOUNDARY_MIRROR) { IXs = xs - s; IXe = xe + s; Xs = xs - s; Xe = xe + s; } if (ys-s > 0) { Ys = ys - s; IYs = ys - s; } else { if (by) Ys = ys - s; else Ys = 0; IYs = 0; } if (ye+s <= N) { Ye = ye + s; IYe = ye + s; } else { if (by) Ye = ye + s; else Ye = N; IYe = N; } if (by == DM_BOUNDARY_PERIODIC || by == DM_BOUNDARY_MIRROR) { IYs = ys - s; IYe = ye + s; Ys = ys - s; Ye = ye + s; } if (zs-s > 0) { Zs = zs - s; IZs = zs - s; } else { if (bz) Zs = zs - s; else Zs = 0; IZs = 0; } if (ze+s <= P) { Ze = ze + s; IZe = ze + s; } else { if (bz) Ze = ze + s; else Ze = P; IZe = P; } if (bz == DM_BOUNDARY_PERIODIC || bz == DM_BOUNDARY_MIRROR) { IZs = zs - s; IZe = ze + s; Zs = zs - s; Ze = ze + s; } /* Resize all X parameters to reflect w */ s_x = s; s_y = s; s_z = s; /* determine starting point of each processor */ nn = x*y*z; ierr = PetscMalloc2(size+1,&bases,size,&ldims);CHKERRQ(ierr); ierr = MPI_Allgather(&nn,1,MPIU_INT,ldims,1,MPIU_INT,comm);CHKERRQ(ierr); bases[0] = 0; for (i=1; i<=size; i++) bases[i] = ldims[i-1]; for (i=1; i<=size; i++) bases[i] += bases[i-1]; base = bases[rank]*dof; /* allocate the base parallel and sequential vectors */ dd->Nlocal = x*y*z*dof; ierr = VecCreateMPIWithArray(comm,dof,dd->Nlocal,PETSC_DECIDE,NULL,&global);CHKERRQ(ierr); dd->nlocal = (Xe-Xs)*(Ye-Ys)*(Ze-Zs)*dof; ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,dof,dd->nlocal,NULL,&local);CHKERRQ(ierr); /* generate appropriate vector scatters */ /* local to global inserts non-ghost point region into global */ ierr = PetscMalloc1((IXe-IXs)*(IYe-IYs)*(IZe-IZs),&idx);CHKERRQ(ierr); left = xs - Xs; right = left + x; bottom = ys - Ys; top = bottom + y; down = zs - Zs; up = down + z; count = 0; for (i=down; ineighbors);CHKERRQ(ierr); dd->neighbors[0] = n0; dd->neighbors[1] = n1; dd->neighbors[2] = n2; dd->neighbors[3] = n3; dd->neighbors[4] = n4; dd->neighbors[5] = n5; dd->neighbors[6] = n6; dd->neighbors[7] = n7; dd->neighbors[8] = n8; dd->neighbors[9] = n9; dd->neighbors[10] = n10; dd->neighbors[11] = n11; dd->neighbors[12] = n12; dd->neighbors[13] = rank; dd->neighbors[14] = n14; dd->neighbors[15] = n15; dd->neighbors[16] = n16; dd->neighbors[17] = n17; dd->neighbors[18] = n18; dd->neighbors[19] = n19; dd->neighbors[20] = n20; dd->neighbors[21] = n21; dd->neighbors[22] = n22; dd->neighbors[23] = n23; dd->neighbors[24] = n24; dd->neighbors[25] = n25; dd->neighbors[26] = n26; /* If star stencil then delete the corner neighbors */ if (stencil_type == DMDA_STENCIL_STAR) { /* save information about corner neighbors */ sn0 = n0; sn1 = n1; sn2 = n2; sn3 = n3; sn5 = n5; sn6 = n6; sn7 = n7; sn8 = n8; sn9 = n9; sn11 = n11; sn15 = n15; sn17 = n17; sn18 = n18; sn19 = n19; sn20 = n20; sn21 = n21; sn23 = n23; sn24 = n24; sn25 = n25; sn26 = n26; n0 = n1 = n2 = n3 = n5 = n6 = n7 = n8 = n9 = n11 = n15 = n17 = n18 = n19 = n20 = n21 = n23 = n24 = n25 = n26 = -1; } ierr = PetscMalloc1((Xe-Xs)*(Ye-Ys)*(Ze-Zs),&idx);CHKERRQ(ierr); nn = 0; /* Bottom Level */ for (k=0; k= 0) { /* left below */ x_t = lx[n0 % m]; y_t = ly[(n0 % (m*n))/m]; z_t = lz[n0 / (m*n)]; s_t = bases[n0] + x_t*y_t*z_t - (s_y-i)*x_t - s_x - (s_z-k-1)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n0] + x_t*y_t*z_t - (s_y-i)*x_t - s_x; /* 2D case */ for (j=0; j= 0) { /* directly below */ x_t = x; y_t = ly[(n1 % (m*n))/m]; z_t = lz[n1 / (m*n)]; s_t = bases[n1] + x_t*y_t*z_t - (s_y+1-i)*x_t - (s_z-k-1)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n1] + x_t*y_t*z_t - (s_y+1-i)*x_t; /* 2D case */ for (j=0; j= 0) { /* right below */ x_t = lx[n2 % m]; y_t = ly[(n2 % (m*n))/m]; z_t = lz[n2 / (m*n)]; s_t = bases[n2] + x_t*y_t*z_t - (s_y+1-i)*x_t - (s_z-k-1)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n2] + x_t*y_t*z_t - (s_y+1-i)*x_t; /* 2D case */ for (j=0; j= 0) { /* directly left */ x_t = lx[n3 % m]; y_t = y; z_t = lz[n3 / (m*n)]; s_t = bases[n3] + (i+1)*x_t - s_x + x_t*y_t*z_t - (s_z-k)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n3] + (i+1)*x_t - s_x + x_t*y_t*z_t - x_t*y_t; /* 2D case */ for (j=0; j= 0) { /* middle */ x_t = x; y_t = y; z_t = lz[n4 / (m*n)]; s_t = bases[n4] + i*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n4] + i*x_t + x_t*y_t*z_t - x_t*y_t; /* 2D case */ for (j=0; j= 0) { /* directly right */ x_t = lx[n5 % m]; y_t = y; z_t = lz[n5 / (m*n)]; s_t = bases[n5] + i*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n5] + i*x_t + x_t*y_t*z_t - x_t*y_t; /* 2D case */ for (j=0; j= 0) { /* left above */ x_t = lx[n6 % m]; y_t = ly[(n6 % (m*n))/m]; z_t = lz[n6 / (m*n)]; s_t = bases[n6] + i*x_t - s_x + x_t*y_t*z_t - (s_z-k)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n6] + i*x_t - s_x + x_t*y_t*z_t - x_t*y_t; /* 2D case */ for (j=0; j= 0) { /* directly above */ x_t = x; y_t = ly[(n7 % (m*n))/m]; z_t = lz[n7 / (m*n)]; s_t = bases[n7] + (i-1)*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n7] + (i-1)*x_t + x_t*y_t*z_t - x_t*y_t; /* 2D case */ for (j=0; j= 0) { /* right above */ x_t = lx[n8 % m]; y_t = ly[(n8 % (m*n))/m]; z_t = lz[n8 / (m*n)]; s_t = bases[n8] + (i-1)*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; if (twod && (s_t < 0)) s_t = bases[n8] + (i-1)*x_t + x_t*y_t*z_t - x_t*y_t; /* 2D case */ for (j=0; j= 0) { /* left below */ x_t = lx[n9 % m]; y_t = ly[(n9 % (m*n))/m]; /* z_t = z; */ s_t = bases[n9] - (s_y-i)*x_t -s_x + (k+1)*x_t*y_t; for (j=0; j= 0) { /* directly below */ x_t = x; y_t = ly[(n10 % (m*n))/m]; /* z_t = z; */ s_t = bases[n10] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; for (j=0; j= 0) { /* right below */ x_t = lx[n11 % m]; y_t = ly[(n11 % (m*n))/m]; /* z_t = z; */ s_t = bases[n11] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; for (j=0; j= 0) { /* directly left */ x_t = lx[n12 % m]; y_t = y; /* z_t = z; */ s_t = bases[n12] + (i+1)*x_t - s_x + k*x_t*y_t; for (j=0; j= 0) { /* directly right */ x_t = lx[n14 % m]; y_t = y; /* z_t = z; */ s_t = bases[n14] + i*x_t + k*x_t*y_t; for (j=0; j= 0) { /* left above */ x_t = lx[n15 % m]; y_t = ly[(n15 % (m*n))/m]; /* z_t = z; */ s_t = bases[n15] + i*x_t - s_x + k*x_t*y_t; for (j=0; j= 0) { /* directly above */ x_t = x; y_t = ly[(n16 % (m*n))/m]; /* z_t = z; */ s_t = bases[n16] + (i-1)*x_t + k*x_t*y_t; for (j=0; j= 0) { /* right above */ x_t = lx[n17 % m]; y_t = ly[(n17 % (m*n))/m]; /* z_t = z; */ s_t = bases[n17] + (i-1)*x_t + k*x_t*y_t; for (j=0; j= 0) { /* left below */ x_t = lx[n18 % m]; y_t = ly[(n18 % (m*n))/m]; /* z_t = lz[n18 / (m*n)]; */ s_t = bases[n18] - (s_y-i)*x_t -s_x + (k+1)*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n18] - (s_y-i)*x_t -s_x + x_t*y_t; /* 2d case */ for (j=0; j= 0) { /* directly below */ x_t = x; y_t = ly[(n19 % (m*n))/m]; /* z_t = lz[n19 / (m*n)]; */ s_t = bases[n19] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n19] - (s_y+1-i)*x_t + x_t*y_t; /* 2d case */ for (j=0; j= 0) { /* right below */ x_t = lx[n20 % m]; y_t = ly[(n20 % (m*n))/m]; /* z_t = lz[n20 / (m*n)]; */ s_t = bases[n20] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n20] - (s_y+1-i)*x_t + x_t*y_t; /* 2d case */ for (j=0; j= 0) { /* directly left */ x_t = lx[n21 % m]; y_t = y; /* z_t = lz[n21 / (m*n)]; */ s_t = bases[n21] + (i+1)*x_t - s_x + k*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n21] + (i+1)*x_t - s_x; /* 2d case */ for (j=0; j= 0) { /* middle */ x_t = x; y_t = y; /* z_t = lz[n22 / (m*n)]; */ s_t = bases[n22] + i*x_t + k*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n22] + i*x_t; /* 2d case */ for (j=0; j= 0) { /* directly right */ x_t = lx[n23 % m]; y_t = y; /* z_t = lz[n23 / (m*n)]; */ s_t = bases[n23] + i*x_t + k*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n23] + i*x_t; /* 2d case */ for (j=0; j= 0) { /* left above */ x_t = lx[n24 % m]; y_t = ly[(n24 % (m*n))/m]; /* z_t = lz[n24 / (m*n)]; */ s_t = bases[n24] + i*x_t - s_x + k*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n24] + i*x_t - s_x; /* 2d case */ for (j=0; j= 0) { /* directly above */ x_t = x; y_t = ly[(n25 % (m*n))/m]; /* z_t = lz[n25 / (m*n)]; */ s_t = bases[n25] + (i-1)*x_t + k*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n25] + (i-1)*x_t; /* 2d case */ for (j=0; j= 0) { /* right above */ x_t = lx[n26 % m]; y_t = ly[(n26 % (m*n))/m]; /* z_t = lz[n26 / (m*n)]; */ s_t = bases[n26] + (i-1)*x_t + k*x_t*y_t; if (twod && (s_t >= M*N*P)) s_t = bases[n26] + (i-1)*x_t; /* 2d case */ for (j=0; j= 0) { /* left below */ x_t = lx[n0 % m]; y_t = ly[(n0 % (m*n))/m]; z_t = lz[n0 / (m*n)]; s_t = bases[n0] + x_t*y_t*z_t - (s_y-i)*x_t - s_x - (s_z-k-1)*x_t*y_t; for (j=0; j= 0) { /* directly below */ x_t = x; y_t = ly[(n1 % (m*n))/m]; z_t = lz[n1 / (m*n)]; s_t = bases[n1] + x_t*y_t*z_t - (s_y+1-i)*x_t - (s_z-k-1)*x_t*y_t; for (j=0; j= 0) { /* right below */ x_t = lx[n2 % m]; y_t = ly[(n2 % (m*n))/m]; z_t = lz[n2 / (m*n)]; s_t = bases[n2] + x_t*y_t*z_t - (s_y+1-i)*x_t - (s_z-k-1)*x_t*y_t; for (j=0; j= 0) { /* directly left */ x_t = lx[n3 % m]; y_t = y; z_t = lz[n3 / (m*n)]; s_t = bases[n3] + (i+1)*x_t - s_x + x_t*y_t*z_t - (s_z-k)*x_t*y_t; for (j=0; j= 0) { /* middle */ x_t = x; y_t = y; z_t = lz[n4 / (m*n)]; s_t = bases[n4] + i*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; for (j=0; j= 0) { /* directly right */ x_t = lx[n5 % m]; y_t = y; z_t = lz[n5 / (m*n)]; s_t = bases[n5] + i*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; for (j=0; j= 0) { /* left above */ x_t = lx[n6 % m]; y_t = ly[(n6 % (m*n))/m]; z_t = lz[n6 / (m*n)]; s_t = bases[n6] + i*x_t - s_x + x_t*y_t*z_t - (s_z-k)*x_t*y_t; for (j=0; j= 0) { /* directly above */ x_t = x; y_t = ly[(n7 % (m*n))/m]; z_t = lz[n7 / (m*n)]; s_t = bases[n7] + (i-1)*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; for (j=0; j= 0) { /* right above */ x_t = lx[n8 % m]; y_t = ly[(n8 % (m*n))/m]; z_t = lz[n8 / (m*n)]; s_t = bases[n8] + (i-1)*x_t + x_t*y_t*z_t - (s_z-k)*x_t*y_t; for (j=0; j= 0) { /* left below */ x_t = lx[n9 % m]; y_t = ly[(n9 % (m*n))/m]; /* z_t = z; */ s_t = bases[n9] - (s_y-i)*x_t -s_x + (k+1)*x_t*y_t; for (j=0; j= 0) { /* directly below */ x_t = x; y_t = ly[(n10 % (m*n))/m]; /* z_t = z; */ s_t = bases[n10] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; for (j=0; j= 0) { /* right below */ x_t = lx[n11 % m]; y_t = ly[(n11 % (m*n))/m]; /* z_t = z; */ s_t = bases[n11] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; for (j=0; j= 0) { /* directly left */ x_t = lx[n12 % m]; y_t = y; /* z_t = z; */ s_t = bases[n12] + (i+1)*x_t - s_x + k*x_t*y_t; for (j=0; j= 0) { /* directly right */ x_t = lx[n14 % m]; y_t = y; /* z_t = z; */ s_t = bases[n14] + i*x_t + k*x_t*y_t; for (j=0; j= 0) { /* left above */ x_t = lx[n15 % m]; y_t = ly[(n15 % (m*n))/m]; /* z_t = z; */ s_t = bases[n15] + i*x_t - s_x + k*x_t*y_t; for (j=0; j= 0) { /* directly above */ x_t = x; y_t = ly[(n16 % (m*n))/m]; /* z_t = z; */ s_t = bases[n16] + (i-1)*x_t + k*x_t*y_t; for (j=0; j= 0) { /* right above */ x_t = lx[n17 % m]; y_t = ly[(n17 % (m*n))/m]; /* z_t = z; */ s_t = bases[n17] + (i-1)*x_t + k*x_t*y_t; for (j=0; j= 0) { /* left below */ x_t = lx[n18 % m]; y_t = ly[(n18 % (m*n))/m]; /* z_t = lz[n18 / (m*n)]; */ s_t = bases[n18] - (s_y-i)*x_t -s_x + (k+1)*x_t*y_t; for (j=0; j= 0) { /* directly below */ x_t = x; y_t = ly[(n19 % (m*n))/m]; /* z_t = lz[n19 / (m*n)]; */ s_t = bases[n19] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; for (j=0; j= 0) { /* right below */ x_t = lx[n20 % m]; y_t = ly[(n20 % (m*n))/m]; /* z_t = lz[n20 / (m*n)]; */ s_t = bases[n20] - (s_y+1-i)*x_t + (k+1)*x_t*y_t; for (j=0; j= 0) { /* directly left */ x_t = lx[n21 % m]; y_t = y; /* z_t = lz[n21 / (m*n)]; */ s_t = bases[n21] + (i+1)*x_t - s_x + k*x_t*y_t; for (j=0; j= 0) { /* middle */ x_t = x; y_t = y; /* z_t = lz[n22 / (m*n)]; */ s_t = bases[n22] + i*x_t + k*x_t*y_t; for (j=0; j= 0) { /* directly right */ x_t = lx[n23 % m]; y_t = y; /* z_t = lz[n23 / (m*n)]; */ s_t = bases[n23] + i*x_t + k*x_t*y_t; for (j=0; j= 0) { /* left above */ x_t = lx[n24 % m]; y_t = ly[(n24 % (m*n))/m]; /* z_t = lz[n24 / (m*n)]; */ s_t = bases[n24] + i*x_t - s_x + k*x_t*y_t; for (j=0; j= 0) { /* directly above */ x_t = x; y_t = ly[(n25 % (m*n))/m]; /* z_t = lz[n25 / (m*n)]; */ s_t = bases[n25] + (i-1)*x_t + k*x_t*y_t; for (j=0; j= 0) { /* right above */ x_t = lx[n26 % m]; y_t = ly[(n26 % (m*n))/m]; /* z_t = lz[n26 / (m*n)]; */ s_t = bases[n26] + (i-1)*x_t + k*x_t*y_t; for (j=0; jltogmap);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)da,(PetscObject)da->ltogmap);CHKERRQ(ierr); ierr = PetscFree2(bases,ldims);CHKERRQ(ierr); dd->m = m; dd->n = n; dd->p = p; /* note petsc expects xs/xe/Xs/Xe to be multiplied by #dofs in many places */ dd->xs = xs*dof; dd->xe = xe*dof; dd->ys = ys; dd->ye = ye; dd->zs = zs; dd->ze = ze; dd->Xs = Xs*dof; dd->Xe = Xe*dof; dd->Ys = Ys; dd->Ye = Ye; dd->Zs = Zs; dd->Ze = Ze; ierr = VecDestroy(&local);CHKERRQ(ierr); ierr = VecDestroy(&global);CHKERRQ(ierr); dd->gtol = gtol; dd->base = base; da->ops->view = DMView_DA_3d; dd->ltol = NULL; dd->ao = NULL; PetscFunctionReturn(0); } #undef __FUNCT__ #define __FUNCT__ "DMDACreate3d" /*@C DMDACreate3d - Creates an object that will manage the communication of three-dimensional regular array data that is distributed across some processors. Collective on MPI_Comm Input Parameters: + comm - MPI communicator . bx,by,bz - type of ghost nodes the array have. Use one of DM_BOUNDARY_NONE, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_PERIODIC. . stencil_type - Type of stencil (DMDA_STENCIL_STAR or DMDA_STENCIL_BOX) . M,N,P - global dimension in each direction of the array (use -M, -N, and or -P to indicate that it may be set to a different value from the command line with -da_grid_x -da_grid_y -da_grid_z

) . m,n,p - corresponding number of processors in each dimension (or PETSC_DECIDE to have calculated) . dof - number of degrees of freedom per node . s - stencil width - lx, ly, lz - arrays containing the number of nodes in each cell along the x, y, and z coordinates, or NULL. If non-null, these must be of length as m,n,p and the corresponding m,n, or p cannot be PETSC_DECIDE. Sum of the lx[] entries must be M, sum of the ly[] must N, sum of the lz[] must be P Output Parameter: . da - the resulting distributed array object Options Database Key: + -dm_view - Calls DMView() at the conclusion of DMDACreate3d() . -da_grid_x - number of grid points in x direction, if M < 0 . -da_grid_y - number of grid points in y direction, if N < 0 . -da_grid_z - number of grid points in z direction, if P < 0 . -da_processors_x - number of processors in x direction . -da_processors_y - number of processors in y direction . -da_processors_z - number of processors in z direction . -da_refine_x - refinement ratio in x direction . -da_refine_y - refinement ratio in y direction . -da_refine_z - refinement ratio in z directio - -da_refine - refine the DMDA n times before creating it, , if M, N, or P < 0 Level: beginner Notes: The stencil type DMDA_STENCIL_STAR with width 1 corresponds to the standard 7-pt stencil, while DMDA_STENCIL_BOX with width 1 denotes the standard 27-pt stencil. The array data itself is NOT stored in the DMDA, it is stored in Vec objects; The appropriate vector objects can be obtained with calls to DMCreateGlobalVector() and DMCreateLocalVector() and calls to VecDuplicate() if more are needed. .keywords: distributed array, create, three-dimensional .seealso: DMDestroy(), DMView(), DMDACreate1d(), DMDACreate2d(), DMGlobalToLocalBegin(), DMDAGetRefinementFactor(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin(), DMLocalToLocalBegin(), DMLocalToLocalEnd(), DMDASetRefinementFactor(), DMDAGetInfo(), DMCreateGlobalVector(), DMCreateLocalVector(), DMDACreateNaturalVector(), DMLoad(), DMDAGetOwnershipRanges() @*/ PetscErrorCode DMDACreate3d(MPI_Comm comm,DMBoundaryType bx,DMBoundaryType by,DMBoundaryType bz,DMDAStencilType stencil_type,PetscInt M, PetscInt N,PetscInt P,PetscInt m,PetscInt n,PetscInt p,PetscInt dof,PetscInt s,const PetscInt lx[],const PetscInt ly[],const PetscInt lz[],DM *da) { PetscErrorCode ierr; PetscFunctionBegin; ierr = DMDACreate(comm, da);CHKERRQ(ierr); ierr = DMSetDimension(*da, 3);CHKERRQ(ierr); ierr = DMDASetSizes(*da, M, N, P);CHKERRQ(ierr); ierr = DMDASetNumProcs(*da, m, n, p);CHKERRQ(ierr); ierr = DMDASetBoundaryType(*da, bx, by, bz);CHKERRQ(ierr); ierr = DMDASetDof(*da, dof);CHKERRQ(ierr); ierr = DMDASetStencilType(*da, stencil_type);CHKERRQ(ierr); ierr = DMDASetStencilWidth(*da, s);CHKERRQ(ierr); ierr = DMDASetOwnershipRanges(*da, lx, ly, lz);CHKERRQ(ierr); /* This violates the behavior for other classes, but right now users expect negative dimensions to be handled this way */ ierr = DMSetFromOptions(*da);CHKERRQ(ierr); ierr = DMSetUp(*da);CHKERRQ(ierr); PetscFunctionReturn(0); }