Actual source code: hypre.c

  1: #define PETSCKSP_DLL

  3: /* 
  4:    Provides an interface to the LLNL package hypre
  5: */

  7: /* Must use hypre 2.0.0 or more recent. */

 9:  #include private/pcimpl.h
 11: #include "HYPRE.h"
 12: #include "HYPRE_parcsr_ls.h"
 13: #include "_hypre_parcsr_mv.h"
 14: #include "_hypre_IJ_mv.h"

 17: EXTERN PetscErrorCode MatHYPRE_IJMatrixCreate(Mat,HYPRE_IJMatrix*);
 18: EXTERN PetscErrorCode MatHYPRE_IJMatrixCopy(Mat,HYPRE_IJMatrix);
 19: EXTERN PetscErrorCode MatHYPRE_IJMatrixFastCopy(Mat,HYPRE_IJMatrix);
 20: EXTERN PetscErrorCode VecHYPRE_IJVectorCreate(Vec,HYPRE_IJVector*);

 22: /* 
 23:    Private context (data structure) for the  preconditioner.  
 24: */
 25: typedef struct {
 26:   HYPRE_Solver       hsolver;
 27:   HYPRE_IJMatrix     ij;
 28:   HYPRE_IJVector     b,x;

 30:   PetscErrorCode     (*destroy)(HYPRE_Solver);
 31:   PetscErrorCode     (*solve)(HYPRE_Solver,HYPRE_ParCSRMatrix,HYPRE_ParVector,HYPRE_ParVector);
 32:   PetscErrorCode     (*setup)(HYPRE_Solver,HYPRE_ParCSRMatrix,HYPRE_ParVector,HYPRE_ParVector);
 33: 
 34:   MPI_Comm           comm_hypre;
 35:   char              *hypre_type;

 37:   /* options for Pilut and BoomerAMG*/
 38:   int                maxiter;
 39:   double             tol;

 41:   /* options for Pilut */
 42:   int                factorrowsize;

 44:   /* options for ParaSails */
 45:   int                nlevels;
 46:   double             threshhold;
 47:   double             filter;
 48:   int                sym;
 49:   double             loadbal;
 50:   int                logging;
 51:   int                ruse;
 52:   int                symt;

 54:   /* options for Euclid */
 55:   PetscTruth         bjilu;
 56:   int                levels;

 58:   /* options for Euclid and BoomerAMG */
 59:   PetscTruth         printstatistics;

 61:   /* options for BoomerAMG */
 62:   int                cycletype;
 63:   int                maxlevels;
 64:   double             strongthreshold;
 65:   double             maxrowsum;
 66:   int                gridsweeps[3];
 67:   int                coarsentype;
 68:   int                measuretype;
 69:   int                relaxtype[3];
 70:   double             relaxweight;
 71:   double             outerrelaxweight;
 72:   int                relaxorder;
 73:   double             truncfactor;
 74:   PetscTruth         applyrichardson;
 75:   int                pmax;
 76:   int                interptype;
 77:   int                agg_nl;
 78:   int                agg_num_paths;
 79:   int                nodal_coarsen;
 80:   PetscTruth         nodal_relax;
 81:   int                nodal_relax_levels;
 82: } PC_HYPRE;


 87: static PetscErrorCode PCSetUp_HYPRE(PC pc)
 88: {
 89:   PC_HYPRE           *jac = (PC_HYPRE*)pc->data;
 90:   PetscErrorCode     ierr;
 91:   HYPRE_ParCSRMatrix hmat;
 92:   HYPRE_ParVector    bv,xv;
 93:   PetscInt           bs;
 94:   int                hierr;

 97:   if (!jac->hypre_type) {
 98:     PCHYPRESetType(pc,"pilut");
 99:   }
100: #if 1
101:   if (!pc->setupcalled) {
102:     /* create the matrix and vectors the first time through */
103:     Vec x,b;
104:     MatHYPRE_IJMatrixCreate(pc->pmat,&jac->ij);
105:     MatGetVecs(pc->pmat,&x,&b);
106:     VecHYPRE_IJVectorCreate(x,&jac->x);
107:     VecHYPRE_IJVectorCreate(b,&jac->b);
108:     VecDestroy(x);
109:     VecDestroy(b);
110:   } else if (pc->flag != SAME_NONZERO_PATTERN) {
111:     /* rebuild the matrix from scratch */
112:     HYPRE_IJMatrixDestroy(jac->ij);
113:     MatHYPRE_IJMatrixCreate(pc->pmat,&jac->ij);
114:   }
115: #else  
116:   if (!jac->ij) { /* create the matrix the first time through */
117:     MatHYPRE_IJMatrixCreate(pc->pmat,&jac->ij);
118:   }
119:   if (!jac->b) { /* create the vectors the first time through */
120:     Vec x,b;
121:     MatGetVecs(pc->pmat,&x,&b);
122:     VecHYPRE_IJVectorCreate(x,&jac->x);
123:     VecHYPRE_IJVectorCreate(b,&jac->b);
124:     VecDestroy(x);
125:     VecDestroy(b);
126:   }
127: #endif
128:   /* special case for BoomerAMG */
129:   if (jac->setup == HYPRE_BoomerAMGSetup) {
130:     MatGetBlockSize(pc->pmat,&bs);
131:     if (bs > 1) {
132:       HYPRE_BoomerAMGSetNumFunctions(jac->hsolver,bs);
133:     }
134:   };
135:   MatHYPRE_IJMatrixCopy(pc->pmat,jac->ij);
136:   HYPRE_IJMatrixGetObject(jac->ij,(void**)&hmat);
137:   HYPRE_IJVectorGetObject(jac->b,(void**)&bv);
138:   HYPRE_IJVectorGetObject(jac->x,(void**)&xv);
139:   h(*jac->setup)(jac->hsolver,hmat,bv,xv);
140:   if (hierr) SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE setup, error code %d",hierr);
141:   return(0);
142: }

144: /*
145:     Replaces the address where the HYPRE vector points to its data with the address of
146:   PETSc's data. Saves the old address so it can be reset when we are finished with it.
147:   Allows use to get the data into a HYPRE vector without the cost of memcopies 
148: */
149: #define HYPREReplacePointer(b,newvalue,savedvalue) {\
150:    hypre_ParVector *par_vector   = (hypre_ParVector *)hypre_IJVectorObject(((hypre_IJVector*)b));\
151:    hypre_Vector    *local_vector = hypre_ParVectorLocalVector(par_vector);\
152:    savedvalue         = local_vector->data;\
153:    local_vector->data = newvalue;}

