Actual source code: dadist.c

petsc-3.5.0 2014-06-30
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:   }
 47:   VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);
 48:   VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);
 49:   VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);
 50:   return(0);
 51: }

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

 60:    Collective on DMDA

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

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

 68:    Level: developer

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

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

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

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

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

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