PTEMS  0.1.0-dev+git.81fd0e4
PolyTopic Element Method Solver
ptems::GMRESSolver< T > Class Template Reference

Linear system solver using GMRES. More...

#include <ptems/solvers/gmres.hpp>

Inheritance diagram for ptems::GMRESSolver< T >:
Collaboration diagram for ptems::GMRESSolver< T >:

Public Types

typedef remove_complex_t< T > real_type
 The real valued type the solver is for (either T, or R for T=std:complex<R>) More...
 
typedef T value_type
 Defines the type of a matrix entry in the linear system. More...
 
typedef Ref reference
 Defines the type of a reference to a matrix entry in the linear system. More...
 
typedef ConstRef const_reference
 Defines the type of a const reference to a matrix entry in the linear system. More...
 
typedef std::optional< typename detail::ReferenceWrapper< reference >::type > optional_reference
 Defines the type of a reference to a matrix entry in the linear system. More...
 
typedef std::optional< typename detail::ReferenceWrapper< const_reference >::type > optional_const_reference
 Defines the type of a const reference to a matrix entry in the linear system. More...
 

Public Member Functions

 GMRESSolver (const ParallelComm &comm, const SparsityPattern &mat, std::size_t size, real_type tolerance, std::size_t maxItns, bool updateInitialGuess=false)
 Constructs a GMRES solver, without preconditioner, for a sparse matrix. More...
 
 GMRESSolver (const ParallelComm &comm, const SparsityPattern &mat, std::size_t size, const PPreconditioner< T > &preconditioner, real_type tolerance, std::size_t maxItns, bool updateInitialGuess=false)
 Constructs a GMRES solver for a sparse matrix. More...
 
const T & InitialGuess (std::size_t i) const
 Returns a const reference to the specified entry of the initial guess. More...
 
T & InitialGuess (std::size_t i)
 Returns a mutable reference to the specified entry of the initial guess. More...
 
void FillInitialGuess (T value)
 Fills the initial guess vector with a constant. More...
 
template<typename It >
void FillInitialGuess (It begin, It end)
 Fills the initial guess vector with the values from the specified iterator range. More...
 
virtual bool DistributedConstruction () const override
 Gets if the matrix and right hand side should be constructed distributed (for MPI) More...
 
virtual LinearSolver< T >::optional_reference Entry (std::size_t i, std::size_t j) override
 Gets a reference to the specified matrix entry. More...
 
virtual LinearSolver< T >::optional_const_reference Entry (std::size_t i, std::size_t j) const override
 Gets a const reference to the specified matrix entry. More...
 
virtual void Clear () override
 Clear the matrix of the linear system. More...
 
std::size_t size () const override
 Gets the size of the linear system. More...
 
virtual std::vector< T > Solve (const std::vector< T > &rhs, std::size_t offsetRHS=0, std::size_t lenRHS=-1) override
 Solves the linear system with the specified right-hand side. More...
 
virtual reference operator() (std::size_t i, std::size_t j)
 Gets a reference to the specified matrix entry. More...
 
virtual const_reference operator() (std::size_t i, std::size_t j) const
 Gets a const reference to the specified matrix entry. More...
 
virtual std::vector< T > operator() (const std::vector< T > &rhs, std::size_t offsetRHS=0, std::size_t lenRHS=-1)
 Solves the linear system with the specified right-hand side. More...
 

Detailed Description

template<typename T>
class ptems::GMRESSolver< T >

Linear system solver using GMRES.

Todo:
Add restart?
Template Parameters
TThe type of the matrix entries

Member Typedef Documentation

◆ const_reference

template<typename T , typename Ref = T&, typename ConstRef = const T&>
typedef ConstRef ptems::LinearSolver< T, Ref, ConstRef >::const_reference
inherited

Defines the type of a const reference to a matrix entry in the linear system.

Can be a proxy object in some cases.

◆ optional_const_reference

template<typename T , typename Ref = T&, typename ConstRef = const T&>
typedef std::optional<typename detail::ReferenceWrapper<const_reference>::type> ptems::LinearSolver< T, Ref, ConstRef >::optional_const_reference
inherited

Defines the type of a const reference to a matrix entry in the linear system.

Can be a proxy object in some cases.

◆ optional_reference

template<typename T , typename Ref = T&, typename ConstRef = const T&>
typedef std::optional<typename detail::ReferenceWrapper<reference>::type> ptems::LinearSolver< T, Ref, ConstRef >::optional_reference
inherited

