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 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; 311 312 PetscFunctionBegin; 313 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 314 ierr = PetscTryMethod(pc,"PCFactorGetMatSolverPackage_C",(PC,const MatSolverPackage*),(pc,stype));CHKERRQ(ierr); 315 PetscFunctionReturn(0); 316 } 317 318 #undef __FUNCT__ 319 #define __FUNCT__ "PCFactorSetFill" 320 /*@ 321 PCFactorSetFill - Indicate the amount of fill you expect in the factored matrix, 322 fill = number nonzeros in factor/number nonzeros in original matrix. 323 324 Not Collective, each process can expect a different amount of fill 325 326 Input Parameters: 327 + pc - the preconditioner context 328 - fill - amount of expected fill 329 330 Options Database Key: 331 . -pc_factor_fill <fill> - Sets fill amount 332 333 Level: intermediate 334 335 Note: 336 For sparse matrix factorizations it is difficult to predict how much 337 fill to expect. By running with the option -info PETSc will print the 338 actual amount of fill used; allowing you to set the value accurately for 339 future runs. Default PETSc uses a value of 5.0 340 341 This parameter has NOTHING to do with the levels-of-fill of ILU(). That is set with PCFactorSetLevels() or -pc_factor_levels. 342 343 344 .keywords: PC, set, factorization, direct, fill 345 346 @*/ 347 PetscErrorCode PCFactorSetFill(PC pc,PetscReal fill) 348 { 349 PetscErrorCode ierr; 350 351 PetscFunctionBegin; 352 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 353 if (fill < 1.0) SETERRQ(((PetscObject)pc)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Fill factor cannot be less then 1.0"); 354 ierr = PetscTryMethod(pc,"PCFactorSetFill_C",(PC,PetscReal),(pc,fill));CHKERRQ(ierr); 355 PetscFunctionReturn(0); 356 } 357 358 #undef __FUNCT__ 359 #define __FUNCT__ "PCFactorSetUseInPlace" 360 /*@ 361 PCFactorSetUseInPlace - Tells the system to do an in-place factorization. 362 For dense matrices, this enables the solution of much larger problems. 363 For sparse matrices the factorization cannot be done truly in-place 364 so this does not save memory during the factorization, but after the matrix 365 is factored, the original unfactored matrix is freed, thus recovering that 366 space. 367 368 Logically Collective on PC 369 370 Input Parameters: 371 . pc - the preconditioner context 372 373 Options Database Key: 374 . -pc_factor_in_place - Activates in-place factorization 375 376 Notes: 377 PCFactorSetUseInplace() can only be used with the KSP method KSPPREONLY or when 378 a different matrix is provided for the multiply and the preconditioner in 379 a call to KSPSetOperators(). 380 This is because the Krylov space methods require an application of the 381 matrix multiplication, which is not possible here because the matrix has 382 been factored in-place, replacing the original matrix. 383 384 Level: intermediate 385 386 .keywords: PC, set, factorization, direct, inplace, in-place, LU 387 388 .seealso: PCILUSetUseInPlace() 389 @*/ 390 PetscErrorCode PCFactorSetUseInPlace(PC pc) 391 { 392 PetscErrorCode ierr; 393 394 PetscFunctionBegin; 395 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 396 ierr = PetscTryMethod(pc,"PCFactorSetUseInPlace_C",(PC),(pc));CHKERRQ(ierr); 397 PetscFunctionReturn(0); 398 } 399 400 #undef __FUNCT__ 401 #define __FUNCT__ "PCFactorSetMatOrderingType" 402 /*@C 403 PCFactorSetMatOrderingType - Sets the ordering routine (to reduce fill) to 404 be used in the LU factorization. 405 406 Logically Collective on PC 407 408 Input Parameters: 409 + pc - the preconditioner context 410 - ordering - the matrix ordering name, for example, MATORDERINGND or MATORDERINGRCM 411 412 Options Database Key: 413 . -pc_factor_mat_ordering_type <nd,rcm,...> - Sets ordering routine 414 415 Level: intermediate 416 417 Notes: nested dissection is used by default 418 419 For Cholesky and ICC and the SBAIJ format reorderings are not available, 420 since only the upper triangular part of the matrix is stored. You can use the 421 SeqAIJ format in this case to get reorderings. 422 423 @*/ 424 PetscErrorCode PCFactorSetMatOrderingType(PC pc,const MatOrderingType ordering) 425 { 426 PetscErrorCode ierr; 427 428 PetscFunctionBegin; 429 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 430 ierr = PetscTryMethod(pc,"PCFactorSetMatOrderingType_C",(PC,const MatOrderingType),(pc,ordering));CHKERRQ(ierr); 431 PetscFunctionReturn(0); 432 } 433 434 #undef __FUNCT__ 435 #define __FUNCT__ "PCFactorSetColumnPivot" 436 /*@ 437 PCFactorSetColumnPivot - Determines when column pivoting is done during matrix factorization. 438 For PETSc dense matrices column pivoting is always done, for PETSc sparse matrices 439 it is never done. For the MATLAB and SuperLU factorization this is used. 440 441 Logically Collective on PC 442 443 Input Parameters: 444 + pc - the preconditioner context 445 - dtcol - 0.0 implies no pivoting, 1.0 complete pivoting (slower, requires more memory but more stable) 446 447 Options Database Key: 448 . -pc_factor_pivoting <dtcol> 449 450 Level: intermediate 451 452 .seealso: PCILUSetMatOrdering(), PCFactorSetPivotInBlocks() 453 @*/ 454 PetscErrorCode PCFactorSetColumnPivot(PC pc,PetscReal dtcol) 455 { 456 PetscErrorCode ierr; 457 458 PetscFunctionBegin; 459 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 460 PetscValidLogicalCollectiveReal(pc,dtcol,2); 461 ierr = PetscTryMethod(pc,"PCFactorSetColumnPivot_C",(PC,PetscReal),(pc,dtcol));CHKERRQ(ierr); 462 PetscFunctionReturn(0); 463 } 464 465 #undef __FUNCT__ 466 #define __FUNCT__ "PCFactorSetPivotInBlocks" 467 /*@ 468 PCFactorSetPivotInBlocks - Determines if pivoting is done while factoring each block 469 with BAIJ or SBAIJ matrices 470 471 Logically Collective on PC 472 473 Input Parameters: 474 + pc - the preconditioner context 475 - pivot - PETSC_TRUE or PETSC_FALSE 476 477 Options Database Key: 478 . -pc_factor_pivot_in_blocks <true,false> 479 480 Level: intermediate 481 482 .seealso: PCILUSetMatOrdering(), PCFactorSetColumnPivot() 483 @*/ 484 PetscErrorCode PCFactorSetPivotInBlocks(PC pc,PetscBool pivot) 485 { 486 PetscErrorCode ierr; 487 488 PetscFunctionBegin; 489 PetscValidHeaderSpecific(pc,PC_CLASSID,1); 490 PetscValidLogicalCollectiveBool(pc,pivot,2); 491 ierr = PetscTryMethod(pc,"PCFactorSetPivotInBlocks_C",(PC,PetscBool),(pc,pivot));CHKERRQ(ierr); 492 PetscFunctionReturn(0); 493 } 494 495 #undef __FUNCT__ 496 #define __FUNCT__ "PCFactorSetReuseFill" 497 /*@ 498 PCFactorSetReuseFill - When matrices with same different nonzero structure are factored, 499 this causes later ones to use the fill ratio computed in the initial factorization. 500 501 Logically Collective on PC 502 503 Input Parameters: 504 + pc - the preconditioner context 505 - flag - PETSC_TRUE to reuse else PETSC_FALSE 506 507 Options Database Key: 508 . -pc_factor_reuse_fill - Activates PCFactorSetReuseFill() 509 510 Level: intermediate 511 512 .keywords: PC, levels, reordering, factorization, incomplete, Cholesky 513 514 .seealso: PCFactorSetReuseOrdering() 515 @*/ 516 PetscErrorCode PCFactorSetReuseFill(PC pc,PetscBool flag) 517 { 518 PetscErrorCode ierr; 519 520 PetscFunctionBegin; 521 PetscValidHeaderSpecific(pc,PC_CLASSID,2); 522 PetscValidLogicalCollectiveBool(pc,flag,2); 523 ierr = PetscTryMethod(pc,"PCFactorSetReuseFill_C",(PC,PetscBool),(pc,flag));CHKERRQ(ierr); 524 PetscFunctionReturn(0); 525 } 526