Actual source code: ilu.c

  1: #define PETSCKSP_DLL

  3: /*
  4:    Defines a ILU factorization preconditioner for any Mat implementation
  5: */
 6:  #include private/pcimpl.h
 7:  #include src/ksp/pc/impls/factor/ilu/ilu.h
 8:  #include src/mat/matimpl.h

 10: /* ------------------------------------------------------------------------------------------*/
 14: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetReuseFill_ILU(PC pc,PetscTruth flag)
 15: {
 16:   PC_ILU *lu;
 17: 
 19:   lu = (PC_ILU*)pc->data;
 20:   lu->reusefill = flag;
 21:   return(0);
 22: }

 28: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetZeroPivot_ILU(PC pc,PetscReal z)
 29: {
 30:   PC_ILU *ilu;

 33:   ilu                 = (PC_ILU*)pc->data;
 34:   ilu->info.zeropivot = z;
 35:   return(0);
 36: }

 42: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetShiftNonzero_ILU(PC pc,PetscReal shift)
 43: {
 44:   PC_ILU *dir;

 47:   dir = (PC_ILU*)pc->data;
 48:   if (shift == (PetscReal) PETSC_DECIDE) {
 49:     dir->info.shiftnz = 1.e-12;
 50:   } else {
 51:     dir->info.shiftnz = shift;
 52:   }
 53:   return(0);
 54: }

 60: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetShiftPd_ILU(PC pc,PetscTruth shift)
 61: {
 62:   PC_ILU *dir;
 63: 
 65:   dir = (PC_ILU*)pc->data;
 66:   if (shift) {
 67:     dir->info.shift_fraction = 0.0;
 68:     dir->info.shiftpd = 1.0;
 69:   } else {
 70:     dir->info.shiftpd = 0.0;
 71:   }
 72:   return(0);
 73: }

 79: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorReorderForNonzeroDiagonal_ILU(PC pc,PetscReal z)
 80: {
 81:   PC_ILU *ilu = (PC_ILU*)pc->data;

 84:   ilu->nonzerosalongdiagonal = PETSC_TRUE;
 85:   if (z == PETSC_DECIDE) {
 86:     ilu->nonzerosalongdiagonaltol = 1.e-10;
 87:   } else {
 88:     ilu->nonzerosalongdiagonaltol = z;
 89:   }
 90:   return(0);
 91: }

 96: PetscErrorCode PCDestroy_ILU_Internal(PC pc)
 97: {
 98:   PC_ILU         *ilu = (PC_ILU*)pc->data;

102:   if (!ilu->inplace && ilu->fact) {MatDestroy(ilu->fact);}
103:   if (ilu->row && ilu->col && ilu->row != ilu->col) {ISDestroy(ilu->row);}
104:   if (ilu->col) {ISDestroy(ilu->col);}
105:   return(0);
106: }

111: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetUseDropTolerance_ILU(PC pc,PetscReal dt,PetscReal dtcol,PetscInt dtcount)
112: {
113:   PC_ILU         *ilu;

117:   ilu = (PC_ILU*)pc->data;
118:   if (pc->setupcalled && (!ilu->usedt || ilu->info.dt != dt || ilu->info.dtcol != dtcol || ilu->info.dtcount != dtcount)) {
119:     pc->setupcalled   = 0;
120:     PCDestroy_ILU_Internal(pc);
121:   }
122:   ilu->usedt        = PETSC_TRUE;
123:   ilu->info.dt      = dt;
124:   ilu->info.dtcol   = dtcol;
125:   ilu->info.dtcount = dtcount;
126:   ilu->info.fill    = PETSC_DEFAULT;
127:   return(0);
128: }

134: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetFill_ILU(PC pc,PetscReal fill)
135: {
136:   PC_ILU *dir;

139:   dir            = (PC_ILU*)pc->data;
140:   dir->info.fill = fill;
141:   return(0);
142: }

