#include #undef __FUNCT__ #define __FUNCT__ "DMDACreatePatchIS" /*@ DMDACreatePatchIS - Creates an index set corresponding to a patch of the DA. Not Collective Input Parameters: + da - the DMDA . lower - a matstencil with i, j and k corresponding to the lower corner of the patch - upper - a matstencil with i, j and k corresponding to the upper corner of the patch Output Parameters: . is - the IS corresponding to the patch Level: developer .seealso: DMDACreateDomainDecomposition(), DMDACreateDomainDecompositionScatters() @*/ PetscErrorCode DMDACreatePatchIS(DM da,MatStencil *lower,MatStencil *upper,IS *is) { PetscInt ms=0,ns=0,ps=0; PetscInt me=1,ne=1,pe=1; PetscInt mr=0,nr=0,pr=0; PetscInt ii,jj,kk; PetscInt si,sj,sk; PetscInt i,j,k,l,idx; PetscInt base; PetscInt xm=1,ym=1,zm=1; const PetscInt *lx,*ly,*lz; PetscInt ox,oy,oz; PetscInt m,n,p,M,N,P,dof; PetscInt nindices; PetscInt *indices; DM_DA *dd = (DM_DA*)da->data; PetscErrorCode ierr; PetscFunctionBegin; /* need to get the sizes of the actual DM rather than the "global" space of a subdomain DM */ M = dd->M;N = dd->N;P=dd->P; m = dd->m;n = dd->n;p=dd->p; dof = dd->w; ierr = DMDAGetOffset(da,&ox,&oy,&oz,NULL,NULL,NULL);CHKERRQ(ierr); ierr = DMDAGetOwnershipRanges(da,&lx,&ly,&lz);CHKERRQ(ierr); nindices = (upper->i - lower->i)*(upper->j - lower->j)*(upper->k - lower->k)*dof; ierr = PetscMalloc(sizeof(PetscInt)*nindices,&indices);CHKERRQ(ierr); /* start at index 0 on processor 0 */ mr = 0; nr = 0; pr = 0; ms = 0; ns = 0; ps = 0; if (lx) me = lx[0]; if (ly) ne = ly[0]; if (lz) pe = lz[0]; idx = 0; for (k=lower->k-oz;kk-oz;k++) { for (j=lower->j-oy;j < upper->j-oy;j++) { for (i=lower->i-ox;i < upper->i-ox;i++) { /* "actual" indices rather than ones outside of the domain */ ii = i; jj = j; kk = k; if (ii < 0) ii = M + ii; if (jj < 0) jj = N + jj; if (kk < 0) kk = P + kk; if (ii > M-1) ii = ii - M; if (jj > N-1) jj = jj - N; if (kk > P-1) kk = kk - P; /* gone out of processor range on x axis */ while(ii > me-1 || ii < ms) { if (mr == m-1) { ms = 0; me = lx[0]; mr = 0; } else { mr++; ms = me; me += lx[mr]; } } /* gone out of processor range on y axis */ while(jj > ne-1 || jj < ns) { if (nr == n-1) { ns = 0; ne = ly[0]; nr = 0; } else { nr++; ns = ne; ne += ly[nr]; } } /* gone out of processor range on z axis */ while(kk > pe-1 || kk < ps) { if (pr == p-1) { ps = 0; pe = lz[0]; pr = 0; } else { pr++; ps = pe; pe += lz[pr]; } } /* compute the vector base on owning processor */ xm = me - ms; ym = ne - ns; zm = pe - ps; base = ms*ym*zm + ns*M + ps*M*N; /* compute the local coordinates on owning processor */ si = ii - ms; sj = jj - ns; sk = kk - ps; for (l=0;l