G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsGMRes.h
Go to the documentation of this file.
1
13#pragma once
14
16
17namespace gismo
18{
19
23template<class T = real_t>
24class gsGMRes : public gsIterativeSolver<T>
25{
26public:
28
29 typedef gsMatrix<T> VectorType;
30
31 typedef typename Base::LinOpPtr LinOpPtr;
32
33 typedef memory::shared_ptr<gsGMRes> Ptr;
34 typedef memory::unique_ptr<gsGMRes> uPtr;
35
40 template< typename OperatorType >
41 explicit gsGMRes( const OperatorType& mat, const LinOpPtr& precond = LinOpPtr() )
42 : Base(mat, precond) {}
43
48 template< typename OperatorType >
49 static uPtr make( const OperatorType& mat, const LinOpPtr& precond = LinOpPtr() )
50 { return uPtr( new gsGMRes(mat, precond) ); }
51
52 bool initIteration( const VectorType& rhs, VectorType& x );
53 bool step( VectorType& x );
54 void finalizeIteration( VectorType& x );
55
56private:
57
60 void solveUpperTriangular(const VectorType& R, const VectorType& gg)
61 {
62 y = R.template triangularView<gsEigen::Upper>().solve(gg);
63 }
64
66 std::ostream &print(std::ostream &os) const
67 {
68 os << "gsGMRes\n";
69 return os;
70 }
71
72private:
73 using Base::m_mat;
74 using Base::m_precond;
76 using Base::m_tol;
77 using Base::m_num_iter;
78 using Base::m_rhs_norm;
79 using Base::m_error;
80
81
82 gsMatrix<T> tmp, g, g_tmp, h_tmp, y, w;
83 gsMatrix<T> residual;
84 gsMatrix<T> H_prev, H, Omega, Omega_prev, Omega_tmp, Omega_prev_tmp;
85 std::vector< gsMatrix<T> > v;
86 T beta;
87};
88
89} // namespace gismo
90
91#ifndef GISMO_BUILD_LIB
92#include GISMO_HPP_HEADER(gsGMRes.hpp)
93#endif
The generalized minimal residual (GMRES) method.
Definition gsGMRes.h:25
void finalizeIteration(VectorType &x)
Some post-processing might be required.
Definition gsGMRes.hpp:45
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition gsGMRes.hpp:83
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition gsGMRes.hpp:20
static uPtr make(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Make function using a matrix (operator) and optionally a preconditionner.
Definition gsGMRes.h:49
void solveUpperTriangular(const VectorType &R, const VectorType &gg)
Definition gsGMRes.h:60
gsGMRes(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Constructor using a matrix (operator) and optionally a preconditionner.
Definition gsGMRes.h:41
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsGMRes.h:66
Abstract class for iterative solvers.
Definition gsIterativeSolver.h:27
T m_rhs_norm
The norm of the right-hand-side.
Definition gsIterativeSolver.h:257
T m_error
The relative error as absolute_error/m_rhs_norm.
Definition gsIterativeSolver.h:258
LinOpPtr m_precond
The preconditioner.
Definition gsIterativeSolver.h:253
gsOptionList::Real m_tol
The tolerance for m_error to be reached.
Definition gsIterativeSolver.h:255
index_t m_num_iter
The number of iterations performed.
Definition gsIterativeSolver.h:256
index_t m_max_iters
The upper bound for the number of iterations.
Definition gsIterativeSolver.h:254
const LinOpPtr m_mat
The matrix/operator to be solved for.
Definition gsIterativeSolver.h:252
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Abstract class for iterative solvers.
The G+Smo namespace, containing all definitions for the library.