Reference documentation for deal.II version 9.0.0
la_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2015 - 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/logstream.h>
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/index_set.h>
24 #include <deal.II/lac/read_write_vector.h>
25 #include <deal.II/lac/vector_operation.h>
26 #include <deal.II/lac/vector_space_vector.h>
27 #include <deal.II/lac/vector_type_traits.h>
28 
29 // boost::serialization::make_array used to be in array.hpp, but was
30 // moved to a different file in BOOST 1.64
31 #include <boost/version.hpp>
32 #if BOOST_VERSION >= 106400
33 # include <boost/serialization/array_wrapper.hpp>
34 #else
35 # include <boost/serialization/array.hpp>
36 #endif
37 #include <boost/serialization/split_member.hpp>
38 
39 #include <cstdio>
40 #include <iostream>
41 #include <cstring>
42 #include <vector>
43 
44 
45 DEAL_II_NAMESPACE_OPEN
46 
47 namespace LinearAlgebra
48 {
62  template <typename Number>
63  class Vector : public ReadWriteVector<Number>, public VectorSpaceVector<Number>
64  {
65  public:
66  typedef types::global_dof_index size_type;
67  typedef typename ReadWriteVector<Number>::value_type value_type;
68 
72  Vector() = default;
73 
78  Vector(const Vector<Number> &V);
79 
90  explicit Vector(const size_type n);
91 
96  template <typename InputIterator>
97  Vector(const InputIterator first, const InputIterator last);
98 
107  virtual void reinit(const size_type size,
108  const bool omit_zeroing_entries = false) override;
109 
118  template <typename Number2>
119  void reinit(const ReadWriteVector<Number2> &in_vector,
120  const bool omit_zeroing_entries = false);
121 
131  virtual void reinit(const IndexSet &locally_stored_indices,
132  const bool omit_zeroing_entries = false) override;
133 
134 
139  virtual void reinit(const VectorSpaceVector<Number> &V,
140  const bool omit_zeroing_entries = false) override;
141 
145  Vector<Number> &operator= (const Vector<Number> &in_vector);
146 
150  template <typename Number2>
151  Vector<Number> &operator= (const Vector<Number2> &in_vector);
152 
157  virtual Vector<Number> &operator= (const Number s) override;
158 
162  virtual Vector<Number> &operator*= (const Number factor) override;
163 
167  virtual Vector<Number> &operator/= (const Number factor) override;
168 
172  virtual Vector<Number> &operator+= (const VectorSpaceVector<Number> &V) override;
173 
177  virtual Vector<Number> &operator-= (const VectorSpaceVector<Number> &V) override;
178 
182  virtual Number operator* (const VectorSpaceVector<Number> &V) const override;
183 
187  virtual void import(const ReadWriteVector<Number> &V,
188  VectorOperation::values operation,
189  std::shared_ptr<const CommunicationPatternBase>
190  communication_pattern =
191  std::shared_ptr<const CommunicationPatternBase>()) override;
192 
196  virtual void add(const Number a) override;
197 
201  virtual void add(const Number a, const VectorSpaceVector<Number> &V) override;
202 
207  virtual void add(const Number a, const VectorSpaceVector<Number> &V,
208  const Number b, const VectorSpaceVector<Number> &W) override;
209 
214  virtual void sadd(const Number s, const Number a,
215  const VectorSpaceVector<Number> &V) override;
216 
222  virtual void scale(const VectorSpaceVector<Number> &scaling_factors) override;
223 
227  virtual void equ(const Number a, const VectorSpaceVector<Number> &V) override;
228 
232  virtual bool all_zero() const override;
233 
237  virtual value_type mean_value() const override;
238 
243  virtual typename VectorSpaceVector<Number>::real_type l1_norm() const override;
244 
249  virtual typename VectorSpaceVector<Number>::real_type l2_norm() const override;
250 
255  virtual typename VectorSpaceVector<Number>::real_type linfty_norm() const override;
256 
276  virtual Number add_and_dot(const Number a,
277  const VectorSpaceVector<Number> &V,
278  const VectorSpaceVector<Number> &W) override;
279 
284  virtual size_type size() const override;
285 
297  virtual ::IndexSet locally_owned_elements() const override;
298 
302  virtual void print(std::ostream &out,
303  const unsigned int precision=3,
304  const bool scientific=true,
305  const bool across=true) const override;
306 
312  void block_write (std::ostream &out) const;
313 
325  void block_read (std::istream &in);
326 
330  virtual std::size_t memory_consumption() const override;
331 
338 
339  private:
345  template <typename Archive>
346  void serialize(Archive &ar, const unsigned int version);
347 
348  friend class boost::serialization::access;
349 
353  template <typename Number2> friend class Vector;
354  };
355 
357  /*----------------------- Inline functions ----------------------------------*/
358 
359  template <typename Number>
360  inline
362  :
363  ReadWriteVector<Number>(V)
364  {}
365 
366 
367 
368  template <typename Number>
369  inline
370  Vector<Number>::Vector(const size_type n)
371  :
372  ReadWriteVector<Number>(n)
373  {}
374 
375 
376 
377  template <typename Number>
378  template <typename InputIterator>
379  inline
380  Vector<Number>::Vector(const InputIterator first, const InputIterator last)
381  {
382  this->reinit(complete_index_set(std::distance (first, last)), true);
383  std::copy(first, last, this->begin());
384  }
385 
386 
387 
388  template <typename Number>
389  inline
390  typename Vector<Number>::size_type Vector<Number>::size() const
391  {
393  }
394 
395 
396 
397  template <typename Number>
398  inline
400  {
402  }
403 
404 
405 
406  template <typename Number>
407  inline
408  void Vector<Number>::print(std::ostream &out,
409  const unsigned int precision,
410  const bool scientific,
411  const bool) const
412  {
413  ReadWriteVector<Number>::print(out, precision, scientific);
414  }
415 
416 
417 
418  template <typename Number>
419  template <typename Archive>
420  inline
421  void Vector<Number>::serialize(Archive &ar, const unsigned int)
422  {
423  size_type current_size = this->size();
424  ar &static_cast<Subscriptor &>(*this);
425  ar &this->stored_elements;
426  // If necessary, resize the vector during a read operation
427  if (this->size()!=current_size)
428  this->reinit(this->size());
429  ar &boost::serialization::make_array(this->values.get(),this->size());
430  }
431 
432 
433 
434  template <typename Number>
435  inline
437  {
439  }
440 } // end of namespace LinearAlgebra
441 
442 
448 template <typename Number>
449 struct is_serial_vector< LinearAlgebra::Vector< Number > > : std::true_type
450 {
451 };
452 
453 
454 DEAL_II_NAMESPACE_CLOSE
455 
456 #ifdef DEAL_II_MSVC
457 #include <deal.II/lac/la_vector.templates.h>
458 #endif
459 
460 #endif
void block_write(std::ostream &out) const
virtual VectorSpaceVector< Number >::real_type linfty_norm() const override
virtual void add(const Number a) override
std::size_t memory_consumption() const
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:436
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:399
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
unsigned int global_dof_index
Definition: types.h:88
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:408
#define DeclException0(Exception0)
Definition: exceptions.h:323
virtual Vector< Number > & operator/=(const Number factor) override
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
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:390
iterator begin()
std::unique_ptr< Number[], decltype(&free)> values
Definition: vector.h:936
virtual VectorSpaceVector< Number >::real_type l1_norm() const override
virtual VectorSpaceVector< Number >::real_type l2_norm() const override
void block_read(std::istream &in)
size_type size() const
virtual value_type mean_value() const override
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
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:421