Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
la_parallel_block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2018 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 
22 #include <deal.II/base/exceptions.h>
23 
24 #include <deal.II/lac/block_indices.h>
25 #include <deal.II/lac/block_vector_base.h>
26 #include <deal.II/lac/la_parallel_vector.h>
27 #include <deal.II/lac/vector_operation.h>
28 #include <deal.II/lac/vector_type_traits.h>
29 
30 #include <cstdio>
31 #include <vector>
32 
33 DEAL_II_NAMESPACE_OPEN
34 
35 
36 #ifdef DEAL_II_WITH_PETSC
37 namespace PETScWrappers
38 {
39  namespace MPI
40  {
41  class BlockVector;
42  }
43 } // namespace PETScWrappers
44 #endif
45 
46 #ifdef DEAL_II_WITH_TRILINOS
47 namespace TrilinosWrappers
48 {
49  namespace MPI
50  {
51  class BlockVector;
52  }
53 } // namespace TrilinosWrappers
54 #endif
55 
56 namespace LinearAlgebra
57 {
58  namespace distributed
59  {
81  template <typename Number>
82  class BlockVector : public BlockVectorBase<Vector<Number>>,
83  public VectorSpaceVector<Number>
84  {
85  public:
98  static constexpr unsigned int communication_block_size = 20;
99 
104 
108  using BlockType = typename BaseClass::BlockType;
109 
113  using value_type = typename BaseClass::value_type;
114  using real_type = typename BaseClass::real_type;
115  using pointer = typename BaseClass::pointer;
116  using const_pointer = typename BaseClass::const_pointer;
117  using reference = typename BaseClass::reference;
118  using const_reference = typename BaseClass::const_reference;
119  using size_type = typename BaseClass::size_type;
120  using iterator = typename BaseClass::iterator;
121  using const_iterator = typename BaseClass::const_iterator;
122 
127 
138  explicit BlockVector(const size_type num_blocks = 0,
139  const size_type block_size = 0);
140 
146 
159  template <typename OtherNumber>
160  explicit BlockVector(const BlockVector<OtherNumber> &v);
161 
166  BlockVector(const std::vector<size_type> &block_sizes);
167 
172  BlockVector(const std::vector<IndexSet> &local_ranges,
173  const std::vector<IndexSet> &ghost_indices,
174  const MPI_Comm communicator);
175 
179  BlockVector(const std::vector<IndexSet> &local_ranges,
180  const MPI_Comm communicator);
181 
190  virtual ~BlockVector() override = default;
191 
196  virtual BlockVector &
197  operator=(const value_type s) override;
198 
203  BlockVector &
204  operator=(const BlockVector &V);
205 
210  template <class Number2>
211  BlockVector &
213 
217  BlockVector &
218  operator=(const Vector<Number> &V);
219 
220 #ifdef DEAL_II_WITH_PETSC
221 
229  operator=(const PETScWrappers::MPI::BlockVector &petsc_vec);
230 #endif
231 
232 #ifdef DEAL_II_WITH_TRILINOS
233 
242  operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
243 #endif
244 
258  void
259  reinit(const size_type num_blocks,
260  const size_type block_size = 0,
261  const bool omit_zeroing_entries = false);
262 
282  void
283  reinit(const std::vector<size_type> &N,
284  const bool omit_zeroing_entries = false);
285 
300  template <typename Number2>
301  void
302  reinit(const BlockVector<Number2> &V,
303  const bool omit_zeroing_entries = false);
304 
329  virtual void
330  compress(::VectorOperation::values operation) override;
331 
340  void
341  update_ghost_values() const;
342 
351  void
352  zero_out_ghosts() const;
353 
357  bool
358  has_ghost_elements() const;
359 
364  template <typename OtherNumber>
365  void
366  add(const std::vector<size_type> & indices,
367  const ::Vector<OtherNumber> &values);
368 
373  void
374  sadd(const Number s, const BlockVector<Number> &V);
375 
381  DEAL_II_DEPRECATED
382  void
383  equ(const Number a,
384  const BlockVector<Number> &u,
385  const Number b,
386  const BlockVector<Number> &v);
387 
393  DEAL_II_DEPRECATED
394  void
395  sadd(const Number s,
396  const Number a,
397  const BlockVector<Number> &V,
398  const Number b,
399  const BlockVector<Number> &W);
400 
406  virtual bool
407  all_zero() const override;
408 
412  virtual Number
413  mean_value() const override;
414 
419  real_type
420  lp_norm(const real_type p) const;
421 
439  void
442 
447 
452  virtual void
454  const bool omit_zeroing_entries = false) override;
455 
459  virtual BlockVector<Number> &
460  operator*=(const Number factor) override;
461 
465  virtual BlockVector<Number> &
466  operator/=(const Number factor) override;
467 
471  virtual BlockVector<Number> &
472  operator+=(const VectorSpaceVector<Number> &V) override;
473 
477  virtual BlockVector<Number> &
478  operator-=(const VectorSpaceVector<Number> &V) override;
479 
488  virtual void
489  import(
491  VectorOperation::values operation,
492  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
493  std::shared_ptr<const CommunicationPatternBase>()) override;
494 
498  virtual Number
499  operator*(const VectorSpaceVector<Number> &V) const override;
500 
517  template <typename FullMatrixType>
518  void
519  multivector_inner_product(FullMatrixType & matrix,
520  const BlockVector<Number> &V,
521  const bool symmetric = false) const;
522 
539  template <typename FullMatrixType>
540  Number
541  multivector_inner_product_with_metric(const FullMatrixType & matrix,
542  const BlockVector<Number> &V,
543  const bool symmetric = false) const;
544 
554  template <typename FullMatrixType>
555  void
557  const FullMatrixType &matrix,
558  const Number s = Number(0.),
559  const Number b = Number(1.)) const;
560 
564  virtual void
565  add(const Number a) override;
566 
570  virtual void
571  add(const Number a, const VectorSpaceVector<Number> &V) override;
572 
576  virtual void
577  add(const Number a,
578  const VectorSpaceVector<Number> &V,
579  const Number b,
580  const VectorSpaceVector<Number> &W) override;
581 
586  virtual void
587  add(const std::vector<size_type> &indices,
588  const std::vector<Number> & values);
589 
594  virtual void
595  sadd(const Number s,
596  const Number a,
597  const VectorSpaceVector<Number> &V) override;
598 
604  virtual void
605  scale(const VectorSpaceVector<Number> &scaling_factors) override;
606 
610  virtual void
611  equ(const Number a, const VectorSpaceVector<Number> &V) override;
612 
617  virtual real_type
618  l1_norm() const override;
619 
624  virtual real_type
625  l2_norm() const override;
626 
630  real_type
631  norm_sqr() const;
632 
637  virtual real_type
638  linfty_norm() const override;
639 
660  virtual Number
661  add_and_dot(const Number a,
662  const VectorSpaceVector<Number> &V,
663  const VectorSpaceVector<Number> &W) override;
664 
669  virtual size_type
670  size() const override;
671 
683  virtual ::IndexSet
684  locally_owned_elements() const override;
685 
689  virtual void
690  print(std::ostream & out,
691  const unsigned int precision = 3,
692  const bool scientific = true,
693  const bool across = true) const override;
694 
698  virtual std::size_t
699  memory_consumption() const override;
701 
713 
719  };
720 
723  } // end of namespace distributed
724 
725 } // end of namespace LinearAlgebra
726 
727 
736 template <typename Number>
737 inline void
740 {
741  u.swap(v);
742 }
743 
744 
750 template <typename Number>
752  : std::false_type
753 {};
754 
755 
756 DEAL_II_NAMESPACE_CLOSE
757 
758 #ifdef DEAL_II_MSVC
759 # include <deal.II/lac/la_parallel_block_vector.templates.h>
760 #endif
761 
762 #endif
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
virtual std::size_t memory_consumption() const override
virtual BlockVector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual void compress(::VectorOperation::values operation) override
virtual BlockVector & operator=(const value_type s) override
real_type lp_norm(const real_type p) const
virtual BlockVector< Number > & operator/=(const Number factor) override
virtual real_type l2_norm() const override
virtual Number mean_value() const override
virtual real_type linfty_norm() const override
virtual bool all_zero() const override
void reinit(const size_type num_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
void equ(const Number a, const BlockVector< Number > &u, const Number b, const BlockVector< Number > &v)
static ::ExceptionBase & ExcVectorTypeNotCompatible()
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
void swap(LinearAlgebra::distributed::BlockVector< Number > &u, LinearAlgebra::distributed::BlockVector< Number > &v)
#define DeclException0(Exception0)
Definition: exceptions.h:473
virtual real_type l1_norm() const override
void swap(BlockVector< Number > &v)
void mmult(BlockVector< Number > &V, const FullMatrixType &matrix, const Number s=Number(0.), const Number b=Number(1.)) const
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
BlockVector(const size_type num_blocks=0, const size_type block_size=0)
Number multivector_inner_product_with_metric(const FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
virtual size_type size() const override
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
void add(const std::vector< size_type > &indices, const ::Vector< OtherNumber > &values)
virtual BlockVector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
virtual ::IndexSet locally_owned_elements() const override
typename BlockType::real_type real_type
void multivector_inner_product(FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
void sadd(const Number s, const BlockVector< Number > &V)
static constexpr unsigned int communication_block_size
virtual BlockVector< Number > & operator*=(const Number factor) override
LinearAlgebra::distributed::BlockVector< Number > BlockVector
virtual ~BlockVector() override=default
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override