Actual source code: icc.c

petsc-3.5.4 2015-05-23
Report Typos and Errors
  2: #include <../src/ksp/pc/impls/factor/icc/icc.h>   /*I "petscpc.h" I*/

  6: static PetscErrorCode PCSetup_ICC(PC pc)
  7: {
  8:   PC_ICC         *icc = (PC_ICC*)pc->data;
  9:   IS             perm,cperm;
 11:   MatInfo        info;

 14:   MatGetOrdering(pc->pmat, ((PC_Factor*)icc)->ordering,&perm,&cperm);

 16:   if (!pc->setupcalled) {
 17:     if (!((PC_Factor*)icc)->fact) {
 18:       MatGetFactor(pc->pmat,((PC_Factor*)icc)->solvertype,MAT_FACTOR_ICC,&((PC_Factor*)icc)->fact);
 19:     }
 20:     MatICCFactorSymbolic(((PC_Factor*)icc)->fact,pc->pmat,perm,&((PC_Factor*)icc)->info);
 21:   } else if (pc->flag != SAME_NONZERO_PATTERN) {
 22:     MatDestroy(&((PC_Factor*)icc)->fact);
 23:     MatGetFactor(pc->pmat,((PC_Factor*)icc)->solvertype,MAT_FACTOR_ICC,&((PC_Factor*)icc)->fact);
 24:     MatICCFactorSymbolic(((PC_Factor*)icc)->fact,pc->pmat,perm,&((PC_Factor*)icc)->info);
 25:   }
 26:   MatGetInfo(((PC_Factor*)icc)->fact,MAT_LOCAL,&info);
 27:   icc->actualfill = info.fill_ratio_needed;

 29:   ISDestroy(&cperm);
 30:   ISDestroy(&perm);
 31:   MatCholeskyFactorNumeric(((PC_Factor*)icc)->fact,pc->pmat,&((PC_Factor*)icc)->info);
 32:   return(0);
 33: }

 37: static PetscErrorCode PCReset_ICC(PC pc)
 38: {
 39:   PC_ICC         *icc = (PC_ICC*)pc->data;

 43:   MatDestroy(&((PC_Factor*)icc)->fact);
 44:   return(0);
 45: }

 49: static PetscErrorCode PCDestroy_ICC(PC pc)
 50: {
 51:   PC_ICC         *icc = (PC_ICC*)pc->data;

 55:   PCReset_ICC(pc);
 56:   PetscFree(((PC_Factor*)icc)->ordering);
 57:   PetscFree(((PC_Factor*)icc)->solvertype);
 58:   PetscFree(pc->data);
 59:   return(0);
 60: }

 64: static PetscErrorCode PCApply_ICC(PC pc,Vec x,Vec y)
 65: {
 66:   PC_ICC         *icc = (PC_ICC*)pc->data;

 70:   MatSolve(((PC_Factor*)icc)->fact,x,y);
 71:   return(0);
 72: }

 76: static PetscErrorCode PCApplySymmetricLeft_ICC(PC pc,Vec x,Vec y)
 77: {
 79:   PC_ICC         *icc = (PC_ICC*)pc->data;

 82:   MatForwardSolve(((PC_Factor*)icc)->fact,x,y);
 83:   return(0);
 84: }

 88: static PetscErrorCode PCApplySymmetricRight_ICC(PC pc,Vec x,Vec y)
 89: {
 91:   PC_ICC         *icc = (PC_ICC*)pc->data;

 94:   MatBackwardSolve(((PC_Factor*)icc)->fact,x,y);
 95:   return(0);
 96: }

100: static PetscErrorCode PCSetFromOptions_ICC(PC pc)
101: {
102:   PC_ICC         *icc = (PC_ICC*)pc->data;
103:   PetscBool      flg;
105:   /* PetscReal      dt[3];*/

108:   PetscOptionsHead("ICC Options");
109:   PCSetFromOptions_Factor(pc);

111:   PetscOptionsReal("-pc_factor_levels","levels of fill","PCFactorSetLevels",((PC_Factor*)icc)->info.levels,&((PC_Factor*)icc)->info.levels,&flg);
112:   /*dt[0] = ((PC_Factor*)icc)->info.dt;
113:   dt[1] = ((PC_Factor*)icc)->info.dtcol;
114:   dt[2] = ((PC_Factor*)icc)->info.dtcount;
115:   PetscInt       dtmax = 3;
116:   PetscOptionsRealArray("-pc_factor_drop_tolerance","<dt,dtcol,maxrowcount>","PCFactorSetDropTolerance",dt,&dtmax,&flg);
117:   if (flg) {
118:     PCFactorSetDropTolerance(pc,dt[0],dt[1],(PetscInt)dt[2]);
119:   }
120:   */
121:   PetscOptionsTail();
122:   return(0);
123: }

127: static PetscErrorCode PCView_ICC(PC pc,PetscViewer viewer)
128: {

132:   PCView_Factor(pc,viewer);
133:   return(0);
134: }

