xref: /petsc/src/ksp/pc/impls/factor/factor.c (revision c7f610a14381a3c93d588cae6b722596f84a7640)
15e8efad8SHong Zhang 
2c6db04a5SJed Brown #include <../src/ksp/pc/impls/factor/factor.h>  /*I "petscpc.h" I*/
35e8efad8SHong Zhang 
4ee45ca4aSHong Zhang #undef __FUNCT__
5f8260c8fSBarry Smith #define __FUNCT__ "PCFactorSetUpMatSolverPackage"
6f8260c8fSBarry Smith /*@
7f8260c8fSBarry Smith     PCFactorSetUpMatSolverPackage - Can be called after KSPSetOperators() or PCSetOperators(), causes MatGetFactor() to be called so then one may
8f8260c8fSBarry Smith        set the options for that particular factorization object.
9f8260c8fSBarry Smith 
10f8260c8fSBarry Smith   Input Parameter:
11f8260c8fSBarry Smith .  pc  - the preconditioner context
12f8260c8fSBarry Smith 
13f8260c8fSBarry Smith   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.
14f8260c8fSBarry Smith 
15f8260c8fSBarry Smith .seealso: PCFactorSetMatSolverPackage(), PCFactorGetMatrix()
16f8260c8fSBarry Smith 
172bd2b0e6SSatish Balay   Level: intermediate
182bd2b0e6SSatish Balay 
19f8260c8fSBarry Smith @*/
20f8260c8fSBarry Smith PetscErrorCode PCFactorSetUpMatSolverPackage(PC pc)
21f8260c8fSBarry Smith {
22f8260c8fSBarry Smith   PetscErrorCode ierr;
23f8260c8fSBarry Smith 
24f8260c8fSBarry Smith   PetscFunctionBegin;
25f8260c8fSBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
26f8260c8fSBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetUpMatSolverPackage_C",(PC),(pc));CHKERRQ(ierr);
27b3a44c85SBarry Smith   PetscFunctionReturn(0);
28f8260c8fSBarry Smith }
29f8260c8fSBarry Smith 
30f8260c8fSBarry Smith #undef __FUNCT__
31ee45ca4aSHong Zhang #define __FUNCT__ "PCFactorSetZeroPivot"
32ee45ca4aSHong Zhang /*@
33ee45ca4aSHong Zhang    PCFactorSetZeroPivot - Sets the size at which smaller pivots are declared to be zero
34ee45ca4aSHong Zhang 
35ad4df100SBarry Smith    Logically Collective on PC
36ee45ca4aSHong Zhang 
37ee45ca4aSHong Zhang    Input Parameters:
38afaefe49SHong Zhang +  pc - the preconditioner context
39afaefe49SHong Zhang -  zero - all pivots smaller than this will be considered zero
40ee45ca4aSHong Zhang 
41ee45ca4aSHong Zhang    Options Database Key:
42ee45ca4aSHong Zhang .  -pc_factor_zeropivot <zero> - Sets tolerance for what is considered a zero pivot
43ee45ca4aSHong Zhang 
44ee45ca4aSHong Zhang    Level: intermediate
45ee45ca4aSHong Zhang 
46ee45ca4aSHong Zhang .keywords: PC, set, factorization, direct, fill
47ee45ca4aSHong Zhang 
48daa17b54SHong Zhang .seealso: PCFactorSetShiftType(), PCFactorSetShiftAmount()
49ee45ca4aSHong Zhang @*/
507087cfbeSBarry Smith PetscErrorCode  PCFactorSetZeroPivot(PC pc,PetscReal zero)
51ee45ca4aSHong Zhang {
524ac538c5SBarry Smith   PetscErrorCode ierr;
53afaefe49SHong Zhang 
54ee45ca4aSHong Zhang   PetscFunctionBegin;
550700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
56c5eb9154SBarry Smith   PetscValidLogicalCollectiveReal(pc,zero,2);
574ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetZeroPivot_C",(PC,PetscReal),(pc,zero));CHKERRQ(ierr);
58ee45ca4aSHong Zhang   PetscFunctionReturn(0);
59ee45ca4aSHong Zhang }
60ee45ca4aSHong Zhang 
615e8efad8SHong Zhang #undef __FUNCT__
62d90ac83dSHong Zhang #define __FUNCT__ "PCFactorSetShiftType"
63915743fcSHong Zhang /*@
64915743fcSHong Zhang    PCFactorSetShiftType - adds a particular type of quantity to the diagonal of the matrix during
65915743fcSHong Zhang      numerical factorization, thus the matrix has nonzero pivots
66915743fcSHong Zhang 
67ad4df100SBarry Smith    Logically Collective on PC
68915743fcSHong Zhang 
69915743fcSHong Zhang    Input Parameters:
70915743fcSHong Zhang +  pc - the preconditioner context
71915743fcSHong Zhang -  shifttype - type of shift; one of MAT_SHIFT_NONE, MAT_SHIFT_NONZERO,  MAT_SHIFT_POSITIVE_DEFINITE, MAT_SHIFT_INBLOCKS
72915743fcSHong Zhang 
73915743fcSHong Zhang    Options Database Key:
74915743fcSHong Zhang .  -pc_factor_shift_type <shifttype> - Sets shift type or PETSC_DECIDE for the default; use '-help' for a list of available types
75915743fcSHong Zhang 
76915743fcSHong Zhang    Level: intermediate
77915743fcSHong Zhang 
78915743fcSHong Zhang .keywords: PC, set, factorization,
79915743fcSHong Zhang 
80915743fcSHong Zhang .seealso: PCFactorSetZeroPivot(), PCFactorSetShiftAmount()
81915743fcSHong Zhang @*/
827087cfbeSBarry Smith PetscErrorCode  PCFactorSetShiftType(PC pc,MatFactorShiftType shifttype)
83d90ac83dSHong Zhang {
844ac538c5SBarry Smith   PetscErrorCode ierr;
85d90ac83dSHong Zhang 
86d90ac83dSHong Zhang   PetscFunctionBegin;
870700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
88c5eb9154SBarry Smith   PetscValidLogicalCollectiveEnum(pc,shifttype,2);
894ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetShiftType_C",(PC,MatFactorShiftType),(pc,shifttype));CHKERRQ(ierr);
90d90ac83dSHong Zhang   PetscFunctionReturn(0);
91d90ac83dSHong Zhang }
92d90ac83dSHong Zhang 
93d90ac83dSHong Zhang #undef __FUNCT__
94d90ac83dSHong Zhang #define __FUNCT__ "PCFactorSetShiftAmount"
95915743fcSHong Zhang /*@
96915743fcSHong Zhang    PCFactorSetShiftAmount - adds a quantity to the diagonal of the matrix during
97915743fcSHong Zhang      numerical factorization, thus the matrix has nonzero pivots
98915743fcSHong Zhang 
99ad4df100SBarry Smith    Logically Collective on PC
100915743fcSHong Zhang 
101915743fcSHong Zhang    Input Parameters:
102915743fcSHong Zhang +  pc - the preconditioner context
103915743fcSHong Zhang -  shiftamount - amount of shift
104915743fcSHong Zhang 
105915743fcSHong Zhang    Options Database Key:
106915743fcSHong Zhang .  -pc_factor_shift_amount <shiftamount> - Sets shift amount or PETSC_DECIDE for the default
107915743fcSHong Zhang 
108915743fcSHong Zhang    Level: intermediate
109915743fcSHong Zhang 
110915743fcSHong Zhang .keywords: PC, set, factorization,
111915743fcSHong Zhang 
112915743fcSHong Zhang .seealso: PCFactorSetZeroPivot(), PCFactorSetShiftType()
113915743fcSHong Zhang @*/
1147087cfbeSBarry Smith PetscErrorCode  PCFactorSetShiftAmount(PC pc,PetscReal shiftamount)
115d90ac83dSHong Zhang {
1164ac538c5SBarry Smith   PetscErrorCode ierr;
117d90ac83dSHong Zhang 
118d90ac83dSHong Zhang   PetscFunctionBegin;
1190700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
120c5eb9154SBarry Smith   PetscValidLogicalCollectiveReal(pc,shiftamount,2);
1214ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetShiftAmount_C",(PC,PetscReal),(pc,shiftamount));CHKERRQ(ierr);
122d90ac83dSHong Zhang   PetscFunctionReturn(0);
123d90ac83dSHong Zhang }
124d90ac83dSHong Zhang 
125d90ac83dSHong Zhang #undef __FUNCT__
126b7c853c4SBarry Smith #define __FUNCT__ "PCFactorSetDropTolerance"
12778fc6b22SHong Zhang /*
128b7c853c4SBarry Smith    PCFactorSetDropTolerance - The preconditioner will use an ILU
12978fc6b22SHong Zhang    based on a drop tolerance. (Under development)
13085317021SBarry Smith 
131ad4df100SBarry Smith    Logically Collective on PC
13285317021SBarry Smith 
13385317021SBarry Smith    Input Parameters:
13485317021SBarry Smith +  pc - the preconditioner context
13585317021SBarry Smith .  dt - the drop tolerance, try from 1.e-10 to .1
13685317021SBarry Smith .  dtcol - tolerance for column pivot, good values [0.1 to 0.01]
13785317021SBarry Smith -  maxrowcount - the max number of nonzeros allowed in a row, best value
13885317021SBarry Smith                  depends on the number of nonzeros in row of original matrix
13985317021SBarry Smith 
14085317021SBarry Smith    Options Database Key:
141b7c853c4SBarry Smith .  -pc_factor_drop_tolerance <dt,dtcol,maxrowcount> - Sets drop tolerance
14285317021SBarry Smith 
14385317021SBarry Smith    Level: intermediate
14485317021SBarry Smith 
14585317021SBarry Smith       There are NO default values for the 3 parameters, you must set them with reasonable values for your
14685317021SBarry Smith       matrix. We don't know how to compute reasonable values.
14785317021SBarry Smith 
14885317021SBarry Smith .keywords: PC, levels, reordering, factorization, incomplete, ILU
14978fc6b22SHong Zhang */
1507087cfbeSBarry Smith PetscErrorCode  PCFactorSetDropTolerance(PC pc,PetscReal dt,PetscReal dtcol,PetscInt maxrowcount)
15185317021SBarry Smith {
1524ac538c5SBarry Smith   PetscErrorCode ierr;
15385317021SBarry Smith 
15485317021SBarry Smith   PetscFunctionBegin;
1550700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
156c5eb9154SBarry Smith   PetscValidLogicalCollectiveReal(pc,dtcol,2);
157c5eb9154SBarry Smith   PetscValidLogicalCollectiveInt(pc,maxrowcount,3);
1584ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetDropTolerance_C",(PC,PetscReal,PetscReal,PetscInt),(pc,dt,dtcol,maxrowcount));CHKERRQ(ierr);
15985317021SBarry Smith   PetscFunctionReturn(0);
16085317021SBarry Smith }
16185317021SBarry Smith 
16285317021SBarry Smith #undef __FUNCT__
163*c7f610a1SBarry Smith #define __FUNCT__ "PCFactorGetZeroPivot"
164*c7f610a1SBarry Smith /*@
165*c7f610a1SBarry Smith    PCFactorGetZeroPivot - Gets the tolerance used to define a zero privot
166*c7f610a1SBarry Smith 
167*c7f610a1SBarry Smith    Not Collective
168*c7f610a1SBarry Smith 
169*c7f610a1SBarry Smith    Input Parameters:
170*c7f610a1SBarry Smith .  pc - the preconditioner context
171*c7f610a1SBarry Smith 
172*c7f610a1SBarry Smith    Output Parameter:
173*c7f610a1SBarry Smith .  pivot - the tolerance
174*c7f610a1SBarry Smith 
175*c7f610a1SBarry Smith    Level: intermediate
176*c7f610a1SBarry Smith 
177*c7f610a1SBarry Smith 
178*c7f610a1SBarry Smith .seealso: PCFactorSetZeroPivot()
179*c7f610a1SBarry Smith @*/
180*c7f610a1SBarry Smith PetscErrorCode  PCFactorGetZeroPivot(PC pc,PetscReal *pivot)
181*c7f610a1SBarry Smith {
182*c7f610a1SBarry Smith   PetscErrorCode ierr;
183*c7f610a1SBarry Smith 
184*c7f610a1SBarry Smith   PetscFunctionBegin;
185*c7f610a1SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
186*c7f610a1SBarry Smith   ierr = PetscUseMethod(pc,"PCFactorGetZeroPivot_C",(PC,PetscReal*),(pc,pivot));CHKERRQ(ierr);
187*c7f610a1SBarry Smith   PetscFunctionReturn(0);
188*c7f610a1SBarry Smith }
189*c7f610a1SBarry Smith 
190*c7f610a1SBarry Smith #undef __FUNCT__
191*c7f610a1SBarry Smith #define __FUNCT__ "PCFactorGetShiftAmount"
192*c7f610a1SBarry Smith /*@
193*c7f610a1SBarry Smith    PCFactorGetShiftAmount - Gets the tolerance used to define a zero privot
194*c7f610a1SBarry Smith 
195*c7f610a1SBarry Smith    Not Collective
196*c7f610a1SBarry Smith 
197*c7f610a1SBarry Smith    Input Parameters:
198*c7f610a1SBarry Smith .  pc - the preconditioner context
199*c7f610a1SBarry Smith 
200*c7f610a1SBarry Smith    Output Parameter:
201*c7f610a1SBarry Smith .  shift - how much to shift the diagonal entry
202*c7f610a1SBarry Smith 
203*c7f610a1SBarry Smith    Level: intermediate
204*c7f610a1SBarry Smith 
205*c7f610a1SBarry Smith 
206*c7f610a1SBarry Smith .seealso: PCFactorSetShiftAmount(), PCFactorSetShiftType(), PCFactorGetShiftType()
207*c7f610a1SBarry Smith @*/
208*c7f610a1SBarry Smith PetscErrorCode  PCFactorGetShiftAmount(PC pc,PetscReal *shift)
209*c7f610a1SBarry Smith {
210*c7f610a1SBarry Smith   PetscErrorCode ierr;
211*c7f610a1SBarry Smith 
212*c7f610a1SBarry Smith   PetscFunctionBegin;
213*c7f610a1SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
214*c7f610a1SBarry Smith   ierr = PetscUseMethod(pc,"PCFactorGetShiftAmount_C",(PC,PetscReal*),(pc,shift));CHKERRQ(ierr);
215*c7f610a1SBarry Smith   PetscFunctionReturn(0);
216*c7f610a1SBarry Smith }
217*c7f610a1SBarry Smith 
218*c7f610a1SBarry Smith #undef __FUNCT__
219*c7f610a1SBarry Smith #define __FUNCT__ "PCFactorGetShiftType"
220*c7f610a1SBarry Smith /*@
221*c7f610a1SBarry Smith    PCFactorGetShiftType - Gets the type of shift, if any, done when a zero pivot is detected
222*c7f610a1SBarry Smith 
223*c7f610a1SBarry Smith    Not Collective
224*c7f610a1SBarry Smith 
225*c7f610a1SBarry Smith    Input Parameters:
226*c7f610a1SBarry Smith .  pc - the preconditioner context
227*c7f610a1SBarry Smith 
228*c7f610a1SBarry Smith    Output Parameter:
229*c7f610a1SBarry Smith .  type - one of MAT_SHIFT_NONE, MAT_SHIFT_NONZERO,  MAT_SHIFT_POSITIVE_DEFINITE, or MAT_SHIFT_INBLOCKS
230*c7f610a1SBarry Smith 
231*c7f610a1SBarry Smith    Level: intermediate
232*c7f610a1SBarry Smith 
233*c7f610a1SBarry Smith 
234*c7f610a1SBarry Smith .seealso: PCFactorSetShiftType(), MatFactorShiftType, PCFactorSetShiftAmount(), PCFactorGetShiftAmount()
235*c7f610a1SBarry Smith @*/
236*c7f610a1SBarry Smith PetscErrorCode  PCFactorGetShiftType(PC pc,MatFactorShiftType *type)
237*c7f610a1SBarry Smith {
238*c7f610a1SBarry Smith   PetscErrorCode ierr;
239*c7f610a1SBarry Smith 
240*c7f610a1SBarry Smith   PetscFunctionBegin;
241*c7f610a1SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
242*c7f610a1SBarry Smith   ierr = PetscUseMethod(pc,"PCFactorGetShiftType_C",(PC,MatFactorShiftType*),(pc,type));CHKERRQ(ierr);
243*c7f610a1SBarry Smith   PetscFunctionReturn(0);
244*c7f610a1SBarry Smith }
245*c7f610a1SBarry Smith 
246*c7f610a1SBarry Smith #undef __FUNCT__
2472591b318SToby Isaac #define __FUNCT__ "PCFactorGetLevels"
2482591b318SToby Isaac /*@
2492591b318SToby Isaac    PCFactorGetLevels - Gets the number of levels of fill to use.
2502591b318SToby Isaac 
2512591b318SToby Isaac    Logically Collective on PC
2522591b318SToby Isaac 
2532591b318SToby Isaac    Input Parameters:
2542591b318SToby Isaac .  pc - the preconditioner context
2552591b318SToby Isaac 
2562591b318SToby Isaac    Output Parameter:
2572591b318SToby Isaac .  levels - number of levels of fill
2582591b318SToby Isaac 
2592591b318SToby Isaac    Level: intermediate
2602591b318SToby Isaac 
2612591b318SToby Isaac .keywords: PC, levels, fill, factorization, incomplete, ILU
2622591b318SToby Isaac @*/
2632591b318SToby Isaac PetscErrorCode  PCFactorGetLevels(PC pc,PetscInt *levels)
2642591b318SToby Isaac {
2652591b318SToby Isaac   PetscErrorCode ierr;
2662591b318SToby Isaac 
2672591b318SToby Isaac   PetscFunctionBegin;
2682591b318SToby Isaac   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
269c60c7ad4SBarry Smith   ierr = PetscUseMethod(pc,"PCFactorGetLevels_C",(PC,PetscInt*),(pc,levels));CHKERRQ(ierr);
2702591b318SToby Isaac   PetscFunctionReturn(0);
2712591b318SToby Isaac }
2722591b318SToby Isaac 
2732591b318SToby Isaac #undef __FUNCT__
27485317021SBarry Smith #define __FUNCT__ "PCFactorSetLevels"
27585317021SBarry Smith /*@
27685317021SBarry Smith    PCFactorSetLevels - Sets the number of levels of fill to use.
27785317021SBarry Smith 
278ad4df100SBarry Smith    Logically Collective on PC
27985317021SBarry Smith 
28085317021SBarry Smith    Input Parameters:
28185317021SBarry Smith +  pc - the preconditioner context
28285317021SBarry Smith -  levels - number of levels of fill
28385317021SBarry Smith 
28485317021SBarry Smith    Options Database Key:
28585317021SBarry Smith .  -pc_factor_levels <levels> - Sets fill level
28685317021SBarry Smith 
28785317021SBarry Smith    Level: intermediate
28885317021SBarry Smith 
28985317021SBarry Smith .keywords: PC, levels, fill, factorization, incomplete, ILU
29085317021SBarry Smith @*/
2917087cfbeSBarry Smith PetscErrorCode  PCFactorSetLevels(PC pc,PetscInt levels)
29285317021SBarry Smith {
2934ac538c5SBarry Smith   PetscErrorCode ierr;
29485317021SBarry Smith 
29585317021SBarry Smith   PetscFunctionBegin;
2960700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
297ce94432eSBarry Smith   if (levels < 0) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_OUTOFRANGE,"negative levels");
298c5eb9154SBarry Smith   PetscValidLogicalCollectiveInt(pc,levels,2);
2994ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetLevels_C",(PC,PetscInt),(pc,levels));CHKERRQ(ierr);
30085317021SBarry Smith   PetscFunctionReturn(0);
30185317021SBarry Smith }
30285317021SBarry Smith 
30385317021SBarry Smith #undef __FUNCT__
30485317021SBarry Smith #define __FUNCT__ "PCFactorSetAllowDiagonalFill"
30585317021SBarry Smith /*@
30685317021SBarry Smith    PCFactorSetAllowDiagonalFill - Causes all diagonal matrix entries to be
30785317021SBarry Smith    treated as level 0 fill even if there is no non-zero location.
30885317021SBarry Smith 
309ad4df100SBarry Smith    Logically Collective on PC
31085317021SBarry Smith 
31185317021SBarry Smith    Input Parameters:
31285317021SBarry Smith +  pc - the preconditioner context
31392e9c092SBarry Smith -  flg - PETSC_TRUE to turn on, PETSC_FALSE to turn off
31485317021SBarry Smith 
31585317021SBarry Smith    Options Database Key:
31685317021SBarry Smith .  -pc_factor_diagonal_fill
31785317021SBarry Smith 
31885317021SBarry Smith    Notes:
31985317021SBarry Smith    Does not apply with 0 fill.
32085317021SBarry Smith 
32185317021SBarry Smith    Level: intermediate
32285317021SBarry Smith 
32385317021SBarry Smith .keywords: PC, levels, fill, factorization, incomplete, ILU
32492e9c092SBarry Smith 
32592e9c092SBarry Smith .seealso: PCFactorGetAllowDiagonalFill()
32692e9c092SBarry Smith 
32785317021SBarry Smith @*/
32892e9c092SBarry Smith PetscErrorCode  PCFactorSetAllowDiagonalFill(PC pc,PetscBool flg)
32985317021SBarry Smith {
3304ac538c5SBarry Smith   PetscErrorCode ierr;
33185317021SBarry Smith 
33285317021SBarry Smith   PetscFunctionBegin;
3330700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
33492e9c092SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetAllowDiagonalFill_C",(PC,PetscBool),(pc,flg));CHKERRQ(ierr);
33592e9c092SBarry Smith   PetscFunctionReturn(0);
33692e9c092SBarry Smith }
33792e9c092SBarry Smith 
33892e9c092SBarry Smith #undef __FUNCT__
33992e9c092SBarry Smith #define __FUNCT__ "PCFactorGetAllowDiagonalFill"
34092e9c092SBarry Smith /*@
34192e9c092SBarry Smith    PCFactorGetAllowDiagonalFill - Determines if all diagonal matrix entries are
34292e9c092SBarry Smith        treated as level 0 fill even if there is no non-zero location.
34392e9c092SBarry Smith 
34492e9c092SBarry Smith    Logically Collective on PC
34592e9c092SBarry Smith 
34692e9c092SBarry Smith    Input Parameter:
34792e9c092SBarry Smith .  pc - the preconditioner context
34892e9c092SBarry Smith 
34992e9c092SBarry Smith    Output Parameter:
35092e9c092SBarry Smith .   flg - PETSC_TRUE to turn on, PETSC_FALSE to turn off
35192e9c092SBarry Smith 
35292e9c092SBarry Smith    Options Database Key:
35392e9c092SBarry Smith .  -pc_factor_diagonal_fill
35492e9c092SBarry Smith 
35592e9c092SBarry Smith    Notes:
35692e9c092SBarry Smith    Does not apply with 0 fill.
35792e9c092SBarry Smith 
35892e9c092SBarry Smith    Level: intermediate
35992e9c092SBarry Smith 
36092e9c092SBarry Smith .keywords: PC, levels, fill, factorization, incomplete, ILU
36192e9c092SBarry Smith 
36292e9c092SBarry Smith .seealso: PCFactorSetAllowDiagonalFill()
36392e9c092SBarry Smith 
36492e9c092SBarry Smith @*/
36592e9c092SBarry Smith PetscErrorCode  PCFactorGetAllowDiagonalFill(PC pc,PetscBool *flg)
36692e9c092SBarry Smith {
36792e9c092SBarry Smith   PetscErrorCode ierr;
36892e9c092SBarry Smith 
36992e9c092SBarry Smith   PetscFunctionBegin;
37092e9c092SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
371c60c7ad4SBarry Smith   ierr = PetscUseMethod(pc,"PCFactorGetAllowDiagonalFill_C",(PC,PetscBool*),(pc,flg));CHKERRQ(ierr);
37285317021SBarry Smith   PetscFunctionReturn(0);
37385317021SBarry Smith }
37485317021SBarry Smith 
37585317021SBarry Smith #undef __FUNCT__
37685317021SBarry Smith #define __FUNCT__ "PCFactorReorderForNonzeroDiagonal"
37785317021SBarry Smith /*@
37885317021SBarry Smith    PCFactorReorderForNonzeroDiagonal - reorders rows/columns of matrix to remove zeros from diagonal
37985317021SBarry Smith 
380ad4df100SBarry Smith    Logically Collective on PC
38185317021SBarry Smith 
38285317021SBarry Smith    Input Parameters:
38385317021SBarry Smith +  pc - the preconditioner context
38485317021SBarry Smith -  tol - diagonal entries smaller than this in absolute value are considered zero
38585317021SBarry Smith 
38685317021SBarry Smith    Options Database Key:
38792e9c092SBarry Smith .  -pc_factor_nonzeros_along_diagonal <tol>
38885317021SBarry Smith 
38985317021SBarry Smith    Level: intermediate
39085317021SBarry Smith 
39185317021SBarry Smith .keywords: PC, set, factorization, direct, fill
39285317021SBarry Smith 
39385317021SBarry Smith .seealso: PCFactorSetFill(), PCFactorSetShiftNonzero(), PCFactorSetZeroPivot(), MatReorderForNonzeroDiagonal()
39485317021SBarry Smith @*/
3957087cfbeSBarry Smith PetscErrorCode  PCFactorReorderForNonzeroDiagonal(PC pc,PetscReal rtol)
39685317021SBarry Smith {
3974ac538c5SBarry Smith   PetscErrorCode ierr;
39885317021SBarry Smith 
39985317021SBarry Smith   PetscFunctionBegin;
4000700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
401c5eb9154SBarry Smith   PetscValidLogicalCollectiveReal(pc,rtol,2);
4024ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorReorderForNonzeroDiagonal_C",(PC,PetscReal),(pc,rtol));CHKERRQ(ierr);
40385317021SBarry Smith   PetscFunctionReturn(0);
40485317021SBarry Smith }
40585317021SBarry Smith 
40685317021SBarry Smith #undef __FUNCT__
40785317021SBarry Smith #define __FUNCT__ "PCFactorSetMatSolverPackage"
408bf6011e8SBarry Smith /*@C
40985317021SBarry Smith    PCFactorSetMatSolverPackage - sets the software that is used to perform the factorization
41085317021SBarry Smith 
411ad4df100SBarry Smith    Logically Collective on PC
41285317021SBarry Smith 
41385317021SBarry Smith    Input Parameters:
41485317021SBarry Smith +  pc - the preconditioner context
415f60c3dc2SHong Zhang -  stype - for example, superlu, superlu_dist
41685317021SBarry Smith 
41785317021SBarry Smith    Options Database Key:
418f60c3dc2SHong Zhang .  -pc_factor_mat_solver_package <stype> - petsc, superlu, superlu_dist, mumps, cusparse
41985317021SBarry Smith 
42085317021SBarry Smith    Level: intermediate
42185317021SBarry Smith 
42285317021SBarry Smith    Note:
42385317021SBarry Smith      By default this will use the PETSc factorization if it exists
42485317021SBarry Smith 
42585317021SBarry Smith 
42685317021SBarry Smith .keywords: PC, set, factorization, direct, fill
42785317021SBarry Smith 
4287112b564SBarry Smith .seealso: MatGetFactor(), MatSolverPackage, PCFactorGetMatSolverPackage()
42985317021SBarry Smith 
43085317021SBarry Smith @*/
4317087cfbeSBarry Smith PetscErrorCode  PCFactorSetMatSolverPackage(PC pc,const MatSolverPackage stype)
43285317021SBarry Smith {
4334ac538c5SBarry Smith   PetscErrorCode ierr;
43485317021SBarry Smith 
43585317021SBarry Smith   PetscFunctionBegin;
4360700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
4374ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetMatSolverPackage_C",(PC,const MatSolverPackage),(pc,stype));CHKERRQ(ierr);
43885317021SBarry Smith   PetscFunctionReturn(0);
43985317021SBarry Smith }
44085317021SBarry Smith 
44185317021SBarry Smith #undef __FUNCT__
4427112b564SBarry Smith #define __FUNCT__ "PCFactorGetMatSolverPackage"
443bf6011e8SBarry Smith /*@C
4447112b564SBarry Smith    PCFactorGetMatSolverPackage - gets the software that is used to perform the factorization
4457112b564SBarry Smith 
446c5eb9154SBarry Smith    Not Collective
4477112b564SBarry Smith 
4487112b564SBarry Smith    Input Parameter:
4497112b564SBarry Smith .  pc - the preconditioner context
4507112b564SBarry Smith 
4517112b564SBarry Smith    Output Parameter:
4520298fd71SBarry Smith .   stype - for example, superlu, superlu_dist (NULL if the PC does not have a solver package)
4537112b564SBarry Smith 
4547112b564SBarry Smith    Level: intermediate
4557112b564SBarry Smith 
4567112b564SBarry Smith 
4577112b564SBarry Smith .keywords: PC, set, factorization, direct, fill
4587112b564SBarry Smith 
4597112b564SBarry Smith .seealso: MatGetFactor(), MatSolverPackage, PCFactorGetMatSolverPackage()
4607112b564SBarry Smith 
4617112b564SBarry Smith @*/
4627087cfbeSBarry Smith PetscErrorCode  PCFactorGetMatSolverPackage(PC pc,const MatSolverPackage *stype)
4637112b564SBarry Smith {
4648b5c83b4SJed Brown   PetscErrorCode ierr,(*f)(PC,const MatSolverPackage*);
4657112b564SBarry Smith 
4667112b564SBarry Smith   PetscFunctionBegin;
4670700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
4680005d66cSJed Brown   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCFactorGetMatSolverPackage_C",&f);CHKERRQ(ierr);
4698b5c83b4SJed Brown   if (f) {
4708b5c83b4SJed Brown     ierr = (*f)(pc,stype);CHKERRQ(ierr);
4718b5c83b4SJed Brown   } else {
4720298fd71SBarry Smith     *stype = NULL;
4738b5c83b4SJed Brown   }
4747112b564SBarry Smith   PetscFunctionReturn(0);
4757112b564SBarry Smith }
4767112b564SBarry Smith 
4777112b564SBarry Smith #undef __FUNCT__
47885317021SBarry Smith #define __FUNCT__ "PCFactorSetFill"
47985317021SBarry Smith /*@
48085317021SBarry Smith    PCFactorSetFill - Indicate the amount of fill you expect in the factored matrix,
48185317021SBarry Smith    fill = number nonzeros in factor/number nonzeros in original matrix.
48285317021SBarry Smith 
483c5eb9154SBarry Smith    Not Collective, each process can expect a different amount of fill
48485317021SBarry Smith 
48585317021SBarry Smith    Input Parameters:
48685317021SBarry Smith +  pc - the preconditioner context
48785317021SBarry Smith -  fill - amount of expected fill
48885317021SBarry Smith 
48985317021SBarry Smith    Options Database Key:
49085317021SBarry Smith .  -pc_factor_fill <fill> - Sets fill amount
49185317021SBarry Smith 
49285317021SBarry Smith    Level: intermediate
49385317021SBarry Smith 
49485317021SBarry Smith    Note:
49585317021SBarry Smith    For sparse matrix factorizations it is difficult to predict how much
49685317021SBarry Smith    fill to expect. By running with the option -info PETSc will print the
49785317021SBarry Smith    actual amount of fill used; allowing you to set the value accurately for
49885317021SBarry Smith    future runs. Default PETSc uses a value of 5.0
49985317021SBarry Smith 
50001a79839SBarry Smith    This parameter has NOTHING to do with the levels-of-fill of ILU(). That is set with PCFactorSetLevels() or -pc_factor_levels.
50101a79839SBarry Smith 
50201a79839SBarry Smith 
50385317021SBarry Smith .keywords: PC, set, factorization, direct, fill
50485317021SBarry Smith 
50585317021SBarry Smith @*/
5067087cfbeSBarry Smith PetscErrorCode  PCFactorSetFill(PC pc,PetscReal fill)
50785317021SBarry Smith {
5084ac538c5SBarry Smith   PetscErrorCode ierr;
50985317021SBarry Smith 
51085317021SBarry Smith   PetscFunctionBegin;
5110700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
512ce94432eSBarry Smith   if (fill < 1.0) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_OUTOFRANGE,"Fill factor cannot be less then 1.0");
5134ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetFill_C",(PC,PetscReal),(pc,fill));CHKERRQ(ierr);
51485317021SBarry Smith   PetscFunctionReturn(0);
51585317021SBarry Smith }
51685317021SBarry Smith 
51785317021SBarry Smith #undef __FUNCT__
51885317021SBarry Smith #define __FUNCT__ "PCFactorSetUseInPlace"
51985317021SBarry Smith /*@
52085317021SBarry Smith    PCFactorSetUseInPlace - Tells the system to do an in-place factorization.
52185317021SBarry Smith    For dense matrices, this enables the solution of much larger problems.
52285317021SBarry Smith    For sparse matrices the factorization cannot be done truly in-place
52385317021SBarry Smith    so this does not save memory during the factorization, but after the matrix
52485317021SBarry Smith    is factored, the original unfactored matrix is freed, thus recovering that
52585317021SBarry Smith    space.
52685317021SBarry Smith 
527ad4df100SBarry Smith    Logically Collective on PC
52885317021SBarry Smith 
52985317021SBarry Smith    Input Parameters:
5308e37d05fSBarry Smith +  pc - the preconditioner context
5318e37d05fSBarry Smith -  flg - PETSC_TRUE to enable, PETSC_FALSE to disable
53285317021SBarry Smith 
53385317021SBarry Smith    Options Database Key:
5348e37d05fSBarry Smith .  -pc_factor_in_place <true,false>- Activate/deactivate in-place factorization
53585317021SBarry Smith 
53685317021SBarry Smith    Notes:
53785317021SBarry Smith    PCFactorSetUseInplace() can only be used with the KSP method KSPPREONLY or when
53885317021SBarry Smith    a different matrix is provided for the multiply and the preconditioner in
53985317021SBarry Smith    a call to KSPSetOperators().
54085317021SBarry Smith    This is because the Krylov space methods require an application of the
54185317021SBarry Smith    matrix multiplication, which is not possible here because the matrix has
54285317021SBarry Smith    been factored in-place, replacing the original matrix.
54385317021SBarry Smith 
54485317021SBarry Smith    Level: intermediate
54585317021SBarry Smith 
54685317021SBarry Smith .keywords: PC, set, factorization, direct, inplace, in-place, LU
54785317021SBarry Smith 
5488e37d05fSBarry Smith .seealso: PCFactorGetUseInPlace()
54985317021SBarry Smith @*/
5508e37d05fSBarry Smith PetscErrorCode  PCFactorSetUseInPlace(PC pc,PetscBool flg)
55185317021SBarry Smith {
5524ac538c5SBarry Smith   PetscErrorCode ierr;
55385317021SBarry Smith 
55485317021SBarry Smith   PetscFunctionBegin;
5550700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
5568e37d05fSBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetUseInPlace_C",(PC,PetscBool),(pc,flg));CHKERRQ(ierr);
5578e37d05fSBarry Smith   PetscFunctionReturn(0);
5588e37d05fSBarry Smith }
5598e37d05fSBarry Smith 
5608e37d05fSBarry Smith #undef __FUNCT__
5618e37d05fSBarry Smith #define __FUNCT__ "PCFactorGetUseInPlace"
5628e37d05fSBarry Smith /*@
5638e37d05fSBarry Smith    PCFactorGetUseInPlace - Determines if an in-place factorization is being used.
5648e37d05fSBarry Smith 
5658e37d05fSBarry Smith    Logically Collective on PC
5668e37d05fSBarry Smith 
5678e37d05fSBarry Smith    Input Parameter:
5688e37d05fSBarry Smith .  pc - the preconditioner context
5698e37d05fSBarry Smith 
5708e37d05fSBarry Smith    Output Parameter:
5718e37d05fSBarry Smith .  flg - PETSC_TRUE to enable, PETSC_FALSE to disable
5728e37d05fSBarry Smith 
5738e37d05fSBarry Smith    Level: intermediate
5748e37d05fSBarry Smith 
5758e37d05fSBarry Smith .keywords: PC, set, factorization, direct, inplace, in-place, LU
5768e37d05fSBarry Smith 
5778e37d05fSBarry Smith .seealso: PCFactorSetUseInPlace()
5788e37d05fSBarry Smith @*/
5798e37d05fSBarry Smith PetscErrorCode  PCFactorGetUseInPlace(PC pc,PetscBool *flg)
5808e37d05fSBarry Smith {
5818e37d05fSBarry Smith   PetscErrorCode ierr;
5828e37d05fSBarry Smith 
5838e37d05fSBarry Smith   PetscFunctionBegin;
5848e37d05fSBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
585c60c7ad4SBarry Smith   ierr = PetscUseMethod(pc,"PCFactorGetUseInPlace_C",(PC,PetscBool*),(pc,flg));CHKERRQ(ierr);
58685317021SBarry Smith   PetscFunctionReturn(0);
58785317021SBarry Smith }
58885317021SBarry Smith 
58985317021SBarry Smith #undef __FUNCT__
59085317021SBarry Smith #define __FUNCT__ "PCFactorSetMatOrderingType"
59185317021SBarry Smith /*@C
59285317021SBarry Smith     PCFactorSetMatOrderingType - Sets the ordering routine (to reduce fill) to
59385317021SBarry Smith     be used in the LU factorization.
59485317021SBarry Smith 
595ad4df100SBarry Smith     Logically Collective on PC
59685317021SBarry Smith 
59785317021SBarry Smith     Input Parameters:
59885317021SBarry Smith +   pc - the preconditioner context
5992692d6eeSBarry Smith -   ordering - the matrix ordering name, for example, MATORDERINGND or MATORDERINGRCM
60085317021SBarry Smith 
60185317021SBarry Smith     Options Database Key:
60285317021SBarry Smith .   -pc_factor_mat_ordering_type <nd,rcm,...> - Sets ordering routine
60385317021SBarry Smith 
60485317021SBarry Smith     Level: intermediate
60585317021SBarry Smith 
60685317021SBarry Smith     Notes: nested dissection is used by default
60785317021SBarry Smith 
60885317021SBarry Smith     For Cholesky and ICC and the SBAIJ format reorderings are not available,
60985317021SBarry Smith     since only the upper triangular part of the matrix is stored. You can use the
61085317021SBarry Smith     SeqAIJ format in this case to get reorderings.
61185317021SBarry Smith 
61285317021SBarry Smith @*/
61319fd82e9SBarry Smith PetscErrorCode  PCFactorSetMatOrderingType(PC pc,MatOrderingType ordering)
61485317021SBarry Smith {
6154ac538c5SBarry Smith   PetscErrorCode ierr;
61685317021SBarry Smith 
61785317021SBarry Smith   PetscFunctionBegin;
618c5eb9154SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
61919fd82e9SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetMatOrderingType_C",(PC,MatOrderingType),(pc,ordering));CHKERRQ(ierr);
62085317021SBarry Smith   PetscFunctionReturn(0);
62185317021SBarry Smith }
62285317021SBarry Smith 
62385317021SBarry Smith #undef __FUNCT__
6248ff23777SHong Zhang #define __FUNCT__ "PCFactorSetColumnPivot"
62585317021SBarry Smith /*@
6268ff23777SHong Zhang     PCFactorSetColumnPivot - Determines when column pivoting is done during matrix factorization.
62785317021SBarry Smith       For PETSc dense matrices column pivoting is always done, for PETSc sparse matrices
628e3c5b3baSBarry Smith       it is never done. For the MATLAB and SuperLU factorization this is used.
62985317021SBarry Smith 
630ad4df100SBarry Smith     Logically Collective on PC
63185317021SBarry Smith 
63285317021SBarry Smith     Input Parameters:
63385317021SBarry Smith +   pc - the preconditioner context
63485317021SBarry Smith -   dtcol - 0.0 implies no pivoting, 1.0 complete pivoting (slower, requires more memory but more stable)
63585317021SBarry Smith 
63685317021SBarry Smith     Options Database Key:
63785317021SBarry Smith .   -pc_factor_pivoting <dtcol>
63885317021SBarry Smith 
63985317021SBarry Smith     Level: intermediate
64085317021SBarry Smith 
64185317021SBarry Smith .seealso: PCILUSetMatOrdering(), PCFactorSetPivotInBlocks()
64285317021SBarry Smith @*/
6437087cfbeSBarry Smith PetscErrorCode  PCFactorSetColumnPivot(PC pc,PetscReal dtcol)
64485317021SBarry Smith {
6454ac538c5SBarry Smith   PetscErrorCode ierr;
64685317021SBarry Smith 
64785317021SBarry Smith   PetscFunctionBegin;
648c5eb9154SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
649c5eb9154SBarry Smith   PetscValidLogicalCollectiveReal(pc,dtcol,2);
6504ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetColumnPivot_C",(PC,PetscReal),(pc,dtcol));CHKERRQ(ierr);
65185317021SBarry Smith   PetscFunctionReturn(0);
65285317021SBarry Smith }
65385317021SBarry Smith 
65485317021SBarry Smith #undef __FUNCT__
65585317021SBarry Smith #define __FUNCT__ "PCFactorSetPivotInBlocks"
65685317021SBarry Smith /*@
65785317021SBarry Smith     PCFactorSetPivotInBlocks - Determines if pivoting is done while factoring each block
65885317021SBarry Smith       with BAIJ or SBAIJ matrices
65985317021SBarry Smith 
660ad4df100SBarry Smith     Logically Collective on PC
66185317021SBarry Smith 
66285317021SBarry Smith     Input Parameters:
66385317021SBarry Smith +   pc - the preconditioner context
66485317021SBarry Smith -   pivot - PETSC_TRUE or PETSC_FALSE
66585317021SBarry Smith 
66685317021SBarry Smith     Options Database Key:
66785317021SBarry Smith .   -pc_factor_pivot_in_blocks <true,false>
66885317021SBarry Smith 
66985317021SBarry Smith     Level: intermediate
67085317021SBarry Smith 
6718ff23777SHong Zhang .seealso: PCILUSetMatOrdering(), PCFactorSetColumnPivot()
67285317021SBarry Smith @*/
6737087cfbeSBarry Smith PetscErrorCode  PCFactorSetPivotInBlocks(PC pc,PetscBool pivot)
67485317021SBarry Smith {
6754ac538c5SBarry Smith   PetscErrorCode ierr;
67685317021SBarry Smith 
67785317021SBarry Smith   PetscFunctionBegin;
678c5eb9154SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
679acfcf0e5SJed Brown   PetscValidLogicalCollectiveBool(pc,pivot,2);
6804ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetPivotInBlocks_C",(PC,PetscBool),(pc,pivot));CHKERRQ(ierr);
68185317021SBarry Smith   PetscFunctionReturn(0);
68285317021SBarry Smith }
68385317021SBarry Smith 
68485317021SBarry Smith #undef __FUNCT__
68585317021SBarry Smith #define __FUNCT__ "PCFactorSetReuseFill"
68685317021SBarry Smith /*@
68785317021SBarry Smith    PCFactorSetReuseFill - When matrices with same different nonzero structure are factored,
68885317021SBarry Smith    this causes later ones to use the fill ratio computed in the initial factorization.
68985317021SBarry Smith 
690ad4df100SBarry Smith    Logically Collective on PC
69185317021SBarry Smith 
69285317021SBarry Smith    Input Parameters:
69385317021SBarry Smith +  pc - the preconditioner context
69485317021SBarry Smith -  flag - PETSC_TRUE to reuse else PETSC_FALSE
69585317021SBarry Smith 
69685317021SBarry Smith    Options Database Key:
69785317021SBarry Smith .  -pc_factor_reuse_fill - Activates PCFactorSetReuseFill()
69885317021SBarry Smith 
69985317021SBarry Smith    Level: intermediate
70085317021SBarry Smith 
70185317021SBarry Smith .keywords: PC, levels, reordering, factorization, incomplete, Cholesky
70285317021SBarry Smith 
70385317021SBarry Smith .seealso: PCFactorSetReuseOrdering()
70485317021SBarry Smith @*/
7057087cfbeSBarry Smith PetscErrorCode  PCFactorSetReuseFill(PC pc,PetscBool flag)
70685317021SBarry Smith {
7074ac538c5SBarry Smith   PetscErrorCode ierr;
70885317021SBarry Smith 
70985317021SBarry Smith   PetscFunctionBegin;
7100700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,2);
711acfcf0e5SJed Brown   PetscValidLogicalCollectiveBool(pc,flag,2);
7124ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCFactorSetReuseFill_C",(PC,PetscBool),(pc,flag));CHKERRQ(ierr);
71385317021SBarry Smith   PetscFunctionReturn(0);
71485317021SBarry Smith }
715