1 #define PETSCDM_DLL 2 3 /* 4 Code for manipulating distributed regular arrays in parallel. 5 */ 6 7 #include "private/daimpl.h" /*I "petscdm.h" I*/ 8 9 #undef __FUNCT__ 10 #define __FUNCT__ "DMCreateGlobalVector_DA" 11 PetscErrorCode PETSCDM_DLLEXPORT DMCreateGlobalVector_DA(DM da,Vec* g) 12 { 13 PetscErrorCode ierr; 14 DM_DA *dd = (DM_DA*)da->data; 15 16 PetscFunctionBegin; 17 PetscValidHeaderSpecific(da,DM_CLASSID,1); 18 PetscValidPointer(g,2); 19 ierr = VecCreate(((PetscObject)da)->comm,g);CHKERRQ(ierr); 20 ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr); 21 ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr); 22 ierr = PetscObjectCompose((PetscObject)*g,"DMDA",(PetscObject)da);CHKERRQ(ierr); 23 ierr = VecSetLocalToGlobalMapping(*g,dd->ltogmap);CHKERRQ(ierr); 24 ierr = VecSetLocalToGlobalMappingBlock(*g,dd->ltogmapb);CHKERRQ(ierr); 25 ierr = VecSetBlockSize(*g,dd->w);CHKERRQ(ierr); 26 ierr = VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);CHKERRQ(ierr); 27 ierr = VecSetOperation(*g,VECOP_LOAD,(void(*)(void))VecLoad_Default_DA);CHKERRQ(ierr); 28 PetscFunctionReturn(0); 29 } 30 31 #undef __FUNCT__ 32 #define __FUNCT__ "DMDACreateNaturalVector" 33 /*@ 34 DMDACreateNaturalVector - Creates a parallel PETSc vector that 35 will hold vector values in the natural numbering, rather than in 36 the PETSc parallel numbering associated with the DMDA. 37 38 Collective on DMDA 39 40 Input Parameter: 41 . da - the distributed array 42 43 Output Parameter: 44 . g - the distributed global vector 45 46 Level: developer 47 48 Note: 49 The output parameter, g, is a regular PETSc vector that should be destroyed 50 with a call to VecDestroy() when usage is finished. 51 52 The number of local entries in the vector on each process is the same 53 as in a vector created with DMCreateGlobalVector(). 54 55 .keywords: distributed array, create, global, distributed, vector 56 57 .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(), 58 DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(), 59 DMGlobalToLocalEnd(), DMDALocalToGlobalBegin() 60 @*/ 61 PetscErrorCode PETSCDM_DLLEXPORT DMDACreateNaturalVector(DM da,Vec* g) 62 { 63 PetscErrorCode ierr; 64 PetscInt cnt; 65 DM_DA *dd = (DM_DA*)da->data; 66 67 PetscFunctionBegin; 68 PetscValidHeaderSpecific(da,DM_CLASSID,1); 69 PetscValidPointer(g,2); 70 if (dd->natural) { 71 ierr = PetscObjectGetReference((PetscObject)dd->natural,&cnt);CHKERRQ(ierr); 72 if (cnt == 1) { /* object is not currently used by anyone */ 73 ierr = PetscObjectReference((PetscObject)dd->natural);CHKERRQ(ierr); 74 *g = dd->natural; 75 } else { 76 ierr = VecDuplicate(dd->natural,g);CHKERRQ(ierr); 77 } 78 } else { /* create the first version of this guy */ 79 ierr = VecCreateMPI(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,g);CHKERRQ(ierr); 80 ierr = VecSetBlockSize(*g, dd->w);CHKERRQ(ierr); 81 ierr = PetscObjectReference((PetscObject)*g);CHKERRQ(ierr); 82 dd->natural = *g; 83 } 84 PetscFunctionReturn(0); 85 } 86 87 88 89