G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMinimalResidual.h
Go to the documentation of this file.
1 
13 #pragma once
14 
16 
17 namespace gismo
18 {
19 
24 template<class T=real_t>
26 {
27 
28 public:
29  typedef gsIterativeSolver<T> Base;
30 
31  typedef gsMatrix<T> VectorType;
32 
33  typedef typename Base::LinOpPtr LinOpPtr;
34 
35  typedef memory::shared_ptr<gsMinimalResidual> Ptr;
36  typedef memory::unique_ptr<gsMinimalResidual> uPtr;
37 
42  template< typename OperatorType >
43  explicit gsMinimalResidual( const OperatorType& mat,
44  const LinOpPtr& precond = LinOpPtr())
45  : Base(mat, precond), m_inexact_residual(false) {}
46 
51  template< typename OperatorType >
52  static uPtr make( const OperatorType& mat, const LinOpPtr& precond = LinOpPtr() )
53  { return uPtr( new gsMinimalResidual(mat, precond) ); }
54 
55  bool initIteration( const VectorType& rhs, VectorType& x );
56  void finalizeIteration( VectorType& x );
57 
58  bool step( VectorType& x );
59 
62  {
64  opt.addSwitch( "InexactResidual",
65  "If true, the residual is estimated, not accurately computed.",
66  false );
67  return opt;
68  }
69 
72  {
73  Base::setOptions(opt);
74  m_inexact_residual = opt.askSwitch("InexactResidual", m_inexact_residual);
75  return *this;
76  }
77 
79  void setInexactResidual( bool flag ) { m_inexact_residual = flag; }
80 
82  std::ostream &print(std::ostream &os) const
83  {
84  os << "gsMinimalResidual\n";
85  return os;
86  }
87 
88 private:
89  using Base::m_mat;
90  using Base::m_precond;
91  using Base::m_max_iters;
92  using Base::m_tol;
93  using Base::m_num_iter;
94  using Base::m_rhs_norm;
95  using Base::m_error;
96 
97  gsMatrix<T> negResidual,
98  vPrev, v, vNew,
99  wPrev, w, wNew, AwPrev, Aw, AwNew,
100  zNew, z, Az;
101 
102  T eta,
103  gammaPrev, gamma, gammaNew,
104  sPrev, s, sNew,
105  cPrev, c, cNew;
106 
107  bool m_inexact_residual;
108 };
109 
110 } // namespace gismo
111 
112 #ifndef GISMO_BUILD_LIB
113 #include GISMO_HPP_HEADER(gsMinimalResidual.hpp)
114 #endif
const LinOpPtr m_mat
The matrix/operator to be solved for.
Definition: gsIterativeSolver.h:252
void finalizeIteration(VectorType &x)
Some post-processing might be required.
Definition: gsMinimalResidual.hpp:102
virtual gsIterativeSolver & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsIterativeSolver.h:102
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsMinimalResidual.h:82
gsOptionList::Real m_tol
The tolerance for m_error to be reached.
Definition: gsIterativeSolver.h:255
gsMinimalResidual & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsMinimalResidual.h:71
The minimal residual (MinRes) method.
Definition: gsMinimalResidual.h:25
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: gsMinimalResidual.h:61
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
gsMinimalResidual(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsMinimalResidual.h:43
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsMinimalResidual.hpp:18
T m_error
The relative error as absolute_error/m_rhs_norm.
Definition: gsIterativeSolver.h:258
Abstract class for iterative solvers.
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsMinimalResidual.hpp:54
void setInexactResidual(bool flag)
If true, the residual is estimated, not accurately computed.
Definition: gsMinimalResidual.h:79
bool askSwitch(const std::string &label, const bool &value=false) const
Reads value for option label from options.
Definition: gsOptionList.cpp:128
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
static uPtr make(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Make function using a matrix (operator) and optionally a preconditionner.
Definition: gsMinimalResidual.h:52
void addSwitch(const std::string &label, const std::string &desc, const bool &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:235
index_t m_num_iter
The number of iterations performed.
Definition: gsIterativeSolver.h:256
LinOpPtr m_precond
The preconditioner.
Definition: gsIterativeSolver.h:253