Reference documentation for deal.II version 9.2.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\}}\)
mg_block_smoother.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 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_block_smoother_h
17 #define dealii_mg_block_smoother_h
18 
19 
20 #include <deal.II/base/config.h>
21 
24 
28 
30 
31 #include <vector>
32 
34 
35 /*
36  * MGSmootherBase is defined in mg_base.h
37  */
38 
41 
50 template <typename MatrixType, class RelaxationType, typename number>
51 class MGSmootherBlock : public MGSmoother<BlockVector<number>>
52 {
53 public:
57  MGSmootherBlock(const unsigned int steps = 1,
58  const bool variable = false,
59  const bool symmetric = false,
60  const bool transpose = false,
61  const bool reverse = false);
62 
76  template <class MGMatrixType, class MGRelaxationType>
77  void
78  initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers);
79 
83  void
84  clear();
85 
89  void
90  set_reverse(const bool);
91 
97  virtual void
98  smooth(const unsigned int level,
100  const BlockVector<number> &rhs) const;
101 
105  std::size_t
106  memory_consumption() const;
107 
108 private:
113 
118 
122  bool reverse;
123 
130 };
131 
134 //---------------------------------------------------------------------------
135 
136 #ifndef DOXYGEN
137 
138 template <typename MatrixType, class RelaxationType, typename number>
140  const unsigned int steps,
141  const bool variable,
142  const bool symmetric,
143  const bool transpose,
144  const bool reverse)
145  : MGSmoother<BlockVector<number>>(steps, variable, symmetric, transpose)
146  , reverse(reverse)
147  , mem(&this->vector_memory)
148 {}
149 
150 
151 template <typename MatrixType, class RelaxationType, typename number>
152 inline void
154 {
155  unsigned int i = matrices.min_level(), max_level = matrices.max_level();
156  for (; i <= max_level; ++i)
157  {
158  smoothers[i] = LinearOperator<BlockVector<number>>();
159  matrices[i] = LinearOperator<BlockVector<number>>();
160  }
161 }
162 
163 
164 template <typename MatrixType, class RelaxationType, typename number>
165 template <class MGMatrixType, class MGRelaxationType>
166 inline void
168  const MGMatrixType & m,
169  const MGRelaxationType &s)
170 {
171  const unsigned int min = m.min_level();
172  const unsigned int max = m.max_level();
173 
174  matrices.resize(min, max);
175  smoothers.resize(min, max);
176 
177  for (unsigned int i = min; i <= max; ++i)
178  {
179  // Workaround: Unfortunately, not every "m[i]" object has a
180  // rich enough interface to populate reinit_(domain|range)_vector.
181  // Thus, apply an empty LinearOperator exemplar.
182  matrices[i] = linear_operator<BlockVector<number>>(
184  smoothers[i] = linear_operator<BlockVector<number>>(matrices[i], s[i]);
185  }
186 }
187 
188 
189 template <typename MatrixType, class RelaxationType, typename number>
190 inline void
192  const bool flag)
193 {
194  reverse = flag;
195 }
196 
197 
198 template <typename MatrixType, class RelaxationType, typename number>
199 inline std::size_t
201 {
202  return sizeof(*this) + matrices.memory_consumption() +
203  smoothers.memory_consumption() +
204  this->vector_memory.memory_consumption();
205 }
206 
207 
208 template <typename MatrixType, class RelaxationType, typename number>
209 inline void
211  const unsigned int level,
213  const BlockVector<number> &rhs) const
214 {
215  LogStream::Prefix prefix("Smooth");
216 
217  unsigned int maxlevel = matrices.max_level();
218  unsigned int steps2 = this->steps;
219 
220  if (this->variable)
221  steps2 *= (1 << (maxlevel - level));
222 
223  typename VectorMemory<BlockVector<number>>::Pointer r(*this->mem);
224  typename VectorMemory<BlockVector<number>>::Pointer d(*this->mem);
225  r->reinit(u);
226  d->reinit(u);
227 
228  bool T = this->transpose;
229  if (this->symmetric && (steps2 % 2 == 0))
230  T = false;
231 
232  for (unsigned int i = 0; i < steps2; ++i)
233  {
234  if (T)
235  {
236  matrices[level].vmult(*r, u);
237  r->sadd(-1., 1., rhs);
238  smoothers[level].Tvmult(*d, *r);
239  }
240  else
241  {
242  matrices[level].vmult(*r, u);
243  r->sadd(-1., 1., rhs);
244  smoothers[level].vmult(*d, *r);
245  }
246  u += *d;
247  if (this->symmetric)
248  T = !T;
249  }
250 }
251 
252 #endif // DOXYGEN
253 
255 
256 #endif
LogStream::Prefix
Definition: logstream.h:103
MGSmoother
Definition: mg_smoother.h:50
mg_smoother.h
MGSmootherBlock::clear
void clear()
BlockVector< number >
VectorizedArray::max
VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
Definition: vectorization.h:5466
VectorizedArray::min
VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
Definition: vectorization.h:5483
linear_operator.h
MGSmoother< BlockVector< number > >::symmetric
bool symmetric
Definition: mg_smoother.h:118
MGSmootherBlock::mem
SmartPointer< VectorMemory< BlockVector< number > >, MGSmootherBlock< MatrixType, RelaxationType, number > > mem
Definition: mg_block_smoother.h:129
Physics::Elasticity::Kinematics::d
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
level
unsigned int level
Definition: grid_out.cc:4355
MGSmootherBlock
Definition: mg_block_smoother.h:51
LAPACKSupport::T
static const char T
Definition: lapack_support.h:163
LAPACKSupport::symmetric
@ symmetric
Matrix is symmetric.
Definition: lapack_support.h:115
block_vector.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
smartpointer.h
mg_level_object.h
MGSmoother< BlockVector< number > >::transpose
bool transpose
Definition: mg_smoother.h:124
MGSmootherBlock::memory_consumption
std::size_t memory_consumption() const
MGSmootherBlock::smooth
virtual void smooth(const unsigned int level, BlockVector< number > &u, const BlockVector< number > &rhs) const
SmartPointer
Definition: smartpointer.h:68
MGSmootherBlock::smoothers
MGLevelObject< LinearOperator< BlockVector< number > > > smoothers
Definition: mg_block_smoother.h:117
MGSmoother< BlockVector< number > >::variable
bool variable
Definition: mg_smoother.h:112
MGSmootherBlock::MGSmootherBlock
MGSmootherBlock(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false, const bool reverse=false)
MGLevelObject
Definition: mg_level_object.h:50
MGSmootherBlock::set_reverse
void set_reverse(const bool)
vector_memory.h
MGSmootherBlock::initialize
void initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers)
config.h
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
MGSmootherBlock::matrices
MGLevelObject< LinearOperator< BlockVector< number > > > matrices
Definition: mg_block_smoother.h:112
MGSmootherBlock::reverse
bool reverse
Definition: mg_block_smoother.h:122
LinearOperator
Definition: linear_operator.h:169
DerivativeForm::transpose
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Definition: derivative_form.h:470
VectorMemory
Definition: vector_memory.h:107
MGSmoother< BlockVector< number > >::steps
unsigned int steps
Definition: mg_smoother.h:106