Defines the type of a reference to a matrix entry in the linear system.

Can be a proxy object in some cases.

◆ real_type

template<typename T >
typedef remove_complex_t<T> ptems::GMRESSolver< T >::real_type

The real valued type the solver is for (either T, or R for T=std:complex<R>)

◆ reference

template<typename T , typename Ref = T&, typename ConstRef = const T&>
typedef Ref ptems::LinearSolver< T, Ref, ConstRef >::reference
inherited

Defines the type of a reference to a matrix entry in the linear system.

Can be a proxy object in some cases.

◆ value_type

template<typename T , typename Ref = T&, typename ConstRef = const T&>
typedef T ptems::LinearSolver< T, Ref, ConstRef >::value_type
inherited

Defines the type of a matrix entry in the linear system.

Constructor & Destructor Documentation

◆ GMRESSolver() [1/2]

template<typename T >
ptems::GMRESSolver< T >::GMRESSolver ( const ParallelComm comm,
const SparsityPattern mat,
std::size_t  size,
real_type  tolerance,
std::size_t  maxItns,
bool  updateInitialGuess = false 
)
inline

Constructs a GMRES solver, without preconditioner, for a sparse matrix.

Parameters
commMPI communicator to use for construction and solving
matThe sparsity pattern of the sparse matrix
sizeThe size of the linear system
toleranceThe desired tolerance for the GMRES iteration
maxItnsThe maximum number of GMRES iterations to perform
updateInitialGuessSpecifies whether the initial guess should be updated with the solution of Solve. This is useful, for example, with nonlinear solvers as the initial guess for a linear solver at a nonlibnear iteration step will be the solution from the previous iteration of the nonlinear solver.

◆ GMRESSolver() [2/2]

template<typename T >
ptems::GMRESSolver< T >::GMRESSolver ( const ParallelComm comm,
const SparsityPattern mat,
std::size_t  size,
const PPreconditioner< T > &  preconditioner,
real_type  tolerance,
std::size_t  maxItns,
bool  updateInitialGuess = false 
)
inline

Constructs a GMRES solver for a sparse matrix.

Parameters
commMPI communicator to use for construction and solving
matThe sparsity pattern of the sparse matrix
sizeThe size of the linear system
preconditionerThe preconditioner to use at each step of the GMRES iteration. Can be null to use without preconditioner
toleranceThe desired tolerance for the GMRES iteration
maxItnsThe maximum number of GMRES iterations to perform
updateInitialGuessSpecifies whether the initial guess should be updated with the solution of Solve. This is useful, for example, with nonlinear solvers as the initial guess for a linear solver at a nonlibnear iteration step will be the solution from the previous iteration of the nonlinear solver.

Member Function Documentation

◆ Clear()

template<typename T >
virtual void ptems::GMRESSolver< T >::Clear ( )
inlineoverridevirtual

Clear the matrix of the linear system.

Implements ptems::LinearSolver< T, Ref, ConstRef >.

◆ DistributedConstruction()

template<typename T >
virtual bool ptems::GMRESSolver< T >::DistributedConstruction ( ) const
inlineoverridevirtual

Gets if the matrix and right hand side should be constructed distributed (for MPI)

Returns
true yo distribute construction across processes, false otherwise

Implements ptems::LinearSolver< T, Ref, ConstRef >.

◆ Entry() [1/2]

template<typename T >
virtual LinearSolver<T>::optional_const_reference ptems::GMRESSolver< T >::Entry ( std::size_t  i,
std::size_t  j 
) const
inlineoverridevirtual

Gets a const reference to the specified matrix entry.

Exceptions
std::out_of_rangeIf the row or column index are not less than the linear system size
Parameters
iThe row index
jThe column index
Returns
A const reference to the element if its a non-zero entry, or an empty optional if the entry is a zero entry in the sparse matrix

Implements ptems::LinearSolver< T, Ref, ConstRef >.

◆ Entry() [2/2]

template<typename T >
virtual LinearSolver<T>::optional_reference ptems::GMRESSolver< T >::Entry ( std::size_t  i,
std::size_t  j 
)
inlineoverridevirtual

Gets a reference to the specified matrix entry.

Exceptions
std::out_of_rangeIf the row or column index are not less than the linear system size
Parameters
iThe row index
jThe column index
Returns
A reference to the element if its a non-zero entry, or an empty optional if the entry is a zero entry in the sparse matrix

