Reference documentation for deal.II version Git 1ecc23629d 2021-05-18 09:57:04 +0200
\(\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\}}\)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
LinearAlgebra::Vector< Number > Class Template Reference

#include <deal.II/lac/la_vector.h>

Inheritance diagram for LinearAlgebra::Vector< Number >:
[legend]

Public Types

using size_type = types::global_dof_index
 
using value_type = typename ReadWriteVector< Number >::value_type
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using iterator = value_type *
 
using const_iterator = const value_type *
 
using reference = value_type &
 
using const_reference = const value_type &
 
using real_type = typename numbers::NumberTraits< Number >::real_type
 
using real_type = typename numbers::NumberTraits< Number >::real_type
 

Public Member Functions

 Vector ()=default
 
 Vector (const Vector< Number > &V)
 
 Vector (const size_type n)
 
template<typename InputIterator >
 Vector (const InputIterator first, const InputIterator last)
 
virtual void reinit (const size_type size, const bool omit_zeroing_entries=false) override
 
template<typename Number2 >
void reinit (const ReadWriteVector< Number2 > &in_vector, const bool omit_zeroing_entries=false)
 
virtual void reinit (const IndexSet &locally_stored_indices, const bool omit_zeroing_entries=false) override
 
virtual void reinit (const VectorSpaceVector< Number > &V, const bool omit_zeroing_entries=false) override
 
bool has_ghost_elements () const
 
Vector< Number > & operator= (const Vector< Number > &in_vector)
 
template<typename Number2 >
Vector< Number > & operator= (const Vector< Number2 > &in_vector)
 
virtual Vector< Number > & operator= (const Number s) override
 
virtual Vector< Number > & operator*= (const Number factor) override
 
virtual Vector< Number > & operator/= (const Number factor) override
 
virtual Vector< Number > & operator+= (const VectorSpaceVector< Number > &V) override
 
virtual Vector< Number > & operator-= (const VectorSpaceVector< Number > &V) override
 
virtual Number operator* (const VectorSpaceVector< Number > &V) const override
 
virtual void import (const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > communication_pattern={}) override
 
virtual void add (const Number a) override
 
virtual void add (const Number a, const VectorSpaceVector< Number > &V) override
 
virtual void add (const Number a, const VectorSpaceVector< Number > &V, const Number b, const VectorSpaceVector< Number > &W) override
 
virtual void sadd (const Number s, const Number a, const VectorSpaceVector< Number > &V) override
 
virtual void scale (const VectorSpaceVector< Number > &scaling_factors) override
 
virtual void equ (const Number a, const VectorSpaceVector< Number > &V) override
 
virtual bool all_zero () const override
 
virtual value_type mean_value () const override
 
virtual VectorSpaceVector< Number >::real_type l1_norm () const override
 
virtual VectorSpaceVector< Number >::real_type l2_norm () const override
 
virtual VectorSpaceVector< Number >::real_type linfty_norm () const override
 
