Actual source code: dadist.c

petsc-dev 2014-02-02
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: PetscErrorCode  VecDuplicate_MPI_DA(Vec g,Vec *gg)
 11: {
 13:   DM             da;
 14:   PetscLayout    map;

 17:   VecGetDM(g, &da);
 18:   DMCreateGlobalVector(da,gg);
 19:   VecGetLayout(g,&map);
 20:   VecSetLayout(*gg,map);
 21:   return(0);
 22: }


 27: PetscErrorCode  DMCreateGlobalVector_DA(DM da,Vec *g)
 28: {
 30:   DM_DA          *dd = (DM_DA*)da->data;

 35:   if (da->defaultSection) {
 36:     DMCreateGlobalVector_Section_Private(da,g);
 37:     /* The view and load functions break for general layouts */
 38:     return(0);
 39:   } else {
 40:     VecCreate(PetscObjectComm((PetscObject)da),g);
 41:     VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
 42:     VecSetBlockSize(*g,dd->w);
 43:     VecSetType(*g,da->vectype);
 44:     VecSetDM(*g, da);
 45:     VecSetLocalToGlobalMapping(*g,da->ltogmap);
 46:     VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);
 47:   }
 48:   VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);
 49:   VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);
 50:   VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);
 51:   return(0);
 52: }

 56: /*@
 57:    DMDACreateNaturalVector - Creates a parallel PETSc vector that
 58:    will hold vector values in the natural numbering, rather than in
 59:    the PETSc parallel numbering associated with the DMDA.

 61:    Collective on DMDA

 63:    Input Parameter:
 64: .  da - the distributed array

 66:    Output Parameter:
 67: .  g - the distributed global vector

 69:    Level: developer

 71:    Note:
 72:    The output parameter, g, is a regular PETSc vector that should be destroyed
 73:    with a call to VecDestroy() when usage is finished.

 75:    The number of local entries in the vector on each process is the same
 76:    as in a vector created with DMCreateGlobalVector().

 78: .keywords: distributed array, create, global, distributed, vector

 80: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 81:           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
 82:           DMGlobalToLocalEnd(), DMDALocalToGlobalBegin()
 83: @*/
 84: PetscErrorCode  DMDACreateNaturalVector(DM da,Vec *g)
 85: {
 87:   PetscInt       cnt;
 88:   DM_DA          *dd = (DM_DA*)da->data;

 93:   if (dd->natural) {
 94:     PetscObjectGetReference((PetscObject)dd->natural,&cnt);
 95:     if (cnt == 1) { /* object is not currently used by anyone */
 96:       PetscObjectReference((PetscObject)dd->natural);
 97:       *g   = dd->natural;
 98:     } else {
 99:       VecDuplicate(dd->natural,g);
100:     }
101:   } else { /* create the first version of this guy */
102:     VecCreate(PetscObjectComm((PetscObject)da),g);
103:     VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
104:     VecSetBlockSize(*g, dd->w);
105:     VecSetType(*g,VECMPI);
106:     PetscObjectReference((PetscObject)*g);

108:     dd->natural = *g;
109:   }
110:   return(0);
111: }