EpetraExt Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
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"
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
62class Epetra_Vector;
64class Epetra_Import;
65
67
74#ifndef HYPRE_ENUMS
75#define HYPRE_ENUMS
77
91
97#endif //HYPRE_ENUMS
98
100
101public:
102
104
105
110 EpetraExt_HypreIJMatrix(HYPRE_IJMatrix matrix);
111
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
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
294
295
297
305
307
308
310
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
355protected:
356
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
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_ */
Hypre_Chooser
Enumerated type to choose to solve or precondition.
Hypre_Solver
Enumerated type for Hypre solvers.
int SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, int, int), int parameter1, int parameter2)
Set a parameter that takes two int parameters.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
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(* SolverPrecondPtr_)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver)
int Hypre_ParCSRBiCGSTABCreate(MPI_Comm comm, HYPRE_Solver *solver)
BiCGSTAB Create passing function.
bool * IsSolverSetup_
Flag to know if solver needs to be destoyed.
int(* SolverSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
int(* SolverSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
int MyRowStart_
First row on local processor.
int SetParameter(bool UsePreconditioner)
Sets the solver to use the selected preconditioner.
int InitializeDefaults()
Set global variables to default values.
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.
int CreatePrecond()
Create the preconditioner with selected type.
int Hypre_EuclidCreate(MPI_Comm comm, HYPRE_Solver *solver)
Euclid Create passing function.
int SetParameter(Hypre_Chooser chooser)
Choose to solve the problem or apply the preconditioner.
bool TransposeSolve_
Do a transpose solve, only BoomerAMG.
int NumGlobalCols_
Number of columns across all processors.
int(* PrecondSolvePtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
int(EpetraExt_HypreIJMatrix::* PrecondCreatePtr_)(MPI_Comm, HYPRE_Solver *)
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 CreateSolver()
Create the solver with selected type.
int Hypre_BoomerAMGCreate(MPI_Comm comm, HYPRE_Solver *solver)
AMG Create passing function.
int Hypre_ParCSRHybridCreate(MPI_Comm comm, HYPRE_Solver *solver)
Hybrid Create passing function.
int LeftScale(const Epetra_Vector &X)
Scales the EpetraExt_HypreIJMatrix on the left with a Epetra_Vector x.
int SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, int), int parameter)
Set a parameter that takes a single int.
int NumGlobalRows_
Number of rows across all processors.
int Hypre_AMSCreate(MPI_Comm comm, HYPRE_Solver *solver)
AMS Create passing function.
int Hypre_ParCSRFlexGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
FlexGMRES Create passing function.
int(* SolverDestroyPtr_)(HYPRE_Solver)
EpetraExt_HypreIJMatrix(HYPRE_IJMatrix matrix)
Epetra_HypreIJMatrix constructor.
int SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, double), double parameter)
Set a parameter that takes a single double.
int(EpetraExt_HypreIJMatrix::* SolverCreatePtr_)(MPI_Comm, HYPRE_Solver *)
int(* PrecondDestroyPtr_)(HYPRE_Solver)
int SetParameter(Hypre_Chooser chooser, Hypre_Solver Solver, bool transpose=false)
Sets the solver that is used by the Solve() and ApplyInverse() methods. Until this is called,...
Hypre_Chooser SolveOrPrec_
Choose to solve or apply preconditioner.
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.
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 SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, double *), double *parameter)
Set a parameter that takes a double*.
virtual ~EpetraExt_HypreIJMatrix()
EpetraExt_HypreIJMatrix Destructor.
int NumMyRows_
Number of rows on local processor.
int Hypre_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver)
PCG Create passing function.
int Hypre_ParCSRLGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
LGMRES Create passing function.
int SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, int *), int *parameter)
Set a parameter that takes an int*.
int SetParameter(Hypre_Chooser chooser, int(*pt2Func)(HYPRE_Solver, double, int), double parameter1, int parameter2)
Set a parameter that takes a double then an int.
int NumMyRowEntries(int MyRow, int &NumEntries) const
Return the current number of values stored for the specified local row.
int MyRowEnd_
Last row on local processor.
int Hypre_ParaSailsCreate(MPI_Comm comm, HYPRE_Solver *solver)
ParaSails Create passing function.
int Hypre_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver)
GMRES Create passing function.
HYPRE_IJMatrix & GetMatrix()
Return a reference to the Hypre matrix.
int ExtractMyEntryView(int CurEntry, const double *&Value, int &RowIndex, int &ColIndex) const
Returns a const reference to the ith entry in the matrix, along with its row and column index.
bool * IsPrecondSetup_
Flag to know if preconditioner needs to be destroyed.
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.
int(* PrecondSetupPtr_)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
int MatType_
Hypre matrix type (parCSR).
int RightScale(const Epetra_Vector &X)
Scales the EpetraExt_HypreIJMatrix on the right with a Epetra_Vector x.
virtual bool UpperTriangular() const