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\}}\)
block_sparse_matrix_ez.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 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 #ifndef dealii_block_sparse_matrix_ez_h
17 #define dealii_block_sparse_matrix_ez_h
18 
19 
20 // TODO: Derive BlockSparseMatrixEZ from BlockMatrixBase, like all the
21 // other block matrices as well; this would allow to instantiate a few
22 // functions with this template argument as well (in particular
23 // AffineConstraints::distribute_local_to_global)
24 
25 #include <deal.II/base/config.h>
26 
30 #include <deal.II/base/table.h>
31 
34 
36 
37 // Forward declaration
38 #ifndef DOXYGEN
39 template <typename Number>
40 class BlockVector;
41 #endif
42 
60 template <typename Number>
61 class BlockSparseMatrixEZ : public Subscriptor
62 {
63 public:
68 
72  BlockSparseMatrixEZ() = default;
73 
78  BlockSparseMatrixEZ(const unsigned int block_rows,
79  const unsigned int block_cols);
80 
87 
94 
104  operator=(const double d);
105 
106 
110  void
111  clear();
112 
120  void
121  reinit(const unsigned int n_block_rows, const unsigned int n_block_cols);
128  void
129  collect_sizes();
130 
135  block(const unsigned int row, const unsigned int column);
136 
137 
142  const SparseMatrixEZ<Number> &
143  block(const unsigned int row, const unsigned int column) const;
144 
148  unsigned int
149  n_block_rows() const;
150 
154  unsigned int
155  n_block_cols() const;
156 
163  bool
164  empty() const;
165 
172  size_type
173  m() const;
174 
181  size_type
182  n() const;
183 
189  void
190  set(const size_type i, const size_type j, const Number value);
191 
197  void
198  add(const size_type i, const size_type j, const Number value);
199 
200 
205  template <typename somenumber>
206  void
207  vmult(BlockVector<somenumber> &dst, const BlockVector<somenumber> &src) const;
208 
214  template <typename somenumber>
215  void
217  const BlockVector<somenumber> &src) const;
218 
223  template <typename somenumber>
224  void
226  const BlockVector<somenumber> &src) const;
227 
233  template <typename somenumber>
234  void
236  const BlockVector<somenumber> &src) const;
237 
238 
244  template <class StreamType>
245  void
246  print_statistics(StreamType &s, bool full = false);
247 
248 private:
254 
260 
265 };
266 
268 /*----------------------------------------------------------------------*/
269 
270 
271 template <typename Number>
272 inline unsigned int
274 {
275  return row_indices.size();
276 }
277 
278 
279 
280 template <typename Number>
281 inline unsigned int
283 {
284  return column_indices.size();
285 }
286 
287 
288 
289 template <typename Number>
290 inline SparseMatrixEZ<Number> &
291 BlockSparseMatrixEZ<Number>::block(const unsigned int row,
292  const unsigned int column)
293 {
294  AssertIndexRange(row, n_block_rows());
295  AssertIndexRange(column, n_block_cols());
296 
297  return blocks[row][column];
298 }
299 
300 
301 
302 template <typename Number>
303 inline const SparseMatrixEZ<Number> &
304 BlockSparseMatrixEZ<Number>::block(const unsigned int row,
305  const unsigned int column) const
306 {
307  AssertIndexRange(row, n_block_rows());
308  AssertIndexRange(column, n_block_cols());
309 
310  return blocks[row][column];
311 }
312 
313 
314 
315 template <typename Number>
318 {
319  return row_indices.total_size();
320 }
321 
322 
323 
324 template <typename Number>
327 {
328  return column_indices.total_size();
329 }
330 
331 
332 
333 template <typename Number>
334 inline void
336  const size_type j,
337  const Number value)
338 {
340 
341  const std::pair<size_type, size_type> row_index =
342  row_indices.global_to_local(i),
343  col_index =
344  column_indices.global_to_local(j);
345  block(row_index.first, col_index.first)
346  .set(row_index.second, col_index.second, value);
347 }
348 
349 
350 
351 template <typename Number>
352 inline void
354  const size_type j,
355  const Number value)
356 {
358 
359  const std::pair<unsigned int, size_type> row_index =
360  row_indices.global_to_local(i),
361  col_index =
362  column_indices.global_to_local(j);
363  block(row_index.first, col_index.first)
364  .add(row_index.second, col_index.second, value);
365 }
366 
367 
368 template <typename Number>
369 template <typename somenumber>
370 void
372  const BlockVector<somenumber> &src) const
373 {
374  Assert(dst.n_blocks() == n_block_rows(),
375  ExcDimensionMismatch(dst.n_blocks(), n_block_rows()));
376  Assert(src.n_blocks() == n_block_cols(),
377  ExcDimensionMismatch(src.n_blocks(), n_block_cols()));
378 
379  dst = 0.;
380 
381  for (unsigned int row = 0; row < n_block_rows(); ++row)
382  for (unsigned int col = 0; col < n_block_cols(); ++col)
383  block(row, col).vmult_add(dst.block(row), src.block(col));
384 }
385 
386 
387 
388 template <typename Number>
389 template <typename somenumber>
390 void
392  const BlockVector<somenumber> &src) const
393 {
394  Assert(dst.n_blocks() == n_block_rows(),
395  ExcDimensionMismatch(dst.n_blocks(), n_block_rows()));
396  Assert(src.n_blocks() == n_block_cols(),
397  ExcDimensionMismatch(src.n_blocks(), n_block_cols()));
398 
399  for (unsigned int row = 0; row < n_block_rows(); ++row)
400  for (unsigned int col = 0; col < n_block_cols(); ++col)
401  block(row, col).vmult_add(dst.block(row), src.block(col));
402 }
403 
404 
405 
406 template <typename Number>
407 template <typename somenumber>
408 void
410  const BlockVector<somenumber> &src) const
411 {
412  Assert(dst.n_blocks() == n_block_cols(),
413  ExcDimensionMismatch(dst.n_blocks(), n_block_cols()));
414  Assert(src.n_blocks() == n_block_rows(),
415  ExcDimensionMismatch(src.n_blocks(), n_block_rows()));
416 
417  dst = 0.;
418 
419  for (unsigned int row = 0; row < n_block_rows(); ++row)
420  for (unsigned int col = 0; col < n_block_cols(); ++col)
421  block(row, col).Tvmult_add(dst.block(col), src.block(row));
422 }
423 
424 
425 
426 template <typename Number>
427 template <typename somenumber>
428 void
431  const BlockVector<somenumber> &src) const
432 {
433  Assert(dst.n_blocks() == n_block_cols(),
434  ExcDimensionMismatch(dst.n_blocks(), n_block_cols()));
435  Assert(src.n_blocks() == n_block_rows(),
436  ExcDimensionMismatch(src.n_blocks(), n_block_rows()));
437 
438  for (unsigned int row = 0; row < n_block_rows(); ++row)
439  for (unsigned int col = 0; col < n_block_cols(); ++col)
440  block(row, col).Tvmult_add(dst.block(col), src.block(row));
441 }
442 
443 
444 template <typename number>
445 template <class StreamType>
446 inline void
448 {
449  size_type used_total = 0;
450  size_type allocated_total = 0;
451  size_type reserved_total = 0;
452  std::vector<size_type> used_by_line_total;
453 
454  size_type used;
455  size_type allocated;
456  size_type reserved;
457  std::vector<size_type> used_by_line;
458 
459  for (size_type i = 0; i < n_block_rows(); ++i)
460  for (size_type j = 0; j < n_block_cols(); ++j)
461  {
462  used_by_line.clear();
463  out << "block:\t" << i << '\t' << j << std::endl;
464  block(i, j).compute_statistics(
465  used, allocated, reserved, used_by_line, full);
466 
467  out << "used:" << used << std::endl
468  << "allocated:" << allocated << std::endl
469  << "reserved:" << reserved << std::endl;
470 
471  used_total += used;
472  allocated_total += allocated;
473  reserved_total += reserved;
474 
475  if (full)
476  {
477  used_by_line_total.resize(used_by_line.size());
478  for (size_type i = 0; i < used_by_line.size(); ++i)
479  if (used_by_line[i] != 0)
480  {
481  out << "row-entries\t" << i << "\trows\t" << used_by_line[i]
482  << std::endl;
483  used_by_line_total[i] += used_by_line[i];
484  }
485  }
486  }
487  out << "Total" << std::endl
488  << "used:" << used_total << std::endl
489  << "allocated:" << allocated_total << std::endl
490  << "reserved:" << reserved_total << std::endl;
491  for (size_type i = 0; i < used_by_line_total.size(); ++i)
492  if (used_by_line_total[i] != 0)
493  {
494  out << "row-entries\t" << i << "\trows\t" << used_by_line_total[i]
495  << std::endl;
496  }
497 }
498 
499 
501 
502 #endif // dealii_block_sparse_matrix_ez_h
BlockSparseMatrixEZ::print_statistics
void print_statistics(StreamType &s, bool full=false)
Definition: block_sparse_matrix_ez.h:447
BlockSparseMatrixEZ::blocks
Table< 2, SparseMatrixEZ< Number > > blocks
Definition: block_sparse_matrix_ez.h:264
BlockSparseMatrixEZ::Tvmult
void Tvmult(BlockVector< somenumber > &dst, const BlockVector< somenumber > &src) const
Definition: block_sparse_matrix_ez.h:409
SparseMatrixEZ< Number >
BlockVector
Definition: block_vector.h:71
BlockSparseMatrixEZ::add
void add(const size_type i, const size_type j, const Number value)
Definition: block_sparse_matrix_ez.h:353
BlockSparseMatrixEZ::n
size_type n() const
Definition: block_sparse_matrix_ez.h:326
BlockSparseMatrixEZ::collect_sizes
void collect_sizes()
BlockSparseMatrixEZ::block
SparseMatrixEZ< Number > & block(const unsigned int row, const unsigned int column)
Definition: block_sparse_matrix_ez.h:291
BlockSparseMatrixEZ::n_block_rows
unsigned int n_block_rows() const
Definition: block_sparse_matrix_ez.h:273
AssertIndexRange
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
block_indices.h
BlockSparseMatrixEZ::BlockSparseMatrixEZ
BlockSparseMatrixEZ()=default
BlockSparseMatrixEZ::set
void set(const size_type i, const size_type j, const Number value)
Definition: block_sparse_matrix_ez.h:335
Physics::Elasticity::Kinematics::d
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
Table
Definition: table.h:699
Subscriptor
Definition: subscriptor.h:62
BlockSparseMatrixEZ::vmult
void vmult(BlockVector< somenumber > &dst, const BlockVector< somenumber > &src) const
Definition: block_sparse_matrix_ez.h:371
BlockSparseMatrixEZ::empty
bool empty() const
BlockSparseMatrixEZ::column_indices
BlockIndices column_indices
Definition: block_sparse_matrix_ez.h:259
BlockSparseMatrixEZ::size_type
types::global_dof_index size_type
Definition: block_sparse_matrix_ez.h:67
AssertIsFinite
#define AssertIsFinite(number)
Definition: exceptions.h:1681
types::global_dof_index
unsigned int global_dof_index
Definition: types.h:76
subscriptor.h
BlockSparseMatrixEZ::reinit
void reinit(const unsigned int n_block_rows, const unsigned int n_block_cols)
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
BlockVectorBase< Vector< Number > >::n_blocks
unsigned int n_blocks() const
sparse_matrix_ez.h
BlockSparseMatrixEZ::n_block_cols
unsigned int n_block_cols() const
Definition: block_sparse_matrix_ez.h:282
BlockSparseMatrixEZ::m
size_type m() const
Definition: block_sparse_matrix_ez.h:317
smartpointer.h
BlockSparseMatrixEZ::row_indices
BlockIndices row_indices
Definition: block_sparse_matrix_ez.h:253
exceptions.h
BlockSparseMatrixEZ::clear
void clear()
unsigned int
value
static const bool value
Definition: dof_tools_constraints.cc:433
BlockSparseMatrixEZ::vmult_add
void vmult_add(BlockVector< somenumber > &dst, const BlockVector< somenumber > &src) const
Definition: block_sparse_matrix_ez.h:391
BlockSparseMatrixEZ::Tvmult_add
void Tvmult_add(BlockVector< somenumber > &dst, const BlockVector< somenumber > &src) const
Definition: block_sparse_matrix_ez.h:429
BlockSparseMatrixEZ
Definition: affine_constraints.h:1907
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
StandardExceptions::ExcDimensionMismatch
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
config.h
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
BlockVectorBase< Vector< Number > >::block
BlockType & block(const unsigned int i)
table.h
BlockSparseMatrixEZ::operator=
BlockSparseMatrixEZ & operator=(const BlockSparseMatrixEZ< Number > &)
BlockIndices
Definition: block_indices.h:60