Reference documentation for deal.II version GIT 49863513f1 2023-10-02 19:40:02+00:00
\(\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\}}\)
sparse_matrix_collection.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2022 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_sparse_matrix_collection_h
17 #define dealii_mg_sparse_matrix_collection_h
18 
19 #include <deal.II/base/config.h>
20 
22 
26 #include <deal.II/lac/vector.h>
27 
30 
31 #include <memory>
32 
34 
35 namespace mg
36 {
41  template <typename number>
43  {
44  public:
45  void
46  resize(const unsigned int minlevel, const unsigned int maxlevel);
47 
48  template <int dim, int spacedim>
49  void
50  reinit(const DoFHandler<dim, spacedim> &dof_handler);
51 
52  void
53  set_zero();
54 
57 
63  };
64 
65 
66  template <typename number>
67  void
68  SparseMatrixCollection<number>::resize(const unsigned int minlevel,
69  const unsigned int maxlevel)
70  {
71  matrix.resize(minlevel, maxlevel);
72  matrix.clear_elements();
73  matrix_up.resize(minlevel + 1, maxlevel);
74  matrix_up.clear_elements();
75  matrix_down.resize(minlevel + 1, maxlevel);
76  matrix_down.clear_elements();
77  matrix_in.resize(minlevel, maxlevel);
78  matrix_in.clear_elements();
79  matrix_out.resize(minlevel, maxlevel);
80  matrix_out.clear_elements();
81  sparsity.resize(minlevel, maxlevel);
82  sparsity_edge.resize(minlevel, maxlevel);
83  }
84 
85 
86  template <typename number>
87  template <int dim, int spacedim>
88  void
90  const DoFHandler<dim, spacedim> &dof_handler)
91  {
92  AssertIndexRange(sparsity.max_level(),
93  dof_handler.get_triangulation().n_levels());
94 
95  for (unsigned int level = sparsity.min_level();
96  level <= sparsity.max_level();
97  ++level)
98  {
99  DynamicSparsityPattern dsp(dof_handler.n_dofs(level));
100  MGTools::make_flux_sparsity_pattern(dof_handler, dsp, level);
101  sparsity[level].copy_from(dsp);
102  matrix[level].reinit(sparsity[level]);
103  matrix_in[level].reinit(sparsity[level]);
104  matrix_out[level].reinit(sparsity[level]);
105  if (level > 0)
106  {
107  DynamicSparsityPattern ci_sparsity;
108  ci_sparsity.reinit(dof_handler.n_dofs(level - 1),
109  dof_handler.n_dofs(level));
111  ci_sparsity,
112  level);
113  sparsity_edge[level].copy_from(ci_sparsity);
114  matrix_up[level].reinit(sparsity_edge[level]);
115  matrix_down[level].reinit(sparsity_edge[level]);
116  }
117  }
118  }
119 
120  template <typename number>
121  void
123  {
124  matrix = 0.;
125  matrix_in = 0.;
126  matrix_out = 0.;
127  matrix_up = 0.;
128  matrix_down = 0.;
129  }
130 
131 } // namespace mg
132 
134 
135 #endif
const Triangulation< dim, spacedim > & get_triangulation() const
types::global_dof_index n_dofs() const
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
unsigned int n_levels() const
void reinit(const DoFHandler< dim, spacedim > &dof_handler)
MGLevelObject< SparseMatrix< number > > matrix_in
MGLevelObject< SparseMatrix< number > > matrix
MGLevelObject< SparseMatrix< number > > matrix_out
MGLevelObject< SparseMatrix< number > > matrix_up
MGLevelObject< SparsityPattern > sparsity
void resize(const unsigned int minlevel, const unsigned int maxlevel)
MGLevelObject< SparsityPattern > sparsity_edge
MGLevelObject< SparseMatrix< number > > matrix_down
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
unsigned int level
Definition: grid_out.cc:4617
#define AssertIndexRange(index, range)
Definition: exceptions.h:1857
@ matrix
Contents is actually a matrix.
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity, const unsigned int level, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true)
Definition: mg_tools.cc:606
void make_flux_sparsity_pattern_edge(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity, const unsigned int level)
Definition: mg_tools.cc:680
Definition: mg.h:82