vrcore  0.45
visuReal Messkern
 All Classes Files Functions Variables
precond.hpp
Go to the documentation of this file.
1 
3 // Copyright Gunter Winkler 2004 - 2007.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 // authors: Gunter Winkler <guwi17 at gmx dot de>
9 
10 
11 #ifndef _H_PRECOND_HPP_
12 #define _H_PRECOND_HPP_
13 
14 #include <iostream>
15 
16 #include <boost/numeric/ublas/vector_expression.hpp>
17 
18 #include "cholesky.hpp"
19 
20 namespace ublas = boost::numeric::ublas;
21 
24 template < class MATRIX = int >
26 
27 public:
28  IdentityPreconditioner(const MATRIX& A) { }
29 
30  template<class Vector>
31  void apply(const Vector& b, Vector& x) const
32  {
33  x = b;
34  }
35 private:
37 };
38 
41 template<class Matrix>
43 
44 public:
45  typedef typename Matrix::value_type value_type;
46  typedef typename Matrix::size_type size_type;
47 
48  DiagonalPreconditioner(const Matrix & A, const double eps = 1.0e-14)
49  : diag(A.size1()), EPS(eps)
50  {
51  for (size_type i=0; i<A.size1(); ++i) {
52  if ( fabs( A(i,i) ) > EPS ) {
53  diag(i) = 1.0 / A(i,i);
54  } else {
55  diag(i) = 0;
56  }
57  }
58  }
59 
60  template<class Vector>
61  void apply(const Vector& b, Vector& x) const
62  {
63  x = element_prod( diag, b );
64  }
65 
66 private:
68  ublas::vector< value_type > diag;
69  const double EPS;
70 
71 };
72 
73 template <class Matrix>
75 make_DiagonalPreconditioner(const Matrix & A, const double eps = 1.0e-14)
76 {
77  return DiagonalPreconditioner<Matrix>(A, eps);
78 }
79 
80 
85 template<class Matrix> class CholeskyPreconditioner {
86 
87 public:
88  CholeskyPreconditioner(const Matrix & A) : L(A)
89  {
91  }
92 
93  template<class Vector>
94  void apply(const Vector& b, Vector& x) const
95  {
96  x = b;
97  cholesky_solve(L, x, ublas::lower());
98  }
99 
100 private:
102  Matrix L;
103 };
104 
105 
106 template <class Matrix>
108 make_CholeskyPreconditioner(const Matrix & A)
109 {
111 }
112 
113 
114 
121 template<class Matrix> class IncompleteCholeskyPreconditioner {
122 
123 public:
124  IncompleteCholeskyPreconditioner(const Matrix & A) : L(A)
125  {
127  }
128 
129  template<class Vector>
130  void apply(const Vector& b, Vector& x) const
131  {
132  x = b;
133  cholesky_solve(L, x, ublas::lower());
134  }
135 
136 private:
138  Matrix L;
139 };
140 
141 
142 template <class Matrix>
144 make_IncompleteCholeskyPreconditioner(const Matrix & A)
145 {
147 }
148 
149 
150 #endif
scales x with diagonal of a given matrix
Definition: precond.hpp:42
cholesky decomposition
decomposes given matrix and solve L L^T x = b
Definition: precond.hpp:121
size_t cholesky_decompose(const MATRIX &A, TRIA &L)
decompose the symmetric positive definit matrix A into product L L^T.
Definition: cholesky.hpp:51
void cholesky_solve(const TRIA &L, VEC &x, ublas::lower)
solve system L L^T x = b inplace
Definition: cholesky.hpp:220
size_t incomplete_cholesky_decompose(MATRIX &A)
decompose the symmetric positive definit matrix A into product L L^T.
Definition: cholesky.hpp:172
Do-nothing preconditioner.
Definition: precond.hpp:25
decomposes given matrix and solve L L^T x = b
Definition: precond.hpp:85