Reference documentation for deal.II version 8.5.1
shifted_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2015 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__shifted_matrix_h
17 #define dealii__shifted_matrix_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/smartpointer.h>
22 
23 DEAL_II_NAMESPACE_OPEN
24 
42 template<typename MatrixType>
44 {
45 public:
49  ShiftedMatrix (const MatrixType &A, const double sigma);
50 
54  void shift (const double sigma);
55 
59  double shift () const;
60 
64  template <typename VectorType>
65  void vmult (VectorType &dst, const VectorType &src) const;
66 
70  template <typename VectorType>
71  double residual (VectorType &dst, const VectorType &src, const VectorType &rhs) const;
72 
73 private:
78 
82  // VectorType aux;
86  double sigma;
87 };
88 
89 
90 
106 template<typename MatrixType, class MatrixType2, class VectorType>
108 {
109 public:
113  ShiftedMatrixGeneralized (const MatrixType &A,
114  const MatrixType2 &M,
115  const double sigma);
116 
120  void shift (const double sigma);
121 
125  double shift () const;
126 
130  void vmult (VectorType &dst, const VectorType &src) const;
131 
135  double residual (VectorType &dst, const VectorType &src, const VectorType &rhs) const;
136 
137 private:
146 
150  mutable VectorType aux;
151 
155  double sigma;
156 };
157 
158 
160 //---------------------------------------------------------------------------
161 
162 template <typename MatrixType>
163 inline
165  const double sigma)
166  :
167  A(&A), sigma(sigma)
168 {}
169 
170 
171 
172 template <typename MatrixType>
173 inline void
175 {
176  sigma = s;
177 }
178 
179 
180 template <typename MatrixType>
181 inline double
183 {
184  return sigma;
185 }
186 
187 
188 
189 template <typename MatrixType>
190 template <class VectorType>
191 inline void
192 ShiftedMatrix<MatrixType>::vmult (VectorType &dst, const VectorType &src) const
193 {
194  A->vmult(dst, src);
195  if (sigma != 0.)
196  dst.add(sigma, src);
197 }
198 
199 
200 template <typename MatrixType>
201 template <class VectorType>
202 inline double
204  const VectorType &src,
205  const VectorType &rhs) const
206 {
207  A->vmult(dst, src);
208  if (sigma != 0.)
209  dst.add(sigma, src);
210  dst.sadd(-1.,1.,rhs);
211  return dst.l2_norm ();
212 }
213 
214 
215 //---------------------------------------------------------------------------
216 template <typename MatrixType, class MatrixType2, class VectorType>
217 inline
219 ::ShiftedMatrixGeneralized (const MatrixType &A,
220  const MatrixType2 &M,
221  const double sigma)
222  :
223  A(&A), M(&M), sigma(sigma)
224 {}
225 
226 
227 template <typename MatrixType, class MatrixType2, class VectorType>
228 inline void
230 {
231  sigma = s;
232 }
233 
234 template <typename MatrixType, class MatrixType2, class VectorType>
235 inline double
237 {
238  return sigma;
239 }
240 
241 
242 template <typename MatrixType, class MatrixType2, class VectorType>
243 inline void
245 (VectorType &dst,
246  const VectorType &src) const
247 {
248  A->vmult(dst, src);
249  if (sigma != 0.)
250  {
251  aux.reinit(dst);
252  M->vmult(aux, src);
253  dst.add(sigma, aux);
254  }
255 }
256 
257 
258 template <typename MatrixType, class MatrixType2, class VectorType>
259 inline double
261 (VectorType &dst,
262  const VectorType &src,
263  const VectorType &rhs) const
264 {
265  A->vmult(dst, src);
266  if (sigma != 0.)
267  {
268  aux.reinit(dst);
269  M->vmult(aux, src);
270  dst.add(sigma, aux);
271  }
272  dst.sadd(-1.,1.,rhs);
273  return dst.l2_norm ();
274 }
275 
276 
277 DEAL_II_NAMESPACE_CLOSE
278 
279 #endif
SmartPointer< const MatrixType2, ShiftedMatrixGeneralized< MatrixType, MatrixType2, VectorType > > M
SmartPointer< const MatrixType, ShiftedMatrixGeneralized< MatrixType, MatrixType2, VectorType > > A
double residual(VectorType &dst, const VectorType &src, const VectorType &rhs) const
double residual(VectorType &dst, const VectorType &src, const VectorType &rhs) const
void vmult(VectorType &dst, const VectorType &src) const
ShiftedMatrixGeneralized(const MatrixType &A, const MatrixType2 &M, const double sigma)
ShiftedMatrix(const MatrixType &A, const double sigma)
SmartPointer< const MatrixType, ShiftedMatrix< MatrixType > > A
double shift() const
void vmult(VectorType &dst, const VectorType &src) const