Actual source code: daindex.c

petsc-3.5.4 2015-05-23
Report Typos and Errors
  2: /*
  3:   Code for manipulating distributed regular arrays in parallel.
  4: */

  6: #include <petsc-private/dmdaimpl.h>    /*I   "petscdmda.h"   I*/

 10: /*
 11:    Gets the natural number for each global number on the process.

 13:    Used by DMDAGetAO() and DMDAGlobalToNatural_Create()
 14: */
 15: PetscErrorCode DMDAGetNatural_Private(DM da,PetscInt *outNlocal,IS *isnatural)
 16: {
 18:   PetscInt       Nlocal,i,j,k,*lidx,lict = 0;
 19:   DM_DA          *dd = (DM_DA*)da->data;

 22:   Nlocal = (dd->xe-dd->xs);
 23:   if (dd->dim > 1) Nlocal *= (dd->ye-dd->ys);
 24:   if (dd->dim > 2) Nlocal *= (dd->ze-dd->zs);

 26:   PetscMalloc1(Nlocal,&lidx);

 28:   if (dd->dim == 1) {
 29:     for (i=dd->xs; i<dd->xe; i++) {
 30:       /*  global number in natural ordering */
 31:       lidx[lict++] = i;
 32:     }
 33:   } else if (dd->dim == 2) {
 34:     for (j=dd->ys; j<dd->ye; j++) {
 35:       for (i=dd->xs; i<dd->xe; i++) {
 36:         /*  global number in natural ordering */
 37:         lidx[lict++] = i + j*dd->M*dd->w;
 38:       }
 39:     }
 40:   } else if (dd->dim == 3) {
 41:     for (k=dd->zs; k<dd->ze; k++) {
 42:       for (j=dd->ys; j<dd->ye; j++) {
 43:         for (i=dd->xs; i<dd->xe; i++) {
 44:           lidx[lict++] = i + j*dd->M*dd->w + k*dd->M*dd->N*dd->w;
 45:         }
 46:       }
 47:     }
 48:   }
 49:   *outNlocal = Nlocal;
 50:   ISCreateGeneral(PetscObjectComm((PetscObject)da),Nlocal,lidx,PETSC_OWN_POINTER,isnatural);
 51:   return(0);
 52: }

 56: /*@
 57:    DMDAGetAO - Gets the application ordering context for a distributed array.

 59:    Collective on DMDA

 61:    Input Parameter:
 62: .  da - the distributed array

 64:    Output Parameters:
 65: .  ao - the application ordering context for DMDAs

 67:    Level: intermediate

 69:    Notes:
 70:    In this case, the AO maps to the natural grid ordering that would be used
 71:    for the DMDA if only 1 processor were employed (ordering most rapidly in the
 72:    x-direction, then y, then z).  Multiple degrees of freedom are numbered
 73:    for each node (rather than 1 component for the whole grid, then the next
 74:    component, etc.)

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

 78: .seealso: DMDACreate2d(), DMDAGetGhostCorners(), DMDAGetCorners(), DMDALocalToGlocal()
 79:           DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToLocalBegin(), DMLocalToLocalEnd(), DMDAGetOwnershipRanges(),
 80:           AO, AOPetscToApplication(), AOApplicationToPetsc()
 81: @*/
 82: PetscErrorCode  DMDAGetAO(DM da,AO *ao)
 83: {
 84:   DM_DA *dd = (DM_DA*)da->data;


 90:   /*
 91:      Build the natural ordering to PETSc ordering mappings.
 92:   */
 93:   if (!dd->ao) {
 94:     IS             ispetsc,isnatural;
 96:     PetscInt       Nlocal;

 98:     DMDAGetNatural_Private(da,&Nlocal,&isnatural);
 99:     ISCreateStride(PetscObjectComm((PetscObject)da),Nlocal,dd->base,1,&ispetsc);
100:     AOCreateBasicIS(isnatural,ispetsc,&dd->ao);
101:     PetscLogObjectParent((PetscObject)da,(PetscObject)dd->ao);
102:     ISDestroy(&ispetsc);
103:     ISDestroy(&isnatural);
104:   }
105:   *ao = dd->ao;
106:   return(0);
107: }