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_coarse.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2002 - 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_coarse_h
16#define dealii_mg_coarse_h
17
18
19#include <deal.II/base/config.h>
20
24
26
28
38template <typename VectorType = Vector<double>>
40{
41public:
46
51
55 void
57
61 void
63
67 void
68 operator()(const unsigned int level,
69 VectorType &dst,
70 const VectorType &src) const override;
71
72private:
79};
80
81
82
87template <class VectorType, class MatrixType>
89{
90public:
95
100
104 void
106
110 void
111 initialize(const MatrixType &matrix);
112
116 virtual void
117 operator()(const unsigned int level,
118 VectorType &dst,
119 const VectorType &src) const override;
120
121private:
125 ObserverPointer<const MatrixType,
128};
129
130
131
138template <typename VectorType,
139 typename SolverType,
140 typename MatrixType,
141 typename PreconditionerType>
143{
144public:
149
155 const MatrixType &matrix,
156 const PreconditionerType &precondition);
157
162 void
163 initialize(SolverType &solver,
164 const MatrixType &matrix,
165 const PreconditionerType &precondition);
166
170 void
172
177 virtual void
178 operator()(const unsigned int level,
179 VectorType &dst,
180 const VectorType &src) const override;
181
182private:
186 ObserverPointer<SolverType,
188 SolverType,
189 MatrixType,
190 PreconditionerType>>
192
196 ObserverPointer<const MatrixType,
198 SolverType,
199 MatrixType,
200 PreconditionerType>>
202
206 ObserverPointer<const PreconditionerType,
208 SolverType,
209 MatrixType,
210 PreconditionerType>>
212};
213
214
215
224template <typename number = double, typename VectorType = Vector<number>>
226{
227public:
232
236 void
238
239 void
240 operator()(const unsigned int level,
241 VectorType &dst,
242 const VectorType &src) const override;
243
244private:
249};
250
257template <typename number = double, typename VectorType = Vector<number>>
258class MGCoarseGridSVD : public MGCoarseGridBase<VectorType>
259{
260public:
264 MGCoarseGridSVD() = default;
265
269 void
270 initialize(const FullMatrix<number> &A, const double threshold = 0);
271
272 void
273 operator()(const unsigned int level,
274 VectorType &dst,
275 const VectorType &src) const;
276
280 void
281 log() const;
282
283private:
288};
289
292#ifndef DOXYGEN
293/* ------------------ Functions for MGCoarseGridApplySmoother -----------*/
294template <typename VectorType>
296 : coarse_smooth(nullptr)
297{}
298
299template <typename VectorType>
301 const MGSmootherBase<VectorType> &coarse_smooth)
302 : coarse_smooth(nullptr)
303{
304 initialize(coarse_smooth);
305}
306
307
308template <typename VectorType>
309void
311 const MGSmootherBase<VectorType> &coarse_smooth_)
312{
315 &coarse_smooth_, typeid(*this).name());
316}
317
318
319template <typename VectorType>
320void
322{
323 coarse_smooth = nullptr;
324}
325
326
327template <typename VectorType>
328void
330 VectorType &dst,
331 const VectorType &src) const
332{
333 coarse_smooth->apply(level, dst, src);
334}
335
336/* ------------------ Functions for MGCoarseGridApplyOperator ----------*/
337
338template <class VectorType, class PreconditionerType>
340 PreconditionerType>::MGCoarseGridApplyOperator()
341 : matrix(0, typeid(*this).name())
342{}
343
344
345
346template <class VectorType, class PreconditionerType>
348 MGCoarseGridApplyOperator(const PreconditionerType &matrix)
349 : matrix(&matrix, typeid(*this).name())
350{}
351
352
353
354template <class VectorType, class PreconditionerType>
355void
357 const PreconditionerType &matrix_)
358{
359 matrix = &matrix_;
360}
361
362
363
364template <class VectorType, class PreconditionerType>
365void
367{
368 matrix = 0;
369}
370
371
372template <class VectorType, class PreconditionerType>
373void
375 const unsigned int /*level*/,
376 VectorType &dst,
377 const VectorType &src) const
378{
379 Assert(matrix != nullptr, ExcNotInitialized());
380
381 matrix->vmult(dst, src);
382}
383
384/* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */
385
386template <typename VectorType,
387 typename SolverType,
388 typename MatrixType,
389 typename PreconditionerType>
391 SolverType,
393 PreconditionerType>::MGCoarseGridIterativeSolver()
394 : solver(0, typeid(*this).name())
395 , matrix(0, typeid(*this).name())
396 , preconditioner(0, typeid(*this).name())
397{}
398
399
400
401template <typename VectorType,
402 typename SolverType,
403 typename MatrixType,
404 typename PreconditionerType>
406 SolverType,
408 PreconditionerType>::
409 MGCoarseGridIterativeSolver(SolverType &solver,
410 const MatrixType &matrix,
411 const PreconditionerType &preconditioner)
412 : solver(&solver, typeid(*this).name())
413 , matrix(&matrix, typeid(*this).name())
414 , preconditioner(&preconditioner, typeid(*this).name())
415{}
416
417
418
419template <typename VectorType,
420 typename SolverType,
421 typename MatrixType,
422 typename PreconditionerType>
423void
426 SolverType,
428 PreconditionerType>::initialize(SolverType &solver_,
429 const MatrixType &matrix_,
430 const PreconditionerType &preconditioner_)
431{
432 solver = &solver_;
433 matrix = &matrix_;
434 preconditioner = &preconditioner_;
435}
436
437
438
439template <typename VectorType,
440 typename SolverType,
441 typename MatrixType,
442 typename PreconditionerType>
443void
445 SolverType,
447 PreconditionerType>::clear()
448{
449 solver = 0;
450 matrix = 0;
451 preconditioner = 0;
452}
453
454
455
456template <typename VectorType,
457 typename SolverType,
458 typename MatrixType,
459 typename PreconditionerType>
460void
463 SolverType,
465 PreconditionerType>::operator()(const unsigned int /*level*/,
466 VectorType &dst,
467 const VectorType &src) const
468{
469 Assert(solver != nullptr, ExcNotInitialized());
470 Assert(matrix != nullptr, ExcNotInitialized());
471 Assert(preconditioner != nullptr, ExcNotInitialized());
472
473 dst = 0;
474
475 if constexpr (std::is_same_v<VectorType, typename SolverType::vector_type>)
476 {
477 solver->solve(*matrix, dst, src, *preconditioner);
478 }
479 else
480 {
481 typename SolverType::vector_type src_;
482 typename SolverType::vector_type dst_;
483
484 src_ = src;
485 dst_ = dst;
486
487 solver->solve(*matrix, dst_, src_, *preconditioner);
488
489 dst = dst_;
490 }
491}
492
493
494
495/* ------------------ Functions for MGCoarseGridHouseholder ------------ */
496
497template <typename number, typename VectorType>
499 const FullMatrix<number> *A)
500{
501 if (A != nullptr)
502 householder.initialize(*A);
503}
504
505
506
507template <typename number, typename VectorType>
508void
510 const FullMatrix<number> &A)
511{
512 householder.initialize(A);
513}
514
515
516
517template <typename number, typename VectorType>
518void
520 const unsigned int /*level*/,
521 VectorType &dst,
522 const VectorType &src) const
523{
524 householder.least_squares(dst, src);
525}
526
527//---------------------------------------------------------------------------
528
529
530
531template <typename number, typename VectorType>
532void
534 double threshold)
535{
536 matrix.reinit(A.n_rows(), A.n_cols());
537 matrix = A;
538 matrix.compute_inverse_svd(threshold);
539}
540
541
542template <typename number, typename VectorType>
543void
544MGCoarseGridSVD<number, VectorType>::operator()(const unsigned int /*level*/,
545 VectorType &dst,
546 const VectorType &src) const
547{
548 matrix.vmult(dst, src);
549}
550
551
552template <typename number, typename VectorType>
553void
555{
556 const unsigned int n = std::min(matrix.n_rows(), matrix.n_cols());
557
558 for (unsigned int i = 0; i < n; ++i)
559 deallog << ' ' << matrix.singular_value(i);
560 deallog << std::endl;
561}
562
563
564#endif // DOXYGEN
565
567
568#endif
void initialize(const MatrixType &matrix)
virtual void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
ObserverPointer< const MatrixType, MGCoarseGridApplyOperator< VectorType, MatrixType > > matrix
Definition mg_coarse.h:127
MGCoarseGridApplyOperator(const MatrixType &matrix)
void initialize(const MGSmootherBase< VectorType > &coarse_smooth)
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
MGCoarseGridApplySmoother(const MGSmootherBase< VectorType > &coarse_smooth)
ObserverPointer< const MGSmootherBase< VectorType >, MGCoarseGridApplySmoother< VectorType > > coarse_smooth
Definition mg_coarse.h:78
void initialize(const FullMatrix< number > &A)
Householder< number > householder
Definition mg_coarse.h:248
MGCoarseGridHouseholder(const FullMatrix< number > *A=nullptr)
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const override
ObserverPointer< const MatrixType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > matrix
Definition mg_coarse.h:201
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)
ObserverPointer< SolverType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > solver
Definition mg_coarse.h:191
ObserverPointer< const PreconditionerType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > preconditioner
Definition mg_coarse.h:211
void log() const
MGCoarseGridSVD()=default
LAPACKFullMatrix< number > matrix
Definition mg_coarse.h:287
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: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()
LogStream deallog
Definition logstream.cc:36
@ matrix
Contents is actually a matrix.
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
Tpetra::CrsMatrix< Number, LO, GO, NodeType< MemorySpace > > MatrixType
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)