Reference documentation for deal.II version GIT 1e9e64a91d 2022-09-28 19:20:02+00:00
\(\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 - 2021 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 {
77  template <typename Number>
78  class Vector : public ReadWriteVector<Number>,
79  public VectorSpaceVector<Number>
80  {
81  public:
84 
88  Vector() = default;
89 
94  Vector(const Vector<Number> &V);
95 
106  explicit Vector(const size_type n);
107 
112  template <typename InputIterator>
113  Vector(const InputIterator first, const InputIterator last);
114 
123  virtual void
125  const bool omit_zeroing_entries = false) override;
126 
135  template <typename Number2>
136  void
138  const bool omit_zeroing_entries = false);
139 
149  virtual void
150  reinit(const IndexSet &locally_stored_indices,
151  const bool omit_zeroing_entries = false) override;
152 
153 
158  virtual void
160  const bool omit_zeroing_entries = false) override;
161 
168  bool
170 
175  operator=(const Vector<Number> &in_vector);
176 
180  template <typename Number2>
182  operator=(const Vector<Number2> &in_vector);
183 
188  virtual Vector<Number> &
189  operator=(const Number s) override;
190 
194  virtual Vector<Number> &
195  operator*=(const Number factor) override;
196 
200  virtual Vector<Number> &
201  operator/=(const Number factor) override;
202 
206  virtual Vector<Number> &
208 
212  virtual Vector<Number> &
214 
218  virtual Number
219  operator*(const VectorSpaceVector<Number> &V) const override;
220 
224  virtual void
225  import(const ReadWriteVector<Number> &V,
226  VectorOperation::values operation,
227  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
228  communication_pattern = {}) override;
229 
233  virtual void
234  add(const Number a) override;
235 
239  virtual void
240  add(const Number a, const VectorSpaceVector<Number> &V) override;
241 
246  virtual void
247  add(const Number a,
249  const Number b,
250  const VectorSpaceVector<Number> &W) override;
251 
256  virtual void
257  sadd(const Number s,
258  const Number a,
259  const VectorSpaceVector<Number> &V) override;
260 
266  virtual void
267  scale(const VectorSpaceVector<Number> &scaling_factors) override;
268 
272  virtual void
273  equ(const Number a, const VectorSpaceVector<Number> &V) override;
274 
278  virtual bool
279  all_zero() const override;
280 
284  virtual value_type
285  mean_value() const override;
286 
291  virtual typename VectorSpaceVector<Number>::real_type
292  l1_norm() const override;
293 
298  virtual typename VectorSpaceVector<Number>::real_type
299  l2_norm() const override;
300 
305  virtual typename VectorSpaceVector<Number>::real_type
306  linfty_norm() const override;
307 
328  virtual Number
329  add_and_dot(const Number a,
331  const VectorSpaceVector<Number> &W) override;
332 
337  virtual size_type
338  size() const override;
339 
351  virtual ::IndexSet
352  locally_owned_elements() const override;
353 
357  virtual void
358  print(std::ostream & out,
359  const unsigned int precision = 3,
360  const bool scientific = true,
361  const bool across = true) const override;
362 
371  void
372  print_as_numpy_array(std::ostream & out,
373  const unsigned int precision = 9) const;
374 
380  void
381  block_write(std::ostream &out) const;
382 
394  void
395  block_read(std::istream &in);
396 
400  virtual std::size_t
401  memory_consumption() const override;
402 
408  template <typename Archive>
409  void
410  serialize(Archive &ar, const unsigned int version);
411 
418 
419  private:
420  // Make all other ReadWriteVector types friends.
421  template <typename Number2>
422  friend class Vector;
423  };
424 
426  /*--------------------------- Inline functions ----------------------------*/
427 
428  template <typename Number>
430  : ReadWriteVector<Number>(V)
431  {}
432 
433 
434 
435  template <typename Number>
437  : ReadWriteVector<Number>(n)
438  {}
439 
440 
441 
442  template <typename Number>
443  template <typename InputIterator>
444  inline Vector<Number>::Vector(const InputIterator first,
445  const InputIterator last)
446  {
447  this->reinit(complete_index_set(std::distance(first, last)), true);
448  std::copy(first, last, this->begin());
449  }
450 
451 
452 
453  template <typename Number>
454  inline typename Vector<Number>::size_type
456  {
458  }
459 
460 
461 
462  template <typename Number>
463  inline ::IndexSet
465  {
467  }
468 
469 
470 
471  template <typename Number>
472  inline void
473  Vector<Number>::print(std::ostream & out,
474  const unsigned int precision,
475  const bool scientific,
476  const bool) const
477  {
478  ReadWriteVector<Number>::print(out, precision, scientific);
479  }
480 
481 
482 
483  template <typename Number>
484  template <typename Archive>
485  inline void
486  Vector<Number>::serialize(Archive &ar, const unsigned int)
487  {
488  size_type current_size = this->size();
489  ar &static_cast<Subscriptor &>(*this);
490  ar &this->stored_elements;
491  // If necessary, resize the vector during a read operation
492  if (this->size() != current_size)
493  this->reinit(this->size());
494  ar &boost::serialization::make_array(this->values.get(), this->size());
495  }
496 
497 
498 
499  template <typename Number>
500  inline std::size_t
502  {
504  }
505 } // end of namespace LinearAlgebra
506 
507 
511 template <typename Number>
512 struct is_serial_vector<LinearAlgebra::Vector<Number>> : std::true_type
513 {};
514 
515 #ifndef DOXYGEN
516 /*----------------------- Inline functions ----------------------------------*/
517 
518 namespace LinearAlgebra
519 {
520  template <typename Number>
521  inline bool
523  {
524  return false;
525  }
526 } // namespace LinearAlgebra
527 
528 #endif
529 
530 
532 
533 #ifdef DEAL_II_MSVC
534 # include <deal.II/lac/la_vector.templates.h>
535 #endif
536 
537 #endif
std::size_t memory_consumption() const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true) const
typename numbers::NumberTraits< Number >::real_type real_type
void print_as_numpy_array(std::ostream &out, const unsigned int precision=9) const
virtual VectorSpaceVector< Number >::real_type l2_norm() const override
virtual void reinit(const IndexSet &locally_stored_indices, const bool omit_zeroing_entries=false) override
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual Vector< Number > & operator=(const Number s) override
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual void reinit(const size_type size, const bool omit_zeroing_entries=false) override
virtual void add(const Number a, const VectorSpaceVector< Number > &V, const Number b, const VectorSpaceVector< Number > &W) override
void serialize(Archive &ar, const unsigned int version)
Definition: la_vector.h:486
virtual ::IndexSet locally_owned_elements() const override
Definition: la_vector.h:464
Vector< Number > & operator=(const Vector< Number > &in_vector)
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual VectorSpaceVector< Number >::real_type l1_norm() const override
types::global_dof_index size_type
Definition: la_vector.h:82
friend class Vector
Definition: la_vector.h:422
virtual value_type mean_value() const override
virtual void add(const Number a, const VectorSpaceVector< Number > &V) override
virtual bool all_zero() const override
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:473
virtual void reinit(const VectorSpaceVector< Number > &V, const bool omit_zeroing_entries=false) override
void block_read(std::istream &in)
Vector< Number > & operator=(const Vector< Number2 > &in_vector)
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual Vector< Number > & operator/=(const Number factor) override
virtual VectorSpaceVector< Number >::real_type linfty_norm() const override
void block_write(std::ostream &out) const
typename ReadWriteVector< Number >::value_type value_type
Definition: la_vector.h:83
virtual std::size_t memory_consumption() const override
Definition: la_vector.h:501
virtual void add(const Number a) override
virtual size_type size() const override
Definition: la_vector.h:455
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
bool has_ghost_elements() const
virtual Vector< Number > & operator*=(const Number factor) override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
void reinit(const ReadWriteVector< Number2 > &in_vector, const bool omit_zeroing_entries=false)
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
Definition: vector.h:109
size_type size() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:457
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:458
Point< 2 > first
Definition: grid_out.cc:4605
static ::ExceptionBase & ExcVectorTypeNotCompatible()
#define DeclException0(Exception0)
Definition: exceptions.h:464
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1054
static const char V
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * begin(VectorType &V)
void copy(const T *begin, const T *end, U *dest)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
unsigned int global_dof_index
Definition: types.h:81