Reference documentation for deal.II version GIT 194dd8bb02 2022-12-03 08:20: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\}}\)
block_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2021 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_vector_h
17 #define dealii_block_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 
28 
29 #include <cstdio>
30 #include <vector>
31 
33 
34 
35 // Forward declaration
36 #ifndef DOXYGEN
37 # ifdef DEAL_II_WITH_TRILINOS
38 namespace TrilinosWrappers
39 {
40  namespace MPI
41  {
42  class BlockVector;
43  }
44 } // namespace TrilinosWrappers
45 # endif
46 #endif
47 
48 
70 template <typename Number>
71 class BlockVector : public BlockVectorBase<Vector<Number>>
72 {
73 public:
78 
82  using BlockType = typename BaseClass::BlockType;
83 
88  using real_type = typename BaseClass::real_type;
89  using pointer = typename BaseClass::pointer;
91  using reference = typename BaseClass::reference;
93  using size_type = typename BaseClass::size_type;
94  using iterator = typename BaseClass::iterator;
96 
107  explicit BlockVector(const unsigned int n_blocks = 0,
108  const size_type block_size = 0);
109 
115 
116 
121  BlockVector(BlockVector<Number> && /*v*/) noexcept = default;
122 
129  template <typename OtherNumber>
130  explicit BlockVector(const BlockVector<OtherNumber> &v);
131 
132 #ifdef DEAL_II_WITH_TRILINOS
138 
139 #endif
144  BlockVector(const std::vector<size_type> &block_sizes);
145 
151 
161  template <typename InputIterator>
162  BlockVector(const std::vector<size_type> &block_sizes,
163  const InputIterator first,
164  const InputIterator end);
165 
169  ~BlockVector() override = default;
170 
181  void
184 
191  bool
193 
198  BlockVector &
200 
207 
213  operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
214 
219  template <class Number2>
222 
228 
229 #ifdef DEAL_II_WITH_TRILINOS
236 #endif
237 
250  void
251  reinit(const unsigned int n_blocks,
252  const size_type block_size = 0,
253  const bool omit_zeroing_entries = false);
254 
271  void
272  reinit(const std::vector<size_type> &block_sizes,
273  const bool omit_zeroing_entries = false);
274 
284  void
286  const bool omit_zeroing_entries = false);
287 
301  template <typename Number2>
302  void
304  const bool omit_zeroing_entries = false);
305 
310  template <class BlockVector2>
311  void
312  scale(const BlockVector2 &v);
313 
325  void
327 
331  void
332  print(std::ostream & out,
333  const unsigned int precision = 3,
334  const bool scientific = true,
335  const bool across = true) const;
336 
342  void
343  block_write(std::ostream &out) const;
344 
356  void
357  block_read(std::istream &in);
358 
369 };
370 
373 #ifndef DOXYGEN
374 /*----------------------- Inline functions ----------------------------------*/
375 
376 
377 
378 template <typename Number>
379 template <typename InputIterator>
380 BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
381  const InputIterator first,
382  const InputIterator end)
383 {
384  // first set sizes of blocks, but
385  // don't initialize them as we will
386  // copy elements soon
387  (void)end;
388  reinit(block_sizes, true);
389  InputIterator start = first;
390  for (size_type b = 0; b < block_sizes.size(); ++b)
391  {
392  InputIterator end = start;
393  std::advance(end, static_cast<signed int>(block_sizes[b]));
394  std::copy(start, end, this->block(b).begin());
395  start = end;
396  };
397  Assert(start == end, ExcIteratorRangeDoesNotMatchVectorSize());
398 }
399 
400 
401 
402 template <typename Number>
403 inline BlockVector<Number> &
404 BlockVector<Number>::operator=(const value_type s)
405 {
406  AssertIsFinite(s);
407 
408  BaseClass::operator=(s);
409  return *this;
410 }
411 
412 
413 
414 template <typename Number>
415 inline BlockVector<Number> &
417 {
418  reinit(v, true);
419  BaseClass::operator=(v);
420  return *this;
421 }
422 
423 
424 
425 template <typename Number>
426 inline BlockVector<Number> &
428 {
429  BaseClass::operator=(v);
430  return *this;
431 }
432 
433 
434 
435 template <typename Number>
436 template <typename Number2>
437 inline BlockVector<Number> &
439 {
440  reinit(v, true);
441  BaseClass::operator=(v);
442  return *this;
443 }
444 
445 template <typename Number>
446 inline void
448 {
449  for (size_type i = 0; i < this->n_blocks(); ++i)
450  this->components[i].compress(operation);
451 }
452 
453 
454 
455 template <typename Number>
456 inline bool
458 {
459  return false;
460 }
461 
462 
463 
464 template <typename Number>
465 template <class BlockVector2>
466 void
467 BlockVector<Number>::scale(const BlockVector2 &v)
468 {
469  BaseClass::scale(v);
470 }
471 
472 #endif // DOXYGEN
473 
474 
482 template <typename Number>
483 inline void
485 {
486  u.swap(v);
487 }
488 
489 
490 namespace internal
491 {
492  namespace LinearOperatorImplementation
493  {
494  template <typename>
495  class ReinitHelper;
496 
501  template <typename number>
502  class ReinitHelper<BlockVector<number>>
503  {
504  public:
505  template <typename Matrix>
506  static void
507  reinit_range_vector(const Matrix & matrix,
509  bool omit_zeroing_entries)
510  {
511  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
512  }
513 
514  template <typename Matrix>
515  static void
516  reinit_domain_vector(const Matrix & matrix,
518  bool omit_zeroing_entries)
519  {
520  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
521  }
522  };
523 
524  } // namespace LinearOperatorImplementation
525 } /* namespace internal */
526 
527 
531 template <typename Number>
532 struct is_serial_vector<BlockVector<Number>> : std::true_type
533 {};
534 
536 
537 #endif
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
typename BlockType::const_reference const_reference
typename BlockType::value_type value_type
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
typename BlockType::reference reference
typename BlockType::real_type real_type
BlockVector(const std::vector< size_type > &block_sizes)
typename BaseClass::const_reference const_reference
Definition: block_vector.h:92
void reinit(const BlockIndices &block_indices, const bool omit_zeroing_entries=false)
void swap(BlockVector< Number > &v)
typename BaseClass::reference reference
Definition: block_vector.h:91
BlockVector< Number > & operator=(const TrilinosWrappers::MPI::BlockVector &V)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
bool has_ghost_elements() const
BlockVector< Number > & operator=(const Vector< Number > &V)
BlockVector(const TrilinosWrappers::MPI::BlockVector &v)
BlockVector(const BlockIndices &block_indices)
typename BaseClass::value_type value_type
Definition: block_vector.h:87
typename BaseClass::const_pointer const_pointer
Definition: block_vector.h:90
BlockVector(const BlockVector< Number > &V)
void block_write(std::ostream &out) const
typename BaseClass::pointer pointer
Definition: block_vector.h:89
~BlockVector() override=default
typename BaseClass::BlockType BlockType
Definition: block_vector.h:82
BlockVector(const unsigned int n_blocks=0, const size_type block_size=0)
void scale(const BlockVector2 &v)
BlockVector(BlockVector< Number > &&) noexcept=default
void reinit(const std::vector< size_type > &block_sizes, const bool omit_zeroing_entries=false)
typename BaseClass::iterator iterator
Definition: block_vector.h:94
void block_read(std::istream &in)
BlockVector< Number > & operator=(BlockVector< Number > &&)=default
BlockVector & operator=(const value_type s)
typename BaseClass::size_type size_type
Definition: block_vector.h:93
BlockVector< Number > & operator=(const BlockVector< Number > &v)
BlockVector< Number > & operator=(const BlockVector< Number2 > &V)
BlockVector(const std::vector< size_type > &block_sizes, const InputIterator first, const InputIterator end)
void compress(::VectorOperation::values operation=::VectorOperation::unknown)
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
void swap(BlockVector< Number > &u, BlockVector< Number > &v)
Definition: block_vector.h:484
typename BaseClass::const_iterator const_iterator
Definition: block_vector.h:95
void reinit(const BlockVector< Number2 > &V, const bool omit_zeroing_entries=false)
typename BaseClass::real_type real_type
Definition: block_vector.h:88
Definition: vector.h:109
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:507
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:516
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
Point< 2 > first
Definition: grid_out.cc:4605
#define DeclException0(Exception0)
Definition: exceptions.h:464
#define Assert(cond, exc)
Definition: exceptions.h:1501
#define AssertIsFinite(number)
Definition: exceptions.h:1786
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
constexpr int block_size
Definition: cuda_size.h:29
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:2132
@ matrix
Contents is actually a matrix.
static const char V
types::global_dof_index size_type
Definition: cuda_kernels.h:45
std::enable_if_t< IsBlockVector< VectorType >::value, unsigned int > n_blocks(const VectorType &vector)
Definition: operators.h:50
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(VectorType &V)
std::string compress(const std::string &input)
Definition: utilities.cc:392
void copy(const T *begin, const T *end, U *dest)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
void advance(std::tuple< I1, I2 > &t, const unsigned int n)