LifeV
LinearSolver Class Reference

LinearSolver - Class to wrap linear solver. More...

#include <LinearSolver.hpp>

+ Collaboration diagram for LinearSolver:

Private Attributes

operatorPtr_Type M_operator
 
matrixPtr_Type M_matrix
 
matrixPtr_Type M_baseMatrixForPreconditioner
 
vectorPtr_Type M_rhs
 
preconditionerPtr_Type M_preconditioner
 
operatorPtr_Type M_preconditionerOperator
 
SolverType M_solverType
 
SolverOperatorPtr_Type M_solverOperator
 
Teuchos::ParameterList M_parameterList
 
std::shared_ptr< DisplayerM_displayer
 
Int M_maxItersForReuse
 
bool M_reusePreconditioner
 
bool M_quitOnFailure
 
bool M_silent
 
SolverOperator_Type::SolverOperatorStatusType M_lossOfPrecision
 
SolverOperator_Type::SolverOperatorStatusType M_maxNumItersReached
 
SolverOperator_Type::SolverOperatorStatusType M_converged
 
Real M_tolerance
 

Public Types

enum  SolverType { UndefinedSolver, Belos, AztecOO }
 
typedef Real value_Type
 
typedef LinearSolver solver_Type
 
typedef Epetra_MultiVector multiVector_Type
 
typedef std::shared_ptr< multiVector_TypemultiVectorPtr_Type
 
typedef Epetra_Operator operator_Type
 
typedef std::shared_ptr< operator_TypeoperatorPtr_Type
 
typedef Operators::SolverOperator SolverOperator_Type
 
typedef std::shared_ptr< SolverOperator_TypeSolverOperatorPtr_Type
 
typedef MatrixEpetra< Realmatrix_Type
 
typedef std::shared_ptr< matrix_TypematrixPtr_Type
 
typedef VectorEpetra vector_Type
 
typedef std::shared_ptr< VectorEpetravectorPtr_Type
 
typedef Preconditioner preconditioner_Type
 
typedef std::shared_ptr< preconditioner_TypepreconditionerPtr_Type
 
typedef Teuchos::ParameterList parameterList_Type
 
typedef Teuchos::RCP< parameterList_TypeparameterListPtr_Type
 

Constructors & Destructor

 LinearSolver ()
 Empty constructor. More...
 
 LinearSolver (const std::shared_ptr< Epetra_Comm > commPtr)
 Constructor. More...
 
 ~LinearSolver ()
 Destructor. More...
 

Methods

Int solve (vectorPtr_Type solutionPtr)
 Solves the system and returns the number of iterations. More...
 
Real computeResidual (vectorPtr_Type solutionPtr)
 Compute the residual. More...
 
std::string printStatus ()
 return the solver status More...
 
void setPreconditionerFromGetPot (const GetPot &dataFile, const std::string &section)
 Setup the preconditioner from a GetPot file. More...
 
void buildPreconditioner ()
 Builds the preconditioner starting from the matrix "baseMatrixForPreconditioner". More...
 
void resetPreconditioner ()
 Reset the stored preconditioner. More...
 
bool isPreconditionerSet () const
 Return true if preconditioner has been setted. More...
 
void resetStatus ()
 Reset the status for the state of convergence and loss of accuracy. More...
 
void showMe (std::ostream &output=std::cout) const
 Print informations about the solver. More...
 
void setupSolverOperator ()
 Setup the solver operator to be used. More...
 

Set Method

void setSolverType (const SolverType &solverType)
 Set the solver which should be used. More...
 
void setCommunicator (const std::shared_ptr< Epetra_Comm > commPtr)
 Method to set communicator for Displayer (for empty constructor) More...
 
void setOperator (matrixPtr_Type matrixPtr)
 Method to set matrix from MatrixEpetra. More...
 
void setOperator (operatorPtr_Type operPtr)
 Method to set a general linear operator (of class derived from Epetra_Operator) defining the linear system. More...
 
