Reference documentation for deal.II version 9.6.0
\(\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: LGPL-2.1-or-later
4// Copyright (C) 2005 - 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_block_smoother_h
16#define dealii_mg_block_smoother_h
17
18
19#include <deal.II/base/config.h>
20
23
27
29
30#include <vector>
31
33
34/*
35 * MGSmootherBase is defined in mg_base.h
36 */
37
49template <typename MatrixType, typename RelaxationType, typename number>
50class MGSmootherBlock : public MGSmoother<BlockVector<number>>
51{
52public:
56 MGSmootherBlock(const unsigned int steps = 1,
57 const bool variable = false,
58 const bool symmetric = false,
59 const bool transpose = false,
60 const bool reverse = false);
61
75 template <typename MGMatrixType, typename MGRelaxationType>
76 void
77 initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers);
78
82 void
84
88 void
89 set_reverse(const bool);
90
96 virtual void
97 smooth(const unsigned int level,
99 const BlockVector<number> &rhs) const;
100
104 std::size_t
106
107private:
112
117
122
129};
130
133//---------------------------------------------------------------------------
134
135#ifndef DOXYGEN
136
137template <typename MatrixType, typename RelaxationType, typename number>
139 const unsigned int steps,
140 const bool variable,
141 const bool symmetric,
142 const bool transpose,
143 const bool reverse)
144 : MGSmoother<BlockVector<number>>(steps, variable, symmetric, transpose)
145 , reverse(reverse)
146 , mem(&this->vector_memory)
147{}
148
149
150template <typename MatrixType, typename RelaxationType, typename number>
151inline void
153{
154 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
155 for (; i <= max_level; ++i)
156 {
157 smoothers[i] = LinearOperator<BlockVector<number>>();
158 matrices[i] = LinearOperator<BlockVector<number>>();
159 }
160}
161
162
163template <typename MatrixType, typename RelaxationType, typename number>
164template <typename MGMatrixType, typename MGRelaxationType>
165inline void
167 const MGMatrixType &m,
168 const MGRelaxationType &s)
169{
170 const unsigned int min = m.min_level();
171 const unsigned int max = m.max_level();
172
173 matrices.resize(min, max);
174 smoothers.resize(min, max);
175
176 for (unsigned int i = min; i <= max; ++i)
177 {
178 // Workaround: Unfortunately, not every "m[i]" object has a
179 // rich enough interface to populate reinit_(domain|range)_vector.
180 // Thus, apply an empty LinearOperator exemplar.
183 smoothers[i] = linear_operator<BlockVector<number>>(matrices[i], s[i]);
184 }
185}
186
187
188template <typename MatrixType, typename RelaxationType, typename number>
189inline void
191 const bool flag)
192{
193 reverse = flag;
194}
195
196
197template <typename MatrixType, typename RelaxationType, typename number>
198inline std::size_t
200{
201 return sizeof(*this) + matrices.memory_consumption() +
202 smoothers.memory_consumption() +
203 this->vector_memory.memory_consumption();
204}
205
206
207template <typename MatrixType, typename RelaxationType, typename number>
208inline void
210 const unsigned int level,
212 const BlockVector<number> &rhs) const
213{
214 LogStream::Prefix prefix("Smooth");
215
216 unsigned int maxlevel = matrices.max_level();
217 unsigned int steps2 = this->steps;
218
219 if (this->variable)
220 steps2 *= (1 << (maxlevel - level));
221
222 typename VectorMemory<BlockVector<number>>::Pointer r(*this->mem);
223 typename VectorMemory<BlockVector<number>>::Pointer d(*this->mem);
224 r->reinit(u);
225 d->reinit(u);
226
227 bool T = this->transpose;
228 if (this->symmetric && (steps2 % 2 == 0))
229 T = false;
230
231 for (unsigned int i = 0; i < steps2; ++i)
232 {
233 if (T)
234 {
235 matrices[level].vmult(*r, u);
236 r->sadd(-1., 1., rhs);
237 smoothers[level].Tvmult(*d, *r);
238 }
239 else
240 {
241 matrices[level].vmult(*r, u);
242 r->sadd(-1., 1., rhs);
243 smoothers[level].vmult(*d, *r);
244 }
245 u += *d;
246 if (this->symmetric)
247 T = !T;
248 }
249}
250
251#endif // DOXYGEN
252
254
255#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
SmartPointer< VectorMemory< BlockVector< number > >, MGSmootherBlock< MatrixType, RelaxationType, number > > mem
void initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers)
void set_reverse(const bool)
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:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
unsigned int level
Definition grid_out.cc:4626
LinearOperator< Range, Domain, Payload > linear_operator(const OperatorExemplar &, const Matrix &)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)