1 #include <../src/ksp/pc/impls/factor/factor.h> /*I "petscpc.h" I*/ 2 #include <petsc/private/matimpl.h> 3 4 /* 5 If an ordering is not yet set and the matrix is available determine a default ordering 6 */ 7 PetscErrorCode PCFactorSetDefaultOrdering_Factor(PC pc) 8 { 9 PetscBool foundmtype, flg, destroy = PETSC_FALSE; 10 const char *prefix; 11 12 PetscFunctionBegin; 13 if (pc->pmat) { 14 PetscCall(PCGetOptionsPrefix(pc, &prefix)); 15 PetscCall(MatSetOptionsPrefixFactor(pc->pmat, prefix)); 16 PC_Factor *fact = (PC_Factor *)pc->data; 17 PetscCall(MatSolverTypeGet(fact->solvertype, ((PetscObject)pc->pmat)->type_name, fact->factortype, NULL, &foundmtype, NULL)); 18 if (foundmtype) { 19 if (!fact->fact) { 20 /* factored matrix is not present at this point, we want to create it during PCSetUp. 21 Since this can be called from setfromoptions, we destroy it when we are done with it */ 22 PetscCall(MatGetFactor(pc->pmat, fact->solvertype, fact->factortype, &fact->fact)); 23 destroy = PETSC_TRUE; 24 } 25 if (!fact->fact) PetscFunctionReturn(PETSC_SUCCESS); 26 if (!fact->fact->assembled) { 27 PetscCall(PetscStrcmp(fact->solvertype, fact->fact->solvertype, &flg)); 28 if (!flg) { 29 Mat B; 30 PetscCall(MatGetFactor(pc->pmat, fact->solvertype, fact->factortype, &B)); 31 PetscCall(MatHeaderReplace(fact->fact, &B)); 32 } 33 } 34 if (!fact->ordering) { 35 PetscBool canuseordering; 36 MatOrderingType otype; 37 38 PetscCall(MatFactorGetCanUseOrdering(fact->fact, &canuseordering)); 39 if (canuseordering) { 40 PetscCall(MatFactorGetPreferredOrdering(fact->fact, fact->factortype, &otype)); 41 } else otype = MATORDERINGEXTERNAL; 42 PetscCall(PetscStrallocpy(otype, (char **)&fact->ordering)); 43 } 44 if (destroy) PetscCall(MatDestroy(&fact->fact)); 45 } 46 } 47 PetscFunctionReturn(PETSC_SUCCESS); 48 } 49 50 static PetscErrorCode PCFactorSetReuseOrdering_Factor(PC pc, PetscBool flag) 51 { 52 PC_Factor *lu = (PC_Factor *)pc->data; 53 54 PetscFunctionBegin; 55 lu->reuseordering = flag; 56 PetscFunctionReturn(PETSC_SUCCESS); 57 } 58 59 static PetscErrorCode PCFactorSetReuseFill_Factor(PC pc, PetscBool flag) 60 { 61 PC_Factor *lu = (PC_Factor *)pc->data; 62 63 PetscFunctionBegin; 64 lu->reusefill = flag; 65 PetscFunctionReturn(PETSC_SUCCESS); 66 } 67 68 static PetscErrorCode PCFactorSetUseInPlace_Factor(PC pc, PetscBool flg) 69 { 70 PC_Factor *dir = (PC_Factor *)pc->data; 71 72 PetscFunctionBegin; 73 dir->inplace = flg; 74 PetscFunctionReturn(PETSC_SUCCESS); 75 } 76 77 static PetscErrorCode PCFactorGetUseInPlace_Factor(PC pc, PetscBool *flg) 78 { 79 PC_Factor *dir = (PC_Factor *)pc->data; 80 81 PetscFunctionBegin; 82 *flg = dir->inplace; 83 PetscFunctionReturn(PETSC_SUCCESS); 84 } 85 86 /*@ 87 PCFactorSetUpMatSolverType - Can be called after `KSPSetOperators()` or `PCSetOperators()`, causes `MatGetFactor()` to be called so then one may 88 set the options for that particular factorization object. 89 90 Input Parameter: 91 . pc - the preconditioner context 92 93 Note: 94 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. 95 This function raises an error if the requested combination of solver package and matrix type is not supported. 96 97 Level: intermediate 98 99 .seealso: `PCCHOLESKY`, `PCLU`, `PCFactorSetMatSolverType()`, `PCFactorGetMatrix()` 100 @*/ 101 PetscErrorCode PCFactorSetUpMatSolverType(PC pc) 102 { 103 PetscFunctionBegin; 104 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 105 PetscTryMethod(pc, "PCFactorSetUpMatSolverType_C", (PC), (pc)); 106 PetscFunctionReturn(PETSC_SUCCESS); 107 } 108 109 /*@ 110 PCFactorSetZeroPivot - Sets the size at which smaller pivots are declared to be zero 111 112 Logically Collective 113 114 Input Parameters: 115 + pc - the preconditioner context 116 - zero - all pivots smaller than this will be considered zero 117 118 Options Database Key: 119 . -pc_factor_zeropivot <zero> - Sets tolerance for what is considered a zero pivot 120 121 Level: intermediate 122 123 .seealso: `PCCHOLESKY`, `PCLU`, `PCFactorSetShiftType()`, `PCFactorSetShiftAmount()` 124 @*/ 125 PetscErrorCode PCFactorSetZeroPivot(PC pc, PetscReal zero) 126 { 127 PetscFunctionBegin; 128 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 129 PetscValidLogicalCollectiveReal(pc, zero, 2); 130 PetscTryMethod(pc, "PCFactorSetZeroPivot_C", (PC, PetscReal), (pc, zero)); 131 PetscFunctionReturn(PETSC_SUCCESS); 132 } 133 134 /*@ 135 PCFactorSetShiftType - adds a particular type of quantity to the diagonal of the matrix during 136 numerical factorization, thus the matrix has nonzero pivots 137 138 Logically Collective 139 140 Input Parameters: 141 + pc - the preconditioner context 142 - shifttype - type of shift; one of `MAT_SHIFT_NONE`, `MAT_SHIFT_NONZERO`, `MAT_SHIFT_POSITIVE_DEFINITE`, `MAT_SHIFT_INBLOCKS` 143 144 Options Database Key: 145 . -pc_factor_shift_type <shifttype> - Sets shift type; use '-help' for a list of available types 146 147 Level: intermediate 148 149 .seealso: `PCCHOLESKY`, `PCLU`, `PCFactorSetZeroPivot()`, `PCFactorSetShiftAmount()` 150 @*/ 151 PetscErrorCode PCFactorSetShiftType(PC pc, MatFactorShiftType shifttype) 152 { 153 PetscFunctionBegin; 154 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 155 PetscValidLogicalCollectiveEnum(pc, shifttype, 2); 156 PetscTryMethod(pc, "PCFactorSetShiftType_C", (PC, MatFactorShiftType), (pc, shifttype)); 157 PetscFunctionReturn(PETSC_SUCCESS); 158 } 159 160 /*@ 161 PCFactorSetShiftAmount - adds a quantity to the diagonal of the matrix during 162 numerical factorization, thus the matrix has nonzero pivots 163 164 Logically Collective 165 166 Input Parameters: 167 + pc - the preconditioner context 168 - shiftamount - amount of shift or `PETSC_DECIDE` for the default 169 170 Options Database Key: 171 . -pc_factor_shift_amount <shiftamount> - Sets shift amount or -1 for the default 172 173 Level: intermediate 174 175 .seealso: `PCCHOLESKY`, `PCLU`, ``PCFactorSetZeroPivot()`, `PCFactorSetShiftType()` 176 @*/ 177 PetscErrorCode PCFactorSetShiftAmount(PC pc, PetscReal shiftamount) 178 { 179 PetscFunctionBegin; 180 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 181 PetscValidLogicalCollectiveReal(pc, shiftamount, 2); 182 PetscTryMethod(pc, "PCFactorSetShiftAmount_C", (PC, PetscReal), (pc, shiftamount)); 183 PetscFunctionReturn(PETSC_SUCCESS); 184 } 185 186 /*@ 187 PCFactorSetDropTolerance - The preconditioner will use an `PCILU` 188 based on a drop tolerance. 189 190 Logically Collective 191 192 Input Parameters: 193 + pc - the preconditioner context 194 . dt - the drop tolerance, try from 1.e-10 to .1 195 . dtcol - tolerance for column pivot, good values [0.1 to 0.01] 196 - maxrowcount - the max number of nonzeros allowed in a row, best value 197 depends on the number of nonzeros in row of original matrix 198 199 Options Database Key: 200 . -pc_factor_drop_tolerance <dt,dtcol,maxrowcount> - Sets drop tolerance 201 202 Level: intermediate 203 204 Note: 205 There are NO default values for the 3 parameters, you must set them with reasonable values for your 206 matrix. We don't know how to compute reasonable values. 207 208 .seealso: `PCILU` 209 @*/ 210 PetscErrorCode PCFactorSetDropTolerance(PC pc, PetscReal dt, PetscReal dtcol, PetscInt maxrowcount) 211 { 212 PetscFunctionBegin; 213 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 214 PetscValidLogicalCollectiveReal(pc, dtcol, 3); 215 PetscValidLogicalCollectiveInt(pc, maxrowcount, 4); 216 PetscTryMethod(pc, "PCFactorSetDropTolerance_C", (PC, PetscReal, PetscReal, PetscInt), (pc, dt, dtcol, maxrowcount)); 217 PetscFunctionReturn(PETSC_SUCCESS); 218 } 219 220 /*@ 221 PCFactorGetZeroPivot - Gets the tolerance used to define a zero privot 222 223 Not Collective 224 225 Input Parameter: 226 . pc - the preconditioner context 227 228 Output Parameter: 229 . pivot - the tolerance 230 231 Level: intermediate 232 233 .seealso: `PCLU`, `PCCHOLESKY`, `PCFactorSetZeroPivot()` 234 @*/ 235 PetscErrorCode PCFactorGetZeroPivot(PC pc, PetscReal *pivot) 236 { 237 PetscFunctionBegin; 238 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 239 PetscUseMethod(pc, "PCFactorGetZeroPivot_C", (PC, PetscReal *), (pc, pivot)); 240 PetscFunctionReturn(PETSC_SUCCESS); 241 } 242 243 /*@ 244 PCFactorGetShiftAmount - Gets the tolerance used to define a zero privot 245 246 Not Collective 247 248 Input Parameter: 249 . pc - the preconditioner context 250 251 Output Parameter: 252 . shift - how much to shift the diagonal entry 253 254 Level: intermediate 255 256 .seealso: `PCLU`, `PCCHOLESKY`, `PCFactorSetShiftAmount()`, `PCFactorSetShiftType()`, `PCFactorGetShiftType()` 257 @*/ 258 PetscErrorCode PCFactorGetShiftAmount(PC pc, PetscReal *shift) 259 { 260 PetscFunctionBegin; 261 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 262 PetscUseMethod(pc, "PCFactorGetShiftAmount_C", (PC, PetscReal *), (pc, shift)); 263 PetscFunctionReturn(PETSC_SUCCESS); 264 } 265 266 /*@ 267 PCFactorGetShiftType - Gets the type of shift, if any, done when a zero pivot is detected 268 269 Not Collective 270 271 Input Parameter: 272 . pc - the preconditioner context 273 274 Output Parameter: 275 . type - one of `MAT_SHIFT_NONE`, `MAT_SHIFT_NONZERO`, `MAT_SHIFT_POSITIVE_DEFINITE`, or `MAT_SHIFT_INBLOCKS` 276 277 Level: intermediate 278 279 .seealso: `PCLU`, `PCCHOLESKY`, `PCFactorSetShiftType()`, `MatFactorShiftType`, `PCFactorSetShiftAmount()`, `PCFactorGetShiftAmount()` 280 @*/ 281 PetscErrorCode PCFactorGetShiftType(PC pc, MatFactorShiftType *type) 282 { 283 PetscFunctionBegin; 284 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 285 PetscUseMethod(pc, "PCFactorGetShiftType_C", (PC, MatFactorShiftType *), (pc, type)); 286 PetscFunctionReturn(PETSC_SUCCESS); 287 } 288 289 /*@ 290 PCFactorGetLevels - Gets the number of levels of fill to use. 291 292 Logically Collective 293 294 Input Parameter: 295 . pc - the preconditioner context 296 297 Output Parameter: 298 . levels - number of levels of fill 299 300 Level: intermediate 301 302 .seealso: `PCILU`, `PCICC`, `PCFactorSetLevels()` 303 @*/ 304 PetscErrorCode PCFactorGetLevels(PC pc, PetscInt *levels) 305 { 306 PetscFunctionBegin; 307 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 308 PetscUseMethod(pc, "PCFactorGetLevels_C", (PC, PetscInt *), (pc, levels)); 309 PetscFunctionReturn(PETSC_SUCCESS); 310 } 311 312 /*@ 313 PCFactorSetLevels - Sets the number of levels of fill to use. 314 315 Logically Collective 316 317 Input Parameters: 318 + pc - the preconditioner context 319 - levels - number of levels of fill 320 321 Options Database Key: 322 . -pc_factor_levels <levels> - Sets fill level 323 324 Level: intermediate 325 326 .seealso: `PCILU`, `PCICC`, `PCFactorGetLevels()` 327 @*/ 328 PetscErrorCode PCFactorSetLevels(PC pc, PetscInt levels) 329 { 330 PetscFunctionBegin; 331 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 332 PetscCheck(levels >= 0, PetscObjectComm((PetscObject)pc), PETSC_ERR_ARG_OUTOFRANGE, "negative levels"); 333 PetscValidLogicalCollectiveInt(pc, levels, 2); 334 PetscTryMethod(pc, "PCFactorSetLevels_C", (PC, PetscInt), (pc, levels)); 335 PetscFunctionReturn(PETSC_SUCCESS); 336 } 337 338 /*@ 339 PCFactorSetAllowDiagonalFill - Causes all diagonal matrix entries to be 340 treated as level 0 fill even if there is no non-zero location. 341 342 Logically Collective 343 344 Input Parameters: 345 + pc - the preconditioner context 346 - flg - `PETSC_TRUE` to turn on, `PETSC_FALSE` to turn off 347 348 Options Database Key: 349 . -pc_factor_diagonal_fill <bool> - allow the diagonal fill 350 351 Note: 352 Does not apply with 0 fill. 353 354 Level: intermediate 355 356 .seealso: `PCILU`, `PCICC`, `PCFactorGetAllowDiagonalFill()` 357 @*/ 358 PetscErrorCode PCFactorSetAllowDiagonalFill(PC pc, PetscBool flg) 359 { 360 PetscFunctionBegin; 361 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 362 PetscTryMethod(pc, "PCFactorSetAllowDiagonalFill_C", (PC, PetscBool), (pc, flg)); 363 PetscFunctionReturn(PETSC_SUCCESS); 364 } 365 366 /*@ 367 PCFactorGetAllowDiagonalFill - Determines if all diagonal matrix entries are 368 treated as level 0 fill even if there is no non-zero location. 369 370 Logically Collective 371 372 Input Parameter: 373 . pc - the preconditioner context 374 375 Output Parameter: 376 . flg - `PETSC_TRUE` to turn on, `PETSC_FALSE` to turn off 377 378 Note: 379 Does not apply with 0 fill. 380 381 Level: intermediate 382 383 .seealso: `PCILU`, `PCICC`, `PCFactorSetAllowDiagonalFill()` 384 @*/ 385 PetscErrorCode PCFactorGetAllowDiagonalFill(PC pc, PetscBool *flg) 386 { 387 PetscFunctionBegin; 388 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 389 PetscUseMethod(pc, "PCFactorGetAllowDiagonalFill_C", (PC, PetscBool *), (pc, flg)); 390 PetscFunctionReturn(PETSC_SUCCESS); 391 } 392 393 /*@ 394 PCFactorReorderForNonzeroDiagonal - reorders rows/columns of matrix to remove zeros from diagonal 395 396 Logically Collective 397 398 Input Parameters: 399 + pc - the preconditioner context 400 - rtol - diagonal entries smaller than this in absolute value are considered zero 401 402 Options Database Key: 403 . -pc_factor_nonzeros_along_diagonal <tol> - perform the reordering with the given tolerance 404 405 Level: intermediate 406 407 .seealso: `PCILU`, `PCICC`, `PCFactorSetFill()`, `PCFactorSetShiftNonzero()`, `PCFactorSetZeroPivot()`, `MatReorderForNonzeroDiagonal()` 408 @*/ 409 PetscErrorCode PCFactorReorderForNonzeroDiagonal(PC pc, PetscReal rtol) 410 { 411 PetscFunctionBegin; 412 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 413 PetscValidLogicalCollectiveReal(pc, rtol, 2); 414 PetscTryMethod(pc, "PCFactorReorderForNonzeroDiagonal_C", (PC, PetscReal), (pc, rtol)); 415 PetscFunctionReturn(PETSC_SUCCESS); 416 } 417 418 /*@C 419 PCFactorSetMatSolverType - sets the solver package that is used to perform the factorization 420 421 Logically Collective 422 423 Input Parameters: 424 + pc - the preconditioner context 425 - stype - for example, `MATSOLVERSUPERLU`, `MATSOLVERSUPERLU_DIST`, `MATSOLVERMUMPS` 426 427 Options Database Key: 428 . -pc_factor_mat_solver_type <stype> - petsc, superlu, superlu_dist, mumps, cusparse 429 430 Level: intermediate 431 432 Note: 433 By default this will use the PETSc factorization if it exists 434 435 .seealso: `PCLU`, `PCCHOLESKY`, `MatGetFactor()`, `MatSolverType`, `PCFactorGetMatSolverType()`, 436 `MATSOLVERSUPERLU`, `MATSOLVERSUPERLU_DIST`, `MATSOLVERMUMPS` 437 @*/ 438 PetscErrorCode PCFactorSetMatSolverType(PC pc, MatSolverType stype) 439 { 440 PetscFunctionBegin; 441 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 442 PetscTryMethod(pc, "PCFactorSetMatSolverType_C", (PC, MatSolverType), (pc, stype)); 443 PetscFunctionReturn(PETSC_SUCCESS); 444 } 445 446 /*@C 447 PCFactorGetMatSolverType - gets the solver package that is used to perform the factorization 448 449 Not Collective 450 451 Input Parameter: 452 . pc - the preconditioner context 453 454 Output Parameter: 455 . stype - for example, `MATSOLVERSUPERLU`, `MATSOLVERSUPERLU_DIST`, `MATSOLVERMUMPS` 456 457 Level: intermediate 458 459 .seealso: `PCLU`, `PCCHOLESKY`, `MatGetFactor()`, `MatSolverType`, `MATSOLVERSUPERLU`, 460 `MATSOLVERSUPERLU_DIST`, `MATSOLVERMUMPS` 461 @*/ 462 PetscErrorCode PCFactorGetMatSolverType(PC pc, MatSolverType *stype) 463 { 464 PetscErrorCode (*f)(PC, MatSolverType *); 465 466 PetscFunctionBegin; 467 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 468 PetscAssertPointer(stype, 2); 469 PetscCall(PetscObjectQueryFunction((PetscObject)pc, "PCFactorGetMatSolverType_C", &f)); 470 if (f) PetscCall((*f)(pc, stype)); 471 else *stype = NULL; 472 PetscFunctionReturn(PETSC_SUCCESS); 473 } 474 475 /*@ 476 PCFactorSetFill - Indicate the amount of fill you expect in the factored matrix, 477 fill = number nonzeros in factor/number nonzeros in original matrix. 478 479 Not Collective, each process can expect a different amount of fill 480 481 Input Parameters: 482 + pc - the preconditioner context 483 - fill - amount of expected fill 484 485 Options Database Key: 486 . -pc_factor_fill <fill> - Sets fill amount 487 488 Level: intermediate 489 490 Notes: 491 For sparse matrix factorizations it is difficult to predict how much 492 fill to expect. By running with the option -info PETSc will print the 493 actual amount of fill used; allowing you to set the value accurately for 494 future runs. Default PETSc uses a value of 5.0 495 496 This is ignored for most solver packages 497 498 This parameter has NOTHING to do with the levels-of-fill of ILU(). That is set with `PCFactorSetLevels()` or -pc_factor_levels. 499 500 .seealso: `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `PCFactorSetReuseFill()` 501 @*/ 502 PetscErrorCode PCFactorSetFill(PC pc, PetscReal fill) 503 { 504 PetscFunctionBegin; 505 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 506 PetscCheck(fill >= 1.0, PetscObjectComm((PetscObject)pc), PETSC_ERR_ARG_OUTOFRANGE, "Fill factor cannot be less then 1.0"); 507 PetscTryMethod(pc, "PCFactorSetFill_C", (PC, PetscReal), (pc, fill)); 508 PetscFunctionReturn(PETSC_SUCCESS); 509 } 510 511 /*@ 512 PCFactorSetUseInPlace - Tells the preconditioner to do an in-place factorization. 513 514 Logically Collective 515 516 Input Parameters: 517 + pc - the preconditioner context 518 - flg - `PETSC_TRUE` to enable, `PETSC_FALSE` to disable 519 520 Options Database Key: 521 . -pc_factor_in_place <true,false> - Activate/deactivate in-place factorization 522 523 Note: 524 For dense matrices, this enables the solution of much larger problems. 525 For sparse matrices the factorization cannot be done truly in-place 526 so this does not save memory during the factorization, but after the matrix 527 is factored, the original unfactored matrix is freed, thus recovering that 528 space. For ICC(0) and ILU(0) with the default natural ordering the factorization is done efficiently in-place. 529 530 `PCFactorSetUseInplace()` can only be used with the `KSP` method `KSPPREONLY` or when 531 a different matrix is provided for the multiply and the preconditioner in 532 a call to `KSPSetOperators()`. 533 This is because the Krylov space methods require an application of the 534 matrix multiplication, which is not possible here because the matrix has 535 been factored in-place, replacing the original matrix. 536 537 Level: intermediate 538 539 .seealso: `PC`, `Mat`, `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `PCFactorGetUseInPlace()` 540 @*/ 541 PetscErrorCode PCFactorSetUseInPlace(PC pc, PetscBool flg) 542 { 543 PetscFunctionBegin; 544 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 545 PetscTryMethod(pc, "PCFactorSetUseInPlace_C", (PC, PetscBool), (pc, flg)); 546 PetscFunctionReturn(PETSC_SUCCESS); 547 } 548 549 /*@ 550 PCFactorGetUseInPlace - Determines if an in-place factorization is being used. 551 552 Logically Collective 553 554 Input Parameter: 555 . pc - the preconditioner context 556 557 Output Parameter: 558 . flg - `PETSC_TRUE` to enable, `PETSC_FALSE` to disable 559 560 Level: intermediate 561 562 .seealso: `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `PCFactorSetUseInPlace()` 563 @*/ 564 PetscErrorCode PCFactorGetUseInPlace(PC pc, PetscBool *flg) 565 { 566 PetscFunctionBegin; 567 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 568 PetscUseMethod(pc, "PCFactorGetUseInPlace_C", (PC, PetscBool *), (pc, flg)); 569 PetscFunctionReturn(PETSC_SUCCESS); 570 } 571 572 /*@C 573 PCFactorSetMatOrderingType - Sets the ordering routine (to reduce fill) to 574 be used in the `PCLU`, `PCCHOLESKY`, `PCILU`, or `PCICC` preconditioners 575 576 Logically Collective 577 578 Input Parameters: 579 + pc - the preconditioner context 580 - ordering - the matrix ordering name, for example, `MATORDERINGND` or `MATORDERINGRCM` 581 582 Options Database Key: 583 . -pc_factor_mat_ordering_type <nd,rcm,...,external> - Sets ordering routine 584 585 Level: intermediate 586 587 Notes: 588 Nested dissection is used by default for some of PETSc's sparse matrix formats 589 590 For `PCCHOLESKY` and `PCICC` and the `MATSBAIJ` format the only reordering available is natural since only the upper half of the matrix is stored 591 and reordering this matrix is very expensive. 592 593 You can use a `MATSEQAIJ` matrix with Cholesky and ICC and use any ordering. 594 595 `MATORDERINGEXTERNAL` means PETSc will not compute an ordering and the package will use its own ordering, usable with `MATSOLVERCHOLMOD`, `MATSOLVERUMFPACK`, and others. 596 597 .seealso: `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `MatOrderingType`, `MATORDERINGEXTERNAL`, `MATORDERINGND`, `MATORDERINGRCM` 598 @*/ 599 PetscErrorCode PCFactorSetMatOrderingType(PC pc, MatOrderingType ordering) 600 { 601 PetscFunctionBegin; 602 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 603 PetscTryMethod(pc, "PCFactorSetMatOrderingType_C", (PC, MatOrderingType), (pc, ordering)); 604 PetscFunctionReturn(PETSC_SUCCESS); 605 } 606 607 /*@ 608 PCFactorSetColumnPivot - Determines when column pivoting is done during matrix factorization. 609 For PETSc dense matrices column pivoting is always done, for PETSc sparse matrices 610 it is never done. For the MATLAB and `MATSOLVERSUPERLU` factorization this is used. 611 612 Logically Collective 613 614 Input Parameters: 615 + pc - the preconditioner context 616 - dtcol - 0.0 implies no pivoting, 1.0 complete pivoting (slower, requires more memory but more stable) 617 618 Options Database Key: 619 . -pc_factor_pivoting <dtcol> - perform the pivoting with the given tolerance 620 621 Level: intermediate 622 623 .seealso: `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `PCILUSetMatOrdering()`, `PCFactorSetPivotInBlocks()` 624 @*/ 625 PetscErrorCode PCFactorSetColumnPivot(PC pc, PetscReal dtcol) 626 { 627 PetscFunctionBegin; 628 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 629 PetscValidLogicalCollectiveReal(pc, dtcol, 2); 630 PetscTryMethod(pc, "PCFactorSetColumnPivot_C", (PC, PetscReal), (pc, dtcol)); 631 PetscFunctionReturn(PETSC_SUCCESS); 632 } 633 634 /*@ 635 PCFactorSetPivotInBlocks - Determines if pivoting is done while factoring each block 636 with `MATBAIJ` or `MATSBAIJ` matrices 637 638 Logically Collective 639 640 Input Parameters: 641 + pc - the preconditioner context 642 - pivot - `PETSC_TRUE` or `PETSC_FALSE` 643 644 Options Database Key: 645 . -pc_factor_pivot_in_blocks <true,false> - Pivot inside matrix dense blocks for `MATBAIJ` and `MATSBAIJ` 646 647 Level: intermediate 648 649 .seealso: `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `PCILUSetMatOrdering()`, `PCFactorSetColumnPivot()` 650 @*/ 651 PetscErrorCode PCFactorSetPivotInBlocks(PC pc, PetscBool pivot) 652 { 653 PetscFunctionBegin; 654 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 655 PetscValidLogicalCollectiveBool(pc, pivot, 2); 656 PetscTryMethod(pc, "PCFactorSetPivotInBlocks_C", (PC, PetscBool), (pc, pivot)); 657 PetscFunctionReturn(PETSC_SUCCESS); 658 } 659 660 /*@ 661 PCFactorSetReuseFill - When matrices with different nonzero structure are factored, 662 this causes later ones to use the fill ratio computed in the initial factorization. 663 664 Logically Collective 665 666 Input Parameters: 667 + pc - the preconditioner context 668 - flag - `PETSC_TRUE` to reuse else `PETSC_FALSE` 669 670 Options Database Key: 671 . -pc_factor_reuse_fill - Activates `PCFactorSetReuseFill()` 672 673 Level: intermediate 674 675 .seealso: `PCLU`, `PCCHOLESKY`, `PCILU`, `PCICC`, `PCFactorSetReuseOrdering()`, `PCFactorSetFill()` 676 @*/ 677 PetscErrorCode PCFactorSetReuseFill(PC pc, PetscBool flag) 678 { 679 PetscFunctionBegin; 680 PetscValidHeaderSpecific(pc, PC_CLASSID, 1); 681 PetscValidLogicalCollectiveBool(pc, flag, 2); 682 PetscTryMethod(pc, "PCFactorSetReuseFill_C", (PC, PetscBool), (pc, flag)); 683 PetscFunctionReturn(PETSC_SUCCESS); 684 } 685 686 PetscErrorCode PCFactorInitialize(PC pc, MatFactorType ftype) 687 { 688 PC_Factor *fact = (PC_Factor *)pc->data; 689 690 PetscFunctionBegin; 691 PetscCall(MatFactorInfoInitialize(&fact->info)); 692 fact->factortype = ftype; 693 fact->info.shifttype = (PetscReal)MAT_SHIFT_NONE; 694 fact->info.shiftamount = 100.0 * PETSC_MACHINE_EPSILON; 695 fact->info.zeropivot = 100.0 * PETSC_MACHINE_EPSILON; 696 fact->info.pivotinblocks = 1.0; 697 pc->ops->getfactoredmatrix = PCFactorGetMatrix_Factor; 698 699 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetZeroPivot_C", PCFactorSetZeroPivot_Factor)); 700 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetZeroPivot_C", PCFactorGetZeroPivot_Factor)); 701 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetShiftType_C", PCFactorSetShiftType_Factor)); 702 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetShiftType_C", PCFactorGetShiftType_Factor)); 703 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetShiftAmount_C", PCFactorSetShiftAmount_Factor)); 704 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetShiftAmount_C", PCFactorGetShiftAmount_Factor)); 705 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetMatSolverType_C", PCFactorGetMatSolverType_Factor)); 706 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetMatSolverType_C", PCFactorSetMatSolverType_Factor)); 707 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetUpMatSolverType_C", PCFactorSetUpMatSolverType_Factor)); 708 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetFill_C", PCFactorSetFill_Factor)); 709 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetMatOrderingType_C", PCFactorSetMatOrderingType_Factor)); 710 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetLevels_C", PCFactorSetLevels_Factor)); 711 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetLevels_C", PCFactorGetLevels_Factor)); 712 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetAllowDiagonalFill_C", PCFactorSetAllowDiagonalFill_Factor)); 713 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetAllowDiagonalFill_C", PCFactorGetAllowDiagonalFill_Factor)); 714 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetPivotInBlocks_C", PCFactorSetPivotInBlocks_Factor)); 715 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetUseInPlace_C", PCFactorSetUseInPlace_Factor)); 716 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetUseInPlace_C", PCFactorGetUseInPlace_Factor)); 717 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetReuseOrdering_C", PCFactorSetReuseOrdering_Factor)); 718 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetReuseFill_C", PCFactorSetReuseFill_Factor)); 719 PetscFunctionReturn(PETSC_SUCCESS); 720 } 721 722 PetscErrorCode PCFactorClearComposedFunctions(PC pc) 723 { 724 PetscFunctionBegin; 725 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetZeroPivot_C", NULL)); 726 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetZeroPivot_C", NULL)); 727 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetShiftType_C", NULL)); 728 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetShiftType_C", NULL)); 729 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetShiftAmount_C", NULL)); 730 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetShiftAmount_C", NULL)); 731 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetMatSolverType_C", NULL)); 732 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetMatSolverType_C", NULL)); 733 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetUpMatSolverType_C", NULL)); 734 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetFill_C", NULL)); 735 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetMatOrderingType_C", NULL)); 736 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetLevels_C", NULL)); 737 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetLevels_C", NULL)); 738 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetAllowDiagonalFill_C", NULL)); 739 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetAllowDiagonalFill_C", NULL)); 740 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetPivotInBlocks_C", NULL)); 741 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetUseInPlace_C", NULL)); 742 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorGetUseInPlace_C", NULL)); 743 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetReuseOrdering_C", NULL)); 744 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetReuseFill_C", NULL)); 745 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorReorderForNonzeroDiagonal_C", NULL)); 746 PetscCall(PetscObjectComposeFunction((PetscObject)pc, "PCFactorSetDropTolerance_C", NULL)); 747 PetscFunctionReturn(PETSC_SUCCESS); 748 } 749