void setRightHandSide (const vectorPtr_Type rhsPtr)
 Method to set the right hand side (rhs) of the linear system. More...
 
void setPreconditioner (preconditionerPtr_Type preconditionerPtr)
 Method to set an Preconditioner preconditioner. More...
 
void setPreconditioner (operatorPtr_Type preconditionerPtr)
 Method to set a general Epetra_Operator as preconditioner. More...
 
void setBaseMatrixForPreconditioner (matrixPtr_Type baseMatrixPtr)
 Method to set a matrix on which the preconditioner should be created. More...
 
void setParameters (const Teuchos::ParameterList &list)
 Method to setup the solver using Teuchos::ParameterList. More...
 
template<typename T >
void setParameter (const std::string &name, T value)
 Method to set a particular parameter. More...
 
void resetParameters ()
 Method to reset the parameters list of the solver. More...
 
void setReusePreconditioner (const bool reusePreconditioner)
 Specify if the preconditioner should be reuse or not. More...
 
void setQuitOnFailure (const bool enable)
 Specify if the application should stop when problems occur in the iterations. More...
 
void setTolerance (const Real &tolerance)
 Set the tolerance of the solver. More...
 

Get Method

Int numIterations () const
 Return the total number of iterations. More...
 
Real recursiveResidual ()
 Return the recursive residual. More...
 
preconditionerPtr_Typepreconditioner ()
 Method to get a shared pointer to the preconditioner. More...
 
Teuchos::ParameterList & parametersList ()
 Return a Teuchos parameters list. More...
 
SolverOperatorPtr_Type solver ()
 Return a pointer on the Belos solver manager. More...
 
std::shared_ptr< Displayerdisplayer ()
 Return a shared pointer on the displayer. More...
 
Int maxItersForReuse () const
 Returns the maximum of iterations tolerate to avoid recomputing the preconditioner. More...
 
bool reusePreconditioner () const
 Returns if the preconditioner can be reused. More...
 
bool quitOnFailure () const
 Returns if the application should stop if a problem occurs. More...
 
bool silent () const
 Returns if the solver is in silent mode. More...
 
SolverOperator_Type::SolverOperatorStatusType hasReachedMaxNumIters () const
 Returns if the maximum number of iterations has been reached. More...
 
SolverOperator_Type::SolverOperatorStatusType isLossOfAccuracyDetected () const
 Returns if a loss of precision has been detected. More...
 
SolverOperator_Type::SolverOperatorStatusType hasConverged () const
 Returns if the convergence has been achieved. More...
 

Detailed Description

LinearSolver - Class to wrap linear solver.

By default the solver is block gmres.

Author
Gwenol Grandperrin gweno.nosp@m.l.gr.nosp@m.andpe.nosp@m.rrin.nosp@m.@epfl.nosp@m..ch

Definition at line 92 of file LinearSolver.hpp.

Member Typedef Documentation

◆ value_Type

typedef Real value_Type

Definition at line 99 of file LinearSolver.hpp.

◆ solver_Type

Definition at line 101 of file LinearSolver.hpp.

◆ multiVector_Type

Definition at line 102 of file LinearSolver.hpp.

◆ multiVectorPtr_Type

typedef std::shared_ptr<multiVector_Type> multiVectorPtr_Type

Definition at line 103 of file LinearSolver.hpp.

◆ operator_Type

Definition at line 104 of file LinearSolver.hpp.

◆ operatorPtr_Type

typedef std::shared_ptr<operator_Type> operatorPtr_Type

Definition at line 105 of file LinearSolver.hpp.

◆ SolverOperator_Type

◆ SolverOperatorPtr_Type

typedef std::shared_ptr< SolverOperator_Type > SolverOperatorPtr_Type

Definition at line 107 of file LinearSolver.hpp.

◆ matrix_Type

Definition at line 108 of file LinearSolver.hpp.

◆ matrixPtr_Type

typedef std::shared_ptr<matrix_Type> matrixPtr_Type

Definition at line 109 of file LinearSolver.hpp.

