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