deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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_block_smoother.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2005 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_mg_block_smoother_h
14#define dealii_mg_block_smoother_h
15
16
17#include <deal.II/base/config.h>
18
21
25
27
28#include <vector>
29
31
32/*
33 * MGSmootherBase is defined in mg_base.h
34 */
35
47template <typename MatrixType, typename RelaxationType, typename number>
48class MGSmootherBlock : public MGSmoother<BlockVector<number>>
49{
50public:
54 MGSmootherBlock(const unsigned int steps = 1,
55 const bool variable = false,
56 const bool symmetric = false,
57 const bool transpose = false,
58 const bool reverse = false);
59
73 template <typename MGMatrixType, typename MGRelaxationType>
74 void
75 initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers);
76
80 void
82
86 void
87 set_reverse(const bool);
88
94 virtual void
95 smooth(const unsigned int level,
97 const BlockVector<number> &rhs) const;
98
102 std::size_t
104
105private:
110
115
120
127};
128
131//---------------------------------------------------------------------------
132
133#ifndef DOXYGEN
134
135template <typename MatrixType, typename RelaxationType, typename number>
137 const unsigned int steps,
138 const bool variable,
139 const bool symmetric,
140 const bool transpose,
141 const bool reverse)
142 : MGSmoother<BlockVector<number>>(steps, variable, symmetric, transpose)
143 , reverse(reverse)
144 , mem(&this->vector_memory)
145{}
146
147
148template <typename MatrixType, typename RelaxationType, typename number>
149inline void
151{
152 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
153 for (; i <= max_level; ++i)
154 {
155 smoothers[i] = LinearOperator<BlockVector<number>>();
156 matrices[i] = LinearOperator<BlockVector<number>>();
157 }
158}
159
160
161template <typename MatrixType, typename RelaxationType, typename number>
162template <typename MGMatrixType, typename MGRelaxationType>
163inline void
165 const MGMatrixType &m,
166 const MGRelaxationType &s)
167{
168 const unsigned int min = m.min_level();
169 const unsigned int max = m.max_level();
170
171 matrices.resize(min, max);
172 smoothers.resize(min, max);
173
174 for (unsigned int i = min; i <= max; ++i)
175 {
176 // Workaround: Unfortunately, not every "m[i]" object has a
177 // rich enough interface to populate reinit_(domain|range)_vector.
178 // Thus, apply an empty LinearOperator exemplar.
179 matrices[i] = linear_operator<BlockVector<number>>(
181 smoothers[i] = linear_operator<BlockVector<number>>(matrices[i], s[i]);
182 }
183}
184
185
186template <typename MatrixType, typename RelaxationType, typename number>
187inline void
189 const bool flag)
190{
191 reverse = flag;
192}
193
194
195template <typename MatrixType, typename RelaxationType, typename number>
196inline std::size_t
198{
199 return sizeof(*this) + matrices.memory_consumption() +
200 smoothers.memory_consumption() +
201 this->vector_memory.memory_consumption();
202}
203
204
205template <typename MatrixType, typename RelaxationType, typename number>
206inline void
208 const unsigned int level,
210 const BlockVector<number> &rhs) const
211{
212 LogStream::Prefix prefix("Smooth");
213
214 unsigned int maxlevel = matrices.max_level();
215 unsigned int steps2 = this->steps;
216
217 if (this->variable)
218 steps2 *= (1 << (maxlevel - level));
219
220 typename VectorMemory<BlockVector<number>>::Pointer r(*this->mem);
221 typename VectorMemory<BlockVector<number>>::Pointer d(*this->mem);
222 r->reinit(u);
223 d->reinit(u);
224
225 bool T = this->transpose;
226 if (this->symmetric && (steps2 % 2 == 0))
227 T = false;
228
229 for (unsigned int i = 0; i < steps2; ++i)
230 {
231 if (T)
232 {
233 matrices[level].vmult(*r, u);
234 r->sadd(-1., 1., rhs);
235 smoothers[level].Tvmult(*d, *r);
236 }
237 else
238 {
239 matrices[level].vmult(*r, u);
240 r->sadd(-1., 1., rhs);
241 smoothers[level].vmult(*d, *r);
242 }
243 u += *d;
244 if (this->symmetric)
245 T = !T;
246 }
247}
248
249#endif // DOXYGEN
250
252
253#endif
virtual void smooth(const unsigned int level, BlockVector< number > &u, const BlockVector< number > &rhs) const
MGLevelObject< LinearOperator< BlockVector< number > > > smoothers
std::size_t memory_consumption() const
void initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers)
void set_reverse(const bool)
ObserverPointer< VectorMemory< BlockVector< number > >, MGSmootherBlock< MatrixType, RelaxationType, number > > mem
MGLevelObject< LinearOperator< BlockVector< number > > > matrices
MGSmootherBlock(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false, const bool reverse=false)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
unsigned int level
Definition grid_out.cc:4642
constexpr char T
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)