Actual source code: dadist.c

  1: /*$Id: dadist.c,v 1.29 2001/03/23 23:25:00 balay Exp $*/
  2: 
  3: /*
  4:   Code for manipulating distributed regular arrays in parallel.
  5: */

  7: #include "src/dm/da/daimpl.h"    /*I   "petscda.h"   I*/


 10: int DAGetGlobalToGlobal1_Private(DA da,int **gtog1)
 11: {
 14:   *gtog1 = da->gtog1;
 15:   return(0);
 16: }

 18: /*@C
 19:    DACreateGlobalVector - Creates a parallel PETSc vector that
 20:    may be used with the DAXXX routines.

 22:    Collective on DA

 24:    Input Parameter:
 25: .  da - the distributed array

 27:    Output Parameter:
 28: .  g - the distributed global vector

 30:    Level: beginner

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

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

 38: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 39:           DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
 40:           DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateNaturalVector()
 41: @*/
 42: int DACreateGlobalVector(DA da,Vec* g)
 43: {

 48:   VecDuplicate(da->global,g);
 49:   PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);
 50:   return(0);
 51: }

 53: /*@C
 54:    DACreateNaturalVector - Creates a parallel PETSc vector that
 55:    will hold vector values in the natural numbering, rather than in 
 56:    the PETSc parallel numbering associated with the DA.

 58:    Collective on DA

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

 63:    Output Parameter:
 64: .  g - the distributed global vector

 66:    Level: developer

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

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

 74: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 75:           DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
 76:           DAGlobalToLocalEnd(), DALocalToGlobal()
 77: @*/
 78: int DACreateNaturalVector(DA da,Vec* g)
 79: {
 80:   int cnt,m,ierr;

 84:   if (da->natural) {
 85:     PetscObjectGetReference((PetscObject)da->natural,&cnt);
 86:     if (cnt == 1) { /* object is not currently used by anyone */
 87:       PetscObjectReference((PetscObject)da->natural);
 88:       *g   = da->natural;
 89:     } else {
 90:       VecDuplicate(da->natural,g);
 91:     }
 92:   } else { /* create the first version of this guy */
 93:     VecGetLocalSize(da->global,&m);
 94:     VecCreateMPI(da->comm,m,PETSC_DETERMINE,g);
 95:     PetscObjectReference((PetscObject)*g);
 96:     da->natural = *g;
 97:   }
 98:   return(0);
 99: }