Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/exceptions.h>
22 #include <deal.II/lac/block_indices.h>
23 #include <deal.II/lac/block_vector_base.h>
24 #include <deal.II/lac/la_parallel_vector.h>
25 #include <deal.II/lac/vector_operation.h>
26 #include <deal.II/lac/vector_type_traits.h>
27 
28 #include <cstdio>
29 #include <vector>
30 
31 DEAL_II_NAMESPACE_OPEN
32 
33 
34 #ifdef DEAL_II_WITH_PETSC
35 namespace PETScWrappers
36 {
37  namespace MPI
38  {
39  class BlockVector;
40  }
41 }
42 #endif
43 
44 #ifdef DEAL_II_WITH_TRILINOS
45 namespace TrilinosWrappers
46 {
47  namespace MPI
48  {
49  class BlockVector;
50  }
51 }
52 #endif
53 
54 namespace LinearAlgebra
55 {
56  namespace distributed
57  {
58 
80  template <typename Number>
81  class BlockVector : public BlockVectorBase<Vector<Number> >,
82  public VectorSpaceVector<Number>
83  {
95  static constexpr unsigned int communication_block_size = 20;
96  public:
97 
102 
106  typedef typename BaseClass::BlockType BlockType;
107 
111  typedef typename BaseClass::value_type value_type;
112  typedef typename BaseClass::real_type real_type;
113  typedef typename BaseClass::pointer pointer;
114  typedef typename BaseClass::const_pointer const_pointer;
115  typedef typename BaseClass::reference reference;
116  typedef typename BaseClass::const_reference const_reference;
117  typedef typename BaseClass::size_type size_type;
118  typedef typename BaseClass::iterator iterator;
119  typedef typename BaseClass::const_iterator const_iterator;
120 
125 
136  explicit BlockVector (const size_type num_blocks = 0,
137  const size_type block_size = 0);
138 
143  BlockVector (const BlockVector<Number> &V);
144 
157  template <typename OtherNumber>
158  explicit
160 
165  BlockVector (const std::vector<size_type> &block_sizes);
166 
171  BlockVector (const std::vector<IndexSet> &local_ranges,
172  const std::vector<IndexSet> &ghost_indices,
173  const MPI_Comm communicator);
174 
178  BlockVector (const std::vector<IndexSet> &local_ranges,
179  const MPI_Comm communicator);
180 
185  virtual BlockVector &operator = (const value_type s) override;
186 
191  BlockVector &
192  operator= (const BlockVector &V);
193 
198  template <class Number2>
199  BlockVector &
201 
205  BlockVector &
206  operator= (const Vector<Number> &V);
207 
208 #ifdef DEAL_II_WITH_PETSC
209 
218 #endif
219 
220 #ifdef DEAL_II_WITH_TRILINOS
221 
230  operator = (const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
231 #endif
232 
246  void reinit (const size_type num_blocks,
247  const size_type block_size = 0,
248  const bool omit_zeroing_entries = false);
249 
269  void reinit (const std::vector<size_type> &N,
270  const bool omit_zeroing_entries=false);
271 
286  template <typename Number2>
287  void reinit (const BlockVector<Number2> &V,
288  const bool omit_zeroing_entries=false);
289 
314  virtual void compress (::VectorOperation::values operation) override;
315 
324  void update_ghost_values () const;
325 
334  void zero_out_ghosts () const;
335 
339  bool has_ghost_elements() const;
340 
345  template <typename OtherNumber>
346  void add (const std::vector<size_type> &indices,
347  const ::Vector<OtherNumber> &values);
348 
353  void sadd (const Number s,
354  const BlockVector<Number> &V);
355 
361  DEAL_II_DEPRECATED
362  void equ (const Number a, const BlockVector<Number> &u,
363  const Number b, const BlockVector<Number> &v);
364 
370  DEAL_II_DEPRECATED
371  void sadd (const Number s,
372  const Number a,
373  const BlockVector<Number> &V,
374  const Number b,
375  const BlockVector<Number> &W);
376 
382  virtual bool all_zero () const override;
383 
387  virtual Number mean_value () const override;
388 
393  real_type lp_norm (const real_type p) const;
394 
412  void swap (BlockVector<Number> &v);
414 
419 
424  virtual void reinit(const VectorSpaceVector<Number> &V,
425  const bool omit_zeroing_entries = false) override;
426 
430  virtual BlockVector<Number> &operator*= (const Number factor) override;
431 
435  virtual BlockVector<Number> &operator/= (const Number factor) override;
436 
440  virtual BlockVector<Number> &operator+= (const VectorSpaceVector<Number> &V) override;
441 
445  virtual BlockVector<Number> &operator-= (const VectorSpaceVector<Number> &V) override;
446 
455  virtual void import(const LinearAlgebra::ReadWriteVector<Number> &V,
456  VectorOperation::values operation,
457  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
458  std::shared_ptr<const CommunicationPatternBase> ()) override;
459 
463  virtual Number operator* (const VectorSpaceVector<Number> &V) const override;
464 
480  template <typename FullMatrixType>
481  void multivector_inner_product(FullMatrixType &matrix,
482  const BlockVector<Number> &V,
483  const bool symmetric = false) const;
484 
500  template <typename FullMatrixType>
501  Number multivector_inner_product_with_metric(const FullMatrixType &matrix,
502  const BlockVector<Number> &V,
503  const bool symmetric = false) const;
504 
514  template <typename FullMatrixType>
515  void mmult(BlockVector<Number> &V,
516  const FullMatrixType &matrix,
517  const Number s = Number(0.),
518  const Number b = Number(1.)) const;
519 
523  virtual void add(const Number a) override;
524 
528  virtual void add(const Number a, const VectorSpaceVector<Number> &V) override;
529 
533  virtual void add(const Number a, const VectorSpaceVector<Number> &V,
534  const Number b, const VectorSpaceVector<Number> &W) override;
535 
540  virtual void add (const std::vector<size_type> &indices,
541  const std::vector<Number> &values);
542 
547  virtual void sadd(const Number s, const Number a,
548  const VectorSpaceVector<Number> &V) override;
549 
555  virtual void scale(const VectorSpaceVector<Number> &scaling_factors) override;
556 
560  virtual void equ(const Number a, const VectorSpaceVector<Number> &V) override;
561 
566  virtual real_type l1_norm() const override;
567 
572  virtual real_type l2_norm() const override;
573 
577  real_type norm_sqr() const;
578 
583  virtual real_type linfty_norm() const override;
584 
604  virtual Number add_and_dot(const Number a,
605  const VectorSpaceVector<Number> &V,
606  const VectorSpaceVector<Number> &W) override;
607 
612  virtual size_type size() const override;
613 
625  virtual ::IndexSet locally_owned_elements() const override;
626 
630  virtual void print(std::ostream &out,
631  const unsigned int precision=3,
632  const bool scientific=true,
633  const bool across=true) const override;
634 
638  virtual std::size_t memory_consumption() const override;
640 
652 
658  };
659 
662  } // end of namespace distributed
663 
664 } // end of namespace LinearAlgebra
665 
666 
675 template <typename Number>
676 inline
679 {
680  u.swap (v);
681 }
682 
683 
689 template <typename Number>
690 struct is_serial_vector< LinearAlgebra::distributed::BlockVector< Number > > : std::false_type
691 {
692 };
693 
694 
695 DEAL_II_NAMESPACE_CLOSE
696 
697 #ifdef DEAL_II_MSVC
698 #include <deal.II/lac/la_parallel_block_vector.templates.h>
699 #endif
700 
701 #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)
BlockVectorBase< Vector< Number > > BaseClass
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:323
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
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
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override