43 #ifndef IFPACK_HYPRE_H
44 #define IFPACK_HYPRE_H
49 #include "HYPRE_IJ_mv.h"
50 #include "HYPRE_parcsr_ls.h"
52 #include "_hypre_parcsr_mv.h"
53 #include "_hypre_IJ_mv.h"
54 #include "HYPRE_parcsr_mv.h"
59 #include "Epetra_CompObject.h"
60 #include "Epetra_MultiVector.h"
61 #include "Epetra_Vector.h"
62 #include "Epetra_CrsGraph.h"
63 #include "Epetra_CrsMatrix.h"
64 #include "Epetra_BlockMap.h"
65 #include "Epetra_Map.h"
66 #include "Epetra_Object.h"
67 #include "Epetra_Comm.h"
68 #include "Epetra_CrsMatrix.h"
69 #include "Epetra_Time.h"
70 #include "Teuchos_RefCountPtr.hpp"
71 #include "Epetra_MpiComm.h"
97 class FunctionParameter{
100 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
int),
int param1) :
103 int_func_(funct_name),
104 int_param1_(param1) {}
107 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
double),
double param1):
110 double_func_(funct_name),
111 double_param1_(param1) {}
114 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
double,
int),
double param1,
int param2):
117 double_int_func_(funct_name),
119 double_param1_(param1) {}
122 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
int,
int),
int param1,
int param2):
125 int_int_func_(funct_name),
127 int_param2_(param2) {}
130 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
int*),
int *param1):
133 int_star_func_(funct_name),
134 int_star_param_(param1) {}
137 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
double*),
double* param1):
140 double_star_func_(funct_name),
141 double_star_param_(param1) {}
144 FunctionParameter(
Hypre_Chooser chooser,
int (*funct_name)(HYPRE_Solver,
int**),
int ** param1):
147 int_star_star_func_(funct_name),
148 int_star_star_param_(param1) {}
151 int CallFunction(HYPRE_Solver solver, HYPRE_Solver precond){
154 return int_func_(solver, int_param1_);
155 }
else if(option_ == 1){
156 return double_func_(solver, double_param1_);
157 }
else if(option_ == 2){
158 return double_int_func_(solver, double_param1_, int_param1_);
159 }
else if (option_ == 3){
160 return int_int_func_(solver, int_param1_, int_param2_);
161 }
else if (option_ == 4){
162 return int_star_func_(solver, int_star_param_);
163 }
else if (option_ == 5){
164 return double_star_func_(solver, double_star_param_);
166 return int_star_star_func_(solver,int_star_star_param_);
170 return int_func_(precond, int_param1_);
171 }
else if(option_ == 1){
172 return double_func_(precond, double_param1_);
173 }
else if(option_ == 2){
174 return double_int_func_(precond, double_param1_, int_param1_);
175 }
else if(option_ == 3) {
176 return int_int_func_(precond, int_param1_, int_param2_);
177 }
else if(option_ == 4) {
178 return int_star_func_(precond, int_star_param_);
179 }
else if (option_ == 5){
180 return double_star_func_(precond, double_star_param_);
182 return int_star_star_func_(precond,int_star_star_param_);
190 int (*int_func_)(HYPRE_Solver, int);
191 int (*double_func_)(HYPRE_Solver, double);
192 int (*double_int_func_)(HYPRE_Solver, double, int);
193 int (*int_int_func_)(HYPRE_Solver, int, int);
194 int (*int_star_func_)(HYPRE_Solver,
int*);
195 int (*double_star_func_)(HYPRE_Solver,
double*);
196 int (*int_star_star_func_)(HYPRE_Solver,
int **);
199 double double_param1_;
200 int *int_star_param_;
201 double *double_star_param_;
202 int ** int_star_star_param_;
223 ~Ifpack_Hypre(){ Destroy();}
240 bool IsComputed()
const{
return(IsComputed_);}
283 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int),
int parameter);
294 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
double),
double parameter);
306 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
double,
int),
double parameter1,
int parameter2);
318 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int,
int),
int parameter1,
int parameter2);
329 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
double*),
double* parameter);
340 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int*),
int* parameter);
352 int SetParameter(
Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int**),
int** parameter);
375 int SetParameter(
bool UsePreconditioner){ UsePreconditioner_ = UsePreconditioner;
return 0;}
384 int SetParameter(
Hypre_Chooser chooser) { SolveOrPrec_ = chooser;
return 0;}
387 int CallFunctions()
const;
399 int SetUseTranspose(
bool UseTranspose_in) {UseTranspose_ = UseTranspose_in;
return(0);};
440 const int MaxIters = 1550,
441 const double Tol = 1e-9,
445 double Condest()
const{
return(Condest_);}
451 const char*
Label()
const {
return(Label_);}
454 int SetLabel(
const char* Label_in)
456 strcpy(Label_,Label_in);
467 double NormInf()
const {
return(0.0);};
482 const HYPRE_IJMatrix& HypreMatrix()
490 virtual std::ostream&
Print(std::ostream& os)
const;
496 virtual int NumCompute()
const{
return(NumCompute_);}
505 virtual double ComputeTime()
const{
return(ComputeTime_);}
514 virtual double ComputeFlops()
const{
return(ComputeFlops_);}
525 Ifpack_Hypre(
const Ifpack_Hypre&
RHS) : Time_(RHS.Comm()){}
528 Ifpack_Hypre& operator=(
const Ifpack_Hypre& ){
return(*
this);}
534 MPI_Comm GetMpiComm()
const
535 {
return (dynamic_cast<const Epetra_MpiComm*>(&A_->Comm()))->GetMpiComm();}
552 int NumGlobalRows()
const {
return(A_->NumGlobalRows());};
555 int NumGlobalCols()
const {
return(A_->NumGlobalCols());};
558 int NumMyRows()
const {
return(A_->NumMyRows());};
561 int NumMyCols()
const {
return(A_->NumMyCols());};
576 int CopyEpetraToHypre();
582 int Hypre_BoomerAMGCreate(MPI_Comm , HYPRE_Solver *solver)
583 {
return HYPRE_BoomerAMGCreate(solver);}
586 int Hypre_ParaSailsCreate(MPI_Comm comm, HYPRE_Solver *solver)
587 {
return HYPRE_ParaSailsCreate(comm, solver);}
590 int Hypre_EuclidCreate(MPI_Comm comm, HYPRE_Solver *solver)
591 {
return HYPRE_EuclidCreate(comm, solver);}
594 int Hypre_AMSCreate(MPI_Comm , HYPRE_Solver *solver)
595 {
return HYPRE_AMSCreate(solver);}
598 int Hypre_ParCSRHybridCreate(MPI_Comm , HYPRE_Solver *solver)
599 {
return HYPRE_ParCSRHybridCreate(solver);}
602 int Hypre_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver)
603 {
return HYPRE_ParCSRPCGCreate(comm, solver);}
606 int Hypre_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
607 {
return HYPRE_ParCSRGMRESCreate(comm, solver);}
610 int Hypre_ParCSRFlexGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
611 {
return HYPRE_ParCSRFlexGMRESCreate(comm, solver);}
614 int Hypre_ParCSRLGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
615 {
return HYPRE_ParCSRLGMRESCreate(comm, solver);}
618 int Hypre_ParCSRBiCGSTABCreate(MPI_Comm comm, HYPRE_Solver *solver)
619 {
return HYPRE_ParCSRBiCGSTABCreate(comm, solver);}
625 Teuchos::RefCountPtr<Epetra_RowMatrix> A_;
643 mutable int NumApplyInverse_;
645 double InitializeTime_;
649 mutable double ApplyInverseTime_;
651 double ComputeFlops_;
653 mutable double ApplyInverseFlops_;
658 mutable HYPRE_IJMatrix HypreA_;
660 mutable HYPRE_ParCSRMatrix ParMatrix_;
662 mutable HYPRE_IJVector XHypre_;
664 mutable HYPRE_IJVector YHypre_;
665 mutable HYPRE_ParVector ParX_;
666 mutable HYPRE_ParVector ParY_;
667 mutable hypre_ParVector *XVec_;
668 mutable hypre_ParVector *YVec_;
669 mutable hypre_Vector *XLocal_;
670 mutable hypre_Vector *YLocal_;
672 mutable HYPRE_Solver Solver_;
674 mutable HYPRE_Solver Preconditioner_;
676 int (Ifpack_Hypre::*SolverCreatePtr_)(MPI_Comm, HYPRE_Solver*);
677 int (*SolverDestroyPtr_)(HYPRE_Solver);
678 int (*SolverSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
679 int (*SolverSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
680 int (*SolverPrecondPtr_)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver);
681 int (Ifpack_Hypre::*PrecondCreatePtr_)(MPI_Comm, HYPRE_Solver*);
682 int (*PrecondDestroyPtr_)(HYPRE_Solver);
683 int (*PrecondSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
684 int (*PrecondSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
686 bool *IsSolverSetup_;
687 bool *IsPrecondSetup_;
700 bool UsePreconditioner_;
702 std::vector<Teuchos::RCP<FunctionParameter> > FunsToCall_;
virtual int NumInitialize() const =0
Returns the number of calls to Initialize().
virtual int SetUseTranspose(bool UseTranspose)=0
virtual double ComputeTime() const =0
Returns the time spent in Compute().
virtual double ComputeFlops() const =0
Returns the number of flops in the computation phase.
virtual double ApplyInverseTime() const =0
Returns the time spent in ApplyInverse().
virtual double ApplyInverseFlops() const =0
Returns the number of flops in the application of the preconditioner.
virtual const Epetra_RowMatrix & Matrix() const =0
Returns a pointer to the matrix to be preconditioned.
virtual bool IsInitialized() const =0
Returns true if the preconditioner has been successfully initialized, false otherwise.
virtual std::ostream & Print(std::ostream &os) const =0
Prints basic information on iostream. This function is used by operator<<.
virtual const Epetra_Map & OperatorDomainMap() const =0
virtual const char * Label() const =0
virtual int Initialize()=0
Computes all it is necessary to initialize the preconditioner.
virtual double InitializeTime() const =0
Returns the time spent in Initialize().
Ifpack_CondestType
Ifpack_CondestType: enum to define the type of condition number estimate.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
virtual const Epetra_Map & OperatorRangeMap() const =0
virtual const Epetra_Comm & Comm() const =0
virtual int SetParameters(Teuchos::ParameterList &List)=0
Sets all parameters for the preconditioner.
virtual double Condest() const =0
Returns the computed condition number estimate, or -1.0 if not computed.
virtual bool UseTranspose() const =0
Ifpack_ScalingType enumerable type.
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
Applies the preconditioner to vector X, returns the result in Y.
virtual double InitializeFlops() const =0
Returns the number of flops in the initialization phase.
void BiCGSTAB(Epetra_CrsMatrix &A, Epetra_Vector &x, Epetra_Vector &b, Ifpack_CrsRiluk *M, int Maxiter, double Tolerance, double *residual, bool verbose)
virtual bool HasNormInf() const =0
virtual int NumCompute() const =0
Returns the number of calls to Compute().
virtual double NormInf() const =0
virtual bool IsComputed() const =0
Returns true if the preconditioner has been successfully computed, false otherwise.
virtual int Compute()=0
Computes all it is necessary to apply the preconditioner.
int Solve(int, TYPE *, TYPE *, TYPE *)
virtual int NumApplyInverse() const =0
Returns the number of calls to ApplyInverse().