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,"boomeramg");
99: }
101: if (pc->setupcalled) {
102: /* always destroy the old matrix and create a new memory;
103: hope this does not churn the memory too much. The problem
104: is I do not know if it is possible to put the matrix back to
105: its initial state so that we can directly copy the values
106: the second time through. */
107: HYPRE_IJMatrixDestroy(jac->ij);
108: jac->ij = 0;
109: }
111: if (!jac->ij) { /* create the matrix the first time through */
112: MatHYPRE_IJMatrixCreate(pc->pmat,&jac->ij);
113: }
114: if (!jac->b) { /* create the vectors the first time through */
115: Vec x,b;
116: MatGetVecs(pc->pmat,&x,&b);
117: VecHYPRE_IJVectorCreate(x,&jac->x);
118: VecHYPRE_IJVectorCreate(b,&jac->b);
119: VecDestroy(x);
120: VecDestroy(b);
121: }
123: /* special case for BoomerAMG */
124: if (jac->setup == HYPRE_BoomerAMGSetup) {
125: MatGetBlockSize(pc->pmat,&bs);
126: if (bs > 1) {
127: HYPRE_BoomerAMGSetNumFunctions(jac->hsolver,bs);
128: }
129: };
130: MatHYPRE_IJMatrixCopy(pc->pmat,jac->ij);
131: HYPRE_IJMatrixGetObject(jac->ij,(void**)&hmat);
132: HYPRE_IJVectorGetObject(jac->b,(void**)&bv);
133: HYPRE_IJVectorGetObject(jac->x,(void**)&xv);
134: h(*jac->setup)(jac->hsolver,hmat,bv,xv);
135: if (hierr) SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE setup, error code %d",hierr);
136: return(0);
137: }
139: /*
140: Replaces the address where the HYPRE vector points to its data with the address of
141: PETSc's data. Saves the old address so it can be reset when we are finished with it.
142: Allows use to get the data into a HYPRE vector without the cost of memcopies
143: */
144: #define HYPREReplacePointer(b,newvalue,savedvalue) {\
145: hypre_ParVector *par_vector = (hypre_ParVector *)hypre_IJVectorObject(((hypre_IJVector*)b));\
146: hypre_Vector *local_vector = hypre_ParVectorLocalVector(par_vector);\
147: savedvalue = local_vector->data;\
148: local_vector->data = newvalue;}
152: static PetscErrorCode PCApply_HYPRE(PC pc,Vec b,Vec x)
153: {
154: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
155: PetscErrorCode ierr;
156: HYPRE_ParCSRMatrix hmat;
157: PetscScalar *bv,*xv;
158: HYPRE_ParVector jbv,jxv;
159: PetscScalar *sbv,*sxv;
160: int hierr;
163: if (!jac->applyrichardson) {VecSet(x,0.0);}
164: VecGetArray(b,&bv);
165: VecGetArray(x,&xv);
166: HYPREReplacePointer(jac->b,bv,sbv);
167: HYPREReplacePointer(jac->x,xv,sxv);
169: HYPRE_IJMatrixGetObject(jac->ij,(void**)&hmat);
170: HYPRE_IJVectorGetObject(jac->b,(void**)&jbv);
171: HYPRE_IJVectorGetObject(jac->x,(void**)&jxv);
172: h(*jac->solve)(jac->hsolver,hmat,jbv,jxv);
174: /*if (hierr && (hierr != HYPRE_ERROR_CONV || jac->solve != HYPRE_BoomerAMGSolve))SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE solver, error code %d",hierr);
175: */
176: /* error code of HYPRE_ERROR_CONV means convergence not achieved - if
177: the tolerance is set to 0.0 (the default), a convergence error will
178: not occur (so we may not want to overide the conv. error here?*/
179: if (hierr && hierr != HYPRE_ERROR_CONV)
180: {
181: SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE solver, error code %d",hierr);
182: }
183: if (hierr) hypre__global_error = 0;
184:
186: HYPREReplacePointer(jac->b,sbv,bv);
187: HYPREReplacePointer(jac->x,sxv,xv);
188: VecRestoreArray(x,&xv);
189: VecRestoreArray(b,&bv);
190: return(0);
191: }
195: static PetscErrorCode PCDestroy_HYPRE(PC pc)
196: {
197: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
201: if (jac->ij) { HYPRE_IJMatrixDestroy(jac->ij); }
202: if (jac->b) { HYPRE_IJVectorDestroy(jac->b); }
203: if (jac->x) { HYPRE_IJVectorDestroy(jac->x); }
204: if (jac->destroy) { (*jac->destroy)(jac->hsolver); }
205: PetscStrfree(jac->hypre_type);
206: if (jac->comm_hypre != MPI_COMM_NULL) { MPI_Comm_free(&(jac->comm_hypre));}
207: PetscFree(jac);
209: PetscObjectChangeTypeName((PetscObject)pc,0);
210: PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPRESetType_C","",PETSC_NULL);
211: PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPREGetType_C","",PETSC_NULL);
212: return(0);
213: }
215: /* --------------------------------------------------------------------------------------------*/
218: static PetscErrorCode PCSetFromOptions_HYPRE_Pilut(PC pc)
219: {
220: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
222: PetscTruth flag;
225: PetscOptionsHead("HYPRE Pilut Options");
226: PetscOptionsInt("-pc_hypre_pilut_maxiter","Number of iterations","None",jac->maxiter,&jac->maxiter,&flag);
227: if (flag) {
228: HYPRE_ParCSRPilutSetMaxIter(jac->hsolver,jac->maxiter);
229: }
230: PetscOptionsReal("-pc_hypre_pilut_tol","Drop tolerance","None",jac->tol,&jac->tol,&flag);
231: if (flag) {
232: HYPRE_ParCSRPilutSetDropTolerance(jac->hsolver,jac->tol);
233: }
234: PetscOptionsInt("-pc_hypre_pilut_factorrowsize","FactorRowSize","None",jac->factorrowsize,&jac->factorrowsize,&flag);
235: if (flag) {
236: HYPRE_ParCSRPilutSetFactorRowSize(jac->hsolver,jac->factorrowsize);
237: }
238: PetscOptionsTail();
239: return(0);
240: }
244: static PetscErrorCode PCView_HYPRE_Pilut(PC pc,PetscViewer viewer)
245: {
246: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
248: PetscTruth iascii;
251: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
252: if (iascii) {
253: PetscViewerASCIIPrintf(viewer," HYPRE Pilut preconditioning\n");
254: if (jac->maxiter != PETSC_DEFAULT) {
255: PetscViewerASCIIPrintf(viewer," HYPRE Pilut: maximum number of iterations %d\n",jac->maxiter);
256: } else {
257: PetscViewerASCIIPrintf(viewer," HYPRE Pilut: default maximum number of iterations \n");
258: }
259: if (jac->tol != PETSC_DEFAULT) {
260: PetscViewerASCIIPrintf(viewer," HYPRE Pilut: drop tolerance %G\n",jac->tol);
261: } else {
262: PetscViewerASCIIPrintf(viewer," HYPRE Pilut: default drop tolerance \n");
263: }
264: if (jac->factorrowsize != PETSC_DEFAULT) {
265: PetscViewerASCIIPrintf(viewer," HYPRE Pilut: factor row size %d\n",jac->factorrowsize);
266: } else {
267: PetscViewerASCIIPrintf(viewer," HYPRE Pilut: default factor row size \n");
268: }
269: }
270: return(0);
271: }
273: /* --------------------------------------------------------------------------------------------*/
276: static PetscErrorCode PCSetFromOptions_HYPRE_Euclid(PC pc)
277: {
278: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
280: PetscTruth flag;
281: char *args[8],levels[16];
282: PetscInt cnt = 0;
285: PetscOptionsHead("HYPRE Euclid Options");
286: PetscOptionsInt("-pc_hypre_euclid_levels","Number of levels of fill ILU(k)","None",jac->levels,&jac->levels,&flag);
287: if (flag) {
288: if (jac->levels < 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of levels %d must be nonegative",jac->levels);
289: sprintf(levels,"%d",jac->levels);
290: args[cnt++] = (char*)"-level"; args[cnt++] = levels;
291: }
292: PetscOptionsTruth("-pc_hypre_euclid_bj","Use block Jacobi ILU(k)","None",jac->bjilu,&jac->bjilu,PETSC_NULL);
293: if (jac->bjilu) {
294: args[cnt++] =(char*) "-bj"; args[cnt++] = (char*)"1";
295: }
296:
297: PetscOptionsTruth("-pc_hypre_euclid_print_statistics","Print statistics","None",jac->printstatistics,&jac->printstatistics,PETSC_NULL);
298: if (jac->printstatistics) {
299: args[cnt++] = (char*)"-eu_stats"; args[cnt++] = (char*)"1";
300: args[cnt++] = (char*)"-eu_mem"; args[cnt++] = (char*)"1";
301: }
302: PetscOptionsTail();
303: if (cnt) {
304: HYPRE_EuclidSetParams(jac->hsolver,cnt,args);
305: }
306: return(0);
307: }
311: static PetscErrorCode PCView_HYPRE_Euclid(PC pc,PetscViewer viewer)
312: {
313: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
315: PetscTruth iascii;
318: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
319: if (iascii) {
320: PetscViewerASCIIPrintf(viewer," HYPRE Euclid preconditioning\n");
321: PetscViewerASCIIPrintf(viewer," HYPRE Euclid: number of levels %d\n",jac->levels);
322: if (jac->bjilu) {
323: PetscViewerASCIIPrintf(viewer," HYPRE Euclid: Using block Jacobi ILU instead of parallel ILU\n");
324: }
325: }
326: return(0);
327: }
329: /* --------------------------------------------------------------------------------------------*/
333: static PetscErrorCode PCApplyTranspose_HYPRE_BoomerAMG(PC pc,Vec b,Vec x)
334: {
335: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
336: PetscErrorCode ierr;
337: HYPRE_ParCSRMatrix hmat;
338: PetscScalar *bv,*xv;
339: HYPRE_ParVector jbv,jxv;
340: PetscScalar *sbv,*sxv;
341: int hierr;
344: VecSet(x,0.0);
345: VecGetArray(b,&bv);
346: VecGetArray(x,&xv);
347: HYPREReplacePointer(jac->b,bv,sbv);
348: HYPREReplacePointer(jac->x,xv,sxv);
350: HYPRE_IJMatrixGetObject(jac->ij,(void**)&hmat);
351: HYPRE_IJVectorGetObject(jac->b,(void**)&jbv);
352: HYPRE_IJVectorGetObject(jac->x,(void**)&jxv);
353:
354: hHYPRE_BoomerAMGSolveT(jac->hsolver,hmat,jbv,jxv);
355: /* error code of 1 in BoomerAMG merely means convergence not achieved */
356: if (hierr && (hierr != 1)) SETERRQ1(PETSC_ERR_LIB,"Error in HYPRE solver, error code %d",hierr);
357: if (hierr) hypre__global_error = 0;
358:
359: HYPREReplacePointer(jac->b,sbv,bv);
360: HYPREReplacePointer(jac->x,sxv,xv);
361: VecRestoreArray(x,&xv);
362: VecRestoreArray(b,&bv);
363: return(0);
364: }
366: static const char *HYPREBoomerAMGCycleType[] = {"","V","W"};
367: static const char *HYPREBoomerAMGCoarsenType[] = {"CLJP","Ruge-Stueben","","modifiedRuge-Stueben","","","Falgout", "", "PMIS", "", "HMIS"};
368: static const char *HYPREBoomerAMGMeasureType[] = {"local","global"};
369: static const char *HYPREBoomerAMGRelaxType[] = {"Jacobi","sequential-Gauss-Seidel","","SOR/Jacobi","backward-SOR/Jacobi","","symmetric-SOR/Jacobi",
370: "","","Gaussian-elimination"};
371: static const char *HYPREBoomerAMGInterpType[] = {"classical", "", "", "direct", "multipass", "multipass-wts", "ext+i",
372: "ext+i-cc", "standard", "standard-wts", "", "", "FF", "FF1"};
375: static PetscErrorCode PCSetFromOptions_HYPRE_BoomerAMG(PC pc)
376: {
377: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
379: int n,indx;
380: PetscTruth flg, tmp_truth;
381: double tmpdbl, twodbl[2];
384: PetscOptionsHead("HYPRE BoomerAMG Options");
385: PetscOptionsEList("-pc_hypre_boomeramg_cycle_type","Cycle type","None",HYPREBoomerAMGCycleType,2,HYPREBoomerAMGCycleType[jac->cycletype],&indx,&flg);
386: if (flg) {
387: jac->cycletype = indx;
388: HYPRE_BoomerAMGSetCycleType(jac->hsolver,jac->cycletype);
389: }
390: PetscOptionsInt("-pc_hypre_boomeramg_max_levels","Number of levels (of grids) allowed","None",jac->maxlevels,&jac->maxlevels,&flg);
391: if (flg) {
392: if (jac->maxlevels < 2) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of levels %d must be at least two",jac->maxlevels);
393: HYPRE_BoomerAMGSetMaxLevels(jac->hsolver,jac->maxlevels);
394: }
395: PetscOptionsInt("-pc_hypre_boomeramg_max_iter","Maximum iterations used PER hypre call","None",jac->maxiter,&jac->maxiter,&flg);
396: if (flg) {
397: if (jac->maxiter < 1) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Number of iterations %d must be at least one",jac->maxiter);
398: HYPRE_BoomerAMGSetMaxIter(jac->hsolver,jac->maxiter);
399: }
400: PetscOptionsScalar("-pc_hypre_boomeramg_tol","Convergence tolerance PER hypre call (0.0 = use a fixed number of iterations)","None",jac->tol,&jac->tol,&flg);
401: if (flg) {
402: if (jac->tol < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Tolerance %G must be greater than or equal to zero",jac->tol);
403: HYPRE_BoomerAMGSetTol(jac->hsolver,jac->tol);
404: }
406: PetscOptionsScalar("-pc_hypre_boomeramg_truncfactor","Truncation factor for interpolation (0=no truncation)","None",jac->truncfactor,&jac->truncfactor,&flg);
407: if (flg) {
408: if (jac->truncfactor < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Truncation factor %G must be great than or equal zero",jac->truncfactor);
409: HYPRE_BoomerAMGSetTruncFactor(jac->hsolver,jac->truncfactor);
410: }
412: PetscOptionsInt("-pc_hypre_boomeramg_P_max","Max elements per row for interpolation operator ( 0=unlimited )","None",jac->pmax,&jac->pmax,&flg);
413: if (flg) {
414: if (jac->pmax < 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"P_max %G must be greater than or equal to zero",jac->pmax);
415: HYPRE_BoomerAMGSetPMaxElmts(jac->hsolver,jac->pmax);
416: }
418: PetscOptionsInt("-pc_hypre_boomeramg_agg_nl","Number of levels of aggressive coarsening","None",jac->agg_nl,&jac->agg_nl,&flg);
419: if (flg) {
420: 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);
422: HYPRE_BoomerAMGSetAggNumLevels(jac->hsolver,jac->agg_nl);
423: }
426: PetscOptionsInt("-pc_hypre_boomeramg_agg_num_paths","Number of paths for aggressive coarsening","None",jac->agg_num_paths,&jac->agg_num_paths,&flg);
427: if (flg) {
428: 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);
430: HYPRE_BoomerAMGSetNumPaths(jac->hsolver,jac->agg_num_paths);
431: }
434: PetscOptionsScalar("-pc_hypre_boomeramg_strong_threshold","Threshold for being strongly connected","None",jac->strongthreshold,&jac->strongthreshold,&flg);
435: if (flg) {
436: if (jac->strongthreshold < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Strong threshold %G must be great than or equal zero",jac->strongthreshold);
437: HYPRE_BoomerAMGSetStrongThreshold(jac->hsolver,jac->strongthreshold);
438: }
439: PetscOptionsScalar("-pc_hypre_boomeramg_max_row_sum","Maximum row sum","None",jac->maxrowsum,&jac->maxrowsum,&flg);
440: if (flg) {
441: if (jac->maxrowsum < 0.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Maximum row sum %G must be greater than zero",jac->maxrowsum);
442: if (jac->maxrowsum > 1.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Maximum row sum %G must be less than or equal one",jac->maxrowsum);
443: HYPRE_BoomerAMGSetMaxRowSum(jac->hsolver,jac->maxrowsum);
444: }
446: /* Grid sweeps */
447: PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_all","Number of sweeps for the up and down grid levels","None",jac->gridsweeps[0],&indx,&flg);
448: if (flg) {
449: HYPRE_BoomerAMGSetNumSweeps(jac->hsolver,indx);
450: /* modify the jac structure so we can view the updated options with PC_View */
451: jac->gridsweeps[0] = indx;
452: jac->gridsweeps[1] = indx;
453: /*defaults coarse to 1 */
454: jac->gridsweeps[2] = 1;
455: }
457: PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_down","Number of sweeps for the down cycles","None",jac->gridsweeps[0], &indx ,&flg);
458: if (flg) {
459: HYPRE_BoomerAMGSetCycleNumSweeps(jac->hsolver,indx, 1);
460: jac->gridsweeps[0] = indx;
461: }
462: PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_up","Number of sweeps for the up cycles","None",jac->gridsweeps[1],&indx,&flg);
463: if (flg) {
464: HYPRE_BoomerAMGSetCycleNumSweeps(jac->hsolver,indx, 2);
465: jac->gridsweeps[1] = indx;
466: }
467: PetscOptionsInt("-pc_hypre_boomeramg_grid_sweeps_coarse","Number of sweeps for the coarse level","None",jac->gridsweeps[2],&indx,&flg);
468: if (flg) {
469: HYPRE_BoomerAMGSetCycleNumSweeps(jac->hsolver,indx, 3);
470: jac->gridsweeps[2] = indx;
471: }
473: /* Relax type */
474: PetscOptionsEList("-pc_hypre_boomeramg_relax_type_all","Relax type for the up and down cycles","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[6],&indx,&flg);
475: if (flg) {
476: jac->relaxtype[0] = jac->relaxtype[1] = indx;
477: HYPRE_BoomerAMGSetRelaxType(jac->hsolver, indx);
478: /* by default, coarse type set to 9 */
479: jac->relaxtype[2] = 9;
480:
481: }
482: PetscOptionsEList("-pc_hypre_boomeramg_relax_type_down","Relax type for the down cycles","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[6],&indx,&flg);
483: if (flg) {
484: jac->relaxtype[0] = indx;
485: HYPRE_BoomerAMGSetCycleRelaxType(jac->hsolver, indx, 1);
486: }
487: PetscOptionsEList("-pc_hypre_boomeramg_relax_type_up","Relax type for the up cycles","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[6],&indx,&flg);
488: if (flg) {
489: jac->relaxtype[1] = indx;
490: HYPRE_BoomerAMGSetCycleRelaxType(jac->hsolver, indx, 2);
491: }
492: PetscOptionsEList("-pc_hypre_boomeramg_relax_type_coarse","Relax type on coarse grid","None",HYPREBoomerAMGRelaxType,10,HYPREBoomerAMGRelaxType[9],&indx,&flg);
493: if (flg) {
494: jac->relaxtype[2] = indx;
495: HYPRE_BoomerAMGSetCycleRelaxType(jac->hsolver, indx, 3);
496: }
498: /* Relaxation Weight */
499: 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);
500: if (flg) {
501: HYPRE_BoomerAMGSetRelaxWt(jac->hsolver,tmpdbl);
502: jac->relaxweight = tmpdbl;
503: }
505: n=2;
506: twodbl[0] = twodbl[1] = 1.0;
507: PetscOptionsRealArray("-pc_hypre_boomeramg_relax_weight_level","Set the relaxation weight for a particular level (weight,level)","None",twodbl, &n, &flg);
508: if (flg) {
509: if (n == 2) {
510: indx = (int)PetscAbsReal(twodbl[1]);
511: HYPRE_BoomerAMGSetLevelRelaxWt(jac->hsolver,twodbl[0],indx);
512: } else {
513: SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Relax weight level: you must provide 2 values separated by a comma (and no space), you provided %d",n);
514: }
515: }
517: /* Outer relaxation Weight */
518: 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);
519: if (flg) {
520: HYPRE_BoomerAMGSetOuterWt( jac->hsolver, tmpdbl);
521: jac->outerrelaxweight = tmpdbl;
522: }
524: n=2;
525: twodbl[0] = twodbl[1] = 1.0;
526: PetscOptionsRealArray("-pc_hypre_boomeramg_outer_relax_weight_level","Set the outer relaxation weight for a particular level (weight,level)","None",twodbl, &n, &flg);
527: if (flg) {
528: if (n == 2) {
529: indx = (int)PetscAbsReal(twodbl[1]);
530: HYPRE_BoomerAMGSetLevelOuterWt( jac->hsolver, twodbl[0], indx);
531: } else {
532: 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);
533: }
534: }
536: /* the Relax Order */
537: PetscOptionsTruth( "-pc_hypre_boomeramg_no_CF", "Do not use CF-relaxation", "None", PETSC_FALSE, &tmp_truth, &flg);
539: if (flg) {
540: jac->relaxorder = 0;
541: HYPRE_BoomerAMGSetRelaxOrder(jac->hsolver, jac->relaxorder);
542: }
543: PetscOptionsEList("-pc_hypre_boomeramg_measure_type","Measure type","None",HYPREBoomerAMGMeasureType,2,HYPREBoomerAMGMeasureType[0],&indx,&flg);
544: if (flg) {
545: jac->measuretype = indx;
546: HYPRE_BoomerAMGSetMeasureType(jac->hsolver,jac->measuretype);
547: }
548: /* update list length 3/07 */
549: PetscOptionsEList("-pc_hypre_boomeramg_coarsen_type","Coarsen type","None",HYPREBoomerAMGCoarsenType,11,HYPREBoomerAMGCoarsenType[6],&indx,&flg);
550: if (flg) {
551: jac->coarsentype = indx;
552: HYPRE_BoomerAMGSetCoarsenType(jac->hsolver,jac->coarsentype);
553: }
554:
555: /* new 3/07 */
556: PetscOptionsEList("-pc_hypre_boomeramg_interp_type","Interpolation type","None",HYPREBoomerAMGInterpType,14,HYPREBoomerAMGInterpType[0],&indx,&flg);
557: if (flg) {
558: jac->interptype = indx;
559: HYPRE_BoomerAMGSetInterpType(jac->hsolver,jac->interptype);
560: }
562: flg = PETSC_FALSE;
563: PetscOptionsTruth("-pc_hypre_boomeramg_print_statistics","Print statistics","None",flg,&flg,PETSC_NULL);
564: if (flg) {
565: int level=3;
566: jac->printstatistics = PETSC_TRUE;
567: PetscOptionsInt("-pc_hypre_boomeramg_print_statistics","Print statistics","None",level,&level,PETSC_NULL);
568: HYPRE_BoomerAMGSetPrintLevel(jac->hsolver,level);
569: }
571: flg = PETSC_FALSE;
572: PetscOptionsTruth("-pc_hypre_boomeramg_print_debug","Print debug information","None",flg,&flg,PETSC_NULL);
573: if (flg) {
574: int level=3;
575: jac->printstatistics = PETSC_TRUE;
576: PetscOptionsInt("-pc_hypre_boomeramg_print_debug","Print debug information","None",level,&level,PETSC_NULL);
577: HYPRE_BoomerAMGSetDebugFlag(jac->hsolver,level);
578: }
580: PetscOptionsTruth( "-pc_hypre_boomeramg_nodal_coarsen", "HYPRE_BoomerAMGSetNodal()", "None", PETSC_FALSE, &tmp_truth, &flg);
581: if (flg && tmp_truth) {
582: jac->nodal_coarsen = 1;
583: HYPRE_BoomerAMGSetNodal(jac->hsolver,1);
584: }
586: PetscOptionsTruth( "-pc_hypre_boomeramg_nodal_relaxation", "Nodal relaxation via Schwarz", "None", PETSC_FALSE, &tmp_truth, &flg);
587: if (flg && tmp_truth) {
588: PetscInt tmp_int;
589: PetscOptionsInt( "-pc_hypre_boomeramg_nodal_relaxation", "Nodal relaxation via Schwarz", "None",jac->nodal_relax_levels,&tmp_int,&flg);
590: if (flg) jac->nodal_relax_levels = tmp_int;
591: HYPRE_BoomerAMGSetSmoothType(jac->hsolver,6);
592: HYPRE_BoomerAMGSetDomainType(jac->hsolver,1);
593: HYPRE_BoomerAMGSetOverlap(jac->hsolver,0);
594: HYPRE_BoomerAMGSetSmoothNumLevels(jac->hsolver,jac->nodal_relax_levels);
595: }
597: PetscOptionsTail();
598: return(0);
599: }
603: static PetscErrorCode PCApplyRichardson_HYPRE_BoomerAMG(PC pc,Vec b,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt its,PetscTruth guesszero,PetscInt *outits,PCRichardsonConvergedReason *reason)
604: {
605: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
607: int oits;
610: HYPRE_BoomerAMGSetMaxIter(jac->hsolver,its*jac->maxiter);
611: HYPRE_BoomerAMGSetTol(jac->hsolver,rtol);
612: jac->applyrichardson = PETSC_TRUE;
613: PCApply_HYPRE(pc,b,y);
614: jac->applyrichardson = PETSC_FALSE;
615: HYPRE_BoomerAMGGetNumIterations(jac->hsolver,&oits);
616: *outits = oits;
617: if (oits == its) *reason = PCRICHARDSON_CONVERGED_ITS;
618: else *reason = PCRICHARDSON_CONVERGED_RTOL;
619: HYPRE_BoomerAMGSetTol(jac->hsolver,jac->tol);
620: HYPRE_BoomerAMGSetMaxIter(jac->hsolver,jac->maxiter);
621: return(0);
622: }
627: static PetscErrorCode PCView_HYPRE_BoomerAMG(PC pc,PetscViewer viewer)
628: {
629: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
631: PetscTruth iascii;
634: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
635: if (iascii) {
636: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG preconditioning\n");
637: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Cycle type %s\n",HYPREBoomerAMGCycleType[jac->cycletype]);
638: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Maximum number of levels %d\n",jac->maxlevels);
639: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Maximum number of iterations PER hypre call %d\n",jac->maxiter);
640: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Convergence tolerance PER hypre call %G\n",jac->tol);
641: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Threshold for strong coupling %G\n",jac->strongthreshold);
642: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Interpolation truncation factor %G\n",jac->truncfactor);
643: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Interpolation: max elements per row %d\n",jac->pmax);
644: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Number of levels of aggressive coarsening %d\n",jac->agg_nl);
645: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Number of paths for aggressive coarsening %d\n",jac->agg_num_paths);
646:
647: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Maximum row sums %G\n",jac->maxrowsum);
649: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Sweeps down %d\n",jac->gridsweeps[0]);
650: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Sweeps up %d\n",jac->gridsweeps[1]);
651: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Sweeps on coarse %d\n",jac->gridsweeps[2]);
653: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Relax down %s\n",HYPREBoomerAMGRelaxType[jac->relaxtype[0]]);
654: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Relax up %s\n",HYPREBoomerAMGRelaxType[jac->relaxtype[1]]);
655: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Relax on coarse %s\n",HYPREBoomerAMGRelaxType[jac->relaxtype[2]]);
657: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Relax weight (all) %G\n",jac->relaxweight);
658: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Outer relax weight (all) %G\n",jac->outerrelaxweight);
660: if (jac->relaxorder) {
661: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Using CF-relaxation\n");
662: } else {
663: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Not using CF-relaxation\n");
664: }
665: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Measure type %s\n",HYPREBoomerAMGMeasureType[jac->measuretype]);
666: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Coarsen type %s\n",HYPREBoomerAMGCoarsenType[jac->coarsentype]);
667: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Interpolation type %s\n",HYPREBoomerAMGInterpType[jac->interptype]);
668: if (jac->nodal_coarsen) {
669: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Using nodal coarsening (with HYPRE_BOOMERAMGSetNodal())\n");
670: }
671: if (jac->nodal_relax) {
672: PetscViewerASCIIPrintf(viewer," HYPRE BoomerAMG: Using nodal relaxation via Schwarz smoothing on levels %d\n",jac->nodal_relax_levels);
673: }
674: }
675: return(0);
676: }
678: /* --------------------------------------------------------------------------------------------*/
681: static PetscErrorCode PCSetFromOptions_HYPRE_ParaSails(PC pc)
682: {
683: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
685: int indx;
686: PetscTruth flag;
687: const char *symtlist[] = {"nonsymmetric","SPD","nonsymmetric,SPD"};
690: PetscOptionsHead("HYPRE ParaSails Options");
691: PetscOptionsInt("-pc_hypre_parasails_nlevels","Number of number of levels","None",jac->nlevels,&jac->nlevels,0);
692: PetscOptionsReal("-pc_hypre_parasails_thresh","Threshold","None",jac->threshhold,&jac->threshhold,&flag);
693: if (flag) {
694: HYPRE_ParaSailsSetParams(jac->hsolver,jac->threshhold,jac->nlevels);
695: }
697: PetscOptionsReal("-pc_hypre_parasails_filter","filter","None",jac->filter,&jac->filter,&flag);
698: if (flag) {
699: HYPRE_ParaSailsSetFilter(jac->hsolver,jac->filter);
700: }
702: PetscOptionsReal("-pc_hypre_parasails_loadbal","Load balance","None",jac->loadbal,&jac->loadbal,&flag);
703: if (flag) {
704: HYPRE_ParaSailsSetLoadbal(jac->hsolver,jac->loadbal);
705: }
707: PetscOptionsTruth("-pc_hypre_parasails_logging","Print info to screen","None",(PetscTruth)jac->logging,(PetscTruth*)&jac->logging,&flag);
708: if (flag) {
709: HYPRE_ParaSailsSetLogging(jac->hsolver,jac->logging);
710: }
712: PetscOptionsTruth("-pc_hypre_parasails_reuse","Reuse nonzero pattern in preconditioner","None",(PetscTruth)jac->ruse,(PetscTruth*)&jac->ruse,&flag);
713: if (flag) {
714: HYPRE_ParaSailsSetReuse(jac->hsolver,jac->ruse);
715: }
717: PetscOptionsEList("-pc_hypre_parasails_sym","Symmetry of matrix and preconditioner","None",symtlist,3,symtlist[0],&indx,&flag);
718: if (flag) {
719: jac->symt = indx;
720: HYPRE_ParaSailsSetSym(jac->hsolver,jac->symt);
721: }
723: PetscOptionsTail();
724: return(0);
725: }
729: static PetscErrorCode PCView_HYPRE_ParaSails(PC pc,PetscViewer viewer)
730: {
731: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
733: PetscTruth iascii;
734: const char *symt = 0;;
737: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
738: if (iascii) {
739: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails preconditioning\n");
740: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: nlevels %d\n",jac->nlevels);
741: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: threshold %G\n",jac->threshhold);
742: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: filter %G\n",jac->filter);
743: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: load balance %G\n",jac->loadbal);
744: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: reuse nonzero structure %s\n",PetscTruths[jac->ruse]);
745: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: print info to screen %s\n",PetscTruths[jac->logging]);
746: if (!jac->symt) {
747: symt = "nonsymmetric matrix and preconditioner";
748: } else if (jac->symt == 1) {
749: symt = "SPD matrix and preconditioner";
750: } else if (jac->symt == 2) {
751: symt = "nonsymmetric matrix but SPD preconditioner";
752: } else {
753: SETERRQ1(PETSC_ERR_ARG_WRONG,"Unknown HYPRE ParaSails symmetric option %d",jac->symt);
754: }
755: PetscViewerASCIIPrintf(viewer," HYPRE ParaSails: %s\n",symt);
756: }
757: return(0);
758: }
759: /* ---------------------------------------------------------------------------------*/
764: PetscErrorCode PCHYPREGetType_HYPRE(PC pc,const char *name[])
765: {
766: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
769: *name = jac->hypre_type;
770: return(0);
771: }
777: PetscErrorCode PCHYPRESetType_HYPRE(PC pc,const char name[])
778: {
779: PC_HYPRE *jac = (PC_HYPRE*)pc->data;
781: PetscTruth flag;
784: if (jac->hypre_type) {
785: PetscStrcmp(jac->hypre_type,name,&flag);
786: if (!flag) SETERRQ(PETSC_ERR_ORDER,"Cannot reset the HYPRE preconditioner type once it has been set");
787: return(0);
788: } else {
789: PetscStrallocpy(name, &jac->hypre_type);
790: }
791:
792: jac->maxiter = PETSC_DEFAULT;
793: jac->tol = PETSC_DEFAULT;
794: jac->printstatistics = PetscLogPrintInfo;
796: PetscStrcmp("pilut",jac->hypre_type,&flag);
797: if (flag) {
798: HYPRE_ParCSRPilutCreate(jac->comm_hypre,&jac->hsolver);
799: pc->ops->setfromoptions = PCSetFromOptions_HYPRE_Pilut;
800: pc->ops->view = PCView_HYPRE_Pilut;
801: jac->destroy = HYPRE_ParCSRPilutDestroy;
802: jac->setup = HYPRE_ParCSRPilutSetup;
803: jac->solve = HYPRE_ParCSRPilutSolve;
804: jac->factorrowsize = PETSC_DEFAULT;
805: return(0);
806: }
807: PetscStrcmp("parasails",jac->hypre_type,&flag);
808: if (flag) {
809: HYPRE_ParaSailsCreate(jac->comm_hypre,&jac->hsolver);
810: pc->ops->setfromoptions = PCSetFromOptions_HYPRE_ParaSails;
811: pc->ops->view = PCView_HYPRE_ParaSails;
812: jac->destroy = HYPRE_ParaSailsDestroy;
813: jac->setup = HYPRE_ParaSailsSetup;
814: jac->solve = HYPRE_ParaSailsSolve;
815: /* initialize */
816: jac->nlevels = 1;
817: jac->threshhold = .1;
818: jac->filter = .1;
819: jac->loadbal = 0;
820: if (PetscLogPrintInfo) {
821: jac->logging = (int) PETSC_TRUE;
822: } else {
823: jac->logging = (int) PETSC_FALSE;
824: }
825: jac->ruse = (int) PETSC_FALSE;
826: jac->symt = 0;
827: HYPRE_ParaSailsSetParams(jac->hsolver,jac->threshhold,jac->nlevels);
828: HYPRE_ParaSailsSetFilter(jac->hsolver,jac->filter);
829: HYPRE_ParaSailsSetLoadbal(jac->hsolver,jac->loadbal);
830: HYPRE_ParaSailsSetLogging(jac->hsolver,jac->logging);
831: HYPRE_ParaSailsSetReuse(jac->hsolver,jac->ruse);
832: HYPRE_ParaSailsSetSym(jac->hsolver,jac->symt);
833: return(0);
834: }
835: PetscStrcmp("euclid",jac->hypre_type,&flag);
836: if (flag) {
837: HYPRE_EuclidCreate(jac->comm_hypre,&jac->hsolver);
838: pc->ops->setfromoptions = PCSetFromOptions_HYPRE_Euclid;
839: pc->ops->view = PCView_HYPRE_Euclid;
840: jac->destroy = HYPRE_EuclidDestroy;
841: jac->setup = HYPRE_EuclidSetup;
842: jac->solve = HYPRE_EuclidSolve;
843: /* initialization */
844: jac->bjilu = PETSC_FALSE;
845: jac->levels = 1;
846: return(0);
847: }
848: PetscStrcmp("boomeramg",jac->hypre_type,&flag);
849: if (flag) {
850: HYPRE_BoomerAMGCreate(&jac->hsolver);
851: pc->ops->setfromoptions = PCSetFromOptions_HYPRE_BoomerAMG;
852: pc->ops->view = PCView_HYPRE_BoomerAMG;
853: pc->ops->applytranspose = PCApplyTranspose_HYPRE_BoomerAMG;
854: pc->ops->applyrichardson = PCApplyRichardson_HYPRE_BoomerAMG;
855: jac->destroy = HYPRE_BoomerAMGDestroy;
856: jac->setup = HYPRE_BoomerAMGSetup;
857: jac->solve = HYPRE_BoomerAMGSolve;
858: jac->applyrichardson = PETSC_FALSE;
859: /* these defaults match the hypre defaults */
860: jac->cycletype = 1;
861: jac->maxlevels = 25;
862: jac->maxiter = 1;
863: jac->tol = 0.0; /* tolerance of zero indicates use as preconditioner (suppresses convergence errors) */
864: jac->truncfactor = 0.0;
865: jac->strongthreshold = .25;
866: jac->maxrowsum = .9;
867: jac->coarsentype = 6;
868: jac->measuretype = 0;
869: jac->gridsweeps[0] = jac->gridsweeps[1] = jac->gridsweeps[2] = 1;
870: jac->relaxtype[0] = jac->relaxtype[1] = 6; /* Defaults to SYMMETRIC since in PETSc we are using a a PC - most likely with CG */
871: jac->relaxtype[2] = 9; /*G.E. */
872: jac->relaxweight = 1.0;
873: jac->outerrelaxweight = 1.0;
874: jac->relaxorder = 1;
875: jac->interptype = 0;
876: jac->agg_nl = 0;
877: jac->pmax = 0;
878: jac->truncfactor = 0.0;
879: jac->agg_num_paths = 1;
881: jac->nodal_coarsen = 0;
882: jac->nodal_relax = PETSC_FALSE;
883: jac->nodal_relax_levels = 1;
884: HYPRE_BoomerAMGSetCycleType(jac->hsolver,jac->cycletype);
885: HYPRE_BoomerAMGSetMaxLevels(jac->hsolver,jac->maxlevels);
886: HYPRE_BoomerAMGSetMaxIter(jac->hsolver,jac->maxiter);
887: HYPRE_BoomerAMGSetTol(jac->hsolver,jac->tol);
888: HYPRE_BoomerAMGSetTruncFactor(jac->hsolver,jac->truncfactor);
889: HYPRE_BoomerAMGSetStrongThreshold(jac->hsolver,jac->strongthreshold);
890: HYPRE_BoomerAMGSetMaxRowSum(jac->hsolver,jac->maxrowsum);
891: HYPRE_BoomerAMGSetCoarsenType(jac->hsolver,jac->coarsentype);
892: HYPRE_BoomerAMGSetMeasureType(jac->hsolver,jac->measuretype);
893: HYPRE_BoomerAMGSetRelaxOrder(jac->hsolver, jac->relaxorder);
894: HYPRE_BoomerAMGSetInterpType(jac->hsolver,jac->interptype);
895: HYPRE_BoomerAMGSetAggNumLevels(jac->hsolver,jac->agg_nl);
896: HYPRE_BoomerAMGSetPMaxElmts(jac->hsolver,jac->pmax);
897: HYPRE_BoomerAMGSetNumPaths(jac->hsolver,jac->agg_num_paths);
898: HYPRE_BoomerAMGSetRelaxType(jac->hsolver, jac->relaxtype[0]); /*defaults coarse to 9*/
899: HYPRE_BoomerAMGSetNumSweeps(jac->hsolver, jac->gridsweeps[0]); /*defaults coarse to 1 */
900: return(0);
901: }
902: PetscStrfree(jac->hypre_type);
903: jac->hypre_type = PETSC_NULL;
904: SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown HYPRE preconditioner %s; Choices are pilut, parasails, euclid, boomeramg",name);
905: return(0);
906: }
909: /*
910: It only gets here if the HYPRE type has not been set before the call to
911: ...SetFromOptions() which actually is most of the time
912: */
915: static PetscErrorCode PCSetFromOptions_HYPRE(PC pc)
916: {
918: int indx;
919: const char *type[] = {"pilut","parasails","boomeramg","euclid"};
920: PetscTruth flg;
923: PetscOptionsHead("HYPRE preconditioner options");
924: PetscOptionsEList("-pc_hypre_type","HYPRE preconditioner type","PCHYPRESetType",type,4,"boomeramg",&indx,&flg);
925: if (flg) {
926: PCHYPRESetType_HYPRE(pc,type[indx]);
927: } else {
928: PCHYPRESetType_HYPRE(pc,"boomeramg");
929: }
930: if (pc->ops->setfromoptions) {
931: pc->ops->setfromoptions(pc);
932: }
933: PetscOptionsTail();
934: return(0);
935: }
939: /*@C
940: PCHYPRESetType - Sets which hypre preconditioner you wish to use
942: Input Parameters:
943: + pc - the preconditioner context
944: - name - either pilut, parasails, boomeramg, euclid
946: Options Database Keys:
947: -pc_hypre_type - One of pilut, parasails, boomeramg, euclid
948:
949: Level: intermediate
951: .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC,
952: PCHYPRE
954: @*/
955: PetscErrorCode PCHYPRESetType(PC pc,const char name[])
956: {
957: PetscErrorCode ierr,(*f)(PC,const char[]);
962: PetscObjectQueryFunction((PetscObject)pc,"PCHYPRESetType_C",(void (**)(void))&f);
963: if (f) {
964: (*f)(pc,name);
965: }
966: return(0);
967: }
971: /*@C
972: PCHYPREGetType - Gets which hypre preconditioner you are using
974: Input Parameter:
975: . pc - the preconditioner context
977: Output Parameter:
978: . name - either pilut, parasails, boomeramg, euclid
980: Level: intermediate
982: .seealso: PCCreate(), PCHYPRESetType(), PCType (for list of available types), PC,
983: PCHYPRE
985: @*/
986: PetscErrorCode PCHYPREGetType(PC pc,const char *name[])
987: {
988: PetscErrorCode ierr,(*f)(PC,const char*[]);
993: PetscObjectQueryFunction((PetscObject)pc,"PCHYPREGetType_C",(void (**)(void))&f);
994: if (f) {
995: (*f)(pc,name);
996: }
997: return(0);
998: }
1000: /*MC
1001: PCHYPRE - Allows you to use the matrix element based preconditioners in the LLNL package hypre
1003: Options Database Keys:
1004: + -pc_hypre_type - One of pilut, parasails, boomeramg, euclid
1005: - Too many others to list, run with -pc_type hypre -pc_hypre_type XXX -help to see options for the XXX
1006: preconditioner
1007:
1008: Level: intermediate
1010: Notes: Apart from pc_hypre_type (for which there is PCHYPRESetType()),
1011: the many hypre options can ONLY be set via the options database (e.g. the command line
1012: or with PetscOptionsSetValue(), there are no functions to set them)
1014: The options -pc_hypre_boomeramg_max_iter and -pc_hypre_boomeramg_rtol refer to the number of iterations
1015: (V-cycles) and tolerance that boomeramg does EACH time it is called. So for example, if
1016: -pc_hypre_boomeramg_max_iter is set to 2 then 2-V-cycles are being used to define the preconditioner
1017: (-pc_hypre_boomeramg_rtol should be set to 0.0 - the default - to strictly use a fixed number of
1018: iterations per hypre call). -ksp_max_it and -ksp_rtol STILL determine the total number of iterations
1019: and tolerance for the Krylov solver. For example, if -pc_hypre_boomeramg_max_iter is 2 and -ksp_max_it is 10
1020: then AT MOST twenty V-cycles of boomeramg will be called.
1022: Note that the option -pc_hypre_boomeramg_relax_type_all defaults to symmetric relaxation
1023: (symmetric-SOR/Jacobi), which is required for Krylov solvers like CG that expect symmetry.
1024: Otherwise, you may want to use -pc_hypre_boomeramg_relax_type_all SOR/Jacobi.
1025: If you wish to use BoomerAMG WITHOUT a Krylov method use -ksp_type richardson NOT -ksp_type preonly
1026: and use -ksp_max_it to control the number of V-cycles.
1027: (see the PETSc FAQ.html at the PETSc website under the Documentation tab).
1029: 2007-02-03 Using HYPRE-1.11.1b, the routine HYPRE_BoomerAMGSolveT and the option
1030: -pc_hypre_parasails_reuse were failing with SIGSEGV. Dalcin L.
1032: See PCPFMG for access to the hypre Struct PFMG solver
1034: .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC,
1035: PCHYPRESetType(), PCPFMG
1037: M*/
1042: PetscErrorCode PCCreate_HYPRE(PC pc)
1043: {
1044: PC_HYPRE *jac;
1048: PetscNewLog(pc,PC_HYPRE,&jac);
1049: pc->data = jac;
1050: pc->ops->destroy = PCDestroy_HYPRE;
1051: pc->ops->setfromoptions = PCSetFromOptions_HYPRE;
1052: pc->ops->setup = PCSetUp_HYPRE;
1053: pc->ops->apply = PCApply_HYPRE;
1054: jac->comm_hypre = MPI_COMM_NULL;
1055: jac->hypre_type = PETSC_NULL;
1056: /* duplicate communicator for hypre */
1057: MPI_Comm_dup(((PetscObject)pc)->comm,&(jac->comm_hypre));
1058: PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPRESetType_C","PCHYPRESetType_HYPRE",PCHYPRESetType_HYPRE);
1059: PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCHYPREGetType_C","PCHYPREGetType_HYPRE",PCHYPREGetType_HYPRE);
1060: return(0);
1061: }
1064: /* ---------------------------------------------------------------------------------------------------------------------------------*/
1066: /* we know we are working with a HYPRE_StructMatrix */
1067: #include ../src/dm/da/utils/mhyp.h
1068: #include private/matimpl.h
1069: #include private/pcimpl.h
1071: typedef struct {
1072: MPI_Comm hcomm; /* does not share comm with HYPRE_StructMatrix because need to create solver before getting matrix */
1073: HYPRE_StructSolver hsolver;
1075: /* keep copy of PFMG options used so may view them */
1076: int its;
1077: double tol;
1078: int relax_type;
1079: int rap_type;
1080: int num_pre_relax,num_post_relax;
1081: int max_levels;
1082: } PC_PFMG;
1086: PetscErrorCode PCDestroy_PFMG(PC pc)
1087: {
1089: PC_PFMG *ex = (PC_PFMG*) pc->data;
1092: if (ex->hsolver) {HYPRE_StructPFMGDestroy(ex->hsolver);}
1093: MPI_Comm_free(&ex->hcomm);
1094: PetscFree(ex);
1095: return(0);
1096: }
1098: static const char *PFMGRelaxType[] = {"Jacobi","Weighted-Jacobi","symmetric-Red/Black-Gauss-Seidel","Red/Black-Gauss-Seidel"};
1099: static const char *PFMGRAPType[] = {"Galerkin","non-Galerkin"};
1103: PetscErrorCode PCView_PFMG(PC pc,PetscViewer viewer)
1104: {
1106: PetscTruth iascii;
1107: PC_PFMG *ex = (PC_PFMG*) pc->data;
1110: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
1111: if (iascii) {
1112: PetscViewerASCIIPrintf(viewer," HYPRE PFMG preconditioning\n");
1113: PetscViewerASCIIPrintf(viewer," HYPRE PFMG: max iterations %d\n",ex->its);
1114: PetscViewerASCIIPrintf(viewer," HYPRE PFMG: tolerance %g\n",ex->tol);
1115: PetscViewerASCIIPrintf(viewer," HYPRE PFMG: relax type %s\n",PFMGRelaxType[ex->relax_type]);
1116: PetscViewerASCIIPrintf(viewer," HYPRE PFMG: RAP type %s\n",PFMGRAPType[ex->rap_type]);
1117: PetscViewerASCIIPrintf(viewer," HYPRE PFMG: number pre-relax %d post-relax %d\n",ex->num_pre_relax,ex->num_post_relax);
1118: PetscViewerASCIIPrintf(viewer," HYPRE PFMG: max levels %d\n",ex->max_levels);
1119: }
1120: return(0);
1121: }
1126: PetscErrorCode PCSetFromOptions_PFMG(PC pc)
1127: {
1129: PC_PFMG *ex = (PC_PFMG*) pc->data;
1130: PetscTruth flg = PETSC_FALSE;
1133: PetscOptionsHead("PFMG options");
1134: PetscOptionsTruth("-pc_pfmg_print_statistics","Print statistics","HYPRE_StructPFMGSetPrintLevel",flg,&flg,PETSC_NULL);
1135: if (flg) {
1136: int level=3;
1137: HYPRE_StructPFMGSetPrintLevel(ex->hsolver,level);
1138: }
1139: PetscOptionsInt("-pc_pfmg_its","Number of iterations of PFMG to use as preconditioner","HYPRE_StructPFMGSetMaxIter",ex->its,&ex->its,PETSC_NULL);
1140: HYPRE_StructPFMGSetMaxIter(ex->hsolver,ex->its);
1141: PetscOptionsInt("-pc_pfmg_num_pre_relax","Number of smoothing steps before coarse grid","HYPRE_StructPFMGSetNumPreRelax",ex->num_pre_relax,&ex->num_pre_relax,PETSC_NULL);
1142: HYPRE_StructPFMGSetNumPreRelax(ex->hsolver,ex->num_pre_relax);
1143: PetscOptionsInt("-pc_pfmg_num_post_relax","Number of smoothing steps after coarse grid","HYPRE_StructPFMGSetNumPostRelax",ex->num_post_relax,&ex->num_post_relax,PETSC_NULL);
1144: HYPRE_StructPFMGSetNumPostRelax(ex->hsolver,ex->num_post_relax);
1146: PetscOptionsInt("-pc_pfmg_max_levels","Max Levels for MG hierarchy","HYPRE_StructPFMGSetMaxLevels",ex->max_levels,&ex->max_levels,PETSC_NULL);
1147: HYPRE_StructPFMGSetMaxLevels(ex->hsolver,ex->max_levels);
1149: PetscOptionsReal("-pc_pfmg_tol","Tolerance of PFMG","HYPRE_StructPFMGSetTol",ex->tol,&ex->tol,PETSC_NULL);
1150: HYPRE_StructPFMGSetTol(ex->hsolver,ex->tol);
1151: PetscOptionsEList("-pc_pfmg_relax_type","Relax type for the up and down cycles","HYPRE_StructPFMGSetRelaxType",PFMGRelaxType,4,PFMGRelaxType[ex->relax_type],&ex->relax_type,PETSC_NULL);
1152: HYPRE_StructPFMGSetRelaxType(ex->hsolver, ex->relax_type);
1153: PetscOptionsEList("-pc_pfmg_rap_type","RAP type","HYPRE_StructPFMGSetRAPType",PFMGRAPType,2,PFMGRAPType[ex->rap_type],&ex->rap_type,PETSC_NULL);
1154: HYPRE_StructPFMGSetRAPType(ex->hsolver, ex->rap_type);
1155: PetscOptionsTail();
1156: return(0);
1157: }
1161: PetscErrorCode PCApply_PFMG(PC pc,Vec x,Vec y)
1162: {
1163: PetscErrorCode ierr;
1164: PC_PFMG *ex = (PC_PFMG*) pc->data;
1165: PetscScalar *xx,*yy;
1166: int ilower[3],iupper[3];
1167: Mat_HYPREStruct *mx = (Mat_HYPREStruct *)(pc->pmat->data);
1170: DAGetCorners(mx->da,&ilower[0],&ilower[1],&ilower[2],&iupper[0],&iupper[1],&iupper[2]);
1171: iupper[0] += ilower[0] - 1;
1172: iupper[1] += ilower[1] - 1;
1173: iupper[2] += ilower[2] - 1;
1175: /* copy x values over to hypre */
1176: HYPRE_StructVectorSetConstantValues(mx->hb,0.0);
1177: VecGetArray(x,&xx);
1178: HYPRE_StructVectorSetBoxValues(mx->hb,ilower,iupper,xx);
1179: VecRestoreArray(x,&xx);
1180: HYPRE_StructVectorAssemble(mx->hb);
1182: HYPRE_StructPFMGSolve(ex->hsolver,mx->hmat,mx->hb,mx->hx);
1184: /* copy solution values back to PETSc */
1185: VecGetArray(y,&yy);
1186: HYPRE_StructVectorGetBoxValues(mx->hx,ilower,iupper,yy);
1187: VecRestoreArray(y,&yy);
1188: return(0);
1189: }
1193: static PetscErrorCode PCApplyRichardson_PFMG(PC pc,Vec b,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt its,PetscTruth guesszero,PetscInt *outits,PCRichardsonConvergedReason *reason)
1194: {
1195: PC_PFMG *jac = (PC_PFMG*)pc->data;
1197: int oits;
1200: HYPRE_StructPFMGSetMaxIter(jac->hsolver,its*jac->its);
1201: HYPRE_StructPFMGSetTol(jac->hsolver,rtol);
1203: PCApply_PFMG(pc,b,y);
1204: HYPRE_StructPFMGGetNumIterations(jac->hsolver,&oits);
1205: *outits = oits;
1206: if (oits == its) *reason = PCRICHARDSON_CONVERGED_ITS;
1207: else *reason = PCRICHARDSON_CONVERGED_RTOL;
1208: HYPRE_StructPFMGSetTol(jac->hsolver,jac->tol);
1209: HYPRE_StructPFMGSetMaxIter(jac->hsolver,jac->its);
1210: return(0);
1211: }
1216: PetscErrorCode PCSetUp_PFMG(PC pc)
1217: {
1218: PetscErrorCode ierr;
1219: PC_PFMG *ex = (PC_PFMG*) pc->data;
1220: Mat_HYPREStruct *mx = (Mat_HYPREStruct *)(pc->pmat->data);
1221: PetscTruth flg;
1224: PetscTypeCompare((PetscObject)pc->pmat,MATHYPRESTRUCT,&flg);
1225: if (!flg) SETERRQ(PETSC_ERR_ARG_INCOMP,"Must use MATHYPRESTRUCT with this preconditioner");
1227: /* create the hypre solver object and set its information */
1228: if (ex->hsolver) {
1229: HYPRE_StructPFMGDestroy(ex->hsolver);
1230: }
1231: HYPRE_StructPFMGCreate(ex->hcomm,&ex->hsolver);
1232: PCSetFromOptions_PFMG(pc);
1233: HYPRE_StructPFMGSetup(ex->hsolver,mx->hmat,mx->hb,mx->hx);
1234: HYPRE_StructPFMGSetZeroGuess(ex->hsolver);
1236: return(0);
1237: }
1240: /*MC
1241: PCPFMG - the hypre PFMG multigrid solver
1243: Level: advanced
1245: Options Database:
1246: + -pc_pfmg_its <its> number of iterations of PFMG to use as preconditioner
1247: . -pc_pfmg_num_pre_relax <steps> number of smoothing steps before coarse grid
1248: . -pc_pfmg_num_post_relax <steps> number of smoothing steps after coarse grid
1249: . -pc_pfmg_tol <tol> tolerance of PFMG
1250: . -pc_pfmg_relax_type -relaxation type for the up and down cycles, one of Jacobi,Weighted-Jacobi,symmetric-Red/Black-Gauss-Seidel,Red/Black-Gauss-Seidel
1251: - -pc_pfmg_rap_type - type of coarse matrix generation, one of Galerkin,non-Galerkin
1253: Notes: This is for CELL-centered descretizations
1255: This must be used with the MATHYPRESTRUCT matrix type.
1256: This is less general than in hypre, it supports only one block per process defined by a PETSc DA.
1258: .seealso: PCMG, MATHYPRESTRUCT
1259: M*/
1264: PetscErrorCode PCCreate_PFMG(PC pc)
1265: {
1267: PC_PFMG *ex;
1270: PetscNew(PC_PFMG,&ex);\
1271: pc->data = ex;
1273: ex->its = 1;
1274: ex->tol = 1.e-8;
1275: ex->relax_type = 1;
1276: ex->rap_type = 0;
1277: ex->num_pre_relax = 1;
1278: ex->num_post_relax = 1;
1279: ex->max_levels = 0;
1281: pc->ops->setfromoptions = PCSetFromOptions_PFMG;
1282: pc->ops->view = PCView_PFMG;
1283: pc->ops->destroy = PCDestroy_PFMG;
1284: pc->ops->apply = PCApply_PFMG;
1285: pc->ops->applyrichardson = PCApplyRichardson_PFMG;
1286: pc->ops->setup = PCSetUp_PFMG;
1287: MPI_Comm_dup(((PetscObject)pc)->comm,&(ex->hcomm));
1288: HYPRE_StructPFMGCreate(ex->hcomm,&ex->hsolver);
1289: return(0);
1290: }
1293: /* we know we are working with a HYPRE_SStructMatrix */
1294: typedef struct {
1295: MPI_Comm hcomm; /* does not share comm with HYPRE_SStructMatrix because need to create solver before getting matrix */
1296: HYPRE_SStructSolver ss_solver;
1298: /* keep copy of SYSPFMG options used so may view them */
1299: int its;
1300: double tol;
1301: int relax_type;
1302: int num_pre_relax,num_post_relax;
1303: } PC_SysPFMG;
1307: PetscErrorCode PCDestroy_SysPFMG(PC pc)
1308: {
1310: PC_SysPFMG *ex = (PC_SysPFMG*) pc->data;
1313: if (ex->ss_solver) {HYPRE_SStructSysPFMGDestroy(ex->ss_solver);}
1314: MPI_Comm_free(&ex->hcomm);
1315: PetscFree(ex);
1316: return(0);
1317: }
1319: static const char *SysPFMGRelaxType[] = {"Weighted-Jacobi","Red/Black-Gauss-Seidel"};
1323: PetscErrorCode PCView_SysPFMG(PC pc,PetscViewer viewer)
1324: {
1326: PetscTruth iascii;
1327: PC_SysPFMG *ex = (PC_SysPFMG*) pc->data;
1330: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
1331: if (iascii) {
1332: PetscViewerASCIIPrintf(viewer," HYPRE SysPFMG preconditioning\n");
1333: PetscViewerASCIIPrintf(viewer," HYPRE SysPFMG: max iterations %d\n",ex->its);
1334: PetscViewerASCIIPrintf(viewer," HYPRE SysPFMG: tolerance %g\n",ex->tol);
1335: PetscViewerASCIIPrintf(viewer," HYPRE SysPFMG: relax type %s\n",PFMGRelaxType[ex->relax_type]);
1336: PetscViewerASCIIPrintf(viewer," HYPRE SysPFMG: number pre-relax %d post-relax %d\n",ex->num_pre_relax,ex->num_post_relax);
1337: }
1338: return(0);
1339: }
1344: PetscErrorCode PCSetFromOptions_SysPFMG(PC pc)
1345: {
1347: PC_SysPFMG *ex = (PC_SysPFMG*) pc->data;
1348: PetscTruth flg = PETSC_FALSE;
1351: PetscOptionsHead("SysPFMG options");
1352: PetscOptionsTruth("-pc_syspfmg_print_statistics","Print statistics","HYPRE_SStructSysPFMGSetPrintLevel",flg,&flg,PETSC_NULL);
1353: if (flg) {
1354: int level=3;
1355: HYPRE_SStructSysPFMGSetPrintLevel(ex->ss_solver,level);
1356: }
1357: PetscOptionsInt("-pc_syspfmg_its","Number of iterations of SysPFMG to use as preconditioner","HYPRE_SStructSysPFMGSetMaxIter",ex->its,&ex->its,PETSC_NULL);
1358: HYPRE_SStructSysPFMGSetMaxIter(ex->ss_solver,ex->its);
1359: PetscOptionsInt("-pc_syspfmg_num_pre_relax","Number of smoothing steps before coarse grid","HYPRE_SStructSysPFMGSetNumPreRelax",ex->num_pre_relax,&ex->num_pre_relax,PETSC_NULL);
1360: HYPRE_SStructSysPFMGSetNumPreRelax(ex->ss_solver,ex->num_pre_relax);
1361: PetscOptionsInt("-pc_syspfmg_num_post_relax","Number of smoothing steps after coarse grid","HYPRE_SStructSysPFMGSetNumPostRelax",ex->num_post_relax,&ex->num_post_relax,PETSC_NULL);
1362: HYPRE_SStructSysPFMGSetNumPostRelax(ex->ss_solver,ex->num_post_relax);
1364: PetscOptionsReal("-pc_syspfmg_tol","Tolerance of SysPFMG","HYPRE_SStructSysPFMGSetTol",ex->tol,&ex->tol,PETSC_NULL);
1365: HYPRE_SStructSysPFMGSetTol(ex->ss_solver,ex->tol);
1366: PetscOptionsEList("-pc_syspfmg_relax_type","Relax type for the up and down cycles","HYPRE_SStructSysPFMGSetRelaxType",SysPFMGRelaxType,4,SysPFMGRelaxType[ex->relax_type],&ex->relax_type,PETSC_NULL);
1367: HYPRE_SStructSysPFMGSetRelaxType(ex->ss_solver, ex->relax_type);
1368: PetscOptionsTail();
1369: return(0);
1370: }
1374: PetscErrorCode PCApply_SysPFMG(PC pc,Vec x,Vec y)
1375: {
1376: PetscErrorCode ierr;
1377: PC_SysPFMG *ex = (PC_SysPFMG*) pc->data;
1378: PetscScalar *xx,*yy;
1379: int ilower[3],iupper[3];
1380: Mat_HYPRESStruct *mx = (Mat_HYPRESStruct *)(pc->pmat->data);
1381: int ordering= mx->dofs_order;
1382: int nvars= mx->nvars;
1383: int part= 0;
1384: int size;
1385: int i;
1388: DAGetCorners(mx->da,&ilower[0],&ilower[1],&ilower[2],&iupper[0],&iupper[1],&iupper[2]);
1389: iupper[0] += ilower[0] - 1;
1390: iupper[1] += ilower[1] - 1;
1391: iupper[2] += ilower[2] - 1;
1393: size= 1;
1394: for (i= 0; i< 3; i++) {
1395: size*= (iupper[i]-ilower[i]+1);
1396: }
1397: /* copy x values over to hypre for variable ordering */
1398: if (ordering) {
1399: HYPRE_SStructVectorSetConstantValues(mx->ss_b,0.0);
1400: VecGetArray(x,&xx);
1401: for (i= 0; i< nvars; i++) {
1402: HYPRE_SStructVectorSetBoxValues(mx->ss_b,part,ilower,iupper,i,xx+(size*i));
1403: }
1404: VecRestoreArray(x,&xx);
1405: HYPRE_SStructVectorAssemble(mx->ss_b);
1407: HYPRE_SStructMatrixMatvec(1.0,mx->ss_mat,mx->ss_b,0.0,mx->ss_x);
1408: HYPRE_SStructSysPFMGSolve(ex->ss_solver,mx->ss_mat,mx->ss_b,mx->ss_x);
1410: /* copy solution values back to PETSc */
1411: VecGetArray(y,&yy);
1412: for (i= 0; i< nvars; i++) {
1413: HYPRE_SStructVectorGetBoxValues(mx->ss_x,part,ilower,iupper,i,yy+(size*i));
1414: }
1415: VecRestoreArray(y,&yy);
1416: }
1418: else { /* nodal ordering must be mapped to variable ordering for sys_pfmg */
1419: PetscScalar *z;
1420: int j, k;
1422: PetscMalloc(nvars*size*sizeof(PetscScalar),&z);
1423: HYPRE_SStructVectorSetConstantValues(mx->ss_b,0.0);
1424: VecGetArray(x,&xx);
1426: /* transform nodal to hypre's variable ordering for sys_pfmg */
1427: for (i= 0; i< size; i++) {
1428: k= i*nvars;
1429: for (j= 0; j< nvars; j++) {
1430: z[j*size+i]= xx[k+j];
1431: }
1432: }
1433: for (i= 0; i< nvars; i++) {
1434: HYPRE_SStructVectorSetBoxValues(mx->ss_b,part,ilower,iupper,i,z+(size*i));
1435: }
1436: VecRestoreArray(x,&xx);
1438: HYPRE_SStructVectorAssemble(mx->ss_b);
1440: HYPRE_SStructSysPFMGSolve(ex->ss_solver,mx->ss_mat,mx->ss_b,mx->ss_x);
1442: /* copy solution values back to PETSc */
1443: VecGetArray(y,&yy);
1444: for (i= 0; i< nvars; i++) {
1445: HYPRE_SStructVectorGetBoxValues(mx->ss_x,part,ilower,iupper,i,z+(size*i));
1446: }
1447: /* transform hypre's variable ordering for sys_pfmg to nodal ordering */
1448: for (i= 0; i< size; i++) {
1449: k= i*nvars;
1450: for (j= 0; j< nvars; j++) {
1451: yy[k+j]= z[j*size+i];
1452: }
1453: }
1454: VecRestoreArray(y,&yy);
1456: PetscFree(z);
1457: }
1459: return(0);
1460: }
1464: static PetscErrorCode PCApplyRichardson_SysPFMG(PC pc,Vec b,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt its,PetscTruth guesszero,PetscInt *outits,PCRichardsonConvergedReason *reason)
1465: {
1466: PC_SysPFMG *jac = (PC_SysPFMG*)pc->data;
1468: int oits;
1472: HYPRE_SStructSysPFMGSetMaxIter(jac->ss_solver,its*jac->its);
1473: HYPRE_SStructSysPFMGSetTol(jac->ss_solver,rtol);
1475: PCApply_SysPFMG(pc,b,y);
1476: HYPRE_SStructSysPFMGGetNumIterations(jac->ss_solver,&oits);
1477: *outits = oits;
1478: if (oits == its) *reason = PCRICHARDSON_CONVERGED_ITS;
1479: else *reason = PCRICHARDSON_CONVERGED_RTOL;
1480: HYPRE_SStructSysPFMGSetTol(jac->ss_solver,jac->tol);
1481: HYPRE_SStructSysPFMGSetMaxIter(jac->ss_solver,jac->its);
1482: return(0);
1483: }
1488: PetscErrorCode PCSetUp_SysPFMG(PC pc)
1489: {
1490: PetscErrorCode ierr;
1491: PC_SysPFMG *ex = (PC_SysPFMG*) pc->data;
1492: Mat_HYPRESStruct *mx = (Mat_HYPRESStruct *)(pc->pmat->data);
1493: PetscTruth flg;
1496: PetscTypeCompare((PetscObject)pc->pmat,MATHYPRESSTRUCT,&flg);
1497: if (!flg) SETERRQ(PETSC_ERR_ARG_INCOMP,"Must use MATHYPRESSTRUCT with this preconditioner");
1499: /* create the hypre sstruct solver object and set its information */
1500: if (ex->ss_solver) {
1501: HYPRE_SStructSysPFMGDestroy(ex->ss_solver);
1502: }
1503: HYPRE_SStructSysPFMGCreate(ex->hcomm,&ex->ss_solver);
1504: PCSetFromOptions_SysPFMG(pc);
1505: HYPRE_SStructSysPFMGSetZeroGuess(ex->ss_solver);
1506: HYPRE_SStructSysPFMGSetup(ex->ss_solver,mx->ss_mat,mx->ss_b,mx->ss_x);
1508: return(0);
1509: }
1512: /*MC
1513: PCSysPFMG - the hypre SysPFMG multigrid solver
1515: Level: advanced
1517: Options Database:
1518: + -pc_syspfmg_its <its> number of iterations of SysPFMG to use as preconditioner
1519: . -pc_syspfmg_num_pre_relax <steps> number of smoothing steps before coarse grid
1520: . -pc_syspfmg_num_post_relax <steps> number of smoothing steps after coarse grid
1521: . -pc_syspfmg_tol <tol> tolerance of SysPFMG
1522: . -pc_syspfmg_relax_type -relaxation type for the up and down cycles, one of Weighted-Jacobi,Red/Black-Gauss-Seidel
1524: Notes: This is for CELL-centered descretizations
1526: This must be used with the MATHYPRESSTRUCT matrix type.
1527: This is less general than in hypre, it supports only one part, and one block per process defined by a PETSc DA.
1528: Also, only cell-centered variables.
1530: .seealso: PCMG, MATHYPRESSTRUCT
1531: M*/
1536: PetscErrorCode PCCreate_SysPFMG(PC pc)
1537: {
1538: PetscErrorCode ierr;
1539: PC_SysPFMG *ex;
1542: PetscNew(PC_SysPFMG,&ex);\
1543: pc->data = ex;
1545: ex->its = 1;
1546: ex->tol = 1.e-8;
1547: ex->relax_type = 1;
1548: ex->num_pre_relax = 1;
1549: ex->num_post_relax = 1;
1551: pc->ops->setfromoptions = PCSetFromOptions_SysPFMG;
1552: pc->ops->view = PCView_SysPFMG;
1553: pc->ops->destroy = PCDestroy_SysPFMG;
1554: pc->ops->apply = PCApply_SysPFMG;
1555: pc->ops->applyrichardson = PCApplyRichardson_SysPFMG;
1556: pc->ops->setup = PCSetUp_SysPFMG;
1557: MPI_Comm_dup(((PetscObject)pc)->comm,&(ex->hcomm));
1558: HYPRE_SStructSysPFMGCreate(ex->hcomm,&ex->ss_solver);
1559: return(0);
1560: }