157: static PetscErrorCode PCApply_HYPRE(PC pc,Vec b,Vec x)
158: {
159:   PC_HYPRE           *jac = (PC_HYPRE*)pc->data;
160:   PetscErrorCode     ierr;
161:   HYPRE_ParCSRMatrix hmat;
162:   PetscScalar        *bv,*xv;
163:   HYPRE_ParVector    jbv,jxv;
164:   PetscScalar        *sbv,*sxv;
165:   int                hierr;

168:   if (!jac->applyrichardson) {VecSet(x,0.0);}
169:   VecGetArray(b,&bv);
170:   VecGetArray(x,&xv);
171:   HYPREReplacePointer(jac->b,bv,sbv);
172:   HYPREReplacePointer(jac->x,xv,sxv);

174:   HYPRE_IJMatrixGetObject(jac->ij,(void**)&hmat);
175:   HYPRE_IJVectorGetObject(jac->b,(void**)&jbv);
176:   HYPRE_IJVectorGetObject(jac->x,(void**)&jxv);
177:   h(*jac->solve)(jac->hsolver,hmat,jbv,jxv);

179:   /*if (hierr && (hierr != HYPRE_ERROR_CONV || jac->solve != HYPRE_BoomerAMGSolve))SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE solver, error code %d",hierr);
180:    */
181:  /* error code of HYPRE_ERROR_CONV means convergence not achieved - if
182:     the tolerance is set to 0.0 (the default), a convergence error will
183:     not occur (so we may not want to overide the conv. error here?*/
184:  if (hierr && hierr != HYPRE_ERROR_CONV)
185:   {
186:      SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE solver, error code %d",hierr);
187:   }
188:  if (hierr) hypre__global_error = 0;
189: 

191:   HYPREReplacePointer(jac->b,sbv,bv);
192:   HYPREReplacePointer(jac->x,sxv,xv);
193:   VecRestoreArray(x,&xv);
194:   VecRestoreArray(b,&bv);
195:   return(0);
196: }

200: static PetscErrorCode PCDestroy_HYPRE(PC pc)
201: {
202:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;

206:   if (jac->ij) { HYPRE_IJMatrixDestroy(jac->ij); }
207:   if (jac->b)  { HYPRE_IJVectorDestroy(jac->b);  }
208:   if (jac->x)  { HYPRE_IJVectorDestroy(jac->x);  }
209:   if (jac->destroy) { (*jac->destroy)(jac->hsolver); }
210:   PetscStrfree(jac->hypre_type);
211:   if (jac->comm_hypre != MPI_COMM_NULL) { MPI_Comm_free(&(jac->comm_hypre));}
212:   PetscFree(jac);

214:   PetscObjectChangeTypeName((PetscObject)pc,0);
215:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPRESetType_C","",PETSC_NULL);
216:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPREGetType_C","",PETSC_NULL);
217:   return(0);
218: }

220: /* --------------------------------------------------------------------------------------------*/
223: static PetscErrorCode PCSetFromOptions_HYPRE_Pilut(PC pc)
224: {
225:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
227:   PetscTruth     flag;

230:   PetscOptionsHead("HYPRE Pilut Options");
231:   PetscOptionsInt("-pc_hypre_pilut_maxiter","Number of iterations","None",jac->maxiter,&jac->maxiter,&flag);
232:   if (flag) {
233:     HYPRE_ParCSRPilutSetMaxIter(jac->hsolver,jac->maxiter);
234:   }
235:   PetscOptionsReal("-pc_hypre_pilut_tol","Drop tolerance","None",jac->tol,&jac->tol,&flag);
236:   if (flag) {
237:     HYPRE_ParCSRPilutSetDropTolerance(jac->hsolver,jac->tol);
238:   }
239:   PetscOptionsInt("-pc_hypre_pilut_factorrowsize","FactorRowSize","None",jac->factorrowsize,&jac->factorrowsize,&flag);
240:   if (flag) {
241:     HYPRE_ParCSRPilutSetFactorRowSize(jac->hsolver,jac->factorrowsize);
242:   }
243:   PetscOptionsTail();
244:   return(0);
245: }

249: static PetscErrorCode PCView_HYPRE_Pilut(PC pc,PetscViewer viewer)
250: {
251:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
253:   PetscTruth     iascii;

256:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
257:   if (iascii) {
258:     PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut preconditioning\n");
259:     if (jac->maxiter != PETSC_DEFAULT) {
260:       PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut: maximum number of iterations %d\n",jac->maxiter);
261:     } else {
262:       PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut: default maximum number of iterations \n");
263:     }
264:     if (jac->tol != PETSC_DEFAULT) {
265:       PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut: drop tolerance %G\n",jac->tol);
266:     } else {
267:       PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut: default drop tolerance \n");
268:     }
269:     if (jac->factorrowsize != PETSC_DEFAULT) {
270:       PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut: factor row size %d\n",jac->factorrowsize);
271:     } else {
272:       PetscViewerASCIIPrintf(viewer,"  HYPRE Pilut: default factor row size \n");
273:     }
274:   }
275:   return(0);
276: }

