Reference documentation for deal.II version GIT 29f9da0a34 2023-12-07 10:00: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 - 2022 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 
38 namespace mg
39 {
45  template <typename VectorType = Vector<double>>
46  class Matrix : public MGMatrixBase<VectorType>
47  {
48  public:
52  Matrix() = default;
53 
58  template <typename MatrixType>
60 
65  template <typename MatrixType>
66  void
68 
72  void
73  reset();
74 
79  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 
123 template <typename MatrixType, typename number>
124 class MGMatrixSelect : public MGMatrixBase<Vector<number>>
125 {
126 public:
131  MGMatrixSelect(const unsigned int row = 0,
132  const unsigned int col = 0,
134 
139  void
141 
145  void
146  select_block(const unsigned int row, const unsigned int col);
147 
151  virtual void
152  vmult(const unsigned int level,
153  Vector<number> &dst,
154  const Vector<number> &src) const;
155 
159  virtual void
160  vmult_add(const unsigned int level,
161  Vector<number> &dst,
162  const Vector<number> &src) const;
163 
167  virtual void
168  Tvmult(const unsigned int level,
169  Vector<number> &dst,
170  const Vector<number> &src) const;
171 
175  virtual void
176  Tvmult_add(const unsigned int level,
177  Vector<number> &dst,
178  const Vector<number> &src) const;
179 
180 private:
189  unsigned int row;
193  unsigned int col;
194 };
195 
198 /*----------------------------------------------------------------------*/
199 
200 namespace mg
201 {
202  template <typename VectorType>
203  template <typename MatrixType>
204  inline void
206  {
207  matrices.resize(p.min_level(), p.max_level());
208  for (unsigned int level = p.min_level(); level <= p.max_level(); ++level)
209  {
210  // Workaround: Unfortunately, not every "p[level]" object has a
211  // rich enough interface to populate reinit_(domain|range)_vector.
212  // Thus, apply an empty LinearOperator exemplar.
213  matrices[level] =
214  linear_operator<VectorType>(LinearOperator<VectorType>(),
216  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>
241  inline const LinearOperator<VectorType> &
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
unsigned int min_level() const
void set_matrix(MGLevelObject< MatrixType > *M)
Definition: mg_matrix.h:335
virtual void vmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:355
virtual void vmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:369
MGMatrixSelect(const unsigned int row=0, const unsigned int col=0, MGLevelObject< MatrixType > *matrix=0)
Definition: mg_matrix.h:323
void select_block(const unsigned int row, const unsigned int col)
Definition: mg_matrix.h:344
virtual void Tvmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:383
unsigned int row
Definition: mg_matrix.h:189
SmartPointer< MGLevelObject< MatrixType >, MGMatrixSelect< MatrixType, number > > matrix
Definition: mg_matrix.h:185
unsigned int col
Definition: mg_matrix.h:193
virtual void Tvmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition: mg_matrix.h:397
Definition: vector.h:110
virtual unsigned int get_minlevel() const override
Definition: mg_matrix.h:295
virtual void vmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:251
virtual void vmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:262
std::size_t memory_consumption() const
Definition: mg_matrix.h:313
virtual void Tvmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:273
void initialize(const MGLevelObject< MatrixType > &M)
Definition: mg_matrix.h:205
void reset()
Definition: mg_matrix.h:224
virtual unsigned int get_maxlevel() const override
Definition: mg_matrix.h:304
MGLevelObject< LinearOperator< VectorType > > matrices
Definition: mg_matrix.h:109
virtual void Tvmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition: mg_matrix.h:284
Matrix()=default
const LinearOperator< VectorType > & operator[](unsigned int level) const
Definition: mg_matrix.h:242
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
unsigned int level
Definition: grid_out.cc:4617
static ::ExceptionBase & ExcNotInitialized()
#define Assert(cond, exc)
Definition: exceptions.h:1631
@ matrix
Contents is actually a matrix.
T & get_underlying_value(T &p)
Definition: utilities.h:1601
Definition: mg.h:82