Reference documentation for deal.II version Git 840703ecf3 2019-10-14 17:15:20 -0400
\(\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 // Forward declaration
41 #ifndef DOXYGEN
42 template <int dim, int spacedim>
43 class DoFHandler;
44 #endif
45 
46 /*
47  * MGTransferBase is defined in mg_base.h
48  */
49 
52 
64 {
65 public:
71 
76 
82  DEAL_II_DEPRECATED
84  const MGConstrainedDoFs & mg_constrained_dofs);
85 
89  std::size_t
90  memory_consumption() const;
91 
92 protected:
100  template <int dim, int spacedim>
101  void
103  const DoFHandler<dim, spacedim> &mg_dof);
104 
111  // TODO: rename this to block_mask, in the same way as has already been done
112  // in MGTransferComponent, and give it type BlockMask
113  std::vector<bool> selected;
114 
118  unsigned int n_mg_blocks;
119 
126  // TODO: rename this to mg_block_mask, in the same way as has already been
127  // done in MGTransferComponent, and give it type BlockMask
128  std::vector<unsigned int> mg_block;
129 
133  mutable std::vector<std::vector<types::global_dof_index>> sizes;
134 
138  std::vector<types::global_dof_index> block_start;
139 
143  std::vector<std::vector<types::global_dof_index>> mg_block_start;
144 
149 
150 private:
151  std::vector<std::shared_ptr<BlockSparsityPattern>> prolongation_sparsities;
152 
153 protected:
159  std::vector<std::shared_ptr<BlockSparseMatrix<double>>> prolongation_matrices;
160 
167  std::vector<std::vector<std::vector<std::pair<unsigned int, unsigned int>>>>
169 
176 };
177 
197 template <typename number>
198 class MGTransferBlock : public MGTransferBase<BlockVector<number>>,
199  private MGTransferBlockBase
200 {
201 public:
205  MGTransferBlock();
206 
210  virtual ~MGTransferBlock() override;
211 
216  void
217  initialize(const std::vector<number> & factors,
218  VectorMemory<Vector<number>> &memory);
219 
226  template <int dim, int spacedim>
227  void
229  const DoFHandler<dim, spacedim> &mg_dof,
230  const std::vector<bool> & selected);
231 
232  virtual void
233  prolongate(const unsigned int to_level,
234  BlockVector<number> & dst,
235  const BlockVector<number> &src) const override;
236 
237  virtual void
238  restrict_and_add(const unsigned int from_level,
239  BlockVector<number> & dst,
240  const BlockVector<number> &src) const override;
241 
253  template <int dim, typename number2, int spacedim>
254  void
255  copy_to_mg(const DoFHandler<dim, spacedim> & mg_dof,
257  const BlockVector<number2> & src) const;
258 
265  template <int dim, typename number2, int spacedim>
266  void
267  copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
268  BlockVector<number2> & dst,
269  const MGLevelObject<BlockVector<number>> &src) const;
270 
276  template <int dim, typename number2, int spacedim>
277  void
278  copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
279  BlockVector<number2> & dst,
280  const MGLevelObject<BlockVector<number>> &src) const;
281 
283 
284 private:
289  std::vector<number> factors;
290 
296 };
297 
298 
299 // TODO:[GK] Update documentation for copy_* functions
300 
313 template <typename number>
314 class MGTransferBlockSelect : public MGTransferBase<Vector<number>>,
315  private MGTransferBlockBase
316 {
317 public:
323 
328 
334  DEAL_II_DEPRECATED
336  const MGConstrainedDoFs & mg_constrained_dofs);
337 
341  virtual ~MGTransferBlockSelect() override = default;
342 
355  template <int dim, int spacedim>
356  void
358  const DoFHandler<dim, spacedim> &mg_dof,
359  unsigned int selected);
360 
364  void
365  select(const unsigned int block);
366 
367  virtual void
368  prolongate(const unsigned int to_level,
369  Vector<number> & dst,
370  const Vector<number> &src) const override;
371 
372  virtual void
373  restrict_and_add(const unsigned int from_level,
374  Vector<number> & dst,
375  const Vector<number> &src) const override;
376 
383  template <int dim, typename number2, int spacedim>
384  void
385  copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof,
387  const Vector<number2> & src) const;
388 
395  template <int dim, typename number2, int spacedim>
396  void
397  copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
398  Vector<number2> & dst,
399  const MGLevelObject<Vector<number>> &src) const;
400 
406  template <int dim, typename number2, int spacedim>
407  void
408  copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
409  Vector<number2> & dst,
410  const MGLevelObject<Vector<number>> &src) const;
411 
419  template <int dim, typename number2, int spacedim>
420  void
421  copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof,
423  const BlockVector<number2> & src) const;
424 
431  template <int dim, typename number2, int spacedim>
432  void
433  copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
434  BlockVector<number2> & dst,
435  const MGLevelObject<Vector<number>> &src) const;
436 
442  template <int dim, typename number2, int spacedim>
443  void
444  copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
445  BlockVector<number2> & dst,
446  const MGLevelObject<Vector<number>> &src) const;
447 
451  std::size_t
452  memory_consumption() const;
453 
454 private:
458  template <int dim, class OutVector, int spacedim>
459  void
460  do_copy_from_mg(const DoFHandler<dim, spacedim> & mg_dof,
461  OutVector & dst,
462  const MGLevelObject<Vector<number>> &src,
463  const unsigned int offset) const;
464 
468  template <int dim, class OutVector, int spacedim>
469  void
470  do_copy_from_mg_add(const DoFHandler<dim, spacedim> & mg_dof,
471  OutVector & dst,
472  const MGLevelObject<Vector<number>> &src,
473  const unsigned int offset) const;
474 
478  template <int dim, class InVector, int spacedim>
479  void
480  do_copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof,
482  const InVector & src,
483  const unsigned int offset) const;
487  unsigned int selected_block;
488 };
489 
492 //------------------------- inline function definition ------------------------
493 template <typename number>
494 inline void
495 MGTransferBlockSelect<number>::select(const unsigned int block)
496 {
497  selected_block = block;
498 }
499 
500 DEAL_II_NAMESPACE_CLOSE
501 
502 #endif
void build_matrices(const DoFHandler< dim, spacedim > &dof, const DoFHandler< dim, spacedim > &mg_dof)
std::size_t memory_consumption() const
Definition: multigrid.cc:182
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:473
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