1 #if !defined(__PETSCDMDA_H) 2 #define __PETSCDMDA_H 3 4 #include <petscdm.h> 5 #include <petscpf.h> 6 #include <petscao.h> 7 8 /*E 9 DMDAStencilType - Determines if the stencil extends only along the coordinate directions, or also 10 to the northeast, northwest etc 11 12 Level: beginner 13 14 .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDACreate(), DMDASetStencilType() 15 E*/ 16 typedef enum { DMDA_STENCIL_STAR,DMDA_STENCIL_BOX } DMDAStencilType; 17 18 /*MC 19 DMDA_STENCIL_STAR - "Star"-type stencil. In logical grid coordinates, only (i,j,k), (i+s,j,k), (i,j+s,k), 20 (i,j,k+s) are in the stencil NOT, for example, (i+s,j+s,k) 21 22 Level: beginner 23 24 .seealso: DMDA_STENCIL_BOX, DMDAStencilType, DMDASetStencilType() 25 M*/ 26 27 /*MC 28 DMDA_STENCIL_BOX - "Box"-type stencil. In logical grid coordinates, any of (i,j,k), (i+s,j+r,k+t) may 29 be in the stencil. 30 31 Level: beginner 32 33 .seealso: DMDA_STENCIL_STAR, DMDAStencilType, DMDASetStencilType() 34 M*/ 35 36 /*E 37 DMDABoundaryType - Describes the choice for fill of ghost cells on physical domain boundaries. 38 39 Level: beginner 40 41 A boundary may be of type DMDA_BOUNDARY_NONE (no ghost nodes), DMDA_BOUNDARY_GHOST (ghost nodes 42 exist but aren't filled, you can put values into them and then apply a stencil that uses those ghost locations), 43 DMDA_BOUNDARY_MIRROR (not yet implemented for 3d), or DMDA_BOUNDARY_PERIODIC 44 (ghost nodes filled by the opposite edge of the domain). 45 46 Note: This is information for the boundary of the __PHYSICAL__ domain. It has nothing to do with boundaries between 47 processes, that width is always determined by the stencil width, see DMDASetStencilWidth(). 48 49 .seealso: DMDASetBoundaryType(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDACreate() 50 E*/ 51 typedef enum { DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_GHOSTED, DMDA_BOUNDARY_MIRROR, DMDA_BOUNDARY_PERIODIC } DMDABoundaryType; 52 53 PETSC_EXTERN const char *const DMDABoundaryTypes[]; 54 55 /*E 56 DMDAInterpolationType - Defines the type of interpolation that will be returned by 57 DMCreateInterpolation. 58 59 Level: beginner 60 61 .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateInterpolation(), DMDASetInterpolationType(), DMDACreate() 62 E*/ 63 typedef enum { DMDA_Q0, DMDA_Q1 } DMDAInterpolationType; 64 65 PETSC_EXTERN PetscErrorCode DMDASetInterpolationType(DM,DMDAInterpolationType); 66 PETSC_EXTERN PetscErrorCode DMDAGetInterpolationType(DM,DMDAInterpolationType*); 67 68 /*E 69 DMDAElementType - Defines the type of elements that will be returned by 70 DMDAGetElements() 71 72 Level: beginner 73 74 .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateInterpolation(), DMDASetInterpolationType(), 75 DMDASetElementType(), DMDAGetElements(), DMDARestoreElements(), DMDACreate() 76 E*/ 77 typedef enum { DMDA_ELEMENT_P1, DMDA_ELEMENT_Q1 } DMDAElementType; 78 79 PETSC_EXTERN PetscErrorCode DMDASetElementType(DM,DMDAElementType); 80 PETSC_EXTERN PetscErrorCode DMDAGetElementType(DM,DMDAElementType*); 81 PETSC_EXTERN PetscErrorCode DMDAGetElements(DM,PetscInt *,PetscInt *,const PetscInt*[]); 82 PETSC_EXTERN PetscErrorCode DMDARestoreElements(DM,PetscInt *,PetscInt *,const PetscInt*[]); 83 84 typedef enum { DMDA_X,DMDA_Y,DMDA_Z } DMDADirection; 85 86 #define MATSEQUSFFT "sequsfft" 87 88 PETSC_EXTERN PetscErrorCode DMDACreate(MPI_Comm,DM*); 89 PETSC_EXTERN PetscErrorCode DMDASetDim(DM,PetscInt); 90 PETSC_EXTERN PetscErrorCode DMDASetSizes(DM,PetscInt,PetscInt,PetscInt); 91 PETSC_EXTERN PetscErrorCode DMDACreate1d(MPI_Comm,DMDABoundaryType,PetscInt,PetscInt,PetscInt,const PetscInt[],DM *); 92 PETSC_EXTERN PetscErrorCode DMDACreate2d(MPI_Comm,DMDABoundaryType,DMDABoundaryType,DMDAStencilType,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],DM*); 93 PETSC_EXTERN PetscErrorCode DMDACreate3d(MPI_Comm,DMDABoundaryType,DMDABoundaryType,DMDABoundaryType,DMDAStencilType,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],DM*); 94 95 PETSC_EXTERN PetscErrorCode DMDAGlobalToNaturalBegin(DM,Vec,InsertMode,Vec); 96 PETSC_EXTERN PetscErrorCode DMDAGlobalToNaturalEnd(DM,Vec,InsertMode,Vec); 97 PETSC_EXTERN PetscErrorCode DMDANaturalToGlobalBegin(DM,Vec,InsertMode,Vec); 98 PETSC_EXTERN PetscErrorCode DMDANaturalToGlobalEnd(DM,Vec,InsertMode,Vec); 99 PETSC_EXTERN PetscErrorCode DMDALocalToLocalBegin(DM,Vec,InsertMode,Vec); 100 PETSC_EXTERN PetscErrorCode DMDALocalToLocalEnd(DM,Vec,InsertMode,Vec); 101 PETSC_EXTERN PetscErrorCode DMDACreateNaturalVector(DM,Vec *); 102 103 PETSC_EXTERN PetscErrorCode DMDAGetCorners(DM,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*); 104 PETSC_EXTERN PetscErrorCode DMDAGetGhostCorners(DM,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*); 105 PETSC_EXTERN PetscErrorCode DMDAGetInfo(DM,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,DMDABoundaryType*,DMDABoundaryType*,DMDABoundaryType*,DMDAStencilType*); 106 PETSC_EXTERN PetscErrorCode DMDAGetProcessorSubset(DM,DMDADirection,PetscInt,MPI_Comm*); 107 PETSC_EXTERN PetscErrorCode DMDAGetProcessorSubsets(DM,DMDADirection,MPI_Comm*); 108 PETSC_EXTERN PetscErrorCode DMDAGetRay(DM,DMDADirection,PetscInt,Vec*,VecScatter*); 109 110 PETSC_EXTERN PetscErrorCode DMDAGlobalToNaturalAllCreate(DM,VecScatter*); 111 PETSC_EXTERN PetscErrorCode DMDANaturalAllToGlobalCreate(DM,VecScatter*); 112 113 PETSC_EXTERN PetscErrorCode DMDAGetGlobalIndices(DM,PetscInt*,PetscInt**); 114 115 PETSC_EXTERN PetscErrorCode DMDAGetScatter(DM,VecScatter*,VecScatter*,VecScatter*); 116 PETSC_EXTERN PetscErrorCode DMDAGetNeighbors(DM,const PetscMPIInt**); 117 118 PETSC_EXTERN PetscErrorCode DMDAGetAO(DM,AO*); 119 PETSC_EXTERN PetscErrorCode DMDASetUniformCoordinates(DM,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal); 120 PETSC_EXTERN PetscErrorCode DMDAGetBoundingBox(DM,PetscReal[],PetscReal[]); 121 PETSC_EXTERN PetscErrorCode DMDAGetLocalBoundingBox(DM,PetscReal[],PetscReal[]); 122 /* function to wrap coordinates around boundary */ 123 PETSC_EXTERN PetscErrorCode DMDAMapCoordsToPeriodicDomain(DM,PetscScalar*,PetscScalar*); 124 125 PETSC_EXTERN PetscErrorCode DMDAGetReducedDMDA(DM,PetscInt,DM*); 126 127 PETSC_EXTERN PetscErrorCode DMDASetFieldName(DM,PetscInt,const char[]); 128 PETSC_EXTERN PetscErrorCode DMDAGetFieldName(DM,PetscInt,const char**); 129 PETSC_EXTERN PetscErrorCode DMDASetCoordinateName(DM,PetscInt,const char[]); 130 PETSC_EXTERN PetscErrorCode DMDAGetCoordinateName(DM,PetscInt,const char**); 131 132 PETSC_EXTERN PetscErrorCode DMDASetBoundaryType(DM,DMDABoundaryType,DMDABoundaryType,DMDABoundaryType); 133 PETSC_EXTERN PetscErrorCode DMDASetDof(DM, PetscInt); 134 PETSC_EXTERN PetscErrorCode DMDASetOverlap(DM,PetscInt,PetscInt,PetscInt); 135 PETSC_EXTERN PetscErrorCode DMDAGetOverlap(DM,PetscInt*,PetscInt*,PetscInt*); 136 PETSC_EXTERN PetscErrorCode DMDAGetOffset(DM,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*); 137 PETSC_EXTERN PetscErrorCode DMDASetOffset(DM,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt); 138 PETSC_EXTERN PetscErrorCode DMDASetStencilWidth(DM, PetscInt); 139 PETSC_EXTERN PetscErrorCode DMDASetOwnershipRanges(DM,const PetscInt[],const PetscInt[],const PetscInt[]); 140 PETSC_EXTERN PetscErrorCode DMDAGetOwnershipRanges(DM,const PetscInt**,const PetscInt**,const PetscInt**); 141 PETSC_EXTERN PetscErrorCode DMDASetNumProcs(DM, PetscInt, PetscInt, PetscInt); 142 PETSC_EXTERN PetscErrorCode DMDASetStencilType(DM, DMDAStencilType); 143 144 PETSC_EXTERN PetscErrorCode DMDAVecGetArray(DM,Vec,void *); 145 PETSC_EXTERN PetscErrorCode DMDAVecRestoreArray(DM,Vec,void *); 146 147 PETSC_EXTERN PetscErrorCode DMDAVecGetArrayDOF(DM,Vec,void *); 148 PETSC_EXTERN PetscErrorCode DMDAVecRestoreArrayDOF(DM,Vec,void *); 149 150 PETSC_EXTERN PetscErrorCode DMDASplitComm2d(MPI_Comm,PetscInt,PetscInt,PetscInt,MPI_Comm*); 151 152 PETSC_EXTERN PetscErrorCode DMDASetUseDomainDecomposition(DM,PetscBool); 153 PETSC_EXTERN PetscErrorCode DMDAGetUseDomainDecomposition(DM,PetscBool*); 154 155 PETSC_EXTERN PetscErrorCode DMDACreatePatchIS(DM,MatStencil*,MatStencil*,IS*); 156 157 /*S 158 DMDALocalInfo - C struct that contains information about a structured grid and a processors logical 159 location in it. 160 161 Level: beginner 162 163 Concepts: distributed array 164 165 Developer note: Then entries in this struct are int instead of PetscInt so that the elements may 166 be extracted in Fortran as if from an integer array 167 168 .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DM, DMDAGetLocalInfo(), DMDAGetInfo() 169 S*/ 170 typedef struct { 171 PetscInt dim,dof,sw; 172 PetscInt mx,my,mz; /* global number of grid points in each direction */ 173 PetscInt xs,ys,zs; /* starting point of this processor, excluding ghosts */ 174 PetscInt xm,ym,zm; /* number of grid points on this processor, excluding ghosts */ 175 PetscInt gxs,gys,gzs; /* starting point of this processor including ghosts */ 176 PetscInt gxm,gym,gzm; /* number of grid points on this processor including ghosts */ 177 DMDABoundaryType bx,by,bz; /* type of ghost nodes at boundary */ 178 DMDAStencilType st; 179 DM da; 180 } DMDALocalInfo; 181 182 /*MC 183 DMDACoor2d - Structure for holding 2d (x and y) coordinates. 184 185 Level: intermediate 186 187 Sample Usage: 188 DMDACoor2d **coors; 189 Vec vcoors; 190 DM cda; 191 192 DMGetCoordinates(da,&vcoors); 193 DMDAGetCoordinateDA(da,&cda); 194 DMDAVecGetArray(cda,vcoors,&coors); 195 DMDAGetCorners(cda,&mstart,&nstart,0,&m,&n,0) 196 for (i=mstart; i<mstart+m; i++) { 197 for (j=nstart; j<nstart+n; j++) { 198 x = coors[j][i].x; 199 y = coors[j][i].y; 200 ...... 201 } 202 } 203 DMDAVecRestoreArray(dac,vcoors,&coors); 204 205 .seealso: DMDACoor3d, DMDAForEachPointBegin(), DMDAGetCoordinateDA(), DMGetCoordinates(), DMDAGetGhostCoordinates() 206 M*/ 207 typedef struct {PetscScalar x,y;} DMDACoor2d; 208 209 /*MC 210 DMDACoor3d - Structure for holding 3d (x, y and z) coordinates. 211 212 Level: intermediate 213 214 Sample Usage: 215 DMDACoor3d ***coors; 216 Vec vcoors; 217 DM cda; 218 219 DMGetCoordinates(da,&vcoors); 220 DMDAGetCoordinateDA(da,&cda); 221 DMDAVecGetArray(cda,vcoors,&coors); 222 DMDAGetCorners(cda,&mstart,&nstart,&pstart,&m,&n,&p) 223 for (i=mstart; i<mstart+m; i++) { 224 for (j=nstart; j<nstart+n; j++) { 225 for (k=pstart; k<pstart+p; k++) { 226 x = coors[k][j][i].x; 227 y = coors[k][j][i].y; 228 z = coors[k][j][i].z; 229 ...... 230 } 231 } 232 DMDAVecRestoreArray(dac,vcoors,&coors); 233 234 .seealso: DMDACoor2d, DMDAForEachPointBegin(), DMDAGetCoordinateDA(), DMGetCoordinates(), DMDAGetGhostCoordinates() 235 M*/ 236 typedef struct {PetscScalar x,y,z;} DMDACoor3d; 237 238 PETSC_EXTERN PetscErrorCode DMDAGetLocalInfo(DM,DMDALocalInfo*); 239 240 PETSC_EXTERN PetscErrorCode MatRegisterDAAD(void); 241 PETSC_EXTERN PetscErrorCode MatCreateDAAD(DM,Mat*); 242 PETSC_EXTERN PetscErrorCode MatCreateSeqUSFFT(Vec,DM,Mat*); 243 244 PETSC_EXTERN PetscErrorCode DMDASetGetMatrix(DM,PetscErrorCode (*)(DM, MatType,Mat *)); 245 PETSC_EXTERN PetscErrorCode DMDASetBlockFills(DM,const PetscInt*,const PetscInt*); 246 PETSC_EXTERN PetscErrorCode DMDASetRefinementFactor(DM,PetscInt,PetscInt,PetscInt); 247 PETSC_EXTERN PetscErrorCode DMDAGetRefinementFactor(DM,PetscInt*,PetscInt*,PetscInt*); 248 249 PETSC_EXTERN PetscErrorCode DMDAGetArray(DM,PetscBool ,void*); 250 PETSC_EXTERN PetscErrorCode DMDARestoreArray(DM,PetscBool ,void*); 251 252 PETSC_EXTERN PetscErrorCode DMDACreatePF(DM,PF*); 253 254 PETSC_EXTERN PetscErrorCode DMDAGetNumCells(DM, PetscInt *); 255 PETSC_EXTERN PetscErrorCode DMDAGetNumVertices(DM, PetscInt *, PetscInt *, PetscInt *, PetscInt *); 256 PETSC_EXTERN PetscErrorCode DMDAGetNumFaces(DM, PetscInt *, PetscInt *, PetscInt *, PetscInt *, PetscInt *, PetscInt *); 257 PETSC_EXTERN PetscErrorCode DMDAGetHeightStratum(DM, PetscInt, PetscInt *, PetscInt *); 258 PETSC_EXTERN PetscErrorCode DMDACreateSection(DM, PetscInt[], PetscInt[], PetscInt[], PetscInt[]); 259 PETSC_EXTERN PetscErrorCode DMDAComputeCellGeometry(DM, PetscInt, PetscQuadrature *, PetscReal [], PetscReal [], PetscReal [], PetscReal []); 260 PETSC_EXTERN PetscErrorCode DMDAVecGetClosure(DM, PetscSection, Vec, PetscInt, const PetscScalar **); 261 PETSC_EXTERN PetscErrorCode DMDAVecSetClosure(DM, PetscSection, Vec, PetscInt, const PetscScalar *, InsertMode); 262 PETSC_EXTERN PetscErrorCode DMDAGetClosure(DM,PetscSection,PetscInt,PetscInt*,const PetscInt**); 263 PETSC_EXTERN PetscErrorCode DMDARestoreClosure(DM,PetscSection,PetscInt,PetscInt*,const PetscInt**); 264 PETSC_EXTERN PetscErrorCode DMDAGetClosureScalar(DM,PetscSection,PetscInt,PetscScalar*,const PetscScalar**); 265 PETSC_EXTERN PetscErrorCode DMDARestoreClosureScalar(DM,PetscSection,PetscInt,PetscScalar*,const PetscScalar**); 266 PETSC_EXTERN PetscErrorCode DMDASetClosureScalar(DM,PetscSection,PetscInt,PetscScalar*,const PetscScalar*,InsertMode); 267 PETSC_EXTERN PetscErrorCode DMDAConvertToCell(DM, MatStencil, PetscInt *); 268 269 #endif 270