Reference documentation for deal.II version 9.3.3
\(\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\}}\)
multigrid.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2000 - 2020 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
26#include <deal.II/lac/vector.h>
27
31#include <deal.II/multigrid/mg_transfer_block.templates.h>
33#include <deal.II/multigrid/mg_transfer_component.templates.h>
34#include <deal.II/multigrid/multigrid.templates.h>
35
37
38
40 : n_mg_blocks(0)
41{}
42
43
44
46 : n_mg_blocks(0)
47 , mg_constrained_dofs(&mg_c)
48{}
49
50
51
52template <typename number>
54 : memory(nullptr, typeid(*this).name())
55{}
56
57
58template <typename number>
60{
61 if (memory != nullptr)
62 memory = nullptr;
63}
64
65
66template <typename number>
67void
68MGTransferBlock<number>::initialize(const std::vector<number> & f,
70{
71 factors = f;
72 memory = &mem;
73}
74
75
76template <typename number>
77void
78MGTransferBlock<number>::prolongate(const unsigned int to_level,
80 const BlockVector<number> &src) const
81{
82 Assert((to_level >= 1) && (to_level <= prolongation_matrices.size()),
83 ExcIndexRange(to_level, 1, prolongation_matrices.size() + 1));
84 Assert(src.n_blocks() == this->n_mg_blocks,
85 ExcDimensionMismatch(src.n_blocks(), this->n_mg_blocks));
86 Assert(dst.n_blocks() == this->n_mg_blocks,
87 ExcDimensionMismatch(dst.n_blocks(), this->n_mg_blocks));
88
89#ifdef DEBUG
90 if (this->mg_constrained_dofs != nullptr)
91 Assert(this->mg_constrained_dofs->get_user_constraint_matrix(to_level - 1)
92 .get_local_lines()
93 .size() == 0,
95#endif
96
97 // Multiplicate with prolongation
98 // matrix, but only those blocks
99 // selected.
100 for (unsigned int b = 0; b < this->mg_block.size(); ++b)
101 {
102 if (this->selected[b])
103 prolongation_matrices[to_level - 1]->block(b, b).vmult(
104 dst.block(this->mg_block[b]), src.block(this->mg_block[b]));
105 }
106}
107
108
109template <typename number>
110void
111MGTransferBlock<number>::restrict_and_add(const unsigned int from_level,
113 const BlockVector<number> &src) const
114{
115 Assert((from_level >= 1) && (from_level <= prolongation_matrices.size()),
116 ExcIndexRange(from_level, 1, prolongation_matrices.size() + 1));
117 Assert(src.n_blocks() == this->n_mg_blocks,
118 ExcDimensionMismatch(src.n_blocks(), this->n_mg_blocks));
119 Assert(dst.n_blocks() == this->n_mg_blocks,
120 ExcDimensionMismatch(dst.n_blocks(), this->n_mg_blocks));
121
122 for (unsigned int b = 0; b < this->mg_block.size(); ++b)
123 {
124 if (this->selected[b])
125 {
126 if (factors.size() != 0)
127 {
128 Assert(memory != nullptr, ExcNotInitialized());
129 Vector<number> *aux = memory->alloc();
130 aux->reinit(dst.block(this->mg_block[b]));
131 prolongation_matrices[from_level - 1]->block(b, b).Tvmult(
132 *aux, src.block(this->mg_block[b]));
133
134 dst.block(this->mg_block[b]).add(factors[b], *aux);
135 memory->free(aux);
136 }
137 else
138 {
139 prolongation_matrices[from_level - 1]->block(b, b).Tvmult_add(
140 dst.block(this->mg_block[b]), src.block(this->mg_block[b]));
141 }
142 }
143 }
144}
145
146
147
148std::size_t
150{
151 std::size_t result = sizeof(*this);
153 sizeof(ComponentMask);
155 sizeof(mg_target_component);
158 sizeof(component_start);
160 sizeof(mg_component_start);
164 sizeof(prolongation_matrices);
165 // TODO:[GK] Add this.
166 // result += MemoryConsumption::memory_consumption(copy_to_and_from_indices)
167 // - sizeof(copy_to_and_from_indices);
168 return result;
169}
170
171
172// TODO:[GK] Add all those little vectors.
173std::size_t
175{
176 std::size_t result = sizeof(*this);
177 result += sizeof(unsigned int) * sizes.size();
180 result +=
183 sizeof(mg_block_start);
187 sizeof(prolongation_matrices);
188 // TODO:[GK] Add this.
189 // result += MemoryConsumption::memory_consumption(copy_indices)
190 // - sizeof(copy_indices);
191 return result;
192}
193
194
195//----------------------------------------------------------------------//
196
197template <typename number>
199 : selected_component(0)
200 , mg_selected_component(0)
201{}
202
203
204template <typename number>
206 : selected_component(0)
207 , mg_selected_component(0)
208 , constraints(&c)
209{}
210
211
212
213template <typename number>
214void
215MGTransferSelect<number>::prolongate(const unsigned int to_level,
216 Vector<number> & dst,
217 const Vector<number> &src) const
218{
219 Assert((to_level >= 1) && (to_level <= prolongation_matrices.size()),
220 ExcIndexRange(to_level, 1, prolongation_matrices.size() + 1));
221
222 prolongation_matrices[to_level - 1]
223 ->block(mg_target_component[mg_selected_component],
224 mg_target_component[mg_selected_component])
225 .vmult(dst, src);
226}
227
228
229
230template <typename number>
231void
232MGTransferSelect<number>::restrict_and_add(const unsigned int from_level,
233 Vector<number> & dst,
234 const Vector<number> &src) const
235{
236 Assert((from_level >= 1) && (from_level <= prolongation_matrices.size()),
237 ExcIndexRange(from_level, 1, prolongation_matrices.size() + 1));
238
239 prolongation_matrices[from_level - 1]
240 ->block(mg_target_component[mg_selected_component],
241 mg_target_component[mg_selected_component])
242 .Tvmult_add(dst, src);
243}
244
245
246//----------------------------------------------------------------------//
247
248template <typename number>
250 : selected_block(0)
251{}
252
253
254
255template <typename number>
257 const MGConstrainedDoFs &mg_c)
258 : MGTransferBlockBase(mg_c)
259 , selected_block(0)
260{}
261
262
263
264template <typename number>
265void
267 Vector<number> & dst,
268 const Vector<number> &src) const
269{
270 Assert((to_level >= 1) && (to_level <= prolongation_matrices.size()),
271 ExcIndexRange(to_level, 1, prolongation_matrices.size() + 1));
272
273#ifdef DEBUG
274 if (this->mg_constrained_dofs != nullptr)
275 Assert(this->mg_constrained_dofs->get_user_constraint_matrix(to_level - 1)
276 .get_local_lines()
277 .size() == 0,
279#endif
280
281 prolongation_matrices[to_level - 1]
282 ->block(selected_block, selected_block)
283 .vmult(dst, src);
284}
285
286
287template <typename number>
288void
290 Vector<number> & dst,
291 const Vector<number> &src) const
292{
293 Assert((from_level >= 1) && (from_level <= prolongation_matrices.size()),
294 ExcIndexRange(from_level, 1, prolongation_matrices.size() + 1));
295
296 prolongation_matrices[from_level - 1]
297 ->block(selected_block, selected_block)
298 .Tvmult_add(dst, src);
299}
300
301
302
303// Explicit instantiations
304
305#include "multigrid.inst"
306
307template class MGTransferBlock<float>;
308template class MGTransferBlock<double>;
309template class MGTransferSelect<float>;
310template class MGTransferSelect<double>;
311template class MGTransferBlockSelect<float>;
312template class MGTransferBlockSelect<double>;
313
314
std::vector< unsigned int > mg_block
std::vector< std::vector< types::global_dof_index > > sizes
std::vector< bool > selected
std::vector< types::global_dof_index > block_start
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
std::vector< std::shared_ptr< BlockSparsityPattern > > prolongation_sparsities
std::vector< std::vector< types::global_dof_index > > mg_block_start
std::size_t memory_consumption() const
Definition: multigrid.cc:174
virtual void prolongate(const unsigned int to_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:266
virtual void restrict_and_add(const unsigned int from_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:289
virtual void prolongate(const unsigned int to_level, BlockVector< number > &dst, const BlockVector< number > &src) const override
Definition: multigrid.cc:78
virtual void restrict_and_add(const unsigned int from_level, BlockVector< number > &dst, const BlockVector< number > &src) const override
Definition: multigrid.cc:111
virtual ~MGTransferBlock() override
Definition: multigrid.cc:59
void initialize(const std::vector< number > &factors, VectorMemory< Vector< number > > &memory)
Definition: multigrid.cc:68
std::vector< unsigned int > mg_target_component
std::vector< unsigned int > target_component
std::vector< types::global_dof_index > component_start
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
std::vector< std::vector< types::global_dof_index > > mg_component_start
std::vector< std::shared_ptr< BlockSparsityPattern > > prolongation_sparsities
std::vector< std::vector< types::global_dof_index > > sizes
std::size_t memory_consumption() const
Definition: multigrid.cc:149
virtual void prolongate(const unsigned int to_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:215
virtual void restrict_and_add(const unsigned int from_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:232
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
unsigned int n_blocks() const
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
#define Assert(cond, exc)
Definition: exceptions.h:1465
BlockType & block(const unsigned int i)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotInitialized()
void add(const std::vector< size_type > &indices, const std::vector< OtherNumber > &values)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)