136: extern PetscErrorCode  PCFactorSetDropTolerance_ILU(PC,PetscReal,PetscReal,PetscInt);

138: /*MC
139:      PCICC - Incomplete Cholesky factorization preconditioners.

141:    Options Database Keys:
142: +  -pc_factor_levels <k> - number of levels of fill for ICC(k)
143: .  -pc_factor_in_place - only for ICC(0) with natural ordering, reuses the space of the matrix for
144:                       its factorization (overwrites original matrix)
145: .  -pc_factor_fill <nfill> - expected amount of fill in factored matrix compared to original matrix, nfill > 1
146: -  -pc_factor_mat_ordering_type <natural,nd,1wd,rcm,qmd> - set the row/column ordering of the factored matrix

148:    Level: beginner

150:   Concepts: incomplete Cholesky factorization

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

154:           For BAIJ matrices this implements a point block ICC.

156:           The Manteuffel shift is only implemented for matrices with block size 1

158:           By default, the Manteuffel is applied (for matrices with block size 1). Call PCFactorSetShiftType(pc,MAT_SHIFT_POSITIVE_DEFINITE);
159:           to turn off the shift.

161:    References:
162:    Review article: APPROXIMATE AND INCOMPLETE FACTORIZATIONS, TONY F. CHAN AND HENK A. VAN DER VORST
163:       http://igitur-archive.library.uu.nl/math/2001-0621-115821/proc.pdf chapter in Parallel Numerical
164:       Algorithms, edited by D. Keyes, A. Semah, V. Venkatakrishnan, ICASE/LaRC Interdisciplinary Series in
165:       Science and Engineering, Kluwer, pp. 167--202.


168: .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC, PCSOR, MatOrderingType,
169:            PCFactorSetZeroPivot(), PCFactorSetShiftType(), PCFactorSetShiftAmount(),
170:            PCFactorSetFill(), PCFactorSetMatOrderingType(), PCFactorSetReuseOrdering(),
171:            PCFactorSetLevels()

173: M*/

177: PETSC_EXTERN PetscErrorCode PCCreate_ICC(PC pc)
178: {
180:   PC_ICC         *icc;

183:   PetscNewLog(pc,&icc);

185:   ((PC_Factor*)icc)->fact = 0;

187:   PetscStrallocpy(MATORDERINGNATURAL,(char**)&((PC_Factor*)icc)->ordering);
188:   PetscStrallocpy(MATSOLVERPETSC,&((PC_Factor*)icc)->solvertype);
189:   MatFactorInfoInitialize(&((PC_Factor*)icc)->info);

191:   ((PC_Factor*)icc)->factortype  = MAT_FACTOR_ICC;
192:   ((PC_Factor*)icc)->info.levels = 0.;
193:   ((PC_Factor*)icc)->info.fill   = 1.0;
194:   icc->implctx                   = 0;

196:   ((PC_Factor*)icc)->info.dtcol       = PETSC_DEFAULT;
197:   ((PC_Factor*)icc)->info.shifttype   = (PetscReal) MAT_SHIFT_POSITIVE_DEFINITE;
198:   ((PC_Factor*)icc)->info.shiftamount = 100.0*PETSC_MACHINE_EPSILON;
199:   ((PC_Factor*)icc)->info.zeropivot   = 100.0*PETSC_MACHINE_EPSILON;

201:   pc->data                     = (void*)icc;
202:   pc->ops->apply               = PCApply_ICC;
203:   pc->ops->applytranspose      = PCApply_ICC;
204:   pc->ops->setup               = PCSetup_ICC;
205:   pc->ops->reset               = PCReset_ICC;
206:   pc->ops->destroy             = PCDestroy_ICC;
207:   pc->ops->setfromoptions      = PCSetFromOptions_ICC;
208:   pc->ops->view                = PCView_ICC;
209:   pc->ops->getfactoredmatrix   = PCFactorGetMatrix_Factor;
210:   pc->ops->applysymmetricleft  = PCApplySymmetricLeft_ICC;
211:   pc->ops->applysymmetricright = PCApplySymmetricRight_ICC;

213:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetUpMatSolverPackage_C",PCFactorSetUpMatSolverPackage_Factor);
214:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorGetMatSolverPackage_C",PCFactorGetMatSolverPackage_Factor);
215:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetZeroPivot_C",PCFactorSetZeroPivot_Factor);
216:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetShiftType_C",PCFactorSetShiftType_Factor);
217:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetShiftAmount_C",PCFactorSetShiftAmount_Factor);
218:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetLevels_C",PCFactorSetLevels_Factor);
219:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorGetLevels_C",PCFactorGetLevels_Factor);
220:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetFill_C",PCFactorSetFill_Factor);
221:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetMatOrderingType_C",PCFactorSetMatOrderingType_Factor);
222:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetMatSolverPackage_C",PCFactorSetMatSolverPackage_Factor);
223:   PetscObjectComposeFunction((PetscObject)pc,"PCFactorSetDropTolerance_C",PCFactorSetDropTolerance_ILU);
224:   return(0);
225: }