Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
shifted_matrix.h
1 // ---------------------------------------------------------------------
2 // @f$Id: shifted_matrix.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2001 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__shifted_matrix_h
18 #define __deal2__shifted_matrix_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/smartpointer.h>
23 
25 
39 template<class MATRIX>
41 {
42 public:
47  ShiftedMatrix (const MATRIX &A, const double sigma);
48 
52  void shift (const double sigma);
53 
57  double shift () const;
58 
62  template <class VECTOR>
63  void vmult (VECTOR &dst, const VECTOR &src) const;
64 
68  template <class VECTOR>
69  double residual (VECTOR &dst, const VECTOR &src, const VECTOR &rhs) const;
70 
71 private:
76 
80  // VECTOR aux;
84  double sigma;
85 };
86 
87 
88 
98 template<class MATRIX, class MASSMATRIX, class VECTOR>
100 {
101 public:
107  const MASSMATRIX &M,
108  const double sigma);
109 
113  void shift (const double sigma);
114 
118  double shift () const;
119 
123  void vmult (VECTOR &dst, const VECTOR &src) const;
124 
128  double residual (VECTOR &dst, const VECTOR &src, const VECTOR &rhs) const;
129 
130 private:
139 
143  VECTOR aux;
144 
148  double sigma;
149 };
150 
151 
153 //---------------------------------------------------------------------------
154 
155 template <class MATRIX>
156 inline
157 ShiftedMatrix<MATRIX>::ShiftedMatrix (const MATRIX &A, const double sigma)
158  :
159  A(&A), sigma(sigma)
160 {}
161 
162 
163 
164 template <class MATRIX>
165 inline void
167 {
168  sigma = s;
169 }
170 
171 
172 template <class MATRIX>
173 inline double
175 {
176  return sigma;
177 }
178 
179 
180 
181 template <class MATRIX>
182 template <class VECTOR>
183 inline void
184 ShiftedMatrix<MATRIX>::vmult (VECTOR &dst, const VECTOR &src) const
185 {
186  A->vmult(dst, src);
187  if (sigma != 0.)
188  dst.add(sigma, src);
189 }
190 
191 
192 template <class MATRIX>
193 template <class VECTOR>
194 inline double
196  const VECTOR &src,
197  const VECTOR &rhs) const
198 {
199  A->vmult(dst, src);
200  if (sigma != 0.)
201  dst.add(sigma, src);
202  dst.sadd(-1.,1.,rhs);
203  return dst.l2_norm ();
204 }
205 
206 
207 //---------------------------------------------------------------------------
208 template <class MATRIX, class MASSMATRIX, class VECTOR>
209 inline
212  const MASSMATRIX &M,
213  const double sigma)
214  :
215  A(&A), M(&M), sigma(sigma)
216 {}
217 
218 
219 template <class MATRIX, class MASSMATRIX, class VECTOR>
220 inline void
222 {
223  sigma = s;
224 }
225 
226 template <class MATRIX, class MASSMATRIX, class VECTOR>
227 inline double
229 {
230  return sigma;
231 }
232 
233 
234 template <class MATRIX, class MASSMATRIX, class VECTOR>
235 inline void
237  const VECTOR &src) const
238 {
239  A->vmult(dst, src);
240  if (sigma != 0.)
241  {
242  aux.reinit(dst);
243  M.vmult(aux, src);
244  dst.add(sigma, aux);
245  }
246 }
247 
248 
249 template <class MATRIX, class MASSMATRIX, class VECTOR>
250 inline double
252  const VECTOR &src,
253  const VECTOR &rhs) const
254 {
255  A->vmult(dst, src);
256  if (sigma != 0.)
257  {
258  aux.reinit(dst);
259  M.vmult(aux, src);
260  dst.add(sigma, aux);
261  }
262  dst.sadd(-1.,1.,rhs);
263  return dst.l2_norm ();
264 }
265 
266 
267 DEAL_II_NAMESPACE_CLOSE
268 
269 #endif
SmartPointer< const MATRIX, ShiftedMatrixGeneralized< MATRIX, MASSMATRIX, VECTOR > > A
ShiftedMatrixGeneralized(const MATRIX &A, const MASSMATRIX &M, const double sigma)
void vmult(VECTOR &dst, const VECTOR &src) const
double residual(VECTOR &dst, const VECTOR &src, const VECTOR &rhs) const
SmartPointer< const MATRIX, ShiftedMatrix< MATRIX > > A
ShiftedMatrix(const MATRIX &A, const double sigma)
void vmult(VECTOR &dst, const VECTOR &src) const
double residual(VECTOR &dst, const VECTOR &src, const VECTOR &rhs) const
SmartPointer< const MASSMATRIX, ShiftedMatrixGeneralized< MATRIX, MASSMATRIX, VECTOR > > M
double shift() const