Reference documentation for deal.II version GIT 5dcc62ab57 2022-07-04 21:05: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 
69 template <typename Number>
70 class BlockVector : public BlockVectorBase<Vector<Number>>
71 {
72 public:
77 
81  using BlockType = typename BaseClass::BlockType;
82 
87  using real_type = typename BaseClass::real_type;
88  using pointer = typename BaseClass::pointer;
90  using reference = typename BaseClass::reference;
92  using size_type = typename BaseClass::size_type;
93  using iterator = typename BaseClass::iterator;
95 
106  explicit BlockVector(const unsigned int n_blocks = 0,
107  const size_type block_size = 0);
108 
114 
115 
120  BlockVector(BlockVector<Number> && /*v*/) noexcept = default;
121 
128  template <typename OtherNumber>
129  explicit BlockVector(const BlockVector<OtherNumber> &v);
130 
131 #ifdef DEAL_II_WITH_TRILINOS
137 
138 #endif
143  BlockVector(const std::vector<size_type> &block_sizes);
144 
150 
160  template <typename InputIterator>
161  BlockVector(const std::vector<size_type> &block_sizes,
162  const InputIterator first,
163  const InputIterator end);
164 
168  ~BlockVector() override = default;
169 
180  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
506  reinit_range_vector(const Matrix & matrix,
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
515  reinit_domain_vector(const Matrix & matrix,
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
Definition: vector.h:109
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Point< 2 > first
Definition: grid_out.cc:4604
#define DeclException0(Exception0)
Definition: exceptions.h:464
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
typename BlockType::const_reference const_reference
typename BlockType::value_type value_type
#define Assert(cond, exc)
Definition: exceptions.h:1473
#define AssertIsFinite(number)
Definition: exceptions.h:1758
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:506
typename BlockType::reference reference
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:515
typename BlockType::real_type real_type
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
BlockVector(const std::vector< size_type > &block_sizes)
typename BaseClass::const_reference const_reference
Definition: block_vector.h:91
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:90
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:86
typename BaseClass::const_pointer const_pointer
Definition: block_vector.h:89
BlockVector(const BlockVector< Number > &V)
void block_write(std::ostream &out) const
typename BaseClass::pointer pointer
Definition: block_vector.h:88
~BlockVector() override=default
typename BaseClass::BlockType BlockType
Definition: block_vector.h:81
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:93
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:92
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:483
typename BaseClass::const_iterator const_iterator
Definition: block_vector.h:94
void reinit(const BlockVector< Number2 > &V, const bool omit_zeroing_entries=false)
typename BaseClass::real_type real_type
Definition: block_vector.h:87
constexpr int block_size
Definition: cuda_size.h:29
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:2087
@ matrix
Contents is actually a matrix.
static const char V
types::global_dof_index size_type
Definition: cuda_kernels.h:45
std::enable_if< IsBlockVector< VectorType >::value, unsigned int >::type 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)