◆ vector_Type

Definition at line 110 of file LinearSolver.hpp.

◆ vectorPtr_Type

typedef std::shared_ptr<VectorEpetra> vectorPtr_Type

Definition at line 111 of file LinearSolver.hpp.

◆ preconditioner_Type

Definition at line 112 of file LinearSolver.hpp.

◆ preconditionerPtr_Type

typedef std::shared_ptr<preconditioner_Type> preconditionerPtr_Type

Definition at line 113 of file LinearSolver.hpp.

◆ parameterList_Type

typedef Teuchos::ParameterList parameterList_Type

Definition at line 114 of file LinearSolver.hpp.

◆ parameterListPtr_Type

typedef Teuchos::RCP< parameterList_Type > parameterListPtr_Type

Definition at line 115 of file LinearSolver.hpp.

Member Enumeration Documentation

◆ SolverType

enum SolverType
Enumerator
UndefinedSolver 
Belos 
AztecOO 

Definition at line 117 of file LinearSolver.hpp.

Constructor & Destructor Documentation

◆ LinearSolver() [1/2]

Empty constructor.

Definition at line 49 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ LinearSolver() [2/2]

LinearSolver ( const std::shared_ptr< Epetra_Comm >  commPtr)

Constructor.

Parameters
commPtrCommunicator

Definition at line 71 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ ~LinearSolver()

Destructor.

Definition at line 93 of file LinearSolver.cpp.

Member Function Documentation

◆ solve()

Int solve ( vectorPtr_Type  solutionPtr)

Solves the system and returns the number of iterations.

The Matrix has already been passed by the method setMatrix or setOperator

The preconditioner is build starting from the matrix baseMatrixForPreconditioner if it is set otherwise from the problem matrix.

Parameters
solutionPtrVector to store the solution
Returns
Number of iterations, M_maxIter+1 if solve failed.

Definition at line 102 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ computeResidual()

Real computeResidual ( vectorPtr_Type  solutionPtr)

Compute the residual.

Parameters
solutionPtrShared pointer on the solution of the system The method returns -1 if an error occurs

Definition at line 218 of file LinearSolver.cpp.

◆ printStatus()

std::string printStatus ( )

return the solver status

Definition at line 241 of file LinearSolver.cpp.

◆ setPreconditionerFromGetPot()

void setPreconditionerFromGetPot ( const GetPot dataFile,
const std::string &  section 
)

Setup the preconditioner from a GetPot file.

Parameters
dataFileGetPot object which contains the data about the preconditioner
sectionSection the GetPot structure where to find the informations about the preconditioner

Definition at line 267 of file LinearSolver.cpp.

◆ buildPreconditioner()

void buildPreconditioner ( )

Builds the preconditioner starting from the matrix "baseMatrixForPreconditioner".

The preconditioner is build starting from the matrix baseMatrixForPreconditioner by the preconditioner object passed in by the method setPreconditioner

Parameters
baseMatrixForPreconditionerBase matrix for the preconditioner construction

Definition at line 278 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ resetPreconditioner()

void resetPreconditioner ( )

Reset the stored preconditioner.

