57 BoomerAMG(Op& op,
int steps_=1,
int coarsentype=21,
int interpoltype=0,
double tol=1.0e-8,
58 int cycleType=1,
int relaxType=2,
double strongThreshold=0.3,
59 int variant=0,
int overlap=1,
int syseqn=1,
int verbosity_=2)
60 : op(op), steps(steps_), verbosity(verbosity_), eqnIndex(0)
62 static char main[] =
"main";
67 std::vector<int> Ap, Ai;
68 std::vector<double> Az;
73 std::cout <<
"HYPRE_BoomerAMG: n=" << n <<
", nnz=" << nnz <<
75 ", coarsentype=" << coarsentype <<
", interpolationtype=" <<
78 Ap.resize(n+1); Ai.resize(nnz); Az.resize(nnz);
81 for (
int i=0;i<n;i++) Ap[i]=Ap[i+1]-Ap[i];
82 ixx = (
int *)Malloc(n*
sizeof(
int), main);
83 for (
int i=0;i<n;i++) ixx[i]=i;
85 HYPRE_IJMatrixCreate(0, 0, n-1, 0, n-1, &ij_matrix);
86 HYPRE_IJMatrixSetPrintLevel(ij_matrix,10);
87 HYPRE_IJMatrixSetObjectType(ij_matrix, HYPRE_PARCSR);
88 HYPRE_IJMatrixInitialize(ij_matrix);
90 HYPRE_IJMatrixSetValues(ij_matrix,n,&Ap[0],ixx,&Ai[0],&Az[0]);
91 HYPRE_IJMatrixAssemble(ij_matrix);
92 HYPRE_IJMatrixGetObject(ij_matrix, (
void **) &parcsr_matrix);
94 HYPRE_BoomerAMGCreate(&preconditioner);
95 HYPRE_BoomerAMGSetPrintLevel(preconditioner,1);
96 HYPRE_BoomerAMGSetCoarsenType(preconditioner,coarsentype);
97 HYPRE_BoomerAMGSetInterpType(preconditioner,interpoltype);
98 HYPRE_BoomerAMGSetMaxIter(preconditioner,steps);
99 HYPRE_BoomerAMGSetTol(preconditioner,tol);
100 HYPRE_BoomerAMGSetStrongThreshold(preconditioner, strongThreshold);
101 HYPRE_BoomerAMGSetCycleType(preconditioner, cycleType);
102 HYPRE_BoomerAMGSetRelaxType(preconditioner, relaxType);
103 HYPRE_BoomerAMGSetVariant (preconditioner, variant);
104 HYPRE_BoomerAMGSetOverlap (preconditioner, overlap) ;
107 HYPRE_BoomerAMGSetNodal(preconditioner, 1);
108 HYPRE_BoomerAMGSetNumFunctions(preconditioner, syseqn);
109 int i, k, lng = n/syseqn;
110 eqnIndex = (
int *)Malloc(n*
sizeof(
int), main);
111 for (i=0; i<syseqn; i++)
112 for (k=0; k<lng; k++)
113 eqnIndex[i*lng+k] = i;
115 HYPRE_BoomerAMGSetDofFunc(preconditioner, eqnIndex);
118 HYPRE_BoomerAMGSetup(preconditioner,parcsr_matrix,0,0);
120 xxraw = (
double *)Malloc(n*
sizeof(
double), main);
121 yyraw = (
double *)Malloc(n*
sizeof(
double), main);
123 HYPRE_IJVectorCreate(0, 0, n-1, &xxij);
124 HYPRE_IJVectorSetPrintLevel(xxij,10);
125 HYPRE_IJVectorSetObjectType(xxij, HYPRE_PARCSR);
126 HYPRE_IJVectorInitialize(xxij);
127 HYPRE_IJVectorAssemble(xxij);
128 HYPRE_IJVectorGetObject(xxij, (
void **) &xx);
130 HYPRE_IJVectorCreate(0, 0, n-1, &yyij);
131 HYPRE_IJVectorSetPrintLevel(yyij,10);
132 HYPRE_IJVectorSetObjectType(yyij, HYPRE_PARCSR);
133 HYPRE_IJVectorInitialize(yyij);
134 HYPRE_IJVectorAssemble(yyij);
135 HYPRE_IJVectorGetObject(yyij, (
void **) &yy);
152 virtual void apply (domain_type& x, range_type
const& y) {
155 for (
int i=0; i<n; i++)
158 HYPRE_IJVectorSetValues(yyij, n, ixx, yyraw);
159 HYPRE_IJVectorSetValues(xxij, n, ixx, xxraw);
160 HYPRE_BoomerAMGSolve(preconditioner,parcsr_matrix,yy,xx);
164 double rel_resid_norm;
165 HYPRE_BoomerAMGGetNumIterations (preconditioner,&num_iterations);
166 HYPRE_BoomerAMGGetFinalRelativeResidualNorm (preconditioner, &rel_resid_norm);
169 std::cout <<
"HYPRE_BoomerAMG1: " << num_iterations <<
" steps, rel_resid_norm="
170 << rel_resid_norm <<
'\n';
173 HYPRE_IJVectorGetValues(xxij,n,ixx,xxraw);