1 2 #include <../src/ksp/pc/impls/factor/factor.h> /*I "petscpc.h" I*/ 3 4 #undef __FUNCT__ 5 #define __FUNCT__ "PCFactorSetUpMatSolverPackage" 6 /*@ 7 PCFactorSetUpMatSolverPackage - Can be called after KSPSetOperators() or PCSetOperators(), causes MatGetFactor() to be called so then one may 8 set the options for that particular factorization object. 9 10 Input Parameter: 11 . pc - the preconditioner context 12 13 Notes: After you have called this function (which has to be after the KSPSetOperators() or PCSetOperators()) you can call PCFactorGetMatrix() and then set factor options on that matrix. 14 15 .seealso: PCFactorSetMatSolverPackage(), PCFactorGetMatrix() 16 17 @*/ 18 PetscErrorCode PCFactorSetUpMatSolverPackage(PC pc) 19 { 20 PetscErrorCode ierr; 21 22 PetscFunctionBegin; 23 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 24 ierr = PetscTryMethod(pc,"PCFactorSetUpMatSolverPackage_C",(PC),(pc));CHKERRQ(ierr); 25 PetscFunctionReturn(0); 26 } 27 28 #undef __FUNCT__ 29 #define __FUNCT__ "PCFactorSetZeroPivot" 30 /*@ 31 PCFactorSetZeroPivot - Sets the size at which smaller pivots are declared to be zero 32 33 Logically Collective on PC 34 35 Input Parameters: 36 + pc - the preconditioner context 37 - zero - all pivots smaller than this will be considered zero 38 39 Options Database Key: 40 . -pc_factor_zeropivot <zero> - Sets tolerance for what is considered a zero pivot 41 42 Level: intermediate 43 44 .keywords: PC, set, factorization, direct, fill 45 46 .seealso: PCFactorSetShiftType(), PCFactorSetShiftAmount() 47 @*/ 48 PetscErrorCode PCFactorSetZeroPivot(PC pc,PetscReal zero) 49 { 50 PetscErrorCode ierr; 51 52 PetscFunctionBegin; 53 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 54 PetscValidLogicalCollectiveReal(pc,zero,2); 55 ierr = PetscTryMethod(pc,"PCFactorSetZeroPivot_C",(PC,PetscReal),(pc,zero));CHKERRQ(ierr); 56 PetscFunctionReturn(0); 57 } 58 59 #undef __FUNCT__ 60 #define __FUNCT__ "PCFactorSetShiftType" 61 /*@ 62 PCFactorSetShiftType - adds a particular type of quantity to the diagonal of the matrix during 63 numerical factorization, thus the matrix has nonzero pivots 64 65 Logically Collective on PC 66 67 Input Parameters: 68 + pc - the preconditioner context 69 - shifttype - type of shift; one of MAT_SHIFT_NONE, MAT_SHIFT_NONZERO, MAT_SHIFT_POSITIVE_DEFINITE, MAT_SHIFT_INBLOCKS 70 71 Options Database Key: 72 . -pc_factor_shift_type <shifttype> - Sets shift type or PETSC_DECIDE for the default; use '-help' for a list of available types 73 74 Level: intermediate 75 76 .keywords: PC, set, factorization, 77 78 .seealso: PCFactorSetZeroPivot(), PCFactorSetShiftAmount() 79 @*/ 80 PetscErrorCode PCFactorSetShiftType(PC pc,MatFactorShiftType shifttype) 81 { 82 PetscErrorCode ierr; 83 84 PetscFunctionBegin; 85 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 86 PetscValidLogicalCollectiveEnum(pc,shifttype,2); 87 ierr = PetscTryMethod(pc,"PCFactorSetShiftType_C",(PC,MatFactorShiftType),(pc,shifttype));CHKERRQ(ierr); 88 PetscFunctionReturn(0); 89 } 90 91 #undef __FUNCT__ 92 #define __FUNCT__ "PCFactorSetShiftAmount" 93 /*@ 94 PCFactorSetShiftAmount - adds a quantity to the diagonal of the matrix during 95 numerical factorization, thus the matrix has nonzero pivots 96 97 Logically Collective on PC 98 99 Input Parameters: 100 + pc - the preconditioner context 101 - shiftamount - amount of shift 102 103 Options Database Key: 104 . -pc_factor_shift_amount <shiftamount> - Sets shift amount or PETSC_DECIDE for the default 105 106 Level: intermediate 107 108 .keywords: PC, set, factorization, 109 110 .seealso: PCFactorSetZeroPivot(), PCFactorSetShiftType() 111 @*/ 112 PetscErrorCode PCFactorSetShiftAmount(PC pc,PetscReal shiftamount) 113 { 114 PetscErrorCode ierr; 115 116 PetscFunctionBegin; 117 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 118 PetscValidLogicalCollectiveReal(pc,shiftamount,2); 119 ierr = PetscTryMethod(pc,"PCFactorSetShiftAmount_C",(PC,PetscReal),(pc,shiftamount));CHKERRQ(ierr); 120 PetscFunctionReturn(0); 121 } 122 123 #undef __FUNCT__ 124 #define __FUNCT__ "PCFactorSetDropTolerance" 125 /* 126 PCFactorSetDropTolerance - The preconditioner will use an ILU 127 based on a drop tolerance. (Under development) 128 129 Logically Collective on PC 130 131 Input Parameters: 132 + pc - the preconditioner context 133 . dt - the drop tolerance, try from 1.e-10 to .1 134 . dtcol - tolerance for column pivot, good values [0.1 to 0.01] 135 - maxrowcount - the max number of nonzeros allowed in a row, best value 136 depends on the number of nonzeros in row of original matrix 137 138 Options Database Key: 139 . -pc_factor_drop_tolerance <dt,dtcol,maxrowcount> - Sets drop tolerance 140 141 Level: intermediate 142 143 There are NO default values for the 3 parameters, you must set them with reasonable values for your 144 matrix. We don't know how to compute reasonable values. 145 146 .keywords: PC, levels, reordering, factorization, incomplete, ILU 147 */ 148 PetscErrorCode PCFactorSetDropTolerance(PC pc,PetscReal dt,PetscReal dtcol,PetscInt maxrowcount) 149 { 150 PetscErrorCode ierr; 151 152 PetscFunctionBegin; 153 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 154 PetscValidLogicalCollectiveReal(pc,dtcol,2); 155 PetscValidLogicalCollectiveInt(pc,maxrowcount,3); 156 ierr = PetscTryMethod(pc,"PCFactorSetDropTolerance_C",(PC,PetscReal,PetscReal,PetscInt),(pc,dt,dtcol,maxrowcount));CHKERRQ(ierr); 157 PetscFunctionReturn(0); 158 } 159 160 #undef __FUNCT__ 161 #define __FUNCT__ "PCFactorSetLevels" 162 /*@ 163 PCFactorSetLevels - Sets the number of levels of fill to use. 164 165 Logically Collective on PC 166 167 Input Parameters: 168 + pc - the preconditioner context 169 - levels - number of levels of fill 170 171 Options Database Key: 172 . -pc_factor_levels <levels> - Sets fill level 173 174 Level: intermediate 175 176 .keywords: PC, levels, fill, factorization, incomplete, ILU 177 @*/ 178 PetscErrorCode PCFactorSetLevels(PC pc,PetscInt levels) 179 { 180 PetscErrorCode ierr; 181 182 PetscFunctionBegin; 183 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 184 if (levels < 0) SETERRQ(((PetscObject)pc)->comm,PETSC_ERR_ARG_OUTOFRANGE,"negative levels"); 185 PetscValidLogicalCollectiveInt(pc,levels,2); 186 ierr = PetscTryMethod(pc,"PCFactorSetLevels_C",(PC,PetscInt),(pc,levels));CHKERRQ(ierr); 187 PetscFunctionReturn(0); 188 } 189 190 #undef __FUNCT__ 191 #define __FUNCT__ "PCFactorSetAllowDiagonalFill" 192 /*@ 193 PCFactorSetAllowDiagonalFill - Causes all diagonal matrix entries to be 194 treated as level 0 fill even if there is no non-zero location. 195 196 Logically Collective on PC 197 198 Input Parameters: 199 + pc - the preconditioner context 200 201 Options Database Key: 202 . -pc_factor_diagonal_fill 203 204 Notes: 205 Does not apply with 0 fill. 206 207 Level: intermediate 208 209 .keywords: PC, levels, fill, factorization, incomplete, ILU 210 @*/ 211 PetscErrorCode PCFactorSetAllowDiagonalFill(PC pc) 212 { 213 PetscErrorCode ierr; 214 215 PetscFunctionBegin; 216 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 217 ierr = PetscTryMethod(pc,"PCFactorSetAllowDiagonalFill_C",(PC),(pc));CHKERRQ(ierr); 218 PetscFunctionReturn(0); 219 } 220 221 #undef __FUNCT__ 222 #define __FUNCT__ "PCFactorReorderForNonzeroDiagonal" 223 /*@ 224 PCFactorReorderForNonzeroDiagonal - reorders rows/columns of matrix to remove zeros from diagonal 225 226 Logically Collective on PC 227 228 Input Parameters: 229 + pc - the preconditioner context 230 - tol - diagonal entries smaller than this in absolute value are considered zero 231 232 Options Database Key: 233 . -pc_factor_nonzeros_along_diagonal 234 235 Level: intermediate 236 237 .keywords: PC, set, factorization, direct, fill 238 239 .seealso: PCFactorSetFill(), PCFactorSetShiftNonzero(), PCFactorSetZeroPivot(), MatReorderForNonzeroDiagonal() 240 @*/ 241 PetscErrorCode PCFactorReorderForNonzeroDiagonal(PC pc,PetscReal rtol) 242 { 243 PetscErrorCode ierr; 244 245 PetscFunctionBegin; 246 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 247 PetscValidLogicalCollectiveReal(pc,rtol,2); 248 ierr = PetscTryMethod(pc,"PCFactorReorderForNonzeroDiagonal_C",(PC,PetscReal),(pc,rtol));CHKERRQ(ierr); 249 PetscFunctionReturn(0); 250 } 251 252 #undef __FUNCT__ 253 #define __FUNCT__ "PCFactorSetMatSolverPackage" 254 /*@C 255 PCFactorSetMatSolverPackage - sets the software that is used to perform the factorization 256 257 Logically Collective on PC 258 259 Input Parameters: 260 + pc - the preconditioner context 261 - stype - for example, spooles, superlu, superlu_dist 262 263 Options Database Key: 264 . -pc_factor_mat_solver_package <stype> - spooles, petsc, superlu, superlu_dist, mumps 265 266 Level: intermediate 267 268 Note: 269 By default this will use the PETSc factorization if it exists 270 271 272 .keywords: PC, set, factorization, direct, fill 273 274 .seealso: MatGetFactor(), MatSolverPackage, PCFactorGetMatSolverPackage() 275 276 @*/ 277 PetscErrorCode PCFactorSetMatSolverPackage(PC pc,const MatSolverPackage stype) 278 { 279 PetscErrorCode ierr; 280 281 PetscFunctionBegin; 282 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 283 ierr = PetscTryMethod(pc,"PCFactorSetMatSolverPackage_C",(PC,const MatSolverPackage),(pc,stype));CHKERRQ(ierr); 284 PetscFunctionReturn(0); 285 } 286 287 #undef __FUNCT__ 288 #define __FUNCT__ "PCFactorGetMatSolverPackage" 289 /*@C 290 PCFactorGetMatSolverPackage - gets the software that is used to perform the factorization 291 292 Not Collective 293 294 Input Parameter: 295 . pc - the preconditioner context 296 297 Output Parameter: 298 . stype - for example, spooles, superlu, superlu_dist (PETSC_NULL if the PC does not have a solver package) 299 300 Level: intermediate 301 302 303 .keywords: PC, set, factorization, direct, fill 304 305 .seealso: MatGetFactor(), MatSolverPackage, PCFactorGetMatSolverPackage() 306 307 @*/ 308 PetscErrorCode PCFactorGetMatSolverPackage(PC pc,const MatSolverPackage *stype) 309 { 310 PetscErrorCode ierr,(*f)(PC,const MatSolverPackage*); 311 312 PetscFunctionBegin; 313 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 314 ierr = PetscObjectQueryFunction((PetscObject)pc,"PCFactorGetMatSolverPackage_C",(void(**)(void))&f);CHKERRQ(ierr); 315 if (f) { 316 ierr = (*f)(pc,stype);CHKERRQ(ierr); 317 } else { 318 *stype = PETSC_NULL; 319 } 320 PetscFunctionReturn(0); 321 } 322 323 #undef __FUNCT__ 324 #define __FUNCT__ "PCFactorSetFill" 325 /*@ 326 PCFactorSetFill - Indicate the amount of fill you expect in the factored matrix, 327 fill = number nonzeros in factor/number nonzeros in original matrix. 328 329 Not Collective, each process can expect a different amount of fill 330 331 Input Parameters: 332 + pc - the preconditioner context 333 - fill - amount of expected fill 334 335 Options Database Key: 336 . -pc_factor_fill <fill> - Sets fill amount 337 338 Level: intermediate 339 340 Note: 341 For sparse matrix factorizations it is difficult to predict how much 342 fill to expect. By running with the option -info PETSc will print the 343 actual amount of fill used; allowing you to set the value accurately for 344 future runs. Default PETSc uses a value of 5.0 345 346 This parameter has NOTHING to do with the levels-of-fill of ILU(). That is set with PCFactorSetLevels() or -pc_factor_levels. 347 348 349 .keywords: PC, set, factorization, direct, fill 350 351 @*/ 352 PetscErrorCode PCFactorSetFill(PC pc,PetscReal fill) 353 { 354 PetscErrorCode ierr; 355 356 PetscFunctionBegin; 357 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 358 if (fill < 1.0) SETERRQ(((PetscObject)pc)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Fill factor cannot be less then 1.0"); 359 ierr = PetscTryMethod(pc,"PCFactorSetFill_C",(PC,PetscReal),(pc,fill));CHKERRQ(ierr); 360 PetscFunctionReturn(0); 361 } 362 363 #undef __FUNCT__ 364 #define __FUNCT__ "PCFactorSetUseInPlace" 365 /*@ 366 PCFactorSetUseInPlace - Tells the system to do an in-place factorization. 367 For dense matrices, this enables the solution of much larger problems. 368 For sparse matrices the factorization cannot be done truly in-place 369 so this does not save memory during the factorization, but after the matrix 370 is factored, the original unfactored matrix is freed, thus recovering that 371 space. 372 373 Logically Collective on PC 374 375 Input Parameters: 376 . pc - the preconditioner context 377 378 Options Database Key: 379 . -pc_factor_in_place - Activates in-place factorization 380 381 Notes: 382 PCFactorSetUseInplace() can only be used with the KSP method KSPPREONLY or when 383 a different matrix is provided for the multiply and the preconditioner in 384 a call to KSPSetOperators(). 385 This is because the Krylov space methods require an application of the 386 matrix multiplication, which is not possible here because the matrix has 387 been factored in-place, replacing the original matrix. 388 389 Level: intermediate 390 391 .keywords: PC, set, factorization, direct, inplace, in-place, LU 392 393 .seealso: PCILUSetUseInPlace() 394 @*/ 395 PetscErrorCode PCFactorSetUseInPlace(PC pc) 396 { 397 PetscErrorCode ierr; 398 399 PetscFunctionBegin; 400 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 401 ierr = PetscTryMethod(pc,"PCFactorSetUseInPlace_C",(PC),(pc));CHKERRQ(ierr); 402 PetscFunctionReturn(0); 403 } 404 405 #undef __FUNCT__ 406 #define __FUNCT__ "PCFactorSetMatOrderingType" 407 /*@C 408 PCFactorSetMatOrderingType - Sets the ordering routine (to reduce fill) to 409 be used in the LU factorization. 410 411 Logically Collective on PC 412 413 Input Parameters: 414 + pc - the preconditioner context 415 - ordering - the matrix ordering name, for example, MATORDERINGND or MATORDERINGRCM 416 417 Options Database Key: 418 . -pc_factor_mat_ordering_type <nd,rcm,...> - Sets ordering routine 419 420 Level: intermediate 421 422 Notes: nested dissection is used by default 423 424 For Cholesky and ICC and the SBAIJ format reorderings are not available, 425 since only the upper triangular part of the matrix is stored. You can use the 426 SeqAIJ format in this case to get reorderings. 427 428 @*/ 429 PetscErrorCode PCFactorSetMatOrderingType(PC pc,const MatOrderingType ordering) 430 { 431 PetscErrorCode ierr; 432 433 PetscFunctionBegin; 434 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 435 ierr = PetscTryMethod(pc,"PCFactorSetMatOrderingType_C",(PC,const MatOrderingType),(pc,ordering));CHKERRQ(ierr); 436 PetscFunctionReturn(0); 437 } 438 439 #undef __FUNCT__ 440 #define __FUNCT__ "PCFactorSetColumnPivot" 441 /*@ 442 PCFactorSetColumnPivot - Determines when column pivoting is done during matrix factorization. 443 For PETSc dense matrices column pivoting is always done, for PETSc sparse matrices 444 it is never done. For the MATLAB and SuperLU factorization this is used. 445 446 Logically Collective on PC 447 448 Input Parameters: 449 + pc - the preconditioner context 450 - dtcol - 0.0 implies no pivoting, 1.0 complete pivoting (slower, requires more memory but more stable) 451 452 Options Database Key: 453 . -pc_factor_pivoting <dtcol> 454 455 Level: intermediate 456 457 .seealso: PCILUSetMatOrdering(), PCFactorSetPivotInBlocks() 458 @*/ 459 PetscErrorCode PCFactorSetColumnPivot(PC pc,PetscReal dtcol) 460 { 461 PetscErrorCode ierr; 462 463 PetscFunctionBegin; 464 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 465 PetscValidLogicalCollectiveReal(pc,dtcol,2); 466 ierr = PetscTryMethod(pc,"PCFactorSetColumnPivot_C",(PC,PetscReal),(pc,dtcol));CHKERRQ(ierr); 467 PetscFunctionReturn(0); 468 } 469 470 #undef __FUNCT__ 471 #define __FUNCT__ "PCFactorSetPivotInBlocks" 472 /*@ 473 PCFactorSetPivotInBlocks - Determines if pivoting is done while factoring each block 474 with BAIJ or SBAIJ matrices 475 476 Logically Collective on PC 477 478 Input Parameters: 479 + pc - the preconditioner context 480 - pivot - PETSC_TRUE or PETSC_FALSE 481 482 Options Database Key: 483 . -pc_factor_pivot_in_blocks <true,false> 484 485 Level: intermediate 486 487 .seealso: PCILUSetMatOrdering(), PCFactorSetColumnPivot() 488 @*/ 489 PetscErrorCode PCFactorSetPivotInBlocks(PC pc,PetscBool pivot) 490 { 491 PetscErrorCode ierr; 492 493 PetscFunctionBegin; 494 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 495 PetscValidLogicalCollectiveBool(pc,pivot,2); 496 ierr = PetscTryMethod(pc,"PCFactorSetPivotInBlocks_C",(PC,PetscBool),(pc,pivot));CHKERRQ(ierr); 497 PetscFunctionReturn(0); 498 } 499 500 #undef __FUNCT__ 501 #define __FUNCT__ "PCFactorSetReuseFill" 502 /*@ 503 PCFactorSetReuseFill - When matrices with same different nonzero structure are factored, 504 this causes later ones to use the fill ratio computed in the initial factorization. 505 506 Logically Collective on PC 507 508 Input Parameters: 509 + pc - the preconditioner context 510 - flag - PETSC_TRUE to reuse else PETSC_FALSE 511 512 Options Database Key: 513 . -pc_factor_reuse_fill - Activates PCFactorSetReuseFill() 514 515 Level: intermediate 516 517 .keywords: PC, levels, reordering, factorization, incomplete, Cholesky 518 519 .seealso: PCFactorSetReuseOrdering() 520 @*/ 521 PetscErrorCode PCFactorSetReuseFill(PC pc,PetscBool flag) 522 { 523 PetscErrorCode ierr; 524 525 PetscFunctionBegin; 526 PetscValidHeaderSpecific(pc,PC_CLASSID,2); 527 PetscValidLogicalCollectiveBool(pc,flag,2); 528 ierr = PetscTryMethod(pc,"PCFactorSetReuseFill_C",(PC,PetscBool),(pc,flag));CHKERRQ(ierr); 529 PetscFunctionReturn(0); 530 } 531