G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsBiCgStab.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 
18 namespace gismo
19 {
20 
24 template<class T = real_t>
25 class gsBiCgStab : public gsIterativeSolver<T>
26 {
27 public:
28  typedef gsIterativeSolver<T> Base;
29 
30  typedef gsMatrix<T> VectorType;
31 
32  typedef typename Base::LinOpPtr LinOpPtr;
33 
34  typedef memory::shared_ptr<gsBiCgStab> Ptr;
35  typedef memory::unique_ptr<gsBiCgStab> uPtr;
36 
41  template< typename OperatorType >
42  explicit gsBiCgStab( const OperatorType& mat, const LinOpPtr& precond = LinOpPtr() )
43  : Base(mat, precond), m_restartThereshold(1e-32) {}
44 
49  template< typename OperatorType >
50  static uPtr make( const OperatorType& mat, const LinOpPtr& precond = LinOpPtr() )
51  { return uPtr( new gsBiCgStab(mat, precond) ); }
52 
55  {
57  opt.addReal("RestartThereshold", "Thereshold for restarting gsBiCgStab solver.", 1e-32 );
58  return opt;
59  }
60 
63  {
64  Base::setOptions(opt);
65  m_restartThereshold = opt.askReal("RestartThereshold", m_restartThereshold);
66  return *this;
67  }
68 
69  bool initIteration( const VectorType& rhs, VectorType& x );
70  bool step( VectorType& x );
71 
73  std::ostream &print(std::ostream &os) const
74  {
75  os << "gsBiCgStab\n";
76  return os;
77  }
78 
79 private:
80  using Base::m_mat;
81  using Base::m_precond;
82  using Base::m_max_iters;
83  using Base::m_tol;
84  using Base::m_num_iter;
85  using Base::m_rhs_norm;
86  using Base::m_error;
87 
88  VectorType m_res;
89  VectorType m_r0;
90  VectorType m_tmp;
91  VectorType m_v;
92  VectorType m_p;
93  VectorType m_y;
94  VectorType m_s;
95  VectorType m_z;
96  VectorType m_t;
97 
98  T m_alpha;
99  T m_rho;
100  T m_w;
101 
102  T m_restartThereshold;
103 };
104 
105 } // namespace gismo
106 
107 #ifndef GISMO_BUILD_LIB
108 #include GISMO_HPP_HEADER(gsBiCgStab.hpp)
109 #endif
gsBiCgStab(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsBiCgStab.h:42
const LinOpPtr m_mat
The matrix/operator to be solved for.
Definition: gsIterativeSolver.h:252
virtual gsIterativeSolver & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsIterativeSolver.h:102
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsBiCgStab.hpp:44
gsOptionList::Real m_tol
The tolerance for m_error to be reached.
Definition: gsIterativeSolver.h:255
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsBiCgStab.hpp:18
Biconjugate gradient stabilized solver.
Definition: gsBiCgStab.h:25
static uPtr make(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Make function using a matrix (operator) and optionally a preconditionner.
Definition: gsBiCgStab.h:50
gsBiCgStab & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsBiCgStab.h:62
T m_rhs_norm
The norm of the right-hand-side.
Definition: gsIterativeSolver.h:257
static gsOptionList defaultOptions()
Returns a list of default options.
Definition: gsIterativeSolver.h:92
index_t m_max_iters
The upper bound for the number of iterations.
Definition: gsIterativeSolver.h:254
static gsOptionList defaultOptions()
Returns a list of default options.
Definition: gsBiCgStab.h:54
T m_error
The relative error as absolute_error/m_rhs_norm.
Definition: gsIterativeSolver.h:258
Real askReal(const std::string &label, const Real &value=0) const
Reads value for option label from options.
Definition: gsOptionList.cpp:139
Abstract class for iterative solvers.
void addReal(const std::string &label, const std::string &desc, const Real &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:211
Abstract class for iterative solvers.
Definition: gsIterativeSolver.h:26
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsBiCgStab.h:73
index_t m_num_iter
The number of iterations performed.
Definition: gsIterativeSolver.h:256
LinOpPtr m_precond
The preconditioner.
Definition: gsIterativeSolver.h:253