Reference documentation for deal.II version Git 3f1f337db3 2021-10-23 13:19:02 -0600
\(\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 - 2021 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 MPI_Comm communicator = dh.get_communicator();
88 
89  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
90  dh.locally_owned_mg_dofs(level),
91  sp,
92  communicator,
93  true);
94  }
95  };
96 
97  template <>
99  {
102 
103  static const bool requires_distributed_sparsity_pattern = false;
104 
105  template <typename SparsityPatternType, int dim, int spacedim>
106  static void
108  Sparsity &,
109  int level,
110  const SparsityPatternType & sp,
111  const DoFHandler<dim, spacedim> &dh)
112  {
113  const MPI_Comm communicator = dh.get_communicator();
114 
115  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
116  dh.locally_owned_mg_dofs(level),
117  sp,
118  communicator,
119  true);
120  }
121  };
122 
123 # ifdef DEAL_II_WITH_MPI
124 # ifdef DEAL_II_TRILINOS_WITH_TPETRA
125  template <typename Number>
127  {
130 
131  static const bool requires_distributed_sparsity_pattern = false;
132 
133  template <typename SparsityPatternType, int dim, int spacedim>
134  static void
136  Sparsity &,
137  int level,
138  const SparsityPatternType & sp,
139  const DoFHandler<dim, spacedim> &dh)
140  {
141  const MPI_Comm communicator = dh.get_communicator();
142 
143  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
144  dh.locally_owned_mg_dofs(level),
145  sp,
146  communicator,
147  true);
148  }
149  };
150 # endif
151 
152  template <>
154  {
157 
158  static const bool requires_distributed_sparsity_pattern = false;
159 
160  template <typename SparsityPatternType, int dim, int spacedim>
161  static void
163  Sparsity &,
164  int level,
165  const SparsityPatternType & sp,
166  const DoFHandler<dim, spacedim> &dh)
167  {
168  const MPI_Comm communicator = dh.get_communicator();
169 
170  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
171  dh.locally_owned_mg_dofs(level),
172  sp,
173  communicator,
174  true);
175  }
176  };
177 # endif
178 
179 #else
180  // ! DEAL_II_WITH_TRILINOS
181  template <typename Number>
182  struct MatrixSelector<LinearAlgebra::distributed::Vector<Number>>
183  {
184  using Sparsity = ::SparsityPattern;
186 
187  static const bool requires_distributed_sparsity_pattern = false;
188 
189  template <typename SparsityPatternType, int dim, int spacedim>
190  static void
191  reinit(Matrix &,
192  Sparsity &,
193  int,
194  const SparsityPatternType &,
196  {
197  AssertThrow(
198  false,
200  "ERROR: MGTransferPrebuilt with LinearAlgebra::distributed::Vector currently "
201  "needs deal.II to be configured with Trilinos."));
202  }
203  };
204 
205 #endif
206 
207 #ifdef DEAL_II_WITH_PETSC
208  template <>
210  {
213 
214  static const bool requires_distributed_sparsity_pattern = true;
215 
216  template <typename SparsityPatternType, int dim, int spacedim>
217  static void
219  Sparsity &,
220  int level,
221  const SparsityPatternType & sp,
222  const DoFHandler<dim, spacedim> &dh)
223  {
224  const MPI_Comm communicator = dh.get_communicator();
225 
226  // Reinit PETSc matrix
227  matrix.reinit(dh.locally_owned_mg_dofs(level + 1),
228  dh.locally_owned_mg_dofs(level),
229  sp,
230  communicator);
231  }
232  };
233 #endif
234 } // namespace internal
235 
236 /*
237  * MGTransferBase is defined in mg_base.h
238  */
239 
242 
243 
244 
249 template <typename VectorType>
250 class MGLevelGlobalTransfer : public MGTransferBase<VectorType>
251 {
252 public:
256  void
257  clear();
258 
265  template <int dim, class InVector, int spacedim>
266  void
267  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
269  const InVector & src) const;
270 
278  template <int dim, class OutVector, int spacedim>
279  void
280  copy_from_mg(const DoFHandler<dim, spacedim> &dof_handler,
281  OutVector & dst,
282  const MGLevelObject<VectorType> &src) const;
283 
289  template <int dim, class OutVector, int spacedim>
290  void
291  copy_from_mg_add(const DoFHandler<dim, spacedim> &dof_handler,
292  OutVector & dst,
293  const MGLevelObject<VectorType> &src) const;
294 
310  void
311  set_component_to_block_map(const std::vector<unsigned int> &map);
312 
316  std::size_t
317  memory_consumption() const;
318 
322  void
323  print_indices(std::ostream &os) const;
324 
325 protected:
329  template <int dim, int spacedim>
330  void
331  fill_and_communicate_copy_indices(
332  const DoFHandler<dim, spacedim> &dof_handler);
333 
337  std::vector<types::global_dof_index> sizes;
338 
346  std::vector<
347  std::vector<std::pair<types::global_dof_index, types::global_dof_index>>>
349 
357  std::vector<
358  std::vector<std::pair<types::global_dof_index, types::global_dof_index>>>
360 
368  std::vector<
369  std::vector<std::pair<types::global_dof_index, types::global_dof_index>>>
371 
379 
384  std::vector<unsigned int> component_to_block_map;
385 
391 
392 private:
396  template <int dim, int spacedim>
397  void
398  assert_built(const DoFHandler<dim, spacedim> &dof_handler) const;
399 };
400 
401 
402 
411 template <typename Number>
413  : public MGTransferBase<LinearAlgebra::distributed::Vector<Number>>
414 {
415 public:
419  void
420  clear();
421 
428  template <int dim, typename Number2, int spacedim>
429  void
430  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
433 
441  template <int dim, typename Number2, int spacedim>
442  void
443  copy_from_mg(
444  const DoFHandler<dim, spacedim> & dof_handler,
447 
453  template <int dim, typename Number2, int spacedim>
454  void
455  copy_from_mg_add(
456  const DoFHandler<dim, spacedim> & dof_handler,
459 
475  void
476  set_component_to_block_map(const std::vector<unsigned int> &map);
477 
481  std::size_t
482  memory_consumption() const;
483 
487  void
488  print_indices(std::ostream &os) const;
489 
490 protected:
495  template <int dim, typename Number2, int spacedim>
496  void
497  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
500  const bool solution_transfer) const;
501 
505  template <int dim, int spacedim>
506  void
507  fill_and_communicate_copy_indices(
508  const DoFHandler<dim, spacedim> &dof_handler);
509 
513  std::vector<types::global_dof_index> sizes;
514 
523  std::vector<Table<2, unsigned int>> copy_indices;
524 
528  std::vector<Table<2, unsigned int>> solution_copy_indices;
529 
537  std::vector<Table<2, unsigned int>> copy_indices_global_mine;
538 
542  std::vector<Table<2, unsigned int>> solution_copy_indices_global_mine;
543 
551  std::vector<Table<2, unsigned int>> copy_indices_level_mine;
552 
556  std::vector<Table<2, unsigned int>> solution_copy_indices_level_mine;
557 
565 
573 
578  std::vector<unsigned int> component_to_block_map;
579 
583  SmartPointer<
584  const MGConstrainedDoFs,
587 
594 
600 
607 
613 
614 private:
618  template <int dim, int spacedim>
619  void
620  assert_built(const DoFHandler<dim, spacedim> &dof_handler) const;
621 };
622 
623 
624 
635 template <typename VectorType>
636 class MGTransferPrebuilt : public MGLevelGlobalTransfer<VectorType>
637 {
638 public:
643  MGTransferPrebuilt() = default;
644 
649  MGTransferPrebuilt(const MGConstrainedDoFs &mg_constrained_dofs);
650 
654  virtual ~MGTransferPrebuilt() override = default;
655 
659  void
660  initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs);
661 
665  void
666  clear();
667 
672  template <int dim, int spacedim>
673  void
674  build(const DoFHandler<dim, spacedim> &dof_handler);
675 
687  virtual void
688  prolongate(const unsigned int to_level,
689  VectorType & dst,
690  const VectorType & src) const override;
691 
707  virtual void
708  restrict_and_add(const unsigned int from_level,
709  VectorType & dst,
710  const VectorType & src) const override;
711 
715  DeclException0(ExcNoProlongation);
716 
720  DeclException0(ExcMatricesNotBuilt);
721 
725  std::size_t
726  memory_consumption() const;
727 
731  void
732  print_matrices(std::ostream &os) const;
733 
734 private:
738  std::vector<
739  std::shared_ptr<typename internal::MatrixSelector<VectorType>::Sparsity>>
741 
747  std::vector<
748  std::shared_ptr<typename internal::MatrixSelector<VectorType>::Matrix>>
750 
755  std::vector<std::vector<bool>> interface_dofs;
756 };
757 
758 
763 
764 #endif
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:162
std::vector< Table< 2, unsigned int > > copy_indices_global_mine
Definition: mg_transfer.h:537
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices
Definition: mg_transfer.h:348
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:107
LinearAlgebra::distributed::Vector< Number > solution_ghosted_global_vector
Definition: mg_transfer.h:599
std::vector< Table< 2, unsigned int > > solution_copy_indices_level_mine
Definition: mg_transfer.h:556
MPI_Comm get_communicator() const
#define AssertThrow(cond, exc)
Definition: exceptions.h:1571
std::vector< unsigned int > component_to_block_map
Definition: mg_transfer.h:384
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:593
virtual void reinit(const SparsityPattern &sparsity)
std::vector< Table< 2, unsigned int > > solution_copy_indices_global_mine
Definition: mg_transfer.h:542
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices_level_mine
Definition: mg_transfer.h:370
std::vector< Table< 2, unsigned int > > copy_indices_level_mine
Definition: mg_transfer.h:551
#define DeclException0(Exception0)
Definition: exceptions.h:464
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
unsigned int level
Definition: grid_out.cc:4589
void reinit(const MPI_Comm &communicator, const SparsityPatternType &sparsity_pattern, const std::vector< size_type > &local_rows_per_process, const std::vector< size_type > &local_columns_per_process, const unsigned int this_process, const bool preset_nonzero_locations=true)
static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, const DoFHandler< dim, spacedim > &dh)
Definition: mg_transfer.h:135
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices_global_mine
Definition: mg_transfer.h:359
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< VectorType > > mg_constrained_dofs
Definition: mg_transfer.h:390
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:740
std::vector< types::global_dof_index > sizes
Definition: mg_transfer.h:337
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< LinearAlgebra::distributed::Vector< Number > > > mg_constrained_dofs
Definition: mg_transfer.h:586
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:218
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
MGLevelObject< LinearAlgebra::distributed::Vector< Number > > solution_ghosted_level_vector
Definition: mg_transfer.h:612
std::vector< Table< 2, unsigned int > > solution_copy_indices
Definition: mg_transfer.h:528
static ::ExceptionBase & ExcNotImplemented()
std::vector< std::vector< bool > > interface_dofs
Definition: mg_transfer.h:755
std::vector< std::shared_ptr< typename internal::MatrixSelector< VectorType >::Matrix > > prolongation_matrices
Definition: mg_transfer.h:749
MGLevelObject< LinearAlgebra::distributed::Vector< Number > > ghosted_level_vector
Definition: mg_transfer.h:606
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)