Reference documentation for deal.II version Git 3f1f337db3 2021-10-23 13:19:02 -0600
\(\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 - 2020 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
61  initialize(const MGSmootherBase<VectorType> &coarse_smooth);
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 
104  MGCoarseGridIterativeSolver(SolverType & solver,
105  const MatrixType & matrix,
106  const PreconditionerType &precondition);
107 
112  void
113  initialize(SolverType & solver,
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:
136  SmartPointer<SolverType,
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:
181  MGCoarseGridHouseholder(const FullMatrix<number> *A = nullptr);
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->smooth(level, dst, src);
285 }
286 
287 /* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */
288 
289 template <class VectorType,
290  class SolverType,
291  class MatrixType,
292  class PreconditionerType>
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>
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
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  internal::MGCoarseGridIterativeSolver::solve(
429  *solver, *matrix, *preconditioner, dst, src);
430 }
431 
432 
433 
434 /* ------------------ Functions for MGCoarseGridHouseholder ------------ */
435 
436 template <typename number, class VectorType>
438  const FullMatrix<number> *A)
439 {
440  if (A != nullptr)
441  householder.initialize(*A);
442 }
443 
444 
445 
446 template <typename number, class VectorType>
447 void
449  const FullMatrix<number> &A)
450 {
451  householder.initialize(A);
452 }
453 
454 
455 
456 template <typename number, class VectorType>
457 void
459  const unsigned int /*level*/,
460  VectorType & dst,
461  const VectorType &src) const
462 {
463  householder.least_squares(dst, src);
464 }
465 
466 //---------------------------------------------------------------------------
467 
468 
469 
470 template <typename number, class VectorType>
471 void
473  double threshold)
474 {
475  matrix.reinit(A.n_rows(), A.n_cols());
476  matrix = A;
477  matrix.compute_inverse_svd(threshold);
478 }
479 
480 
481 template <typename number, class VectorType>
482 void
483 MGCoarseGridSVD<number, VectorType>::operator()(const unsigned int /*level*/,
484  VectorType & dst,
485  const VectorType &src) const
486 {
487  matrix.vmult(dst, src);
488 }
489 
490 
491 template <typename number, class VectorType>
492 void
494 {
495  const unsigned int n = std::min(matrix.n_rows(), matrix.n_cols());
496 
497  for (unsigned int i = 0; i < n; ++i)
498  deallog << ' ' << matrix.singular_value(i);
499  deallog << std::endl;
500 }
501 
502 
503 #endif // DOXYGEN
504 
506 
507 #endif
LogStream deallog
Definition: logstream.cc:37
void initialize(const FullMatrix< number > &A, const double threshold=0)
Contents is actually a matrix.
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
static ::ExceptionBase & ExcNotInitialized()
SmartPointer< SolverType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > solver
Definition: mg_coarse.h:141
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const
LAPACKFullMatrix< number > matrix
Definition: mg_coarse.h:237
SmartPointer< const MatrixType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > matrix
Definition: mg_coarse.h:151
#define Assert(cond, exc)
Definition: exceptions.h:1461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
unsigned int level
Definition: grid_out.cc:4589
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const =0
static const char A
void initialize(const MGSmootherBase< VectorType > &coarse_smooth)
MGCoarseGridHouseholder(const FullMatrix< number > *A=nullptr)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
Householder< number > householder
Definition: mg_coarse.h:198
SmartPointer< const PreconditionerType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > preconditioner
Definition: mg_coarse.h:161
SmartPointer< const MGSmootherBase< VectorType >, MGCoarseGridApplySmoother< VectorType > > coarse_smooth
Definition: mg_coarse.h:77
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
void initialize(const FullMatrix< number > &A)
void log() const