148: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetMatOrdering_ILU(PC pc,MatOrderingType ordering)
149: {
150:   PC_ILU         *dir = (PC_ILU*)pc->data;
152:   PetscTruth     flg;
153: 
155:   if (!pc->setupcalled) {
156:      PetscStrfree(dir->ordering);
157:      PetscStrallocpy(ordering,&dir->ordering);
158:   } else {
159:     PetscStrcmp(dir->ordering,ordering,&flg);
160:     if (!flg) {
161:       pc->setupcalled = 0;
162:       PetscStrfree(dir->ordering);
163:       PetscStrallocpy(ordering,&dir->ordering);
164:       /* free the data structures, then create them again */
165:       PCDestroy_ILU_Internal(pc);
166:     }
167:   }
168:   return(0);
169: }

175: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetReuseOrdering_ILU(PC pc,PetscTruth flag)
176: {
177:   PC_ILU *ilu;

180:   ilu                = (PC_ILU*)pc->data;
181:   ilu->reuseordering = flag;
182:   return(0);
183: }

189: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetLevels_ILU(PC pc,PetscInt levels)
190: {
191:   PC_ILU         *ilu;

195:   ilu = (PC_ILU*)pc->data;

197:   if (!pc->setupcalled) {
198:     ilu->info.levels = levels;
199:   } else if (ilu->usedt || ilu->info.levels != levels) {
200:     ilu->info.levels = levels;
201:     pc->setupcalled  = 0;
202:     ilu->usedt       = PETSC_FALSE;
203:     PCDestroy_ILU_Internal(pc);
204:   }
205:   return(0);
206: }

212: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetUseInPlace_ILU(PC pc)
213: {
214:   PC_ILU *dir;

217:   dir          = (PC_ILU*)pc->data;
218:   dir->inplace = PETSC_TRUE;
219:   return(0);
220: }

226: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetAllowDiagonalFill_ILU(PC pc)
227: {
228:   PC_ILU *dir;

231:   dir                 = (PC_ILU*)pc->data;
232:   dir->info.diagonal_fill = 1;
233:   return(0);
234: }

239: /*@
240:    PCFactorSetUseDropTolerance - The preconditioner will use an ILU 
241:    based on a drop tolerance.

243:    Collective on PC

245:    Input Parameters:
246: +  pc - the preconditioner context
247: .  dt - the drop tolerance, try from 1.e-10 to .1
248: .  dtcol - tolerance for column pivot, good values [0.1 to 0.01]
249: -  maxrowcount - the max number of nonzeros allowed in a row, best value
250:                  depends on the number of nonzeros in row of original matrix

252:    Options Database Key:
253: .  -pc_factor_use_drop_tolerance <dt,dtcol,maxrowcount> - Sets drop tolerance

255:    Level: intermediate

257:     Notes:
258:       This uses the iludt() code of Saad's SPARSKIT package

260: .keywords: PC, levels, reordering, factorization, incomplete, ILU
261: @*/
262: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetUseDropTolerance(PC pc,PetscReal dt,PetscReal dtcol,PetscInt maxrowcount)
263: {
264:   PetscErrorCode ierr,(*f)(PC,PetscReal,PetscReal,PetscInt);

268:   PetscObjectQueryFunction((PetscObject)pc,"PCFactorSetUseDropTolerance_C",(void (**)(void))&f);
269:   if (f) {
270:     (*f)(pc,dt,dtcol,maxrowcount);
271:   }
272:   return(0);
273: }

277: /*@
278:    PCFactorSetLevels - Sets the number of levels of fill to use.

280:    Collective on PC

282:    Input Parameters:
283: +  pc - the preconditioner context
284: -  levels - number of levels of fill

286:    Options Database Key:
287: .  -pc_factor_levels <levels> - Sets fill level

289:    Level: intermediate

291: .keywords: PC, levels, fill, factorization, incomplete, ILU
292: @*/
293: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetLevels(PC pc,PetscInt levels)
294: {
295:   PetscErrorCode ierr,(*f)(PC,PetscInt);

299:   if (levels < 0) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"negative levels");
300:   PetscObjectQueryFunction((PetscObject)pc,"PCFactorSetLevels_C",(void (**)(void))&f);
301:   if (f) {
302:     (*f)(pc,levels);
303:   }
304:   return(0);
305: }

