Reference documentation for deal.II version 9.2.0
\(\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 
20 #include <deal.II/lac/la_vector.h>
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 
52 template <typename number>
54  : memory(nullptr, typeid(*this).name())
55 {}
56 
57 
58 template <typename number>
60 {
61  if (memory != nullptr)
62  memory = nullptr;
63 }
64 
65 
66 template <typename number>
67 void
68 MGTransferBlock<number>::initialize(const std::vector<number> & f,
70 {
71  factors = f;
72  memory = &mem;
73 }
74 
75 
76 template <typename number>
77 void
78 MGTransferBlock<number>::prolongate(const unsigned int to_level,
79  BlockVector<number> & dst,
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 
109 template <typename number>
110 void
111 MGTransferBlock<number>::restrict_and_add(const unsigned int from_level,
112  BlockVector<number> & dst,
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 
148 std::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);
162  sizeof(prolongation_sparsities);
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.
173 std::size_t
175 {
176  std::size_t result = sizeof(*this);
177  result += sizeof(unsigned int) * sizes.size();
180  result +=
183  sizeof(mg_block_start);
185  sizeof(prolongation_sparsities);
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 
197 template <typename number>
199  : selected_component(0)
200  , mg_selected_component(0)
201 {}
202 
203 
204 template <typename number>
206  : selected_component(0)
207  , mg_selected_component(0)
208  , constraints(&c)
209 {}
210 
211 
212 
213 template <typename number>
214 void
215 MGTransferSelect<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 
230 template <typename number>
231 void
232 MGTransferSelect<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 
248 template <typename number>
250  : selected_block(0)
251 {}
252 
253 
254 
255 template <typename number>
257  const MGConstrainedDoFs &mg_c)
258  : MGTransferBlockBase(mg_c)
259  , selected_block(0)
260 {}
261 
262 
263 
264 template <typename number>
265 void
266 MGTransferBlockSelect<number>::prolongate(const unsigned int to_level,
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 
287 template <typename number>
288 void
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 
307 template class MGTransferBlock<float>;
308 template class MGTransferBlock<double>;
309 template class MGTransferSelect<float>;
310 template class MGTransferSelect<double>;
311 template class MGTransferBlockSelect<float>;
312 template class MGTransferBlockSelect<double>;
313 
314 
MGTransferBlock::prolongate
virtual void prolongate(const unsigned int to_level, BlockVector< number > &dst, const BlockVector< number > &src) const override
Definition: multigrid.cc:78
Vector::add
void add(const std::vector< size_type > &indices, const std::vector< OtherNumber > &values)
la_vector.h
sparse_matrix.h
MGTransferBlockBase::selected
std::vector< bool > selected
Definition: mg_transfer_block.h:116
mg_transfer_block.h
mg_smoother.h
MGTransferBlockBase::block_start
std::vector< types::global_dof_index > block_start
Definition: mg_transfer_block.h:141
MGTransferSelect
Definition: mg_transfer_component.h:194
MGTransferBlock::MGTransferBlock
MGTransferBlock()
Definition: multigrid.cc:53
BlockVector< number >
MGTransferComponentBase::mg_component_start
std::vector< std::vector< types::global_dof_index > > mg_component_start
Definition: mg_transfer_component.h:146
MGConstrainedDoFs
Definition: mg_constrained_dofs.h:45
StandardExceptions::ExcNotImplemented
static ::ExceptionBase & ExcNotImplemented()
MGTransferBlock
Definition: mg_transfer_block.h:201
MGTransferComponentBase::prolongation_matrices
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
Definition: mg_transfer_component.h:162
MGTransferBlock::~MGTransferBlock
virtual ~MGTransferBlock() override
Definition: multigrid.cc:59
MGTransferBlockBase::sizes
std::vector< std::vector< types::global_dof_index > > sizes
Definition: mg_transfer_block.h:136
ComponentMask
Definition: component_mask.h:83
la_parallel_vector.h
MGTransferComponentBase::target_component
std::vector< unsigned int > target_component
Definition: mg_transfer_component.h:126
MGTransferBlockSelect::prolongate
virtual void prolongate(const unsigned int to_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:266
MGTransferBlockSelect::MGTransferBlockSelect
MGTransferBlockSelect()
Definition: multigrid.cc:249
StandardExceptions::ExcIndexRange
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
MGTransferComponentBase::mg_target_component
std::vector< unsigned int > mg_target_component
Definition: mg_transfer_component.h:131
MGTransferBlockSelect::restrict_and_add
virtual void restrict_and_add(const unsigned int from_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:289
MGTransferBlockBase::mg_block_start
std::vector< std::vector< types::global_dof_index > > mg_block_start
Definition: mg_transfer_block.h:146
MGTransferSelect::MGTransferSelect
MGTransferSelect()
Definition: multigrid.cc:198
la_parallel_block_vector.h
MGTransferBlockBase
Definition: mg_transfer_block.h:62
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
BlockVectorBase::n_blocks
unsigned int n_blocks() const
MemoryConsumption::memory_consumption
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Definition: memory_consumption.h:268
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
MGTransferComponentBase::component_mask
ComponentMask component_mask
Definition: mg_transfer_component.h:112
petsc_block_vector.h
MGTransferBlockBase::prolongation_sparsities
std::vector< std::shared_ptr< BlockSparsityPattern > > prolongation_sparsities
Definition: mg_transfer_block.h:154
MGTransferSelect::restrict_and_add
virtual void restrict_and_add(const unsigned int from_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:232
MGTransferBlockSelect
Definition: mg_transfer_block.h:330
StandardExceptions::ExcNotInitialized
static ::ExceptionBase & ExcNotInitialized()
MGTransferComponentBase::memory_consumption
std::size_t memory_consumption() const
Definition: multigrid.cc:149
MGTransferBlock::restrict_and_add
virtual void restrict_and_add(const unsigned int from_level, BlockVector< number > &dst, const BlockVector< number > &src) const override
Definition: multigrid.cc:111
Vector::reinit
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
MGTransferBlockBase::memory_consumption
std::size_t memory_consumption() const
Definition: multigrid.cc:174
AffineConstraints< double >
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
vector.h
MGTransferComponentBase::component_start
std::vector< types::global_dof_index > component_start
Definition: mg_transfer_component.h:141
block_sparse_matrix.h
MGTransferBlockBase::MGTransferBlockBase
MGTransferBlockBase()
Definition: multigrid.cc:39
StandardExceptions::ExcDimensionMismatch
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
MGTransferSelect::prolongate
virtual void prolongate(const unsigned int to_level, Vector< number > &dst, const Vector< number > &src) const override
Definition: multigrid.cc:215
petsc_vector.h
MGTransferComponentBase::sizes
std::vector< std::vector< types::global_dof_index > > sizes
Definition: mg_transfer_component.h:136
MGTransferBlockBase::prolongation_matrices
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
Definition: mg_transfer_block.h:162
MGTransferComponentBase::prolongation_sparsities
std::vector< std::shared_ptr< BlockSparsityPattern > > prolongation_sparsities
Definition: mg_transfer_component.h:154
MGTransferBlockBase::mg_block
std::vector< unsigned int > mg_block
Definition: mg_transfer_block.h:131
MGTransferBlock::initialize
void initialize(const std::vector< number > &factors, VectorMemory< Vector< number >> &memory)
Definition: multigrid.cc:68
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
BlockVectorBase::block
BlockType & block(const unsigned int i)
mg_transfer.h
trilinos_vector.h
Vector< number >
mg_transfer_component.h
trilinos_parallel_block_vector.h
VectorMemory
Definition: vector_memory.h:107
int