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\}}\)
la_parallel_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_la_parallel_block_vector_h
17 #define dealii_la_parallel_block_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 
29 
30 #include <cstdio>
31 #include <vector>
32 
34 
35 
36 // Forward declarations
37 #ifndef DOXYGEN
38 # ifdef DEAL_II_WITH_PETSC
39 namespace PETScWrappers
40 {
41  namespace MPI
42  {
43  class BlockVector;
44  }
45 } // namespace PETScWrappers
46 # endif
47 
48 # ifdef DEAL_II_WITH_TRILINOS
49 namespace TrilinosWrappers
50 {
51  namespace MPI
52  {
53  class BlockVector;
54  }
55 } // namespace TrilinosWrappers
56 # endif
57 #endif
58 
59 namespace LinearAlgebra
60 {
61  namespace distributed
62  {
84  template <typename Number>
85  class BlockVector : public BlockVectorBase<Vector<Number>>,
86  public VectorSpaceVector<Number>
87  {
88  public:
101  static constexpr unsigned int communication_block_size = 20;
102 
107 
111  using BlockType = typename BaseClass::BlockType;
112 
117  using real_type = typename BaseClass::real_type;
118  using pointer = typename BaseClass::pointer;
120  using reference = typename BaseClass::reference;
122  using size_type = typename BaseClass::size_type;
123  using iterator = typename BaseClass::iterator;
125 
130 
141  explicit BlockVector(const size_type num_blocks = 0,
142  const size_type block_size = 0);
143 
149 
162  template <typename OtherNumber>
163  explicit BlockVector(const BlockVector<OtherNumber> &v);
164 
169  BlockVector(const std::vector<size_type> &block_sizes);
170 
175  BlockVector(const std::vector<IndexSet> &local_ranges,
176  const std::vector<IndexSet> &ghost_indices,
177  const MPI_Comm communicator);
178 
182  BlockVector(const std::vector<IndexSet> &local_ranges,
183  const MPI_Comm communicator);
184 
193  virtual ~BlockVector() override = default;
194 
199  virtual BlockVector &
200  operator=(const value_type s) override;
201 
206  BlockVector &
207  operator=(const BlockVector &V);
208 
213  template <class Number2>
214  BlockVector &
216 
220  BlockVector &
221  operator=(const Vector<Number> &V);
222 
223 #ifdef DEAL_II_WITH_PETSC
224 
232  operator=(const PETScWrappers::MPI::BlockVector &petsc_vec);
233 #endif
234 
235 #ifdef DEAL_II_WITH_TRILINOS
236 
245  operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
246 #endif
247 
261  void
262  reinit(const size_type num_blocks,
263  const size_type block_size = 0,
264  const bool omit_zeroing_entries = false);
265 
285  void
286  reinit(const std::vector<size_type> &N,
287  const bool omit_zeroing_entries = false);
288 
303  template <typename Number2>
304  void
306  const bool omit_zeroing_entries = false);
307 
332  virtual void
333  compress(::VectorOperation::values operation) override;
334 
343  void
344  update_ghost_values() const;
345 
354  void
355  zero_out_ghosts() const;
356 
360  bool
361  has_ghost_elements() const;
362 
367  template <typename OtherNumber>
368  void
369  add(const std::vector<size_type> & indices,
370  const ::Vector<OtherNumber> &values);
371 
376  void
377  sadd(const Number s, const BlockVector<Number> &V);
378 
384  virtual bool
385  all_zero() const override;
386 
390  virtual Number
391  mean_value() const override;
392 
397  real_type
398  lp_norm(const real_type p) const;
399 
417  void
420 
425 
430  virtual void
432  const bool omit_zeroing_entries = false) override;
433 
437  virtual BlockVector<Number> &
438  operator*=(const Number factor) override;
439 
443  virtual BlockVector<Number> &
444  operator/=(const Number factor) override;
445 
449  virtual BlockVector<Number> &
450  operator+=(const VectorSpaceVector<Number> &V) override;
451 
455  virtual BlockVector<Number> &
456  operator-=(const VectorSpaceVector<Number> &V) override;
457 
466  virtual void
467  import(
469  VectorOperation::values operation,
470  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
471  std::shared_ptr<const CommunicationPatternBase>()) override;
472 
476  virtual Number
477  operator*(const VectorSpaceVector<Number> &V) const override;
478 
495  template <typename FullMatrixType>
496  void
497  multivector_inner_product(FullMatrixType & matrix,
498  const BlockVector<Number> &V,
499  const bool symmetric = false) const;
500 
517  template <typename FullMatrixType>
518  Number
519  multivector_inner_product_with_metric(const FullMatrixType & matrix,
520  const BlockVector<Number> &V,
521  const bool symmetric = false) const;
522 
532  template <typename FullMatrixType>
533  void
535  const FullMatrixType &matrix,
536  const Number s = Number(0.),
537  const Number b = Number(1.)) const;
538 
542  virtual void
543  add(const Number a) override;
544 
548  virtual void
549  add(const Number a, const VectorSpaceVector<Number> &V) override;
550 
554  virtual void
555  add(const Number a,
557  const Number b,
558  const VectorSpaceVector<Number> &W) override;
559 
564  virtual void
565  add(const std::vector<size_type> &indices,
566  const std::vector<Number> & values);
567 
572  virtual void
573  sadd(const Number s,
574  const Number a,
575  const VectorSpaceVector<Number> &V) override;
576 
582  virtual void
583  scale(const VectorSpaceVector<Number> &scaling_factors) override;
584 
588  virtual void
589  equ(const Number a, const VectorSpaceVector<Number> &V) override;
590 
595  virtual real_type
596  l1_norm() const override;
597 
602  virtual real_type
603  l2_norm() const override;
604 
608  real_type
609  norm_sqr() const;
610 
615  virtual real_type
616  linfty_norm() const override;
617 
638  virtual Number
639  add_and_dot(const Number a,
641  const VectorSpaceVector<Number> &W) override;
642 
647  virtual size_type
648  size() const override;
649 
661  virtual ::IndexSet
662  locally_owned_elements() const override;
663 
667  virtual void
668  print(std::ostream & out,
669  const unsigned int precision = 3,
670  const bool scientific = true,
671  const bool across = true) const override;
672 
676  virtual std::size_t
677  memory_consumption() const override;
679 
691 
697  };
698 
701  } // end of namespace distributed
702 
703 } // end of namespace LinearAlgebra
704 
705 
714 template <typename Number>
715 inline void
718 {
719  u.swap(v);
720 }
721 
722 
729 template <typename Number>
731  : std::false_type
732 {};
733 
734 
736 
737 #ifdef DEAL_II_MSVC
738 # include <deal.II/lac/la_parallel_block_vector.templates.h>
739 #endif
740 
741 #endif
LinearAlgebra::distributed::BlockVector::multivector_inner_product
void multivector_inner_product(FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
LinearAlgebra::distributed::BlockVector::BlockType
typename BaseClass::BlockType BlockType
Definition: la_parallel_block_vector.h:111
BlockVectorBase< Vector< Number > >::value_type
typename BlockType::value_type value_type
Definition: block_vector_base.h:468
LinearAlgebra::distributed::BlockVector::update_ghost_values
void update_ghost_values() const
CUDAWrappers::block_size
constexpr int block_size
Definition: cuda_size.h:29
LinearAlgebra::distributed::BlockVector::const_reference
typename BaseClass::const_reference const_reference
Definition: la_parallel_block_vector.h:121
PETScWrappers
Definition: petsc_block_sparse_matrix.h:36
LinearAlgebra
Definition: communication_pattern_base.h:30
LinearAlgebra::distributed::BlockVector::add_and_dot
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
BlockVector
Definition: block_vector.h:71
LinearAlgebra::distributed::Vector< Number >
block_vector_base.h
LinearAlgebra::distributed::BlockVector::locally_owned_elements
virtual ::IndexSet locally_owned_elements() const override
LinearAlgebra::distributed::BlockVector::operator-=
virtual BlockVector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
LAPACKSupport::V
static const char V
Definition: lapack_support.h:175
LinearAlgebra::distributed::BlockVector::multivector_inner_product_with_metric
Number multivector_inner_product_with_metric(const FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
TrilinosWrappers
Definition: types.h:161
LinearAlgebra::distributed::BlockVector::iterator
typename BaseClass::iterator iterator
Definition: la_parallel_block_vector.h:123
LinearAlgebra::distributed::BlockVector::reference
typename BaseClass::reference reference
Definition: la_parallel_block_vector.h:120
LinearAlgebra::distributed::BlockVector::operator*
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
block_indices.h
TrilinosWrappers::MPI::BlockVector
Definition: trilinos_parallel_block_vector.h:75
MPI_Comm
LinearAlgebra::distributed::BlockVector::l2_norm
virtual real_type l2_norm() const override
la_parallel_vector.h
LinearAlgebra::distributed::BlockVector::zero_out_ghosts
void zero_out_ghosts() const
BlockVectorBase< Vector< Number > >::reference
typename BlockType::reference reference
Definition: block_vector_base.h:475
LinearAlgebra::distributed::BlockVector::scale
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
BlockVectorBase< Vector< Number > >::const_reference
typename BlockType::const_reference const_reference
Definition: block_vector_base.h:476
LinearAlgebraDealII::BlockVector
BlockVector< double > BlockVector
Definition: generic_linear_algebra.h:48
LAPACKSupport::symmetric
@ symmetric
Matrix is symmetric.
Definition: lapack_support.h:115
LinearAlgebra::distributed::BlockVector::reinit
void reinit(const size_type num_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
is_serial_vector
Definition: vector_type_traits.h:49
LinearAlgebra::distributed::BlockVector::memory_consumption
virtual std::size_t memory_consumption() const override
LinearAlgebra::distributed::BlockVector::linfty_norm
virtual real_type linfty_norm() const override
vector_operation.h
LinearAlgebra::distributed::BlockVector::operator*=
virtual BlockVector< Number > & operator*=(const Number factor) override
vector_type_traits.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
BlockVectorBase
Definition: block_vector_base.h:450
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
LinearAlgebra::distributed::BlockVector
Definition: la_parallel_block_vector.h:85
LAPACKSupport::matrix
@ matrix
Contents is actually a matrix.
Definition: lapack_support.h:60
LinearAlgebra::distributed::BlockVector::operator/=
virtual BlockVector< Number > & operator/=(const Number factor) override
LinearAlgebra::distributed::BlockVector::const_pointer
typename BaseClass::const_pointer const_pointer
Definition: la_parallel_block_vector.h:119
LinearAlgebra::distributed::BlockVector::value_type
typename BaseClass::value_type value_type
Definition: la_parallel_block_vector.h:116
LinearAlgebra::distributed::BlockVector::ExcVectorTypeNotCompatible
static ::ExceptionBase & ExcVectorTypeNotCompatible()
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
LinearAlgebra::distributed::BlockVector::equ
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
LinearAlgebra::distributed::BlockVector::sadd
void sadd(const Number s, const BlockVector< Number > &V)
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
LinearAlgebra::distributed::BlockVector::swap
void swap(BlockVector< Number > &v)
BlockVectorBase< Vector< Number > >::pointer
value_type * pointer
Definition: block_vector_base.h:469
PETScWrappers::MPI::BlockVector
Definition: petsc_block_vector.h:61
LinearAlgebra::ReadWriteVector
Definition: read_write_vector.h:131
exceptions.h
BlockVectorBase< Vector< Number > >::real_type
typename BlockType::real_type real_type
Definition: block_vector_base.h:488
LinearAlgebra::distributed::BlockVector::real_type
typename BaseClass::real_type real_type
Definition: la_parallel_block_vector.h:117
BlockVectorBase< Vector< Number > >::const_iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
Definition: block_vector_base.h:474
LinearAlgebra::distributed::BlockVector::communication_block_size
static constexpr unsigned int communication_block_size
Definition: la_parallel_block_vector.h:101
LinearAlgebra::distributed::BlockVector::operator=
virtual BlockVector & operator=(const value_type s) override
LinearAlgebra::distributed::BlockVector::mmult
void mmult(BlockVector< Number > &V, const FullMatrixType &matrix, const Number s=Number(0.), const Number b=Number(1.)) const
BlockVectorBase< Vector< Number > >::iterator
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
Definition: block_vector_base.h:472
LinearAlgebra::distributed::BlockVector::size_type
typename BaseClass::size_type size_type
Definition: la_parallel_block_vector.h:122
LinearAlgebra::VectorSpaceVector
Definition: vector_space_vector.h:57
LinearAlgebra::distributed::BlockVector::all_zero
virtual bool all_zero() const override
DeclException0
#define DeclException0(Exception0)
Definition: exceptions.h:473
LinearAlgebra::distributed::BlockVector::ExcIteratorRangeDoesNotMatchVectorSize
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
LinearAlgebra::distributed::BlockVector::compress
virtual void compress(::VectorOperation::values operation) override
LinearAlgebra::distributed::BlockVector::pointer
typename BaseClass::pointer pointer
Definition: la_parallel_block_vector.h:118
LinearAlgebra::distributed::BlockVector::add
void add(const std::vector< size_type > &indices, const ::Vector< OtherNumber > &values)
LinearAlgebra::distributed::BlockVector::l1_norm
virtual real_type l1_norm() const override
LinearAlgebra::distributed::BlockVector::operator+=
virtual BlockVector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
LinearAlgebra::distributed::BlockVector::lp_norm
real_type lp_norm(const real_type p) const
config.h
LAPACKSupport::N
static const char N
Definition: lapack_support.h:159
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
LinearAlgebra::distributed::BlockVector::BlockVector
BlockVector(const size_type num_blocks=0, const size_type block_size=0)
LinearAlgebra::distributed::BlockVector::const_iterator
typename BaseClass::const_iterator const_iterator
Definition: la_parallel_block_vector.h:124
LinearAlgebra::distributed::BlockVector::has_ghost_elements
bool has_ghost_elements() const
LinearAlgebra::distributed::BlockVector::size
virtual size_type size() const override
LinearAlgebra::distributed::BlockVector::norm_sqr
real_type norm_sqr() const
LinearAlgebra::distributed::BlockVector::print
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
LinearAlgebra::distributed::BlockVector::~BlockVector
virtual ~BlockVector() override=default
LinearAlgebra::distributed::BlockVector::mean_value
virtual Number mean_value() const override