Actual source code: daindex.c

  1: /*$Id: daindex.c,v 1.33 2001/06/21 21:19:09 bsmith Exp $*/
  2: 
  3: /*
  4:   Code for manipulating distributed regular arrays in parallel.
  5: */

 7:  #include src/dm/da/daimpl.h

 11: /*@C
 12:    DAGetGlobalIndices - Returns the global node number of all local nodes,
 13:    including ghost nodes.

 15:    Not Collective

 17:    Input Parameter:
 18: .  da - the distributed array

 20:    Output Parameters:
 21: +  n - the number of local elements, including ghost nodes (or PETSC_NULL)
 22: -  idx - the global indices

 24:    Level: intermediate

 26:    Note: 
 27:    For DA_STENCIL_STAR stencils the inactive corner ghost nodes are also included
 28:    in the list of local indices (even though those nodes are not updated 
 29:    during calls to DAXXXToXXX().

 31:    Essentially the same data is returned in the form of a local-to-global mapping
 32:    with the routine DAGetISLocalToGlobalMapping();

 34:    Fortran Note:
 35:    This routine is used differently from Fortran
 36: .vb
 37:         DA          da
 38:         integer     n,da_array(1)
 39:         PetscOffset i_da
 40:         integer     ierr
 41:         call DAGetGlobalIndices(da,n,da_array,i_da,ierr)

 43:    C Access first local entry in list
 44:         value = da_array(i_da + 1)
 45: .ve

 47:    See the Fortran chapter of the users manual for details

 49: .keywords: distributed array, get, global, indices, local-to-global

 51: .seealso: DACreate2d(), DAGetGhostCorners(), DAGetCorners(), DALocalToGlobal()
 52:           DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DALocalToLocalBegin(), DAGetAO(), DAGetGlobalIndicesF90()
 53:           DAGetISLocalToGlobalMapping(), DACreate3d(), DACreate1d(), DALocalToLocalEnd()
 54: @*/
 55: int DAGetGlobalIndices(DA da,int *n,int **idx)
 56: {
 59:   if (n)   *n   = da->Nl;
 60:   if (idx) *idx = da->idx;
 61:   return(0);
 62: }

 66: /*
 67:    Gets the natural number for each global number on the process.

 69:    Used by DAGetAO() and DAGlobalToNatural_Create()
 70: */
 71: int DAGetNatural_Private(DA da,int *outNlocal,IS *isnatural)
 72: {
 73:   int Nlocal,i,j,k,ierr,*lidx,lict = 0;

 76:   Nlocal = (da->xe-da->xs);
 77:   if (da->dim > 1) {
 78:     Nlocal *= (da->ye-da->ys);
 79:   }
 80:   if (da->dim > 2) {
 81:     Nlocal *= (da->ze-da->zs);
 82:   }
 83: 
 84:   PetscMalloc(Nlocal*sizeof(int),&lidx);
 85: 
 86:   if (da->dim == 1) {
 87:     for (i=da->xs; i<da->xe; i++) {
 88:       /*  global number in natural ordering */
 89:       lidx[lict++] = i;
 90:     }
 91:   } else if (da->dim == 2) {
 92:     for (j=da->ys; j<da->ye; j++) {
 93:       for (i=da->xs; i<da->xe; i++) {
 94:         /*  global number in natural ordering */
 95:         lidx[lict++] = i + j*da->M*da->w;
 96:       }
 97:     }
 98:   } else if (da->dim == 3) {
 99:     for (k=da->zs; k<da->ze; k++) {
100:       for (j=da->ys; j<da->ye; j++) {
101:         for (i=da->xs; i<da->xe; i++) {
102:           lidx[lict++] = i + j*da->M*da->w + k*da->M*da->N*da->w;
103:         }
104:       }
105:     }
106:   }
107:   *outNlocal = Nlocal;
108:   ISCreateGeneral(da->comm,Nlocal,lidx,isnatural);
109:   PetscFree(lidx);
110:   return(0);
111: }

115: /*@C
116:    DAGetAO - Gets the application ordering context for a distributed array.

118:    Collective on DA

120:    Input Parameter:
121: .  da - the distributed array

123:    Output Parameters:
124: .  ao - the application ordering context for DAs

126:    Level: intermediate

128:    Notes:
129:    In this case, the AO maps to the natural grid ordering that would be used
130:    for the DA if only 1 processor were employed (ordering most rapidly in the
131:    x-direction, then y, then z).  Multiple degrees of freedom are numbered
132:    for each node (rather than 1 component for the whole grid, then the next
133:    component, etc.)

135: .keywords: distributed array, get, global, indices, local-to-global

137: .seealso: DACreate2d(), DAGetGhostCorners(), DAGetCorners(), DALocalToGlocal()
138:           DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DALocalToLocalBegin(), DALocalToLocalEnd(), DAGetGlobalIndices()
139: @*/
140: int DAGetAO(DA da,AO *ao)
141: {

146:   /* 
147:      Build the natural ordering to PETSc ordering mappings.
148:   */
149:   if (!da->ao) {
150:     IS  ispetsc,isnatural;
151:     int ierr,Nlocal;

153:     DAGetNatural_Private(da,&Nlocal,&isnatural);
154:     ISCreateStride(da->comm,Nlocal,da->base,1,&ispetsc);
155:     AOCreateBasicIS(isnatural,ispetsc,&da->ao);
156:     PetscLogObjectParent(da,da->ao);
157:     ISDestroy(ispetsc);
158:     ISDestroy(isnatural);
159:   }
160:   *ao = da->ao;
161:   return(0);
162: }

164: /*MC
165:     DAGetGlobalIndicesF90 - Returns a Fortran90 pointer to the list of 
166:     global indices (global node number of all local nodes, including
167:     ghost nodes).

169:     Synopsis:
170:     DAGetGlobalIndicesF90(DA da,integer n,{integer, pointer :: idx(:)},integer ierr)

172:     Input Parameter:
173: .   da - the distributed array

175:     Output Parameters:
176: +   n - the number of local elements, including ghost nodes (or PETSC_NULL)
177: .   idx - the Fortran90 pointer to the global indices
178: -   ierr - error code

180:     Level: intermediate

182:     Notes:
183:      Not yet supported for all F90 compilers

185: .keywords: distributed array, get, global, indices, local-to-global, f90

187: .seealso: DAGetGlobalIndices()
188: M*/