virtual Number add_and_dot (const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
 
virtual size_type size () const override
 
virtual ::IndexSet locally_owned_elements () const override
 
virtual void print (std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
 
void print_as_numpy_array (std::ostream &out, const unsigned int precision=9) const
 
void block_write (std::ostream &out) const
 
void block_read (std::istream &in)
 
virtual std::size_t memory_consumption () const override
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int version)
 
virtual void compress (VectorOperation::values)
 
1: Basic Object-handling
void reinit (const TrilinosWrappers::MPI::Vector &trilinos_vec)
 
template<typename Functor >
void apply (const Functor &func)
 
void swap (ReadWriteVector< Number > &v)
 
void import (const ::Vector< Number > &vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const LinearAlgebra::Vector< Number > &vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
template<typename MemorySpace >
void import (const distributed::Vector< Number, MemorySpace > &vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const PETScWrappers::MPI::Vector &petsc_vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const TrilinosWrappers::MPI::Vector &trilinos_vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const TpetraWrappers::Vector< Number > &tpetra_vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const EpetraWrappers::Vector &epetra_vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const CUDAWrappers::Vector< Number > &cuda_vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
size_type n_elements () const
 
size_type locally_owned_size () const
 
const IndexSetget_stored_elements () const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
2: Data-Access
Number operator() (const size_type global_index) const
 
Number & operator() (const size_type global_index)
 
Number operator[] (const size_type global_index) const
 
Number & operator[] (const size_type global_index)
 
template<typename Number2 >
void extract_subvector_to (const std::vector< size_type > &indices, std::vector< Number2 > &values) const
 
template<typename ForwardIterator , typename OutputIterator >
void extract_subvector_to (ForwardIterator indices_begin, const ForwardIterator indices_end, OutputIterator values_begin) const
 
Number local_element (const size_type local_index) const
 
Number & local_element (const size_type local_index)
 
3: Modification of vectors
template<typename Number2 >
void add (const std::vector< size_type > &indices, const std::vector< Number2 > &values)
 
template<typename Number2 >
void add (const std::vector< size_type > &indices, const ReadWriteVector< Number2 > &values)
 
template<typename Number2 >
void add (const size_type n_elements, const size_type *indices, const Number2 *values)
 
void print (std::ostream &out, const unsigned int precision=3, const bool scientific=true) const
 
Subscriptor functionality

Classes derived from Subscriptor provide a facility to subscribe to this object. This is mostly used by the SmartPointer class.

void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Static Public Member Functions

static ::ExceptionBaseExcVectorTypeNotCompatible ()
 
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Protected Member Functions

void import (const Tpetra::Vector< Number, int, types::global_dof_index > &tpetra_vector, const IndexSet &locally_owned_elements, VectorOperation::values operation, const MPI_Comm &mpi_comm, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern)
 
void import (const Epetra_MultiVector &multivector, const IndexSet &locally_owned_elements, VectorOperation::values operation, const MPI_Comm &mpi_comm, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern)
 
unsigned int global_to_local (const types::global_dof_index global_index) const
 
void resize_val (const size_type new_allocated_size)
 
TpetraWrappers::CommunicationPattern create_tpetra_comm_pattern (const IndexSet &source_index_set, const MPI_Comm &mpi_comm)
 
EpetraWrappers::CommunicationPattern create_epetra_comm_pattern (const IndexSet &source_index_set, const MPI_Comm &mpi_comm)
 

Protected Attributes

IndexSet stored_elements
 
IndexSet source_stored_elements
 
std::shared_ptr< Utilities::MPI::CommunicationPatternBasecomm_pattern
 
std::unique_ptr< Number[], decltype(std::free) * > values
 
std::shared_ptr<::parallel::internal::TBBPartitionerthread_loop_partitioner
 

Friends

template<typename Number2 >
class Vector
 

Detailed Description

template<typename Number>
class LinearAlgebra::Vector< Number >

Numerical vector of data. This class derives from both LinearAlgebra::ReadWriteVector and LinearAlgebra::VectorSpaceVector. As opposed to the array of the C++ standard library, this class implements an element of a vector space suitable for numerical computations.

Definition at line 77 of file la_vector.h.

Member Typedef Documentation

◆ size_type

template<typename Number>
using LinearAlgebra::Vector< Number >::size_type = types::global_dof_index

Definition at line 81 of file la_vector.h.

◆ value_type

template<typename Number>
using LinearAlgebra::Vector< Number >::value_type = typename ReadWriteVector<Number>::value_type

Definition at line 82 of file la_vector.h.

◆ pointer

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::pointer = value_type *
inherited

Definition at line 142 of file read_write_vector.h.

◆ const_pointer

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::const_pointer = const value_type *
inherited

Definition at line 143 of file read_write_vector.h.

◆ iterator

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::iterator = value_type *
inherited

Definition at line 144 of file read_write_vector.h.

◆ const_iterator

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::const_iterator = const value_type *
inherited

Definition at line 145 of file read_write_vector.h.

◆ reference

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::reference = value_type &
inherited

Definition at line 146 of file read_write_vector.h.

◆ const_reference

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::const_reference = const value_type &
inherited

Definition at line 147 of file read_write_vector.h.

◆ real_type [1/2]

template<typename Number>
using LinearAlgebra::ReadWriteVector< Number >::real_type = typename numbers::NumberTraits<Number>::real_type
inherited

Definition at line 149 of file read_write_vector.h.

◆ real_type [2/2]

template<typename Number>
using LinearAlgebra::VectorSpaceVector< Number >::real_type = typename numbers::NumberTraits<Number>::real_type
inherited

Definition at line 60 of file vector_space_vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename Number>
LinearAlgebra::Vector< Number >::Vector ( )
default

Constructor. Create a vector of dimension zero.

◆ Vector() [2/4]

template<typename Number >
Vector< Number >::Vector ( const Vector< Number > &  V)
inline

Copy constructor. Sets the dimension to that of the given vector and copies all elements.

Definition at line 427 of file la_vector.h.

◆ Vector() [3/4]

template<typename Number >
Vector< Number >::Vector ( const size_type  n)
inlineexplicit

Constructor. Set dimension to n and initialize all elements with zero.

The constructor is made explicit to avoid accident like this: v=0;. Presumably, the user wants to set every element of the vector to zero, but instead, what happens is this call: v=Vector<Number>(0);, i.e. the vector is replaced by one of length zero.

Definition at line 434 of file la_vector.h.

◆ Vector() [4/4]

template<typename Number >
template<typename InputIterator >
Vector< Number >::Vector ( const InputIterator  first,
const InputIterator  last 
)
inline

Initialize the vector with a given range of values pointed to by the iterators. This function exists in analogy to the std::vector class.

Definition at line 442 of file la_vector.h.

Member Function Documentation

◆ reinit() [1/5]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::reinit ( const size_type  size,
const bool  omit_zeroing_entries = false 
)
overridevirtual

Set the global size of the vector to size. The stored elements have their index in [0,size).

If the flag omit_zeroing_entries is set to false, the memory will be initialized with zero, otherwise the memory will be untouched (and the user must make sure to fill it with reasonable data before using it).

Reimplemented from LinearAlgebra::ReadWriteVector< Number >.

◆ reinit() [2/5]

template<typename Number>
template<typename Number2 >
void LinearAlgebra::Vector< Number >::reinit ( const ReadWriteVector< Number2 > &  in_vector,
const bool  omit_zeroing_entries = false 
)

Uses the same IndexSet as the one of the input vector in_vector and allocates memory for this vector.

If the flag omit_zeroing_entries is set to false, the memory will be initialized with zero, otherwise the memory will be untouched (and the user must make sure to fill it with reasonable data before using it).

◆ reinit() [3/5]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::reinit ( const IndexSet locally_stored_indices,
const bool  omit_zeroing_entries = false 
)
overridevirtual

Initializes the vector. The indices are specified by locally_stored_indices.

If the flag omit_zeroing_entries is set to false, the memory will be initialized with zero, otherwise the memory will be untouched (and the user must make sure to fill it with reasonable data before using it). locally_stored_indices.

Reimplemented from LinearAlgebra::ReadWriteVector< Number >.

◆ reinit() [4/5]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::reinit ( const VectorSpaceVector< Number > &  V,
const bool  omit_zeroing_entries = false 
)
overridevirtual

Change the dimension to that of the vector V. The elements of V are not copied.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ has_ghost_elements()

template<typename Number>
bool LinearAlgebra::Vector< Number >::has_ghost_elements ( ) const

Returns false as this is a serial vector.

This functionality only needs to be called if using MPI based vectors and exists in other objects for compatibility.

◆ operator=() [1/3]

template<typename Number>
Vector<Number>& LinearAlgebra::Vector< Number >::operator= ( const Vector< Number > &  in_vector)

Copies the data of the input vector in_vector.

◆ operator=() [2/3]

template<typename Number>
template<typename Number2 >
Vector<Number>& LinearAlgebra::Vector< Number >::operator= ( const Vector< Number2 > &  in_vector)

Copies the data of the input vector in_vector.

◆ operator=() [3/3]

template<typename Number>
virtual Vector<Number>& LinearAlgebra::Vector< Number >::operator= ( const Number  s)
overridevirtual

Sets all elements of the vector to the scalar s. This operation is only allowed if s is equal to zero.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator*=()

template<typename Number>
virtual Vector<Number>& LinearAlgebra::Vector< Number >::operator*= ( const Number  factor)
overridevirtual

Multiply the entire vector by a fixed factor.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator/=()

template<typename Number>
virtual Vector<Number>& LinearAlgebra::Vector< Number >::operator/= ( const Number  factor)
overridevirtual

Divide the entire vector by a fixed factor.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator+=()

template<typename Number>
virtual Vector<Number>& LinearAlgebra::Vector< Number >::operator+= ( const VectorSpaceVector< Number > &  V)
overridevirtual

Add the vector V to the present one.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator-=()

template<typename Number>
virtual Vector<Number>& LinearAlgebra::Vector< Number >::operator-= ( const VectorSpaceVector< Number > &  V)
overridevirtual

Subtract the vector V from the present one.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator*()

template<typename Number>
virtual Number LinearAlgebra::Vector< Number >::operator* ( const VectorSpaceVector< Number > &  V) const
overridevirtual

Return the scalar product of two vectors.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ import() [1/11]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::import ( const ReadWriteVector< Number > &  V,
VectorOperation::values  operation,
std::shared_ptr< const Utilities::MPI::CommunicationPatternBase communication_pattern = {} 
)
overridevirtual

This function is not implemented and will throw an exception.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add() [1/6]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::add ( const Number  a)
overridevirtual

Add a to all components. Note that a is a scalar not a vector.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add() [2/6]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::add ( const Number  a,
const VectorSpaceVector< Number > &  V 
)
overridevirtual

Simple addition of a multiple of a vector, i.e. *this += a*V.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add() [3/6]

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::add ( const Number  a,
const VectorSpaceVector< Number > &  V,
const Number  b,
const VectorSpaceVector< Number > &  W 
)
overridevirtual

Multiple addition of a multiple of a vector, i.e. *this += a*V+b*W.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ sadd()

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::sadd ( const Number  s,
const Number  a,
const VectorSpaceVector< Number > &  V 
)
overridevirtual

Scaling and simple addition of a multiple of a vector, i.e. *this = s*(*this)+a*V.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ scale()

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::scale ( const VectorSpaceVector< Number > &  scaling_factors)
overridevirtual

Scale each element of this vector by the corresponding element in the argument. This function is mostly meant to simulate multiplication (and immediate re-assignment) by a diagonal scaling matrix.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ equ()

template<typename Number>
virtual void LinearAlgebra::Vector< Number >::equ ( const Number  a,
const VectorSpaceVector< Number > &  V 
)
overridevirtual

Assignment *this = a*V.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ all_zero()

template<typename Number>
virtual bool LinearAlgebra::Vector< Number >::all_zero ( ) const
overridevirtual

Return whether the vector contains only elements with value zero.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ mean_value()

template<typename Number>
virtual value_type LinearAlgebra::Vector< Number >::mean_value ( ) const
overridevirtual

Return the mean value of all the entries of this vector.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ l1_norm()

template<typename Number>
virtual VectorSpaceVector<Number>::real_type LinearAlgebra::Vector< Number >::l1_norm ( ) const
overridevirtual

Return the l1 norm of the vector (i.e., the sum of the absolute values of all entries).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ l2_norm()

template<typename Number>
virtual VectorSpaceVector<Number>::real_type LinearAlgebra::Vector< Number >::l2_norm ( ) const
overridevirtual

Return the l2 norm of the vector (i.e., the square root of the sum of the square of all entries among all processors).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ linfty_norm()

template<typename Number>
virtual VectorSpaceVector<Number>::real_type LinearAlgebra::Vector< Number >::linfty_norm ( ) const
overridevirtual

Return the maximum norm of the vector (i.e., the maximum absolute value among all entries and among all processors).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add_and_dot()

template<typename Number>
virtual Number LinearAlgebra::Vector< Number >::add_and_dot ( const Number  a,
const VectorSpaceVector< Number > &  V,
const VectorSpaceVector< Number > &  W 
)
overridevirtual

Perform a combined operation of a vector addition and a subsequent inner product, returning the value of the inner product. In other words, the result of this function is the same as if the user called

this->add(a, V);
return_value = *this * W;

The reason this function exists is that this operation involves less memory transfer than calling the two functions separately. This method only needs to load three vectors, this, V, W, whereas calling separate methods means to load the calling vector this twice. Since most vector operations are memory transfer limited, this reduces the time by 25% (or 50% if W equals this).

For complex-valued vectors, the scalar product in the second step is implemented as \(\left<v,w\right>=\sum_i v_i \bar{w_i}\).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ size()

template<typename Number >
Vector< Number >::size_type Vector< Number >::size ( ) const
inlineoverridevirtual

Return the global size of the vector, equal to the sum of the number of locally owned indices among all processors.

Implements LinearAlgebra::VectorSpaceVector< Number >.

Definition at line 453 of file la_vector.h.

◆ locally_owned_elements()

template<typename Number >
IndexSet Vector< Number >::locally_owned_elements ( ) const
inlineoverridevirtual

Return an index set that describes which elements of this vector are owned by the current processor. As a consequence, the index sets returned on different processors if this is a distributed vector will form disjoint sets that add up to the complete index set. Obviously, if a vector is created on only one processor, then the result would satisfy

vec.locally_owned_elements() == complete_index_set(vec.size())

Implements LinearAlgebra::VectorSpaceVector< Number >.

Definition at line 462 of file la_vector.h.

◆ print() [1/2]

template<typename Number >
void Vector< Number >::print ( std::ostream &  out,
const unsigned int  precision = 3,
const bool  scientific = true,
const bool  across = true 
) const
inlineoverridevirtual

Print the vector to the output stream out.

Implements LinearAlgebra::VectorSpaceVector< Number >.

Definition at line 471 of file la_vector.h.

◆ print_as_numpy_array()

template<typename Number>
void LinearAlgebra::Vector< Number >::print_as_numpy_array ( std::ostream &  out,
const unsigned int  precision = 9 
) const

Print the vector to the output stream out in a format that can be read by numpy::readtxt(). Note that the IndexSet is not printed but only the values stored in the Vector. To load the vector in python just do vector = numpy.loadtxt('my_vector.txt')

◆ block_write()

template<typename Number>
void LinearAlgebra::Vector< Number >::block_write ( std::ostream &  out) const

Write the vector en bloc to a file. This is done in a binary mode, so the output is neither readable by humans nor (probably) by other computers using a different operating system or number format.

◆ block_read()

template<typename Number>
void LinearAlgebra::Vector< Number >::block_read ( std::istream &  in)

Read a vector en block from a file. This is done using the inverse operations to the above function, so it is reasonably fast because the bitstream is not interpreted.

The vector is resized if necessary.

A primitive form of error checking is performed which will recognize the bluntest attempts to interpret some data as a vector stored bitwise to a file, but not more.

◆ memory_consumption()

template<typename Number >
std::size_t Vector< Number >::memory_consumption ( ) const
inlineoverridevirtual

Return the memory consumption of this class in bytes.

Implements LinearAlgebra::VectorSpaceVector< Number >.

Definition at line 499 of file la_vector.h.

◆ serialize()

template<typename Number >
template<typename Archive >
void Vector< Number >::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Write and read the data of this object from a stream for the purpose of serialization using the BOOST serialization library.

Definition at line 484 of file la_vector.h.

◆ reinit() [5/5]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::reinit ( const TrilinosWrappers::MPI::Vector trilinos_vec)
inherited

Initialize this ReadWriteVector by supplying access to all locally available entries in the given ghosted or non-ghosted vector.

Note
This function currently copies the values from the argument into the ReadWriteVector, so modifications here will not modify trilinos_vec.

This function is mainly written for backwards-compatibility to get element access to a ghosted TrilinosWrappers::MPI::Vector inside the library.

◆ apply()

template<typename Number>
template<typename Functor >
void LinearAlgebra::ReadWriteVector< Number >::apply ( const Functor &  func)
inherited

Apply the functor func to each element of the vector. The functor should look like

struct Functor
{
void operator() (Number &value);
};
Note
This function requires that the header read_write_vector.templates.h be included.

◆ swap()

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::swap ( ReadWriteVector< Number > &  v)
inherited

Swap the contents of this vector and the other vector v. One could do this operation with a temporary variable and copying over the data elements, but this function is significantly more efficient since it only swaps the pointers to the data of the two vectors and therefore does not need to allocate temporary storage and move data around.

This function is analogous to the swap function of all C++ standard containers. Also, there is a global function swap(u,v) that simply calls u.swap(v), again in analogy to standard functions.

◆ import() [2/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const ::Vector< Number > &  vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements.

Note
The parameter communication_pattern is ignored since we are dealing with a serial vector here.

◆ import() [3/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const LinearAlgebra::Vector< Number > &  vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements.

Note
The parameter communication_pattern is ignored since we are dealing with a serial vector here.

◆ import() [4/11]

template<typename Number>
template<typename MemorySpace >
void LinearAlgebra::ReadWriteVector< Number >::import ( const distributed::Vector< Number, MemorySpace > &  vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter can be used if the same communication pattern is used multiple times. This can be used to improve performance.

◆ import() [5/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const PETScWrappers::MPI::Vector petsc_vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector petsc_vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter can be used if the same communication pattern is used multiple times. This can be used to improve performance.

◆ import() [6/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const TrilinosWrappers::MPI::Vector trilinos_vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector trilinos_vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter can be used if the same communication pattern is used multiple times. This can be used to improve performance.

Note
The trilinos_vec is not allowed to have ghost entries.

◆ import() [7/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const TpetraWrappers::Vector< Number > &  tpetra_vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector tpetra_vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter can be used if the same communication pattern is used multiple times. This can be used to improve performance.

◆ import() [8/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const EpetraWrappers::Vector epetra_vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Imports all the elements present in the vector's IndexSet from the input vector epetra_vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter can be used if the same communication pattern is used multiple times. This can be used to improve performance.

◆ import() [9/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const CUDAWrappers::Vector< Number > &  cuda_vec,
VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inherited

Import all the elements present in the vector's IndexSet from the input vector cuda_vec. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter is not used.

◆ import() [10/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const Tpetra::Vector< Number, int, types::global_dof_index > &  tpetra_vector,
const IndexSet locally_owned_elements,
VectorOperation::values  operation,
const MPI_Comm mpi_comm,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern 
)
protectedinherited

Import all the elements present in the vector's IndexSet from the input vector tpetra_vector. This is an helper function and it should not be used directly.

◆ import() [11/11]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::import ( const Epetra_MultiVector &  multivector,
const IndexSet locally_owned_elements,
VectorOperation::values  operation,
const MPI_Comm mpi_comm,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern 
)
protectedinherited

Import all the elements present in the vector's IndexSet from the input vector multivector. This is an helper function and it should not be used directly.

◆ n_elements()

template<typename Number>
size_type LinearAlgebra::ReadWriteVector< Number >::n_elements ( ) const
inherited

This function returns the number of elements stored. It is smaller or equal to the dimension of the vector space that is modeled by an object of this kind. This dimension is return by size().

Deprecated:
use locally_owned_size() instead.

◆ locally_owned_size()

template<typename Number>
size_type LinearAlgebra::ReadWriteVector< Number >::locally_owned_size ( ) const
inherited

Return the local size of the vector, i.e., the number of indices owned locally.

◆ get_stored_elements()

template<typename Number>
const IndexSet& LinearAlgebra::ReadWriteVector< Number >::get_stored_elements ( ) const
inherited

Return the IndexSet that represents the indices of the elements stored.

◆ begin() [1/2]

template<typename Number>
iterator LinearAlgebra::ReadWriteVector< Number >::begin ( )
inherited

Make the ReadWriteVector class a bit like the vector<> class of the C++ standard library by returning iterators to the start and end of the locally stored elements of this vector.

◆ begin() [2/2]

template<typename Number>
const_iterator LinearAlgebra::ReadWriteVector< Number >::begin ( ) const
inherited

Return constant iterator to the start of the locally stored elements of the vector.

◆ end() [1/2]

template<typename Number>
iterator LinearAlgebra::ReadWriteVector< Number >::end ( )
inherited

Return an iterator pointing to the element past the end of the array of locally stored entries.

◆ end() [2/2]

template<typename Number>
const_iterator LinearAlgebra::ReadWriteVector< Number >::end ( ) const
inherited

Return a constant iterator pointing to the element past the end of the array of the locally stored entries.

◆ operator()() [1/2]

template<typename Number>
Number LinearAlgebra::ReadWriteVector< Number >::operator() ( const size_type  global_index) const
inherited

Read access to the data in the position corresponding to global_index. An exception is thrown if global_index is not stored by the current object.

◆ operator()() [2/2]

template<typename Number>
Number& LinearAlgebra::ReadWriteVector< Number >::operator() ( const size_type  global_index)
inherited

Read and write access to the data in the position corresponding to global_index. An exception is thrown if global_index is not stored by the current object.

◆ operator[]() [1/2]

template<typename Number>
Number LinearAlgebra::ReadWriteVector< Number >::operator[] ( const size_type  global_index) const
inherited

Read access to the data in the position corresponding to global_index. An exception is thrown if global_index is not stored by the current object.

This function does the same thing as operator().

◆ operator[]() [2/2]

template<typename Number>
Number& LinearAlgebra::ReadWriteVector< Number >::operator[] ( const size_type  global_index)
inherited

Read and write access to the data in the position corresponding to global_index. An exception is thrown if global_index is not stored by the current object.

This function does the same thing as operator().

◆ extract_subvector_to() [1/2]

template<typename Number>
template<typename Number2 >
void LinearAlgebra::ReadWriteVector< Number >::extract_subvector_to ( const std::vector< size_type > &  indices,
std::vector< Number2 > &  values 
) const
inherited

Instead of getting individual elements of a vector via operator(), this function allows getting a whole set of elements at once. The indices of the elements to be read are stated in the first argument, the corresponding values are returned in the second.

If the current vector is called v, then this function is the equivalent to the code

for (unsigned int i=0; i<indices.size(); ++i)
values[i] = v[indices[i]];
Precondition
The sizes of the indices and values arrays must be identical.

◆ extract_subvector_to() [2/2]

template<typename Number>
template<typename ForwardIterator , typename OutputIterator >
void LinearAlgebra::ReadWriteVector< Number >::extract_subvector_to ( ForwardIterator  indices_begin,
const ForwardIterator  indices_end,
OutputIterator  values_begin 
) const
inherited

Instead of getting individual elements of a vector via operator(), this function allows getting a whole set of elements at once. In contrast to the previous function, this function obtains the indices of the elements by dereferencing all elements of the iterator range provided by the first two arguments, and puts the vector values into memory locations obtained by dereferencing a range of iterators starting at the location pointed to by the third argument.

If the current vector is called v, then this function is the equivalent to the code

ForwardIterator indices_p = indices_begin;
OutputIterator values_p = values_begin;
while (indices_p != indices_end)
{
*values_p = v[*indices_p];
++indices_p;
++values_p;
}
Precondition
It must be possible to write into as many memory locations starting at values_begin as there are iterators between indices_begin and indices_end.

◆ local_element() [1/2]

template<typename Number>
Number LinearAlgebra::ReadWriteVector< Number >::local_element ( const size_type  local_index) const
inherited

Read access to the data field specified by local_index. When you access elements in the order in which they are stored, it is necessary that you know in which they are stored. In other words, you need to know the map between the global indices of the elements this class stores, and the local indices into the contiguous array of these global elements. For this, see the general documentation of this class.

Performance: Direct array access (fast).

◆ local_element() [2/2]

template<typename Number>
Number& LinearAlgebra::ReadWriteVector< Number >::local_element ( const size_type  local_index)
inherited

Read and write access to the data field specified by local_index. When you access elements in the order in which they are stored, it is necessary that you know in which they are stored. In other words, you need to know the map between the global indices of the elements this class stores, and the local indices into the contiguous array of these global elements. For this, see the general documentation of this class.

Performance: Direct array access (fast).

◆ add() [4/6]

template<typename Number>
template<typename Number2 >
void LinearAlgebra::ReadWriteVector< Number >::add ( const std::vector< size_type > &  indices,
const std::vector< Number2 > &  values 
)
inherited

This function adds a whole set of values stored in values to the vector components specified by indices.

◆ add() [5/6]

template<typename Number>
template<typename Number2 >
void LinearAlgebra::ReadWriteVector< Number >::add ( const std::vector< size_type > &  indices,
const ReadWriteVector< Number2 > &  values 
)
inherited

This function is similar to the previous one but takes a ReadWriteVector of values.

◆ add() [6/6]

template<typename Number>
template<typename Number2 >
void LinearAlgebra::ReadWriteVector< Number >::add ( const size_type  n_elements,
const size_type indices,
const Number2 *  values 
)
inherited

Take an address where n_elements are stored contiguously and add them into the vector. Handles all cases which are not covered by the other two add() functions above.

◆ print() [2/2]

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::print ( std::ostream &  out,
const unsigned int  precision = 3,
const bool  scientific = true 
) const
inherited

Prints the vector to the output stream out.

◆ global_to_local()

template<typename Number>
unsigned int LinearAlgebra::ReadWriteVector< Number >::global_to_local ( const types::global_dof_index  global_index) const
inlineprotectedinherited

Return the local position of global_index.

Definition at line 686 of file read_write_vector.h.

◆ resize_val()

template<typename Number>
void LinearAlgebra::ReadWriteVector< Number >::resize_val ( const size_type  new_allocated_size)
protectedinherited

A helper function that is used to resize the val array.

◆ create_tpetra_comm_pattern()

template<typename Number>
TpetraWrappers::CommunicationPattern LinearAlgebra::ReadWriteVector< Number >::create_tpetra_comm_pattern ( const IndexSet source_index_set,
const MPI_Comm mpi_comm 
)
protectedinherited

Return a TpetraWrappers::CommunicationPattern and store it for future use.

◆ create_epetra_comm_pattern()

template<typename Number>
EpetraWrappers::CommunicationPattern LinearAlgebra::ReadWriteVector< Number >::create_epetra_comm_pattern ( const IndexSet source_index_set,
const MPI_Comm mpi_comm 
)
protectedinherited

Return a EpetraWrappers::CommunicationPattern and store it for future use.

◆ subscribe()

void Subscriptor::subscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.

Definition at line 136 of file subscriptor.cc.

◆ unsubscribe()

void Subscriptor::unsubscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Unsubscribes a user from the object.

Note
The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 156 of file subscriptor.cc.

◆ n_subscriptions()

unsigned int Subscriptor::n_subscriptions ( ) const
inlineinherited

Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.

Definition at line 301 of file subscriptor.h.

◆ list_subscribers() [1/2]

template<typename StreamType >
void Subscriptor::list_subscribers ( StreamType &  stream) const
inlineinherited

List the subscribers to the input stream.

Definition at line 318 of file subscriptor.h.

◆ list_subscribers() [2/2]

void Subscriptor::list_subscribers ( ) const
inherited

List the subscribers to deallog.

Definition at line 204 of file subscriptor.cc.

◆ compress()

template<typename Number>
virtual void LinearAlgebra::VectorSpaceVector< Number >::compress ( VectorOperation::values  )
inlinevirtualinherited

This function does nothing and only exists for backward compatibility.

Definition at line 225 of file vector_space_vector.h.

Friends And Related Function Documentation

◆ Vector

template<typename Number>
template<typename Number2 >
friend class Vector
friend

Typedef for the vector type used

Typedef for the vector type used.

Definition at line 420 of file la_vector.h.

Member Data Documentation

◆ stored_elements

template<typename Number>
IndexSet LinearAlgebra::ReadWriteVector< Number >::stored_elements
protectedinherited

Indices of the elements stored.

Definition at line 723 of file read_write_vector.h.

◆ source_stored_elements

template<typename Number>
IndexSet LinearAlgebra::ReadWriteVector< Number >::source_stored_elements
protectedinherited

IndexSet of the elements of the last imported vector;

Definition at line 728 of file read_write_vector.h.

◆ comm_pattern

template<typename Number>
std::shared_ptr<Utilities::MPI::CommunicationPatternBase> LinearAlgebra::ReadWriteVector< Number >::comm_pattern
protectedinherited

CommunicationPattern for the communication between the source_stored_elements IndexSet and the current vector.

Definition at line 734 of file read_write_vector.h.

◆ values

template<typename Number>
std::unique_ptr<Number[], decltype(std::free) *> LinearAlgebra::ReadWriteVector< Number >::values
protectedinherited

Pointer to the array of local elements of this vector.

Definition at line 739 of file read_write_vector.h.

◆ thread_loop_partitioner

template<typename Number>
std::shared_ptr<::parallel::internal::TBBPartitioner> LinearAlgebra::ReadWriteVector< Number >::thread_loop_partitioner
mutableprotectedinherited

For parallel loops with TBB, this member variable stores the affinity information of loops.

Definition at line 746 of file read_write_vector.h.


The documentation for this class was generated from the following file: