Reference documentation for deal.II version 9.1.0-pre
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
81  const MGConstrainedDoFs & mg_constrained_dofs);
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,
215  VectorMemory<Vector<number>> &memory);
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
264  copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
265  BlockVector<number2> & dst,
266  const MGLevelObject<BlockVector<number>> &src) const;
267 
273  template <int dim, typename number2, int spacedim>
274  void
275  copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
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
333  const MGConstrainedDoFs & mg_constrained_dofs);
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
382  copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof,
384  const Vector<number2> & src) const;
385 
392  template <int dim, typename number2, int spacedim>
393  void
394  copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
395  Vector<number2> & dst,
396  const MGLevelObject<Vector<number>> &src) const;
397 
403  template <int dim, typename number2, int spacedim>
404  void
405  copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
406  Vector<number2> & dst,
407  const MGLevelObject<Vector<number>> &src) const;
408 
416  template <int dim, typename number2, int spacedim>
417  void
418  copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof,
420  const BlockVector<number2> & src) const;
421 
428  template <int dim, typename number2, int spacedim>
429  void
430  copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
431  BlockVector<number2> & dst,
432  const MGLevelObject<Vector<number>> &src) const;
433 
439  template <int dim, typename number2, int spacedim>
440  void
441  copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
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
457  do_copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
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
467  do_copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
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
477  do_copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof,
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::vector< types::global_dof_index > block_start
SmartPointer< const MGConstrainedDoFs, MGTransferBlockBase > mg_constrained_dofs
std::vector< std::vector< types::global_dof_index > > sizes
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
#define DeclException0(Exception0)
Definition: exceptions.h:385
std::size_t memory_consumption() const
Definition: multigrid.cc:174
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()
std::vector< std::vector< types::global_dof_index > > mg_block_start
SmartPointer< VectorMemory< Vector< number > >, MGTransferBlock< number > > memory
std::vector< number > factors
std::vector< bool > selected