Reference documentation for deal.II version Git 423cd11810 2020-05-28 01:07:25 +0200
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
mg_matrix.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2019 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_mg_matrix_h
17 #define dealii_mg_matrix_h
18 
19 #include <deal.II/base/config.h>
20 
22 
25 #include <deal.II/lac/vector.h>
26 
28 
29 #include <memory>
30 
32 
35 
36 namespace mg
37 {
46  template <typename VectorType = Vector<double>>
47  class Matrix : public MGMatrixBase<VectorType>
48  {
49  public:
53  Matrix() = default;
54 
59  template <typename MatrixType>
61 
66  template <typename MatrixType>
67  void
69 
73  void
74  reset();
75 
79  const LinearOperator<VectorType> &operator[](unsigned int level) const;
80 
81  virtual void
82  vmult(const unsigned int level,
83  VectorType & dst,
84  const VectorType & src) const override;
85  virtual void
86  vmult_add(const unsigned int level,
87  VectorType & dst,
88  const VectorType & src) const override;
89  virtual void
90  Tvmult(const unsigned int level,
91  VectorType & dst,
92  const VectorType & src) const override;
93  virtual void
94  Tvmult_add(const unsigned int level,
95  VectorType & dst,
96  const VectorType & src) const override;
97  virtual unsigned int
98  get_minlevel() const override;
99  virtual unsigned int
100  get_maxlevel() const override;
101 
105  std::size_t
106  memory_consumption() const;
107 
108  private:
110  };
111 
112 } // namespace mg
113 
114 
125 template <typename MatrixType, typename number>
126 class MGMatrixSelect : public MGMatrixBase<Vector<number>>
127 {
128 public:
133  MGMatrixSelect(const unsigned int row = 0,
134  const unsigned int col = 0,
136 
141  void
142  set_matrix(MGLevelObject<MatrixType> *M);
143 
147  void
148  select_block(const unsigned int row, const unsigned int col);
149 
153  virtual void
154  vmult(const unsigned int level,
155  Vector<number> & dst,
156  const Vector<number> &src) const;
157 
161  virtual void
162  vmult_add(const unsigned int level,
163  Vector<number> & dst,
164  const Vector<number> &src) const;
165 
169  virtual void
170  Tvmult(const unsigned int level,
171  Vector<number> & dst,
172  const Vector<number> &src) const;
173 
177  virtual void
178  Tvmult_add(const unsigned int level,
179  Vector<number> & dst,
180  const Vector<number> &src) const;
181 
182 private:
191  unsigned int row;
195  unsigned int col;
196 };
197 
200 /*----------------------------------------------------------------------*/
201 
202 namespace mg
203 {
204  template <typename VectorType>
205  template <typename MatrixType>
206  inline void
208  {
210  for (unsigned int level = p.min_level(); level <= p.max_level(); ++level)
211  {
212  // Workaround: Unfortunately, not every "p[level]" object has a
213  // rich enough interface to populate reinit_(domain|range)_vector.
214  // Thus, apply an empty LinearOperator exemplar.
215  matrices[level] =
216  linear_operator<VectorType>(LinearOperator<VectorType>(), p[level]);
217  }
218  }
219 
220 
221 
222  template <typename VectorType>
223  inline void
225  {
226  matrices.resize(0, 0);
227  }
228 
229 
230 
231  template <typename VectorType>
232  template <typename MatrixType>
234  {
235  initialize(p);
236  }
237 
238 
239 
240  template <typename VectorType>
242  operator[](unsigned int level) const
243  {
244  return matrices[level];
245  }
246 
247 
248 
249  template <typename VectorType>
250  void
251  Matrix<VectorType>::vmult(const unsigned int level,
252  VectorType & dst,
253  const VectorType & src) const
254  {
255  matrices[level].vmult(dst, src);
256  }
257 
258 
259 
260  template <typename VectorType>
261  void
263  VectorType & dst,
264  const VectorType & src) const
265  {
266  matrices[level].vmult_add(dst, src);
267  }
268 
269 
270 
271  template <typename VectorType>
272  void
273  Matrix<VectorType>::Tvmult(const unsigned int level,
274  VectorType & dst,
275  const VectorType & src) const
276  {
277  matrices[level].Tvmult(dst, src);
278  }
279 
280 
281 
282  template <typename VectorType>
283  void
285  VectorType & dst,
286  const VectorType & src) const
287  {
288  matrices[level].Tvmult_add(dst, src);
289  }
290 
291 
292 
293  template <typename VectorType>
294  unsigned int
296  {
297  return matrices.min_level();
298  }
299 
300 
301 
302  template <typename VectorType>
303  unsigned int
305  {
306  return matrices.max_level();
307  }
308 
309 
310 
311  template <typename VectorType>
312  inline std::size_t
314  {
315  return sizeof(*this) + matrices->memory_consumption();
316  }
317 } // namespace mg
318 
319 
320 /*----------------------------------------------------------------------*/
321 
322 template <typename MatrixType, typename number>
324  const unsigned int col,
326  : matrix(p, typeid(*this).name())
327  , row(row)
328  , col(col)
329 {}
330 
331 
332 
333 template <typename MatrixType, typename number>
334 void
336 {
337  matrix = p;
338 }
339 
340 
341 
342 template <typename MatrixType, typename number>
343 void
345  const unsigned int bcol)
346 {
347  row = brow;
348  col = bcol;
349 }
350 
351 
352 
353 template <typename MatrixType, typename number>
354 void
356  Vector<number> & dst,
357  const Vector<number> &src) const
358 {
360 
361  const MGLevelObject<MatrixType> &m = *matrix;
362  m[level].block(row, col).vmult(dst, src);
363 }
364 
365 
366 
367 template <typename MatrixType, typename number>
368 void
370  Vector<number> & dst,
371  const Vector<number> &src) const
372 {
374 
375  const MGLevelObject<MatrixType> &m = *matrix;
376  m[level].block(row, col).vmult_add(dst, src);
377 }
378 
379 
380 
381 template <typename MatrixType, typename number>
382 void
384  Vector<number> & dst,
385  const Vector<number> &src) const
386 {
388 
389  const MGLevelObject<MatrixType> &m = *matrix;
390  m[level].block(row, col).Tvmult(dst, src);
391 }
392 
393 
394 
395 template <typename MatrixType, typename number>
396 void
398  Vector<number> & dst,
399  const Vector<number> &src) const
400 {
402 
403  const MGLevelObject<MatrixType> &m = *matrix;
404  m[level].block(row, col).Tvmult_add(dst, src);
405 }
406 
408 
409 #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:323
unsigned int col
Definition: mg_matrix.h:195
Contents is actually a matrix.
Matrix()=default
virtual void vmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:369
Definition: mg.h:81
virtual void Tvmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:383
virtual void Tvmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:273
void select_block(const unsigned int row, const unsigned int col)
Definition: mg_matrix.h:344
void set_matrix(MGLevelObject< MatrixType > *M)
Definition: mg_matrix.h:335
static ::ExceptionBase & ExcNotInitialized()
void reset()
Definition: mg_matrix.h:224
std::size_t memory_consumption() const
unsigned int min_level() const
const LinearOperator< VectorType > & operator[](unsigned int level) const
Definition: mg_matrix.h:242
virtual void vmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:251
MGLevelObject< LinearOperator< VectorType > > matrices
Definition: mg_matrix.h:109
#define Assert(cond, exc)
Definition: exceptions.h:1419
unsigned int row
Definition: mg_matrix.h:191
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:362
unsigned int level
Definition: grid_out.cc:4355
void initialize(const MGLevelObject< MatrixType > &M)
Definition: mg_matrix.h:207
virtual unsigned int get_maxlevel() const override
Definition: mg_matrix.h:304
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:361
SmartPointer< MGLevelObject< MatrixType >, MGMatrixSelect< MatrixType, number > > matrix
Definition: mg_matrix.h:187
virtual unsigned int get_minlevel() const override
Definition: mg_matrix.h:295
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
virtual void vmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:262
virtual void Tvmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:284
virtual void vmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:355
virtual void Tvmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:397
std::size_t memory_consumption() const
Definition: mg_matrix.h:313