Reference documentation for deal.II version Git 2618e0f 2017-11-23 17:25:26 +0100
la_parallel_block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2017 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  {
84  public:
89 
93  typedef typename BaseClass::BlockType BlockType;
94 
98  typedef typename BaseClass::value_type value_type;
99  typedef typename BaseClass::real_type real_type;
100  typedef typename BaseClass::pointer pointer;
101  typedef typename BaseClass::const_pointer const_pointer;
102  typedef typename BaseClass::reference reference;
103  typedef typename BaseClass::const_reference const_reference;
104  typedef typename BaseClass::size_type size_type;
105  typedef typename BaseClass::iterator iterator;
106  typedef typename BaseClass::const_iterator const_iterator;
107 
112 
123  explicit BlockVector (const size_type num_blocks = 0,
124  const size_type block_size = 0);
125 
130  BlockVector (const BlockVector<Number> &V);
131 
144  template <typename OtherNumber>
145  explicit
147 
152  BlockVector (const std::vector<size_type> &block_sizes);
153 
158  BlockVector (const std::vector<IndexSet> &local_ranges,
159  const std::vector<IndexSet> &ghost_indices,
160  const MPI_Comm communicator);
161 
165  BlockVector (const std::vector<IndexSet> &local_ranges,
166  const MPI_Comm communicator);
167 
172  virtual BlockVector &operator = (const value_type s) override;
173 
178  BlockVector &
179  operator= (const BlockVector &V);
180 
185  template <class Number2>
186  BlockVector &
188 
192  BlockVector &
193  operator= (const Vector<Number> &V);
194 
195 #ifdef DEAL_II_WITH_PETSC
196 
205 #endif
206 
207 #ifdef DEAL_II_WITH_TRILINOS
208 
217  operator = (const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
218 #endif
219 
233  void reinit (const size_type num_blocks,
234  const size_type block_size = 0,
235  const bool omit_zeroing_entries = false);
236 
256  void reinit (const std::vector<size_type> &N,
257  const bool omit_zeroing_entries=false);
258 
273  template <typename Number2>
274  void reinit (const BlockVector<Number2> &V,
275  const bool omit_zeroing_entries=false);
276 
301  virtual void compress (::VectorOperation::values operation) override;
302 
311  void update_ghost_values () const;
312 
321  void zero_out_ghosts ();
322 
326  bool has_ghost_elements() const;
327 
332  template <typename OtherNumber>
333  void add (const std::vector<size_type> &indices,
334  const ::Vector<OtherNumber> &values);
335 
340  void sadd (const Number s,
341  const BlockVector<Number> &V);
342 
348  DEAL_II_DEPRECATED
349  void equ (const Number a, const BlockVector<Number> &u,
350  const Number b, const BlockVector<Number> &v);
351 
357  DEAL_II_DEPRECATED
358  void sadd (const Number s,
359  const Number a,
360  const BlockVector<Number> &V,
361  const Number b,
362  const BlockVector<Number> &W);
363 
369  virtual bool all_zero () const override;
370 
374  virtual Number mean_value () const override;
375 
380  real_type lp_norm (const real_type p) const;
381 
399  void swap (BlockVector<Number> &v);
401 
406 
411  virtual void reinit(const VectorSpaceVector<Number> &V,
412  const bool omit_zeroing_entries = false) override;
413 
417  virtual BlockVector<Number> &operator*= (const Number factor) override;
418 
422  virtual BlockVector<Number> &operator/= (const Number factor) override;
423 
427  virtual BlockVector<Number> &operator+= (const VectorSpaceVector<Number> &V) override;
428 
432  virtual BlockVector<Number> &operator-= (const VectorSpaceVector<Number> &V) override;
433 
442  virtual void import(const LinearAlgebra::ReadWriteVector<Number> &V,
443  VectorOperation::values operation,
444  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
445  std::shared_ptr<const CommunicationPatternBase> ()) override;
446 
450  virtual Number operator* (const VectorSpaceVector<Number> &V) const override;
451 
467  template <typename FullMatrixType>
468  void multivector_inner_product(FullMatrixType &matrix,
469  const BlockVector<Number> &V,
470  const bool symmetric = false) const;
471 
475  virtual void add(const Number a) override;
476 
480  virtual void add(const Number a, const VectorSpaceVector<Number> &V) override;
481 
485  virtual void add(const Number a, const VectorSpaceVector<Number> &V,
486  const Number b, const VectorSpaceVector<Number> &W) override;
487 
492  virtual void add (const std::vector<size_type> &indices,
493  const std::vector<Number> &values);
494 
499  virtual void sadd(const Number s, const Number a,
500  const VectorSpaceVector<Number> &V) override;
501 
507  virtual void scale(const VectorSpaceVector<Number> &scaling_factors) override;
508 
512  virtual void equ(const Number a, const VectorSpaceVector<Number> &V) override;
513 
518  virtual real_type l1_norm() const override;
519 
524  virtual real_type l2_norm() const override;
525 
530  virtual real_type linfty_norm() const override;
531 
548  virtual Number add_and_dot(const Number a,
549  const VectorSpaceVector<Number> &V,
550  const VectorSpaceVector<Number> &W) override;
551 
556  virtual size_type size() const override;
557 
569  virtual ::IndexSet locally_owned_elements() const override;
570 
574  virtual void print(std::ostream &out,
575  const unsigned int precision=3,
576  const bool scientific=true,
577  const bool across=true) const override;
578 
582  virtual std::size_t memory_consumption() const override;
584 
596 
602  };
603 
606  } // end of namespace distributed
607 
608 } // end of namespace LinearAlgebra
609 
610 
619 template <typename Number>
620 inline
623 {
624  u.swap (v);
625 }
626 
627 
633 template <typename Number>
634 struct is_serial_vector< LinearAlgebra::distributed::BlockVector< Number > > : std::false_type
635 {
636 };
637 
638 
639 DEAL_II_NAMESPACE_CLOSE
640 
641 #ifdef DEAL_II_MSVC
642 #include <deal.II/lac/la_parallel_block_vector.templates.h>
643 #endif
644 
645 #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
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 multivector_inner_product(FullMatrixType &matrix, const BlockVector< Number > &V, const bool symmetric=false) const
void swap(LinearAlgebra::distributed::BlockVector< Number > &u, LinearAlgebra::distributed::BlockVector< Number > &v)
#define DeclException0(Exception0)
Definition: exceptions.h:570
virtual real_type l1_norm() const override
void swap(BlockVector< Number > &v)
real_type lp_norm(const real_type p) const
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
BlockVector(const size_type num_blocks=0, const size_type block_size=0)
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 sadd(const Number s, const BlockVector< Number > &V)
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