Reference documentation for deal.II version 8.5.1
sparse_matrix_collection.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 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_sparse_matrix_collection_h
17 #define dealii__mg_sparse_matrix_collection_h
18 
19 #include <deal.II/lac/vector.h>
20 #include <deal.II/lac/pointer_matrix.h>
21 #include <deal.II/lac/sparse_matrix.h>
22 #include <deal.II/lac/dynamic_sparsity_pattern.h>
23 #include <deal.II/multigrid/mg_base.h>
24 #include <deal.II/multigrid/mg_tools.h>
25 #include <deal.II/base/mg_level_object.h>
26 #include <deal.II/base/std_cxx11/shared_ptr.h>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 namespace mg
31 {
39  template <typename number>
41  {
42  public:
43  void resize(const unsigned int minlevel, const unsigned int maxlevel);
44 
45  template <typename DoFHandlerType>
46  void reinit(const DoFHandlerType &dof_handler);
47 
48  void set_zero();
49 
51  MGLevelObject<SparsityPattern> sparsity_edge;
52 
58  };
59 
60 
61  template <typename number>
62  void
63  SparseMatrixCollection<number>::resize(const unsigned int minlevel, const unsigned int maxlevel)
64  {
65  matrix.resize(minlevel, maxlevel);
66  matrix.clear_elements();
67  matrix_up.resize(minlevel+1, maxlevel);
68  matrix_up.clear_elements();
69  matrix_down.resize(minlevel+1, maxlevel);
70  matrix_down.clear_elements();
71  matrix_in.resize(minlevel, maxlevel);
72  matrix_in.clear_elements();
73  matrix_out.resize(minlevel, maxlevel);
74  matrix_out.clear_elements();
75  sparsity.resize(minlevel, maxlevel);
76  sparsity_edge.resize(minlevel, maxlevel);
77  }
78 
79 
80  template <typename number>
81  template <typename DoFHandlerType>
82  void
83  SparseMatrixCollection<number>::reinit(const DoFHandlerType &dof_handler)
84  {
85  AssertIndexRange(sparsity.max_level(), dof_handler.get_triangulation().n_levels());
86 
87  for (unsigned int level=sparsity.min_level();
88  level<=sparsity.max_level(); ++level)
89  {
90  DynamicSparsityPattern dsp(dof_handler.n_dofs(level));
91  MGTools::make_flux_sparsity_pattern(dof_handler, dsp, level);
92  sparsity[level].copy_from(dsp);
93  matrix[level].reinit(sparsity[level]);
94  matrix_in[level].reinit(sparsity[level]);
95  matrix_out[level].reinit(sparsity[level]);
96  if (level>0)
97  {
98  DynamicSparsityPattern ci_sparsity;
99  ci_sparsity.reinit(dof_handler.n_dofs(level-1), dof_handler.n_dofs(level));
100  MGTools::make_flux_sparsity_pattern_edge(dof_handler, ci_sparsity, level);
101  sparsity_edge[level].copy_from(ci_sparsity);
102  matrix_up[level].reinit(sparsity_edge[level]);
103  matrix_down[level].reinit(sparsity_edge[level]);
104  }
105  }
106  }
107 
108  template <typename number>
109  void
110  SparseMatrixCollection<number>::set_zero()
111  {
112  matrix = 0.;
113  matrix_in = 0.;
114  matrix_out = 0.;
115  matrix_up = 0.;
116  matrix_down = 0.;
117  }
118 
119 }
120 
121 DEAL_II_NAMESPACE_CLOSE
122 
123 #endif
Definition: mg.h:81
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternType &sparsity, const unsigned int level)
Definition: mg_tools.cc:572
#define AssertIndexRange(index, range)
Definition: exceptions.h:1170
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
void make_flux_sparsity_pattern_edge(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternType &sparsity, const unsigned int level)
Definition: mg_tools.cc:647