309: /*@
310:    PCFactorSetAllowDiagonalFill - Causes all diagonal matrix entries to be 
311:    treated as level 0 fill even if there is no non-zero location.

313:    Collective on PC

315:    Input Parameters:
316: +  pc - the preconditioner context

318:    Options Database Key:
319: .  -pc_factor_diagonal_fill

321:    Notes:
322:    Does not apply with 0 fill.

324:    Level: intermediate

326: .keywords: PC, levels, fill, factorization, incomplete, ILU
327: @*/
328: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetAllowDiagonalFill(PC pc)
329: {
330:   PetscErrorCode ierr,(*f)(PC);

334:   PetscObjectQueryFunction((PetscObject)pc,"PCFactorSetAllowDiagonalFill_C",(void (**)(void))&f);
335:   if (f) {
336:     (*f)(pc);
337:   }
338:   return(0);
339: }

341: /* ------------------------------------------------------------------------------------------*/

346: PetscErrorCode PETSCKSP_DLLEXPORT PCFactorSetPivotInBlocks_ILU(PC pc,PetscTruth pivot)
347: {
348:   PC_ILU *dir = (PC_ILU*)pc->data;

351:   dir->info.pivotinblocks = pivot ? 1.0 : 0.0;
352:   return(0);
353: }

358: static PetscErrorCode PCSetFromOptions_ILU(PC pc)
359: {
361:   PetscInt       dtmax = 3,itmp;
362:   PetscTruth     flg,set;
363:   PetscReal      dt[3];
364:   char           tname[256];
365:   PC_ILU         *ilu = (PC_ILU*)pc->data;
366:   PetscFList     ordlist;
367:   PetscReal      tol;

370:   MatOrderingRegisterAll(PETSC_NULL);
371:   PetscOptionsHead("ILU Options");
372:     PetscOptionsInt("-pc_factor_levels","levels of fill","PCFactorSetLevels",(PetscInt)ilu->info.levels,&itmp,&flg);
373:     if (flg) ilu->info.levels = itmp;
374:     PetscOptionsName("-pc_factor_in_place","do factorization in place","PCFactorSetUseInPlace",&flg);
375:     if (flg) ilu->inplace = PETSC_TRUE;
376:     PetscOptionsName("-pc_factor_diagonal_fill","Allow fill into empty diagonal entry","PCFactorSetAllowDiagonalFill",&flg);
377:     ilu->info.diagonal_fill = (double) flg;
378:     PetscOptionsName("-pc_factor_reuse_fill","Reuse fill ratio from previous factorization","PCFactorSetReuseFill",&flg);
379:     if (flg) ilu->reusefill = PETSC_TRUE;
380:     PetscOptionsName("-pc_factor_reuse_ordering","Reuse previous reordering","PCFactorSetReuseOrdering",&flg);
381:     if (flg) ilu->reuseordering = PETSC_TRUE;
382:     PetscOptionsName("-pc_factor_shift_nonzero","Shift added to diagonal","PCFactorSetShiftNonzero",&flg);
383:     if (flg) {
384:       PCFactorSetShiftNonzero(pc,(PetscReal)PETSC_DECIDE);
385:     }
386:     PetscOptionsReal("-pc_factor_shift_nonzero","Shift added to diagonal","PCFactorSetShiftNonzero",ilu->info.shiftnz,&ilu->info.shiftnz,0);
387: 
388:     PetscOptionsName("-pc_factor_shift_positive_definite","Manteuffel shift applied to diagonal","PCFactorSetShiftPd",&flg);
389:     if (flg) {
390:       PetscOptionsInt("-pc_factor_shift_positive_definite","Manteuffel shift applied to diagonal","PCFactorSetShiftPd",(PetscInt)ilu->info.shiftpd,&itmp,&flg);
391:       if (flg && !itmp) {
392:         PCFactorSetShiftPd(pc,PETSC_FALSE);
393:       } else {
394:         PCFactorSetShiftPd(pc,PETSC_TRUE);
395:       }
396:     }
397:     PetscOptionsReal("-pc_factor_zeropivot","Pivot is considered zero if less than","PCFactorSetZeroPivot",ilu->info.zeropivot,&ilu->info.zeropivot,0);

399:     dt[0] = ilu->info.dt;
400:     dt[1] = ilu->info.dtcol;
401:     dt[2] = ilu->info.dtcount;
402:     PetscOptionsRealArray("-pc_factor_use_drop_tolerance","<dt,dtcol,maxrowcount>","PCFactorSetUseDropTolerance",dt,&dtmax,&flg);
403:     if (flg) {
404:       PCFactorSetUseDropTolerance(pc,dt[0],dt[1],(PetscInt)dt[2]);
405:     }
406:     PetscOptionsReal("-pc_factor_fill","Expected fill in factorization","PCFactorSetFill",ilu->info.fill,&ilu->info.fill,&flg);
407:     PetscOptionsName("-pc_factor_nonzeros_along_diagonal","Reorder to remove zeros from diagonal","PCFactorReorderForNonzeroDiagonal",&flg);
408:     if (flg) {
409:       tol = PETSC_DECIDE;
410:       PetscOptionsReal("-pc_factor_nonzeros_along_diagonal","Reorder to remove zeros from diagonal","PCFactorReorderForNonzeroDiagonal",ilu->nonzerosalongdiagonaltol,&tol,0);
411:       PCFactorReorderForNonzeroDiagonal(pc,tol);
412:     }

414:     MatGetOrderingList(&ordlist);
415:     PetscOptionsList("-pc_factor_mat_ordering_type","Reorder to reduce nonzeros in ILU","PCFactorSetMatOrdering",ordlist,ilu->ordering,tname,256,&flg);
416:     if (flg) {
417:       PCFactorSetMatOrdering(pc,tname);
418:     }
419:     flg = ilu->info.pivotinblocks ? PETSC_TRUE : PETSC_FALSE;
420:     PetscOptionsTruth("-pc_factor_pivot_in_blocks","Pivot inside matrix blocks for BAIJ and SBAIJ","PCFactorSetPivotInBlocks",flg,&flg,&set);
421:     if (set) {
422:       PCFactorSetPivotInBlocks(pc,flg);
423:     }
424:   PetscOptionsTail();
425:   return(0);
426: }

