Reference documentation for deal.II version GIT dad323def1 2022-06-25 19:00: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 {
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
124  const bool omit_zeroing_entries = false) override;
125 
134  template <typename Number2>
135  void
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
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> &
207 
211  virtual Vector<Number> &
213 
217  virtual Number
218  operator*(const VectorSpaceVector<Number> &V) const override;
219 
223  virtual void
224  import(const ReadWriteVector<Number> &V,
225  VectorOperation::values operation,
226  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
227  communication_pattern = {}) override;
228 
232  virtual void
233  add(const Number a) override;
234 
238  virtual void
239  add(const Number a, const VectorSpaceVector<Number> &V) override;
240 
245  virtual void
246  add(const Number a,
248  const Number b,
249  const VectorSpaceVector<Number> &W) override;
250 
255  virtual void
256  sadd(const Number s,
257  const Number a,
258  const VectorSpaceVector<Number> &V) override;
259 
265  virtual void
266  scale(const VectorSpaceVector<Number> &scaling_factors) override;
267 
271  virtual void
272  equ(const Number a, const VectorSpaceVector<Number> &V) override;
273 
277  virtual bool
278  all_zero() const override;
279 
283  virtual value_type
284  mean_value() const override;
285 
290  virtual typename VectorSpaceVector<Number>::real_type
291  l1_norm() const override;
292 
297  virtual typename VectorSpaceVector<Number>::real_type
298  l2_norm() const override;
299 
304  virtual typename VectorSpaceVector<Number>::real_type
305  linfty_norm() const override;
306 
327  virtual Number
328  add_and_dot(const Number a,
330  const VectorSpaceVector<Number> &W) override;
331 
336  virtual size_type
337  size() const override;
338 
350  virtual ::IndexSet
351  locally_owned_elements() const override;
352 
356  virtual void
357  print(std::ostream & out,
358  const unsigned int precision = 3,
359  const bool scientific = true,
360  const bool across = true) const override;
361 
370  void
371  print_as_numpy_array(std::ostream & out,
372  const unsigned int precision = 9) const;
373 
379  void
380  block_write(std::ostream &out) const;
381 
393  void
394  block_read(std::istream &in);
395 
399  virtual std::size_t
400  memory_consumption() const override;
401 
407  template <typename Archive>
408  void
409  serialize(Archive &ar, const unsigned int version);
410 
417 
418  private:
419  // Make all other ReadWriteVector types friends.
420  template <typename Number2>
421  friend class Vector;
422  };
423 
425  /*--------------------------- Inline functions ----------------------------*/
426 
427  template <typename Number>
429  : ReadWriteVector<Number>(V)
430  {}
431 
432 
433 
434  template <typename Number>
436  : ReadWriteVector<Number>(n)
437  {}
438 
439 
440 
441  template <typename Number>
442  template <typename InputIterator>
443  inline Vector<Number>::Vector(const InputIterator first,
444  const InputIterator last)
445  {
446  this->reinit(complete_index_set(std::distance(first, last)), true);
447  std::copy(first, last, this->begin());
448  }
449 
450 
451 
452  template <typename Number>
453  inline typename Vector<Number>::size_type
455  {
457  }
458 
459 
460 
461  template <typename Number>
462  inline ::IndexSet
464  {
466  }
467 
468 
469 
470  template <typename Number>
471  inline void
472  Vector<Number>::print(std::ostream & out,
473  const unsigned int precision,
474  const bool scientific,
475  const bool) const
476  {
477  ReadWriteVector<Number>::print(out, precision, scientific);
478  }
479 
480 
481 
482  template <typename Number>
483  template <typename Archive>
484  inline void
485  Vector<Number>::serialize(Archive &ar, const unsigned int)
486  {
487  size_type current_size = this->size();
488  ar &static_cast<Subscriptor &>(*this);
489  ar &this->stored_elements;
490  // If necessary, resize the vector during a read operation
491  if (this->size() != current_size)
492  this->reinit(this->size());
493  ar &boost::serialization::make_array(this->values.get(), this->size());
494  }
495 
496 
497 
498  template <typename Number>
499  inline std::size_t
501  {
503  }
504 } // end of namespace LinearAlgebra
505 
506 
510 template <typename Number>
511 struct is_serial_vector<LinearAlgebra::Vector<Number>> : std::true_type
512 {};
513 
514 #ifndef DOXYGEN
515 /*----------------------- Inline functions ----------------------------------*/
516 
517 namespace LinearAlgebra
518 {
519  template <typename Number>
520  inline bool
522  {
523  return false;
524  }
525 } // namespace LinearAlgebra
526 
527 #endif
528 
529 
531 
532 #ifdef DEAL_II_MSVC
533 # include <deal.II/lac/la_vector.templates.h>
534 #endif
535 
536 #endif
Definition: vector.h:109
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Point< 2 > first
Definition: grid_out.cc:4604
static ::ExceptionBase & ExcVectorTypeNotCompatible()
#define DeclException0(Exception0)
Definition: exceptions.h:464
std::size_t memory_consumption() const
void print_as_numpy_array(std::ostream &out, const unsigned int precision=9) const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true) 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:485
typename numbers::NumberTraits< Number >::real_type real_type
virtual ::IndexSet locally_owned_elements() const override
Definition: la_vector.h:463
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:81
size_type size() const
friend class Vector
Definition: la_vector.h:421
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:472
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:82
virtual std::size_t memory_consumption() const override
Definition: la_vector.h:500
virtual void add(const Number a) override
virtual size_type size() const override
Definition: la_vector.h:454
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
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1063
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:76