Reference documentation for deal.II version 8.5.1
mg_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2016 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__mg_matrix_h
17 #define dealii__mg_matrix_h
18 
19 #include <deal.II/lac/vector.h>
20 #include <deal.II/lac/pointer_matrix.h>
21 #include <deal.II/lac/sparse_matrix.h>
22 #include <deal.II/multigrid/mg_base.h>
23 #include <deal.II/base/mg_level_object.h>
24 #include <deal.II/base/std_cxx11/shared_ptr.h>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
30 
31 namespace mg
32 {
41  template <typename VectorType = Vector<double> >
42  class Matrix
43  : public MGMatrixBase<VectorType>
44  {
45  public:
49  Matrix();
50 
55  template <typename MatrixType>
57 
62  template <typename MatrixType>
63  void
65 
69  const PointerMatrixBase<VectorType> &operator[] (unsigned int level) const;
70 
71  virtual void vmult (const unsigned int level, VectorType &dst, const VectorType &src) const;
72  virtual void vmult_add (const unsigned int level, VectorType &dst, const VectorType &src) const;
73  virtual void Tvmult (const unsigned int level, VectorType &dst, const VectorType &src) const;
74  virtual void Tvmult_add (const unsigned int level, VectorType &dst, const VectorType &src) const;
75  virtual unsigned int get_minlevel() const;
76  virtual unsigned int get_maxlevel() const;
77 
81  std::size_t memory_consumption () const;
82  private:
84  };
85 
86 }
87 
88 
99 template <typename MatrixType, typename number>
100 class MGMatrixSelect : public MGMatrixBase<Vector<number> >
101 {
102 public:
107  MGMatrixSelect (const unsigned int row = 0,
108  const unsigned int col = 0,
110 
116 
120  void select_block (const unsigned int row,
121  const unsigned int col);
122 
126  virtual void vmult (const unsigned int level,
127  Vector<number> &dst,
128  const Vector<number> &src) const;
129 
133  virtual void vmult_add (const unsigned int level,
134  Vector<number> &dst,
135  const Vector<number> &src) const;
136 
140  virtual void Tvmult (const unsigned int level,
141  Vector<number> &dst,
142  const Vector<number> &src) const;
143 
147  virtual void Tvmult_add (const unsigned int level,
148  Vector<number> &dst,
149  const Vector<number> &src) const;
150 
151 private:
159  unsigned int row;
163  unsigned int col;
164 
165 };
166 
169 /*----------------------------------------------------------------------*/
170 
171 namespace mg
172 {
173  template <typename VectorType>
174  template <typename MatrixType>
175  inline
176  void
178  {
179  matrices.resize(p.min_level(), p.max_level());
180  for (unsigned int level=p.min_level(); level <= p.max_level(); ++level)
181  matrices[level] = std_cxx11::shared_ptr<PointerMatrixBase<VectorType> >
182  (new_pointer_matrix_base(p[level], VectorType()));
183  }
184 
185 
186 
187  template <typename VectorType>
188  template <typename MatrixType>
189  inline
191  {
192  initialize(p);
193  }
194 
195 
196 
197  template <typename VectorType>
198  inline
200  {}
201 
202 
203 
204  template <typename VectorType>
205  inline
207  Matrix<VectorType>::operator[] (unsigned int level) const
208  {
209  return *matrices[level];
210  }
211 
212 
213 
214  template <typename VectorType>
215  void
216  Matrix<VectorType>::vmult (const unsigned int level,
217  VectorType &dst,
218  const VectorType &src) const
219  {
220  matrices[level]->vmult(dst, src);
221  }
222 
223 
224 
225  template <typename VectorType>
226  void
227  Matrix<VectorType>::vmult_add (const unsigned int level,
228  VectorType &dst,
229  const VectorType &src) const
230  {
231  matrices[level]->vmult_add(dst, src);
232  }
233 
234 
235 
236  template <typename VectorType>
237  void
238  Matrix<VectorType>::Tvmult (const unsigned int level,
239  VectorType &dst,
240  const VectorType &src) const
241  {
242  matrices[level]->Tvmult(dst, src);
243  }
244 
245 
246 
247  template <typename VectorType>
248  void
249  Matrix<VectorType>::Tvmult_add (const unsigned int level,
250  VectorType &dst,
251  const VectorType &src) const
252  {
253  matrices[level]->Tvmult_add(dst, src);
254  }
255 
256 
257 
258  template <typename VectorType>
259  unsigned int
261  {
262  return matrices.min_level();
263  }
264 
265 
266 
267  template <typename VectorType>
268  unsigned int
270  {
271  return matrices.max_level();
272  }
273 
274 
275 
276  template <typename VectorType>
277  inline
278  std::size_t
280  {
281  return sizeof(*this) + matrices->memory_consumption();
282  }
283 }
284 
285 
286 /*----------------------------------------------------------------------*/
287 
288 template <typename MatrixType, typename number>
290 MGMatrixSelect (const unsigned int row,
291  const unsigned int col,
293  :
294  matrix (p, typeid(*this).name()),
295  row(row),
296  col(col)
297 {}
298 
299 
300 
301 template <typename MatrixType, typename number>
302 void
304 {
305  matrix = p;
306 }
307 
308 
309 
310 template <typename MatrixType, typename number>
311 void
313 select_block (const unsigned int brow,
314  const unsigned int bcol)
315 {
316  row = brow;
317  col = bcol;
318 }
319 
320 
321 
322 template <typename MatrixType, typename number>
323 void
325 vmult (const unsigned int level,
326  Vector<number> &dst,
327  const Vector<number> &src) const
328 {
329  Assert(matrix != 0, ExcNotInitialized());
330 
331  const MGLevelObject<MatrixType> &m = *matrix;
332  m[level].block(row, col).vmult(dst, src);
333 }
334 
335 
336 
337 template <typename MatrixType, typename number>
338 void
340 vmult_add (const unsigned int level,
341  Vector<number> &dst,
342  const Vector<number> &src) const
343 {
344  Assert(matrix != 0, ExcNotInitialized());
345 
346  const MGLevelObject<MatrixType> &m = *matrix;
347  m[level].block(row, col).vmult_add(dst, src);
348 }
349 
350 
351 
352 template <typename MatrixType, typename number>
353 void
355 Tvmult (const unsigned int level,
356  Vector<number> &dst,
357  const Vector<number> &src) const
358 {
359  Assert(matrix != 0, ExcNotInitialized());
360 
361  const MGLevelObject<MatrixType> &m = *matrix;
362  m[level].block(row, col).Tvmult(dst, src);
363 }
364 
365 
366 
367 template <typename MatrixType, typename number>
368 void
370 Tvmult_add (const unsigned int level,
371  Vector<number> &dst,
372  const Vector<number> &src) const
373 {
374  Assert(matrix != 0, ExcNotInitialized());
375 
376  const MGLevelObject<MatrixType> &m = *matrix;
377  m[level].block(row, col).Tvmult_add(dst, src);
378 }
379 
380 DEAL_II_NAMESPACE_CLOSE
381 
382 #endif
unsigned int max_level() const
MGMatrixSelect(const unsigned int row=0, const unsigned int col=0, MGLevelObject< MatrixType > *matrix=0)
Definition: mg_matrix.h:290
unsigned int col
Definition: mg_matrix.h:163
virtual unsigned int get_maxlevel() const
Definition: mg_matrix.h:269
virtual void vmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:340
Definition: mg.h:81
virtual void Tvmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:355
void select_block(const unsigned int row, const unsigned int col)
Definition: mg_matrix.h:313
void set_matrix(MGLevelObject< MatrixType > *M)
Definition: mg_matrix.h:303
virtual void vmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const
Definition: mg_matrix.h:227
static ::ExceptionBase & ExcNotInitialized()
unsigned int min_level() const
SmartPointer< MGLevelObject< MatrixType >, MGMatrixSelect< MatrixType, number > > matrix
Definition: mg_matrix.h:155
#define Assert(cond, exc)
Definition: exceptions.h:313
unsigned int row
Definition: mg_matrix.h:159
const PointerMatrixBase< VectorType > & operator[](unsigned int level) const
Definition: mg_matrix.h:207
virtual void Tvmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const
Definition: mg_matrix.h:249
void initialize(const MGLevelObject< MatrixType > &M)
Definition: mg_matrix.h:177
virtual void vmult(const unsigned int level, VectorType &dst, const VectorType &src) const
Definition: mg_matrix.h:216
virtual void Tvmult(const unsigned int level, VectorType &dst, const VectorType &src) const
Definition: mg_matrix.h:238
virtual unsigned int get_minlevel() const
Definition: mg_matrix.h:260
virtual void vmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:325
virtual void Tvmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:370
std::size_t memory_consumption() const
Definition: mg_matrix.h:279