430: static PetscErrorCode PCView_ILU(PC pc,PetscViewer viewer)
431: {
432:   PC_ILU         *ilu = (PC_ILU*)pc->data;
434:   PetscTruth     isstring,iascii;

437:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);
438:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
439:   if (iascii) {
440:     if (ilu->usedt) {
441:         PetscViewerASCIIPrintf(viewer,"  ILU: drop tolerance %G\n",ilu->info.dt);
442:         PetscViewerASCIIPrintf(viewer,"  ILU: max nonzeros per row %D\n",(PetscInt)ilu->info.dtcount);
443:         PetscViewerASCIIPrintf(viewer,"  ILU: column permutation tolerance %G\n",ilu->info.dtcol);
444:     } else if (ilu->info.levels == 1) {
445:         PetscViewerASCIIPrintf(viewer,"  ILU: %D level of fill\n",(PetscInt)ilu->info.levels);
446:     } else {
447:         PetscViewerASCIIPrintf(viewer,"  ILU: %D levels of fill\n",(PetscInt)ilu->info.levels);
448:     }
449:     PetscViewerASCIIPrintf(viewer,"  ILU: max fill ratio allocated %G\n",ilu->info.fill);
450:     PetscViewerASCIIPrintf(viewer,"  ILU: tolerance for zero pivot %G\n",ilu->info.zeropivot);
451:     if (ilu->info.shiftpd) {PetscViewerASCIIPrintf(viewer,"  ILU: using Manteuffel shift\n");}
452:     if (ilu->inplace) {PetscViewerASCIIPrintf(viewer,"       in-place factorization\n");}
453:     else              {PetscViewerASCIIPrintf(viewer,"       out-of-place factorization\n");}
454:     PetscViewerASCIIPrintf(viewer,"       matrix ordering: %s\n",ilu->ordering);
455:     if (ilu->reusefill)     {PetscViewerASCIIPrintf(viewer,"       Reusing fill from past factorization\n");}
456:     if (ilu->reuseordering) {PetscViewerASCIIPrintf(viewer,"       Reusing reordering from past factorization\n");}
457:     if (ilu->fact) {
458:       PetscViewerASCIIPrintf(viewer,"       Factored matrix follows\n");
459:       PetscViewerASCIIPushTab(viewer);
460:       PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_INFO);
461:       MatView(ilu->fact,viewer);
462:       PetscViewerPopFormat(viewer);
463:       PetscViewerASCIIPopTab(viewer);
464:     }
465:   } else if (isstring) {
466:     PetscViewerStringSPrintf(viewer," lvls=%D,order=%s",(PetscInt)ilu->info.levels,ilu->ordering);
467:   } else {
468:     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for PCILU",((PetscObject)viewer)->type_name);
469:   }
470:   return(0);
471: }

