Reference documentation for deal.II version 9.2.0
\(\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_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2015 - 2020 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_vector_h
17 #define dealii_la_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 #include <deal.II/base/index_set.h>
24 #include <deal.II/base/logstream.h>
25 
30 
31 // boost::serialization::make_array used to be in array.hpp, but was
32 // moved to a different file in BOOST 1.64
33 #include <boost/version.hpp>
34 #if BOOST_VERSION >= 106400
35 # include <boost/serialization/array_wrapper.hpp>
36 #else
37 # include <boost/serialization/array.hpp>
38 #endif
39 #include <boost/serialization/split_member.hpp>
40 
41 #include <cstdio>
42 #include <cstring>
43 #include <iostream>
44 #include <vector>
45 
46 
48 
63 namespace LinearAlgebra
64 {
78  template <typename Number>
79  class Vector : public ReadWriteVector<Number>,
80  public VectorSpaceVector<Number>
81  {
82  public:
85 
89  Vector() = default;
90 
95  Vector(const Vector<Number> &V);
96 
107  explicit Vector(const size_type n);
108 
113  template <typename InputIterator>
114  Vector(const InputIterator first, const InputIterator last);
115 
124  virtual void
125  reinit(const size_type size,
126  const bool omit_zeroing_entries = false) override;
127 
136  template <typename Number2>
137  void
138  reinit(const ReadWriteVector<Number2> &in_vector,
139  const bool omit_zeroing_entries = false);
140 
150  virtual void
151  reinit(const IndexSet &locally_stored_indices,
152  const bool omit_zeroing_entries = false) override;
153 
154 
159  virtual void
161  const bool omit_zeroing_entries = false) override;
162 
169  bool
170  has_ghost_elements() const;
171 
176  operator=(const Vector<Number> &in_vector);
177 
181  template <typename Number2>
183  operator=(const Vector<Number2> &in_vector);
184 
189  virtual Vector<Number> &
190  operator=(const Number s) override;
191 
195  virtual Vector<Number> &
196  operator*=(const Number factor) override;
197 
201  virtual Vector<Number> &
202  operator/=(const Number factor) override;
203 
207  virtual Vector<Number> &
208  operator+=(const VectorSpaceVector<Number> &V) override;
209 
213  virtual Vector<Number> &
214  operator-=(const VectorSpaceVector<Number> &V) override;
215 
219  virtual Number operator*(const VectorSpaceVector<Number> &V) const override;
220 
224  virtual void
225  import(
226  const ReadWriteVector<Number> & V,
227  VectorOperation::values operation,
228  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
229  std::shared_ptr<const CommunicationPatternBase>()) override;
230 
234  virtual void
235  add(const Number a) override;
236 
240  virtual void
241  add(const Number a, const VectorSpaceVector<Number> &V) override;
242 
247  virtual void
248  add(const Number a,
250  const Number b,
251  const VectorSpaceVector<Number> &W) override;
252 
257  virtual void
258  sadd(const Number s,
259  const Number a,
260  const VectorSpaceVector<Number> &V) override;
261 
267  virtual void
268  scale(const VectorSpaceVector<Number> &scaling_factors) override;
269 
273  virtual void
274  equ(const Number a, const VectorSpaceVector<Number> &V) override;
275 
279  virtual bool
280  all_zero() const override;
281 
285  virtual value_type
286  mean_value() const override;
287 
292  virtual typename VectorSpaceVector<Number>::real_type
293  l1_norm() const override;
294 
299  virtual typename VectorSpaceVector<Number>::real_type
300  l2_norm() const override;
301 
306  virtual typename VectorSpaceVector<Number>::real_type
307  linfty_norm() const override;
308 
329  virtual Number
330  add_and_dot(const Number a,
332  const VectorSpaceVector<Number> &W) override;
333 
338  virtual size_type
339  size() const override;
340 
352  virtual ::IndexSet
353  locally_owned_elements() const override;
354 
358  virtual void
359  print(std::ostream & out,
360  const unsigned int precision = 3,
361  const bool scientific = true,
362  const bool across = true) const override;
363 
372  void
373  print_as_numpy_array(std::ostream & out,
374  const unsigned int precision = 9) const;
375 
381  void
382  block_write(std::ostream &out) const;
383 
395  void
396  block_read(std::istream &in);
397 
401  virtual std::size_t
402  memory_consumption() const override;
403 
410 
411  private:
417  template <typename Archive>
418  void
419  serialize(Archive &ar, const unsigned int version);
420 
422 
423  // Make all other ReadWriteVector types friends.
424  template <typename Number2>
425  friend class Vector;
426  };
427 
429  /*--------------------------- Inline functions ----------------------------*/
430 
431  template <typename Number>
433  : ReadWriteVector<Number>(V)
434  {}
435 
436 
437 
438  template <typename Number>
440  : ReadWriteVector<Number>(n)
441  {}
442 
443 
444 
445  template <typename Number>
446  template <typename InputIterator>
447  inline Vector<Number>::Vector(const InputIterator first,
448  const InputIterator last)
449  {
450  this->reinit(complete_index_set(std::distance(first, last)), true);
451  std::copy(first, last, this->begin());
452  }
453 
454 
455 
456  template <typename Number>
457  inline typename Vector<Number>::size_type
459  {
461  }
462 
463 
464 
465  template <typename Number>
466  inline ::IndexSet
468  {
470  }
471 
472 
473 
474  template <typename Number>
475  inline void
476  Vector<Number>::print(std::ostream & out,
477  const unsigned int precision,
478  const bool scientific,
479  const bool) const
480  {
481  ReadWriteVector<Number>::print(out, precision, scientific);
482  }
483 
484 
485 
486  template <typename Number>
487  template <typename Archive>
488  inline void
489  Vector<Number>::serialize(Archive &ar, const unsigned int)
490  {
491  size_type current_size = this->size();
492  ar &static_cast<Subscriptor &>(*this);
493  ar & this->stored_elements;
494  // If necessary, resize the vector during a read operation
495  if (this->size() != current_size)
496  this->reinit(this->size());
497  ar &boost::serialization::make_array(this->values.get(), this->size());
498  }
499 
500 
501 
502  template <typename Number>
503  inline std::size_t
505  {
507  }
508 } // end of namespace LinearAlgebra
509 
510 
516 template <typename Number>
517 struct is_serial_vector<LinearAlgebra::Vector<Number>> : std::true_type
518 {};
519 
520 #ifndef DOXYGEN
521 /*----------------------- Inline functions ----------------------------------*/
522 
523 namespace LinearAlgebra
524 {
525  template <typename Number>
526  inline bool
528  {
529  return false;
530  }
531 } // namespace LinearAlgebra
532 
533 #endif
534 
535 
537 
538 #ifdef DEAL_II_MSVC
539 # include <deal.II/lac/la_vector.templates.h>
540 #endif
541 
542 #endif
LinearAlgebra::Vector::size_type
types::global_dof_index size_type
Definition: la_vector.h:83
LinearAlgebra::Vector::l2_norm
virtual VectorSpaceVector< Number >::real_type l2_norm() const override
IndexSet
Definition: index_set.h:74
LinearAlgebra::Vector::access
friend class boost::serialization::access
Definition: la_vector.h:421
LinearAlgebra::Vector::print_as_numpy_array
void print_as_numpy_array(std::ostream &out, const unsigned int precision=9) const
LinearAlgebraDealII::Vector
Vector< double > Vector
Definition: generic_linear_algebra.h:43
LinearAlgebra::Vector::block_read
void block_read(std::istream &in)
LinearAlgebra::ReadWriteVector::memory_consumption
std::size_t memory_consumption() const
LinearAlgebra
Definition: communication_pattern_base.h:30
LinearAlgebra::Vector::sadd
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
LinearAlgebra::Vector::mean_value
virtual value_type mean_value() const override
LAPACKSupport::V
static const char V
Definition: lapack_support.h:175
LinearAlgebra::Vector::scale
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
AlignedVector::size
size_type size() const
LinearAlgebra::Vector::Vector
friend class Vector
Definition: la_vector.h:425
LinearAlgebra::Vector::operator/=
virtual Vector< Number > & operator/=(const Number factor) override
LinearAlgebra::Vector::operator*=
virtual Vector< Number > & operator*=(const Number factor) override
LinearAlgebra::Vector::block_write
void block_write(std::ostream &out) const
Vector::size
size_type size() const
LinearAlgebra::Vector::operator=
Vector< Number > & operator=(const Vector< Number > &in_vector)
LinearAlgebra::VectorSpaceVector::real_type
typename numbers::NumberTraits< Number >::real_type real_type
Definition: vector_space_vector.h:62
LinearAlgebra::Vector::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: la_vector.h:489
vector_space_vector.h
Subscriptor
Definition: subscriptor.h:62
LinearAlgebra::Vector::equ
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
LinearAlgebra::Vector::operator-=
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
is_serial_vector
Definition: vector_type_traits.h:49
LinearAlgebra::Vector::value_type
typename ReadWriteVector< Number >::value_type value_type
Definition: la_vector.h:84
LinearAlgebra::Vector::all_zero
virtual bool all_zero() const override
vector_operation.h
types::global_dof_index
unsigned int global_dof_index
Definition: types.h:76
LinearAlgebra::ReadWriteVector::print
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true) const
TrilinosWrappers::internal::begin
VectorType::value_type * begin(VectorType &V)
Definition: trilinos_sparse_matrix.cc:51
read_write_vector.h
internal::reinit
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:621
index_set.h
vector_type_traits.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
LinearAlgebra::Vector::has_ghost_elements
bool has_ghost_elements() const
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorOperation::values
values
Definition: vector_operation.h:40
LinearAlgebra::Vector::operator+=
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
LinearAlgebra::ReadWriteVector::value_type
Number value_type
Definition: read_write_vector.h:139
LinearAlgebra::ReadWriteVector
Definition: read_write_vector.h:131
LinearAlgebra::Vector::ExcVectorTypeNotCompatible
static ::ExceptionBase & ExcVectorTypeNotCompatible()
exceptions.h
complete_index_set
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1014
LinearAlgebra::Vector::linfty_norm
virtual VectorSpaceVector< Number >::real_type linfty_norm() const override
Vector::values
AlignedVector< Number > values
Definition: vector.h:995
LinearAlgebra::Vector::locally_owned_elements
virtual ::IndexSet locally_owned_elements() const override
Definition: la_vector.h:467
LinearAlgebra::Vector::print
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
Definition: la_vector.h:476
LinearAlgebra::Vector::reinit
virtual void reinit(const size_type size, const bool omit_zeroing_entries=false) override
LinearAlgebra::Vector::memory_consumption
virtual std::size_t memory_consumption() const override
Definition: la_vector.h:504
LinearAlgebra::VectorSpaceVector
Definition: vector_space_vector.h:57
DeclException0
#define DeclException0(Exception0)
Definition: exceptions.h:473
LinearAlgebra::Vector::l1_norm
virtual VectorSpaceVector< Number >::real_type l1_norm() const override
LinearAlgebra::Vector::add_and_dot
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
config.h
LinearAlgebra::Vector::size
virtual size_type size() const override
Definition: la_vector.h:458
LinearAlgebra::ReadWriteVector::size
size_type size() const
LinearAlgebra::Vector::operator*
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
logstream.h
first
Point< 2 > first
Definition: grid_out.cc:4352
LinearAlgebra::Vector
Definition: la_vector.h:79
internal::VectorOperations::copy
void copy(const T *begin, const T *end, U *dest)
Definition: vector_operations_internal.h:67
LinearAlgebra::Vector::add
virtual void add(const Number a) override