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 int CallFunction(HYPRE_Solver solver, HYPRE_Solver precond){
147 return int_func_(solver, int_param1_);
148 }
else if(option_ == 1){
149 return double_func_(solver, double_param1_);
150 }
else if(option_ == 2){
151 return double_int_func_(solver, double_param1_, int_param1_);
152 }
else if (option_ == 3){
153 return int_int_func_(solver, int_param1_, int_param2_);
154 }
else if (option_ == 4){
155 return int_star_func_(solver, int_star_param_);
157 return double_star_func_(solver, double_star_param_);
161 return int_func_(precond, int_param1_);
162 }
else if(option_ == 1){
163 return double_func_(precond, double_param1_);
164 }
else if(option_ == 2){
165 return double_int_func_(precond, double_param1_, int_param1_);
166 }
else if(option_ == 3) {
167 return int_int_func_(precond, int_param1_, int_param2_);
168 }
else if(option_ == 4) {
169 return int_star_func_(precond, int_star_param_);
171 return double_star_func_(precond, double_star_param_);
177 Hypre_Chooser chooser_;
179 int (*int_func_)(HYPRE_Solver, int);
180 int (*double_func_)(HYPRE_Solver, double);
181 int (*double_int_func_)(HYPRE_Solver, double, int);
182 int (*int_int_func_)(HYPRE_Solver, int, int);
183 int (*int_star_func_)(HYPRE_Solver,
int*);
184 int (*double_star_func_)(HYPRE_Solver,
double*);
187 double double_param1_;
188 int *int_star_param_;
189 double *double_star_param_;
207 Ifpack_Hypre(Epetra_RowMatrix* A);
210 ~Ifpack_Hypre(){ Destroy();}
227 bool IsComputed()
const{
return(IsComputed_);}
270 int SetParameter(Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int),
int parameter);
281 int SetParameter(Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
double),
double parameter);
293 int SetParameter(Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
double,
int),
double parameter1,
int parameter2);
305 int SetParameter(Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int,
int),
int parameter1,
int parameter2);
316 int SetParameter(Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
double*),
double* parameter);
327 int SetParameter(Hypre_Chooser chooser,
int (*pt2Func)(HYPRE_Solver,
int*),
int* parameter);
339 int SetParameter(Hypre_Chooser chooser, Hypre_Solver
Solver);
350 int SetParameter(
bool UsePreconditioner){ UsePreconditioner_ = UsePreconditioner;
return 0;}
359 int SetParameter(Hypre_Chooser chooser) { SolveOrPrec_ = chooser;
return 0;}
362 int CallFunctions()
const;
374 int SetUseTranspose(
bool UseTranspose_in) {UseTranspose_ = UseTranspose_in;
return(0);};
380 int Apply(
const Epetra_MultiVector& X,
381 Epetra_MultiVector& Y)
const{
return(Multiply(
false,X,Y));}
395 int Multiply(
bool Trans,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const;
411 int ApplyInverse(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const;
415 const int MaxIters = 1550,
416 const double Tol = 1e-9,
417 Epetra_RowMatrix* Matrix_in = 0);
420 double Condest()
const{
return(Condest_);}
426 const char* Label()
const {
return(Label_);}
429 int SetLabel(
const char* Label_in)
431 strcpy(Label_,Label_in);
436 const Epetra_Map& OperatorDomainMap()
const{
return *MySimpleMap_;}
439 const Epetra_Map& OperatorRangeMap()
const{
return *MySimpleMap_;}
442 double NormInf()
const {
return(0.0);};
445 bool HasNormInf()
const {
return(
false);};
448 bool UseTranspose()
const {
return(UseTranspose_);};
451 const Epetra_Comm & Comm()
const{
return(A_->Comm());};
454 const Epetra_RowMatrix&
Matrix()
const{
return(*A_);}
457 const HYPRE_IJMatrix& HypreMatrix()
465 virtual std::ostream&
Print(std::ostream& os)
const;
471 virtual int NumCompute()
const{
return(NumCompute_);}
480 virtual double ComputeTime()
const{
return(ComputeTime_);}
489 virtual double ComputeFlops()
const{
return(ComputeFlops_);}
500 Ifpack_Hypre(
const Ifpack_Hypre&
RHS) : Time_(
RHS.Comm()){}
503 Ifpack_Hypre& operator=(
const Ifpack_Hypre&
RHS){
return(*
this);}
509 MPI_Comm GetMpiComm()
const 510 {
return (dynamic_cast<const Epetra_MpiComm*>(&A_->Comm()))->GetMpiComm();}
523 int Solve(
bool Trans,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const;
527 int NumGlobalRows()
const {
return(A_->NumGlobalRows());};
530 int NumGlobalCols()
const {
return(A_->NumGlobalCols());};
533 int NumMyRows()
const {
return(A_->NumMyRows());};
536 int NumMyCols()
const {
return(A_->NumMyCols());};
539 int SetSolverType(Hypre_Solver solver);
542 int SetPrecondType(Hypre_Solver precond);
551 int AddFunToList(Teuchos::RCP<FunctionParameter> NewFun);
554 int Hypre_BoomerAMGCreate(MPI_Comm comm, HYPRE_Solver *solver)
555 {
return HYPRE_BoomerAMGCreate(solver);}
558 int Hypre_ParaSailsCreate(MPI_Comm comm, HYPRE_Solver *solver)
559 {
return HYPRE_ParaSailsCreate(comm, solver);}
562 int Hypre_EuclidCreate(MPI_Comm comm, HYPRE_Solver *solver)
563 {
return HYPRE_EuclidCreate(comm, solver);}
566 int Hypre_AMSCreate(MPI_Comm comm, HYPRE_Solver *solver)
567 {
return HYPRE_AMSCreate(solver);}
570 int Hypre_ParCSRHybridCreate(MPI_Comm comm, HYPRE_Solver *solver)
571 {
return HYPRE_ParCSRHybridCreate(solver);}
574 int Hypre_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver)
575 {
return HYPRE_ParCSRPCGCreate(comm, solver);}
578 int Hypre_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
579 {
return HYPRE_ParCSRGMRESCreate(comm, solver);}
582 int Hypre_ParCSRFlexGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
583 {
return HYPRE_ParCSRFlexGMRESCreate(comm, solver);}
586 int Hypre_ParCSRLGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
587 {
return HYPRE_ParCSRLGMRESCreate(comm, solver);}
590 int Hypre_ParCSRBiCGSTABCreate(MPI_Comm comm, HYPRE_Solver *solver)
591 {
return HYPRE_ParCSRBiCGSTABCreate(comm, solver);}
597 Teuchos::RefCountPtr<Epetra_RowMatrix> A_;
599 Teuchos::ParameterList List_;
615 mutable int NumApplyInverse_;
617 double InitializeTime_;
621 mutable double ApplyInverseTime_;
623 double ComputeFlops_;
625 mutable double ApplyInverseFlops_;
627 mutable Epetra_Time Time_;
630 mutable HYPRE_IJMatrix HypreA_;
632 mutable HYPRE_ParCSRMatrix ParMatrix_;
634 mutable HYPRE_IJVector XHypre_;
636 mutable HYPRE_IJVector YHypre_;
637 mutable HYPRE_ParVector ParX_;
638 mutable HYPRE_ParVector ParY_;
639 mutable hypre_ParVector *XVec_;
640 mutable hypre_ParVector *YVec_;
641 mutable hypre_Vector *XLocal_;
642 mutable hypre_Vector *YLocal_;
644 mutable HYPRE_Solver Solver_;
646 mutable HYPRE_Solver Preconditioner_;
648 int (Ifpack_Hypre::*SolverCreatePtr_)(MPI_Comm, HYPRE_Solver*);
649 int (*SolverDestroyPtr_)(HYPRE_Solver);
650 int (*SolverSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
651 int (*SolverSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
652 int (*SolverPrecondPtr_)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver);
653 int (Ifpack_Hypre::*PrecondCreatePtr_)(MPI_Comm, HYPRE_Solver*);
654 int (*PrecondDestroyPtr_)(HYPRE_Solver);
655 int (*PrecondSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
656 int (*PrecondSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
658 bool *IsSolverSetup_;
659 bool *IsPrecondSetup_;
661 Hypre_Chooser SolveOrPrec_;
663 Teuchos::RefCountPtr<Epetra_Map> MySimpleMap_;
667 Hypre_Solver SolverType_;
669 Hypre_Solver PrecondType_;
671 bool UsePreconditioner_;
673 std::vector<Teuchos::RCP<FunctionParameter> > FunsToCall_;
virtual int NumInitialize() const =0
Returns the number of calls to Initialize().
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 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 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.
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 int NumCompute() const =0
Returns the number of calls to Compute().
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.
virtual int NumApplyInverse() const =0
Returns the number of calls to ApplyInverse().