Reference documentation for deal.II version Git 3ff8e288d2 2020-02-20 17:30:00 +0100
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
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
102  build(const DoFHandler<dim, spacedim> &dof_handler);
103 
113  template <int dim, int spacedim>
114  DEAL_II_DEPRECATED void
116  const DoFHandler<dim, spacedim> &mg_dof);
117 
124  // TODO: rename this to block_mask, in the same way as has already been done
125  // in MGTransferComponent, and give it type BlockMask
126  std::vector<bool> selected;
127 
131  unsigned int n_mg_blocks;
132 
139  // TODO: rename this to mg_block_mask, in the same way as has already been
140  // done in MGTransferComponent, and give it type BlockMask
141  std::vector<unsigned int> mg_block;
142 
146  mutable std::vector<std::vector<types::global_dof_index>> sizes;
147 
151  std::vector<types::global_dof_index> block_start;
152 
156  std::vector<std::vector<types::global_dof_index>> mg_block_start;
157 
162 
163 private:
164  std::vector<std::shared_ptr<BlockSparsityPattern>> prolongation_sparsities;
165 
166 protected:
172  std::vector<std::shared_ptr<BlockSparseMatrix<double>>> prolongation_matrices;
173 
180  std::vector<std::vector<std::vector<std::pair<unsigned int, unsigned int>>>>
182 
189 };
190 
210 template <typename number>
211 class MGTransferBlock : public MGTransferBase<BlockVector<number>>,
212  private MGTransferBlockBase
213 {
214 public:
218  MGTransferBlock();
219 
223  virtual ~MGTransferBlock() override;
224 
229  void
230  initialize(const std::vector<number> & factors,
231  VectorMemory<Vector<number>> &memory);
232 
239  template <int dim, int spacedim>
240  void
241  build(const DoFHandler<dim, spacedim> &dof_handler,
242  const std::vector<bool> & selected);
243 
252  template <int dim, int spacedim>
253  DEAL_II_DEPRECATED void
255  const DoFHandler<dim, spacedim> &mg_dof,
256  const std::vector<bool> & selected);
257 
258  virtual void
259  prolongate(const unsigned int to_level,
260  BlockVector<number> & dst,
261  const BlockVector<number> &src) const override;
262 
263  virtual void
264  restrict_and_add(const unsigned int from_level,
265  BlockVector<number> & dst,
266  const BlockVector<number> &src) const override;
267 
279  template <int dim, typename number2, int spacedim>
280  void
281  copy_to_mg(const DoFHandler<dim, spacedim> & dof_handler,
283  const BlockVector<number2> & src) const;
284 
291  template <int dim, typename number2, int spacedim>
292  void
293  copy_from_mg(const DoFHandler<dim, spacedim> & dof_handler,
294  BlockVector<number2> & dst,
295  const MGLevelObject<BlockVector<number>> &src) const;
296 
302  template <int dim, typename number2, int spacedim>
303  void
304  copy_from_mg_add(const DoFHandler<dim, spacedim> & dof_handler,
305  BlockVector<number2> & dst,
306  const MGLevelObject<BlockVector<number>> &src) const;
307 
309 
310 private:
315  std::vector<number> factors;
316 
322 };
323 
324 
325 // TODO:[GK] Update documentation for copy_* functions
326 
339 template <typename number>
340 class MGTransferBlockSelect : public MGTransferBase<Vector<number>>,
341  private MGTransferBlockBase
342 {
343 public:
349 
354 
360  DEAL_II_DEPRECATED
362  const MGConstrainedDoFs & mg_constrained_dofs);
363 
367  virtual ~MGTransferBlockSelect() override = default;
368 
379  template <int dim, int spacedim>
380  void
381  build(const DoFHandler<dim, spacedim> &dof_handler, unsigned int selected);
382 
394  template <int dim, int spacedim>
395  DEAL_II_DEPRECATED void
397  const DoFHandler<dim, spacedim> &mg_dof,
398  unsigned int selected);
399 
403  void
404  select(const unsigned int block);
405 
406  virtual void
407  prolongate(const unsigned int to_level,
408  Vector<number> & dst,
409  const Vector<number> &src) const override;
410 
411  virtual void
412  restrict_and_add(const unsigned int from_level,
413  Vector<number> & dst,
414  const Vector<number> &src) const override;
415 
422  template <int dim, typename number2, int spacedim>
423  void
424  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
426  const Vector<number2> & src) const;
427 
434  template <int dim, typename number2, int spacedim>
435  void
436  copy_from_mg(const DoFHandler<dim, spacedim> & dof_handler,
437  Vector<number2> & dst,
438  const MGLevelObject<Vector<number>> &src) const;
439 
445  template <int dim, typename number2, int spacedim>
446  void
447  copy_from_mg_add(const DoFHandler<dim, spacedim> & dof_handler,
448  Vector<number2> & dst,
449  const MGLevelObject<Vector<number>> &src) const;
450 
458  template <int dim, typename number2, int spacedim>
459  void
460  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
462  const BlockVector<number2> & src) const;
463 
470  template <int dim, typename number2, int spacedim>
471  void
472  copy_from_mg(const DoFHandler<dim, spacedim> & dof_handler,
473  BlockVector<number2> & dst,
474  const MGLevelObject<Vector<number>> &src) const;
475 
481  template <int dim, typename number2, int spacedim>
482  void
483  copy_from_mg_add(const DoFHandler<dim, spacedim> & dof_handler,
484  BlockVector<number2> & dst,
485  const MGLevelObject<Vector<number>> &src) const;
486 
490  std::size_t
491  memory_consumption() const;
492 
493 private:
497  template <int dim, class OutVector, int spacedim>
498  void
499  do_copy_from_mg(const DoFHandler<dim, spacedim> & dof_handler,
500  OutVector & dst,
501  const MGLevelObject<Vector<number>> &src,
502  const unsigned int offset) const;
503 
507  template <int dim, class OutVector, int spacedim>
508  void
509  do_copy_from_mg_add(const DoFHandler<dim, spacedim> & dof_handler,
510  OutVector & dst,
511  const MGLevelObject<Vector<number>> &src,
512  const unsigned int offset) const;
513 
517  template <int dim, class InVector, int spacedim>
518  void
519  do_copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
521  const InVector & src,
522  const unsigned int offset) const;
526  unsigned int selected_block;
527 };
528 
531 //------------------------- inline function definition ------------------------
532 template <typename number>
533 inline void
534 MGTransferBlockSelect<number>::select(const unsigned int block)
535 {
536  selected_block = block;
537 }
538 
539 DEAL_II_NAMESPACE_CLOSE
540 
541 #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 build(const DoFHandler< dim, spacedim > &dof_handler)
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