Reference documentation for deal.II version 8.1.0
sparse_matrix_collection.h
1 // ---------------------------------------------------------------------
2 // @f$Id: sparse_matrix_collection.h 31932 2013-12-08 02:15:54Z heister @f$
3 //
4 // Copyright (C) 2003 - 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_sparse_matrix_collection_h
18 #define __deal2__mg_sparse_matrix_collection_h
19 
20 #include <deal.II/lac/vector.h>
21 #include <deal.II/lac/pointer_matrix.h>
22 #include <deal.II/lac/sparse_matrix.h>
23 #include <deal.II/lac/compressed_sparsity_pattern.h>
24 #include <deal.II/multigrid/mg_base.h>
25 #include <deal.II/multigrid/mg_tools.h>
26 #include <deal.II/base/mg_level_object.h>
27 #include <deal.II/base/std_cxx1x/shared_ptr.h>
28 
30 
31 namespace mg
32 {
40  template <typename number>
42  {
43  public:
44  void resize(const unsigned int minlevel, const unsigned int maxlevel);
45 
46  template <class DH>
47  void reinit(const DH &dof_handler);
48 
49  void set_zero();
50 
52  MGLevelObject<SparsityPattern> sparsity_edge;
53 
59  };
60 
61 
62  template <typename number>
63  void
64  SparseMatrixCollection<number>::resize(const unsigned int minlevel, const unsigned int maxlevel)
65  {
66  matrix.resize(minlevel, maxlevel);
67  matrix.clear();
68  matrix_up.resize(minlevel+1, maxlevel);
69  matrix_up.clear();
70  matrix_down.resize(minlevel+1, maxlevel);
71  matrix_down.clear();
72  matrix_in.resize(minlevel, maxlevel);
73  matrix_in.clear();
74  matrix_out.resize(minlevel, maxlevel);
75  matrix_out.clear();
76  sparsity.resize(minlevel, maxlevel);
77  sparsity_edge.resize(minlevel, maxlevel);
78  }
79 
80 
81  template <typename number>
82  template <class DH>
83  void
84  SparseMatrixCollection<number>::reinit(const DH &dof_handler)
85  {
86  AssertIndexRange(sparsity.max_level(), dof_handler.get_tria().n_levels());
87 
88  for (unsigned int level=sparsity.min_level();
89  level<=sparsity.max_level(); ++level)
90  {
91  CompressedSparsityPattern c_sparsity(dof_handler.n_dofs(level));
92  MGTools::make_flux_sparsity_pattern(dof_handler, c_sparsity, level);
93  sparsity[level].copy_from(c_sparsity);
94  matrix[level].reinit(sparsity[level]);
95  matrix_in[level].reinit(sparsity[level]);
96  matrix_out[level].reinit(sparsity[level]);
97  if (level>0)
98  {
99  CompressedSparsityPattern ci_sparsity;
100  ci_sparsity.reinit(dof_handler.n_dofs(level-1), dof_handler.n_dofs(level));
101  MGTools::make_flux_sparsity_pattern_edge(dof_handler, ci_sparsity, level);
102  sparsity_edge[level].copy_from(ci_sparsity);
103  matrix_up[level].reinit(sparsity_edge[level]);
104  matrix_down[level].reinit(sparsity_edge[level]);
105  }
106  }
107  }
108 
109  template <typename number>
110  void
112  {
113  matrix = 0.;
114  matrix_in = 0.;
115  matrix_out = 0.;
116  matrix_up = 0.;
117  matrix_down = 0.;
118  }
119 
120 }
121 
122 DEAL_II_NAMESPACE_CLOSE
123 
124 #endif
Definition: mg.h:82
#define AssertIndexRange(index, range)
Definition: exceptions.h:888
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPattern &sparsity, const unsigned int level)
unsigned int max_level() const
void make_flux_sparsity_pattern_edge(const DoFHandler< dim, spacedim > &dof_handler, SparsityPattern &sparsity, const unsigned int level)
unsigned int min_level() const
void reinit(const size_type m, const size_type n)
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)