1 /* 2 Objects to manage the interactions between the mesh data structures and the algebraic objects 3 */ 4 #if !defined(__PETSCDM_H) 5 #define __PETSCDM_H 6 #include "petscmat.h" 7 PETSC_EXTERN_CXX_BEGIN 8 9 extern PetscErrorCode DMInitializePackage(const char[]); 10 /*S 11 DM - Abstract PETSc object that manages an abstract grid object 12 13 Level: intermediate 14 15 Concepts: grids, grid refinement 16 17 Notes: The DMDACreate() based object and the DMCompositeCreate() based object are examples of DMs 18 19 Though the DM objects require the petscsnes.h include files the DM library is 20 NOT dependent on the SNES or KSP library. In fact, the KSP and SNES libraries depend on 21 DM. (This is not great design, but not trivial to fix). 22 23 .seealso: DMCompositeCreate(), DMDACreate() 24 S*/ 25 typedef struct _p_DM* DM; 26 27 extern PetscClassId DM_CLASSID; 28 29 /*E 30 DMType - String with the name of a PETSc DM or the creation function 31 with an optional dynamic library name, for example 32 http://www.mcs.anl.gov/petsc/lib.a:myveccreate() 33 34 Level: beginner 35 36 .seealso: DMSetType(), DM 37 E*/ 38 39 #define DMType char* 40 #define DMDA "da" 41 #define DMADDA "adda" 42 #define DMCOMPOSITE "composite" 43 #define DMSLICED "sliced" 44 #define DMMESH "mesh" 45 #define DMCARTESIAN "cartesian" 46 #define DMIGA "iga" 47 48 extern PetscFList DMList; 49 extern PetscBool DMRegisterAllCalled; 50 extern PetscErrorCode DMCreate(MPI_Comm,DM*); 51 extern PetscErrorCode DMSetType(DM, const DMType); 52 extern PetscErrorCode DMGetType(DM, const DMType *); 53 extern PetscErrorCode DMRegister(const char[],const char[],const char[],PetscErrorCode (*)(DM)); 54 extern PetscErrorCode DMRegisterAll(const char []); 55 extern PetscErrorCode DMRegisterDestroy(void); 56 extern PetscErrorCode DMIGACreate(MPI_Comm,DM*); 57 58 59 /*MC 60 DMRegisterDynamic - Adds a new DM component implementation 61 62 Synopsis: 63 PetscErrorCode DMRegisterDynamic(const char *name,const char *path,const char *func_name, PetscErrorCode (*create_func)(DM)) 64 65 Not Collective 66 67 Input Parameters: 68 + name - The name of a new user-defined creation routine 69 . path - The path (either absolute or relative) of the library containing this routine 70 . func_name - The name of routine to create method context 71 - create_func - The creation routine itself 72 73 Notes: 74 DMRegisterDynamic() may be called multiple times to add several user-defined DMs 75 76 If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 77 78 Sample usage: 79 .vb 80 DMRegisterDynamic("my_da","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyDMCreate", MyDMCreate); 81 .ve 82 83 Then, your DM type can be chosen with the procedural interface via 84 .vb 85 DMCreate(MPI_Comm, DM *); 86 DMSetType(DM,"my_da_name"); 87 .ve 88 or at runtime via the option 89 .vb 90 -da_type my_da_name 91 .ve 92 93 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 94 If your function is not being put into a shared library then use DMRegister() instead 95 96 Level: advanced 97 98 .keywords: DM, register 99 .seealso: DMRegisterAll(), DMRegisterDestroy(), DMRegister() 100 M*/ 101 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 102 #define DMRegisterDynamic(a,b,c,d) DMRegister(a,b,c,0) 103 #else 104 #define DMRegisterDynamic(a,b,c,d) DMRegister(a,b,c,d) 105 #endif 106 107 extern PetscErrorCode DMView(DM,PetscViewer); 108 extern PetscErrorCode DMDestroy(DM); 109 extern PetscErrorCode DMCreateGlobalVector(DM,Vec*); 110 extern PetscErrorCode DMCreateLocalVector(DM,Vec*); 111 extern PetscErrorCode DMGetLocalVector(DM,Vec *); 112 extern PetscErrorCode DMRestoreLocalVector(DM,Vec *); 113 extern PetscErrorCode DMGetGlobalVector(DM,Vec *); 114 extern PetscErrorCode DMRestoreGlobalVector(DM,Vec *); 115 extern PetscErrorCode DMGetLocalToGlobalMapping(DM,ISLocalToGlobalMapping*); 116 extern PetscErrorCode DMGetLocalToGlobalMappingBlock(DM,ISLocalToGlobalMapping*); 117 extern PetscErrorCode DMGetBlockSize(DM,PetscInt*); 118 extern PetscErrorCode DMGetColoring(DM,ISColoringType,const MatType,ISColoring*); 119 extern PetscErrorCode DMGetMatrix(DM, const MatType,Mat*); 120 extern PetscErrorCode DMSetMatrixPreallocateOnly(DM,PetscBool); 121 extern PetscErrorCode DMGetInterpolation(DM,DM,Mat*,Vec*); 122 extern PetscErrorCode DMGetInjection(DM,DM,VecScatter*); 123 extern PetscErrorCode DMRefine(DM,MPI_Comm,DM*); 124 extern PetscErrorCode DMCoarsen(DM,MPI_Comm,DM*); 125 extern PetscErrorCode DMRefineHierarchy(DM,PetscInt,DM[]); 126 extern PetscErrorCode DMCoarsenHierarchy(DM,PetscInt,DM[]); 127 extern PetscErrorCode DMSetFromOptions(DM); 128 extern PetscErrorCode DMSetUp(DM); 129 extern PetscErrorCode DMGetInterpolationScale(DM,DM,Mat,Vec*); 130 extern PetscErrorCode DMGetAggregates(DM,DM,Mat*); 131 extern PetscErrorCode DMGlobalToLocalBegin(DM,Vec,InsertMode,Vec); 132 extern PetscErrorCode DMGlobalToLocalEnd(DM,Vec,InsertMode,Vec); 133 extern PetscErrorCode DMLocalToGlobalBegin(DM,Vec,InsertMode,Vec); 134 extern PetscErrorCode DMLocalToGlobalEnd(DM,Vec,InsertMode,Vec); 135 extern PetscErrorCode DMGetElements(DM,PetscInt *,PetscInt *,const PetscInt*[]); 136 extern PetscErrorCode DMRestoreElements(DM,PetscInt *,PetscInt *,const PetscInt*[]); 137 extern PetscErrorCode DMConvert(DM,const DMType,DM*); 138 139 extern PetscErrorCode DMSetOptionsPrefix(DM,const char []); 140 extern PetscErrorCode DMSetVecType(DM,const VecType); 141 extern PetscErrorCode DMSetContext(DM,void*); 142 extern PetscErrorCode DMGetContext(DM,void**); 143 extern PetscErrorCode DMSetInitialGuess(DM,PetscErrorCode (*)(DM,Vec)); 144 extern PetscErrorCode DMSetFunction(DM,PetscErrorCode (*)(DM,Vec,Vec)); 145 extern PetscErrorCode DMSetJacobian(DM,PetscErrorCode (*)(DM,Vec,Mat,Mat,MatStructure *)); 146 extern PetscErrorCode DMHasInitialGuess(DM,PetscBool *); 147 extern PetscErrorCode DMHasFunction(DM,PetscBool *); 148 extern PetscErrorCode DMHasJacobian(DM,PetscBool *); 149 extern PetscErrorCode DMComputeInitialGuess(DM,Vec); 150 extern PetscErrorCode DMComputeFunction(DM,Vec,Vec); 151 extern PetscErrorCode DMComputeJacobian(DM,Vec,Mat,Mat,MatStructure *); 152 extern PetscErrorCode DMComputeJacobianDefault(DM,Vec,Mat,Mat,MatStructure *); 153 extern PetscErrorCode DMFinalizePackage(void); 154 155 typedef struct NLF_DAAD* NLF; 156 157 #include "petscbag.h" 158 159 extern PetscErrorCode PetscViewerBinaryMatlabOpen(MPI_Comm, const char [], PetscViewer*); 160 extern PetscErrorCode PetscViewerBinaryMatlabDestroy(PetscViewer); 161 extern PetscErrorCode PetscViewerBinaryMatlabOutputBag(PetscViewer, const char [], PetscBag); 162 extern PetscErrorCode PetscViewerBinaryMatlabOutputVec(PetscViewer, const char [], Vec); 163 extern PetscErrorCode PetscViewerBinaryMatlabOutputVecDA(PetscViewer, const char [], Vec, DM); 164 165 /*-------------------------------------------------------------------------*/ 166 /* ISMapping */ 167 /*-------------------------------------------------------------------------*/ 168 extern PetscClassId IS_MAPPING_CLASSID; 169 extern PetscErrorCode ISMappingInitializePackage(const char[]); 170 /*S 171 ISMapping - a generalization of ISLocalToGlobalMapping 172 maps from a domain [0,M) of indices to a range [0,N) of indices. 173 The mapping can be multivalued and can be thought of as a directed 174 graph with the start and end vertices drawn from the domain and range, 175 respectively. In the simplest case, an ISMapping is specified by pairs of ISs 176 of equal length prescribing the endpoints of as set of graph edges. 177 178 The domain is partitioned in parallel into local ownership ranges, the same way 179 as a Vec's indices. Since this is equivalent to specifying a PetscLayout, the domain 180 is said to be "laid out". Once the edges have been specified, the ISMapping is 181 assembled each rank has all of the edges with the source points in its ownership range. 182 183 After assembly, the mapping can be used to map the indices in the local ownership 184 range [m_p, m_{p+1}) to the global range indices on the other end of the edges. 185 Similarly, local indices from [0,m_{p+1}-m_p) can be mapped to the corresponding 186 global range indices. 187 Unlike with ISLocalToGlobalMapping, an ISMapping can be multivalued and some local 188 indices might have empty images. Because of that the output array resulting from the 189 application of the mapping to an input array of length m is supplemented with an offset 190 array of size m+1 to delineate the images of the consecuitive input indices. 191 In addition to mapping just indices, indices together with scalar arrays (of equal 192 sizes) can be mapped, with the scalar values simply "following" the input indices to 193 their images. Since ISMappings are multivalued in general, the scalar values will be 194 replicated. This is useful for employing ISMappings in VecSetValuesLocal or 195 MatSetValuesLocal. 196 197 198 Level: intermediate 199 200 .seealso: ISMappingCreate(), ISMappingSetDomainSizes(), ISMappingApplyLocal(), ISMappingApplyWithValuesLocal() 201 S*/ 202 typedef struct _p_ISMapping *ISMapping; 203 204 extern PetscErrorCode ISMappingRegister(const char[],const char[],const char[],PetscErrorCode (*)(ISMapping)); 205 206 /*MC 207 ISMappingRegisterDynamic - Adds a method to the ISMapping registry. 208 209 Synopsis: 210 PetscErrorCode ISMappingRegisterDynamic(const char *name_mapping,const char *path,const char *name_create,PetscErrorCode (*routine_create)(ISMapping)) 211 212 Not Collective 213 214 Input Parameters: 215 + name_mapping - name of a new user-defined mapping module 216 . path - path (either absolute or relative) the library containing this mapping 217 . name_create - name of routine to create method context 218 - routine_create - routine to create method context 219 220 Level: developer 221 222 Notes: 223 ISMappingRegisterDynamic() may be called multiple times to add several user-defined solvers. 224 225 If dynamic libraries are used, then the fourth input argument (routine_create) 226 is ignored. 227 228 Sample usage: 229 .vb 230 ISMappingRegisterDynamic("my_mapping",/home/username/my_lib/lib/libO/solaris/mylib.a, 231 "MyMappingCreate",MyMappingCreate); 232 .ve 233 234 Then, your mapping can be chosen with the procedural interface via 235 $ ISMappingSetType(mfctx,"my_mapping") 236 or at runtime via the option 237 $ -is_mapping_type my_mapping 238 239 .keywords: ISMapping, register 240 241 .seealso: ISMappingRegisterAll(), ISMappingRegisterDestroy() 242 M*/ 243 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 244 #define ISMappingRegisterDynamic(a,b,c,d) ISMappingRegister(a,b,c,0) 245 #else 246 #define ISMappingRegisterDynamic(a,b,c,d) ISMappingRegister(a,b,c,d) 247 #endif 248 249 extern PetscErrorCode ISMappingRegisterAll(const char[]); 250 extern PetscErrorCode ISMappingRegisterDestroy(void); 251 252 /* 253 Only one real type for now. 254 Will wrap sparse Mat and VecScatter objects as ISMappings in the future. 255 */ 256 #define ISMappingType char* 257 #define IS_MAPPING_IS "ISMappingIS" 258 259 extern PetscErrorCode ISMappingCreate(MPI_Comm comm, ISMapping *mapping); 260 extern PetscErrorCode ISMappingView(ISMapping mapping, PetscViewer viewer); 261 extern PetscErrorCode ISMappingDestroy(ISMapping mapping); 262 extern PetscErrorCode ISMappingSetType(ISMapping mapping, const ISMappingType maptype); 263 extern PetscErrorCode ISMappingSetSizes(ISMapping mapping, PetscInt m, PetscInt n, PetscInt M, PetscInt N); 264 extern PetscErrorCode ISMappingGetSizes(ISMapping mapping, PetscInt *m, PetscInt *n, PetscInt *M, PetscInt *N); 265 266 extern PetscErrorCode ISMappingSetUp(ISMapping mapping); 267 extern PetscErrorCode ISMappingAssemblyBegin(ISMapping mapping); 268 extern PetscErrorCode ISMappingAssemblyEnd(ISMapping mapping); 269 270 extern PetscErrorCode ISMappingGetSupportIS(ISMapping mapping, IS *supp); 271 extern PetscErrorCode ISMappingGetImageIS(ISMapping mapping, IS *image); 272 extern PetscErrorCode ISMappingGetSupportSizeLocal(ISMapping mapping, PetscInt *supp_size); 273 extern PetscErrorCode ISMappingGetImageSizeLocal(ISMapping mapping, PetscInt *image_size); 274 extern PetscErrorCode ISMappingGetMaxImageSizeLocal(ISMapping mapping, PetscInt *max_image_size); 275 extern PetscErrorCode ISMappingISGetEdges(ISMapping mapping, IS *ix, IS *iy); 276 277 extern PetscErrorCode ISMappingMapIndicesLocal(ISMapping mapping, PetscInt insize, const PetscInt inidx[], PetscInt *outsize, PetscInt outidx[], PetscInt offsets[]); 278 extern PetscErrorCode ISMappingMapValuesLocal(ISMapping map, PetscInt insize, const PetscInt inidx[], const PetscScalar invals[], PetscInt *outsize, PetscInt outidx[], PetscScalar outvals[], PetscInt offsets[]); 279 extern PetscErrorCode ISMappingBinIndicesLocal(ISMapping mapping, PetscInt insize, const PetscInt inidx[], PetscInt *outsize, PetscInt outidx[], PetscInt offsets[]); 280 extern PetscErrorCode ISMappingBinValuesLocal(ISMapping map, PetscInt insize, const PetscInt inidx[], const PetscScalar invals[], PetscInt *outsize, PetscInt outidx[], PetscScalar outvals[], PetscInt offsets[]); 281 282 extern PetscErrorCode ISMappingMapIndices(ISMapping mapping, PetscInt insize, const PetscInt inidx[], PetscInt *outsize, PetscInt outidx[], PetscInt offsets[], PetscBool drop); 283 extern PetscErrorCode ISMappingMapValues(ISMapping map, PetscInt insize, const PetscInt inidx[], const PetscScalar invals[], PetscInt *outsize, PetscInt outidx[], PetscScalar outvals[], PetscInt offsets[], PetscBool drop); 284 extern PetscErrorCode ISMappingBinIndices(ISMapping mapping, PetscInt insize, const PetscInt inidx[], PetscInt *outsize, PetscInt outidx[], PetscInt offsets[], PetscBool drop); 285 extern PetscErrorCode ISMappingBinValues(ISMapping map, PetscInt insize, const PetscInt inidx[], const PetscScalar invals[], PetscInt *outsize, PetscInt outidx[], PetscScalar outvals[], PetscInt offsets[], PetscBool drop); 286 287 extern PetscErrorCode ISMappingInvert(ISMapping mapping, ISMapping *imapping); 288 extern PetscErrorCode ISMappingPullback(ISMapping mapping1, ISMapping mapping2, ISMapping *mapping); 289 extern PetscErrorCode ISMappingPushforward(ISMapping mapping1, ISMapping mapping2, ISMapping *mapping); 290 291 extern PetscErrorCode ISMappingGetOperator(ISMapping mapping, Mat *op); 292 293 /* IS_MAPPING_IS */ 294 extern PetscErrorCode ISMappingISSetEdges(ISMapping mapping, IS ix, IS iy); 295 296 297 PETSC_EXTERN_CXX_END 298 #endif 299