Actual source code: dadist.c

petsc-master 2019-06-19
Report Typos and Errors

  2: /*
  3:   Code for manipulating distributed regular arrays in parallel.
  4: */

  6:  #include <petsc/private/dmdaimpl.h>

  8: PetscErrorCode  VecDuplicate_MPI_DA(Vec g,Vec *gg)
  9: {
 11:   DM             da;
 12:   PetscLayout    map;

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


 23: PetscErrorCode  DMCreateGlobalVector_DA(DM da,Vec *g)
 24: {
 26:   DM_DA          *dd = (DM_DA*)da->data;

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

 49: /*@
 50:    DMDACreateNaturalVector - Creates a parallel PETSc vector that
 51:    will hold vector values in the natural numbering, rather than in
 52:    the PETSc parallel numbering associated with the DMDA.

 54:    Collective

 56:    Input Parameter:
 57: .  da - the distributed array

 59:    Output Parameter:
 60: .  g - the distributed global vector

 62:    Level: developer

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

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

 71: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 72:           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
 73:           DMGlobalToLocalEnd(), DMDALocalToGlobalBegin()
 74: @*/
 75: PetscErrorCode  DMDACreateNaturalVector(DM da,Vec *g)
 76: {
 78:   PetscInt       cnt;
 79:   DM_DA          *dd = (DM_DA*)da->data;

 84:   if (dd->natural) {
 85:     PetscObjectGetReference((PetscObject)dd->natural,&cnt);
 86:     if (cnt == 1) { /* object is not currently used by anyone */
 87:       PetscObjectReference((PetscObject)dd->natural);
 88:       *g   = dd->natural;
 89:     } else {
 90:       VecDuplicate(dd->natural,g);
 91:     }
 92:   } else { /* create the first version of this guy */
 93:     VecCreate(PetscObjectComm((PetscObject)da),g);
 94:     VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
 95:     VecSetBlockSize(*g, dd->w);
 96:     VecSetType(*g,da->vectype);
 97:     PetscObjectReference((PetscObject)*g);

 99:     dd->natural = *g;
100:   }
101:   return(0);
102: }