deal.II version GIT relicensing-2167-g9622207b8f 2024-11-21 12:40:00+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\}}\)
Loading...
Searching...
No Matches
mg_matrix.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2003 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_mg_matrix_h
16#define dealii_mg_matrix_h
17
18#include <deal.II/base/config.h>
19
21
24#include <deal.II/lac/vector.h>
25
27
28#include <memory>
29
31
37namespace mg
38{
44 template <typename VectorType = Vector<double>>
45 class Matrix : public MGMatrixBase<VectorType>
46 {
47 public:
51 Matrix() = default;
52
57 template <typename MatrixType>
59
64 template <typename MatrixType>
65 void
67
71 void
72 reset();
73
78 operator[](unsigned int level) const;
79
80 virtual void
81 vmult(const unsigned int level,
82 VectorType &dst,
83 const VectorType &src) const override;
84 virtual void
85 vmult_add(const unsigned int level,
86 VectorType &dst,
87 const VectorType &src) const override;
88 virtual void
89 Tvmult(const unsigned int level,
90 VectorType &dst,
91 const VectorType &src) const override;
92 virtual void
93 Tvmult_add(const unsigned int level,
94 VectorType &dst,
95 const VectorType &src) const override;
96 virtual unsigned int
97 get_minlevel() const override;
98 virtual unsigned int
99 get_maxlevel() const override;
100
104 std::size_t
105 memory_consumption() const;
106
107 private:
109 };
110
111} // namespace mg
112
113
122template <typename MatrixType, typename number>
123class MGMatrixSelect : public MGMatrixBase<Vector<number>>
124{
125public:
130 MGMatrixSelect(const unsigned int row = 0,
131 const unsigned int col = 0,
133
138 void
140
144 void
145 select_block(const unsigned int row, const unsigned int col);
146
150 virtual void
151 vmult(const unsigned int level,
152 Vector<number> &dst,
153 const Vector<number> &src) const;
154
158 virtual void
159 vmult_add(const unsigned int level,
160 Vector<number> &dst,
161 const Vector<number> &src) const;
162
166 virtual void
167 Tvmult(const unsigned int level,
168 Vector<number> &dst,
169 const Vector<number> &src) const;
170
174 virtual void
175 Tvmult_add(const unsigned int level,
176 Vector<number> &dst,
177 const Vector<number> &src) const;
178
179private:
188 unsigned int row;
192 unsigned int col;
193};
194
197/*----------------------------------------------------------------------*/
198
199namespace mg
200{
201 template <typename VectorType>
202 template <typename MatrixType>
203 inline void
205 {
206 matrices.resize(p.min_level(), p.max_level());
207 for (unsigned int level = p.min_level(); level <= p.max_level(); ++level)
208 {
209 // Workaround: Unfortunately, not every "p[level]" object has a
210 // rich enough interface to populate reinit_(domain|range)_vector.
211 // Thus, apply an empty LinearOperator exemplar.
212 matrices[level] =
213 linear_operator<VectorType>(LinearOperator<VectorType>(),
215 p[level]));
216 }
217 }
218
219
220
221 template <typename VectorType>
222 inline void
224 {
225 matrices.resize(0, 0);
226 }
227
228
229
230 template <typename VectorType>
231 template <typename MatrixType>
233 {
234 initialize(p);
235 }
236
237
238
239 template <typename VectorType>
240 inline const LinearOperator<VectorType> &
242 {
243 return matrices[level];
244 }
245
246
247
248 template <typename VectorType>
249 void
251 VectorType &dst,
252 const VectorType &src) const
253 {
254 matrices[level].vmult(dst, src);
255 }
256
257
258
259 template <typename VectorType>
260 void
262 VectorType &dst,
263 const VectorType &src) const
264 {
265 matrices[level].vmult_add(dst, src);
266 }
267
268
269
270 template <typename VectorType>
271 void
273 VectorType &dst,
274 const VectorType &src) const
275 {
276 matrices[level].Tvmult(dst, src);
277 }
278
279
280
281 template <typename VectorType>
282 void
284 VectorType &dst,
285 const VectorType &src) const
286 {
287 matrices[level].Tvmult_add(dst, src);
288 }
289
290
291
292 template <typename VectorType>
293 unsigned int
295 {
296 return matrices.min_level();
297 }
298
299
300
301 template <typename VectorType>
302 unsigned int
304 {
305 return matrices.max_level();
306 }
307
308
309
310 template <typename VectorType>
311 inline std::size_t
313 {
314 return sizeof(*this) + matrices->memory_consumption();
315 }
316} // namespace mg
317
318
319/*----------------------------------------------------------------------*/
320
321template <typename MatrixType, typename number>
323 const unsigned int col,
325 : matrix(p, typeid(*this).name())
326 , row(row)
327 , col(col)
328{}
329
330
331
332template <typename MatrixType, typename number>
333void
338
339
340
341template <typename MatrixType, typename number>
342void
344 const unsigned int bcol)
345{
346 row = brow;
347 col = bcol;
348}
349
350
351
352template <typename MatrixType, typename number>
353void
355 Vector<number> &dst,
356 const Vector<number> &src) const
357{
358 Assert(matrix != 0, ExcNotInitialized());
359
360 const MGLevelObject<MatrixType> &m = *matrix;
361 m[level].block(row, col).vmult(dst, src);
362}
363
364
365
366template <typename MatrixType, typename number>
367void
369 Vector<number> &dst,
370 const Vector<number> &src) const
371{
372 Assert(matrix != 0, ExcNotInitialized());
373
374 const MGLevelObject<MatrixType> &m = *matrix;
375 m[level].block(row, col).vmult_add(dst, src);
376}
377
378
379
380template <typename MatrixType, typename number>
381void
383 Vector<number> &dst,
384 const Vector<number> &src) const
385{
386 Assert(matrix != 0, ExcNotInitialized());
387
388 const MGLevelObject<MatrixType> &m = *matrix;
389 m[level].block(row, col).Tvmult(dst, src);
390}
391
392
393
394template <typename MatrixType, typename number>
395void
397 Vector<number> &dst,
398 const Vector<number> &src) const
399{
400 Assert(matrix != 0, ExcNotInitialized());
401
402 const MGLevelObject<MatrixType> &m = *matrix;
403 m[level].block(row, col).Tvmult_add(dst, src);
404}
405
407
408#endif
std::function< void(Range &v, const Domain &u)> vmult
unsigned int max_level() const
unsigned int min_level() const
void set_matrix(MGLevelObject< MatrixType > *M)
Definition mg_matrix.h:334
virtual void vmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition mg_matrix.h:354
virtual void vmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition mg_matrix.h:368
MGMatrixSelect(const unsigned int row=0, const unsigned int col=0, MGLevelObject< MatrixType > *matrix=0)
Definition mg_matrix.h:322
void select_block(const unsigned int row, const unsigned int col)
Definition mg_matrix.h:343
virtual void Tvmult(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition mg_matrix.h:382
unsigned int row
Definition mg_matrix.h:188
ObserverPointer< MGLevelObject< MatrixType >, MGMatrixSelect< MatrixType, number > > matrix
Definition mg_matrix.h:184
unsigned int col
Definition mg_matrix.h:192
virtual void Tvmult_add(const unsigned int level, Vector< number > &dst, const Vector< number > &src) const
Definition mg_matrix.h:396
virtual unsigned int get_minlevel() const override
Definition mg_matrix.h:294
virtual void vmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition mg_matrix.h:250
virtual void vmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition mg_matrix.h:261
std::size_t memory_consumption() const
Definition mg_matrix.h:312
virtual void Tvmult(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition mg_matrix.h:272
void initialize(const MGLevelObject< MatrixType > &M)
Definition mg_matrix.h:204
void reset()
Definition mg_matrix.h:223
virtual unsigned int get_maxlevel() const override
Definition mg_matrix.h:303
MGLevelObject< LinearOperator< VectorType > > matrices
Definition mg_matrix.h:108
virtual void Tvmult_add(const unsigned int level, VectorType &dst, const VectorType &src) const override
Definition mg_matrix.h:283
Matrix()=default
const LinearOperator< VectorType > & operator[](unsigned int level) const
Definition mg_matrix.h:241
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
unsigned int level
Definition grid_out.cc:4626
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotInitialized()
T & get_underlying_value(T &p)
Definition utilities.h:1639
Definition mg.h:81