Note: This method only affects the LifeV::Preconditioner (i.e. not the Epetra_Operators used as preconditioner

Definition at line 328 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ isPreconditionerSet()

bool isPreconditionerSet ( ) const

Return true if preconditioner has been setted.

Definition at line 337 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ resetStatus()

void resetStatus ( )

Reset the status for the state of convergence and loss of accuracy.

Definition at line 348 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ showMe()

void showMe ( std::ostream &  output = std::cout) const

Print informations about the solver.

Definition at line 356 of file LinearSolver.cpp.

◆ setupSolverOperator()

void setupSolverOperator ( )

Setup the solver operator to be used.

Definition at line 368 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ setSolverType()

void setSolverType ( const SolverType solverType)

Set the solver which should be used.

Parameters
solverOperatorTypeType of solver manager The solver type can be chosen from one of the following: Aztecoo, Belos

Definition at line 415 of file LinearSolver.cpp.

◆ setCommunicator()

void setCommunicator ( const std::shared_ptr< Epetra_Comm >  commPtr)

Method to set communicator for Displayer (for empty constructor)

Parameters
commPtrCommunicator for the displayer

Definition at line 421 of file LinearSolver.cpp.

◆ setOperator() [1/2]

void setOperator ( matrixPtr_Type  matrixPtr)

Method to set matrix from MatrixEpetra.

Parameters
matrixPtrMatrix of the system

Definition at line 426 of file LinearSolver.cpp.

◆ setOperator() [2/2]

void setOperator ( operatorPtr_Type  operPtr)

Method to set a general linear operator (of class derived from Epetra_Operator) defining the linear system.

Parameters
operPtrPointer to an operator for the system

Definition at line 433 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ setRightHandSide()

void setRightHandSide ( const vectorPtr_Type  rhsPtr)

Method to set the right hand side (rhs) of the linear system.

Parameters
rhsPtrright hand side of the system

Definition at line 440 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ setPreconditioner() [1/2]

void setPreconditioner ( preconditionerPtr_Type  preconditionerPtr)

Method to set an Preconditioner preconditioner.

Parameters
preconditionerPtrPreconditioner to be used to solve the system

Definition at line 446 of file LinearSolver.cpp.

◆ setPreconditioner() [2/2]

void setPreconditioner ( operatorPtr_Type  preconditionerPtr)

Method to set a general Epetra_Operator as preconditioner.

Parameters
preconditionerPtrPreconditioner to be set of type Epetra_Operator

Definition at line 455 of file LinearSolver.cpp.

+ Here is the caller graph for this function:

◆ setBaseMatrixForPreconditioner()

void setBaseMatrixForPreconditioner ( matrixPtr_Type  baseMatrixPtr)

Method to set a matrix on which the preconditioner should be created.

Parameters
baseMatrixPtrmatrix on which the preconditioner should be created

Definition at line 464 of file LinearSolver.cpp.

◆ setParameters()

void setParameters ( const Teuchos::ParameterList &  list)

Method to setup the solver using Teuchos::ParameterList.

Parameters
listTeuchos::ParameterList object Note: The parameters are added to the existing one. Use resetParameters to clean the parameters list.

Definition at line 470 of file LinearSolver.cpp.

◆ setParameter()

void setParameter ( const std::string &  name,
value 
)

Method to set a particular parameter.

Parameters
nameName of the parameter
valueValue of the parameter Note: The parameters are added to the existing one. Use resetParameters to clean the parameters list.

Definition at line 379 of file LinearSolver.hpp.

◆ resetParameters()

void resetParameters ( )

Method to reset the parameters list of the solver.

Definition at line 492 of file LinearSolver.cpp.

◆ setReusePreconditioner()

void setReusePreconditioner ( const bool  reusePreconditioner)

Specify if the preconditioner should be reuse or not.

Parameters
reusePreconditionerIf set to true, do not recompute the preconditioner

Definition at line 498 of file LinearSolver.cpp.

◆ setQuitOnFailure()

void setQuitOnFailure ( const bool  enable)

Specify if the application should stop when problems occur in the iterations.

Parameters
enableIf set to true, application will stop if problems occur Note: This option is useful for simulation on clusters. In particular if the system does not converge or if a loss of precision occurs time is saved by stoping the simulation

Definition at line 504 of file LinearSolver.cpp.

◆ setTolerance()

void setTolerance ( const Real tolerance)

Set the tolerance of the solver.

Parameters
toleranceTolerance used by the solver

Definition at line 510 of file LinearSolver.cpp.

◆ numIterations()

Int numIterations ( ) const

Return the total number of iterations.

Definition at line 520 of file LinearSolver.cpp.

◆ recursiveResidual()

Real recursiveResidual ( )

Return the recursive residual.

The method returns -1 if an error occurs

Definition at line 527 of file LinearSolver.cpp.

◆ preconditioner()

Method to get a shared pointer to the preconditioner.

Definition at line 547 of file LinearSolver.cpp.

◆ parametersList()

Teuchos::ParameterList & parametersList ( )

Return a Teuchos parameters list.

Definition at line 553 of file LinearSolver.cpp.

◆ solver()

Return a pointer on the Belos solver manager.

Definition at line 559 of file LinearSolver.cpp.

◆ displayer()

std::shared_ptr< Displayer > displayer ( )

Return a shared pointer on the displayer.

Definition at line 565 of file LinearSolver.cpp.

◆ maxItersForReuse()

Int maxItersForReuse ( ) const

Returns the maximum of iterations tolerate to avoid recomputing the preconditioner.

Definition at line 571 of file LinearSolver.cpp.

◆ reusePreconditioner()

bool reusePreconditioner ( ) const

Returns if the preconditioner can be reused.

Definition at line 577 of file LinearSolver.cpp.

◆ quitOnFailure()

bool quitOnFailure ( ) const

Returns if the application should stop if a problem occurs.

Definition at line 583 of file LinearSolver.cpp.

◆ silent()

bool silent ( ) const

Returns if the solver is in silent mode.

Definition at line 589 of file LinearSolver.cpp.

◆ hasReachedMaxNumIters()

Returns if the maximum number of iterations has been reached.

Definition at line 595 of file LinearSolver.cpp.

◆ isLossOfAccuracyDetected()

Returns if a loss of precision has been detected.

Definition at line 601 of file LinearSolver.cpp.

◆ hasConverged()

Returns if the convergence has been achieved.

Definition at line 607 of file LinearSolver.cpp.

Field Documentation

◆ M_operator

operatorPtr_Type M_operator
private

Definition at line 348 of file LinearSolver.hpp.

◆ M_matrix

matrixPtr_Type M_matrix
private

Definition at line 349 of file LinearSolver.hpp.

◆ M_baseMatrixForPreconditioner

matrixPtr_Type M_baseMatrixForPreconditioner
private

Definition at line 350 of file LinearSolver.hpp.

◆ M_rhs

vectorPtr_Type M_rhs
private

Definition at line 351 of file LinearSolver.hpp.

◆ M_preconditioner

preconditionerPtr_Type M_preconditioner
private

Definition at line 353 of file LinearSolver.hpp.

◆ M_preconditionerOperator

operatorPtr_Type M_preconditionerOperator
private

Definition at line 354 of file LinearSolver.hpp.

◆ M_solverType

SolverType M_solverType
private

Definition at line 356 of file LinearSolver.hpp.

◆ M_solverOperator

SolverOperatorPtr_Type M_solverOperator
private

Definition at line 357 of file LinearSolver.hpp.

◆ M_parameterList

Teuchos::ParameterList M_parameterList
private

Definition at line 359 of file LinearSolver.hpp.

◆ M_displayer

std::shared_ptr<Displayer> M_displayer
private

Definition at line 360 of file LinearSolver.hpp.

◆ M_maxItersForReuse

Int M_maxItersForReuse
private

Definition at line 363 of file LinearSolver.hpp.

◆ M_reusePreconditioner

bool M_reusePreconditioner
private

Definition at line 364 of file LinearSolver.hpp.

◆ M_quitOnFailure

bool M_quitOnFailure
private

Definition at line 365 of file LinearSolver.hpp.

◆ M_silent

bool M_silent
private

Definition at line 366 of file LinearSolver.hpp.

◆ M_lossOfPrecision

Definition at line 369 of file LinearSolver.hpp.

◆ M_maxNumItersReached

SolverOperator_Type::SolverOperatorStatusType M_maxNumItersReached
private

Definition at line 370 of file LinearSolver.hpp.

◆ M_converged

Definition at line 371 of file LinearSolver.hpp.

◆ M_tolerance

Real M_tolerance
private

Definition at line 373 of file LinearSolver.hpp.


The documentation for this class was generated from the following files: