00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef EPETRAEXT_HYPREIJMATRIX_H_
00030 #define EPETRAEXT_HYPREIJMATRIX_H_
00031
00032
00033 #include "Epetra_Object.h"
00034 #include "Epetra_CompObject.h"
00035 #include "Epetra_BasicRowMatrix.h"
00036 #include "Epetra_Map.h"
00037 #include "Epetra_Import.h"
00038 #include "Epetra_MpiComm.h"
00039
00040
00041 #include "krylov.h"
00042 #include "HYPRE_parcsr_ls.h"
00043 #include "_hypre_parcsr_mv.h"
00044 #include "HYPRE_parcsr_mv.h"
00045 #include "HYPRE_IJ_mv.h"
00046 #include "_hypre_IJ_mv.h"
00047 #include "HYPRE.h"
00048
00049 class Epetra_Vector;
00050 class Epetra_MultiVector;
00051 class Epetra_Import;
00052
00054
00061 #ifndef HYPRE_ENUMS
00062 #define HYPRE_ENUMS
00064
00066 enum Hypre_Solver{
00067 BoomerAMG,
00068 ParaSails,
00069 Euclid,
00070 AMS,
00071 Hybrid,
00072 PCG,
00073 GMRES,
00074 FlexGMRES,
00075 LGMRES,
00076 BiCGSTAB
00077 };
00078
00080 enum Hypre_Chooser{
00081 Solver,
00082 Preconditioner
00083 };
00084 #endif //HYPRE_ENUMS
00085
00086 class EpetraExt_HypreIJMatrix: public Epetra_BasicRowMatrix {
00087
00088 public:
00089
00091
00092
00093
00097 EpetraExt_HypreIJMatrix(HYPRE_IJMatrix matrix);
00098
00100 virtual ~EpetraExt_HypreIJMatrix();
00102
00104
00105
00107
00116 int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
00117
00119
00128 int ExtractMyEntryView(int CurEntry, double *&Value, int &RowIndex, int &ColIndex);
00129
00131
00140 int ExtractMyEntryView(int CurEntry, const double *&Value, int &RowIndex, int &ColIndex) const;
00142
00144
00145
00147
00155 int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, int), int parameter);
00156
00158
00166 int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, double), double parameter);
00167
00169
00178 int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, double, int), double parameter1, int parameter2);
00179
00181
00190 int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, int, int), int parameter1, int parameter2);
00191
00193
00201 int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, double*), double* parameter);
00202
00204
00212 int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, int*), int* parameter);
00213
00215
00225 int SetParameter(Hypre_Chooser chooser, Hypre_Solver Solver, bool transpose=false);
00226
00228
00236 int SetParameter(bool UsePreconditioner);
00237
00239
00245 int SetParameter(Hypre_Chooser chooser);
00247
00248
00249
00251
00258 int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00259
00261
00271 int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00272
00274
00280 int LeftScale(const Epetra_Vector& X);
00281
00282
00284
00290 int RightScale(const Epetra_Vector& X);
00292
00294
00295
00297
00303 int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
00304 return(EpetraExt_HypreIJMatrix::Multiply(EpetraExt_HypreIJMatrix::UseTranspose(), X, Y));};
00305
00307
00318 int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
00319 return(EpetraExt_HypreIJMatrix::Solve(EpetraExt_HypreIJMatrix::UpperTriangular(), EpetraExt_HypreIJMatrix::UseTranspose(), false, X, Y));};
00320
00322 virtual bool UseTranspose() const {return(false);}
00323
00325
00326
00327
00329
00336 int NumMyRowEntries(int MyRow, int & NumEntries) const;
00337
00339 HYPRE_IJMatrix& GetMatrix(){ return Matrix_;}
00340
00342 protected:
00343
00345 int InitializeDefaults();
00346
00347
00348
00350 int Hypre_BoomerAMGCreate(MPI_Comm comm, HYPRE_Solver *solver)
00351 { return HYPRE_BoomerAMGCreate(solver);}
00352
00354 int Hypre_ParaSailsCreate(MPI_Comm comm, HYPRE_Solver *solver)
00355 { return HYPRE_ParaSailsCreate(comm, solver);}
00356
00358 int Hypre_EuclidCreate(MPI_Comm comm, HYPRE_Solver *solver)
00359 { return HYPRE_EuclidCreate(comm, solver);}
00360
00362 int Hypre_AMSCreate(MPI_Comm comm, HYPRE_Solver *solver)
00363 { return HYPRE_AMSCreate(solver);}
00364
00366 int Hypre_ParCSRHybridCreate(MPI_Comm comm, HYPRE_Solver *solver)
00367 { return HYPRE_ParCSRHybridCreate(solver);}
00368
00370 int Hypre_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver)
00371 { return HYPRE_ParCSRPCGCreate(comm, solver);}
00372
00374 int Hypre_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
00375 { return HYPRE_ParCSRGMRESCreate(comm, solver);}
00376
00378 int Hypre_ParCSRFlexGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
00379 { return HYPRE_ParCSRFlexGMRESCreate(comm, solver);}
00380
00382 int Hypre_ParCSRLGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
00383 { return HYPRE_ParCSRLGMRESCreate(comm, solver);}
00384
00386 int Hypre_ParCSRBiCGSTABCreate(MPI_Comm comm, HYPRE_Solver *solver)
00387 { return HYPRE_ParCSRBiCGSTABCreate(comm, solver);}
00388
00390 int CreateSolver();
00392 int CreatePrecond();
00393
00394
00395
00396 int SetupSolver() const;
00397 int SetupPrecond() const;
00398
00399
00400 mutable HYPRE_IJMatrix Matrix_;
00401 mutable HYPRE_ParCSRMatrix ParMatrix_;
00402 mutable HYPRE_IJVector X_hypre;
00403 mutable HYPRE_IJVector Y_hypre;
00404 mutable HYPRE_ParVector par_x;
00405 mutable HYPRE_ParVector par_y;
00406 mutable hypre_ParVector *x_vec;
00407 mutable hypre_ParVector *y_vec;
00408 mutable hypre_Vector *x_local;
00409 mutable hypre_Vector *y_local;
00410 mutable HYPRE_Solver Solver_;
00411 mutable HYPRE_Solver Preconditioner_;
00412
00413 int (EpetraExt_HypreIJMatrix::*SolverCreatePtr_)(MPI_Comm, HYPRE_Solver*);
00414 int (*SolverDestroyPtr_)(HYPRE_Solver);
00415 int (*SolverSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
00416 int (*SolverSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
00417 int (*SolverPrecondPtr_)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver);
00418 int (EpetraExt_HypreIJMatrix::*PrecondCreatePtr_)(MPI_Comm, HYPRE_Solver*);
00419 int (*PrecondDestroyPtr_)(HYPRE_Solver);
00420 int (*PrecondSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
00421 int (*PrecondSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
00422
00424 int NumMyRows_;
00426 int NumGlobalRows_;
00428 int NumGlobalCols_;
00430 int MyRowStart_;
00432 int MyRowEnd_;
00434 mutable int MatType_;
00436 bool TransposeSolve_;
00438 Hypre_Chooser SolveOrPrec_;
00440 bool *IsSolverSetup_;
00442 bool *IsPrecondSetup_;
00443 };
00444 #endif