TBCI Numerical high perf. C++ Library  2.8.0
diagprecond.h
Go to the documentation of this file.
1 
15 #ifndef TBCI_SOLVER_DIAGPRECOND_H
16 #define TBCI_SOLVER_DIAGPRECOND_H
17 
18 #include "tbci/solver/precond.h"
19 
21 
26 template <typename T, typename MatrixType = BdMatrix<T> >
27 class DiagPreconditioner : public Preconditioner_Sig<T, MatrixType>
28 {
29  private:
30  BVector<T> invDiag;
31  bool checkdiag;
32  public:
33  friend class SystemMatrix;
34 
36  {}
38  { update (A); }
40 
41  // update-Funktion
42  void update(const MatrixType &A)
43  {
44  const unsigned int rw = A.rows();
45  if (invDiag.size() != A.rows())
46  invDiag.resize(A.rows());
47  BCHK(invDiag.size() == 0, VecErr, "DiagPrecond::update: NULL ptr", 0,);
48  if (do_expcheck()) {
49  /* Check for diagonal zeros separately */
50  for (unsigned int j = 0; j < rw; ++j)
51  EXPCHK(A.get(j,j) == T(0.0), VecErr, "DiagPrecond::update: Diagonal ZERO", j,);
52  }
53  for (unsigned int i = 0; i < rw; ++i)
54  invDiag.set(i) = T(1.0) / A.get(i,i);
55  }
56 
57 
58  // Solve-Funktionen
59  /* template <typename T> */
60  inline TVector<T> solve(const Vector<T> &v) const
61  {
62  TVector<T> tv(v);
63  return (solve(tv));
64  }
65  /* template <typename T> */
66  inline TVector<T> solve(TVector<T> tv) const
67  {
68  const unsigned long sz = invDiag.size();
69  //const unsigned long sz = tv.size();
70  // FIXME: This is do_vec_mul_vec!
71  do_vec_mul_vec<T> (sz, &tv.setval(0), &invDiag.getcref(0));
72  //for (unsigned int i = 0; i < sz; ++i)
73  // tv.set(tv.get(i) * invDiag.get(i), i);
74  return tv;
75  }
76  /* template <typename T> */
77  inline TVector<T> transSolve(const Vector<T> &v) const
78  { return solve(v); }
79  /* template <typename T> */
80  inline TVector<T> transSolve(TVector<T> tv) const
81  { return solve(tv); }
82 
83 };
84 
86 
87 #endif /* TBCI_SOLVER_DIAGPRECOND_H */
Abstract base class for all Preconditioners.
Definition: precond.h:40
T & setval(const unsigned long i) const
Definition: vector.h:192
provides basic Vector functionality but arithmetic operators (+=, - , *, /...).
Definition: bvector.h:67
TVector< T > solve(const Vector< T > &v) const
Definition: diagprecond.h:60
#define NAMESPACE_TBCI
Definition: basics.h:317
#define BCHK(cond, exc, txt, ind, rtval)
Definition: basics.h:575
TVector< T > transSolve(const Vector< T > &v) const
Definition: diagprecond.h:77
#define MatrixType
friend class SystemMatrix
Definition: diagprecond.h:33
DiagPreconditioner(const MatrixType &A)
Definition: diagprecond.h:37
#define EXPCHK(cond, exc, txt, ind, rtval)
Definition: basics.h:630
int i
Definition: LM_fit.h:71
unsigned int do_expcheck()
Definition: tbci_param.h:144
TVector< T > solve(TVector< T > tv) const
Definition: diagprecond.h:66
Temporary Base Class Idiom: Class TVector is used for temporary variables.
Definition: bvector.h:52
#define NAMESPACE_END
Definition: basics.h:323
Definition: bvector.h:54
#define T
Definition: bdmatlib.cc:20
TVector< T > transSolve(TVector< T > tv) const
Definition: diagprecond.h:80
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
&lt; find minimun of func on grid with resolution res
Definition: LM_fit.h:205
void update(const MatrixType &A)
Definition: diagprecond.h:42
exception class
Definition: bvector.h:31