deal.II version GIT relicensing-1927-g3de9220933 2024-10-03 08: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
89template <typename VectorType,
90 typename SolverType,
91 typename MatrixType,
92 typename PreconditionerType>
94{
95public:
100
106 const MatrixType &matrix,
107 const PreconditionerType &precondition);
108
113 void
114 initialize(SolverType &solver,
115 const MatrixType &matrix,
116 const PreconditionerType &precondition);
117
121 void
123
128 virtual void
129 operator()(const unsigned int level,
130 VectorType &dst,
131 const VectorType &src) const override;
132
133private:
137 ObserverPointer<SolverType,
139 SolverType,
140 MatrixType,
141 PreconditionerType>>
143
147 ObserverPointer<const MatrixType,
149 SolverType,
150 MatrixType,
151 PreconditionerType>>
153
157 ObserverPointer<const PreconditionerType,
159 SolverType,
160 MatrixType,
161 PreconditionerType>>
163};
164
165
166
175template <typename number = double, typename VectorType = Vector<number>>
177{
178public:
183
187 void
189
190 void
191 operator()(const unsigned int level,
192 VectorType &dst,
193 const VectorType &src) const override;
194
195private:
200};
201
208template <typename number = double, typename VectorType = Vector<number>>
209class MGCoarseGridSVD : public MGCoarseGridBase<VectorType>
210{
211public:
215 MGCoarseGridSVD() = default;
216
220 void
221 initialize(const FullMatrix<number> &A, const double threshold = 0);
222
223 void
224 operator()(const unsigned int level,
225 VectorType &dst,
226 const VectorType &src) const;
227
231 void
232 log() const;
233
234private:
239};
240
243#ifndef DOXYGEN
244/* ------------------ Functions for MGCoarseGridApplySmoother -----------*/
245template <typename VectorType>
247 : coarse_smooth(nullptr)
248{}
249
250template <typename VectorType>
252 const MGSmootherBase<VectorType> &coarse_smooth)
253 : coarse_smooth(nullptr)
254{
255 initialize(coarse_smooth);
256}
257
258
259template <typename VectorType>
260void
262 const MGSmootherBase<VectorType> &coarse_smooth_)
263{
266 &coarse_smooth_, typeid(*this).name());
267}
268
269
270template <typename VectorType>
271void
273{
274 coarse_smooth = nullptr;
275}
276
277
278template <typename VectorType>
279void
281 VectorType &dst,
282 const VectorType &src) const
283{
284 coarse_smooth->apply(level, dst, src);
285}
286
287/* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */
288
289template <typename VectorType,
290 typename SolverType,
291 typename MatrixType,
292 typename PreconditionerType>
294 SolverType,
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
304template <typename VectorType,
305 typename SolverType,
306 typename MatrixType,
307 typename PreconditionerType>
309 SolverType,
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
322template <typename VectorType,
323 typename SolverType,
324 typename MatrixType,
325 typename PreconditionerType>
326void
329 SolverType,
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
342template <typename VectorType,
343 typename SolverType,
344 typename MatrixType,
345 typename PreconditionerType>
346void
348 SolverType,
350 PreconditionerType>::clear()
351{
352 solver = 0;
353 matrix = 0;
354 preconditioner = 0;
355}
356
357
358
359namespace internal
360{
362 {
363 template <typename VectorType,
364 typename SolverType,
365 typename MatrixType,
366 typename PreconditionerType,
367 std::enable_if_t<
368 std::is_same_v<VectorType, typename SolverType::vector_type>,
369 VectorType> * = nullptr>
370 void
371 solve(SolverType &solver,
372 const MatrixType &matrix,
373 const PreconditionerType &preconditioner,
374 VectorType &dst,
375 const VectorType &src)
376 {
377 solver.solve(matrix, dst, src, preconditioner);
378 }
379
380 template <typename VectorType,
381 typename SolverType,
382 typename MatrixType,
383 typename PreconditionerType,
384 std::enable_if_t<
385 !std::is_same_v<VectorType, typename SolverType::vector_type>,
386 VectorType> * = nullptr>
387 void
388 solve(SolverType &solver,
389 const MatrixType &matrix,
390 const PreconditionerType &preconditioner,
391 VectorType &dst,
392 const VectorType &src)
393 {
394 typename SolverType::vector_type src_;
395 typename SolverType::vector_type dst_;
396
397 src_ = src;
398 dst_ = dst;
399
400 solver.solve(matrix, dst_, src_, preconditioner);
401
402 dst = dst_;
403 }
404 } // namespace MGCoarseGridIterativeSolver
405} // namespace internal
406
407
408
409template <typename VectorType,
410 typename SolverType,
411 typename MatrixType,
412 typename PreconditionerType>
413void
416 SolverType,
418 PreconditionerType>::operator()(const unsigned int /*level*/,
419 VectorType &dst,
420 const VectorType &src) const
421{
422 Assert(solver != nullptr, ExcNotInitialized());
423 Assert(matrix != nullptr, ExcNotInitialized());
424 Assert(preconditioner != nullptr, ExcNotInitialized());
425
426 dst = 0;
427 internal::MGCoarseGridIterativeSolver::solve(
428 *solver, *matrix, *preconditioner, dst, src);
429}
430
431
432
433/* ------------------ Functions for MGCoarseGridHouseholder ------------ */
434
435template <typename number, typename VectorType>
437 const FullMatrix<number> *A)
438{
439 if (A != nullptr)
440 householder.initialize(*A);
441}
442
443
444
445template <typename number, typename VectorType>
446void
448 const FullMatrix<number> &A)
449{
450 householder.initialize(A);
451}
452
453
454
455template <typename number, typename VectorType>
456void
458 const unsigned int /*level*/,
459 VectorType &dst,
460 const VectorType &src) const
461{
462 householder.least_squares(dst, src);
463}
464
465//---------------------------------------------------------------------------
466
467
468
469template <typename number, typename VectorType>
470void
472 double threshold)
473{
474 matrix.reinit(A.n_rows(), A.n_cols());
475 matrix = A;
476 matrix.compute_inverse_svd(threshold);
477}
478
479
480template <typename number, typename VectorType>
481void
482MGCoarseGridSVD<number, VectorType>::operator()(const unsigned int /*level*/,
483 VectorType &dst,
484 const VectorType &src) const
485{
486 matrix.vmult(dst, src);
487}
488
489
490template <typename number, typename VectorType>
491void
493{
494 const unsigned int n = std::min(matrix.n_rows(), matrix.n_cols());
495
496 for (unsigned int i = 0; i < n; ++i)
497 deallog << ' ' << matrix.singular_value(i);
498 deallog << std::endl;
499}
500
501
502#endif // DOXYGEN
503
505
506#endif
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:199
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:152
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:142
ObserverPointer< const PreconditionerType, MGCoarseGridIterativeSolver< VectorType, SolverType, MatrixType, PreconditionerType > > preconditioner
Definition mg_coarse.h:162
void log() const
MGCoarseGridSVD()=default
LAPACKFullMatrix< number > matrix
Definition mg_coarse.h:238
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 > &)