xref: /petsc/src/dm/impls/da/dadist.c (revision 9df75925b8836faedf2e88e69b941251a33bb593)
147c6ae99SBarry Smith 
247c6ae99SBarry Smith /*
347c6ae99SBarry Smith   Code for manipulating distributed regular arrays in parallel.
447c6ae99SBarry Smith */
547c6ae99SBarry Smith 
6af0996ceSBarry Smith #include <petsc/private/dmdaimpl.h>    /*I   "petscdmda.h"   I*/
747c6ae99SBarry Smith 
87087cfbeSBarry Smith PetscErrorCode  VecDuplicate_MPI_DA(Vec g,Vec *gg)
92dcb2ebcSBarry Smith {
102dcb2ebcSBarry Smith   PetscErrorCode ierr;
112dcb2ebcSBarry Smith   DM             da;
12077aedafSJed Brown   PetscLayout    map;
132dcb2ebcSBarry Smith 
142dcb2ebcSBarry Smith   PetscFunctionBegin;
15c688c046SMatthew G Knepley   ierr = VecGetDM(g, &da);CHKERRQ(ierr);
162dcb2ebcSBarry Smith   ierr = DMCreateGlobalVector(da,gg);CHKERRQ(ierr);
17077aedafSJed Brown   ierr = VecGetLayout(g,&map);CHKERRQ(ierr);
18077aedafSJed Brown   ierr = VecSetLayout(*gg,map);CHKERRQ(ierr);
192dcb2ebcSBarry Smith   PetscFunctionReturn(0);
202dcb2ebcSBarry Smith }
212dcb2ebcSBarry Smith 
222dcb2ebcSBarry Smith 
237087cfbeSBarry Smith PetscErrorCode  DMCreateGlobalVector_DA(DM da,Vec *g)
2447c6ae99SBarry Smith {
2547c6ae99SBarry Smith   PetscErrorCode ierr;
2647c6ae99SBarry Smith   DM_DA          *dd = (DM_DA*)da->data;
2747c6ae99SBarry Smith 
2847c6ae99SBarry Smith   PetscFunctionBegin;
2947c6ae99SBarry Smith   PetscValidHeaderSpecific(da,DM_CLASSID,1);
3047c6ae99SBarry Smith   PetscValidPointer(g,2);
31ce94432eSBarry Smith   ierr = VecCreate(PetscObjectComm((PetscObject)da),g);CHKERRQ(ierr);
3247c6ae99SBarry Smith   ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr);
33401ddaa8SBarry Smith   ierr = VecSetBlockSize(*g,dd->w);CHKERRQ(ierr);
3447c6ae99SBarry Smith   ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr);
35c688c046SMatthew G Knepley   ierr = VecSetDM(*g, da);CHKERRQ(ierr);
361411c6eeSJed Brown   ierr = VecSetLocalToGlobalMapping(*g,da->ltogmap);CHKERRQ(ierr);
3747c6ae99SBarry Smith   ierr = VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);CHKERRQ(ierr);
3847c6ae99SBarry Smith   ierr = VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);CHKERRQ(ierr);
392dcb2ebcSBarry Smith   ierr = VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);CHKERRQ(ierr);
4047c6ae99SBarry Smith   PetscFunctionReturn(0);
4147c6ae99SBarry Smith }
4247c6ae99SBarry Smith 
4347c6ae99SBarry Smith /*@
44aa219208SBarry Smith    DMDACreateNaturalVector - Creates a parallel PETSc vector that
4547c6ae99SBarry Smith    will hold vector values in the natural numbering, rather than in
46aa219208SBarry Smith    the PETSc parallel numbering associated with the DMDA.
4747c6ae99SBarry Smith 
483ca8f39cSDave May    Collective
4947c6ae99SBarry Smith 
5047c6ae99SBarry Smith    Input Parameter:
5147c6ae99SBarry Smith .  da - the distributed array
5247c6ae99SBarry Smith 
5347c6ae99SBarry Smith    Output Parameter:
5447c6ae99SBarry Smith .  g - the distributed global vector
5547c6ae99SBarry Smith 
5647c6ae99SBarry Smith    Level: developer
5747c6ae99SBarry Smith 
5847c6ae99SBarry Smith    Note:
5947c6ae99SBarry Smith    The output parameter, g, is a regular PETSc vector that should be destroyed
6047c6ae99SBarry Smith    with a call to VecDestroy() when usage is finished.
6147c6ae99SBarry Smith 
6247c6ae99SBarry Smith    The number of local entries in the vector on each process is the same
63564755cdSBarry Smith    as in a vector created with DMCreateGlobalVector().
6447c6ae99SBarry Smith 
65564755cdSBarry Smith .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
66aa219208SBarry Smith           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
67*9df75925SJed Brown           DMGlobalToLocalEnd(), DMLocalToGlobalBegin()
6847c6ae99SBarry Smith @*/
697087cfbeSBarry Smith PetscErrorCode  DMDACreateNaturalVector(DM da,Vec *g)
7047c6ae99SBarry Smith {
7147c6ae99SBarry Smith   PetscErrorCode ierr;
7247c6ae99SBarry Smith   PetscInt       cnt;
7347c6ae99SBarry Smith   DM_DA          *dd = (DM_DA*)da->data;
7447c6ae99SBarry Smith 
7547c6ae99SBarry Smith   PetscFunctionBegin;
76a9a02de4SBarry Smith   PetscValidHeaderSpecificType(da,DM_CLASSID,1,DMDA);
7747c6ae99SBarry Smith   PetscValidPointer(g,2);
7847c6ae99SBarry Smith   if (dd->natural) {
7947c6ae99SBarry Smith     ierr = PetscObjectGetReference((PetscObject)dd->natural,&cnt);CHKERRQ(ierr);
8047c6ae99SBarry Smith     if (cnt == 1) { /* object is not currently used by anyone */
8147c6ae99SBarry Smith       ierr = PetscObjectReference((PetscObject)dd->natural);CHKERRQ(ierr);
8247c6ae99SBarry Smith       *g   = dd->natural;
8347c6ae99SBarry Smith     } else {
8447c6ae99SBarry Smith       ierr = VecDuplicate(dd->natural,g);CHKERRQ(ierr);
8547c6ae99SBarry Smith     }
8647c6ae99SBarry Smith   } else { /* create the first version of this guy */
87ce94432eSBarry Smith     ierr = VecCreate(PetscObjectComm((PetscObject)da),g);CHKERRQ(ierr);
88a34bdc0bSBarry Smith     ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr);
8947c6ae99SBarry Smith     ierr = VecSetBlockSize(*g, dd->w);CHKERRQ(ierr);
90265bdeeeSBarry Smith     ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr);
9147c6ae99SBarry Smith     ierr = PetscObjectReference((PetscObject)*g);CHKERRQ(ierr);
928865f1eaSKarl Rupp 
9347c6ae99SBarry Smith     dd->natural = *g;
9447c6ae99SBarry Smith   }
9547c6ae99SBarry Smith   PetscFunctionReturn(0);
9647c6ae99SBarry Smith }
9747c6ae99SBarry Smith 
9847c6ae99SBarry Smith 
9947c6ae99SBarry Smith 
100