Reference documentation for deal.II version 9.5.0
\(\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\}}\)
Loading...
Searching...
No Matches
la_vector.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2015 - 2023 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
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
63namespace LinearAlgebra
64{
77 template <typename Number>
78 class Vector : public ReadWriteVector<Number>,
79 public VectorSpaceVector<Number>
80 {
81 public:
84
88 Vector() = default;
89
94 Vector(const Vector<Number> &V);
95
106 explicit Vector(const size_type n);
107
112 template <typename InputIterator>
113 Vector(const InputIterator first, const InputIterator last);
114
123 virtual void
125 const bool omit_zeroing_entries = false) override;
126
135 template <typename Number2>
136 void
138 const bool omit_zeroing_entries = false);
139
149 virtual void
150 reinit(const IndexSet &locally_stored_indices,
151 const bool omit_zeroing_entries = false) override;
152
153
158 virtual void
160 const bool omit_zeroing_entries = false) override;
161
168 bool
170
175 operator=(const Vector<Number> &in_vector);
176
180 template <typename Number2>
182 operator=(const Vector<Number2> &in_vector);
183
188 virtual Vector<Number> &
189 operator=(const Number s) override;
190
194 virtual Vector<Number> &
195 operator*=(const Number factor) override;
196
200 virtual Vector<Number> &
201 operator/=(const Number factor) override;
202
206 virtual Vector<Number> &
208
212 virtual Vector<Number> &
214
218 virtual Number
219 operator*(const VectorSpaceVector<Number> &V) const override;
220
224 virtual void
227 VectorOperation::values operation,
228 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
229 communication_pattern = {}) override;
230
234 DEAL_II_DEPRECATED_EARLY
235 virtual void
236 import(const ReadWriteVector<Number> &V,
237 VectorOperation::values operation,
238 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
239 communication_pattern = {}) override
240 {
241 import_elements(V, operation, communication_pattern);
242 }
243
247 virtual void
248 add(const Number a) override;
249
253 virtual void
254 add(const Number a, const VectorSpaceVector<Number> &V) override;
255
260 virtual void
261 add(const Number a,
263 const Number b,
264 const VectorSpaceVector<Number> &W) override;
265
270 virtual void
271 sadd(const Number s,
272 const Number a,
273 const VectorSpaceVector<Number> &V) override;
274
280 virtual void
281 scale(const VectorSpaceVector<Number> &scaling_factors) override;
282
286 virtual void
287 equ(const Number a, const VectorSpaceVector<Number> &V) override;
288
292 virtual bool
293 all_zero() const override;
294
298 virtual value_type
299 mean_value() const override;
300
306 l1_norm() const override;
307
313 l2_norm() const override;
314
320 linfty_norm() const override;
321
342 virtual Number
343 add_and_dot(const Number a,
345 const VectorSpaceVector<Number> &W) override;
346
351 virtual size_type
352 size() const override;
353
365 virtual ::IndexSet
366 locally_owned_elements() const override;
367
371 virtual void
372 print(std::ostream & out,
373 const unsigned int precision = 3,
374 const bool scientific = true,
375 const bool across = true) const override;
376
385 void
386 print_as_numpy_array(std::ostream & out,
387 const unsigned int precision = 9) const;
388
394 void
395 block_write(std::ostream &out) const;
396
408 void
409 block_read(std::istream &in);
410
414 virtual std::size_t
415 memory_consumption() const override;
416
422 template <typename Archive>
423 void
424 serialize(Archive &ar, const unsigned int version);
425
432
433 private:
434 // Make all other ReadWriteVector types friends.
435 template <typename Number2>
436 friend class Vector;
437 };
438
440 /*--------------------------- Inline functions ----------------------------*/
441
442 template <typename Number>
444 : ReadWriteVector<Number>(V)
445 {}
446
447
448
449 template <typename Number>
451 : ReadWriteVector<Number>(n)
452 {}
453
454
455
456 template <typename Number>
457 template <typename InputIterator>
458 inline Vector<Number>::Vector(const InputIterator first,
459 const InputIterator last)
460 {
461 this->reinit(complete_index_set(std::distance(first, last)), true);
462 std::copy(first, last, this->begin());
463 }
464
465
466
467 template <typename Number>
468 inline typename Vector<Number>::size_type
470 {
472 }
473
474
475
476 template <typename Number>
477 inline ::IndexSet
479 {
481 }
482
483
484
485 template <typename Number>
486 inline void
487 Vector<Number>::print(std::ostream & out,
488 const unsigned int precision,
489 const bool scientific,
490 const bool) const
491 {
492 ReadWriteVector<Number>::print(out, precision, scientific);
493 }
494
495
496
497 template <typename Number>
498 template <typename Archive>
499 inline void
500 Vector<Number>::serialize(Archive &ar, const unsigned int)
501 {
502 size_type current_size = this->size();
503 ar &static_cast<Subscriptor &>(*this);
504 ar &this->stored_elements;
505 // If necessary, resize the vector during a read operation
506 if (this->size() != current_size)
507 this->reinit(this->size());
508 ar &boost::serialization::make_array(this->values.get(), this->size());
509 }
510
511
512
513 template <typename Number>
514 inline std::size_t
516 {
518 }
519} // end of namespace LinearAlgebra
520
521
525template <typename Number>
526struct is_serial_vector<LinearAlgebra::Vector<Number>> : std::true_type
527{};
528
529#ifndef DOXYGEN
530/*----------------------- Inline functions ----------------------------------*/
531
532namespace LinearAlgebra
533{
534 template <typename Number>
535 inline bool
537 {
538 return false;
539 }
540} // namespace LinearAlgebra
541
542#endif
543
544
546
547#ifdef DEAL_II_MSVC
548# include <deal.II/lac/la_vector.templates.h>
549#endif
550
551#endif
std::size_t memory_consumption() const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true) const
typename numbers::NumberTraits< Number >::real_type real_type
virtual VectorSpaceVector< Number >::real_type linfty_norm() const override
void print_as_numpy_array(std::ostream &out, const unsigned int precision=9) const
virtual Vector< Number > & operator=(const Number s) override
virtual void reinit(const IndexSet &locally_stored_indices, const bool omit_zeroing_entries=false) override
virtual VectorSpaceVector< Number >::real_type l1_norm() const override
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual Vector< Number > & operator*=(const Number factor) 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:500
virtual ::IndexSet locally_owned_elements() const override
Definition la_vector.h:478
virtual VectorSpaceVector< Number >::real_type l2_norm() const override
Vector< Number > & operator=(const Vector< Number > &in_vector)
friend class Vector
Definition la_vector.h:436
virtual value_type mean_value() const override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) 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:487
virtual void reinit(const VectorSpaceVector< Number > &V, const bool omit_zeroing_entries=false) override
void block_read(std::istream &in)
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > communication_pattern={}) override
void block_write(std::ostream &out) const
virtual Vector< Number > & operator/=(const Number factor) override
typename ReadWriteVector< Number >::value_type value_type
Definition la_vector.h:83
virtual std::size_t memory_consumption() const override
Definition la_vector.h:515
virtual void add(const Number a) override
virtual size_type size() const override
Definition la_vector.h:469
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 VectorSpaceVector< Number > &V) override
Vector< Number > & operator=(const Vector< Number2 > &in_vector)
void reinit(const ReadWriteVector< Number2 > &in_vector, const bool omit_zeroing_entries=false)
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
Point< 2 > first
Definition grid_out.cc:4615
#define DeclException0(Exception0)
Definition exceptions.h:465
static ::ExceptionBase & ExcVectorTypeNotCompatible()
IndexSet complete_index_set(const IndexSet::size_type N)
Definition index_set.h:1089
unsigned int global_dof_index
Definition types.h:82