MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::MultiVector Class Reference

Class representing an array of Vectors with generally different sizes. More...

#include <multivector.hpp>

Public Member Functions

 MultiVector ()=default
 Create an empty MultiVector with zero blocks.
 
 MultiVector (int num_blocks)
 Create a MultiVector with num_blocks blocks. The individual Vector blocks are default initialized, i.e. they all have size zero.
 
 MultiVector (const Array< int > &vector_sizes)
 Construct a MultiVector with number of blocks and individual block Vector sizes given by vector_sizes.
 
 MultiVector (const Array< int > &vector_sizes, MemoryType mt)
 Construct a MultiVector with number of blocks and individual block Vector sizes given by vector_sizes. All Vector blocks use the MemoryType mt.
 
 MultiVector (Vector &base, const Array< int > &vector_sizes)
 Construct a MultiVector referencing data within a given monolithic Vector base.
 
template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< VectorTypes &, Vector & >... >, bool > = true>
 MultiVector (VectorTypes &...vs)
 Construct a MultiVector referencing multiple Vectors given as arguments.
 
template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< const VectorTypes &, const Vector & >... >, bool > = true>
 MultiVector (const VectorTypes &...vs)
 Construct a MultiVector referencing multiple const Vectors given as arguments. Individual blocks are read-only; non-const operator[] will generate an error.
 
int NumBlocks () const
 Return the number of Vectors in the MultiVector.
 
void SetNumBlocks (int num_blocks)
 Set the number of Vectors in the MultiVector. Existing Vector blocks will remain unmodified. New Vector blocks will be default initialized, i.e. they all have size zero.
 
Vectoroperator[] (int i)
 Read-write access to the i-th Vector. Generates an error if the i-th block is read-only, i.e. it is a pointer to a const Vector.
 
const Vectoroperator[] (int i) const
 Read-only access to the i-th Vector.
 
void SetSizes (const Array< int > &vector_sizes)
 Update the MultiVector according to the given vector_sizes.
 
void SetSizes (const Array< int > &vector_sizes, MemoryType mt)
 Update the MultiVector according to the given vector_sizes and MemoryType mt.
 
void MakeRef (Vector &base, const Array< int > &vector_sizes)
 Update the MultiVector to reference data within a given monolithic Vector base.
 
void MakeRef (int i, Vector &base, int offset, int size)
 Update the i-th MultiVector block to reference data within the given monolithic Vector base at the given offset and with the given size.
 
template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< VectorTypes &, Vector & >... >, bool > = true>
void MakeRef (VectorTypes &...vs)
 Update the MultiVector to reference multiple Vectors given as arguments.
 
template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< const VectorTypes &, const Vector & >... >, bool > = true>
void MakeRef (const VectorTypes &...vs)
 Update the MultiVector to reference multiple const Vectors given as arguments. Individual blocks are read-only; non-const operator[] will generate an error.
 
void MakeRef (int i, Vector &v)
 Update the i-th MultiVector block to reference the given Vector v.
 
void MakeRef (int i, const Vector &v)
 Update the i-th MultiVector block to reference the given const Vector v. The block becomes read-only.
 

Detailed Description

Class representing an array of Vectors with generally different sizes.

This class is similar to BlockVector with the following two main differences:

  • the data for the individual Vector blocks does not need to be part of one big contiguous memory allocation;
  • this class does not inherit from class Vector (as a consequence of the first bullet).

Internally, each Vector block is represented as one of the following three options:

  • (default) a Vector object constructed and owned by this class; this object, in turn, as any Vector object, can own its Memory allocation or refer to a sub-Memory of another Memory object; or
  • a pointer to an externally allocated Vector or classes derived from Vector.
  • a pointer to an externally allocated const Vector or classes derived from Vector. This option is helpful for wrapping const Vector objects as a MultiVector that will be then used as a const MultiVector.

Definition at line 42 of file multivector.hpp.

Constructor & Destructor Documentation

◆ MultiVector() [1/7]

mfem::MultiVector::MultiVector ( )
default

Create an empty MultiVector with zero blocks.

◆ MultiVector() [2/7]

mfem::MultiVector::MultiVector ( int num_blocks)
inline

Create a MultiVector with num_blocks blocks. The individual Vector blocks are default initialized, i.e. they all have size zero.

Definition at line 53 of file multivector.hpp.

◆ MultiVector() [3/7]

mfem::MultiVector::MultiVector ( const Array< int > & vector_sizes)

Construct a MultiVector with number of blocks and individual block Vector sizes given by vector_sizes.

Note
The memory of the individual Vector blocks is NOT initialized.

Definition at line 17 of file multivector.cpp.

◆ MultiVector() [4/7]

mfem::MultiVector::MultiVector ( const Array< int > & vector_sizes,
MemoryType mt )

Construct a MultiVector with number of blocks and individual block Vector sizes given by vector_sizes. All Vector blocks use the MemoryType mt.

Note
The memory of the individual Vector blocks is NOT initialized.

Definition at line 22 of file multivector.cpp.

◆ MultiVector() [5/7]

mfem::MultiVector::MultiVector ( Vector & base,
const Array< int > & vector_sizes )

Construct a MultiVector referencing data within a given monolithic Vector base.

With this constructor, the Memory flags of base and of the individual Vector blocks may need to be explicitly synchronized when data is moved between host and device.

Definition at line 27 of file multivector.cpp.

◆ MultiVector() [6/7]

template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< VectorTypes &, Vector & >... >, bool > = true>
mfem::MultiVector::MultiVector ( VectorTypes &... vs)
inline

Construct a MultiVector referencing multiple Vectors given as arguments.

The VectorTypes reference arguments are expected to be static_cast-able to (Vector &) which is the case if the types are derived from Vector, e.g. HypreParVector, GridFunction, etc.

With this constructor, operations on individual Vector blocks are performed directly on the objects vs. In particular, there is no need to synchronize the Memory flags of vs and the ones of the individual Vector blocks when data is moved between host and device.

Definition at line 92 of file multivector.hpp.

◆ MultiVector() [7/7]

template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< const VectorTypes &, const Vector & >... >, bool > = true>
mfem::MultiVector::MultiVector ( const VectorTypes &... vs)
inline

Construct a MultiVector referencing multiple const Vectors given as arguments. Individual blocks are read-only; non-const operator[] will generate an error.

Definition at line 102 of file multivector.hpp.

Member Function Documentation

◆ MakeRef() [1/6]

template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< const VectorTypes &, const Vector & >... >, bool > >
void mfem::MultiVector::MakeRef ( const VectorTypes &... vs)
inline

Update the MultiVector to reference multiple const Vectors given as arguments. Individual blocks are read-only; non-const operator[] will generate an error.

Definition at line 236 of file multivector.hpp.

◆ MakeRef() [2/6]

void mfem::MultiVector::MakeRef ( int i,
const Vector & v )
inline

Update the i-th MultiVector block to reference the given const Vector v. The block becomes read-only.

Definition at line 191 of file multivector.hpp.

◆ MakeRef() [3/6]

void mfem::MultiVector::MakeRef ( int i,
Vector & base,
int offset,
int size )
inline

Update the i-th MultiVector block to reference data within the given monolithic Vector base at the given offset and with the given size.

After calling this method, the Memory flags of base and of the i-th Vector block may need to be explicitly synchronized when data is moved between host and device.

Definition at line 148 of file multivector.hpp.

◆ MakeRef() [4/6]

void mfem::MultiVector::MakeRef ( int i,
Vector & v )
inline

Update the i-th MultiVector block to reference the given Vector v.

After calling this method, operations on the i-th Vector block are performed directly on the Vector v. In particular, there is no need to synchronize the Memory flags of v and the ones of the i-th Vector blocks when data is moved between host and device.

Definition at line 187 of file multivector.hpp.

◆ MakeRef() [5/6]

void mfem::MultiVector::MakeRef ( Vector & base,
const Array< int > & vector_sizes )

Update the MultiVector to reference data within a given monolithic Vector base.

After calling this method, the Memory flags of base and of the individual Vector blocks may need to be explicitly synchronized when data is moved between host and device.

Definition at line 50 of file multivector.cpp.

◆ MakeRef() [6/6]

template<typename... VectorTypes, std::enable_if_t< std::conjunction_v< std::is_convertible< VectorTypes &, Vector & >... >, bool > >
void mfem::MultiVector::MakeRef ( VectorTypes &... vs)
inline

Update the MultiVector to reference multiple Vectors given as arguments.

The VectorTypes reference arguments are expected to be static_cast-able to (Vector &) which is the case if the types are derived from Vector, e.g. HypreParVector, GridFunction, etc.

After calling this method, operations on individual Vector blocks are performed directly on the objects vs. In particular, there is no need to synchronize the Memory flags of vs and the ones of the individual Vector blocks when data is moved between host and device.

Definition at line 218 of file multivector.hpp.

◆ NumBlocks()

int mfem::MultiVector::NumBlocks ( ) const
inline

Return the number of Vectors in the MultiVector.

Definition at line 105 of file multivector.hpp.

◆ operator[]() [1/2]

Vector & mfem::MultiVector::operator[] ( int i)
inline

Read-write access to the i-th Vector. Generates an error if the i-th block is read-only, i.e. it is a pointer to a const Vector.

Definition at line 196 of file multivector.hpp.

◆ operator[]() [2/2]

const Vector & mfem::MultiVector::operator[] ( int i) const
inline

Read-only access to the i-th Vector.

Definition at line 205 of file multivector.hpp.

◆ SetNumBlocks()

void mfem::MultiVector::SetNumBlocks ( int num_blocks)
inline

Set the number of Vectors in the MultiVector. Existing Vector blocks will remain unmodified. New Vector blocks will be default initialized, i.e. they all have size zero.

Definition at line 110 of file multivector.hpp.

◆ SetSizes() [1/2]

void mfem::MultiVector::SetSizes ( const Array< int > & vector_sizes)

Update the MultiVector according to the given vector_sizes.

This method can be used to add or remove blocks. The individual Vector sizes are updated using the method Vector::SetSize(int).

Definition at line 32 of file multivector.cpp.

◆ SetSizes() [2/2]

void mfem::MultiVector::SetSizes ( const Array< int > & vector_sizes,
MemoryType mt )

Update the MultiVector according to the given vector_sizes and MemoryType mt.

This method can be used to add or remove blocks. The individual Vector sizes and MemoryType are updated using the method Vector::SetSize(int, MemoryType).

Definition at line 41 of file multivector.cpp.


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