Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
mg_transfer_block.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2018 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_transfer_block_h
17 #define dealii_mg_transfer_block_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/mg_level_object.h>
22 
23 #include <deal.II/dofs/dof_handler.h>
24 
25 #include <deal.II/lac/block_matrix_array.h>
26 #include <deal.II/lac/block_sparsity_pattern.h>
27 #include <deal.II/lac/block_vector.h>
28 #include <deal.II/lac/sparsity_pattern.h>
29 #include <deal.II/lac/vector_memory.h>
30 
31 #include <deal.II/multigrid/mg_base.h>
32 #include <deal.II/multigrid/mg_constrained_dofs.h>
33 
34 #include <memory>
35 
36 
37 DEAL_II_NAMESPACE_OPEN
38 
39 
40 template <int dim, int spacedim>
41 class DoFHandler;
42 
43 /*
44  * MGTransferBase is defined in mg_base.h
45  */
46 
49 
61 {
62 public:
68 
73 
79  DEAL_II_DEPRECATED
82 
86  std::size_t
87  memory_consumption() const;
88 
89 protected:
97  template <int dim, int spacedim>
98  void
100  const DoFHandler<dim, spacedim> &mg_dof);
101 
108  // TODO: rename this to block_mask, in the same way as has already been done
109  // in MGTransferComponent, and give it type BlockMask
110  std::vector<bool> selected;
111 
115  unsigned int n_mg_blocks;
116 
123  // TODO: rename this to mg_block_mask, in the same way as has already been
124  // done in MGTransferComponent, and give it type BlockMask
125  std::vector<unsigned int> mg_block;
126 
130  mutable std::vector<std::vector<types::global_dof_index>> sizes;
131 
135  std::vector<types::global_dof_index> block_start;
136 
140  std::vector<std::vector<types::global_dof_index>> mg_block_start;
141 
146 
147 private:
148  std::vector<std::shared_ptr<BlockSparsityPattern>> prolongation_sparsities;
149 
150 protected:
156  std::vector<std::shared_ptr<BlockSparseMatrix<double>>> prolongation_matrices;
157 
164  std::vector<std::vector<std::vector<std::pair<unsigned int, unsigned int>>>>
166 
173 };
174 
194 template <typename number>
195 class MGTransferBlock : public MGTransferBase<BlockVector<number>>,
196  private MGTransferBlockBase
197 {
198 public:
202  MGTransferBlock();
203 
207  virtual ~MGTransferBlock() override;
208 
213  void
214  initialize(const std::vector<number> & factors,
216 
223  template <int dim, int spacedim>
224  void
226  const DoFHandler<dim, spacedim> &mg_dof,
227  const std::vector<bool> & selected);
228 
229  virtual void
230  prolongate(const unsigned int to_level,
231  BlockVector<number> & dst,
232  const BlockVector<number> &src) const override;
233 
234  virtual void
235  restrict_and_add(const unsigned int from_level,
236  BlockVector<number> & dst,
237  const BlockVector<number> &src) const override;
238 
250  template <int dim, typename number2, int spacedim>
251  void
252  copy_to_mg(const DoFHandler<dim, spacedim> & mg_dof,
254  const BlockVector<number2> & src) const;
255 
262  template <int dim, typename number2, int spacedim>
263  void
265  BlockVector<number2> & dst,
266  const MGLevelObject<BlockVector<number>> &src) const;
267 
273  template <int dim, typename number2, int spacedim>
274  void
276  BlockVector<number2> & dst,
277  const MGLevelObject<BlockVector<number>> &src) const;
278 
280 
281 private:
286  std::vector<number> factors;
287 
293 };
294 
295 
296 // TODO:[GK] Update documentation for copy_* functions
297 
310 template <typename number>
311 class MGTransferBlockSelect : public MGTransferBase<Vector<number>>,
312  private MGTransferBlockBase
313 {
314 public:
320 
325 
331  DEAL_II_DEPRECATED
334 
338  virtual ~MGTransferBlockSelect() override = default;
339 
352  template <int dim, int spacedim>
353  void
355  const DoFHandler<dim, spacedim> &mg_dof,
356  unsigned int selected);
357 
361  void
362  select(const unsigned int block);
363 
364  virtual void
365  prolongate(const unsigned int to_level,
366  Vector<number> & dst,
367  const Vector<number> &src) const override;
368 
369  virtual void
370  restrict_and_add(const unsigned int from_level,
371  Vector<number> & dst,
372  const Vector<number> &src) const override;
373 
380  template <int dim, typename number2, int spacedim>
381  void
384  const Vector<number2> & src) const;
385 
392  template <int dim, typename number2, int spacedim>
393  void
395  Vector<number2> & dst,
396  const MGLevelObject<Vector<number>> &src) const;
397 
403  template <int dim, typename number2, int spacedim>
404  void
406  Vector<number2> & dst,
407  const MGLevelObject<Vector<number>> &src) const;
408 
416  template <int dim, typename number2, int spacedim>
417  void
420  const BlockVector<number2> & src) const;
421 
428  template <int dim, typename number2, int spacedim>
429  void
431  BlockVector<number2> & dst,
432  const MGLevelObject<Vector<number>> &src) const;
433 
439  template <int dim, typename number2, int spacedim>
440  void
442  BlockVector<number2> & dst,
443  const MGLevelObject<Vector<number>> &src) const;
444 
448  std::size_t
449  memory_consumption() const;
450 
451 private:
455  template <int dim, class OutVector, int spacedim>
456  void
458  OutVector & dst,
459  const MGLevelObject<Vector<number>> &src,
460  const unsigned int offset) const;
461 
465  template <int dim, class OutVector, int spacedim>
466  void
468  OutVector & dst,
469  const MGLevelObject<Vector<number>> &src,
470  const unsigned int offset) const;
471 
475  template <int dim, class InVector, int spacedim>
476  void
479  const InVector & src,
480  const unsigned int offset) const;
484  unsigned int selected_block;
485 };
486 
489 //------------------------- inline function definition ------------------------
490 template <typename number>
491 inline void
492 MGTransferBlockSelect<number>::select(const unsigned int block)
493 {
494  selected_block = block;
495 }
496 
497 DEAL_II_NAMESPACE_CLOSE
498 
499 #endif
void build_matrices(const DoFHandler< dim, spacedim > &dof, const DoFHandler< dim, spacedim > &mg_dof)
std::size_t memory_consumption() const
Definition: multigrid.cc:174
virtual ~MGTransferBlock() override
Definition: multigrid.cc:67
virtual void prolongate(const unsigned int to_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:276
std::vector< types::global_dof_index > block_start
void do_copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< Vector< number >> &src, const unsigned int offset) const
SmartPointer< const MGConstrainedDoFs, MGTransferBlockBase > mg_constrained_dofs
virtual ~MGTransferBlockSelect() override=default
void do_copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< Vector< number >> &src, const unsigned int offset) const
std::vector< std::vector< types::global_dof_index > > sizes
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, Vector< number2 > &dst, const MGLevelObject< Vector< number >> &src) const
#define DeclException0(Exception0)
Definition: exceptions.h:473
virtual void restrict_and_add(const unsigned int from_level, BlockVector< number > &dst, const BlockVector< number > &src) const override
Definition: multigrid.cc:111
virtual void restrict_and_add(const unsigned int from_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:291
void copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, BlockVector< number2 > &dst, const MGLevelObject< BlockVector< number >> &src) const
void select(const unsigned int block)
std::vector< std::vector< std::vector< std::pair< unsigned int, unsigned int > > > > copy_indices
std::vector< unsigned int > mg_block
static ::ExceptionBase & ExcMatricesNotBuilt()
void do_copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< Vector< number >> &dst, const InVector &src, const unsigned int offset) const
void build_matrices(const DoFHandler< dim, spacedim > &dof, const DoFHandler< dim, spacedim > &mg_dof, unsigned int selected)
std::vector< std::vector< types::global_dof_index > > mg_block_start
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, BlockVector< number2 > &dst, const MGLevelObject< BlockVector< number >> &src) const
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< Vector< number >> &dst, const Vector< number2 > &src) const
std::size_t memory_consumption() const
void build_matrices(const DoFHandler< dim, spacedim > &dof, const DoFHandler< dim, spacedim > &mg_dof, const std::vector< bool > &selected)
SmartPointer< VectorMemory< Vector< number > >, MGTransferBlock< number > > memory
std::vector< number > factors
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< BlockVector< number >> &dst, const BlockVector< number2 > &src) const
virtual void prolongate(const unsigned int to_level, BlockVector< number > &dst, const BlockVector< number > &src) const override
Definition: multigrid.cc:86
void initialize(const std::vector< number > &factors, VectorMemory< Vector< number >> &memory)
Definition: multigrid.cc:76
std::vector< bool > selected
void copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, Vector< number2 > &dst, const MGLevelObject< Vector< number >> &src) const