Reference documentation for deal.II version 8.5.1
mg_block_smoother.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2016 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/smartpointer.h>
22 #include <deal.II/lac/pointer_matrix.h>
23 #include <deal.II/lac/vector_memory.h>
24 #include <deal.II/lac/block_vector.h>
25 #include <deal.II/multigrid/mg_smoother.h>
26 #include <deal.II/base/mg_level_object.h>
27 #include <vector>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 /*
32  * MGSmootherBase is defined in mg_base.h
33  */
34 
37 
46 template <typename MatrixType, class RelaxationType, typename number>
48  : public MGSmoother<BlockVector<number> >
49 {
50 public:
58  const unsigned int steps = 1,
59  const bool variable = false,
60  const bool symmetric = false,
61  const bool transpose = false,
62  const bool reverse = false) DEAL_II_DEPRECATED;
63 
67  MGSmootherBlock (const unsigned int steps = 1,
68  const bool variable = false,
69  const bool symmetric = false,
70  const bool transpose = false,
71  const bool reverse = false);
72 
86  template <class MGMatrixType, class MGRelaxationType>
87  void initialize (const MGMatrixType &matrices,
88  const MGRelaxationType &smoothers);
89 
93  void clear ();
94 
98  void set_reverse (const bool);
99 
105  virtual void smooth (const unsigned int level,
107  const BlockVector<number> &rhs) const;
108 
112  std::size_t memory_consumption () const;
113 private:
118 
123 
127  bool reverse;
128 
133 };
134 
137 //---------------------------------------------------------------------------
138 
139 #ifndef DOXYGEN
140 
141 template <typename MatrixType, class RelaxationType, typename number>
142 inline
145  const unsigned int steps,
146  const bool variable,
147  const bool symmetric,
148  const bool transpose,
149  const bool reverse)
150  : MGSmoother<BlockVector<number> >(steps, variable, symmetric, transpose),
151  reverse(reverse),
152  mem(&mem)
153 {}
154 
155 template <typename MatrixType, class RelaxationType, typename number>
156 inline
158 (const unsigned int steps,
159  const bool variable,
160  const bool symmetric,
161  const bool transpose,
162  const bool reverse)
163  : MGSmoother<BlockVector<number> >(steps, variable, symmetric, transpose),
164  reverse(reverse),
165  mem(&this->vector_memory)
166 {}
167 
168 
169 template <typename MatrixType, class RelaxationType, typename number>
170 inline void
172 {
173  unsigned int i=matrices.min_level(),
174  max_level=matrices.max_level();
175  for (; i<=max_level; ++i)
176  {
177  smoothers[i] = 0;
178  matrices[i] = 0;
179  }
180 }
181 
182 
183 template <typename MatrixType, class RelaxationType, typename number>
184 template <class MGMatrixType, class MGRelaxationType>
185 inline void
187  const MGRelaxationType &s)
188 {
189  const unsigned int min = m.min_level();
190  const unsigned int max = m.max_level();
191 
192  matrices.resize(min, max);
193  smoothers.resize(min, max);
194 
195  for (unsigned int i=min; i<=max; ++i)
196  {
197  matrices[i] = &m[i];
198  smoothers[i] = &s[i];
199  }
200 }
201 
202 
203 template <typename MatrixType, class RelaxationType, typename number>
204 inline void
206 set_reverse (const bool flag)
207 {
208  reverse = flag;
209 }
210 
211 
212 template <typename MatrixType, class RelaxationType, typename number>
213 inline std::size_t
215 memory_consumption () const
216 {
217  return sizeof(*this)
218  + matrices.memory_consumption()
219  + smoothers.memory_consumption()
220  + this->vector_memory.memory_consumption();
221 }
222 
223 
224 template <typename MatrixType, class RelaxationType, typename number>
225 inline void
228  const BlockVector<number> &rhs) const
229 {
230  deallog.push("Smooth");
231 
232  unsigned int maxlevel = matrices.max_level();
233  unsigned int steps2 = this->steps;
234 
235  if (this->variable)
236  steps2 *= (1<<(maxlevel-level));
237 
238  typename VectorMemory<BlockVector<number> >::Pointer r(*this->mem);
239  typename VectorMemory<BlockVector<number> >::Pointer d(*this->mem);
240  r->reinit(u);
241  d->reinit(u);
242 
243  bool T = this->transpose;
244  if (this->symmetric && (steps2 % 2 == 0))
245  T = false;
246 
247  for (unsigned int i=0; i<steps2; ++i)
248  {
249  if (T)
250  {
251  matrices[level].vmult(*r,u);
252  r->sadd(-1.,1.,rhs);
253  smoothers[level].Tvmult(*d, *r);
254  }
255  else
256  {
257  matrices[level].vmult(*r,u);
258  r->sadd(-1.,1.,rhs);
259  smoothers[level].vmult(*d, *r);
260  }
261  u += *d;
262  if (this->symmetric)
263  T = !T;
264  }
265 
266  deallog.pop();
267 }
268 
269 #endif // DOXYGEN
270 
271 DEAL_II_NAMESPACE_CLOSE
272 
273 #endif
MGSmootherBlock(VectorMemory< BlockVector< number > > &mem, const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false, const bool reverse=false) 1
void pop()
Definition: logstream.cc:306
MGLevelObject< PointerMatrix< MatrixType, BlockVector< number > > > matrices
void initialize(const MGMatrixType &matrices, const MGRelaxationType &smoothers)
void set_reverse(const bool)
virtual void smooth(const unsigned int level, BlockVector< number > &u, const BlockVector< number > &rhs) const
VectorizedArray< Number > min(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
SmartPointer< VectorMemory< BlockVector< number > >, MGSmootherBlock< MatrixType, RelaxationType, number > > mem
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void push(const std::string &text)
Definition: logstream.cc:294
std::size_t memory_consumption() const
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
MGLevelObject< PointerMatrix< RelaxationType, BlockVector< number > > > smoothers
VectorizedArray< Number > max(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)