Reference documentation for deal.II version 8.5.1
la_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2015 - 2017 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_space_vector.h>
26 #include <deal.II/lac/vector_type_traits.h>
27 
28 // boost::serialization::make_array used to be in array.hpp, but was
29 // moved to a different file in BOOST 1.64
30 #include <boost/version.hpp>
31 #if BOOST_VERSION >= 106400
32 # include <boost/serialization/array_wrapper.hpp>
33 #else
34 # include <boost/serialization/array.hpp>
35 #endif
36 #include <boost/serialization/split_member.hpp>
37 
38 #include <cstdio>
39 #include <iostream>
40 #include <cstring>
41 #include <vector>
42 
43 
44 DEAL_II_NAMESPACE_OPEN
45 
46 namespace LinearAlgebra
47 {
61  template <typename Number>
62  class Vector : public ReadWriteVector<Number>, public VectorSpaceVector<Number>
63  {
64  public:
65  typedef types::global_dof_index size_type;
66  typedef typename ReadWriteVector<Number>::value_type value_type;
67 
71  Vector();
72 
77  Vector(const Vector<Number> &V);
78 
89  explicit Vector(const size_type n);
90 
95  template <typename InputIterator>
96  Vector(const InputIterator first, const InputIterator last);
97 
101  Vector<Number> &operator= (const Vector<Number> &in_vector);
102 
106  template <typename Number2>
107  Vector<Number> &operator= (const Vector<Number2> &in_vector);
108 
113  Vector<Number> &operator= (const Number s);
114 
118  virtual Vector<Number> &operator*= (const Number factor);
119 
123  virtual Vector<Number> &operator/= (const Number factor);
124 
129 
134 
138  virtual Number operator* (const VectorSpaceVector<Number> &V) const;
139 
143  virtual void import(const ReadWriteVector<Number> &V,
144  VectorOperation::values operation,
145  std_cxx11::shared_ptr<const CommunicationPatternBase>
146  communication_pattern =
147  std_cxx11::shared_ptr<const CommunicationPatternBase>());
148 
152  virtual void add(const Number a);
153 
157  virtual void add(const Number a, const VectorSpaceVector<Number> &V);
158 
163  virtual void add(const Number a, const VectorSpaceVector<Number> &V,
164  const Number b, const VectorSpaceVector<Number> &W);
165 
170  virtual void sadd(const Number s, const Number a,
171  const VectorSpaceVector<Number> &V);
172 
178  virtual void scale(const VectorSpaceVector<Number> &scaling_factors);
179 
183  virtual void equ(const Number a, const VectorSpaceVector<Number> &V);
184 
188  virtual value_type mean_value() const;
189 
194  virtual typename VectorSpaceVector<Number>::real_type l1_norm() const;
195 
200  virtual typename VectorSpaceVector<Number>::real_type l2_norm() const;
201 
206  virtual typename VectorSpaceVector<Number>::real_type linfty_norm() const;
207 
217  virtual Number add_and_dot(const Number a,
218  const VectorSpaceVector<Number> &V,
219  const VectorSpaceVector<Number> &W);
220 
225  virtual size_type size() const;
226 
238  virtual ::IndexSet locally_owned_elements() const;
239 
243  virtual void print(std::ostream &out,
244  const unsigned int precision=3,
245  const bool scientific=true,
246  const bool across=true) const;
252  void block_write (std::ostream &out) const;
253 
265  void block_read (std::istream &in);
266 
270  virtual std::size_t memory_consumption() const;
271 
278 
279  private:
285  template <typename Archive>
286  void serialize(Archive &ar, const unsigned int version);
287 
288  friend class boost::serialization::access;
289 
293  template <typename Number2> friend class Vector;
294  };
295 
297  /*----------------------- Inline functions ----------------------------------*/
298 
299  template <typename Number>
300  inline
302 
303 
304 
305  template <typename Number>
306  inline
308  :
309  ReadWriteVector<Number>(V)
310  {}
311 
312 
313 
314  template <typename Number>
315  inline
316  Vector<Number>::Vector(const size_type n)
317  :
318  ReadWriteVector<Number>(n)
319  {}
320 
321 
322 
323  template <typename Number>
324  template <typename InputIterator>
325  inline
326  Vector<Number>::Vector(const InputIterator first, const InputIterator last)
327  {
328  this->reinit(complete_index_set(std::distance (first, last)), true);
329  std::copy(first, last, this->begin());
330  }
331 
332 
333 
334  template <typename Number>
335  inline
336  typename Vector<Number>::size_type Vector<Number>::size() const
337  {
339  }
340 
341 
342 
343  template <typename Number>
344  inline
346  {
348  }
349 
350 
351 
352  template <typename Number>
353  inline
354  void Vector<Number>::print(std::ostream &out,
355  const unsigned int precision,
356  const bool scientific,
357  const bool) const
358  {
359  ReadWriteVector<Number>::print(out, precision, scientific);
360  }
361 
362 
363 
364  template <typename Number>
365  template <typename Archive>
366  inline
367  void Vector<Number>::serialize(Archive &ar, const unsigned int)
368  {
369  size_type current_size = this->size();
370  ar &static_cast<Subscriptor &>(*this);
371  ar &this->stored_elements;
372  // If necessary, resize the vector during a read operation
373  if (this->size()!=current_size)
374  this->reinit(this->size());
375  ar &boost::serialization::make_array(this->val,this->size());
376  }
377 
378 
379 
380  template <typename Number>
381  inline
383  {
385  }
386 } // end of namespace LinearAlgebra
387 
388 
394 template <typename Number>
395 struct is_serial_vector< LinearAlgebra::Vector< Number > > : std_cxx11::true_type
396 {
397 };
398 
399 
400 DEAL_II_NAMESPACE_CLOSE
401 
402 #ifdef DEAL_II_MSVC
403 #include <deal.II/lac/la_vector.templates.h>
404 #endif
405 
406 #endif
void block_write(std::ostream &out) const
virtual Vector< Number > & operator*=(const Number factor)
std::size_t memory_consumption() const
virtual void scale(const VectorSpaceVector< Number > &scaling_factors)
Vector< Number > & operator=(const Vector< Number > &in_vector)
static ::ExceptionBase & ExcVectorTypeNotCompatible()
virtual size_type size() const
Definition: la_vector.h:336
virtual VectorSpaceVector< Number >::real_type linfty_norm() const
virtual Number operator*(const VectorSpaceVector< Number > &V) const
unsigned int global_dof_index
Definition: types.h:88
virtual void equ(const Number a, const VectorSpaceVector< Number > &V)
std::size_t size() const
#define DeclException0(Exception0)
Definition: exceptions.h:541
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W)
virtual Vector< Number > & operator/=(const Number factor)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true) const
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V)
iterator begin()
virtual value_type mean_value() const
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
Definition: la_vector.h:354
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V)
virtual VectorSpaceVector< Number >::real_type l1_norm() const
void block_read(std::istream &in)
virtual ::IndexSet locally_owned_elements() const
Definition: la_vector.h:345
virtual void add(const Number a)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
virtual std::size_t memory_consumption() const
Definition: la_vector.h:382
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V)
Number * val
Definition: vector.h:1018
virtual VectorSpaceVector< Number >::real_type l2_norm() const
void serialize(Archive &ar, const unsigned int version)
Definition: la_vector.h:367