Reference documentation for deal.II version 8.4.1
mg_transfer.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2016 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_h
17 #define dealii__mg_transfer_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/lac/block_vector.h>
22 #include <deal.II/lac/constraint_matrix.h>
23 #include <deal.II/lac/sparse_matrix.h>
24 #include <deal.II/lac/block_sparsity_pattern.h>
25 #include <deal.II/lac/trilinos_sparse_matrix.h>
26 #include <deal.II/lac/parallel_vector.h>
27 
28 #include <deal.II/lac/vector_memory.h>
29 
30 #include <deal.II/multigrid/mg_base.h>
31 #include <deal.II/multigrid/mg_constrained_dofs.h>
32 #include <deal.II/base/mg_level_object.h>
33 
34 #include <deal.II/dofs/dof_handler.h>
35 
36 #include <deal.II/base/std_cxx11/shared_ptr.h>
37 
38 
39 DEAL_II_NAMESPACE_OPEN
40 
41 
42 namespace internal
43 {
44  template <typename VectorType>
45  struct MatrixSelector
46  {
47  typedef ::SparsityPattern Sparsity;
48  typedef ::SparseMatrix<typename VectorType::value_type> Matrix;
49 
50  template <typename SparsityPatternType, typename DoFHandlerType>
51  static void reinit(Matrix &matrix, Sparsity &sparsity, int level, const SparsityPatternType &sp, const DoFHandlerType &)
52  {
53  sparsity.copy_from (sp);
54  (void)level;
55  matrix.reinit (sparsity);
56  }
57  };
58 
59 #ifdef DEAL_II_WITH_TRILINOS
60  template <typename Number>
61  struct MatrixSelector<parallel::distributed::Vector<Number> >
62  {
63  typedef ::TrilinosWrappers::SparsityPattern Sparsity;
64  typedef ::TrilinosWrappers::SparseMatrix Matrix;
65 
66  template <typename SparsityPatternType, typename DoFHandlerType>
67  static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, DoFHandlerType &dh)
68  {
69  matrix.reinit(dh.locally_owned_mg_dofs(level+1),
70  dh.locally_owned_mg_dofs(level),
71  sp, MPI_COMM_WORLD, true);
72  }
73 
74  };
75  template <>
76  struct MatrixSelector<::TrilinosWrappers::MPI::Vector>
77  {
78  typedef ::TrilinosWrappers::SparsityPattern Sparsity;
79  typedef ::TrilinosWrappers::SparseMatrix Matrix;
80 
81  template <typename SparsityPatternType, typename DoFHandlerType>
82  static void reinit(Matrix &matrix, Sparsity &, int level, const SparsityPatternType &sp, DoFHandlerType &dh)
83  {
84  matrix.reinit(dh.locally_owned_mg_dofs(level+1),
85  dh.locally_owned_mg_dofs(level),
86  sp, MPI_COMM_WORLD, true);
87  }
88 
89  };
90 
91  template <>
92  struct MatrixSelector<::TrilinosWrappers::Vector>
93  {
94  typedef ::TrilinosWrappers::SparsityPattern Sparsity;
95  typedef ::TrilinosWrappers::SparseMatrix Matrix;
96 
97  template <typename SparsityPatternType, typename DoFHandlerType>
98  static void reinit(Matrix &, Sparsity &, int /*level*/, const SparsityPatternType &, DoFHandlerType &)
99  {
100  }
101  };
102 #endif
103 }
104 
105 /*
106  * MGTransferBase is defined in mg_base.h
107  */
108 
111 
112 
113 
121 template <typename VectorType>
122 class MGLevelGlobalTransfer : public MGTransferBase<VectorType>
123 {
124 public:
125 
129  void clear ();
130 
135  template <int dim, class InVector, int spacedim>
136  void
137  copy_to_mg (const DoFHandler<dim,spacedim> &mg_dof,
139  const InVector &src) const;
140 
148  template <int dim, class OutVector, int spacedim>
149  void
150  copy_from_mg (const DoFHandler<dim,spacedim> &mg_dof,
151  OutVector &dst,
152  const MGLevelObject<VectorType> &src) const;
153 
159  template <int dim, class OutVector, int spacedim>
160  void
162  OutVector &dst,
163  const MGLevelObject<VectorType> &src) const;
164 
180  void
181  set_component_to_block_map (const std::vector<unsigned int> &map);
182 
186  std::size_t memory_consumption () const;
187 
191  void print_indices(std::ostream &os) const;
192 
193 protected:
194 
198  template <int dim, int spacedim>
200 
204  std::vector<types::global_dof_index> sizes;
205 
213  std::vector<std::vector<std::pair<types::global_dof_index, types::global_dof_index> > >
215 
223  std::vector<std::vector<std::pair<types::global_dof_index, types::global_dof_index> > >
225 
233  std::vector<std::vector<std::pair<types::global_dof_index, types::global_dof_index> > >
235 
243 
248  std::vector<unsigned int> component_to_block_map;
249 
254 };
255 
256 
257 
269 template <typename Number>
270 class MGLevelGlobalTransfer<parallel::distributed::Vector<Number> > : public MGTransferBase<parallel::distributed::Vector<Number> >
271 {
272 public:
273 
277  void clear ();
278 
283  template <int dim, typename Number2, int spacedim>
284  void
285  copy_to_mg (const DoFHandler<dim,spacedim> &mg_dof,
287  const parallel::distributed::Vector<Number2> &src) const;
288 
296  template <int dim, typename Number2, int spacedim>
297  void
298  copy_from_mg (const DoFHandler<dim,spacedim> &mg_dof,
301 
307  template <int dim, typename Number2, int spacedim>
308  void
312 
328  void
329  set_component_to_block_map (const std::vector<unsigned int> &map);
330 
334  std::size_t memory_consumption () const;
335 
339  void print_indices(std::ostream &os) const;
340 
341 protected:
342 
346  template <int dim, int spacedim>
348 
352  std::vector<types::global_dof_index> sizes;
353 
361  std::vector<std::vector<std::pair<unsigned int, unsigned int> > >
363 
371  std::vector<std::vector<std::pair<unsigned int, unsigned int> > >
373 
381  std::vector<std::vector<std::pair<unsigned int, unsigned int> > >
383 
391 
396  std::vector<unsigned int> component_to_block_map;
397 
402 
409 
415 };
416 
417 
418 
432 template <typename VectorType>
433 class MGTransferPrebuilt : public MGLevelGlobalTransfer<VectorType>
434 {
435 public:
441 
448 
452  virtual ~MGTransferPrebuilt ();
453 
457  void initialize_constraints (const ConstraintMatrix &constraints,
458  const MGConstrainedDoFs &mg_constrained_dofs);
459 
463  void clear ();
464 
468  template <int dim, int spacedim>
469  void build_matrices (const DoFHandler<dim,spacedim> &mg_dof);
470 
482  virtual void prolongate (const unsigned int to_level,
483  VectorType &dst,
484  const VectorType &src) const;
485 
501  virtual void restrict_and_add (const unsigned int from_level,
502  VectorType &dst,
503  const VectorType &src) const;
504 
508  DeclException0(ExcNoProlongation);
509 
513  DeclException0(ExcMatricesNotBuilt);
514 
518  std::size_t memory_consumption () const;
519 
523  void print_matrices(std::ostream &os) const;
524 
525 private:
526 
530  std::vector<std_cxx11::shared_ptr<typename internal::MatrixSelector<VectorType>::Sparsity> > prolongation_sparsities;
531 
537  std::vector<std_cxx11::shared_ptr<typename internal::MatrixSelector<VectorType>::Matrix> > prolongation_matrices;
538 
543  std::vector<std::vector<bool> > interface_dofs;
544 
549 };
550 
551 
555 DEAL_II_NAMESPACE_CLOSE
556 
557 #endif
std::size_t memory_consumption() const
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices
Definition: mg_transfer.h:214
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > copy_indices_global_mine
Definition: mg_transfer.h:372
void build_matrices(const DoFHandler< dim, spacedim > &mg_dof)
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< VectorType > &src) const
SmartPointer< const ConstraintMatrix, MGTransferPrebuilt< VectorType > > constraints
Definition: mg_transfer.h:548
DeclException0(ExcNoProlongation)
std::vector< std_cxx11::shared_ptr< typename internal::MatrixSelector< VectorType >::Matrix > > prolongation_matrices
Definition: mg_transfer.h:537
parallel::distributed::Vector< Number > ghosted_global_vector
Definition: mg_transfer.h:408
std::vector< unsigned int > component_to_block_map
Definition: mg_transfer.h:248
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< parallel::distributed::Vector< Number > > > mg_constrained_dofs
Definition: mg_transfer.h:401
void initialize_constraints(const ConstraintMatrix &constraints, const MGConstrainedDoFs &mg_constrained_dofs)
std::vector< std_cxx11::shared_ptr< typename internal::MatrixSelector< VectorType >::Sparsity > > prolongation_sparsities
Definition: mg_transfer.h:530
void print_matrices(std::ostream &os) const
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices_level_mine
Definition: mg_transfer.h:234
void fill_and_communicate_copy_indices(const DoFHandler< dim, spacedim > &mg_dof)
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > copy_indices_level_mine
Definition: mg_transfer.h:382
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< VectorType > > mg_constrained_dofs
Definition: mg_transfer.h:253
MGLevelObject< parallel::distributed::Vector< Number > > ghosted_level_vector
Definition: mg_transfer.h:414
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< VectorType > &dst, const InVector &src) const
std::vector< types::global_dof_index > sizes
Definition: mg_transfer.h:204
virtual void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const
void print_indices(std::ostream &os) const
std::vector< std::vector< std::pair< types::global_dof_index, types::global_dof_index > > > copy_indices_global_mine
Definition: mg_transfer.h:224
void copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< VectorType > &src) const
std::vector< std::vector< bool > > interface_dofs
Definition: mg_transfer.h:543
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > copy_indices
Definition: mg_transfer.h:362
void set_component_to_block_map(const std::vector< unsigned int > &map)
std::size_t memory_consumption() const