xref: /petsc/src/dm/impls/da/dadist.c (revision e1589f56b6f5b77c5829e929569a3b24fe74d9c5)
147c6ae99SBarry Smith #define PETSCDM_DLL
247c6ae99SBarry Smith 
347c6ae99SBarry Smith /*
447c6ae99SBarry Smith   Code for manipulating distributed regular arrays in parallel.
547c6ae99SBarry Smith */
647c6ae99SBarry Smith 
7*e1589f56SBarry Smith #include "private/daimpl.h"    /*I   "petscdm.h"   I*/
847c6ae99SBarry Smith 
947c6ae99SBarry Smith #undef __FUNCT__
10564755cdSBarry Smith #define __FUNCT__ "DMCreateGlobalVector_DA"
11564755cdSBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMCreateGlobalVector_DA(DM da,Vec* g)
1247c6ae99SBarry Smith {
1347c6ae99SBarry Smith   PetscErrorCode ierr;
1447c6ae99SBarry Smith   DM_DA          *dd = (DM_DA*)da->data;
1547c6ae99SBarry Smith 
1647c6ae99SBarry Smith   PetscFunctionBegin;
1747c6ae99SBarry Smith   PetscValidHeaderSpecific(da,DM_CLASSID,1);
1847c6ae99SBarry Smith   PetscValidPointer(g,2);
1947c6ae99SBarry Smith   ierr = VecCreate(((PetscObject)da)->comm,g);CHKERRQ(ierr);
2047c6ae99SBarry Smith   ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr);
2147c6ae99SBarry Smith   ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr);
22aa219208SBarry Smith   ierr = PetscObjectCompose((PetscObject)*g,"DMDA",(PetscObject)da);CHKERRQ(ierr);
2347c6ae99SBarry Smith   ierr = VecSetLocalToGlobalMapping(*g,dd->ltogmap);CHKERRQ(ierr);
2447c6ae99SBarry Smith   ierr = VecSetLocalToGlobalMappingBlock(*g,dd->ltogmapb);CHKERRQ(ierr);
2547c6ae99SBarry Smith   ierr = VecSetBlockSize(*g,dd->w);CHKERRQ(ierr);
2647c6ae99SBarry Smith   ierr = VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);CHKERRQ(ierr);
2747c6ae99SBarry Smith   ierr = VecSetOperation(*g,VECOP_LOAD,(void(*)(void))VecLoad_Default_DA);CHKERRQ(ierr);
2847c6ae99SBarry Smith   PetscFunctionReturn(0);
2947c6ae99SBarry Smith }
3047c6ae99SBarry Smith 
3147c6ae99SBarry Smith #undef __FUNCT__
32aa219208SBarry Smith #define __FUNCT__ "DMDACreateNaturalVector"
3347c6ae99SBarry Smith /*@
34aa219208SBarry Smith    DMDACreateNaturalVector - Creates a parallel PETSc vector that
3547c6ae99SBarry Smith    will hold vector values in the natural numbering, rather than in
36aa219208SBarry Smith    the PETSc parallel numbering associated with the DMDA.
3747c6ae99SBarry Smith 
38aa219208SBarry Smith    Collective on DMDA
3947c6ae99SBarry Smith 
4047c6ae99SBarry Smith    Input Parameter:
4147c6ae99SBarry Smith .  da - the distributed array
4247c6ae99SBarry Smith 
4347c6ae99SBarry Smith    Output Parameter:
4447c6ae99SBarry Smith .  g - the distributed global vector
4547c6ae99SBarry Smith 
4647c6ae99SBarry Smith    Level: developer
4747c6ae99SBarry Smith 
4847c6ae99SBarry Smith    Note:
4947c6ae99SBarry Smith    The output parameter, g, is a regular PETSc vector that should be destroyed
5047c6ae99SBarry Smith    with a call to VecDestroy() when usage is finished.
5147c6ae99SBarry Smith 
5247c6ae99SBarry Smith    The number of local entries in the vector on each process is the same
53564755cdSBarry Smith    as in a vector created with DMCreateGlobalVector().
5447c6ae99SBarry Smith 
5547c6ae99SBarry Smith .keywords: distributed array, create, global, distributed, vector
5647c6ae99SBarry Smith 
57564755cdSBarry Smith .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
58aa219208SBarry Smith           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
59aa219208SBarry Smith           DMGlobalToLocalEnd(), DMDALocalToGlobalBegin()
6047c6ae99SBarry Smith @*/
61aa219208SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMDACreateNaturalVector(DM da,Vec* g)
6247c6ae99SBarry Smith {
6347c6ae99SBarry Smith   PetscErrorCode ierr;
6447c6ae99SBarry Smith   PetscInt       cnt;
6547c6ae99SBarry Smith   DM_DA          *dd = (DM_DA*)da->data;
6647c6ae99SBarry Smith 
6747c6ae99SBarry Smith   PetscFunctionBegin;
6847c6ae99SBarry Smith   PetscValidHeaderSpecific(da,DM_CLASSID,1);
6947c6ae99SBarry Smith   PetscValidPointer(g,2);
7047c6ae99SBarry Smith   if (dd->natural) {
7147c6ae99SBarry Smith     ierr = PetscObjectGetReference((PetscObject)dd->natural,&cnt);CHKERRQ(ierr);
7247c6ae99SBarry Smith     if (cnt == 1) { /* object is not currently used by anyone */
7347c6ae99SBarry Smith       ierr = PetscObjectReference((PetscObject)dd->natural);CHKERRQ(ierr);
7447c6ae99SBarry Smith       *g   = dd->natural;
7547c6ae99SBarry Smith     } else {
7647c6ae99SBarry Smith       ierr = VecDuplicate(dd->natural,g);CHKERRQ(ierr);
7747c6ae99SBarry Smith     }
7847c6ae99SBarry Smith   } else { /* create the first version of this guy */
7947c6ae99SBarry Smith     ierr = VecCreateMPI(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,g);CHKERRQ(ierr);
8047c6ae99SBarry Smith     ierr = VecSetBlockSize(*g, dd->w);CHKERRQ(ierr);
8147c6ae99SBarry Smith     ierr = PetscObjectReference((PetscObject)*g);CHKERRQ(ierr);
8247c6ae99SBarry Smith     dd->natural = *g;
8347c6ae99SBarry Smith   }
8447c6ae99SBarry Smith   PetscFunctionReturn(0);
8547c6ae99SBarry Smith }
8647c6ae99SBarry Smith 
8747c6ae99SBarry Smith 
8847c6ae99SBarry Smith 
89