475: static PetscErrorCode PCSetUp_ILU(PC pc)
476: {
478:   PC_ILU         *ilu = (PC_ILU*)pc->data;

481:   if (ilu->inplace) {
482:     if (!pc->setupcalled) {

484:       /* In-place factorization only makes sense with the natural ordering,
485:          so we only need to get the ordering once, even if nonzero structure changes */
486:       MatGetOrdering(pc->pmat,ilu->ordering,&ilu->row,&ilu->col);
487:       if (ilu->row) {PetscLogObjectParent(pc,ilu->row);}
488:       if (ilu->col) {PetscLogObjectParent(pc,ilu->col);}
489:     }

491:     /* In place ILU only makes sense with fill factor of 1.0 because 
492:        cannot have levels of fill */
493:     ilu->info.fill          = 1.0;
494:     ilu->info.diagonal_fill = 0;
495:     MatILUFactor(pc->pmat,ilu->row,ilu->col,&ilu->info);
496:     ilu->fact = pc->pmat;
497:   } else if (ilu->usedt) {
498:     if (!pc->setupcalled) {
499:       MatGetOrdering(pc->pmat,ilu->ordering,&ilu->row,&ilu->col);
500:       if (ilu->row) {PetscLogObjectParent(pc,ilu->row);}
501:       if (ilu->col) {PetscLogObjectParent(pc,ilu->col);}
502:       MatILUDTFactor(pc->pmat,ilu->row,ilu->col,&ilu->info,&ilu->fact);
503:       PetscLogObjectParent(pc,ilu->fact);
504:     } else if (pc->flag != SAME_NONZERO_PATTERN) {
505:       MatDestroy(ilu->fact);
506:       if (!ilu->reuseordering) {
507:         if (ilu->row) {ISDestroy(ilu->row);}
508:         if (ilu->col) {ISDestroy(ilu->col);}
509:         MatGetOrdering(pc->pmat,ilu->ordering,&ilu->row,&ilu->col);
510:         if (ilu->row) {PetscLogObjectParent(pc,ilu->row);}
511:         if (ilu->col) {PetscLogObjectParent(pc,ilu->col);}
512:       }
513:       MatILUDTFactor(pc->pmat,ilu->row,ilu->col,&ilu->info,&ilu->fact);
514:       PetscLogObjectParent(pc,ilu->fact);
515:     } else if (!ilu->reusefill) {
516:       MatDestroy(ilu->fact);
517:       MatILUDTFactor(pc->pmat,ilu->row,ilu->col,&ilu->info,&ilu->fact);
518:       PetscLogObjectParent(pc,ilu->fact);
519:     } else {
520:       MatLUFactorNumeric(pc->pmat,&ilu->info,&ilu->fact);
521:     }
522:    } else {
523:     if (!pc->setupcalled) {
524:       /* first time in so compute reordering and symbolic factorization */
525:       MatGetOrdering(pc->pmat,ilu->ordering,&ilu->row,&ilu->col);
526:       if (ilu->row) {PetscLogObjectParent(pc,ilu->row);}
527:       if (ilu->col) {PetscLogObjectParent(pc,ilu->col);}
528:       /*  Remove zeros along diagonal?     */
529:       if (ilu->nonzerosalongdiagonal) {
530:         MatReorderForNonzeroDiagonal(pc->pmat,ilu->nonzerosalongdiagonaltol,ilu->row,ilu->col);
531:       }
532:       MatILUFactorSymbolic(pc->pmat,ilu->row,ilu->col,&ilu->info,&ilu->fact);
533:       PetscLogObjectParent(pc,ilu->fact);
534:     } else if (pc->flag != SAME_NONZERO_PATTERN) {
535:       if (!ilu->reuseordering) {
536:         /* compute a new ordering for the ILU */
537:         ISDestroy(ilu->row);
538:         ISDestroy(ilu->col);
539:         MatGetOrdering(pc->pmat,ilu->ordering,&ilu->row,&ilu->col);
540:         if (ilu->row) {PetscLogObjectParent(pc,ilu->row);}
541:         if (ilu->col) {PetscLogObjectParent(pc,ilu->col);}
542:         /*  Remove zeros along diagonal?     */
543:         if (ilu->nonzerosalongdiagonal) {
544:           MatReorderForNonzeroDiagonal(pc->pmat,ilu->nonzerosalongdiagonaltol,ilu->row,ilu->col);
545:         }
546:       }
547:       MatDestroy(ilu->fact);
548:       MatILUFactorSymbolic(pc->pmat,ilu->row,ilu->col,&ilu->info,&ilu->fact);
549:       PetscLogObjectParent(pc,ilu->fact);
550:     }
551:     MatLUFactorNumeric(pc->pmat,&ilu->info,&ilu->fact);
552:   }
553:   return(0);
554: }

