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