TBCI Numerical high perf. C++ Library 2.8.0
diagprecond.h
Go to the documentation of this file.
1
14
15#ifndef TBCI_SOLVER_DIAGPRECOND_H
16#define TBCI_SOLVER_DIAGPRECOND_H
17
18#include "tbci/solver/precond.h"
19
21
26template <typename T, typename MatrixType = BdMatrix<T> >
27class DiagPreconditioner : public Preconditioner_Sig<T, MatrixType>
28{
29 private:
30 BVector<T> invDiag;
31 bool checkdiag;
32 public:
33 friend class SystemMatrix;
34
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> */
81 { return solve(tv); }
82
83};
84
86
87#endif /* TBCI_SOLVER_DIAGPRECOND_H */
int i
Definition LM_fit.h:71
#define BCHK(cond, exc, txt, ind, rtval)
Definition basics.h:575
#define NAMESPACE_END
Definition basics.h:323
#define EXPCHK(cond, exc, txt, ind, rtval)
Definition basics.h:630
#define NAMESPACE_TBCI
Definition basics.h:317
#define T
Definition bdmatlib.cc:20
provides basic Vector functionality but arithmetic operators (+=, - , *, /...).
Definition bvector.h:68
TVector< T > solve(const Vector< T > &v) const
Definition diagprecond.h:60
TVector< T > solve(TVector< T > tv) const
Definition diagprecond.h:66
void update(const MatrixType &A)
Definition diagprecond.h:42
TVector< T > transSolve(TVector< T > tv) const
Definition diagprecond.h:80
DiagPreconditioner(const MatrixType &A)
Definition diagprecond.h:37
TVector< T > transSolve(const Vector< T > &v) const
Definition diagprecond.h:77
friend class SystemMatrix
Definition diagprecond.h:33
Temporary Base Class Idiom: Class TVector is used for temporary variables.
Definition vector.h:73
T & setval(const unsigned long i) const
Definition vector.h:192
exception class
Definition bvector.h:32
#define MatrixType
unsigned int do_expcheck()
Definition tbci_param.h:144