Reference documentation for deal.II version Git 1c2f3d7ba8 2021-05-16 10:03:46 +0200
\(\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 {
76  template <typename Number>
77  class Vector : public ReadWriteVector<Number>,
78  public VectorSpaceVector<Number>
79  {
80  public:
83 
87  Vector() = default;
88 
93  Vector(const Vector<Number> &V);
94 
105  explicit Vector(const size_type n);
106 
111  template <typename InputIterator>
112  Vector(const InputIterator first, const InputIterator last);
113 
122  virtual void
123  reinit(const size_type size,
124  const bool omit_zeroing_entries = false) override;
125 
134  template <typename Number2>
135  void
136  reinit(const ReadWriteVector<Number2> &in_vector,
137  const bool omit_zeroing_entries = false);
138 
148  virtual void
149  reinit(const IndexSet &locally_stored_indices,
150  const bool omit_zeroing_entries = false) override;
151 
152 
157  virtual void
159  const bool omit_zeroing_entries = false) override;
160 
167  bool
168  has_ghost_elements() const;
169 
174  operator=(const Vector<Number> &in_vector);
175 
179  template <typename Number2>
181  operator=(const Vector<Number2> &in_vector);
182 
187  virtual Vector<Number> &
188  operator=(const Number s) override;
189 
193  virtual Vector<Number> &
194  operator*=(const Number factor) override;
195 
199  virtual Vector<Number> &
200  operator/=(const Number factor) override;
201 
205  virtual Vector<Number> &
206  operator+=(const VectorSpaceVector<Number> &V) override;
207 
211  virtual Vector<Number> &
212  operator-=(const VectorSpaceVector<Number> &V) override;
213 
217  virtual Number operator*(const VectorSpaceVector<Number> &V) const override;
218 
222  virtual void
223  import(const ReadWriteVector<Number> &V,
224  VectorOperation::values operation,
225  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
226  communication_pattern = {}) override;
227 
231  virtual void
232  add(const Number a) override;
233 
237  virtual void
238  add(const Number a, const VectorSpaceVector<Number> &V) override;
239 
244  virtual void
245  add(const Number a,
246  const VectorSpaceVector<Number> &V,
247  const Number b,
248  const VectorSpaceVector<Number> &W) override;
249 
254  virtual void
255  sadd(const Number s,
256  const Number a,
257  const VectorSpaceVector<Number> &V) override;
258 
264  virtual void
265  scale(const VectorSpaceVector<Number> &scaling_factors) override;
266 
270  virtual void
271  equ(const Number a, const VectorSpaceVector<Number> &V) override;
272 
276  virtual bool
277  all_zero() const override;
278 
282  virtual value_type
283  mean_value() const override;
284 
289  virtual typename VectorSpaceVector<Number>::real_type
290  l1_norm() const override;
291 
296  virtual typename VectorSpaceVector<Number>::real_type
297  l2_norm() const override;
298 
303  virtual typename VectorSpaceVector<Number>::real_type
304  linfty_norm() const override;
305 
326  virtual Number
327  add_and_dot(const Number a,
328  const VectorSpaceVector<Number> &V,
329  const VectorSpaceVector<Number> &W) override;
330 
335  virtual size_type
336  size() const override;
337 
349  virtual ::IndexSet
350  locally_owned_elements() const override;
351 
355  virtual void
356  print(std::ostream & out,
357  const unsigned int precision = 3,
358  const bool scientific = true,
359  const bool across = true) const override;
360 
369  void
370  print_as_numpy_array(std::ostream & out,
371  const unsigned int precision = 9) const;
372 
378  void
379  block_write(std::ostream &out) const;
380 
392  void
393  block_read(std::istream &in);
394 
398  virtual std::size_t
399  memory_consumption() const override;
400 
406  template <typename Archive>
407  void
408  serialize(Archive &ar, const unsigned int version);
409 
416 
417  private:
418  // Make all other ReadWriteVector types friends.
419  template <typename Number2>
420  friend class Vector;
421  };
422 
424  /*--------------------------- Inline functions ----------------------------*/
425 
426  template <typename Number>
428  : ReadWriteVector<Number>(V)
429  {}
430 
431 
432 
433  template <typename Number>
435  : ReadWriteVector<Number>(n)
436  {}
437 
438 
439 
440  template <typename Number>
441  template <typename InputIterator>
442  inline Vector<Number>::Vector(const InputIterator first,
443  const InputIterator last)
444  {
445  this->reinit(complete_index_set(std::distance(first, last)), true);
446  std::copy(first, last, this->begin());
447  }
448 
449 
450 
451  template <typename Number>
452  inline typename Vector<Number>::size_type
454  {
456  }
457 
458 
459 
460  template <typename Number>
461  inline ::IndexSet
463  {
465  }
466 
467 
468 
469  template <typename Number>
470  inline void
471  Vector<Number>::print(std::ostream & out,
472  const unsigned int precision,
473  const bool scientific,
474  const bool) const
475  {
476  ReadWriteVector<Number>::print(out, precision, scientific);
477  }
478 
479 
480 
481  template <typename Number>
482  template <typename Archive>
483  inline void
484  Vector<Number>::serialize(Archive &ar, const unsigned int)
485  {
486  size_type current_size = this->size();
487  ar &static_cast<Subscriptor &>(*this);
488  ar & this->stored_elements;
489  // If necessary, resize the vector during a read operation
490  if (this->size() != current_size)
491  this->reinit(this->size());
492  ar &boost::serialization::make_array(this->values.get(), this->size());
493  }
494 
495 
496 
497  template <typename Number>
498  inline std::size_t
500  {
502  }
503 } // end of namespace LinearAlgebra
504 
505 
509 template <typename Number>
510 struct is_serial_vector<LinearAlgebra::Vector<Number>> : std::true_type
511 {};
512 
513 #ifndef DOXYGEN
514 /*----------------------- Inline functions ----------------------------------*/
515 
516 namespace LinearAlgebra
517 {
518  template <typename Number>
519  inline bool
521  {
522  return false;
523  }
524 } // namespace LinearAlgebra
525 
526 #endif
527 
528 
530 
531 #ifdef DEAL_II_MSVC
532 # include <deal.II/lac/la_vector.templates.h>
533 #endif
534 
535 #endif
void block_write(std::ostream &out) const
virtual VectorSpaceVector< Number >::real_type linfty_norm() const override
std::unique_ptr< Number[], decltype(std::free) * > values
virtual void add(const Number a) override
std::size_t memory_consumption() const
static const char V
Vector< Number > & operator=(const Vector< Number > &in_vector)
virtual Vector< Number > & operator*=(const Number factor) override
virtual std::size_t memory_consumption() const override
Definition: la_vector.h:499
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
static ::ExceptionBase & ExcVectorTypeNotCompatible()
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
virtual ::IndexSet locally_owned_elements() const override
Definition: la_vector.h:462
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual void reinit(const size_type size, const bool omit_zeroing_entries=false) 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:471
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
virtual Vector< Number > & operator/=(const Number factor) override
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
void print_as_numpy_array(std::ostream &out, const unsigned int precision=9) const
virtual bool all_zero() const override
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true) const
virtual size_type size() const override
Definition: la_vector.h:453
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
Point< 2 > first
Definition: grid_out.cc:4587
typename numbers::NumberTraits< Number >::real_type real_type
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1013
unsigned int global_dof_index
Definition: types.h:76
virtual VectorSpaceVector< Number >::real_type l1_norm() const override
virtual VectorSpaceVector< Number >::real_type l2_norm() const override
void block_read(std::istream &in)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395
virtual value_type mean_value() const override
typename ReadWriteVector< Number >::value_type value_type
Definition: la_vector.h:82
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
void serialize(Archive &ar, const unsigned int version)
Definition: la_vector.h:484
bool has_ghost_elements() const
void copy(const T *begin, const T *end, U *dest)