Reference documentation for deal.II version GIT fac6d58a2d 2022-05-23 17:55:02+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_coarse.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 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_coarse_h
17 #define dealii_mg_coarse_h
18 
19 
20 #include <deal.II/base/config.h>
21 
25 
27 
29 
32 
37 template <class VectorType = Vector<double>>
38 class MGCoarseGridApplySmoother : public MGCoarseGridBase<VectorType>
39 {
40 public:
45 
50 
54  void
55  clear();
56 
60  void
62 
66  void
67  operator()(const unsigned int level,
68  VectorType & dst,
69  const VectorType & src) const override;
70 
71 private:
78 };
79 
80 
81 
88 template <class VectorType,
89  class SolverType,
90  class MatrixType,
91  class PreconditionerType>
93 {
94 public:
99 
105  const MatrixType & matrix,
106  const PreconditionerType &precondition);
107 
112  void
114  const MatrixType & matrix,
115  const PreconditionerType &precondition);
116 
120  void
121  clear();
122 
127  virtual void
128  operator()(const unsigned int level,
129  VectorType & dst,
130  const VectorType & src) const override;
131 
132 private:
137  MGCoarseGridIterativeSolver<VectorType,
138  SolverType,
139  MatrixType,
140  PreconditionerType>>
142 
146  SmartPointer<const MatrixType,
147  MGCoarseGridIterativeSolver<VectorType,
148  SolverType,
149  MatrixType,
150  PreconditionerType>>
152 
156  SmartPointer<const PreconditionerType,
157  MGCoarseGridIterativeSolver<VectorType,
158  SolverType,
159  MatrixType,
160  PreconditionerType>>
162 };
163 
164 
165 
174 template <typename number = double, class VectorType = Vector<number>>
175 class MGCoarseGridHouseholder : public MGCoarseGridBase<VectorType>
176 {
177 public:
182 
186  void
188 
189  void
190  operator()(const unsigned int level,
191  VectorType & dst,
192  const VectorType & src) const override;
193 
194 private:
199 };
200 
207 template <typename number = double, class VectorType = Vector<number>>
208 class MGCoarseGridSVD : public MGCoarseGridBase<VectorType>
209 {
210 public:
214  MGCoarseGridSVD() = default;
215 
219  void
220  initialize(const FullMatrix<number> &A, const double threshold = 0);
221 
222  void
223  operator()(const unsigned int level,
224  VectorType & dst,
225  const VectorType & src) const;
226 
230  void
231  log() const;
232 
233 private:
238 };
239 
242 #ifndef DOXYGEN
243 /* ------------------ Functions for MGCoarseGridApplySmoother -----------*/
244 template <class VectorType>
246  : coarse_smooth(nullptr)
247 {}
248 
249 template <class VectorType>
251  const MGSmootherBase<VectorType> &coarse_smooth)
252  : coarse_smooth(nullptr)
253 {
254  initialize(coarse_smooth);
255 }
256 
257 
258 template <class VectorType>
259 void
261  const MGSmootherBase<VectorType> &coarse_smooth_)
262 {
263  coarse_smooth =
265  MGCoarseGridApplySmoother<VectorType>>(&coarse_smooth_,
266  typeid(*this).name());
267 }
268 
269 
270 template <class VectorType>
271 void
273 {
274  coarse_smooth = nullptr;
275 }
276 
277 
278 template <class VectorType>
279 void
281  VectorType & dst,
282  const VectorType & src) const
283 {
284  coarse_smooth->apply(level, dst, src);
285 }
286 
287 /* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */
288 
289 template <class VectorType,
290  class SolverType,
291  class MatrixType,
292  class PreconditionerType>
293 MGCoarseGridIterativeSolver<VectorType,
294  SolverType,
295  MatrixType,
296  PreconditionerType>::MGCoarseGridIterativeSolver()
297  : solver(0, typeid(*this).name())
298  , matrix(0, typeid(*this).name())
299  , preconditioner(0, typeid(*this).name())
300 {}
301 
302 
303 
304 template <class VectorType,
305  class SolverType,
306  class MatrixType,
307  class PreconditionerType>
308 MGCoarseGridIterativeSolver<VectorType,
309  SolverType,
310  MatrixType,
311  PreconditionerType>::
312  MGCoarseGridIterativeSolver(SolverType & solver,
313  const MatrixType & matrix,
314  const PreconditionerType &preconditioner)
315  : solver(&solver, typeid(*this).name())
316  , matrix(&matrix, typeid(*this).name())
317  , preconditioner(&preconditioner, typeid(*this).name())
318 {}
319 
320 
321 
322 template <class VectorType,
323  class SolverType,
324  class MatrixType,
325  class PreconditionerType>
326 void
328  VectorType,
329  SolverType,
330  MatrixType,
331  PreconditionerType>::initialize(SolverType & solver_,
332  const MatrixType & matrix_,
333  const PreconditionerType &preconditioner_)
334 {
335  solver = &solver_;
336  matrix = &matrix_;
337  preconditioner = &preconditioner_;
338 }
339 
340 
341 
342 template <class VectorType,
343  class SolverType,
344  class MatrixType,
345  class PreconditionerType>
346 void
347 MGCoarseGridIterativeSolver<VectorType,
348  SolverType,
349  MatrixType,
350  PreconditionerType>::clear()
351 {
352  solver = 0;
353  matrix = 0;
354  preconditioner = 0;
355 }
356 
357 
358 
359 namespace internal
360 {
362  {
363  template <
364  class VectorType,
365  class SolverType,
366  class MatrixType,
367  class PreconditionerType,
368  typename std::enable_if<
369  std::is_same<VectorType, typename SolverType::vector_type>::value,
370  VectorType>::type * = nullptr>
371  void
372  solve(SolverType & solver,
373  const MatrixType & matrix,
374  const PreconditionerType &preconditioner,
375  VectorType & dst,
376  const VectorType & src)
377  {
378  solver.solve(matrix, dst, src, preconditioner);
379  }
380 
381  template <
382  class VectorType,
383  class SolverType,
384  class MatrixType,
385  class PreconditionerType,
386  typename std::enable_if<
387  !std::is_same<VectorType, typename SolverType::vector_type>::value,
388  VectorType>::type * = nullptr>
389  void
390  solve(SolverType & solver,
391  const MatrixType & matrix,
392  const PreconditionerType &preconditioner,
393  VectorType & dst,
394  const VectorType & src)
395  {
396  typename SolverType::vector_type src_;
397  typename SolverType::vector_type dst_;
398 
399  src_ = src;
400  dst_ = dst;
401 
402  solver.solve(matrix, dst_, src_, preconditioner);
403 
404  dst = dst_;
405  }
406  } // namespace MGCoarseGridIterativeSolver
407 } // namespace internal
408 
409 
410 
411 template <class VectorType,
412  class SolverType,
413  class MatrixType,
414  class PreconditionerType>
415 void
417  VectorType,
418  SolverType,
419  MatrixType,
420  PreconditionerType>::operator()(const unsigned int /*level*/,
421  VectorType & dst,
422  const VectorType &src) const
423 {
424  Assert(solver != nullptr, ExcNotInitialized());
425  Assert(matrix != nullptr, ExcNotInitialized());
426  Assert(preconditioner != nullptr, ExcNotInitialized());
427 
428  dst = 0;
429  internal::MGCoarseGridIterativeSolver::solve(
430  *solver, *matrix, *preconditioner, dst, src);
431 }
432 
433 
434 
435 /* ------------------ Functions for MGCoarseGridHouseholder ------------ */
436 
437 template <typename number, class VectorType>
439  const FullMatrix<number> *A)
440 {
441  if (A != nullptr)
442  householder.initialize(*A);
443 }
444 
445 
446 
447 template <typename number, class VectorType>
448 void
450  const FullMatrix<number> &A)
451 {
452  householder.initialize(A);
453 }
454 
455 
456 
457 template <typename number, class VectorType>
458 void
460  const unsigned int /*level*/,
461  VectorType & dst,
462  const VectorType &src) const
463 {
464  householder.least_squares(dst, src);
465 }
466 
467 //---------------------------------------------------------------------------
468 
469 
470 
471 template <typename number, class VectorType>
472 void
474  double threshold)
475 {
476  matrix.reinit(A.n_rows(), A.n_cols());
477  matrix = A;
478  matrix.compute_inverse_svd(threshold);
479 }
480 
481 
482 template <typename number, class VectorType>
483 void
484 MGCoarseGridSVD<number, VectorType>::operator()(const unsigned int /*level*/,
485  VectorType & dst,
486  const VectorType &src) const
487 {
488  matrix.vmult(dst, src);
489 }
490 
491 
492 template <typename number, class VectorType>
493 void
495 {
496  const unsigned int n = std::min(matrix.n_rows(), matrix.n_cols());
497 
498  for (unsigned int i = 0; i < n; ++i)
499  deallog << ' ' << matrix.singular_value(i);
500  deallog << std::endl;
501 }
502 
503 
504 #endif // DOXYGEN
505 
507 
508 #endif
void initialize(const MGSmootherBase< VectorType > &coarse_smooth)
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
SmartPointer< const MGSmootherBase< VectorType >, MGCoarseGridApplySmoother< VectorType > > coarse_smooth
Definition: mg_coarse.h:77
MGCoarseGridApplySmoother(const MGSmootherBase< VectorType > &coarse_smooth)
void initialize(const FullMatrix< number > &A)
Householder< number > householder
Definition: mg_coarse.h:198
MGCoarseGridHouseholder(const FullMatrix< number > *A=nullptr)
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
SmartPointer< const MatrixType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > matrix
Definition: mg_coarse.h:151
SmartPointer< SolverType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > solver
Definition: mg_coarse.h:141
SmartPointer< const PreconditionerType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > preconditioner
Definition: mg_coarse.h:161
void initialize(SolverType &solver, const MatrixType &matrix, const PreconditionerType &precondition)
virtual void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
MGCoarseGridIterativeSolver(SolverType &solver, const MatrixType &matrix, const PreconditionerType &precondition)
void log() const
MGCoarseGridSVD()=default
LAPACKFullMatrix< number > matrix
Definition: mg_coarse.h:237
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const
void initialize(const FullMatrix< number > &A, const double threshold=0)
#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
LogStream deallog
Definition: logstream.cc:37
@ matrix
Contents is actually a matrix.
static const char A