xref: /petsc/src/dm/impls/da/dadist.c (revision c6db04a5321582041def2b1e244c75985478b3ef)
147c6ae99SBarry Smith 
247c6ae99SBarry Smith /*
347c6ae99SBarry Smith   Code for manipulating distributed regular arrays in parallel.
447c6ae99SBarry Smith */
547c6ae99SBarry Smith 
6*c6db04a5SJed Brown #include <private/daimpl.h>    /*I   "petscdmda.h"   I*/
747c6ae99SBarry Smith 
847c6ae99SBarry Smith #undef __FUNCT__
92dcb2ebcSBarry Smith #define __FUNCT__ "VecDuplicate_MPI_DA"
107087cfbeSBarry Smith PetscErrorCode  VecDuplicate_MPI_DA(Vec g,Vec* gg)
112dcb2ebcSBarry Smith {
122dcb2ebcSBarry Smith   PetscErrorCode ierr;
132dcb2ebcSBarry Smith   DM             da;
142dcb2ebcSBarry Smith 
152dcb2ebcSBarry Smith   PetscFunctionBegin;
162dcb2ebcSBarry Smith   ierr = PetscObjectQuery((PetscObject)g,"DMDA",(PetscObject*)&da);CHKERRQ(ierr);
172dcb2ebcSBarry Smith   ierr = DMCreateGlobalVector(da,gg);CHKERRQ(ierr);
182dcb2ebcSBarry Smith   PetscFunctionReturn(0);
192dcb2ebcSBarry Smith }
202dcb2ebcSBarry Smith 
212dcb2ebcSBarry Smith 
222dcb2ebcSBarry Smith #undef __FUNCT__
23564755cdSBarry Smith #define __FUNCT__ "DMCreateGlobalVector_DA"
247087cfbeSBarry Smith PetscErrorCode  DMCreateGlobalVector_DA(DM da,Vec* g)
2547c6ae99SBarry Smith {
2647c6ae99SBarry Smith   PetscErrorCode ierr;
2747c6ae99SBarry Smith   DM_DA          *dd = (DM_DA*)da->data;
2847c6ae99SBarry Smith 
2947c6ae99SBarry Smith   PetscFunctionBegin;
3047c6ae99SBarry Smith   PetscValidHeaderSpecific(da,DM_CLASSID,1);
3147c6ae99SBarry Smith   PetscValidPointer(g,2);
3247c6ae99SBarry Smith   ierr = VecCreate(((PetscObject)da)->comm,g);CHKERRQ(ierr);
3347c6ae99SBarry Smith   ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr);
3447c6ae99SBarry Smith   ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr);
35aa219208SBarry Smith   ierr = PetscObjectCompose((PetscObject)*g,"DMDA",(PetscObject)da);CHKERRQ(ierr);
361411c6eeSJed Brown   ierr = VecSetLocalToGlobalMapping(*g,da->ltogmap);CHKERRQ(ierr);
371411c6eeSJed Brown   ierr = VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);CHKERRQ(ierr);
3847c6ae99SBarry Smith   ierr = VecSetBlockSize(*g,dd->w);CHKERRQ(ierr);
3947c6ae99SBarry Smith   ierr = VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);CHKERRQ(ierr);
4047c6ae99SBarry Smith   ierr = VecSetOperation(*g,VECOP_LOAD,(void(*)(void))VecLoad_Default_DA);CHKERRQ(ierr);
412dcb2ebcSBarry Smith   ierr = VecSetOperation(*g,VECOP_DUPLICATE,(void(*)(void))VecDuplicate_MPI_DA);CHKERRQ(ierr);
4247c6ae99SBarry Smith   PetscFunctionReturn(0);
4347c6ae99SBarry Smith }
4447c6ae99SBarry Smith 
4547c6ae99SBarry Smith #undef __FUNCT__
46aa219208SBarry Smith #define __FUNCT__ "DMDACreateNaturalVector"
4747c6ae99SBarry Smith /*@
48aa219208SBarry Smith    DMDACreateNaturalVector - Creates a parallel PETSc vector that
4947c6ae99SBarry Smith    will hold vector values in the natural numbering, rather than in
50aa219208SBarry Smith    the PETSc parallel numbering associated with the DMDA.
5147c6ae99SBarry Smith 
52aa219208SBarry Smith    Collective on DMDA
5347c6ae99SBarry Smith 
5447c6ae99SBarry Smith    Input Parameter:
5547c6ae99SBarry Smith .  da - the distributed array
5647c6ae99SBarry Smith 
5747c6ae99SBarry Smith    Output Parameter:
5847c6ae99SBarry Smith .  g - the distributed global vector
5947c6ae99SBarry Smith 
6047c6ae99SBarry Smith    Level: developer
6147c6ae99SBarry Smith 
6247c6ae99SBarry Smith    Note:
6347c6ae99SBarry Smith    The output parameter, g, is a regular PETSc vector that should be destroyed
6447c6ae99SBarry Smith    with a call to VecDestroy() when usage is finished.
6547c6ae99SBarry Smith 
6647c6ae99SBarry Smith    The number of local entries in the vector on each process is the same
67564755cdSBarry Smith    as in a vector created with DMCreateGlobalVector().
6847c6ae99SBarry Smith 
6947c6ae99SBarry Smith .keywords: distributed array, create, global, distributed, vector
7047c6ae99SBarry Smith 
71564755cdSBarry Smith .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
72aa219208SBarry Smith           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
73aa219208SBarry Smith           DMGlobalToLocalEnd(), DMDALocalToGlobalBegin()
7447c6ae99SBarry Smith @*/
757087cfbeSBarry Smith PetscErrorCode  DMDACreateNaturalVector(DM da,Vec* g)
7647c6ae99SBarry Smith {
7747c6ae99SBarry Smith   PetscErrorCode ierr;
7847c6ae99SBarry Smith   PetscInt       cnt;
7947c6ae99SBarry Smith   DM_DA          *dd = (DM_DA*)da->data;
8047c6ae99SBarry Smith 
8147c6ae99SBarry Smith   PetscFunctionBegin;
8247c6ae99SBarry Smith   PetscValidHeaderSpecific(da,DM_CLASSID,1);
8347c6ae99SBarry Smith   PetscValidPointer(g,2);
8447c6ae99SBarry Smith   if (dd->natural) {
8547c6ae99SBarry Smith     ierr = PetscObjectGetReference((PetscObject)dd->natural,&cnt);CHKERRQ(ierr);
8647c6ae99SBarry Smith     if (cnt == 1) { /* object is not currently used by anyone */
8747c6ae99SBarry Smith       ierr = PetscObjectReference((PetscObject)dd->natural);CHKERRQ(ierr);
8847c6ae99SBarry Smith       *g   = dd->natural;
8947c6ae99SBarry Smith     } else {
9047c6ae99SBarry Smith       ierr = VecDuplicate(dd->natural,g);CHKERRQ(ierr);
9147c6ae99SBarry Smith     }
9247c6ae99SBarry Smith   } else { /* create the first version of this guy */
9347c6ae99SBarry Smith     ierr = VecCreateMPI(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,g);CHKERRQ(ierr);
9447c6ae99SBarry Smith     ierr = VecSetBlockSize(*g, dd->w);CHKERRQ(ierr);
9547c6ae99SBarry Smith     ierr = PetscObjectReference((PetscObject)*g);CHKERRQ(ierr);
9647c6ae99SBarry Smith     dd->natural = *g;
9747c6ae99SBarry Smith   }
9847c6ae99SBarry Smith   PetscFunctionReturn(0);
9947c6ae99SBarry Smith }
10047c6ae99SBarry Smith 
10147c6ae99SBarry Smith 
10247c6ae99SBarry Smith 
103