Reference documentation for deal.II version GIT e22cb6a53e 2023-09-21 14:00: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 - 2023 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
183 
190  bool
192 
197  BlockVector &
199 
206 
212  operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
213 
218  template <class Number2>
221 
227 
228 #ifdef DEAL_II_WITH_TRILINOS
235 #endif
236 
249  void
250  reinit(const unsigned int n_blocks,
251  const size_type block_size = 0,
252  const bool omit_zeroing_entries = false);
253 
270  void
271  reinit(const std::vector<size_type> &block_sizes,
272  const bool omit_zeroing_entries = false);
273 
283  void
285  const bool omit_zeroing_entries = false);
286 
300  template <typename Number2>
301  void
303  const bool omit_zeroing_entries = false);
304 
309  template <class BlockVector2>
310  void
311  scale(const BlockVector2 &v);
312 
324  void
326 
330  void
331  print(std::ostream &out,
332  const unsigned int precision = 3,
333  const bool scientific = true,
334  const bool across = true) const;
335 
341  void
342  block_write(std::ostream &out) const;
343 
355  void
356  block_read(std::istream &in);
357 
368 };
369 
372 #ifndef DOXYGEN
373 /*----------------------- Inline functions ----------------------------------*/
374 
375 
376 
377 template <typename Number>
378 template <typename InputIterator>
379 BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
380  const InputIterator first,
381  const InputIterator end)
382 {
383  // first set sizes of blocks, but
384  // don't initialize them as we will
385  // copy elements soon
386  (void)end;
387  reinit(block_sizes, true);
388  InputIterator start = first;
389  for (size_type b = 0; b < block_sizes.size(); ++b)
390  {
391  InputIterator end = start;
392  std::advance(end, static_cast<signed int>(block_sizes[b]));
393  std::copy(start, end, this->block(b).begin());
394  start = end;
395  };
396  Assert(start == end, ExcIteratorRangeDoesNotMatchVectorSize());
397 }
398 
399 
400 
401 template <typename Number>
402 inline BlockVector<Number> &
403 BlockVector<Number>::operator=(const value_type s)
404 {
405  AssertIsFinite(s);
406 
407  BaseClass::operator=(s);
408  return *this;
409 }
410 
411 
412 
413 template <typename Number>
414 inline BlockVector<Number> &
416 {
417  reinit(v, true);
418  BaseClass::operator=(v);
419  return *this;
420 }
421 
422 
423 
424 template <typename Number>
425 inline BlockVector<Number> &
427 {
428  BaseClass::operator=(v);
429  return *this;
430 }
431 
432 
433 
434 template <typename Number>
435 template <typename Number2>
436 inline BlockVector<Number> &
438 {
439  reinit(v, true);
440  BaseClass::operator=(v);
441  return *this;
442 }
443 
444 template <typename Number>
445 inline void
447 {
448  for (size_type i = 0; i < this->n_blocks(); ++i)
449  this->components[i].compress(operation);
450 }
451 
452 
453 
454 template <typename Number>
455 inline bool
457 {
458  return false;
459 }
460 
461 
462 
463 template <typename Number>
464 template <class BlockVector2>
465 void
466 BlockVector<Number>::scale(const BlockVector2 &v)
467 {
468  BaseClass::scale(v);
469 }
470 
471 #endif // DOXYGEN
472 
473 
481 template <typename Number>
482 inline void
484 {
485  u.swap(v);
486 }
487 
488 
489 namespace internal
490 {
491  namespace LinearOperatorImplementation
492  {
493  template <typename>
494  class ReinitHelper;
495 
500  template <typename number>
501  class ReinitHelper<BlockVector<number>>
502  {
503  public:
504  template <typename Matrix>
505  static void
508  bool omit_zeroing_entries)
509  {
510  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
511  }
512 
513  template <typename Matrix>
514  static void
517  bool omit_zeroing_entries)
518  {
519  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
520  }
521  };
522 
523  } // namespace LinearOperatorImplementation
524 } /* namespace internal */
525 
526 
530 template <typename Number>
531 struct is_serial_vector<BlockVector<Number>> : std::true_type
532 {};
533 
535 
536 #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
void compress(VectorOperation::values operation=VectorOperation::unknown)
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 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:483
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:110
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:506
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:515
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
Point< 2 > first
Definition: grid_out.cc:4614
#define DeclException0(Exception0)
Definition: exceptions.h:467
#define Assert(cond, exc)
Definition: exceptions.h:1616
#define AssertIsFinite(number)
Definition: exceptions.h:1884
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:2198
@ 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:390
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)