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_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 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_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 
135  template <typename OtherNumber>
136  explicit BlockVector(const BlockVector<OtherNumber> &v);
137 
138 #ifdef DEAL_II_WITH_TRILINOS
139 
144 
145 #endif
146 
150  BlockVector(const std::vector<size_type> &block_sizes);
151 
157 
167  template <typename InputIterator>
168  BlockVector(const std::vector<size_type> &block_sizes,
169  const InputIterator first,
170  const InputIterator end);
171 
175  ~BlockVector() override = default;
176 
187  void
188  compress(::VectorOperation::values operation =
190 
197  bool
198  has_ghost_elements() const;
199 
204  BlockVector &
205  operator=(const value_type s);
206 
212  operator=(const BlockVector<Number> &v);
213 
219  operator=(BlockVector<Number> && /*v*/) = default; // NOLINT
220 
225  template <class Number2>
228 
233  operator=(const Vector<Number> &V);
234 
235 #ifdef DEAL_II_WITH_TRILINOS
236 
242 #endif
243 
256  void
257  reinit(const unsigned int n_blocks,
258  const size_type block_size = 0,
259  const bool omit_zeroing_entries = false);
260 
277  void
278  reinit(const std::vector<size_type> &block_sizes,
279  const bool omit_zeroing_entries = false);
280 
290  void
292  const bool omit_zeroing_entries = false);
293 
307  template <typename Number2>
308  void
310  const bool omit_zeroing_entries = false);
311 
316  template <class BlockVector2>
317  void
318  scale(const BlockVector2 &v);
319 
331  void
333 
337  void
338  print(std::ostream & out,
339  const unsigned int precision = 3,
340  const bool scientific = true,
341  const bool across = true) const;
342 
348  void
349  block_write(std::ostream &out) const;
350 
362  void
363  block_read(std::istream &in);
364 
375 };
376 
379 #ifndef DOXYGEN
380 /*----------------------- Inline functions ----------------------------------*/
381 
382 
383 
384 template <typename Number>
385 template <typename InputIterator>
386 BlockVector<Number>::BlockVector(const std::vector<size_type> &block_sizes,
387  const InputIterator first,
388  const InputIterator end)
389 {
390  // first set sizes of blocks, but
391  // don't initialize them as we will
392  // copy elements soon
393  (void)end;
394  reinit(block_sizes, true);
395  InputIterator start = first;
396  for (size_type b = 0; b < block_sizes.size(); ++b)
397  {
398  InputIterator end = start;
399  std::advance(end, static_cast<signed int>(block_sizes[b]));
400  std::copy(start, end, this->block(b).begin());
401  start = end;
402  };
403  Assert(start == end, ExcIteratorRangeDoesNotMatchVectorSize());
404 }
405 
406 
407 
408 template <typename Number>
409 inline BlockVector<Number> &
411 {
412  AssertIsFinite(s);
413 
414  BaseClass::operator=(s);
415  return *this;
416 }
417 
418 
419 
420 template <typename Number>
421 inline BlockVector<Number> &
423 {
424  reinit(v, true);
425  BaseClass::operator=(v);
426  return *this;
427 }
428 
429 
430 
431 template <typename Number>
432 inline BlockVector<Number> &
433 BlockVector<Number>::operator=(const Vector<Number> &v)
434 {
435  BaseClass::operator=(v);
436  return *this;
437 }
438 
439 
440 
441 template <typename Number>
442 template <typename Number2>
443 inline BlockVector<Number> &
445 {
446  reinit(v, true);
447  BaseClass::operator=(v);
448  return *this;
449 }
450 
451 template <typename Number>
452 inline void
454 {
455  for (size_type i = 0; i < this->n_blocks(); ++i)
456  this->components[i].compress(operation);
457 }
458 
459 
460 
461 template <typename Number>
462 inline bool
464 {
465  return false;
466 }
467 
468 
469 
470 template <typename Number>
471 template <class BlockVector2>
472 void
473 BlockVector<Number>::scale(const BlockVector2 &v)
474 {
475  BaseClass::scale(v);
476 }
477 
478 #endif // DOXYGEN
479 
480 
489 template <typename Number>
490 inline void
492 {
493  u.swap(v);
494 }
495 
496 
497 namespace internal
498 {
499  namespace LinearOperatorImplementation
500  {
501  template <typename>
503 
508  template <typename number>
509  class ReinitHelper<BlockVector<number>>
510  {
511  public:
512  template <typename Matrix>
513  static void
514  reinit_range_vector(const Matrix & matrix,
516  bool omit_zeroing_entries)
517  {
518  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
519  }
520 
521  template <typename Matrix>
522  static void
523  reinit_domain_vector(const Matrix & matrix,
525  bool omit_zeroing_entries)
526  {
527  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
528  }
529  };
530 
531  } // namespace LinearOperatorImplementation
532 } /* namespace internal */
533 
534 
540 template <typename Number>
541 struct is_serial_vector<BlockVector<Number>> : std::true_type
542 {};
543 
545 
546 #endif
internal::LinearOperatorImplementation::ReinitHelper< BlockVector< number > >::reinit_domain_vector
static void reinit_domain_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:523
BlockVector::operator=
BlockVector & operator=(const value_type s)
BlockVectorBase< Vector< Number > >::value_type
typename BlockType::value_type value_type
Definition: block_vector_base.h:468
CUDAWrappers::block_size
constexpr int block_size
Definition: cuda_size.h:29
BlockVector< number >::BlockType
typename BaseClass::BlockType BlockType
Definition: block_vector.h:82
BlockVector::ExcIteratorRangeDoesNotMatchVectorSize
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
BlockVector
Definition: block_vector.h:71
block_vector_base.h
BlockVector::scale
void scale(const BlockVector2 &v)
BlockVector< number >::const_pointer
typename BaseClass::const_pointer const_pointer
Definition: block_vector.h:90
LAPACKSupport::V
static const char V
Definition: lapack_support.h:175
TrilinosWrappers
Definition: types.h:161
block_indices.h
TrilinosWrappers::MPI::BlockVector
Definition: trilinos_parallel_block_vector.h:75
BlockVector< number >::real_type
typename BaseClass::real_type real_type
Definition: block_vector.h:88
BlockVectorBase< Vector< Number > >::reference
typename BlockType::reference reference
Definition: block_vector_base.h:475
BlockVectorBase< Vector< Number > >::const_reference
typename BlockType::const_reference const_reference
Definition: block_vector_base.h:476
MatrixFreeOperators::BlockHelper::n_blocks
std::enable_if< IsBlockVector< VectorType >::value, unsigned int >::type n_blocks(const VectorType &vector)
Definition: operators.h:49
BlockVector::has_ghost_elements
bool has_ghost_elements() const
BlockVector::block_read
void block_read(std::istream &in)
is_serial_vector
Definition: vector_type_traits.h:49
AssertIsFinite
#define AssertIsFinite(number)
Definition: exceptions.h:1681
vector_operation.h
TrilinosWrappers::internal::begin
VectorType::value_type * begin(VectorType &V)
Definition: trilinos_sparse_matrix.cc:51
internal::reinit
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:621
vector_type_traits.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
BlockVectorBase< Vector< Number > >::n_blocks
unsigned int n_blocks() const
BlockVectorBase
Definition: block_vector_base.h:450
GridTools::scale
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:837
BlockVector::swap
void swap(BlockVector< Number > &v)
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
BlockVector< number >::iterator
typename BaseClass::iterator iterator
Definition: block_vector.h:94
LAPACKSupport::matrix
@ matrix
Contents is actually a matrix.
Definition: lapack_support.h:60
TrilinosWrappers::internal::end
VectorType::value_type * end(VectorType &V)
Definition: trilinos_sparse_matrix.cc:65
BlockIndices::swap
void swap(BlockIndices &u, BlockIndices &v)
Definition: block_indices.h:475
BlockVectorBase< Vector< Number > >::BlockType
Vector< Number > BlockType
Definition: block_vector_base.h:456
VectorOperation::values
values
Definition: vector_operation.h:40
BlockVectorBase< Vector< Number > >::const_pointer
const value_type * const_pointer
Definition: block_vector_base.h:470
BlockVectorBase< Vector< Number > >::size_type
types::global_dof_index size_type
Definition: block_vector_base.h:477
VectorOperation::unknown
@ unknown
Definition: vector_operation.h:45
BlockVectorBase< Vector< Number > >::pointer
value_type * pointer
Definition: block_vector_base.h:469
BlockVector::BlockVector
BlockVector(const unsigned int n_blocks=0, const size_type block_size=0)
exceptions.h
BlockVectorBase< Vector< Number > >::real_type
typename BlockType::real_type real_type
Definition: block_vector_base.h:488
BlockVector::block_write
void block_write(std::ostream &out) const
BlockVectorBase< Vector< Number > >::const_iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
Definition: block_vector_base.h:474
BlockVectorBase< Vector< Number > >::block_indices
BlockIndices block_indices
Definition: block_vector_base.h:962
advance
void advance(std::tuple< I1, I2 > &t, const unsigned int n)
Definition: synchronous_iterator.h:146
BlockVector::reinit
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
LinearAlgebra::CUDAWrappers::kernel::size_type
types::global_dof_index size_type
Definition: cuda_kernels.h:45
BlockVectorBase< Vector< Number > >::iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
Definition: block_vector_base.h:472
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
BlockVector< number >::size_type
typename BaseClass::size_type size_type
Definition: block_vector.h:93
BlockVector< number >::reference
typename BaseClass::reference reference
Definition: block_vector.h:91
internal::LinearOperatorImplementation::ReinitHelper< BlockVector< number > >::reinit_range_vector
static void reinit_range_vector(const Matrix &matrix, BlockVector< number > &v, bool omit_zeroing_entries)
Definition: block_vector.h:514
DeclException0
#define DeclException0(Exception0)
Definition: exceptions.h:473
BlockVector< number >::const_reference
typename BaseClass::const_reference const_reference
Definition: block_vector.h:92
BlockVector< number >::const_iterator
typename BaseClass::const_iterator const_iterator
Definition: block_vector.h:95
BlockVector::print
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
config.h
BlockVectorBase< Vector< Number > >::end
iterator end()
internal
Definition: aligned_vector.h:369
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
value_type
first
Point< 2 > first
Definition: grid_out.cc:4352
BlockVector::compress
void compress(::VectorOperation::values operation=::VectorOperation::unknown)
Utilities::compress
std::string compress(const std::string &input)
Definition: utilities.cc:392
BlockVector< number >::pointer
typename BaseClass::pointer pointer
Definition: block_vector.h:89
internal::LinearOperatorImplementation::ReinitHelper
Definition: block_vector.h:502
BlockVector::~BlockVector
~BlockVector() override=default
internal::VectorOperations::copy
void copy(const T *begin, const T *end, U *dest)
Definition: vector_operations_internal.h:67
BlockIndices
Definition: block_indices.h:60
BlockVector< number >::value_type
typename BaseClass::value_type value_type
Definition: block_vector.h:87