558: static PetscErrorCode PCDestroy_ILU(PC pc)
559: {
560:   PC_ILU         *ilu = (PC_ILU*)pc->data;

564:   PCDestroy_ILU_Internal(pc);
565:   PetscStrfree(ilu->ordering);
566:   PetscFree(ilu);
567:   return(0);
568: }

572: static PetscErrorCode PCApply_ILU(PC pc,Vec x,Vec y)
573: {
574:   PC_ILU         *ilu = (PC_ILU*)pc->data;

578:   MatSolve(ilu->fact,x,y);
579:   return(0);
580: }

584: static PetscErrorCode PCApplyTranspose_ILU(PC pc,Vec x,Vec y)
585: {
586:   PC_ILU         *ilu = (PC_ILU*)pc->data;

590:   MatSolveTranspose(ilu->fact,x,y);
591:   return(0);
592: }

596: static PetscErrorCode PCGetFactoredMatrix_ILU(PC pc,Mat *mat)
597: {
598:   PC_ILU *ilu = (PC_ILU*)pc->data;

601:   if (!ilu->fact) SETERRQ(PETSC_ERR_ORDER,"Matrix not yet factored; call after KSPSetUp() or PCSetUp()");
602:   *mat = ilu->fact;
603:   return(0);
604: }

606: /*MC
607:      PCILU - Incomplete factorization preconditioners.

609:    Options Database Keys:
610: +  -pc_factor_levels <k> - number of levels of fill for ILU(k)
611: .  -pc_factor_in_place - only for ILU(0) with natural ordering, reuses the space of the matrix for
612:                       its factorization (overwrites original matrix)
613: .  -pc_factor_diagonal_fill - fill in a zero diagonal even if levels of fill indicate it wouldn't be fill
614: .  -pc_factor_reuse_ordering - reuse ordering of factorized matrix from previous factorization
615: .  -pc_factor_use_drop_tolerance <dt,dtcol,maxrowcount> - use Saad's drop tolerance ILUdt
616: .  -pc_factor_fill <nfill> - expected amount of fill in factored matrix compared to original matrix, nfill > 1
617: .  -pc_factor_nonzeros_along_diagonal - reorder the matrix before factorization to remove zeros from the diagonal,
618:                                    this decreases the chance of getting a zero pivot
619: .  -pc_factor_mat_ordering_type <natural,nd,1wd,rcm,qmd> - set the row/column ordering of the factored matrix
620: .  -pc_factor_pivot_in_blocks - for block ILU(k) factorization, i.e. with BAIJ matrices with block size larger
621:                              than 1 the diagonal blocks are factored with partial pivoting (this increases the 
622:                              stability of the ILU factorization
623: .  -pc_factor_shift_nonzero <shift> - Sets shift amount or PETSC_DECIDE for the default
624: -  -pc_factor_shift_positive_definite [PETSC_TRUE/PETSC_FALSE] - Activate/Deactivate PCFactorSetShiftPd(); the value
625:    is optional with PETSC_TRUE being the default

627:    Level: beginner

629:   Concepts: incomplete factorization

631:    Notes: Only implemented for some matrix formats. Not implemented in parallel

633:           For BAIJ matrices this implements a point block ILU

635: .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC, PCSOR, MatOrderingType,
636:            PCFactorSetZeroPivot(), PCFactorSetShiftNonzero(), PCFactorSetShiftPd(), PCFactorSetUseDropTolerance(),
637:            PCFactorSetFill(), PCFactorSetMatOrdering(), PCFactorSetReuseOrdering(),
638:            PCFactorSetLevels(), PCFactorSetUseInPlace(), PCFactorSetAllowDiagonalFill(), PCFactorSetPivotInBlocks(),
639:            PCFactorSetShiftNonzero(),PCFactorSetShiftPd()

641: M*/

