Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
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/lac/block_vector.h>
22 #include <deal.II/lac/sparsity_pattern.h>
23 #include <deal.II/lac/block_sparsity_pattern.h>
24 #include <deal.II/lac/vector_memory.h>
25 #include <deal.II/lac/block_matrix_array.h>
26 
27 #include <deal.II/multigrid/mg_base.h>
28 #include <deal.II/multigrid/mg_constrained_dofs.h>
29 #include <deal.II/base/mg_level_object.h>
30 
31 
32 
33 #include <deal.II/dofs/dof_handler.h>
34 
35 #include <memory>
36 
37 
38 DEAL_II_NAMESPACE_OPEN
39 
40 
41 template <int dim, int spacedim> class DoFHandler;
42 
43 /*
44  * MGTransferBase is defined in mg_base.h
45  */
46 
49 
61 {
62 public:
68 
73 
79  DEAL_II_DEPRECATED
80  MGTransferBlockBase (const ConstraintMatrix &constraints,
82 
86  std::size_t memory_consumption () const;
87 
88 protected:
96  template <int dim, int spacedim>
98  const DoFHandler<dim,spacedim> &mg_dof);
99 
106 //TODO: rename this to block_mask, in the same way as has already been done in MGTransferComponent, and give it type BlockMask
107  std::vector<bool> selected;
108 
112  unsigned int n_mg_blocks;
113 
120 //TODO: rename this to mg_block_mask, in the same way as has already been done in MGTransferComponent, and give it type BlockMask
121  std::vector<unsigned int> mg_block;
122 
126  mutable std::vector<std::vector<types::global_dof_index> > sizes;
127 
131  std::vector<types::global_dof_index> block_start;
132 
136  std::vector<std::vector<types::global_dof_index> > mg_block_start;
137 
142 
143 private:
144  std::vector<std::shared_ptr<BlockSparsityPattern> > prolongation_sparsities;
145 
146 protected:
147 
153  std::vector<std::shared_ptr<BlockSparseMatrix<double> > > prolongation_matrices;
154 
161  std::vector<std::vector<std::vector<std::pair<unsigned int, unsigned int> > > >
163 
169 };
170 
190 template <typename number>
191 class MGTransferBlock : public MGTransferBase<BlockVector<number> >,
192  private MGTransferBlockBase
193 {
194 public:
198  MGTransferBlock();
199 
203  virtual ~MGTransferBlock ();
204 
209  void initialize (const std::vector<number> &factors,
211 
218  template <int dim, int spacedim>
219  void build_matrices (const DoFHandler<dim,spacedim> &dof,
220  const DoFHandler<dim,spacedim> &mg_dof,
221  const std::vector<bool> &selected);
222 
223  virtual void prolongate (const unsigned int to_level,
224  BlockVector<number> &dst,
225  const BlockVector<number> &src) const;
226 
227  virtual void restrict_and_add (const unsigned int from_level,
228  BlockVector<number> &dst,
229  const BlockVector<number> &src) const;
230 
242  template <int dim, typename number2, int spacedim>
243  void
244  copy_to_mg (const DoFHandler<dim,spacedim> &mg_dof,
246  const BlockVector<number2> &src) const;
247 
254  template <int dim, typename number2, int spacedim>
255  void
256  copy_from_mg (const DoFHandler<dim,spacedim> &mg_dof,
258  const MGLevelObject<BlockVector<number> > &src) const;
259 
265  template <int dim, typename number2, int spacedim>
266  void
269  const MGLevelObject<BlockVector<number> > &src) const;
270 
272 
273 private:
278  std::vector<number> factors;
279 
285 };
286 
287 
288 //TODO:[GK] Update documentation for copy_* functions
289 
302 template <typename number>
303 class MGTransferBlockSelect : public MGTransferBase<Vector<number> >,
304  private MGTransferBlockBase
305 {
306 public:
312 
317 
323  DEAL_II_DEPRECATED
324  MGTransferBlockSelect (const ConstraintMatrix &constraints,
326 
330  virtual ~MGTransferBlockSelect () = default;
331 
344  template <int dim, int spacedim>
345  void build_matrices (const DoFHandler<dim,spacedim> &dof,
346  const DoFHandler<dim,spacedim> &mg_dof,
347  unsigned int selected);
348 
352  void select (const unsigned int block);
353 
354  virtual void prolongate (const unsigned int to_level,
355  Vector<number> &dst,
356  const Vector<number> &src) const;
357 
358  virtual void restrict_and_add (const unsigned int from_level,
359  Vector<number> &dst,
360  const Vector<number> &src) const;
361 
368  template <int dim, typename number2, int spacedim>
369  void
370  copy_to_mg (const DoFHandler<dim,spacedim> &mg_dof,
372  const Vector<number2> &src) const;
373 
380  template <int dim, typename number2, int spacedim>
381  void
382  copy_from_mg (const DoFHandler<dim,spacedim> &mg_dof,
383  Vector<number2> &dst,
384  const MGLevelObject<Vector<number> > &src) const;
385 
391  template <int dim, typename number2, int spacedim>
392  void
394  Vector<number2> &dst,
395  const MGLevelObject<Vector<number> > &src) const;
396 
404  template <int dim, typename number2, int spacedim>
405  void
406  copy_to_mg (const DoFHandler<dim,spacedim> &mg_dof,
408  const BlockVector<number2> &src) const;
409 
416  template <int dim, typename number2, int spacedim>
417  void
418  copy_from_mg (const DoFHandler<dim,spacedim> &mg_dof,
420  const MGLevelObject<Vector<number> > &src) const;
421 
427  template <int dim, typename number2, int spacedim>
428  void
431  const MGLevelObject<Vector<number> > &src) const;
432 
436  std::size_t memory_consumption () const;
437 
438 private:
442  template <int dim, class OutVector, int spacedim>
443  void
445  OutVector &dst,
446  const MGLevelObject<Vector<number> > &src,
447  const unsigned int offset) const;
448 
452  template <int dim, class OutVector, int spacedim>
453  void
455  OutVector &dst,
456  const MGLevelObject<Vector<number> > &src,
457  const unsigned int offset) const;
458 
462  template <int dim, class InVector, int spacedim>
463  void
466  const InVector &src,
467  const unsigned int offset) const;
471  unsigned int selected_block;
472 };
473 
476 //----------inline function definition--------------------------------------------------
477 template <typename number>
478 inline void
479 MGTransferBlockSelect<number>::select(const unsigned int block)
480 {
481  selected_block = block;
482 }
483 
484 DEAL_II_NAMESPACE_CLOSE
485 
486 #endif
void build_matrices(const DoFHandler< dim, spacedim > &dof, const DoFHandler< dim, spacedim > &mg_dof)
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, Vector< number2 > &dst, const MGLevelObject< Vector< number > > &src) const
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, BlockVector< number2 > &dst, const MGLevelObject< BlockVector< number > > &src) const
std::size_t memory_consumption() const
Definition: multigrid.cc:176
virtual void prolongate(const unsigned int to_level, BlockVector< number > &dst, const BlockVector< number > &src) const
Definition: multigrid.cc:86
virtual ~MGTransferBlockSelect()=default
void copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, Vector< number2 > &dst, const MGLevelObject< Vector< number > > &src) const
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< types::global_dof_index > block_start
SmartPointer< const MGConstrainedDoFs, MGTransferBlockBase > mg_constrained_dofs
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< Vector< number > > &dst, const Vector< number2 > &src) const
void do_copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< Vector< number > > &src, const unsigned int offset) const
void do_copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< Vector< number > > &dst, const InVector &src, const unsigned int offset) const
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< BlockVector< number > > &dst, const BlockVector< number2 > &src) const
std::vector< std::vector< types::global_dof_index > > sizes
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
virtual void restrict_and_add(const unsigned int from_level, BlockVector< number > &dst, const BlockVector< number > &src) const
Definition: multigrid.cc:111
#define DeclException0(Exception0)
Definition: exceptions.h:323
virtual ~MGTransferBlock()
Definition: multigrid.cc:69
void initialize(const std::vector< number > &factors, VectorMemory< Vector< number > > &memory)
Definition: multigrid.cc:77
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()
virtual void prolongate(const unsigned int to_level, Vector< number > &dst, const Vector< number > &src) const
Definition: multigrid.cc:281
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
SmartPointer< VectorMemory< Vector< number > >, MGTransferBlock< number > > memory
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)
std::vector< number > factors
virtual void restrict_and_add(const unsigned int from_level, Vector< number > &dst, const Vector< number > &src) const
Definition: multigrid.cc:296
std::vector< bool > selected
void copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, BlockVector< number2 > &dst, const MGLevelObject< BlockVector< number > > &src) const