Actual source code: dadist.c

petsc-3.12.5 2020-03-29
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:   VecCreate(PetscObjectComm((PetscObject)da),g);
 32:   VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
 33:   VecSetBlockSize(*g,dd->w);
 34:   VecSetType(*g,da->vectype);
 35:   VecSetDM(*g, da);
 36:   VecSetLocalToGlobalMapping(*g,da->ltogmap);
 37:   VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);
 38:   VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);
 39:   VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);
 40:   return(0);
 41: }

 43: /*@
 44:    DMDACreateNaturalVector - Creates a parallel PETSc vector that
 45:    will hold vector values in the natural numbering, rather than in
 46:    the PETSc parallel numbering associated with the DMDA.

 48:    Collective

 50:    Input Parameter:
 51: .  da - the distributed array

 53:    Output Parameter:
 54: .  g - the distributed global vector

 56:    Level: developer

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

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

 65: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 66:           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
 67:           DMGlobalToLocalEnd(), DMLocalToGlobalBegin()
 68: @*/
 69: PetscErrorCode  DMDACreateNaturalVector(DM da,Vec *g)
 70: {
 72:   PetscInt       cnt;
 73:   DM_DA          *dd = (DM_DA*)da->data;

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

 93:     dd->natural = *g;
 94:   }
 95:   return(0);
 96: }