Reference documentation for deal.II version Git 06d359936b 2020-09-19 18:16:22 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
mg_transfer.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2020 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_h
17 #define dealii_mg_transfer_h
18 
19 #include <deal.II/base/config.h>
20 
22 
24 
26 
36 
39 
40 #include <memory>
41 
42 
44 
45 
46 namespace internal
47 {
48  template <typename VectorType>
50  {
53 
54  static const bool requires_distributed_sparsity_pattern = false;
55 
56  template <typename SparsityPatternType, int dim, int spacedim>
57  static void
59  Sparsity & sparsity,
60  int level,
61  const SparsityPatternType &sp,
63  {
64  sparsity.copy_from(sp);
65  (void)level;
66  matrix.reinit(sparsity);
67  }
68  };
69 
70 #ifdef DEAL_II_WITH_TRILINOS
71  template <typename Number>
73  {
76 
77  static const bool requires_distributed_sparsity_pattern = false;
78 
79  template <typename SparsityPatternType, int dim, int spacedim>
80  static void
82  Sparsity &,
83  int level,
84  const SparsityPatternType & sp,
85  const DoFHandler<dim, spacedim> &dh)
86  {
87  const ::parallel::TriangulationBase<dim, spacedim> *dist_tria =
88  dynamic_cast<
89  const ::parallel::TriangulationBase<dim, spacedim> *>(
90  &(dh.get_triangulation()));
91  MPI_Comm communicator =
92  dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF;
93 
94  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
95  dh.locally_owned_mg_dofs(level),
96  sp,
97  communicator,
98  true);
99  }
100  };
101 
102  template <>
104  {
107 
108  static const bool requires_distributed_sparsity_pattern = false;
109 
110  template <typename SparsityPatternType, int dim, int spacedim>
111  static void
113  Sparsity &,
114  int level,
115  const SparsityPatternType & sp,
116  const DoFHandler<dim, spacedim> &dh)
117  {
118  const ::parallel::TriangulationBase<dim, spacedim> *dist_tria =
119  dynamic_cast<
120  const ::parallel::TriangulationBase<dim, spacedim> *>(
121  &(dh.get_triangulation()));
122  MPI_Comm communicator =
123  dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF;
124  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
125  dh.locally_owned_mg_dofs(level),
126  sp,
127  communicator,
128  true);
129  }
130  };
131 
132 # ifdef DEAL_II_WITH_MPI
133 # ifdef DEAL_II_TRILINOS_WITH_TPETRA
134  template <typename Number>
136  {
139 
140  static const bool requires_distributed_sparsity_pattern = false;
141 
142  template <typename SparsityPatternType, int dim, int spacedim>
143  static void
145  Sparsity &,
146  int level,
147  const SparsityPatternType & sp,
148  const DoFHandler<dim, spacedim> &dh)
149  {
150  const ::parallel::TriangulationBase<dim, spacedim> *dist_tria =
151  dynamic_cast<
152  const ::parallel::TriangulationBase<dim, spacedim> *>(
153  &(dh.get_triangulation()));
154  MPI_Comm communicator =
155  dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF;
156  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
157  dh.locally_owned_mg_dofs(level),
158  sp,
159  communicator,
160  true);
161  }
162  };
163 # endif
164 
165  template <>
167  {
170 
171  static const bool requires_distributed_sparsity_pattern = false;
172 
173  template <typename SparsityPatternType, int dim, int spacedim>
174  static void
176  Sparsity &,
177  int level,
178  const SparsityPatternType & sp,
179  const DoFHandler<dim, spacedim> &dh)
180  {
181  const ::parallel::TriangulationBase<dim, spacedim> *dist_tria =
182  dynamic_cast<
183  const ::parallel::TriangulationBase<dim, spacedim> *>(
184  &(dh.get_triangulation()));
185  MPI_Comm communicator =
186  dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF;
187  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
188  dh.locally_owned_mg_dofs(level),
189  sp,
190  communicator,
191  true);
192  }
193  };
194 # endif
195 
196 #else
197  // ! DEAL_II_WITH_TRILINOS
198  template <typename Number>
199  struct MatrixSelector<LinearAlgebra::distributed::Vector<Number>>
200  {
201  using Sparsity = ::SparsityPattern;
203 
204  static const bool requires_distributed_sparsity_pattern = false;
205 
206  template <typename SparsityPatternType, int dim, int spacedim>
207  static void
208  reinit(Matrix &,
209  Sparsity &,
210  int,
211  const SparsityPatternType &,
213  {
214  AssertThrow(
215  false,
217  "ERROR: MGTransferPrebuilt with LinearAlgebra::distributed::Vector currently "
218  "needs deal.II to be configured with Trilinos."));
219  }
220  };
221 
222 #endif
223 
224 #ifdef DEAL_II_WITH_PETSC
225  template <>
227  {
230 
231  static const bool requires_distributed_sparsity_pattern = true;
232 
233  template <typename SparsityPatternType, int dim, int spacedim>
234  static void
236  Sparsity &,
237  int level,
238  const SparsityPatternType & sp,
239  const DoFHandler<dim, spacedim> &dh)
240  {
241  const ::parallel::TriangulationBase<dim, spacedim> *dist_tria =
242  dynamic_cast<
243  const ::parallel::TriangulationBase<dim, spacedim> *>(
244  &(dh.get_triangulation()));
245  MPI_Comm communicator =
246  dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF;
247  // Reinit PETSc matrix
248  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
249  dh.locally_owned_mg_dofs(level),
250  sp,
251  communicator);
252  }
253  };
254 #endif
255 } // namespace internal
256 
257 /*
258  * MGTransferBase is defined in mg_base.h
259  */
260 
263 
264 
265 
270 template <typename VectorType>
271 class MGLevelGlobalTransfer : public MGTransferBase<VectorType>
272 {
273 public:
277  void
278  clear();
279 
286  template <int dim, class InVector, int spacedim>
287  void
288  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
290  const InVector & src) const;
291 
299  template <int dim, class OutVector, int spacedim>
300  void
301  copy_from_mg(const DoFHandler<dim, spacedim> &dof_handler,
302  OutVector & dst,
303  const MGLevelObject<VectorType> &src) const;
304 
310  template <int dim, class OutVector, int spacedim>
311  void
312  copy_from_mg_add(const DoFHandler<dim, spacedim> &dof_handler,
313  OutVector & dst,
314  const MGLevelObject<VectorType> &src) const;
315 
331  void
332  set_component_to_block_map(const std::vector<unsigned int> &map);
333 
337  std::size_t
338  memory_consumption() const;
339 
343  void
344  print_indices(std::ostream &os) const;
345 
346 protected:
350  template <int dim, int spacedim>
351  void
352  fill_and_communicate_copy_indices(
353  const DoFHandler<dim, spacedim> &dof_handler);
354 
358  std::vector<types::global_dof_index> sizes;
359 
367  std::vector<
368  std::vector<std::pair<types::global_dof_index, types::global_dof_index>>>
370 
378  std::vector<
379  std::vector<std::pair<types::global_dof_index, types::global_dof_index>>>
381 
389  std::vector<
390  std::vector<std::pair<types::global_dof_index, types::global_dof_index>>>
392 
400 
405  std::vector<unsigned int> component_to_block_map;
406 
412 
413 private:
417  template <int dim, int spacedim>
418  void
419  assert_built(const DoFHandler<dim, spacedim> &dof_handler) const;
420 };
421 
422 
423 
432 template <typename Number>
434  : public MGTransferBase<LinearAlgebra::distributed::Vector<Number>>
435 {
436 public:
440  void
441  clear();
442 
449  template <int dim, typename Number2, int spacedim>
450  void
451  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
454 
462  template <int dim, typename Number2, int spacedim>
463  void
464  copy_from_mg(
465  const DoFHandler<dim, spacedim> & dof_handler,
468 
474  template <int dim, typename Number2, int spacedim>
475  void
476  copy_from_mg_add(
477  const DoFHandler<dim, spacedim> & dof_handler,
480 
496  void
497  set_component_to_block_map(const std::vector<unsigned int> &map);
498 
502  std::size_t
503  memory_consumption() const;
504 
508  void
509  print_indices(std::ostream &os) const;
510 
511 protected:
516  template <int dim, typename Number2, int spacedim>
517  void
518  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
521  const bool solution_transfer) const;
522 
526  template <int dim, int spacedim>
527  void
528  fill_and_communicate_copy_indices(
529  const DoFHandler<dim, spacedim> &dof_handler);
530 
534  std::vector<types::global_dof_index> sizes;
535 
544  std::vector<Table<2, unsigned int>> copy_indices;
545 
549  std::vector<Table<2, unsigned int>> solution_copy_indices;
550 
558  std::vector<Table<2, unsigned int>> copy_indices_global_mine;
559 
563  std::vector<Table<2, unsigned int>> solution_copy_indices_global_mine;
564 
572  std::vector<Table<2, unsigned int>> copy_indices_level_mine;
573 
577  std::vector<Table<2, unsigned int>> solution_copy_indices_level_mine;
578 
586 
594 
599  std::vector<unsigned int> component_to_block_map;
600 
604  SmartPointer<
605  const MGConstrainedDoFs,
608 
615 
621 
628 
634 
635 private:
639  template <int dim, int spacedim>
640  void
641  assert_built(const DoFHandler<dim, spacedim> &dof_handler) const;
642 };
643 
644 
645 
656 template <typename VectorType>
657 class MGTransferPrebuilt : public MGLevelGlobalTransfer<VectorType>
658 {
659 public:
664  MGTransferPrebuilt() = default;
665 
670  MGTransferPrebuilt(const MGConstrainedDoFs &mg_constrained_dofs);
671 
675  virtual ~MGTransferPrebuilt() override = default;
676 
680  void
681  initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs);
682 
686  void
687  clear();
688 
693  template <int dim, int spacedim>
694  void
695  build(const DoFHandler<dim, spacedim> &dof_handler);
696 
702  template <int dim, int spacedim>
703  DEAL_II_DEPRECATED void
704  build_matrices(const DoFHandler<dim, spacedim> &dof_handler);
705 
717  virtual void
718  prolongate(const unsigned int to_level,
719  VectorType & dst,
720  const VectorType & src) const override;
721 
737  virtual void
738  restrict_and_add(const unsigned int from_level,
739  VectorType & dst,
740  const VectorType & src) const override;
741 
745  DeclException0(ExcNoProlongation);
746 
750  DeclException0(ExcMatricesNotBuilt);
751 
755  std::size_t
756  memory_consumption() const;
757 
761  void
762  print_matrices(std::ostream &os) const;
763 
764 private:
768  std::vector<
769  std::shared_ptr<typename internal::MatrixSelector<VectorType>::Sparsity>>
771 
777  std::vector<
778  std::shared_ptr<typename internal::MatrixSelector<VectorType>::Matrix>>
780 
785  std::vector<std::vector<bool>> interface_dofs;
786 };
787 
788 
793 
794 #endif
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:175
const Triangulation< dim, spacedim > & get_triangulation() const
std::vector< Table< 2, unsigned int > > copy_indices_global_mine
Definition: mg_transfer.h:558
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices
Definition: mg_transfer.h:369
Contents is actually a matrix.
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:112
LinearAlgebra::distributed::Vector< Number > solution_ghosted_global_vector
Definition: mg_transfer.h:620
std::vector< Table< 2, unsigned int > > solution_copy_indices_level_mine
Definition: mg_transfer.h:577
#define AssertThrow(cond, exc)
Definition: exceptions.h:1521
std::vector< unsigned int > component_to_block_map
Definition: mg_transfer.h:405
static void reinit(Matrix &matrix, Sparsity &sparsity, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &)
Definition: mg_transfer.h:58
LinearAlgebra::distributed::Vector< Number > ghosted_global_vector
Definition: mg_transfer.h:614
virtual void reinit(const SparsityPattern &sparsity)
std::vector< Table< 2, unsigned int > > solution_copy_indices_global_mine
Definition: mg_transfer.h:563
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices_level_mine
Definition: mg_transfer.h:391
std::vector< Table< 2, unsigned int > > copy_indices_level_mine
Definition: mg_transfer.h:572
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
unsigned int level
Definition: grid_out.cc:4338
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:144
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices_global_mine
Definition: mg_transfer.h:380
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< VectorType > > mg_constrained_dofs
Definition: mg_transfer.h:411
const IndexSet & locally_owned_mg_dofs(const unsigned int level) const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
SparseMatrix< double > SparseMatrix
std::vector< std::shared_ptr< typename internal::MatrixSelector< VectorType >::Sparsity > > prolongation_sparsities
Definition: mg_transfer.h:770
void reinit(const MPI_Comm &communicator, const size_type m, const size_type n, const size_type local_rows, const size_type local_columns, const size_type n_nonzero_per_row, const bool is_symmetric=false, const size_type n_offdiag_nonzero_per_row=0)
std::vector< types::global_dof_index > sizes
Definition: mg_transfer.h:358
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< LinearAlgebra::distributed::Vector< Number > > > mg_constrained_dofs
Definition: mg_transfer.h:607
void reinit(const SparsityPatternType &sparsity_pattern)
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:235
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
MGLevelObject< LinearAlgebra::distributed::Vector< Number > > solution_ghosted_level_vector
Definition: mg_transfer.h:633
std::vector< Table< 2, unsigned int > > solution_copy_indices
Definition: mg_transfer.h:549
static ::ExceptionBase & ExcNotImplemented()
std::vector< std::vector< bool > > interface_dofs
Definition: mg_transfer.h:785
std::vector< std::shared_ptr< typename internal::MatrixSelector< VectorType >::Matrix > > prolongation_matrices
Definition: mg_transfer.h:779
#define DEAL_II_DEPRECATED
Definition: config.h:152
MGLevelObject< LinearAlgebra::distributed::Vector< Number > > ghosted_level_vector
Definition: mg_transfer.h:627
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:81
static const bool requires_distributed_sparsity_pattern
Definition: mg_transfer.h:54
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)