Reference documentation for deal.II version 8.1.0
mg_transfer.h
1 // ---------------------------------------------------------------------
2 // @f$Id: mg_transfer.h 30040 2013-07-18 17:06:48Z maier @f$
3 //
4 // Copyright (C) 2001 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__mg_transfer_h
18 #define __deal2__mg_transfer_h
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/lac/block_vector.h>
23 #include <deal.II/lac/constraint_matrix.h>
24 #include <deal.II/lac/sparse_matrix.h>
25 #include <deal.II/lac/block_sparsity_pattern.h>
26 #include <deal.II/lac/trilinos_sparse_matrix.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_cxx1x/shared_ptr.h>
37 
38 
40 
41 
42 template <int dim, int spacedim> class DoFHandler;
43 
44 namespace internal
45 {
46  template <class VECTOR>
48  {
49  typedef ::SparsityPattern Sparsity;
50  typedef ::SparseMatrix<typename VECTOR::value_type> Matrix;
51 
52  template <class CSP, class DH>
53  static void reinit(Matrix &matrix, Sparsity &sparsity, int level, const CSP &csp, const DH &)
54  {
55  sparsity.copy_from (csp);
56  matrix.reinit (sparsity);
57  }
58  };
59 
60 #ifdef DEAL_II_WITH_TRILINOS
61  template <>
63  {
64  typedef ::TrilinosWrappers::SparsityPattern Sparsity;
65  typedef ::TrilinosWrappers::SparseMatrix Matrix;
66 
67  template <class CSP, class DH>
68  static void reinit(Matrix &matrix, Sparsity &sparsity, int level, const CSP &csp, DH &dh)
69  {
70  matrix.reinit(dh.locally_owned_mg_dofs(level+1),
71  dh.locally_owned_mg_dofs(level),
72  csp, MPI_COMM_WORLD, true);
73  }
74 
75  };
76 
77  template <>
79  {
80  typedef ::TrilinosWrappers::SparsityPattern Sparsity;
81  typedef ::TrilinosWrappers::SparseMatrix Matrix;
82 
83  template <class CSP, class DH>
84  static void reinit(Matrix &matrix, Sparsity &sparsity, int level, const CSP &csp, DH &dh)
85  {
86  }
87  };
88 #endif
89 }
90 
91 /*
92  * MGTransferBase is defined in mg_base.h
93  */
94 
97 
111 template <class VECTOR>
112 class MGTransferPrebuilt : public MGTransferBase<VECTOR>
113 {
114 public:
131  virtual ~MGTransferPrebuilt ();
136  template <int dim, int spacedim>
137  void build_matrices (const DoFHandler<dim,spacedim> &mg_dof);
138 
139  virtual void prolongate (const unsigned int to_level,
140  VECTOR &dst,
141  const VECTOR &src) const;
142 
143  virtual void restrict_and_add (const unsigned int from_level,
144  VECTOR &dst,
145  const VECTOR &src) const;
146 
153  template <int dim, class InVector, int spacedim>
154  void
155  copy_to_mg (const DoFHandler<dim,spacedim> &mg_dof,
157  const InVector &src) const;
158 
171  template <int dim, class OutVector, int spacedim>
172  void
173  copy_from_mg (const DoFHandler<dim,spacedim> &mg_dof,
174  OutVector &dst,
175  const MGLevelObject<VECTOR> &src) const;
176 
185  template <int dim, class OutVector, int spacedim>
186  void
188  OutVector &dst,
189  const MGLevelObject<VECTOR> &src) const;
190 
221  void
222  set_component_to_block_map (const std::vector<unsigned int> &map);
223 
227  DeclException0(ExcNoProlongation);
228 
232  DeclException0(ExcMatricesNotBuilt);
233 
237  std::size_t memory_consumption () const;
238 
242  void print_matrices(std::ostream &os) const;
243 
247  void print_indices(std::ostream &os) const;
248 
249 private:
250 
254  std::vector<types::global_dof_index> sizes;
255 
259  std::vector<std_cxx1x::shared_ptr<typename internal::MatrixSelector<VECTOR>::Sparsity> > prolongation_sparsities;
260 
266  std::vector<std_cxx1x::shared_ptr<typename internal::MatrixSelector<VECTOR>::Matrix> > prolongation_matrices;
267 
276  std::vector<std::vector<std::pair<types::global_dof_index, unsigned int> > >
278 
286  std::vector<std::vector<std::pair<types::global_dof_index, unsigned int> > >
288 
296  std::vector<std::vector<std::pair<types::global_dof_index, unsigned int> > >
298 
299 
306  std::vector<unsigned int> component_to_block_map;
307 
313  std::vector<std::vector<bool> > interface_dofs;
325 };
326 
327 
331 DEAL_II_NAMESPACE_CLOSE
332 
333 #endif
DeclException0(ExcNoProlongation)
void build_matrices(const DoFHandler< dim, spacedim > &mg_dof)
std::vector< unsigned int > component_to_block_map
Definition: mg_transfer.h:306
std::vector< std::vector< std::pair< types::global_dof_index, unsigned int > > > copy_indices
Definition: mg_transfer.h:277
std::vector< std_cxx1x::shared_ptr< typename internal::MatrixSelector< VECTOR >::Sparsity > > prolongation_sparsities
Definition: mg_transfer.h:259
SmartPointer< const ConstraintMatrix, MGTransferPrebuilt< VECTOR > > constraints
Definition: mg_transfer.h:318
void print_matrices(std::ostream &os) const
void reinit(const SparsityType &sparsity_pattern)
void set_component_to_block_map(const std::vector< unsigned int > &map)
std::vector< std_cxx1x::shared_ptr< typename internal::MatrixSelector< VECTOR >::Matrix > > prolongation_matrices
Definition: mg_transfer.h:266
virtual void restrict_and_add(const unsigned int from_level, VECTOR &dst, const VECTOR &src) const
std::vector< std::vector< std::pair< types::global_dof_index, unsigned int > > > copy_indices_from_me
Definition: mg_transfer.h:297
virtual void reinit(const SparsityPattern &sparsity)
virtual ~MGTransferPrebuilt()
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end, const bool optimize_diagonal) DEAL_II_DEPRECATED
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< VECTOR > &src) const
void copy_from_mg_add(const DoFHandler< dim, spacedim > &mg_dof, OutVector &dst, const MGLevelObject< VECTOR > &src) const
std::size_t memory_consumption() const
virtual void prolongate(const unsigned int to_level, VECTOR &dst, const VECTOR &src) const
std::vector< std::vector< bool > > interface_dofs
Definition: mg_transfer.h:313
SmartPointer< const MGConstrainedDoFs, MGTransferPrebuilt< VECTOR > > mg_constrained_dofs
Definition: mg_transfer.h:324
std::vector< types::global_dof_index > sizes
Definition: mg_transfer.h:254
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< VECTOR > &dst, const InVector &src) const
std::vector< std::vector< std::pair< types::global_dof_index, unsigned int > > > copy_indices_to_me
Definition: mg_transfer.h:287
void print_indices(std::ostream &os) const