Reference documentation for deal.II version Git 437f94a 2018-06-23 09:16:19 -0400
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  typedef typename BaseClass::BlockType BlockType;
109 
113  typedef typename BaseClass::value_type value_type;
114  typedef typename BaseClass::real_type real_type;
115  typedef typename BaseClass::pointer pointer;
116  typedef typename BaseClass::const_pointer const_pointer;
117  typedef typename BaseClass::reference reference;
118  typedef typename BaseClass::const_reference const_reference;
119  typedef typename BaseClass::size_type size_type;
120  typedef typename BaseClass::iterator iterator;
121  typedef typename BaseClass::const_iterator 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 
186  virtual BlockVector &
187  operator=(const value_type s) override;
188 
193  BlockVector &
194  operator=(const BlockVector &V);
195 
200  template <class Number2>
201  BlockVector &
203 
207  BlockVector &
208  operator=(const Vector<Number> &V);
209 
210 #ifdef DEAL_II_WITH_PETSC
211 
219  operator=(const PETScWrappers::MPI::BlockVector &petsc_vec);
220 #endif
221 
222 #ifdef DEAL_II_WITH_TRILINOS
223 
232  operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
233 #endif
234 
248  void
249  reinit(const size_type num_blocks,
250  const size_type block_size = 0,
251  const bool omit_zeroing_entries = false);
252 
272  void
273  reinit(const std::vector<size_type> &N,
274  const bool omit_zeroing_entries = false);
275 
290  template <typename Number2>
291  void
292  reinit(const BlockVector<Number2> &V,
293  const bool omit_zeroing_entries = false);
294 
319  virtual void
320  compress(::VectorOperation::values operation) override;
321 
330  void
331  update_ghost_values() const;
332 
341  void
342  zero_out_ghosts() const;
343 
347  bool
348  has_ghost_elements() const;
349 
354  template <typename OtherNumber>
355  void
356  add(const std::vector<size_type> & indices,
357  const ::Vector<OtherNumber> &values);
358 
363  void
364  sadd(const Number s, const BlockVector<Number> &V);
365 
371  DEAL_II_DEPRECATED
372  void
373  equ(const Number a,
374  const BlockVector<Number> &u,
375  const Number b,
376  const BlockVector<Number> &v);
377 
383  DEAL_II_DEPRECATED
384  void
385  sadd(const Number s,
386  const Number a,
387  const BlockVector<Number> &V,
388  const Number b,
389  const BlockVector<Number> &W);
390 
396  virtual bool
397  all_zero() const override;
398 
402  virtual Number
403  mean_value() const override;
404 
409  real_type
410  lp_norm(const real_type p) const;
411 
429  void
432 
437 
442  virtual void
444  const bool omit_zeroing_entries = false) override;
445 
449  virtual BlockVector<Number> &
450  operator*=(const Number factor) override;
451 
455  virtual BlockVector<Number> &
456  operator/=(const Number factor) override;
457 
461  virtual BlockVector<Number> &
462  operator+=(const VectorSpaceVector<Number> &V) override;
463 
467  virtual BlockVector<Number> &
468  operator-=(const VectorSpaceVector<Number> &V) override;
469 
478  virtual void
479  import(
481  VectorOperation::values operation,
482  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
483  std::shared_ptr<const CommunicationPatternBase>()) override;
484 
488  virtual Number
489  operator*(const VectorSpaceVector<Number> &V) const override;
490 
507  template <typename FullMatrixType>
508  void
509  multivector_inner_product(FullMatrixType & matrix,
510  const BlockVector<Number> &V,
511  const bool symmetric = false) const;
512 
529  template <typename FullMatrixType>
530  Number
531  multivector_inner_product_with_metric(const FullMatrixType & matrix,
532  const BlockVector<Number> &V,
533  const bool symmetric = false) const;
534 
544  template <typename FullMatrixType>
545  void
547  const FullMatrixType &matrix,
548  const Number s = Number(0.),
549  const Number b = Number(1.)) const;
550 
554  virtual void
555  add(const Number a) override;
556 
560  virtual void
561  add(const Number a, const VectorSpaceVector<Number> &V) override;
562 
566  virtual void
567  add(const Number a,
568  const VectorSpaceVector<Number> &V,
569  const Number b,
570  const VectorSpaceVector<Number> &W) override;
571 
576  virtual void
577  add(const std::vector<size_type> &indices,
578  const std::vector<Number> & values);
579 
584  virtual void
585  sadd(const Number s,
586  const Number a,
587  const VectorSpaceVector<Number> &V) override;
588 
594  virtual void
595  scale(const VectorSpaceVector<Number> &scaling_factors) override;
596 
600  virtual void
601  equ(const Number a, const VectorSpaceVector<Number> &V) override;
602 
607  virtual real_type
608  l1_norm() const override;
609 
614  virtual real_type
615  l2_norm() const override;
616 
620  real_type
621  norm_sqr() const;
622 
627  virtual real_type
628  linfty_norm() const override;
629 
650  virtual Number
651  add_and_dot(const Number a,
652  const VectorSpaceVector<Number> &V,
653  const VectorSpaceVector<Number> &W) override;
654 
659  virtual size_type
660  size() const override;
661 
673  virtual ::IndexSet
674  locally_owned_elements() const override;
675 
679  virtual void
680  print(std::ostream & out,
681  const unsigned int precision = 3,
682  const bool scientific = true,
683  const bool across = true) const override;
684 
688  virtual std::size_t
689  memory_consumption() const override;
691 
703 
709  };
710 
713  } // end of namespace distributed
714 
715 } // end of namespace LinearAlgebra
716 
717 
726 template <typename Number>
727 inline void
730 {
731  u.swap(v);
732 }
733 
734 
740 template <typename Number>
742  : std::false_type
743 {};
744 
745 
746 DEAL_II_NAMESPACE_CLOSE
747 
748 #ifdef DEAL_II_MSVC
749 # include <deal.II/lac/la_parallel_block_vector.templates.h>
750 #endif
751 
752 #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:385
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
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
Number multivector_inner_product_with_metric(const 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 Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override