Reference documentation for deal.II version GIT 3d869ba6cd 2022-05-16 18:15:01+00:00
\(\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 - 2021 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 {
43  template <typename VectorType = Vector<double>>
44  class Matrix : public MGMatrixBase<VectorType>
45  {
46  public:
50  Matrix() = default;
51 
56  template <typename MatrixType>
58 
63  template <typename MatrixType>
64  void
66 
70  void
71  reset();
72 
77  operator[](unsigned int level) const;
78 
79  virtual void
80  vmult(const unsigned int level,
81  VectorType & dst,
82  const VectorType & src) const override;
83  virtual void
84  vmult_add(const unsigned int level,
85  VectorType & dst,
86  const VectorType & src) const override;
87  virtual void
88  Tvmult(const unsigned int level,
89  VectorType & dst,
90  const VectorType & src) const override;
91  virtual void
92  Tvmult_add(const unsigned int level,
93  VectorType & dst,
94  const VectorType & src) const override;
95  virtual unsigned int
96  get_minlevel() const override;
97  virtual unsigned int
98  get_maxlevel() const override;
99 
103  std::size_t
104  memory_consumption() const;
105 
106  private:
108  };
109 
110 } // namespace mg
111 
112 
121 template <typename MatrixType, typename number>
122 class MGMatrixSelect : public MGMatrixBase<Vector<number>>
123 {
124 public:
129  MGMatrixSelect(const unsigned int row = 0,
130  const unsigned int col = 0,
132 
137  void
139 
143  void
144  select_block(const unsigned int row, const unsigned int col);
145 
149  virtual void
150  vmult(const unsigned int level,
151  Vector<number> & dst,
152  const Vector<number> &src) const;
153 
157  virtual void
158  vmult_add(const unsigned int level,
159  Vector<number> & dst,
160  const Vector<number> &src) const;
161 
165  virtual void
166  Tvmult(const unsigned int level,
167  Vector<number> & dst,
168  const Vector<number> &src) const;
169 
173  virtual void
174  Tvmult_add(const unsigned int level,
175  Vector<number> & dst,
176  const Vector<number> &src) const;
177 
178 private:
187  unsigned int row;
191  unsigned int col;
192 };
193 
196 /*----------------------------------------------------------------------*/
197 
198 namespace mg
199 {
200  template <typename VectorType>
201  template <typename MatrixType>
202  inline void
204  {
205  matrices.resize(p.min_level(), p.max_level());
206  for (unsigned int level = p.min_level(); level <= p.max_level(); ++level)
207  {
208  // Workaround: Unfortunately, not every "p[level]" object has a
209  // rich enough interface to populate reinit_(domain|range)_vector.
210  // Thus, apply an empty LinearOperator exemplar.
211  matrices[level] =
212  linear_operator<VectorType>(LinearOperator<VectorType>(),
214  p[level]));
215  }
216  }
217 
218 
219 
220  template <typename VectorType>
221  inline void
223  {
224  matrices.resize(0, 0);
225  }
226 
227 
228 
229  template <typename VectorType>
230  template <typename MatrixType>
232  {
233  initialize(p);
234  }
235 
236 
237 
238  template <typename VectorType>
239  inline const LinearOperator<VectorType> &
241  {
242  return matrices[level];
243  }
244 
245 
246 
247  template <typename VectorType>
248  void
249  Matrix<VectorType>::vmult(const unsigned int level,
250  VectorType & dst,
251  const VectorType & src) const
252  {
253  matrices[level].vmult(dst, src);
254  }
255 
256 
257 
258  template <typename VectorType>
259  void
261  VectorType & dst,
262  const VectorType & src) const
263  {
264  matrices[level].vmult_add(dst, src);
265  }
266 
267 
268 
269  template <typename VectorType>
270  void
271  Matrix<VectorType>::Tvmult(const unsigned int level,
272  VectorType & dst,
273  const VectorType & src) const
274  {
275  matrices[level].Tvmult(dst, src);
276  }
277 
278 
279 
280  template <typename VectorType>
281  void
283  VectorType & dst,
284  const VectorType & src) const
285  {
286  matrices[level].Tvmult_add(dst, src);
287  }
288 
289 
290 
291  template <typename VectorType>
292  unsigned int
294  {
295  return matrices.min_level();
296  }
297 
298 
299 
300  template <typename VectorType>
301  unsigned int
303  {
304  return matrices.max_level();
305  }
306 
307 
308 
309  template <typename VectorType>
310  inline std::size_t
312  {
313  return sizeof(*this) + matrices->memory_consumption();
314  }
315 } // namespace mg
316 
317 
318 /*----------------------------------------------------------------------*/
319 
320 template <typename MatrixType, typename number>
322  const unsigned int col,
324  : matrix(p, typeid(*this).name())
325  , row(row)
326  , col(col)
327 {}
328 
329 
330 
331 template <typename MatrixType, typename number>
332 void
334 {
335  matrix = p;
336 }
337 
338 
339 
340 template <typename MatrixType, typename number>
341 void
343  const unsigned int bcol)
344 {
345  row = brow;
346  col = bcol;
347 }
348 
349 
350 
351 template <typename MatrixType, typename number>
352 void
354  Vector<number> & dst,
355  const Vector<number> &src) const
356 {
358 
359  const MGLevelObject<MatrixType> &m = *matrix;
360  m[level].block(row, col).vmult(dst, src);
361 }
362 
363 
364 
365 template <typename MatrixType, typename number>
366 void
368  Vector<number> & dst,
369  const Vector<number> &src) const
370 {
372 
373  const MGLevelObject<MatrixType> &m = *matrix;
374  m[level].block(row, col).vmult_add(dst, src);
375 }
376 
377 
378 
379 template <typename MatrixType, typename number>
380 void
382  Vector<number> & dst,
383  const Vector<number> &src) const
384 {
386 
387  const MGLevelObject<MatrixType> &m = *matrix;
388  m[level].block(row, col).Tvmult(dst, src);
389 }
390 
391 
392 
393 template <typename MatrixType, typename number>
394 void
396  Vector<number> & dst,
397  const Vector<number> &src) const
398 {
400 
401  const MGLevelObject<MatrixType> &m = *matrix;
402  m[level].block(row, col).Tvmult_add(dst, src);
403 }
404 
406 
407 #endif
unsigned int max_level() const
unsigned int min_level() const
void set_matrix(MGLevelObject< MatrixType > *M)
Definition: mg_matrix.h:333
virtual void vmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:353
virtual void vmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:367
MGMatrixSelect(const unsigned int row=0, const unsigned int col=0, MGLevelObject< MatrixType > *matrix=0)
Definition: mg_matrix.h:321
void select_block(const unsigned int row, const unsigned int col)
Definition: mg_matrix.h:342
virtual void Tvmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:381
unsigned int row
Definition: mg_matrix.h:187
SmartPointer< MGLevelObject< MatrixType >, MGMatrixSelect< MatrixType, number > > matrix
Definition: mg_matrix.h:183
unsigned int col
Definition: mg_matrix.h:191
virtual void Tvmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:395
Definition: vector.h:109
virtual unsigned int get_minlevel() const override
Definition: mg_matrix.h:293
virtual void vmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:249
virtual void vmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:260
std::size_t memory_consumption() const
Definition: mg_matrix.h:311
virtual void Tvmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:271
void initialize(const MGLevelObject< MatrixType > &M)
Definition: mg_matrix.h:203
void reset()
Definition: mg_matrix.h:222
virtual unsigned int get_maxlevel() const override
Definition: mg_matrix.h:302
MGLevelObject< LinearOperator< VectorType > > matrices
Definition: mg_matrix.h:107
virtual void Tvmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:282
Matrix()=default
const LinearOperator< VectorType > & operator[](unsigned int level) const
Definition: mg_matrix.h:240
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:416
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:417
unsigned int level
Definition: grid_out.cc:4606
static ::ExceptionBase & ExcNotInitialized()
#define Assert(cond, exc)
Definition: exceptions.h:1473
@ matrix
Contents is actually a matrix.
T & get_underlying_value(T &p)
Definition: utilities.h:1427
Definition: mg.h:82