1 /* 2 Preconditioner module. 3 */ 4 #if !defined(__PETSCPC_H) 5 #define __PETSCPC_H 6 #include "petscmat.h" 7 #include "petscdm.h" 8 PETSC_EXTERN_CXX_BEGIN 9 10 extern PetscErrorCode PCInitializePackage(const char[]); 11 12 /* 13 PCList contains the list of preconditioners currently registered 14 These are added with the PCRegisterDynamic() macro 15 */ 16 extern PetscFList PCList; 17 18 /*S 19 PC - Abstract PETSc object that manages all preconditioners 20 21 Level: beginner 22 23 Concepts: preconditioners 24 25 .seealso: PCCreate(), PCSetType(), PCType (for list of available types) 26 S*/ 27 typedef struct _p_PC* PC; 28 29 /*E 30 PCType - String with the name of a PETSc preconditioner method or the creation function 31 with an optional dynamic library name, for example 32 http://www.mcs.anl.gov/petsc/lib.a:mypccreate() 33 34 Level: beginner 35 36 Notes: Click on the links below to see details on a particular solver 37 38 .seealso: PCSetType(), PC, PCCreate() 39 E*/ 40 #define PCType char* 41 #define PCNONE "none" 42 #define PCJACOBI "jacobi" 43 #define PCSOR "sor" 44 #define PCLU "lu" 45 #define PCSHELL "shell" 46 #define PCBJACOBI "bjacobi" 47 #define PCMG "mg" 48 #define PCEISENSTAT "eisenstat" 49 #define PCILU "ilu" 50 #define PCICC "icc" 51 #define PCASM "asm" 52 #define PCGASM "gasm" 53 #define PCKSP "ksp" 54 #define PCCOMPOSITE "composite" 55 #define PCREDUNDANT "redundant" 56 #define PCSPAI "spai" 57 #define PCNN "nn" 58 #define PCCHOLESKY "cholesky" 59 #define PCPBJACOBI "pbjacobi" 60 #define PCMAT "mat" 61 #define PCHYPRE "hypre" 62 #define PCFIELDSPLIT "fieldsplit" 63 #define PCTFS "tfs" 64 #define PCML "ml" 65 #define PCPROMETHEUS "prometheus" 66 #define PCGALERKIN "galerkin" 67 #define PCEXOTIC "exotic" 68 #define PCOPENMP "openmp" 69 #define PCSUPPORTGRAPH "supportgraph" 70 #define PCASA "asa" 71 #define PCCP "cp" 72 #define PCBFBT "bfbt" 73 #define PCLSC "lsc" 74 #define PCPYTHON "python" 75 #define PCPFMG "pfmg" 76 #define PCSYSPFMG "syspfmg" 77 #define PCREDISTRIBUTE "redistribute" 78 #define PCSACUDA "sacuda" 79 #define PCBICGSTABCUDA "bicgstabcuda" 80 #define PCSVD "svd" 81 82 /* Logging support */ 83 extern PetscClassId PC_CLASSID; 84 85 /*E 86 PCSide - If the preconditioner is to be applied to the left, right 87 or symmetrically around the operator. 88 89 Level: beginner 90 91 .seealso: 92 E*/ 93 typedef enum { PC_LEFT,PC_RIGHT,PC_SYMMETRIC } PCSide; 94 extern const char *PCSides[]; 95 96 extern PetscErrorCode PCCreate(MPI_Comm,PC*); 97 extern PetscErrorCode PCSetType(PC,const PCType); 98 extern PetscErrorCode PCSetUp(PC); 99 extern PetscErrorCode PCSetUpOnBlocks(PC); 100 extern PetscErrorCode PCApply(PC,Vec,Vec); 101 extern PetscErrorCode PCApplySymmetricLeft(PC,Vec,Vec); 102 extern PetscErrorCode PCApplySymmetricRight(PC,Vec,Vec); 103 extern PetscErrorCode PCApplyBAorAB(PC,PCSide,Vec,Vec,Vec); 104 extern PetscErrorCode PCApplyTranspose(PC,Vec,Vec); 105 extern PetscErrorCode PCApplyTransposeExists(PC,PetscBool *); 106 extern PetscErrorCode PCApplyBAorABTranspose(PC,PCSide,Vec,Vec,Vec); 107 108 /*E 109 PCRichardsonConvergedReason - reason a PCApplyRichardson method terminates 110 111 Level: advanced 112 113 Notes: this must match finclude/petscpc.h and the KSPConvergedReason values in petscksp.h 114 115 .seealso: PCApplyRichardson() 116 E*/ 117 typedef enum { 118 PCRICHARDSON_CONVERGED_RTOL = 2, 119 PCRICHARDSON_CONVERGED_ATOL = 3, 120 PCRICHARDSON_CONVERGED_ITS = 4, 121 PCRICHARDSON_DIVERGED_DTOL = -4} PCRichardsonConvergedReason; 122 123 extern PetscErrorCode PCApplyRichardson(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*); 124 extern PetscErrorCode PCApplyRichardsonExists(PC,PetscBool *); 125 extern PetscErrorCode PCSetInitialGuessNonzero(PC,PetscBool ); 126 127 extern PetscErrorCode PCRegisterDestroy(void); 128 extern PetscErrorCode PCRegisterAll(const char[]); 129 extern PetscBool PCRegisterAllCalled; 130 131 extern PetscErrorCode PCRegister(const char[],const char[],const char[],PetscErrorCode(*)(PC)); 132 133 /*MC 134 PCRegisterDynamic - Adds a method to the preconditioner package. 135 136 Synopsis: 137 PetscErrorCode PCRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PC)) 138 139 Not collective 140 141 Input Parameters: 142 + name_solver - name of a new user-defined solver 143 . path - path (either absolute or relative) the library containing this solver 144 . name_create - name of routine to create method context 145 - routine_create - routine to create method context 146 147 Notes: 148 PCRegisterDynamic() may be called multiple times to add several user-defined preconditioners. 149 150 If dynamic libraries are used, then the fourth input argument (routine_create) 151 is ignored. 152 153 Sample usage: 154 .vb 155 PCRegisterDynamic("my_solver","/home/username/my_lib/lib/libO/solaris/mylib", 156 "MySolverCreate",MySolverCreate); 157 .ve 158 159 Then, your solver can be chosen with the procedural interface via 160 $ PCSetType(pc,"my_solver") 161 or at runtime via the option 162 $ -pc_type my_solver 163 164 Level: advanced 165 166 Notes: ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, or ${any environmental variable} 167 occuring in pathname will be replaced with appropriate values. 168 If your function is not being put into a shared library then use PCRegister() instead 169 170 .keywords: PC, register 171 172 .seealso: PCRegisterAll(), PCRegisterDestroy() 173 M*/ 174 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 175 #define PCRegisterDynamic(a,b,c,d) PCRegister(a,b,c,0) 176 #else 177 #define PCRegisterDynamic(a,b,c,d) PCRegister(a,b,c,d) 178 #endif 179 180 extern PetscErrorCode PCDestroy(PC); 181 extern PetscErrorCode PCSetFromOptions(PC); 182 extern PetscErrorCode PCGetType(PC,const PCType*); 183 184 extern PetscErrorCode PCFactorGetMatrix(PC,Mat*); 185 extern PetscErrorCode PCSetModifySubMatrices(PC,PetscErrorCode(*)(PC,PetscInt,const IS[],const IS[],Mat[],void*),void*); 186 extern PetscErrorCode PCModifySubMatrices(PC,PetscInt,const IS[],const IS[],Mat[],void*); 187 188 extern PetscErrorCode PCSetOperators(PC,Mat,Mat,MatStructure); 189 extern PetscErrorCode PCGetOperators(PC,Mat*,Mat*,MatStructure*); 190 extern PetscErrorCode PCGetOperatorsSet(PC,PetscBool *,PetscBool *); 191 192 extern PetscErrorCode PCView(PC,PetscViewer); 193 194 extern PetscErrorCode PCSetOptionsPrefix(PC,const char[]); 195 extern PetscErrorCode PCAppendOptionsPrefix(PC,const char[]); 196 extern PetscErrorCode PCGetOptionsPrefix(PC,const char*[]); 197 198 extern PetscErrorCode PCComputeExplicitOperator(PC,Mat*); 199 200 /* 201 These are used to provide extra scaling of preconditioned 202 operator for time-stepping schemes like in SUNDIALS 203 */ 204 extern PetscErrorCode PCGetDiagonalScale(PC,PetscBool *); 205 extern PetscErrorCode PCDiagonalScaleLeft(PC,Vec,Vec); 206 extern PetscErrorCode PCDiagonalScaleRight(PC,Vec,Vec); 207 extern PetscErrorCode PCSetDiagonalScale(PC,Vec); 208 209 /* ------------- options specific to particular preconditioners --------- */ 210 211 extern PetscErrorCode PCJacobiSetUseRowMax(PC); 212 extern PetscErrorCode PCJacobiSetUseRowSum(PC); 213 extern PetscErrorCode PCJacobiSetUseAbs(PC); 214 extern PetscErrorCode PCSORSetSymmetric(PC,MatSORType); 215 extern PetscErrorCode PCSORSetOmega(PC,PetscReal); 216 extern PetscErrorCode PCSORSetIterations(PC,PetscInt,PetscInt); 217 218 extern PetscErrorCode PCEisenstatSetOmega(PC,PetscReal); 219 extern PetscErrorCode PCEisenstatNoDiagonalScaling(PC); 220 221 #define USE_PRECONDITIONER_MATRIX 0 222 #define USE_TRUE_MATRIX 1 223 extern PetscErrorCode PCBJacobiSetUseTrueLocal(PC); 224 extern PetscErrorCode PCBJacobiSetTotalBlocks(PC,PetscInt,const PetscInt[]); 225 extern PetscErrorCode PCBJacobiSetLocalBlocks(PC,PetscInt,const PetscInt[]); 226 227 extern PetscErrorCode PCKSPSetUseTrue(PC); 228 229 extern PetscErrorCode PCShellSetApply(PC,PetscErrorCode (*)(PC,Vec,Vec)); 230 extern PetscErrorCode PCShellSetApplyBA(PC,PetscErrorCode (*)(PC,PCSide,Vec,Vec,Vec)); 231 extern PetscErrorCode PCShellSetApplyTranspose(PC,PetscErrorCode (*)(PC,Vec,Vec)); 232 extern PetscErrorCode PCShellSetSetUp(PC,PetscErrorCode (*)(PC)); 233 extern PetscErrorCode PCShellSetApplyRichardson(PC,PetscErrorCode (*)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*)); 234 extern PetscErrorCode PCShellSetView(PC,PetscErrorCode (*)(PC,PetscViewer)); 235 extern PetscErrorCode PCShellSetDestroy(PC,PetscErrorCode (*)(PC)); 236 extern PetscErrorCode PCShellGetContext(PC,void**); 237 extern PetscErrorCode PCShellSetContext(PC,void*); 238 extern PetscErrorCode PCShellSetName(PC,const char[]); 239 extern PetscErrorCode PCShellGetName(PC,char*[]); 240 241 extern PetscErrorCode PCFactorSetZeroPivot(PC,PetscReal); 242 243 extern PetscErrorCode PCFactorSetShiftType(PC,MatFactorShiftType); 244 extern PetscErrorCode PCFactorSetShiftAmount(PC,PetscReal); 245 246 extern PetscErrorCode PCFactorSetMatSolverPackage(PC,const MatSolverPackage); 247 extern PetscErrorCode PCFactorGetMatSolverPackage(PC,const MatSolverPackage*); 248 extern PetscErrorCode PCFactorSetUpMatSolverPackage(PC); 249 250 extern PetscErrorCode PCFactorSetFill(PC,PetscReal); 251 extern PetscErrorCode PCFactorSetColumnPivot(PC,PetscReal); 252 extern PetscErrorCode PCFactorReorderForNonzeroDiagonal(PC,PetscReal); 253 254 extern PetscErrorCode PCFactorSetMatOrderingType(PC,const MatOrderingType); 255 extern PetscErrorCode PCFactorSetReuseOrdering(PC,PetscBool ); 256 extern PetscErrorCode PCFactorSetReuseFill(PC,PetscBool ); 257 extern PetscErrorCode PCFactorSetUseInPlace(PC); 258 extern PetscErrorCode PCFactorSetAllowDiagonalFill(PC); 259 extern PetscErrorCode PCFactorSetPivotInBlocks(PC,PetscBool ); 260 261 extern PetscErrorCode PCFactorSetLevels(PC,PetscInt); 262 extern PetscErrorCode PCFactorSetDropTolerance(PC,PetscReal,PetscReal,PetscInt); 263 264 extern PetscErrorCode PCASMSetLocalSubdomains(PC,PetscInt,IS[],IS[]); 265 extern PetscErrorCode PCASMSetTotalSubdomains(PC,PetscInt,IS[],IS[]); 266 extern PetscErrorCode PCASMSetOverlap(PC,PetscInt); 267 extern PetscErrorCode PCASMSetSortIndices(PC,PetscBool ); 268 269 /*E 270 PCASMType - Type of additive Schwarz method to use 271 272 $ PC_ASM_BASIC - symmetric version where residuals from the ghost points are used 273 $ and computed values in ghost regions are added together. Classical 274 $ standard additive Schwarz 275 $ PC_ASM_RESTRICT - residuals from ghost points are used but computed values in ghost 276 $ region are discarded. Default 277 $ PC_ASM_INTERPOLATE - residuals from ghost points are not used, computed values in ghost 278 $ region are added back in 279 $ PC_ASM_NONE - ghost point residuals are not used, computed ghost values are discarded 280 $ not very good. 281 282 Level: beginner 283 284 .seealso: PCASMSetType() 285 E*/ 286 typedef enum {PC_ASM_BASIC = 3,PC_ASM_RESTRICT = 1,PC_ASM_INTERPOLATE = 2,PC_ASM_NONE = 0} PCASMType; 287 extern const char *PCASMTypes[]; 288 289 extern PetscErrorCode PCASMSetType(PC,PCASMType); 290 extern PetscErrorCode PCASMCreateSubdomains(Mat,PetscInt,IS*[]); 291 extern PetscErrorCode PCASMDestroySubdomains(PetscInt,IS[],IS[]); 292 extern PetscErrorCode PCASMCreateSubdomains2D(PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt*,IS**,IS**); 293 extern PetscErrorCode PCASMGetLocalSubdomains(PC,PetscInt*,IS*[],IS*[]); 294 extern PetscErrorCode PCASMGetLocalSubmatrices(PC,PetscInt*,Mat*[]); 295 296 /*E 297 PCGASMType - Type of generalized additive Schwarz method to use (differs from ASM in allowing multiple processors per domain) 298 299 $ PC_GASM_BASIC - symmetric version where residuals from the ghost points are used 300 $ and computed values in ghost regions are added together. Classical 301 $ standard additive Schwarz 302 $ PC_GASM_RESTRICT - residuals from ghost points are used but computed values in ghost 303 $ region are discarded. Default 304 $ PC_GASM_INTERPOLATE - residuals from ghost points are not used, computed values in ghost 305 $ region are added back in 306 $ PC_GASM_NONE - ghost point residuals are not used, computed ghost values are discarded 307 $ not very good. 308 309 Level: beginner 310 311 .seealso: PCGASMSetType() 312 E*/ 313 typedef enum {PC_GASM_BASIC = 3,PC_GASM_RESTRICT = 1,PC_GASM_INTERPOLATE = 2,PC_GASM_NONE = 0} PCGASMType; 314 extern const char *PCGASMTypes[]; 315 316 extern PetscErrorCode PCGASMSetLocalSubdomains(PC,PetscInt,IS[],IS[]); 317 extern PetscErrorCode PCGASMSetTotalSubdomains(PC,PetscInt); 318 extern PetscErrorCode PCGASMSetOverlap(PC,PetscInt); 319 extern PetscErrorCode PCGASMSetSortIndices(PC,PetscBool ); 320 321 extern PetscErrorCode PCGASMSetType(PC,PCGASMType); 322 extern PetscErrorCode PCGASMCreateSubdomains(Mat,PetscInt,IS*[]); 323 extern PetscErrorCode PCGASMDestroySubdomains(PetscInt,IS[],IS[]); 324 extern PetscErrorCode PCGASMCreateSubdomains2D(PC,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt*,IS**,IS**); 325 extern PetscErrorCode PCGASMGetLocalSubdomains(PC,PetscInt*,IS*[],IS*[]); 326 extern PetscErrorCode PCGASMGetLocalSubmatrices(PC,PetscInt*,Mat*[]); 327 328 /*E 329 PCCompositeType - Determines how two or more preconditioner are composed 330 331 $ PC_COMPOSITE_ADDITIVE - results from application of all preconditioners are added together 332 $ PC_COMPOSITE_MULTIPLICATIVE - preconditioners are applied sequentially to the residual freshly 333 $ computed after the previous preconditioner application 334 $ PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE - preconditioners are applied sequentially to the residual freshly 335 $ computed from first preconditioner to last and then back (Use only for symmetric matrices and preconditions) 336 $ PC_COMPOSITE_SPECIAL - This is very special for a matrix of the form alpha I + R + S 337 $ where first preconditioner is built from alpha I + S and second from 338 $ alpha I + R 339 340 Level: beginner 341 342 .seealso: PCCompositeSetType() 343 E*/ 344 typedef enum {PC_COMPOSITE_ADDITIVE,PC_COMPOSITE_MULTIPLICATIVE,PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE,PC_COMPOSITE_SPECIAL,PC_COMPOSITE_SCHUR} PCCompositeType; 345 extern const char *PCCompositeTypes[]; 346 347 extern PetscErrorCode PCCompositeSetUseTrue(PC); 348 extern PetscErrorCode PCCompositeSetType(PC,PCCompositeType); 349 extern PetscErrorCode PCCompositeAddPC(PC,PCType); 350 extern PetscErrorCode PCCompositeGetPC(PC,PetscInt,PC *); 351 extern PetscErrorCode PCCompositeSpecialSetAlpha(PC,PetscScalar); 352 353 extern PetscErrorCode PCRedundantSetNumber(PC,PetscInt); 354 extern PetscErrorCode PCRedundantSetScatter(PC,VecScatter,VecScatter); 355 extern PetscErrorCode PCRedundantGetOperators(PC,Mat*,Mat*); 356 357 extern PetscErrorCode PCSPAISetEpsilon(PC,double); 358 extern PetscErrorCode PCSPAISetNBSteps(PC,PetscInt); 359 extern PetscErrorCode PCSPAISetMax(PC,PetscInt); 360 extern PetscErrorCode PCSPAISetMaxNew(PC,PetscInt); 361 extern PetscErrorCode PCSPAISetBlockSize(PC,PetscInt); 362 extern PetscErrorCode PCSPAISetCacheSize(PC,PetscInt); 363 extern PetscErrorCode PCSPAISetVerbose(PC,PetscInt); 364 extern PetscErrorCode PCSPAISetSp(PC,PetscInt); 365 366 extern PetscErrorCode PCHYPRESetType(PC,const char[]); 367 extern PetscErrorCode PCHYPREGetType(PC,const char*[]); 368 extern PetscErrorCode PCBJacobiGetLocalBlocks(PC,PetscInt*,const PetscInt*[]); 369 extern PetscErrorCode PCBJacobiGetTotalBlocks(PC,PetscInt*,const PetscInt*[]); 370 371 extern PetscErrorCode PCFieldSplitSetFields(PC,const char[],PetscInt,const PetscInt*); 372 extern PetscErrorCode PCFieldSplitSetType(PC,PCCompositeType); 373 extern PetscErrorCode PCFieldSplitSetBlockSize(PC,PetscInt); 374 extern PetscErrorCode PCFieldSplitSetIS(PC,const char[],IS); 375 376 /*E 377 PCFieldSplitSchurPreType - Determines how to precondition Schur complement 378 379 Level: intermediate 380 381 .seealso: PCFieldSplitSchurPrecondition() 382 E*/ 383 typedef enum {PC_FIELDSPLIT_SCHUR_PRE_SELF,PC_FIELDSPLIT_SCHUR_PRE_DIAG,PC_FIELDSPLIT_SCHUR_PRE_USER} PCFieldSplitSchurPreType; 384 extern const char *const PCFieldSplitSchurPreTypes[]; 385 386 extern PetscErrorCode PCFieldSplitSchurPrecondition(PC,PCFieldSplitSchurPreType,Mat); 387 extern PetscErrorCode PCFieldSplitGetSchurBlocks(PC,Mat*,Mat*,Mat*,Mat*); 388 389 extern PetscErrorCode PCGalerkinSetRestriction(PC,Mat); 390 extern PetscErrorCode PCGalerkinSetInterpolation(PC,Mat); 391 392 extern PetscErrorCode PCSetCoordinates(PC,PetscInt,PetscReal*); 393 extern PetscErrorCode PCSASetVectors(PC,PetscInt,PetscReal *); 394 395 extern PetscErrorCode PCPythonSetType(PC,const char[]); 396 397 extern PetscErrorCode PCSetDM(PC,DM); 398 extern PetscErrorCode PCGetDM(PC,DM*); 399 400 extern PetscErrorCode PCBiCGStabCUDASetTolerance(PC,PetscReal); 401 402 PETSC_EXTERN_CXX_END 403 404 #endif /* __PETSCPC_H */ 405