bicgstab.hh

Go to the documentation of this file.
1 
6 #ifndef bicgstab_hh
7 #define bicgstab_hh
8 
9 #include <string>
10 #include "basics/typedefs.hh"
11 #include "toolbox/sequence.hh"
12 #include "compositions.hh"
13 
14 namespace concepts {
15 
16  // ******************************************************************* CG **
17 
33  template<class F, class G = F>
34  class BiCGStab : public VecOperator<F> {
35  public:
44  BiCGStab(Operator<F>& A, Real maxeps, int maxit = 0,
45  uint relres = false, bool throwing = true)
46  : VecOperator<F>(A.dimY(), A.dimX()), W_(0), A_(A), M_(0)
47  , maxeps_(maxeps), maxit_(maxit), eps_(1.0), it_(0)
48  , relres_(relres), throwing_(throwing), stag_(false) {}
49 
61  BiCGStab(Operator<F>& A, Operator<G>& Minv, Real maxeps, int maxit = 0,
62  bool relres = 0, bool throwing = true, Operator<G>* M = 0)
63  : VecOperator<F>(A.dimY(), A.dimX()), W_(&Minv), A_(A), M_(M)
64  , maxeps_(maxeps), maxit_(maxit), eps_(1.0), it_(0)
65  , relres_(relres), throwing_(throwing), stag_(false) {}
66 
67 // virtual void operator()(const Function<F,G>& fncY, Function<F,G>& fncX);
68 // void operator()(const Vector<F,G>& fncY, Vector<F,G>& fncX);
69 
73  uint iterations() const { return it_; }
74 
78  Real epsilon() const { return eps_; }
80  bool stagnated() const { return stag_; }
81  protected:
82  std::ostream& info(std::ostream& os) const;
83  private:
90 
94  uint maxit_;
100  uint it_;
102  bool relres_;
106  bool throwing_;
108  bool stag_;
109 
110  virtual void apply_();
111  virtual void apply_(const Vector<F>& fncY, Vector<F>& fncX);
112 
116  template<class I>
117  bool scalarTooSmall_(I& scalar, const std::string name, const uint& it,
118  const Real& eps, const Real& maxeps) const;
122  bool converged_(const Vector<F>& fncY, Vector<F>& fncX,
123  const Vector<F>& x, const uint& it, Real& eps,
124  const Real& maxeps, const Real& l2Y);
125  bool stagnated_(const Vector<F>& x, const Vector<F>& s_p,
126  F& alpha_omega);
127  };
128 
129 } // namespace concepts
130 
131 #endif // bicgstab_hh
uint it_
Number of iterations.
Definition: bicgstab.hh:100
bool relres_
false: absolute residual, true: relative residual
Definition: bicgstab.hh:102
Real eps_
Current residual.
Definition: bicgstab.hh:96
Real maxeps_
Convergence criterion.
Definition: bicgstab.hh:92
std::ostream & info(std::ostream &os) const
virtual const uint dimX() const
Returns the size of the image space of the operator (number of rows of the corresponding matrix)
Definition: compositions.hh:93
Operator< G > * M_
Operator which inverse is Minv, for control of residual.
Definition: bicgstab.hh:89
Solves a symmetric system of linear equations with BiConjugate Gradient Stabilized (BICGSTAB).
Definition: bicgstab.hh:34
bool scalarTooSmall_(I &scalar, const std::string name, const uint &it, const Real &eps, const Real &maxeps) const
Checks if the scalar is zero or NaN and throws an exception in this case.
BiCGStab(Operator< F > &A, Operator< G > &Minv, Real maxeps, int maxit=0, bool relres=0, bool throwing=true, Operator< G > *M=0)
Constructor.
Definition: bicgstab.hh:61
Operator< G > * W_
Optional preconditioner.
Definition: bicgstab.hh:85
bool stagnated() const
Return true, if solver stagnated.
Definition: bicgstab.hh:80
uint maxit_
Maximal number of iterations until abortion.
Definition: bicgstab.hh:94
concepts::Sequence< Real > epsVec_
All residual.
Definition: bicgstab.hh:98
Abstract class for an operator.
Definition: ARPACK.hh:16
bool stag_
true: solver stagnated
Definition: bicgstab.hh:108
BiCGStab(Operator< F > &A, Real maxeps, int maxit=0, uint relres=false, bool throwing=true)
Constructor.
Definition: bicgstab.hh:44
Abstract class for an operator acting on vectors only, not arbitrary functions.
bool stagnated_(const Vector< F > &x, const Vector< F > &s_p, F &alpha_omega)
virtual void apply_()
Intrinsic application method without argument.
bool throwing_
false: best solution is given, when non converging true: exception is thrown, when non converging
Definition: bicgstab.hh:106
Operator< F > & A_
Operator which is solved.
Definition: bicgstab.hh:87
uint iterations() const
Returns the number of iterations.
Definition: bicgstab.hh:73
virtual const uint dimY() const
Returns the size of the source space of the operator (number of columns of the corresponding matrix)
Definition: compositions.hh:98
Real epsilon() const
Returns the residual.
Definition: bicgstab.hh:78
bool converged_(const Vector< F > &fncY, Vector< F > &fncX, const Vector< F > &x, const uint &it, Real &eps, const Real &maxeps, const Real &l2Y)
Calculated current residual and return true if its smaller then maxeps.
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
virtual void apply_(const Vector< F > &fncY, Vector< F > &fncX)
Intrinsic application method, i.e.
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich