G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsGMRes.h
Go to the documentation of this file.
1 
13 #pragma once
14 
16 
17 namespace gismo
18 {
19 
23 template<class T = real_t>
24 class gsGMRes : public gsIterativeSolver<T>
25 {
26 public:
27  typedef gsIterativeSolver<T> Base;
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 
56 private:
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 
72 private:
73  using Base::m_mat;
74  using Base::m_precond;
75  using Base::m_max_iters;
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
const LinOpPtr m_mat
The matrix/operator to be solved for.
Definition: gsIterativeSolver.h:252
void solveUpperTriangular(const VectorType &R, const VectorType &gg)
Definition: gsGMRes.h:60
void solve(const VectorType &rhs, VectorType &x)
Solves the linear system and stores the solution in x.
Definition: gsIterativeSolver.h:114
static uPtr make(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Make function using a matrix (operator) and optionally a preconditionner.
Definition: gsGMRes.h:49
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
gsOptionList::Real m_tol
The tolerance for m_error to be reached.
Definition: gsIterativeSolver.h:255
T m_rhs_norm
The norm of the right-hand-side.
Definition: gsIterativeSolver.h:257
The generalized minimal residual (GMRES) method.
Definition: gsGMRes.h:24
index_t m_max_iters
The upper bound for the number of iterations.
Definition: gsIterativeSolver.h:254
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
T m_error
The relative error as absolute_error/m_rhs_norm.
Definition: gsIterativeSolver.h:258
Abstract class for iterative solvers.
Abstract class for iterative solvers.
Definition: gsIterativeSolver.h:26
void finalizeIteration(VectorType &x)
Some post-processing might be required.
Definition: gsGMRes.hpp:45
index_t m_num_iter
The number of iterations performed.
Definition: gsIterativeSolver.h:256
LinOpPtr m_precond
The preconditioner.
Definition: gsIterativeSolver.h:253