278: /* --------------------------------------------------------------------------------------------*/
281: static PetscErrorCode PCSetFromOptions_HYPRE_Euclid(PC pc)
282: {
283:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
285:   PetscTruth     flag;
286:   char           *args[8],levels[16];
287:   PetscInt       cnt = 0;

290:   PetscOptionsHead("HYPRE Euclid Options");
291:   PetscOptionsInt("-pc_hypre_euclid_levels","Number of levels of fill ILU(k)","None",jac->levels,&jac->levels,&flag);
292:   if (flag) {
293:     if (jac->levels < 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of levels %d must be nonegative",jac->levels);
294:     sprintf(levels,"%d",jac->levels);
295:     args[cnt++] = (char*)"-level"; args[cnt++] = levels;
296:   }
297:   PetscOptionsTruth("-pc_hypre_euclid_bj","Use block Jacobi ILU(k)","None",jac->bjilu,&jac->bjilu,PETSC_NULL);
298:   if (jac->bjilu) {
299:     args[cnt++] =(char*) "-bj"; args[cnt++] = (char*)"1";
300:   }
301: 
302:   PetscOptionsTruth("-pc_hypre_euclid_print_statistics","Print statistics","None",jac->printstatistics,&jac->printstatistics,PETSC_NULL);
303:   if (jac->printstatistics) {
304:     args[cnt++] = (char*)"-eu_stats"; args[cnt++] = (char*)"1";
305:     args[cnt++] = (char*)"-eu_mem"; args[cnt++] = (char*)"1";
306:   }
307:   PetscOptionsTail();
308:   if (cnt) {
309:     HYPRE_EuclidSetParams(jac->hsolver,cnt,args);
310:   }
311:   return(0);
312: }

316: static PetscErrorCode PCView_HYPRE_Euclid(PC pc,PetscViewer viewer)
317: {
318:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
320:   PetscTruth     iascii;

323:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
324:   if (iascii) {
325:     PetscViewerASCIIPrintf(viewer,"  HYPRE Euclid preconditioning\n");
326:     PetscViewerASCIIPrintf(viewer,"  HYPRE Euclid: number of levels %d\n",jac->levels);
327:     if (jac->bjilu) {
328:       PetscViewerASCIIPrintf(viewer,"  HYPRE Euclid: Using block Jacobi ILU instead of parallel ILU\n");
329:     }
330:   }
331:   return(0);
332: }

334: /* --------------------------------------------------------------------------------------------*/

338: static PetscErrorCode PCApplyTranspose_HYPRE_BoomerAMG(PC pc,Vec b,Vec x)
339: {
340:   PC_HYPRE           *jac = (PC_HYPRE*)pc->data;
341:   PetscErrorCode     ierr;
342:   HYPRE_ParCSRMatrix hmat;
343:   PetscScalar        *bv,*xv;
344:   HYPRE_ParVector    jbv,jxv;
345:   PetscScalar        *sbv,*sxv;
346:   int                hierr;

349:   VecSet(x,0.0);
350:   VecGetArray(b,&bv);
351:   VecGetArray(x,&xv);
352:   HYPREReplacePointer(jac->b,bv,sbv);
353:   HYPREReplacePointer(jac->x,xv,sxv);

355:   HYPRE_IJMatrixGetObject(jac->ij,(void**)&hmat);
356:   HYPRE_IJVectorGetObject(jac->b,(void**)&jbv);
357:   HYPRE_IJVectorGetObject(jac->x,(void**)&jxv);
358: 
359:   hHYPRE_BoomerAMGSolveT(jac->hsolver,hmat,jbv,jxv);
360:   /* error code of 1 in BoomerAMG merely means convergence not achieved */
361:   if (hierr && (hierr != 1)) SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE solver, error code %d",hierr);
362:   if (hierr) hypre__global_error = 0;
363: 
364:   HYPREReplacePointer(jac->b,sbv,bv);
365:   HYPREReplacePointer(jac->x,sxv,xv);
366:   VecRestoreArray(x,&xv);
367:   VecRestoreArray(b,&bv);
368:   return(0);
369: }

371: static const char *HYPREBoomerAMGCycleType[]   = {"","V","W"};
372: static const char *HYPREBoomerAMGCoarsenType[] = {"CLJP","Ruge-Stueben","","modifiedRuge-Stueben","","","Falgout", "", "PMIS", "", "HMIS"};
373: static const char *HYPREBoomerAMGMeasureType[] = {"local","global"};
374: static const char *HYPREBoomerAMGRelaxType[]   = {"Jacobi","sequential-Gauss-Seidel","","SOR/Jacobi","backward-SOR/Jacobi","","symmetric-SOR/Jacobi",
375:                                                   "","","Gaussian-elimination"};
376: static const char *HYPREBoomerAMGInterpType[]  = {"classical", "", "", "direct", "multipass", "multipass-wts", "ext+i",
377:                                                   "ext+i-cc", "standard", "standard-wts", "", "", "FF", "FF1"};
380: static PetscErrorCode PCSetFromOptions_HYPRE_BoomerAMG(PC pc)
381: {
382:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
384:   int            n,indx;
385:   PetscTruth     flg, tmp_truth;
386:   double         tmpdbl, twodbl[2];

389:   PetscOptionsHead("HYPRE BoomerAMG Options");
390:   PetscOptionsEList("-pc_hypre_boomeramg_cycle_type","Cycle type","None",HYPREBoomerAMGCycleType,2,HYPREBoomerAMGCycleType[jac->cycletype],&indx,&flg);
391:   if (flg) {
392:     jac->cycletype = indx;
393:     HYPRE_BoomerAMGSetCycleType(jac->hsolver,jac->cycletype);
394:   }
395:   PetscOptionsInt("-pc_hypre_boomeramg_max_levels","Number of levels (of grids) allowed","None",jac->maxlevels,&jac->maxlevels,&flg);
396:   if (flg) {
397:     if (jac->maxlevels < 2) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of levels %d must be at least two",jac->maxlevels);
398:     HYPRE_BoomerAMGSetMaxLevels(jac->hsolver,jac->maxlevels);
399:   }
400:   PetscOptionsInt("-pc_hypre_boomeramg_max_iter","Maximum iterations used PER hypre call","None",jac->maxiter,&jac->maxiter,&flg);
401:   if (flg) {
402:     if (jac->maxiter < 1) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of iterations %d must be at least one",jac->maxiter);
403:     HYPRE_BoomerAMGSetMaxIter(jac->hsolver,jac->maxiter);
404:   }
405:   PetscOptionsScalar("-pc_hypre_boomeramg_tol","Convergence tolerance PER hypre call (0.0 = use a fixed number of iterations)","None",jac->tol,&jac->tol,&flg);
406:   if (flg) {
407:     if (jac->tol < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Tolerance %G must be greater than or equal to zero",jac->tol);
408:     HYPRE_BoomerAMGSetTol(jac->hsolver,jac->tol);
409:   }

411:   PetscOptionsScalar("-pc_hypre_boomeramg_truncfactor","Truncation factor for interpolation (0=no truncation)","None",jac->truncfactor,&jac->truncfactor,&flg);
412:   if (flg) {
413:     if (jac->truncfactor < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Truncation factor %G must be great than or equal zero",jac->truncfactor);
414:     HYPRE_BoomerAMGSetTruncFactor(jac->hsolver,jac->truncfactor);
415:   }

417:  PetscOptionsInt("-pc_hypre_boomeramg_P_max","Max elements per row for interpolation operator ( 0=unlimited )","None",jac->pmax,&jac->pmax,&flg);
418:   if (flg) {
419:     if (jac->pmax < 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"P_max %G must be greater than or equal to zero",jac->pmax);
420:     HYPRE_BoomerAMGSetPMaxElmts(jac->hsolver,jac->pmax);
421:   }

423:  PetscOptionsInt("-pc_hypre_boomeramg_agg_nl","Number of levels of aggressive coarsening","None",jac->agg_nl,&jac->agg_nl,&flg);
424:   if (flg) {
425:      if (jac->agg_nl < 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of levels %G must be greater than or equal to zero",jac->agg_nl);

427:      HYPRE_BoomerAMGSetAggNumLevels(jac->hsolver,jac->agg_nl);
428:   }


431:  PetscOptionsInt("-pc_hypre_boomeramg_agg_num_paths","Number of paths for aggressive coarsening","None",jac->agg_num_paths,&jac->agg_num_paths,&flg);
432:   if (flg) {
433:      if (jac->agg_num_paths < 1) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of paths %G must be greater than or equal to 1",jac->agg_num_paths);

435:      HYPRE_BoomerAMGSetNumPaths(jac->hsolver,jac->agg_num_paths);
436:   }


439:   PetscOptionsScalar("-pc_hypre_boomeramg_strong_threshold","Threshold for being strongly connected","None",jac->strongthreshold,&jac->strongthreshold,&flg);
440:   if (flg) {
441:     if (jac->strongthreshold < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Strong threshold %G must be great than or equal zero",jac->strongthreshold);
442:     HYPRE_BoomerAMGSetStrongThreshold(jac->hsolver,jac->strongthreshold);
443:   }
444:   PetscOptionsScalar("-pc_hypre_boomeramg_max_row_sum","Maximum row sum","None",jac->maxrowsum,&jac->maxrowsum,&flg);
445:   if (flg) {
446:     if (jac->maxrowsum < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Maximum row sum %G must be greater than zero",jac->maxrowsum);
447:     if (jac->maxrowsum > 1.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Maximum row sum %G must be less than or equal one",jac->maxrowsum);
448:     HYPRE_BoomerAMGSetMaxRowSum(jac->hsolver,jac->maxrowsum);
449:   }

451:   /* Grid sweeps */
452:   PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_all","Number of sweeps for the up and down grid levels","None",jac->gridsweeps[0],&indx,&flg);
453:   if (flg) {
454:     HYPRE_BoomerAMGSetNumSweeps(jac->hsolver,indx);
455:     /* modify the jac structure so we can view the updated options with PC_View */
456:     jac->gridsweeps[0] = indx;
457:     jac->gridsweeps[1] = indx;
458:     /*defaults coarse to 1 */
459:     jac->gridsweeps[2] = 1;
460:   }

462:   PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_down","Number of sweeps for the down cycles","None",jac->gridsweeps[0], &indx ,&flg);
463:   if (flg) {
464:     HYPRE_BoomerAMGSetCycleNumSweeps(jac->hsolver,indx, 1);
465:     jac->gridsweeps[0] = indx;
466:   }
467:   PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_up","Number of sweeps for the up cycles","None",jac->gridsweeps[1],&indx,&flg);
468:   if (flg) {
469:     HYPRE_BoomerAMGSetCycleNumSweeps(jac->hsolver,indx, 2);
470:     jac->gridsweeps[1] = indx;
471:   }
472:   PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_coarse","Number of sweeps for the coarse level","None",jac->gridsweeps[2],&indx,&flg);
473:   if (flg) {
474:     HYPRE_BoomerAMGSetCycleNumSweeps(jac->hsolver,indx, 3);
475:     jac->gridsweeps[2] = indx;
476:   }

478:   /* Relax type */
479:   PetscOptionsEList("-pc_hypre_boomeramg_relax_type_all","Relax type for the up and down cycles","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[6],&indx,&flg);
480:   if (flg) {
481:     jac->relaxtype[0] = jac->relaxtype[1]  = indx;
482:     HYPRE_BoomerAMGSetRelaxType(jac->hsolver, indx);
483:     /* by default, coarse type set to 9 */
484:     jac->relaxtype[2] = 9;
485: 
486:   }
487:   PetscOptionsEList("-pc_hypre_boomeramg_relax_type_down","Relax type for the down cycles","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[6],&indx,&flg);
488:   if (flg) {
489:     jac->relaxtype[0] = indx;
490:     HYPRE_BoomerAMGSetCycleRelaxType(jac->hsolver, indx, 1);
491:   }
492:   PetscOptionsEList("-pc_hypre_boomeramg_relax_type_up","Relax type for the up cycles","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[6],&indx,&flg);
493:   if (flg) {
494:     jac->relaxtype[1] = indx;
495:     HYPRE_BoomerAMGSetCycleRelaxType(jac->hsolver, indx, 2);
496:   }
497:   PetscOptionsEList("-pc_hypre_boomeramg_relax_type_coarse","Relax type on coarse grid","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[9],&indx,&flg);
498:   if (flg) {
499:     jac->relaxtype[2] = indx;
500:     HYPRE_BoomerAMGSetCycleRelaxType(jac->hsolver, indx, 3);
501:   }

503:   /* Relaxation Weight */
504:   PetscOptionsReal("-pc_hypre_boomeramg_relax_weight_all","Relaxation weight for all levels (0 = hypre estimates, -k = determined with k CG steps)","None",jac->relaxweight, &tmpdbl ,&flg);
505:   if (flg) {
506:     HYPRE_BoomerAMGSetRelaxWt(jac->hsolver,tmpdbl);
507:     jac->relaxweight = tmpdbl;
508:   }

510:   n=2;
511:   twodbl[0] = twodbl[1] = 1.0;
512:   PetscOptionsRealArray("-pc_hypre_boomeramg_relax_weight_level","Set the relaxation weight for a particular level (weight,level)","None",twodbl, &n, &flg);
513:   if (flg) {
514:     if (n == 2) {
515:       indx =  (int)PetscAbsReal(twodbl[1]);
516:       HYPRE_BoomerAMGSetLevelRelaxWt(jac->hsolver,twodbl[0],indx);
517:     } else {
518:       SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Relax weight level: you must provide 2 values separated by a comma (and no space), you provided %d",n);
519:     }
520:   }

522:   /* Outer relaxation Weight */
523:   PetscOptionsReal("-pc_hypre_boomeramg_outer_relax_weight_all","Outer relaxation weight for all levels ( -k = determined with k CG steps)","None",jac->outerrelaxweight, &tmpdbl ,&flg);
524:   if (flg) {
525:     HYPRE_BoomerAMGSetOuterWt( jac->hsolver, tmpdbl);
526:     jac->outerrelaxweight = tmpdbl;
527:   }

529:   n=2;
530:   twodbl[0] = twodbl[1] = 1.0;
531:   PetscOptionsRealArray("-pc_hypre_boomeramg_outer_relax_weight_level","Set the outer relaxation weight for a particular level (weight,level)","None",twodbl, &n, &flg);
532:   if (flg) {
533:     if (n == 2) {
534:       indx =  (int)PetscAbsReal(twodbl[1]);
535:       HYPRE_BoomerAMGSetLevelOuterWt( jac->hsolver, twodbl[0], indx);
536:     } else {
537:       SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Relax weight outer level: You must provide 2 values separated by a comma (and no space), you provided %d",n);
538:     }
539:   }

541:   /* the Relax Order */
542:   /* PetscOptionsName("-pc_hypre_boomeramg_no_CF", "Do not use CF-relaxation", "None", &flg); */
543:   PetscOptionsTruth( "-pc_hypre_boomeramg_no_CF", "Do not use CF-relaxation", "None", PETSC_FALSE, &tmp_truth, &flg);

545:   if (flg) {
546:     jac->relaxorder = 0;
547:     HYPRE_BoomerAMGSetRelaxOrder(jac->hsolver, jac->relaxorder);
548:   }
549:   PetscOptionsEList("-pc_hypre_boomeramg_measure_type","Measure type","None",HYPREBoomerAMGMeasureType,2,HYPREBoomerAMGMeasureType[0],&indx,&flg);
550:   if (flg) {
551:     jac->measuretype = indx;
552:     HYPRE_BoomerAMGSetMeasureType(jac->hsolver,jac->measuretype);
553:   }
554:   /* update list length 3/07 */
555:   PetscOptionsEList("-pc_hypre_boomeramg_coarsen_type","Coarsen type","None",HYPREBoomerAMGCoarsenType,11,HYPREBoomerAMGCoarsenType[6],&indx,&flg);
556:   if (flg) {
557:     jac->coarsentype = indx;
558:     HYPRE_BoomerAMGSetCoarsenType(jac->hsolver,jac->coarsentype);
559:   }
560: 
561:   /* new 3/07 */
562:   PetscOptionsEList("-pc_hypre_boomeramg_interp_type","Interpolation type","None",HYPREBoomerAMGInterpType,14,HYPREBoomerAMGInterpType[0],&indx,&flg);
563:   if (flg) {
564:     jac->interptype = indx;
565:     HYPRE_BoomerAMGSetInterpType(jac->hsolver,jac->interptype);
566:   }



570:   PetscOptionsName("-pc_hypre_boomeramg_print_statistics","Print statistics","None",&flg);
571:   if (flg) {
572:     int level=3;
573:     jac->printstatistics = PETSC_TRUE;
574:     PetscOptionsInt("-pc_hypre_boomeramg_print_statistics","Print statistics","None",level,&level,PETSC_NULL);
575:     HYPRE_BoomerAMGSetPrintLevel(jac->hsolver,level);
576:     HYPRE_BoomerAMGSetDebugFlag(jac->hsolver,level);
577:   }

579:   PetscOptionsTruth( "-pc_hypre_boomeramg_nodal_coarsen", "HYPRE_BoomerAMGSetNodal()", "None", PETSC_FALSE, &tmp_truth, &flg);
580:   if (flg && tmp_truth) {
581:     jac->nodal_coarsen = 1;
582:     HYPRE_BoomerAMGSetNodal(jac->hsolver,1);
583:   }

585:   PetscOptionsTruth( "-pc_hypre_boomeramg_nodal_relaxation", "Nodal relaxation via Schwarz", "None", PETSC_FALSE, &tmp_truth, &flg);
586:   if (flg && tmp_truth) {
587:     PetscInt tmp_int;
588:     PetscOptionsInt( "-pc_hypre_boomeramg_nodal_relaxation", "Nodal relaxation via Schwarz", "None",jac->nodal_relax_levels,&tmp_int,&flg);
589:     if (flg) jac->nodal_relax_levels = tmp_int;
590:     HYPRE_BoomerAMGSetSmoothType(jac->hsolver,6);
591:     HYPRE_BoomerAMGSetDomainType(jac->hsolver,1);
592:     HYPRE_BoomerAMGSetOverlap(jac->hsolver,0);
593:     HYPRE_BoomerAMGSetSmoothNumLevels(jac->hsolver,jac->nodal_relax_levels);
594:   }

596:   PetscOptionsTail();
597:   return(0);
598: }

602: static PetscErrorCode PCApplyRichardson_HYPRE_BoomerAMG(PC pc,Vec b,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt its)
603: {
604:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;

608:   HYPRE_BoomerAMGSetMaxIter(jac->hsolver,its*jac->maxiter);
609:   HYPRE_BoomerAMGSetTol(jac->hsolver,PetscMin(rtol,jac->tol));
610:   jac->applyrichardson = PETSC_TRUE;
611:   PCApply_HYPRE(pc,b,y);
612:   jac->applyrichardson = PETSC_FALSE;
613:   HYPRE_BoomerAMGSetTol(jac->hsolver,jac->tol);
614:   HYPRE_BoomerAMGSetMaxIter(jac->hsolver,jac->maxiter);
615:   return(0);
616: }


621: static PetscErrorCode PCView_HYPRE_BoomerAMG(PC pc,PetscViewer viewer)
622: {
623:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
625:   PetscTruth     iascii;

628:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
629:   if (iascii) {
630:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG preconditioning\n");
631:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Cycle type %s\n",HYPREBoomerAMGCycleType[jac->cycletype]);
632:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Maximum number of levels %d\n",jac->maxlevels);
633:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Maximum number of iterations PER hypre call %d\n",jac->maxiter);
634:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Convergence tolerance PER hypre call %G\n",jac->tol);
635:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Threshold for strong coupling %G\n",jac->strongthreshold);
636:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Interpolation truncation factor %G\n",jac->truncfactor);
637:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Interpolation: max elements per row %d\n",jac->pmax);
638:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Number of levels of aggressive coarsening %d\n",jac->agg_nl);
639:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Number of paths for aggressive coarsening %d\n",jac->agg_num_paths);
640: 
641:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Maximum row sums %G\n",jac->maxrowsum);

643:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Sweeps down         %d\n",jac->gridsweeps[0]);
644:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Sweeps up           %d\n",jac->gridsweeps[1]);
645:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Sweeps on coarse    %d\n",jac->gridsweeps[2]);

647:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Relax down          %s\n",HYPREBoomerAMGRelaxType[jac->relaxtype[0]]);
648:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Relax up            %s\n",HYPREBoomerAMGRelaxType[jac->relaxtype[1]]);
649:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Relax on coarse     %s\n",HYPREBoomerAMGRelaxType[jac->relaxtype[2]]);

651:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Relax weight  (all)      %G\n",jac->relaxweight);
652:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Outer relax weight (all) %G\n",jac->outerrelaxweight);

654:     if (jac->relaxorder) {
655:       PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Using CF-relaxation\n");
656:     } else {
657:       PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Not using CF-relaxation\n");
658:     }
659:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Measure type        %s\n",HYPREBoomerAMGMeasureType[jac->measuretype]);
660:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Coarsen type        %s\n",HYPREBoomerAMGCoarsenType[jac->coarsentype]);
661:     PetscViewerASCIIPrintf(viewer,"  HYPRE BoomerAMG: Interpolation type  %s\n",HYPREBoomerAMGInterpType[jac->interptype]);
662:     if (jac->nodal_coarsen) {
663:       PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Using nodal coarsening (with HYPRE_BOOMERAMGSetNodal())\n");
664:     }
665:     if (jac->nodal_relax) {
666:       PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Using nodal relaxation via Schwarz smoothing on levels %d\n",jac->nodal_relax_levels);
667:     }
668:   }
669:   return(0);
670: }

672: /* --------------------------------------------------------------------------------------------*/
675: static PetscErrorCode PCSetFromOptions_HYPRE_ParaSails(PC pc)
676: {
677:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
679:   int            indx;
680:   PetscTruth     flag;
681:   const char     *symtlist[] = {"nonsymmetric","SPD","nonsymmetric,SPD"};

684:   PetscOptionsHead("HYPRE ParaSails Options");
685:   PetscOptionsInt("-pc_hypre_parasails_nlevels","Number of number of levels","None",jac->nlevels,&jac->nlevels,0);
686:   PetscOptionsReal("-pc_hypre_parasails_thresh","Threshold","None",jac->threshhold,&jac->threshhold,&flag);
687:   if (flag) {
688:     HYPRE_ParaSailsSetParams(jac->hsolver,jac->threshhold,jac->nlevels);
689:   }

691:   PetscOptionsReal("-pc_hypre_parasails_filter","filter","None",jac->filter,&jac->filter,&flag);
692:   if (flag) {
693:     HYPRE_ParaSailsSetFilter(jac->hsolver,jac->filter);
694:   }

696:   PetscOptionsReal("-pc_hypre_parasails_loadbal","Load balance","None",jac->loadbal,&jac->loadbal,&flag);
697:   if (flag) {
698:     HYPRE_ParaSailsSetLoadbal(jac->hsolver,jac->loadbal);
699:   }

701:   PetscOptionsTruth("-pc_hypre_parasails_logging","Print info to screen","None",(PetscTruth)jac->logging,(PetscTruth*)&jac->logging,&flag);
702:   if (flag) {
703:     HYPRE_ParaSailsSetLogging(jac->hsolver,jac->logging);
704:   }

706:   PetscOptionsTruth("-pc_hypre_parasails_reuse","Reuse nonzero pattern in preconditioner","None",(PetscTruth)jac->ruse,(PetscTruth*)&jac->ruse,&flag);
707:   if (flag) {
708:     HYPRE_ParaSailsSetReuse(jac->hsolver,jac->ruse);
709:   }

711:   PetscOptionsEList("-pc_hypre_parasails_sym","Symmetry of matrix and preconditioner","None",symtlist,3,symtlist[0],&indx,&flag);
712:   if (flag) {
713:     jac->symt = indx;
714:     HYPRE_ParaSailsSetSym(jac->hsolver,jac->symt);
715:   }

717:   PetscOptionsTail();
718:   return(0);
719: }

723: static PetscErrorCode PCView_HYPRE_ParaSails(PC pc,PetscViewer viewer)
724: {
725:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
727:   PetscTruth     iascii;
728:   const char     *symt = 0;;

731:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
732:   if (iascii) {
733:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails preconditioning\n");
734:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: nlevels %d\n",jac->nlevels);
735:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: threshold %G\n",jac->threshhold);
736:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: filter %G\n",jac->filter);
737:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: load balance %G\n",jac->loadbal);
738:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: reuse nonzero structure %s\n",PetscTruths[jac->ruse]);
739:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: print info to screen %s\n",PetscTruths[jac->logging]);
740:     if (!jac->symt) {
741:       symt = "nonsymmetric matrix and preconditioner";
742:     } else if (jac->symt == 1) {
743:       symt = "SPD matrix and preconditioner";
744:     } else if (jac->symt == 2) {
745:       symt = "nonsymmetric matrix but SPD preconditioner";
746:     } else {
747:       SETERRQ1(PETSC_ERR_ARG_WRONG,"Unknown HYPRE ParaSails symmetric option %d",jac->symt);
748:     }
749:     PetscViewerASCIIPrintf(viewer,"  HYPRE ParaSails: %s\n",symt);
750:   }
751:   return(0);
752: }
753: /* ---------------------------------------------------------------------------------*/

758: PetscErrorCode  PCHYPREGetType_HYPRE(PC pc,const char *name[])
759: {
760:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;

763:   *name = jac->hypre_type;
764:   return(0);
765: }

771: PetscErrorCode  PCHYPRESetType_HYPRE(PC pc,const char name[])
772: {
773:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
775:   PetscTruth     flag;

778:   if (jac->hypre_type) {
779:     PetscStrcmp(jac->hypre_type,name,&flag);
780:     if (!flag) SETERRQ(PETSC_ERR_ORDER,"Cannot reset the HYPRE preconditioner type once it has been set");
781:     return(0);
782:   } else {
783:     PetscStrallocpy(name, &jac->hypre_type);
784:   }
785: 
786:   jac->maxiter            = PETSC_DEFAULT;
787:   jac->tol                = PETSC_DEFAULT;
788:   jac->printstatistics    = PetscLogPrintInfo;

790:   PetscStrcmp("pilut",jac->hypre_type,&flag);
791:   if (flag) {
792:     HYPRE_ParCSRPilutCreate(jac->comm_hypre,&jac->hsolver);
793:     pc->ops->setfromoptions = PCSetFromOptions_HYPRE_Pilut;
794:     pc->ops->view           = PCView_HYPRE_Pilut;
795:     jac->destroy            = HYPRE_ParCSRPilutDestroy;
796:     jac->setup              = HYPRE_ParCSRPilutSetup;
797:     jac->solve              = HYPRE_ParCSRPilutSolve;
798:     jac->factorrowsize      = PETSC_DEFAULT;
799:     return(0);
800:   }
801:   PetscStrcmp("parasails",jac->hypre_type,&flag);
802:   if (flag) {
803:     HYPRE_ParaSailsCreate(jac->comm_hypre,&jac->hsolver);
804:     pc->ops->setfromoptions = PCSetFromOptions_HYPRE_ParaSails;
805:     pc->ops->view           = PCView_HYPRE_ParaSails;
806:     jac->destroy            = HYPRE_ParaSailsDestroy;
807:     jac->setup              = HYPRE_ParaSailsSetup;
808:     jac->solve              = HYPRE_ParaSailsSolve;
809:     /* initialize */
810:     jac->nlevels     = 1;
811:     jac->threshhold  = .1;
812:     jac->filter      = .1;
813:     jac->loadbal     = 0;
814:     if (PetscLogPrintInfo) {
815:       jac->logging     = (int) PETSC_TRUE;
816:     } else {
817:       jac->logging     = (int) PETSC_FALSE;
818:     }
819:     jac->ruse = (int) PETSC_FALSE;
820:     jac->symt   = 0;
821:     HYPRE_ParaSailsSetParams(jac->hsolver,jac->threshhold,jac->nlevels);
822:     HYPRE_ParaSailsSetFilter(jac->hsolver,jac->filter);
823:     HYPRE_ParaSailsSetLoadbal(jac->hsolver,jac->loadbal);
824:     HYPRE_ParaSailsSetLogging(jac->hsolver,jac->logging);
825:     HYPRE_ParaSailsSetReuse(jac->hsolver,jac->ruse);
826:     HYPRE_ParaSailsSetSym(jac->hsolver,jac->symt);
827:     return(0);
828:   }
829:   PetscStrcmp("euclid",jac->hypre_type,&flag);
830:   if (flag) {
831:     HYPRE_EuclidCreate(jac->comm_hypre,&jac->hsolver);
832:     pc->ops->setfromoptions = PCSetFromOptions_HYPRE_Euclid;
833:     pc->ops->view           = PCView_HYPRE_Euclid;
834:     jac->destroy            = HYPRE_EuclidDestroy;
835:     jac->setup              = HYPRE_EuclidSetup;
836:     jac->solve              = HYPRE_EuclidSolve;
837:     /* initialization */
838:     jac->bjilu              = PETSC_FALSE;
839:     jac->levels             = 1;
840:     return(0);
841:   }
842:   PetscStrcmp("boomeramg",jac->hypre_type,&flag);
843:   if (flag) {
844:     HYPRE_BoomerAMGCreate(&jac->hsolver);
845:     pc->ops->setfromoptions  = PCSetFromOptions_HYPRE_BoomerAMG;
846:     pc->ops->view            = PCView_HYPRE_BoomerAMG;
847:     pc->ops->applytranspose  = PCApplyTranspose_HYPRE_BoomerAMG;
848:     pc->ops->applyrichardson = PCApplyRichardson_HYPRE_BoomerAMG;
849:     jac->destroy             = HYPRE_BoomerAMGDestroy;
850:     jac->setup               = HYPRE_BoomerAMGSetup;
851:     jac->solve               = HYPRE_BoomerAMGSolve;
852:     jac->applyrichardson     = PETSC_FALSE;
853:     /* these defaults match the hypre defaults */
854:     jac->cycletype        = 1;
855:     jac->maxlevels        = 25;
856:     jac->maxiter          = 1;
857:     jac->tol              = 0.0; /* tolerance of zero indicates use as preconditioner (suppresses convergence errors) */
858:     jac->truncfactor      = 0.0;
859:     jac->strongthreshold  = .25;
860:     jac->maxrowsum        = .9;
861:     jac->coarsentype      = 6;
862:     jac->measuretype      = 0;
863:     jac->gridsweeps[0]    = jac->gridsweeps[1] = jac->gridsweeps[2] = 1;
864:     jac->relaxtype[0]     = jac->relaxtype[1] = 6; /* Defaults to SYMMETRIC since in PETSc we are using a a PC - most likely with CG */
865:     jac->relaxtype[2]     = 9; /*G.E. */
866:     jac->relaxweight      = 1.0;
867:     jac->outerrelaxweight = 1.0;
868:     jac->relaxorder       = 1;
869:     jac->interptype       = 0;
870:     jac->agg_nl           = 0;
871:     jac->pmax             = 0;
872:     jac->truncfactor      = 0.0;
873:     jac->agg_num_paths    = 1;

875:     jac->nodal_coarsen    = 0;
876:     jac->nodal_relax      = PETSC_FALSE;
877:     jac->nodal_relax_levels = 1;
878:     HYPRE_BoomerAMGSetCycleType(jac->hsolver,jac->cycletype);
879:     HYPRE_BoomerAMGSetMaxLevels(jac->hsolver,jac->maxlevels);
880:     HYPRE_BoomerAMGSetMaxIter(jac->hsolver,jac->maxiter);
881:     HYPRE_BoomerAMGSetTol(jac->hsolver,jac->tol);
882:     HYPRE_BoomerAMGSetTruncFactor(jac->hsolver,jac->truncfactor);
883:     HYPRE_BoomerAMGSetStrongThreshold(jac->hsolver,jac->strongthreshold);
884:     HYPRE_BoomerAMGSetMaxRowSum(jac->hsolver,jac->maxrowsum);
885:     HYPRE_BoomerAMGSetCoarsenType(jac->hsolver,jac->coarsentype);
886:     HYPRE_BoomerAMGSetMeasureType(jac->hsolver,jac->measuretype);
887:     HYPRE_BoomerAMGSetRelaxOrder(jac->hsolver, jac->relaxorder);
888:     HYPRE_BoomerAMGSetInterpType(jac->hsolver,jac->interptype);
889:     HYPRE_BoomerAMGSetAggNumLevels(jac->hsolver,jac->agg_nl);
890:     HYPRE_BoomerAMGSetPMaxElmts(jac->hsolver,jac->pmax);
891:     HYPRE_BoomerAMGSetNumPaths(jac->hsolver,jac->agg_num_paths);
892:     HYPRE_BoomerAMGSetRelaxType(jac->hsolver, jac->relaxtype[0]);  /*defaults coarse to 9*/
893:     HYPRE_BoomerAMGSetNumSweeps(jac->hsolver, jac->gridsweeps[0]); /*defaults coarse to 1 */
894:     return(0);
895:   }
896:   PetscStrfree(jac->hypre_type);
897:   jac->hypre_type = PETSC_NULL;
898:   SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown HYPRE preconditioner %s; Choices are pilut, parasails, euclid, boomeramg",name);
899:   return(0);
900: }

903: /*
904:     It only gets here if the HYPRE type has not been set before the call to 
905:    ...SetFromOptions() which actually is most of the time
906: */
909: static PetscErrorCode PCSetFromOptions_HYPRE(PC pc)
910: {
911:   PC_HYPRE       *jac = (PC_HYPRE*)pc->data;
913:   int            indx;
914:   const char     *type[] = {"pilut","parasails","boomeramg","euclid"};
915:   PetscTruth     flg;

918:   PetscOptionsHead("HYPRE preconditioner options");
919:   PetscOptionsEList("-pc_hypre_type","HYPRE preconditioner type","PCHYPRESetType",type,4,"pilut",&indx,&flg);
920:   if (PetscOptionsPublishCount) {   /* force the default if it was not yet set and user did not set with option */
921:     if (!flg && !jac->hypre_type) {
922:       flg   = PETSC_TRUE;
923:       indx = 0;
924:     }
925:   }
926:   if (flg) {
927:     PCHYPRESetType_HYPRE(pc,type[indx]);
928:   }
929:   if (pc->ops->setfromoptions) {
930:     pc->ops->setfromoptions(pc);
931:   }
932:   PetscOptionsTail();
933:   return(0);
934: }

938: /*@C
939:      PCHYPRESetType - Sets which hypre preconditioner you wish to use

941:    Input Parameters:
942: +     pc - the preconditioner context
943: -     name - either  pilut, parasails, boomeramg, euclid

945:    Options Database Keys:
946:    -pc_hypre_type - One of pilut, parasails, boomeramg, euclid
947:  
948:    Level: intermediate

950: .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC,
951:            PCHYPRE

953: @*/
954: PetscErrorCode  PCHYPRESetType(PC pc,const char name[])
955: {
956:   PetscErrorCode ierr,(*f)(PC,const char[]);

961:   PetscObjectQueryFunction((PetscObject)pc,"PCHYPRESetType_C",(void (**)(void))&f);
962:   if (f) {
963:     (*f)(pc,name);
964:   }
965:   return(0);
966: }

970: /*@C
971:      PCHYPREGetType - Gets which hypre preconditioner you are using

973:    Input Parameter:
974: .     pc - the preconditioner context

976:    Output Parameter:
977: .     name - either  pilut, parasails, boomeramg, euclid

979:    Level: intermediate

981: .seealso:  PCCreate(), PCHYPRESetType(), PCType (for list of available types), PC,
982:            PCHYPRE

984: @*/
985: PetscErrorCode  PCHYPREGetType(PC pc,const char *name[])
986: {
987:   PetscErrorCode ierr,(*f)(PC,const char*[]);

992:   PetscObjectQueryFunction((PetscObject)pc,"PCHYPREGetType_C",(void (**)(void))&f);
993:   if (f) {
994:     (*f)(pc,name);
995:   }
996:   return(0);
997: }

999: /*MC
1000:      PCHYPRE - Allows you to use the matrix element based preconditioners in the LLNL package hypre

1002:    Options Database Keys:
1003: +   -pc_hypre_type - One of pilut, parasails, boomeramg, euclid
1004: -   Too many others to list, run with -pc_type hypre -pc_hypre_type XXX -help to see options for the XXX
1005:           preconditioner
1006:  
1007:    Level: intermediate

1009:    Notes: Apart from pc_hypre_type (for which there is PCHYPRESetType()),
1010:           the many hypre options can ONLY be set via the options database (e.g. the command line
1011:           or with PetscOptionsSetValue(), there are no functions to set them)

1013:           The options -pc_hypre_boomeramg_max_iter and -pc_hypre_boomeramg_rtol refer to the number of iterations
1014:           (V-cycles) and tolerance that boomeramg does EACH time it is called. So for example, if 
1015:           -pc_hypre_boomeramg_max_iter is set to 2 then 2-V-cycles are being used to define the preconditioner 
1016:           (-pc_hypre_boomeramg_rtol should be set to 0.0 - the default - to strictly use a fixed number of 
1017:           iterations per hypre call). -ksp_max_it and -ksp_rtol STILL determine the total number of iterations 
1018:           and tolerance for the Krylov solver. For example, if -pc_hypre_boomeramg_max_iter is 2 and -ksp_max_it is 10 
1019:           then AT MOST twenty V-cycles of boomeramg will be called.

1021:            Note that the option -pc_hypre_boomeramg_relax_type_all defaults to symmetric relaxation 
1022:            (symmetric-SOR/Jacobi), which is required for Krylov solvers like CG that expect symmetry.  
1023:            Otherwise, you may want to use -pc_hypre_boomeramg_relax_type_all SOR/Jacobi.
1024:           If you wish to use BoomerAMG WITHOUT a Krylov method use -ksp_type richardson NOT -ksp_type preonly
1025:           and use -ksp_max_it to control the number of V-cycles.
1026:           (see the PETSc FAQ.html at the PETSc website under the Documentation tab).

1028:           2007-02-03 Using HYPRE-1.11.1b, the routine HYPRE_BoomerAMGSolveT and the option
1029:           -pc_hypre_parasails_reuse were failing with SIGSEGV. Dalcin L.

1031: .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC,
1032:            PCHYPRESetType()

1034: M*/

1039: PetscErrorCode  PCCreate_HYPRE(PC pc)
1040: {
1041:   PC_HYPRE       *jac;

1045:   PetscNewLog(pc,PC_HYPRE,&jac);
1046:   pc->data                 = jac;
1047:   pc->ops->destroy         = PCDestroy_HYPRE;
1048:   pc->ops->setfromoptions  = PCSetFromOptions_HYPRE;
1049:   pc->ops->setup           = PCSetUp_HYPRE;
1050:   pc->ops->apply           = PCApply_HYPRE;
1051:   jac->comm_hypre          = MPI_COMM_NULL;
1052:   jac->hypre_type          = PETSC_NULL;
1053:   /* duplicate communicator for hypre */
1054:   MPI_Comm_dup(((PetscObject)pc)->comm,&(jac->comm_hypre));
1055:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPRESetType_C","PCHYPRESetType_HYPRE",PCHYPRESetType_HYPRE);
1056:   PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPREGetType_C","PCHYPREGetType_HYPRE",PCHYPREGetType_HYPRE);
1057:   return(0);
1058: }