646: PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_ILU(PC pc)
647: {
649:   PC_ILU         *ilu;

652:   PetscNew(PC_ILU,&ilu);
653:   PetscLogObjectMemory(pc,sizeof(PC_ILU));

655:   ilu->fact                    = 0;
656:   MatFactorInfoInitialize(&ilu->info);
657:   ilu->info.levels             = 0;
658:   ilu->info.fill               = 1.0;
659:   ilu->col                     = 0;
660:   ilu->row                     = 0;
661:   ilu->inplace                 = PETSC_FALSE;
662:   PetscStrallocpy(MATORDERING_NATURAL,&ilu->ordering);
663:   ilu->reuseordering           = PETSC_FALSE;
664:   ilu->usedt                   = PETSC_FALSE;
665:   ilu->info.dt                 = PETSC_DEFAULT;
666:   ilu->info.dtcount            = PETSC_DEFAULT;
667:   ilu->info.dtcol              = PETSC_DEFAULT;
668:   ilu->info.shiftnz            = 0.0;
669:   ilu->info.shiftpd            = 0.0; /* false */
670:   ilu->info.shift_fraction     = 0.0;
671:   ilu->info.zeropivot          = 1.e-12;
672:   ilu->info.pivotinblocks      = 1.0;
673:   ilu->reusefill               = PETSC_FALSE;
674:   ilu->info.diagonal_fill      = 0;
675:   pc->data                     = (void*)ilu;

677:   pc->ops->destroy             = PCDestroy_ILU;
678:   pc->ops->apply               = PCApply_ILU;
679:   pc->ops->applytranspose      = PCApplyTranspose_ILU;
680:   pc->ops->setup               = PCSetUp_ILU;
681:   pc->ops->setfromoptions      = PCSetFromOptions_ILU;
682:   pc->ops->getfactoredmatrix   = PCGetFactoredMatrix_ILU;
683:   pc->ops->view                = PCView_ILU;
684:   pc->ops->applyrichardson     = 0;

686:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetZeroPivot_C","PCFactorSetZeroPivot_ILU",
687:                     PCFactorSetZeroPivot_ILU);
688:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetShiftNonzero_C","PCFactorSetShiftNonzero_ILU",
689:                     PCFactorSetShiftNonzero_ILU);
690:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetShiftPd_C","PCFactorSetShiftPd_ILU",
691:                     PCFactorSetShiftPd_ILU);

693:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetUseDropTolerance_C","PCFactorSetUseDropTolerance_ILU",
694:                     PCFactorSetUseDropTolerance_ILU);
695:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetFill_C","PCFactorSetFill_ILU",
696:                     PCFactorSetFill_ILU);
697:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetMatOrdering_C","PCFactorSetMatOrdering_ILU",
698:                     PCFactorSetMatOrdering_ILU);
699:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetReuseOrdering_C","PCFactorSetReuseOrdering_ILU",
700:                     PCFactorSetReuseOrdering_ILU);
701:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetReuseFill_C","PCFactorSetReuseFill_ILU",
702:                     PCFactorSetReuseFill_ILU);
703:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetLevels_C","PCFactorSetLevels_ILU",
704:                     PCFactorSetLevels_ILU);
705:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetUseInPlace_C","PCFactorSetUseInPlace_ILU",
706:                     PCFactorSetUseInPlace_ILU);
707:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetAllowDiagonalFill_C","PCFactorSetAllowDiagonalFill_ILU",
708:                     PCFactorSetAllowDiagonalFill_ILU);
709:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorSetPivotInBlocks_C","PCFactorSetPivotInBlocks_ILU",
710:                     PCFactorSetPivotInBlocks_ILU);
711:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCFactorReorderForNonzeroDiagonal_C","PCFactorReorderForNonzeroDiagonal_ILU",
712:                     PCFactorReorderForNonzeroDiagonal_ILU);
713:   return(0);
714: }