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

  9: #undef __FUNCT__  
 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: }


 65: #undef __FUNCT__  
 67: /*@C
 68:    DAGetAO - Gets the application ordering context for a distributed array.

 70:    Collective on DA

 72:    Input Parameter:
 73: .  da - the distributed array

 75:    Output Parameters:
 76: .  ao - the application ordering context for DAs

 78:    Level: intermediate

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

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

 89: .seealso: DACreate2d(), DAGetGhostCorners(), DAGetCorners(), DALocalToGlocal()
 90:           DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DALocalToLocalBegin(), DALocalToLocalEnd(), DAGetGlobalIndices()
 91: @*/
 92: int DAGetAO(DA da,AO *ao)
 93: {

 97:   /* 
 98:      Build the natural ordering to PETSc ordering mappings.
 99:   */
100:   if (!da->ao) {
101:     IS  ispetsc,isnatural;
102:     int ierr,i,j,k,*lidx,lict = 0,Nlocal;

104:     Nlocal = (da->xe-da->xs);
105:     if (da->dim > 1) {
106:       Nlocal *= (da->ye-da->ys);
107:     }
108:     if (da->dim > 2) {
109:       Nlocal *= (da->ze-da->zs);
110:     }

112:     ISCreateStride(da->comm,Nlocal,da->base,1,&ispetsc);
113:     PetscMalloc(Nlocal*sizeof(int),&lidx);

115:     if (da->dim == 1) {
116:        for (i=da->xs; i<da->xe; i++) {
117:          /*  global number in natural ordering */
118:          lidx[lict++] = i;
119:        }
120:     } else if (da->dim == 2) {
121:       for (j=da->ys; j<da->ye; j++) {
122:         for (i=da->xs; i<da->xe; i++) {
123:           /*  global number in natural ordering */
124:           lidx[lict++] = i + j*da->M*da->w;
125:         }
126:       }
127:     } else if (da->dim == 3) {
128:       for (k=da->zs; k<da->ze; k++) {
129:         for (j=da->ys; j<da->ye; j++) {
130:           for (i=da->xs; i<da->xe; i++) {
131:             lidx[lict++] = i + j*da->M*da->w + k*da->M*da->N*da->w;
132:           }
133:         }
134:       }
135:     }

137:     ISCreateGeneral(da->comm,Nlocal,lidx,&isnatural);
138:     PetscFree(lidx);

140:     AOCreateBasicIS(isnatural,ispetsc,&da->ao);
141:     PetscLogObjectParent(da,da->ao);
142:     ISDestroy(ispetsc);
143:     ISDestroy(isnatural);
144:   }
145:   *ao = da->ao;
146:   return(0);
147: }

149: /*MC
150:     DAGetGlobalIndicesF90 - Returns a Fortran90 pointer to the list of 
151:     global indices (global node number of all local nodes, including
152:     ghost nodes).

154:     Synopsis:
155:     DAGetGlobalIndicesF90(DA da,integer n,{integer, pointer :: idx(:)},integer ierr)

157:     Input Parameter:
158: .   da - the distributed array

160:     Output Parameters:
161: +   n - the number of local elements, including ghost nodes (or PETSC_NULL)
162: .   idx - the Fortran90 pointer to the global indices
163: -   ierr - error code

165:     Level: intermediate

167:     Notes:
168:      Not yet supported for all F90 compilers

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

172: .seealso: DAGetGlobalIndices()
173: M*/