Reference documentation for deal.II version GIT 75f1417c0d 2023-02-03 16:10: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\}}\)
la_parallel_block_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2022 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 
141  explicit BlockVector(const size_type num_blocks = 0,
142  const size_type block_size = 0);
143 
149 
156  template <typename OtherNumber>
158 
163  BlockVector(const std::vector<size_type> &block_sizes);
164 
169  BlockVector(const std::vector<IndexSet> &local_ranges,
170  const std::vector<IndexSet> &ghost_indices,
171  const MPI_Comm & communicator);
172 
176  BlockVector(const std::vector<IndexSet> &local_ranges,
177  const MPI_Comm & communicator);
178 
187  virtual ~BlockVector() override = default;
188 
193  virtual BlockVector &
194  operator=(const value_type s) override;
195 
200  BlockVector &
202 
207  template <class Number2>
208  BlockVector &
210 
214  BlockVector &
216 
217 #ifdef DEAL_II_WITH_PETSC
227 #endif
228 
229 #ifdef DEAL_II_WITH_TRILINOS
240 #endif
241 
255  void
256  reinit(const size_type num_blocks,
257  const size_type block_size = 0,
258  const bool omit_zeroing_entries = false);
259 
279  void
280  reinit(const std::vector<size_type> &block_sizes,
281  const bool omit_zeroing_entries = false);
282 
297  template <typename Number2>
298  void
300  const bool omit_zeroing_entries = false);
301 
319  void
320  reinit(const std::vector<IndexSet> &local_ranges,
321  const std::vector<IndexSet> &ghost_indices,
322  const MPI_Comm & communicator);
323 
327  void
328  reinit(const std::vector<IndexSet> &local_ranges,
329  const MPI_Comm & communicator);
330 
354  virtual void
355  compress(::VectorOperation::values operation) override;
356 
365  void
367 
378  DEAL_II_DEPRECATED void
380 
381 
390  void
392 
396  bool
398 
402  void
403  set_ghost_state(const bool ghosted) const;
404 
419  template <typename Number2>
420  void
422 
427  template <typename OtherNumber>
428  void
429  add(const std::vector<size_type> & indices,
430  const ::Vector<OtherNumber> &values);
431 
436  void
437  sadd(const Number s, const BlockVector<Number> &V);
438 
444  virtual bool
445  all_zero() const override;
446 
450  virtual Number
451  mean_value() const override;
452 
457  real_type
458  lp_norm(const real_type p) const;
459 
477  void
490  virtual void
492  const bool omit_zeroing_entries = false) override;
493 
497  virtual BlockVector<Number> &
498  operator*=(const Number factor) override;
499 
503  virtual BlockVector<Number> &
504  operator/=(const Number factor) override;
505 
509  virtual BlockVector<Number> &
511 
515  virtual BlockVector<Number> &
517 
526  virtual void
528  VectorOperation::values operation,
529  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
530  communication_pattern = {}) override;
531 
535  virtual Number
536  operator*(const VectorSpaceVector<Number> &V) const override;
537 
554  template <typename FullMatrixType>
555  void
557  const BlockVector<Number> &V,
558  const bool symmetric = false) const;
559 
576  template <typename FullMatrixType>
577  Number
579  const BlockVector<Number> &V,
580  const bool symmetric = false) const;
581 
591  template <typename FullMatrixType>
592  void
594  const FullMatrixType &matrix,
595  const Number s = Number(0.),
596  const Number b = Number(1.)) const;
597 
601  virtual void
602  add(const Number a) override;
603 
607  virtual void
608  add(const Number a, const VectorSpaceVector<Number> &V) override;
609 
613  virtual void
614  add(const Number a,
616  const Number b,
617  const VectorSpaceVector<Number> &W) override;
618 
623  virtual void
624  add(const std::vector<size_type> &indices,
625  const std::vector<Number> & values);
626 
631  virtual void
632  sadd(const Number s,
633  const Number a,
634  const VectorSpaceVector<Number> &V) override;
635 
641  virtual void
642  scale(const VectorSpaceVector<Number> &scaling_factors) override;
643 
647  virtual void
648  equ(const Number a, const VectorSpaceVector<Number> &V) override;
649 
654  virtual real_type
655  l1_norm() const override;
656 
661  virtual real_type
662  l2_norm() const override;
663 
667  real_type
668  norm_sqr() const;
669 
674  virtual real_type
675  linfty_norm() const override;
676 
697  virtual Number
698  add_and_dot(const Number a,
700  const VectorSpaceVector<Number> &W) override;
701 
706  virtual size_type
707  size() const override;
708 
720  virtual ::IndexSet
721  locally_owned_elements() const override;
722 
726  virtual void
727  print(std::ostream & out,
728  const unsigned int precision = 3,
729  const bool scientific = true,
730  const bool across = true) const override;
731 
735  virtual std::size_t
736  memory_consumption() const override;
750 
756  };
757 
760  } // end of namespace distributed
761 
762 } // end of namespace LinearAlgebra
763 
764 
772 template <typename Number>
773 inline void
776 {
777  u.swap(v);
778 }
779 
780 
785 template <typename Number>
787  : std::false_type
788 {};
789 
790 
792 
793 #ifdef DEAL_II_MSVC
794 # include <deal.II/lac/la_parallel_block_vector.templates.h>
795 #endif
796 
797 #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
void swap(LinearAlgebra::distributed::BlockVector< Number > &u, LinearAlgebra::distributed::BlockVector< Number > &v)
BlockVector & operator=(const BlockVector &V)
BlockVector & operator=(const Vector< Number > &V)
virtual real_type linfty_norm() const override
void swap(BlockVector< Number > &v)
BlockVector(const size_type num_blocks=0, const size_type block_size=0)
virtual BlockVector & operator=(const value_type s) override
virtual real_type l1_norm() const override
virtual void add(const Number a, const VectorSpaceVector< Number > &V, const Number b, const VectorSpaceVector< Number > &W) override
virtual void add(const std::vector< size_type > &indices, const std::vector< Number > &values)
void reinit(const std::vector< IndexSet > &local_ranges, const std::vector< IndexSet > &ghost_indices, const MPI_Comm &communicator)
BlockVector< Number > & operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec)
virtual void reinit(const VectorSpaceVector< Number > &V, const bool omit_zeroing_entries=false) override
virtual ::IndexSet locally_owned_elements() const override
virtual BlockVector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
static constexpr unsigned int communication_block_size
virtual BlockVector< Number > & operator/=(const Number factor) override
virtual BlockVector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual ~BlockVector() override=default
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual BlockVector< Number > & operator*=(const Number factor) override
BlockVector & operator=(const BlockVector< Number2 > &V)
BlockVector(const std::vector< size_type > &block_sizes)
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
BlockVector(const BlockVector< OtherNumber > &v)
BlockVector(const BlockVector< Number > &V)
void reinit(const size_type num_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
virtual std::size_t memory_consumption() const override
virtual Number mean_value() const override
virtual bool all_zero() const override
virtual void compress(::VectorOperation::values operation) override
void set_ghost_state(const bool ghosted) const
void add(const std::vector< size_type > &indices, const ::Vector< OtherNumber > &values)
virtual real_type l2_norm() const override
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
Number multivector_inner_product_with_metric(const FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
BlockVector< Number > & operator=(const PETScWrappers::MPI::BlockVector &petsc_vec)
virtual void add(const Number a, const VectorSpaceVector< Number > &V) override
typename BaseClass::const_reference const_reference
real_type lp_norm(const real_type p) const
void reinit(const BlockVector< Number2 > &V, const bool omit_zeroing_entries=false)
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
void reinit(const std::vector< IndexSet > &local_ranges, const MPI_Comm &communicator)
void sadd(const Number s, const BlockVector< Number > &V)
void copy_locally_owned_data_from(const BlockVector< Number2 > &src)
virtual void add(const Number a) override
BlockVector(const std::vector< IndexSet > &local_ranges, const std::vector< IndexSet > &ghost_indices, const MPI_Comm &communicator)
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
typename BaseClass::const_pointer const_pointer
typename BaseClass::const_iterator const_iterator
BlockVector(const std::vector< IndexSet > &local_ranges, const MPI_Comm &communicator)
void multivector_inner_product(FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
void mmult(BlockVector< Number > &V, const FullMatrixType &matrix, const Number s=Number(0.), const Number b=Number(1.)) const
void reinit(const std::vector< size_type > &block_sizes, const bool omit_zeroing_entries=false)
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
virtual size_type size() const override
#define DEAL_II_DEPRECATED
Definition: config.h:162
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:462
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
#define DeclException0(Exception0)
Definition: exceptions.h:465
static ::ExceptionBase & ExcVectorTypeNotCompatible()
constexpr int block_size
Definition: cuda_size.h:29
@ matrix
Contents is actually a matrix.
@ symmetric
Matrix is symmetric.
static const char V
BlockVector< double > BlockVector
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)