16 #ifndef MOAB_HYPRESOLVER
17 #define MOAB_HYPRESOLVER
40 const Eigen::SparseMatrix< double >* m_operator;
47 explicit AbstractSolver(
bool iter_mode )
49 iterative_mode = iter_mode;
53 virtual void SetOperator(
const HypreParMatrix& op ) = 0;
57 class HypreSolver :
public AbstractSolver
60 typedef HypreParVector Vector;
67 mutable HypreParVector *B, *X;
70 mutable int setup_called;
73 HypreSolver(
bool iterative =
true );
75 HypreSolver( HypreParMatrix* _A,
bool iterative =
true );
78 virtual operator HYPRE_Solver()
const = 0;
80 virtual void Verbosity(
int )
85 virtual void SetPreconditioner( HypreSolver& )
90 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const = 0;
92 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const = 0;
94 virtual void SetOperator(
const HypreParMatrix& )
99 virtual void GetFinalResidualNorm(
double& normr ) = 0;
101 virtual void GetNumIterations(
int& num_iterations ) = 0;
104 virtual HYPRE_Int Solve(
const HypreParVector& b, HypreParVector& x )
const;
106 virtual ~HypreSolver();
110 class HyprePCG :
public HypreSolver
113 HYPRE_Solver pcg_solver;
116 HyprePCG( HypreParMatrix& _A );
118 void SetTol(
double tol );
119 void SetMaxIter(
int max_iter );
120 void SetLogging(
int logging );
121 virtual void Verbosity(
int print_lvl );
124 virtual void SetPreconditioner( HypreSolver& precond );
129 void SetResidualConvergenceOptions(
int res_frequency = -1,
double rtol = 0.0 );
132 void SetZeroInintialIterate()
134 iterative_mode =
false;
137 virtual void GetFinalResidualNorm(
double& normr )
139 HYPRE_ParCSRPCGGetFinalRelativeResidualNorm( pcg_solver, &normr );
142 virtual void GetNumIterations(
int& num_iterations )
145 HYPRE_ParCSRPCGGetNumIterations( pcg_solver, &num_it );
146 num_iterations = internal::to_int( num_it );
150 virtual operator HYPRE_Solver()
const
156 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const
158 return (HYPRE_PtrToParSolverFcn)HYPRE_ParCSRPCGSetup;
161 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const
163 return (HYPRE_PtrToParSolverFcn)HYPRE_ParCSRPCGSolve;
167 virtual HYPRE_Int Solve(
const HypreParVector& b, HypreParVector& x )
const;
168 using HypreSolver::Solve;
174 class HypreGMRES :
public HypreSolver
177 HYPRE_Solver gmres_solver;
180 HypreGMRES( HypreParMatrix& _A );
182 void SetTol(
double atol,
double rtol = 1e-20 );
183 void SetMaxIter(
int max_iter );
184 void SetKDim(
int dim );
185 void SetLogging(
int logging );
186 virtual void Verbosity(
int print_lvl );
189 virtual void SetPreconditioner( HypreSolver& precond );
194 void SkipRealResidualCheck()
196 HYPRE_GMRESSetSkipRealResidualCheck( gmres_solver, 1 );
200 void SetZeroInintialIterate()
202 iterative_mode =
false;
205 virtual void GetFinalResidualNorm(
double& normr )
207 HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm( gmres_solver, &normr );
210 virtual void GetNumIterations(
int& num_iterations )
213 HYPRE_GMRESGetNumIterations( gmres_solver, &num_it );
214 num_iterations = internal::to_int( num_it );
218 virtual operator HYPRE_Solver()
const
224 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const
226 return (HYPRE_PtrToParSolverFcn)HYPRE_ParCSRGMRESSetup;
229 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const
231 return (HYPRE_PtrToParSolverFcn)HYPRE_ParCSRGMRESSolve;
235 virtual HYPRE_Int Solve(
const HypreParVector& b, HypreParVector& x )
const;
236 using HypreSolver::Solve;
238 virtual ~HypreGMRES();
242 class HypreIdentity :
public HypreSolver
245 virtual operator HYPRE_Solver()
const
250 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const
252 return (HYPRE_PtrToParSolverFcn)hypre_ParKrylovIdentitySetup;
254 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const
256 return (HYPRE_PtrToParSolverFcn)hypre_ParKrylovIdentity;
259 virtual void GetNumIterations(
int& num_iterations )
264 virtual void GetFinalResidualNorm(
double& normr )
269 virtual ~HypreIdentity() {}
273 class HypreDiagScale :
public HypreSolver
276 HypreDiagScale() : HypreSolver() {}
277 explicit HypreDiagScale( HypreParMatrix& A ) : HypreSolver( &A ) {}
278 virtual operator HYPRE_Solver()
const
283 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const
285 return (HYPRE_PtrToParSolverFcn)HYPRE_ParCSRDiagScaleSetup;
287 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const
289 return (HYPRE_PtrToParSolverFcn)HYPRE_ParCSRDiagScale;
292 virtual void GetNumIterations(
int& num_iterations )
297 virtual void GetFinalResidualNorm(
double& normr )
302 HypreParMatrix* GetData()
306 virtual ~HypreDiagScale() {}
310 class HypreParaSails :
public HypreSolver
313 HYPRE_Solver sai_precond;
316 HypreParaSails( HypreParMatrix& A );
318 void SetSymmetry(
int sym );
320 virtual void GetNumIterations(
int& num_iterations )
325 virtual void GetFinalResidualNorm(
double& normr )
331 virtual operator HYPRE_Solver()
const
336 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const
338 return (HYPRE_PtrToParSolverFcn)HYPRE_ParaSailsSetup;
340 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const
342 return (HYPRE_PtrToParSolverFcn)HYPRE_ParaSailsSolve;
345 virtual ~HypreParaSails();
349 class HypreBoomerAMG :
public HypreSolver
352 HYPRE_Solver amg_precond;
355 void SetDefaultOptions();
360 void ResetAMGPrecond();
365 HypreBoomerAMG( HypreParMatrix& A );
367 virtual void SetOperator(
const HypreParMatrix& op );
369 virtual void GetNumIterations(
int& num_iterations )
374 virtual void GetFinalResidualNorm(
double& normr )
382 void SetSystemsOptions(
int dim );
384 virtual void Verbosity(
int print_level )
386 HYPRE_BoomerAMGSetPrintLevel( amg_precond, print_level );
390 virtual operator HYPRE_Solver()
const
395 virtual HYPRE_PtrToParSolverFcn SetupFcn()
const
397 return (HYPRE_PtrToParSolverFcn)HYPRE_BoomerAMGSetup;
399 virtual HYPRE_PtrToParSolverFcn SolveFcn()
const
401 return (HYPRE_PtrToParSolverFcn)HYPRE_BoomerAMGSolve;
404 virtual ~HypreBoomerAMG();