Implements ptems::LinearSolver< T, Ref, ConstRef >.

◆ FillInitialGuess() [1/2]

template<typename T >
template<typename It >
void ptems::GMRESSolver< T >::FillInitialGuess ( It  begin,
It  end 
)
inline

Fills the initial guess vector with the values from the specified iterator range.

Exceptions
std::invalid_argumentIf the size of the specified range is different to the size of the initial guess vector. If this exception is thrown some values WILL have been copied to the initial guess vector.
Template Parameters
ItType of the iterators over the range
Parameters
beginThe begin iterator of the range
endThe first-past-the-end iterator of the range

◆ FillInitialGuess() [2/2]

template<typename T >
void ptems::GMRESSolver< T >::FillInitialGuess ( value)
inline

Fills the initial guess vector with a constant.

Parameters
valueValue to fill initial guess vector with

◆ InitialGuess() [1/2]

template<typename T >
T& ptems::GMRESSolver< T >::InitialGuess ( std::size_t  i)
inline

Returns a mutable reference to the specified entry of the initial guess.

Can be used to populate the initial guess

Exceptions
std::out_of_rangeIf i is not in the range [0, size())
Parameters
iIndex of entry in initial guess
Returns
Mutable reference to entry in initial guess

◆ InitialGuess() [2/2]

template<typename T >
const T& ptems::GMRESSolver< T >::InitialGuess ( std::size_t  i) const
inline

Returns a const reference to the specified entry of the initial guess.

Can be used to populate the initial guess

Exceptions
std::out_of_rangeIf i is not in the range [0, size())
Parameters
iIndex of entry in initial guess
Returns
Const reference to entry in initial guess

◆ operator()() [1/3]

template<typename T , typename Ref = T&, typename ConstRef = const T&>
virtual std::vector<T> ptems::LinearSolver< T, Ref, ConstRef >::operator() ( const std::vector< T > &  rhs,
std::size_t  offsetRHS = 0,
std::size_t  lenRHS = -1 
)
inlinevirtualinherited

Solves the linear system with the specified right-hand side.

Parameters
rhsThe right hand side vector
offsetRHSIf using distributed matrix/rhs construction specifies the offset to the start of the right hand side vector populated by this process
lenRHSIf using distributed matrix/rhs construction specifies the length of the right hand side vector populated by this process (or greater than size() for all)
Returns
std::vector<T>

◆ operator()() [2/3]

template<typename T , typename Ref = T&, typename ConstRef = const T&>
virtual reference ptems::LinearSolver< T, Ref, ConstRef >::operator() ( std::size_t  i,
std::size_t  j 
)
inlinevirtualinherited

Gets a reference to the specified matrix entry.

Exceptions
std::out_of_rangeIf the row or column index are not less than the linear system size
std::invalid_argumentIf the entry is not a non-zero entry of the sparse matrix
Parameters
iThe row index
jThe column index
Returns
A reference to the element if its a non-zero entry

◆ operator()() [3/3]

template<typename T , typename Ref = T&, typename ConstRef = const T&>
virtual const_reference ptems::LinearSolver< T, Ref, ConstRef >::operator() ( std::size_t  i,
std::size_t  j 
) const
inlinevirtualinherited

Gets a const reference to the specified matrix entry.

Exceptions
std::out_of_rangeIf the row or column index are not less than the linear system size
std::invalid_argumentIf the entry is not a non-zero entry of the sparse matrix
Parameters
iThe row index
jThe column index
Returns
A const reference to the element if its a non-zero entry

◆ size()

template<typename T >
std::size_t ptems::GMRESSolver< T >::size ( ) const
inlineoverridevirtual

Gets the size of the linear system.

Returns
The number of rows and columns in the sparse matrix

Implements ptems::LinearSolver< T, Ref, ConstRef >.

◆ Solve()

template<typename T >
virtual std::vector<T> ptems::GMRESSolver< T >::Solve ( const std::vector< T > &  rhs,
std::size_t  offsetRHS = 0,
std::size_t  lenRHS = -1 
)
inlineoverridevirtual

Solves the linear system with the specified right-hand side.

Parameters
rhsThe right hand side vector
offsetRHSIf using distributed matrix/rhs construction specifies the offset to the start of the right hand side vector populated by this process
lenRHSIf using distributed matrix/rhs construction specifies the length of the right hand side vector populated by this process (or greater than size() for all)
Returns
std::vector<T>

Implements ptems::LinearSolver< T, Ref, ConstRef >.


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