Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
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.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 
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/index_set.h>
24 #include <deal.II/base/logstream.h>
25 
26 #include <deal.II/lac/read_write_vector.h>
27 #include <deal.II/lac/vector_operation.h>
28 #include <deal.II/lac/vector_space_vector.h>
29 #include <deal.II/lac/vector_type_traits.h>
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 
47 DEAL_II_NAMESPACE_OPEN
48 
63 namespace LinearAlgebra
64 {
78  template <typename Number>
79  class Vector : public ReadWriteVector<Number>,
80  public VectorSpaceVector<Number>
81  {
82  public:
83  using size_type = types::global_dof_index;
84  using value_type = typename ReadWriteVector<Number>::value_type;
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 
167  operator=(const Vector<Number> &in_vector);
168 
172  template <typename Number2>
174  operator=(const Vector<Number2> &in_vector);
175 
180  virtual Vector<Number> &
181  operator=(const Number s) override;
182 
186  virtual Vector<Number> &
187  operator*=(const Number factor) override;
188 
192  virtual Vector<Number> &
193  operator/=(const Number factor) override;
194 
198  virtual Vector<Number> &
199  operator+=(const VectorSpaceVector<Number> &V) override;
200 
204  virtual Vector<Number> &
205  operator-=(const VectorSpaceVector<Number> &V) override;
206 
210  virtual Number operator*(const VectorSpaceVector<Number> &V) const override;
211 
215  virtual void
216  import(
217  const ReadWriteVector<Number> & V,
218  VectorOperation::values operation,
219  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
220  std::shared_ptr<const CommunicationPatternBase>()) override;
221 
225  virtual void
226  add(const Number a) override;
227 
231  virtual void
232  add(const Number a, const VectorSpaceVector<Number> &V) override;
233 
238  virtual void
239  add(const Number a,
240  const VectorSpaceVector<Number> &V,
241  const Number b,
242  const VectorSpaceVector<Number> &W) override;
243 
248  virtual void
249  sadd(const Number s,
250  const Number a,
251  const VectorSpaceVector<Number> &V) override;
252 
258  virtual void
259  scale(const VectorSpaceVector<Number> &scaling_factors) override;
260 
264  virtual void
265  equ(const Number a, const VectorSpaceVector<Number> &V) override;
266 
270  virtual bool
271  all_zero() const override;
272 
276  virtual value_type
277  mean_value() const override;
278 
283  virtual typename VectorSpaceVector<Number>::real_type
284  l1_norm() const override;
285 
290  virtual typename VectorSpaceVector<Number>::real_type
291  l2_norm() const override;
292 
297  virtual typename VectorSpaceVector<Number>::real_type
298  linfty_norm() const override;
299 
320  virtual Number
321  add_and_dot(const Number a,
322  const VectorSpaceVector<Number> &V,
323  const VectorSpaceVector<Number> &W) override;
324 
329  virtual size_type
330  size() const override;
331 
343  virtual ::IndexSet
344  locally_owned_elements() const override;
345 
349  virtual void
350  print(std::ostream & out,
351  const unsigned int precision = 3,
352  const bool scientific = true,
353  const bool across = true) const override;
354 
360  void
361  block_write(std::ostream &out) const;
362 
374  void
375  block_read(std::istream &in);
376 
380  virtual std::size_t
381  memory_consumption() const override;
382 
389 
390  private:
396  template <typename Archive>
397  void
398  serialize(Archive &ar, const unsigned int version);
399 
400  friend class boost::serialization::access;
401 
405  template <typename Number2>
406  friend class Vector;
407  };
408 
410  /*--------------------------- Inline functions ----------------------------*/
411 
412  template <typename Number>
414  : ReadWriteVector<Number>(V)
415  {}
416 
417 
418 
419  template <typename Number>
420  inline Vector<Number>::Vector(const size_type n)
421  : ReadWriteVector<Number>(n)
422  {}
423 
424 
425 
426  template <typename Number>
427  template <typename InputIterator>
428  inline Vector<Number>::Vector(const InputIterator first,
429  const InputIterator last)
430  {
431  this->reinit(complete_index_set(std::distance(first, last)), true);
432  std::copy(first, last, this->begin());
433  }
434 
435 
436 
437  template <typename Number>
438  inline typename Vector<Number>::size_type
440  {
442  }
443 
444 
445 
446  template <typename Number>
447  inline ::IndexSet
449  {
451  }
452 
453 
454 
455  template <typename Number>
456  inline void
457  Vector<Number>::print(std::ostream & out,
458  const unsigned int precision,
459  const bool scientific,
460  const bool) const
461  {
462  ReadWriteVector<Number>::print(out, precision, scientific);
463  }
464 
465 
466 
467  template <typename Number>
468  template <typename Archive>
469  inline void
470  Vector<Number>::serialize(Archive &ar, const unsigned int)
471  {
472  size_type current_size = this->size();
473  ar &static_cast<Subscriptor &>(*this);
474  ar & this->stored_elements;
475  // If necessary, resize the vector during a read operation
476  if (this->size() != current_size)
477  this->reinit(this->size());
478  ar &boost::serialization::make_array(this->values.get(), this->size());
479  }
480 
481 
482 
483  template <typename Number>
484  inline std::size_t
486  {
488  }
489 } // end of namespace LinearAlgebra
490 
491 
497 template <typename Number>
498 struct is_serial_vector<LinearAlgebra::Vector<Number>> : std::true_type
499 {};
500 
501 
502 DEAL_II_NAMESPACE_CLOSE
503 
504 #ifdef DEAL_II_MSVC
505 # include <deal.II/lac/la_vector.templates.h>
506 #endif
507 
508 #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:485
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
static ::ExceptionBase & ExcVectorTypeNotCompatible()
LinearAlgebra::distributed::Vector< Number > Vector
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
virtual ::IndexSet locally_owned_elements() const override
Definition: la_vector.h:448
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:457
#define DeclException0(Exception0)
Definition: exceptions.h:473
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:439
iterator begin()
unsigned int global_dof_index
Definition: types.h:89
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)
AlignedVector< Number > values
Definition: vector.h:1014
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:470