EpetraExt Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_HypreIJMatrix.h
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 
42 #ifndef EPETRAEXT_HYPREIJMATRIX_H_
43 #define EPETRAEXT_HYPREIJMATRIX_H_
44 
45 // Trilinos source files
46 #include "Epetra_Object.h"
47 #include "Epetra_CompObject.h"
48 #include "Epetra_BasicRowMatrix.h"
49 #include "Epetra_Map.h"
50 #include "Epetra_Import.h"
51 #include "Epetra_MpiComm.h"
52 
53 //Hypre source files
54 #include "krylov.h"
55 #include "HYPRE_parcsr_ls.h"
56 #include "_hypre_parcsr_mv.h"
57 #include "HYPRE_parcsr_mv.h"
58 #include "HYPRE_IJ_mv.h"
59 #include "_hypre_IJ_mv.h"
60 #include "HYPRE.h"
61 
62 class Epetra_Vector;
63 class Epetra_MultiVector;
64 class Epetra_Import;
65 
67 
74 #ifndef HYPRE_ENUMS
75 #define HYPRE_ENUMS
76 
79  enum Hypre_Solver{
83  AMS,
85  PCG,
90  };
91 
96  };
97 #endif //HYPRE_ENUMS
98 
100 
101 public:
102 
104 
105 
110  EpetraExt_HypreIJMatrix(HYPRE_IJMatrix matrix);
111 
113  virtual ~EpetraExt_HypreIJMatrix();
115 
117 
118 
120 
129  int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, double *Values, int * Indices) const;
130 
132 
141  int ExtractMyEntryView(int CurEntry, double *&Value, int &RowIndex, int &ColIndex);
142 
144 
153  int ExtractMyEntryView(int CurEntry, const double *&Value, int &RowIndex, int &ColIndex) const;
155 
157 
158 
160 
168  int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, int), int parameter);
169 
171 
179  int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, double), double parameter);
180 
182 
191  int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, double, int), double parameter1, int parameter2);
192 
194 
203  int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, int, int), int parameter1, int parameter2);
204 
206 
214  int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, double*), double* parameter);
215 
217 
225  int SetParameter(Hypre_Chooser chooser, int (*pt2Func)(HYPRE_Solver, int*), int* parameter);
226 
228 
238  int SetParameter(Hypre_Chooser chooser, Hypre_Solver Solver, bool transpose=false);
239 
241 
249  int SetParameter(bool UsePreconditioner);
250 
252 
258  int SetParameter(Hypre_Chooser chooser);
260 
262 
264 
271  int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
272 
274 
284  int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
285 
287 
293  int LeftScale(const Epetra_Vector& X);
294 
295 
297 
303  int RightScale(const Epetra_Vector& X);
305 
307 
308 
310 
316  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
318 
320 
333 
335  virtual bool UseTranspose() const {return(false);}
336 
338 
340 
342 
349  int NumMyRowEntries(int MyRow, int & NumEntries) const;
350 
352  HYPRE_IJMatrix& GetMatrix(){ return Matrix_;}
353 
355 protected:
356 
358  int InitializeDefaults();
359 
360  // These methods are needed only because the create methods in Hypre sometimes take an MPI_Comm but not always.
361  // They simply call the create solver in the correct way.
363  int Hypre_BoomerAMGCreate(MPI_Comm comm, HYPRE_Solver *solver)
364  { return HYPRE_BoomerAMGCreate(solver);}
365 
367  int Hypre_ParaSailsCreate(MPI_Comm comm, HYPRE_Solver *solver)
368  { return HYPRE_ParaSailsCreate(comm, solver);}
369 
371  int Hypre_EuclidCreate(MPI_Comm comm, HYPRE_Solver *solver)
372  { return HYPRE_EuclidCreate(comm, solver);}
373 
375  int Hypre_AMSCreate(MPI_Comm comm, HYPRE_Solver *solver)
376  { return HYPRE_AMSCreate(solver);}
377 
379  int Hypre_ParCSRHybridCreate(MPI_Comm comm, HYPRE_Solver *solver)
380  { return HYPRE_ParCSRHybridCreate(solver);}
381 
383  int Hypre_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver)
384  { return HYPRE_ParCSRPCGCreate(comm, solver);}
385 
387  int Hypre_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
388  { return HYPRE_ParCSRGMRESCreate(comm, solver);}
389 
391  int Hypre_ParCSRFlexGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
392  { return HYPRE_ParCSRFlexGMRESCreate(comm, solver);}
393 
395  int Hypre_ParCSRLGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
396  { return HYPRE_ParCSRLGMRESCreate(comm, solver);}
397 
399  int Hypre_ParCSRBiCGSTABCreate(MPI_Comm comm, HYPRE_Solver *solver)
400  { return HYPRE_ParCSRBiCGSTABCreate(comm, solver);}
401 
403  int CreateSolver();
405  int CreatePrecond();
406  // These two methods setup the solver or preconditioner by calling the pointer.
407  // They are const because they are called from the Solve() routine.
408  // They really aren't const because they change the value of IsSolverSetup_. This is because it should only be called if it isn't setup.
409  int SetupSolver() const;
410  int SetupPrecond() const;
411 
412  // Hypre variables
413  mutable HYPRE_IJMatrix Matrix_;
414  mutable HYPRE_ParCSRMatrix ParMatrix_;
415  mutable HYPRE_IJVector X_hypre;
416  mutable HYPRE_IJVector Y_hypre;
417  mutable HYPRE_ParVector par_x;
418  mutable HYPRE_ParVector par_y;
419  mutable hypre_ParVector *x_vec;
420  mutable hypre_ParVector *y_vec;
421  mutable hypre_Vector *x_local;
422  mutable hypre_Vector *y_local;
423  mutable HYPRE_Solver Solver_;
424  mutable HYPRE_Solver Preconditioner_;
425  // The following are pointers to functions to use the solver and preconditioner.
426  int (EpetraExt_HypreIJMatrix::*SolverCreatePtr_)(MPI_Comm, HYPRE_Solver*);
427  int (*SolverDestroyPtr_)(HYPRE_Solver);
428  int (*SolverSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
429  int (*SolverSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
430  int (*SolverPrecondPtr_)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver);
431  int (EpetraExt_HypreIJMatrix::*PrecondCreatePtr_)(MPI_Comm, HYPRE_Solver*);
432  int (*PrecondDestroyPtr_)(HYPRE_Solver);
433  int (*PrecondSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
434  int (*PrecondSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector);
435 
447  mutable int MatType_;
456 };
457 #endif /* EPETRAEXT_HYPREIJMATRIX_H_ */
int ExtractMyEntryView(int CurEntry, double *&Value, int &RowIndex, int &ColIndex)
Returns a reference to the ith entry in the matrix, along with its row and column index...
int Hypre_ParCSRLGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
LGMRES Create passing function.
bool * IsSolverSetup_
Flag to know if solver needs to be destoyed.
virtual ~EpetraExt_HypreIJMatrix()
EpetraExt_HypreIJMatrix Destructor.
int LeftScale(const Epetra_Vector &X)
Scales the EpetraExt_HypreIJMatrix on the left with a Epetra_Vector x.
int InitializeDefaults()
Set global variables to default values.
int(* SolverSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a EpetraExt_HypreIJMatrix solving a Epetra_MultiVector X in Y...
int(* PrecondDestroyPtr_)(HYPRE_Solver)
int(* PrecondSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a EpetraExt_HypreIJMatrix multiplied by a Epetra_MultiVector X in Y...
int MyRowEnd_
Last row on local processor.
int Hypre_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver)
PCG Create passing function.
int(* SolverDestroyPtr_)(HYPRE_Solver)
int(* SolverSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
EpetraExt_HypreIJMatrix(HYPRE_IJMatrix matrix)
Epetra_HypreIJMatrix constructor.
HYPRE_IJMatrix & GetMatrix()
Return a reference to the Hypre matrix.
int MyRowStart_
First row on local processor.
int NumMyRowEntries(int MyRow, int &NumEntries) const
Return the current number of values stored for the specified local row.
int NumGlobalCols_
Number of columns across all processors.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
virtual bool UpperTriangular() const
Hypre_Chooser
Enumerated type to choose to solve or precondition.
int(* PrecondSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
Hypre_Chooser SolveOrPrec_
Choose to solve or apply preconditioner.
int Hypre_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
GMRES Create passing function.
int(EpetraExt_HypreIJMatrix::* PrecondCreatePtr_)(MPI_Comm, HYPRE_Solver *)
int RightScale(const Epetra_Vector &X)
Scales the EpetraExt_HypreIJMatrix on the right with a Epetra_Vector x.
int(EpetraExt_HypreIJMatrix::* SolverCreatePtr_)(MPI_Comm, HYPRE_Solver *)
int Hypre_ParCSRFlexGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
FlexGMRES Create passing function.
int SetupPrecond() const
int MatType_
Hypre matrix type (parCSR).
int NumGlobalRows_
Number of rows across all processors.
int CreatePrecond()
Create the preconditioner with selected type.
int(* SolverPrecondPtr_)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver)
int Hypre_ParaSailsCreate(MPI_Comm comm, HYPRE_Solver *solver)
ParaSails Create passing function.
int Hypre_AMSCreate(MPI_Comm comm, HYPRE_Solver *solver)
AMS Create passing function.
int Hypre_BoomerAMGCreate(MPI_Comm comm, HYPRE_Solver *solver)
AMG Create passing function.
Hypre_Solver
Enumerated type for Hypre solvers.
int Hypre_EuclidCreate(MPI_Comm comm, HYPRE_Solver *solver)
Euclid Create passing function.
int Hypre_ParCSRHybridCreate(MPI_Comm comm, HYPRE_Solver *solver)
Hybrid Create passing function.
int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const
Returns a copy of the specified local row in user-provided arrays.
bool * IsPrecondSetup_
Flag to know if preconditioner needs to be destroyed.
bool TransposeSolve_
Do a transpose solve, only BoomerAMG.
int NumMyRows_
Number of rows on local processor.
int SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, int), int parameter)
Set a parameter that takes a single int.
int SetupSolver() const
int Hypre_ParCSRBiCGSTABCreate(MPI_Comm comm, HYPRE_Solver *solver)
BiCGSTAB Create passing function.
int CreateSolver()
Create the solver with selected type.
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.