1dba47a55SKris Buschelman 29b54502bSHong Zhang /* 39b54502bSHong Zhang Defines a ILU factorization preconditioner for any Mat implementation 49b54502bSHong Zhang */ 5c6db04a5SJed Brown #include <../src/ksp/pc/impls/factor/ilu/ilu.h> /*I "petscpc.h" I*/ 69b54502bSHong Zhang 77087cfbeSBarry Smith PetscErrorCode PCFactorReorderForNonzeroDiagonal_ILU(PC pc,PetscReal z) 89b54502bSHong Zhang { 99b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 109b54502bSHong Zhang 119b54502bSHong Zhang PetscFunctionBegin; 129b54502bSHong Zhang ilu->nonzerosalongdiagonal = PETSC_TRUE; 132fa5cd67SKarl Rupp if (z == PETSC_DECIDE) ilu->nonzerosalongdiagonaltol = 1.e-10; 142fa5cd67SKarl Rupp else ilu->nonzerosalongdiagonaltol = z; 159b54502bSHong Zhang PetscFunctionReturn(0); 169b54502bSHong Zhang } 179b54502bSHong Zhang 18574deadeSBarry Smith PetscErrorCode PCReset_ILU(PC pc) 199b54502bSHong Zhang { 209b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 219b54502bSHong Zhang PetscErrorCode ierr; 229b54502bSHong Zhang 239b54502bSHong Zhang PetscFunctionBegin; 243d1c1ea0SBarry Smith if (!ilu->hdr.inplace) {ierr = MatDestroy(&((PC_Factor*)ilu)->fact);CHKERRQ(ierr);} 256bf464f9SBarry Smith if (ilu->row && ilu->col && ilu->row != ilu->col) {ierr = ISDestroy(&ilu->row);CHKERRQ(ierr);} 26fcfd50ebSBarry Smith ierr = ISDestroy(&ilu->col);CHKERRQ(ierr); 279b54502bSHong Zhang PetscFunctionReturn(0); 289b54502bSHong Zhang } 299b54502bSHong Zhang 307087cfbeSBarry Smith PetscErrorCode PCFactorSetDropTolerance_ILU(PC pc,PetscReal dt,PetscReal dtcol,PetscInt dtcount) 319b54502bSHong Zhang { 32075768bcSBarry Smith PC_ILU *ilu = (PC_ILU*)pc->data; 339b54502bSHong Zhang 349b54502bSHong Zhang PetscFunctionBegin; 354c9036c7SBarry Smith if (pc->setupcalled && (((PC_Factor*)ilu)->info.dt != dt || ((PC_Factor*)ilu)->info.dtcol != dtcol || ((PC_Factor*)ilu)->info.dtcount != dtcount)) { 36ce94432eSBarry Smith SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Cannot change drop tolerance after using PC"); 379b54502bSHong Zhang } 38075768bcSBarry Smith ((PC_Factor*)ilu)->info.dt = dt; 39075768bcSBarry Smith ((PC_Factor*)ilu)->info.dtcol = dtcol; 40075768bcSBarry Smith ((PC_Factor*)ilu)->info.dtcount = dtcount; 414c9036c7SBarry Smith ((PC_Factor*)ilu)->info.usedt = 1.0; 429b54502bSHong Zhang PetscFunctionReturn(0); 439b54502bSHong Zhang } 449b54502bSHong Zhang 454416b707SBarry Smith static PetscErrorCode PCSetFromOptions_ILU(PetscOptionItems *PetscOptionsObject,PC pc) 469b54502bSHong Zhang { 479b54502bSHong Zhang PetscErrorCode ierr; 4878fc6b22SHong Zhang PetscInt itmp; 498afaa268SBarry Smith PetscBool flg,set; 509b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 519b54502bSHong Zhang PetscReal tol; 529b54502bSHong Zhang 539b54502bSHong Zhang PetscFunctionBegin; 54e55864a3SBarry Smith ierr = PetscOptionsHead(PetscOptionsObject,"ILU Options");CHKERRQ(ierr); 55e55864a3SBarry Smith ierr = PCSetFromOptions_Factor(PetscOptionsObject,pc);CHKERRQ(ierr); 568ff23777SHong Zhang 57075768bcSBarry Smith ierr = PetscOptionsInt("-pc_factor_levels","levels of fill","PCFactorSetLevels",(PetscInt)((PC_Factor*)ilu)->info.levels,&itmp,&flg);CHKERRQ(ierr); 58075768bcSBarry Smith if (flg) ((PC_Factor*)ilu)->info.levels = itmp; 592fa5cd67SKarl Rupp 608afaa268SBarry Smith ierr = PetscOptionsBool("-pc_factor_diagonal_fill","Allow fill into empty diagonal entry","PCFactorSetAllowDiagonalFill",((PC_Factor*)ilu)->info.diagonal_fill ? PETSC_TRUE : PETSC_FALSE,&flg,&set);CHKERRQ(ierr); 618afaa268SBarry Smith if (set) ((PC_Factor*)ilu)->info.diagonal_fill = (PetscReal) flg; 622401956bSBarry Smith ierr = PetscOptionsName("-pc_factor_nonzeros_along_diagonal","Reorder to remove zeros from diagonal","PCFactorReorderForNonzeroDiagonal",&flg);CHKERRQ(ierr); 639b54502bSHong Zhang if (flg) { 649b54502bSHong Zhang tol = PETSC_DECIDE; 652401956bSBarry Smith ierr = PetscOptionsReal("-pc_factor_nonzeros_along_diagonal","Reorder to remove zeros from diagonal","PCFactorReorderForNonzeroDiagonal",ilu->nonzerosalongdiagonaltol,&tol,0);CHKERRQ(ierr); 662401956bSBarry Smith ierr = PCFactorReorderForNonzeroDiagonal(pc,tol);CHKERRQ(ierr); 679b54502bSHong Zhang } 689b54502bSHong Zhang 699b54502bSHong Zhang ierr = PetscOptionsTail();CHKERRQ(ierr); 709b54502bSHong Zhang PetscFunctionReturn(0); 719b54502bSHong Zhang } 729b54502bSHong Zhang 739b54502bSHong Zhang static PetscErrorCode PCView_ILU(PC pc,PetscViewer viewer) 749b54502bSHong Zhang { 759b54502bSHong Zhang PetscErrorCode ierr; 769b54502bSHong Zhang 779b54502bSHong Zhang PetscFunctionBegin; 78914a5d51SHong Zhang ierr = PCView_Factor(pc,viewer);CHKERRQ(ierr); 799b54502bSHong Zhang PetscFunctionReturn(0); 809b54502bSHong Zhang } 819b54502bSHong Zhang 829b54502bSHong Zhang static PetscErrorCode PCSetUp_ILU(PC pc) 839b54502bSHong Zhang { 849b54502bSHong Zhang PetscErrorCode ierr; 859b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 86f3a39becSBarry Smith MatInfo info; 87ace3abfcSBarry Smith PetscBool flg; 88ea799195SBarry Smith MatSolverType stype; 8900e125f8SBarry Smith MatFactorError err; 909b54502bSHong Zhang 919b54502bSHong Zhang PetscFunctionBegin; 92c6e4fdc6SHong Zhang pc->failedreason = PC_NOERROR; 9392927226SBarry Smith /* ugly hack to change default, since it is not support by some matrix types */ 9492927226SBarry Smith if (((PC_Factor*)ilu)->info.shifttype == (PetscReal)MAT_SHIFT_NONZERO) { 9522d28d08SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)pc->pmat,MATSEQAIJ,&flg);CHKERRQ(ierr); 9692927226SBarry Smith if (!flg) { 9722d28d08SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)pc->pmat,MATMPIAIJ,&flg);CHKERRQ(ierr); 9892927226SBarry Smith if (!flg) { 9992927226SBarry Smith ((PC_Factor*)ilu)->info.shifttype = (PetscReal)MAT_SHIFT_INBLOCKS; 100955c1f14SBarry Smith PetscInfo(pc,"Changing shift type from NONZERO to INBLOCKS because block matrices do not support NONZERO\n");CHKERRQ(ierr); 10192927226SBarry Smith } 10292927226SBarry Smith } 10392927226SBarry Smith } 10492927226SBarry Smith 10584d44b13SHong Zhang ierr = MatSetErrorIfFailure(pc->pmat,pc->erroriffailure);CHKERRQ(ierr); 1063d1c1ea0SBarry Smith if (ilu->hdr.inplace) { 1079b54502bSHong Zhang if (!pc->setupcalled) { 1089b54502bSHong Zhang 1099b54502bSHong Zhang /* In-place factorization only makes sense with the natural ordering, 1109b54502bSHong Zhang so we only need to get the ordering once, even if nonzero structure changes */ 111075768bcSBarry Smith ierr = MatGetOrdering(pc->pmat,((PC_Factor*)ilu)->ordering,&ilu->row,&ilu->col);CHKERRQ(ierr); 1123bb1ff40SBarry Smith if (ilu->row) {ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilu->row);CHKERRQ(ierr);} 1133bb1ff40SBarry Smith if (ilu->col) {ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilu->col);CHKERRQ(ierr);} 1149b54502bSHong Zhang } 1159b54502bSHong Zhang 1169b54502bSHong Zhang /* In place ILU only makes sense with fill factor of 1.0 because 1179b54502bSHong Zhang cannot have levels of fill */ 118075768bcSBarry Smith ((PC_Factor*)ilu)->info.fill = 1.0; 11975567043SBarry Smith ((PC_Factor*)ilu)->info.diagonal_fill = 0.0; 1202fa5cd67SKarl Rupp 121365a8a9eSBarry Smith ierr = MatILUFactor(pc->pmat,ilu->row,ilu->col,&((PC_Factor*)ilu)->info);CHKERRQ(ierr);CHKERRQ(ierr); 12200e125f8SBarry Smith ierr = MatFactorGetError(pc->pmat,&err);CHKERRQ(ierr); 12300e125f8SBarry Smith if (err) { /* Factor() fails */ 12400e125f8SBarry Smith pc->failedreason = (PCFailedReason)err; 1256baea169SHong Zhang PetscFunctionReturn(0); 1266baea169SHong Zhang } 1276baea169SHong Zhang 128075768bcSBarry Smith ((PC_Factor*)ilu)->fact = pc->pmat; 129b33856dcSBarry Smith /* must update the pc record of the matrix state or the PC will attempt to run PCSetUp() yet again */ 130b33856dcSBarry Smith ierr = PetscObjectStateGet((PetscObject)pc->pmat,&pc->matstate);CHKERRQ(ierr); 1319b54502bSHong Zhang } else { 1329b54502bSHong Zhang if (!pc->setupcalled) { 1339b54502bSHong Zhang /* first time in so compute reordering and symbolic factorization */ 134075768bcSBarry Smith ierr = MatGetOrdering(pc->pmat,((PC_Factor*)ilu)->ordering,&ilu->row,&ilu->col);CHKERRQ(ierr); 1353bb1ff40SBarry Smith if (ilu->row) {ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilu->row);CHKERRQ(ierr);} 1363bb1ff40SBarry Smith if (ilu->col) {ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilu->col);CHKERRQ(ierr);} 1379b54502bSHong Zhang /* Remove zeros along diagonal? */ 1389b54502bSHong Zhang if (ilu->nonzerosalongdiagonal) { 1399b54502bSHong Zhang ierr = MatReorderForNonzeroDiagonal(pc->pmat,ilu->nonzerosalongdiagonaltol,ilu->row,ilu->col);CHKERRQ(ierr); 1409b54502bSHong Zhang } 14186daa42cSBarry Smith if (!((PC_Factor*)ilu)->fact) { 14211bfe483SHong Zhang ierr = MatGetFactor(pc->pmat,((PC_Factor*)ilu)->solvertype,MAT_FACTOR_ILU,&((PC_Factor*)ilu)->fact);CHKERRQ(ierr); 143a1f19f5aSHong Zhang } 144075768bcSBarry Smith ierr = MatILUFactorSymbolic(((PC_Factor*)ilu)->fact,pc->pmat,ilu->row,ilu->col,&((PC_Factor*)ilu)->info);CHKERRQ(ierr); 145075768bcSBarry Smith ierr = MatGetInfo(((PC_Factor*)ilu)->fact,MAT_LOCAL,&info);CHKERRQ(ierr); 1463d1c1ea0SBarry Smith ilu->hdr.actualfill = info.fill_ratio_needed; 1472fa5cd67SKarl Rupp 1483bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)((PC_Factor*)ilu)->fact);CHKERRQ(ierr); 1499b54502bSHong Zhang } else if (pc->flag != SAME_NONZERO_PATTERN) { 1503d1c1ea0SBarry Smith if (!ilu->hdr.reuseordering) { 1519b54502bSHong Zhang /* compute a new ordering for the ILU */ 152fcfd50ebSBarry Smith ierr = ISDestroy(&ilu->row);CHKERRQ(ierr); 153fcfd50ebSBarry Smith ierr = ISDestroy(&ilu->col);CHKERRQ(ierr); 154075768bcSBarry Smith ierr = MatGetOrdering(pc->pmat,((PC_Factor*)ilu)->ordering,&ilu->row,&ilu->col);CHKERRQ(ierr); 1553bb1ff40SBarry Smith if (ilu->row) {ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilu->row);CHKERRQ(ierr);} 1563bb1ff40SBarry Smith if (ilu->col) {ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilu->col);CHKERRQ(ierr);} 1579b54502bSHong Zhang /* Remove zeros along diagonal? */ 1589b54502bSHong Zhang if (ilu->nonzerosalongdiagonal) { 1599b54502bSHong Zhang ierr = MatReorderForNonzeroDiagonal(pc->pmat,ilu->nonzerosalongdiagonaltol,ilu->row,ilu->col);CHKERRQ(ierr); 1609b54502bSHong Zhang } 1619b54502bSHong Zhang } 1626bf464f9SBarry Smith ierr = MatDestroy(&((PC_Factor*)ilu)->fact);CHKERRQ(ierr); 16314798fb4SJed Brown ierr = MatGetFactor(pc->pmat,((PC_Factor*)ilu)->solvertype,MAT_FACTOR_ILU,&((PC_Factor*)ilu)->fact);CHKERRQ(ierr); 164075768bcSBarry Smith ierr = MatILUFactorSymbolic(((PC_Factor*)ilu)->fact,pc->pmat,ilu->row,ilu->col,&((PC_Factor*)ilu)->info);CHKERRQ(ierr); 165075768bcSBarry Smith ierr = MatGetInfo(((PC_Factor*)ilu)->fact,MAT_LOCAL,&info);CHKERRQ(ierr); 1663d1c1ea0SBarry Smith ilu->hdr.actualfill = info.fill_ratio_needed; 1672fa5cd67SKarl Rupp 1683bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)((PC_Factor*)ilu)->fact);CHKERRQ(ierr); 1699b54502bSHong Zhang } 17000e125f8SBarry Smith ierr = MatFactorGetError(((PC_Factor*)ilu)->fact,&err);CHKERRQ(ierr); 17100e125f8SBarry Smith if (err) { /* FactorSymbolic() fails */ 17200e125f8SBarry Smith pc->failedreason = (PCFailedReason)err; 1736baea169SHong Zhang PetscFunctionReturn(0); 1746baea169SHong Zhang } 1756baea169SHong Zhang 176075768bcSBarry Smith ierr = MatLUFactorNumeric(((PC_Factor*)ilu)->fact,pc->pmat,&((PC_Factor*)ilu)->info);CHKERRQ(ierr); 17700e125f8SBarry Smith ierr = MatFactorGetError(((PC_Factor*)ilu)->fact,&err);CHKERRQ(ierr); 17800e125f8SBarry Smith if (err) { /* FactorNumeric() fails */ 17900e125f8SBarry Smith pc->failedreason = (PCFailedReason)err; 1806baea169SHong Zhang } 1819b54502bSHong Zhang } 18200c67f3bSHong Zhang 1833ca39a21SBarry Smith ierr = PCFactorGetMatSolverType(pc,&stype);CHKERRQ(ierr); 18400c67f3bSHong Zhang if (!stype) { 185ea799195SBarry Smith MatSolverType solverpackage; 1863ca39a21SBarry Smith ierr = MatFactorGetSolverType(((PC_Factor*)ilu)->fact,&solverpackage);CHKERRQ(ierr); 1873ca39a21SBarry Smith ierr = PCFactorSetMatSolverType(pc,solverpackage);CHKERRQ(ierr); 18800c67f3bSHong Zhang } 1899b54502bSHong Zhang PetscFunctionReturn(0); 1909b54502bSHong Zhang } 1919b54502bSHong Zhang 1929b54502bSHong Zhang static PetscErrorCode PCDestroy_ILU(PC pc) 1939b54502bSHong Zhang { 1949b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 1959b54502bSHong Zhang PetscErrorCode ierr; 1969b54502bSHong Zhang 1979b54502bSHong Zhang PetscFunctionBegin; 198574deadeSBarry Smith ierr = PCReset_ILU(pc);CHKERRQ(ierr); 199503cfb0cSBarry Smith ierr = PetscFree(((PC_Factor*)ilu)->solvertype);CHKERRQ(ierr); 200503cfb0cSBarry Smith ierr = PetscFree(((PC_Factor*)ilu)->ordering);CHKERRQ(ierr); 201c31cb41cSBarry Smith ierr = PetscFree(pc->data);CHKERRQ(ierr); 2029b54502bSHong Zhang PetscFunctionReturn(0); 2039b54502bSHong Zhang } 2049b54502bSHong Zhang 2059b54502bSHong Zhang static PetscErrorCode PCApply_ILU(PC pc,Vec x,Vec y) 2069b54502bSHong Zhang { 2079b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 2089b54502bSHong Zhang PetscErrorCode ierr; 2099b54502bSHong Zhang 2109b54502bSHong Zhang PetscFunctionBegin; 211075768bcSBarry Smith ierr = MatSolve(((PC_Factor*)ilu)->fact,x,y);CHKERRQ(ierr); 2129b54502bSHong Zhang PetscFunctionReturn(0); 2139b54502bSHong Zhang } 2149b54502bSHong Zhang 2159b54502bSHong Zhang static PetscErrorCode PCApplyTranspose_ILU(PC pc,Vec x,Vec y) 2169b54502bSHong Zhang { 2179b54502bSHong Zhang PC_ILU *ilu = (PC_ILU*)pc->data; 2189b54502bSHong Zhang PetscErrorCode ierr; 2199b54502bSHong Zhang 2209b54502bSHong Zhang PetscFunctionBegin; 221075768bcSBarry Smith ierr = MatSolveTranspose(((PC_Factor*)ilu)->fact,x,y);CHKERRQ(ierr); 2229b54502bSHong Zhang PetscFunctionReturn(0); 2239b54502bSHong Zhang } 2249b54502bSHong Zhang 225f0b9ad6cSBarry Smith static PetscErrorCode PCApplySymmetricLeft_ILU(PC pc,Vec x,Vec y) 226f0b9ad6cSBarry Smith { 227f0b9ad6cSBarry Smith PetscErrorCode ierr; 228f0b9ad6cSBarry Smith PC_ILU *icc = (PC_ILU*)pc->data; 229f0b9ad6cSBarry Smith 230f0b9ad6cSBarry Smith PetscFunctionBegin; 231f0b9ad6cSBarry Smith ierr = MatForwardSolve(((PC_Factor*)icc)->fact,x,y);CHKERRQ(ierr); 232f0b9ad6cSBarry Smith PetscFunctionReturn(0); 233f0b9ad6cSBarry Smith } 234f0b9ad6cSBarry Smith 235f0b9ad6cSBarry Smith static PetscErrorCode PCApplySymmetricRight_ILU(PC pc,Vec x,Vec y) 236f0b9ad6cSBarry Smith { 237f0b9ad6cSBarry Smith PetscErrorCode ierr; 238f0b9ad6cSBarry Smith PC_ILU *icc = (PC_ILU*)pc->data; 239f0b9ad6cSBarry Smith 240f0b9ad6cSBarry Smith PetscFunctionBegin; 241f0b9ad6cSBarry Smith ierr = MatBackwardSolve(((PC_Factor*)icc)->fact,x,y);CHKERRQ(ierr); 242f0b9ad6cSBarry Smith PetscFunctionReturn(0); 243f0b9ad6cSBarry Smith } 244f0b9ad6cSBarry Smith 2459b54502bSHong Zhang /*MC 2469b54502bSHong Zhang PCILU - Incomplete factorization preconditioners. 2479b54502bSHong Zhang 2489b54502bSHong Zhang Options Database Keys: 2492401956bSBarry Smith + -pc_factor_levels <k> - number of levels of fill for ILU(k) 2502401956bSBarry Smith . -pc_factor_in_place - only for ILU(0) with natural ordering, reuses the space of the matrix for 2519b54502bSHong Zhang its factorization (overwrites original matrix) 2522401956bSBarry Smith . -pc_factor_diagonal_fill - fill in a zero diagonal even if levels of fill indicate it wouldn't be fill 2532401956bSBarry Smith . -pc_factor_reuse_ordering - reuse ordering of factorized matrix from previous factorization 25455ba2a51SBarry Smith . -pc_factor_fill <nfill> - expected amount of fill in factored matrix compared to original matrix, nfill > 1 2552401956bSBarry Smith . -pc_factor_nonzeros_along_diagonal - reorder the matrix before factorization to remove zeros from the diagonal, 2569b54502bSHong Zhang this decreases the chance of getting a zero pivot 2572401956bSBarry Smith . -pc_factor_mat_ordering_type <natural,nd,1wd,rcm,qmd> - set the row/column ordering of the factored matrix 258967c93d3SBarry Smith - -pc_factor_pivot_in_blocks - for block ILU(k) factorization, i.e. with BAIJ matrices with block size larger 2599b54502bSHong Zhang than 1 the diagonal blocks are factored with partial pivoting (this increases the 2609b54502bSHong Zhang stability of the ILU factorization 2619b54502bSHong Zhang 2629b54502bSHong Zhang Level: beginner 2639b54502bSHong Zhang 2649b54502bSHong Zhang Concepts: incomplete factorization 2659b54502bSHong Zhang 266*95452b02SPatrick Sanan Notes: 267*95452b02SPatrick Sanan Only implemented for some matrix formats. (for parallel see PCHYPRE for hypre's ILU) 2689b54502bSHong Zhang 2699b54502bSHong Zhang For BAIJ matrices this implements a point block ILU 2709b54502bSHong Zhang 271f0b9ad6cSBarry Smith The "symmetric" application of this preconditioner is not actually symmetric since L is not transpose(U) 272f0b9ad6cSBarry Smith even when the matrix is not symmetric since the U stores the diagonals of the factorization. 273f0b9ad6cSBarry Smith 274cd0a26f6SPaul Mullowney If you are using MATSEQAIJCUSPARSE matrices (or MATMPIAIJCUSPARESE matrices with block Jacobi), factorization 275cd0a26f6SPaul Mullowney is never done on the GPU). 276ac793be5SBarry Smith 277c582cd25SBarry Smith References: 27896a0c994SBarry Smith + 1. - T. Dupont, R. Kendall, and H. Rachford. An approximate factorization procedure for solving 27996a0c994SBarry Smith self adjoint elliptic difference equations. SIAM J. Numer. Anal., 5, 1968. 28096a0c994SBarry Smith . 2. - T.A. Oliphant. An implicit numerical method for solving two dimensional timedependent diffusion problems. Quart. Appl. Math., 19, 1961. 28196a0c994SBarry Smith - 3. - TONY F. CHAN AND HENK A. VAN DER VORST, APPROXIMATE AND INCOMPLETE FACTORIZATIONS, 28296a0c994SBarry Smith Chapter in Parallel Numerical 283c582cd25SBarry Smith Algorithms, edited by D. Keyes, A. Semah, V. Venkatakrishnan, ICASE/LaRC Interdisciplinary Series in 28496a0c994SBarry Smith Science and Engineering, Kluwer. 285c582cd25SBarry Smith 286c582cd25SBarry Smith 2879b54502bSHong Zhang .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC, PCSOR, MatOrderingType, 288145b9266SHong Zhang PCFactorSetZeroPivot(), PCFactorSetShiftSetType(), PCFactorSetAmount(), 289b7c853c4SBarry Smith PCFactorSetDropTolerance(),PCFactorSetFill(), PCFactorSetMatOrderingType(), PCFactorSetReuseOrdering(), 29092e9c092SBarry Smith PCFactorSetLevels(), PCFactorSetUseInPlace(), PCFactorSetAllowDiagonalFill(), PCFactorSetPivotInBlocks(), 29192e9c092SBarry Smith PCFactorGetAllowDiagonalFill(), PCFactorGetUseInPlace() 2929b54502bSHong Zhang 2939b54502bSHong Zhang M*/ 2949b54502bSHong Zhang 2958cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PCCreate_ILU(PC pc) 2969b54502bSHong Zhang { 2979b54502bSHong Zhang PetscErrorCode ierr; 2989b54502bSHong Zhang PC_ILU *ilu; 2999b54502bSHong Zhang 3009b54502bSHong Zhang PetscFunctionBegin; 301b00a9115SJed Brown ierr = PetscNewLog(pc,&ilu);CHKERRQ(ierr); 3023d1c1ea0SBarry Smith pc->data = (void*)ilu; 3033d1c1ea0SBarry Smith ierr = PCFactorInitialize(pc);CHKERRQ(ierr); 3049b54502bSHong Zhang 305879e8a4dSBarry Smith ((PC_Factor*)ilu)->factortype = MAT_FACTOR_ILU; 30675567043SBarry Smith ((PC_Factor*)ilu)->info.levels = 0.; 307075768bcSBarry Smith ((PC_Factor*)ilu)->info.fill = 1.0; 3089b54502bSHong Zhang ilu->col = 0; 3099b54502bSHong Zhang ilu->row = 0; 31019fd82e9SBarry Smith ierr = PetscStrallocpy(MATORDERINGNATURAL,(char**)&((PC_Factor*)ilu)->ordering);CHKERRQ(ierr); 311075768bcSBarry Smith ((PC_Factor*)ilu)->info.dt = PETSC_DEFAULT; 312075768bcSBarry Smith ((PC_Factor*)ilu)->info.dtcount = PETSC_DEFAULT; 313075768bcSBarry Smith ((PC_Factor*)ilu)->info.dtcol = PETSC_DEFAULT; 3149b54502bSHong Zhang 315574deadeSBarry Smith pc->ops->reset = PCReset_ILU; 3169b54502bSHong Zhang pc->ops->destroy = PCDestroy_ILU; 3179b54502bSHong Zhang pc->ops->apply = PCApply_ILU; 3189b54502bSHong Zhang pc->ops->applytranspose = PCApplyTranspose_ILU; 3199b54502bSHong Zhang pc->ops->setup = PCSetUp_ILU; 3209b54502bSHong Zhang pc->ops->setfromoptions = PCSetFromOptions_ILU; 3219b54502bSHong Zhang pc->ops->view = PCView_ILU; 322f0b9ad6cSBarry Smith pc->ops->applysymmetricleft = PCApplySymmetricLeft_ILU; 323f0b9ad6cSBarry Smith pc->ops->applysymmetricright = PCApplySymmetricRight_ILU; 3249b54502bSHong Zhang pc->ops->applyrichardson = 0; 325bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetDropTolerance_C",PCFactorSetDropTolerance_ILU);CHKERRQ(ierr); 326bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFactorReorderForNonzeroDiagonal_C",PCFactorReorderForNonzeroDiagonal_ILU);CHKERRQ(ierr); 3279b54502bSHong Zhang PetscFunctionReturn(0); 3289b54502bSHong Zhang } 329