12#ifndef MFEM_MULTIVECTOR_HPP
13#define MFEM_MULTIVECTOR_HPP
45 std::vector<std::variant<Vector,Vector*,const Vector*>> blocks;
54 : blocks(num_blocks) { }
88 template <
typename... VectorTypes,
91 std::is_convertible<VectorTypes&,Vector&>...>,
bool> =
true>
97 template <
typename... VectorTypes,
100 std::is_convertible<const VectorTypes&,const Vector&>...>,
150 blocks[i].emplace<0>(base, offset, size);
164 template <
typename... VectorTypes,
167 std::is_convertible<VectorTypes&,Vector&>...>,
bool> =
true>
168 inline void MakeRef(VectorTypes &...vs);
173 template <
typename... VectorTypes,
176 std::is_convertible<const VectorTypes&,const Vector&>...>,
178 inline void MakeRef(
const VectorTypes &...vs);
198 auto &bi = blocks[i];
199 const auto idx = bi.index();
200 if (idx == 0) {
return std::get<0>(bi); }
201 if (idx == 1) {
return *std::get<1>(bi); }
202 MFEM_ABORT(
"Non-const access to a const Vector block!");
207 auto &bi = blocks[i];
208 const auto idx = bi.index();
209 return (idx == 0) ? std::get<0>(bi) :
210 (idx == 1) ? *std::get<1>(bi) :
214template <
typename... VectorTypes,
217 std::is_convertible<VectorTypes&,Vector&>...>,
bool>>
220 blocks.resize(
sizeof...(vs));
221 if constexpr (
sizeof...(vs) > 0)
223 const std::array vs_p{&
static_cast<Vector&
>(vs)...};
224 for (std::size_t i = 0; i <
sizeof...(vs); i++)
231template <
typename... VectorTypes,
234 std::is_convertible<const VectorTypes&,const Vector&>...>,
238 blocks.resize(
sizeof...(vs));
239 if constexpr (
sizeof...(vs) > 0)
241 const std::array vs_p{&
static_cast<const Vector&
>(vs)...};
242 for (std::size_t i = 0; i <
sizeof...(vs); i++)
Class representing an array of Vectors with generally different sizes.
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 gi...
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.
void SetNumBlocks(int num_blocks)
Set the number of Vectors in the MultiVector. Existing Vector blocks will remain unmodified....
int NumBlocks() const
Return the number of Vectors in the MultiVector.
void MakeRef(int i, Vector &v)
Update the i-th MultiVector block to reference the given Vector v.
MultiVector(VectorTypes &...vs)
Construct a MultiVector referencing multiple Vectors given as arguments.
MultiVector()=default
Create an empty MultiVector with zero blocks.
void MakeRef(Vector &base, const Array< int > &vector_sizes)
Update the MultiVector to reference data within a given monolithic Vector base.
MultiVector(int num_blocks)
Create a MultiVector with num_blocks blocks. The individual Vector blocks are default initialized,...
MultiVector(const VectorTypes &...vs)
Construct a MultiVector referencing multiple const Vectors given as arguments. Individual blocks are ...
Vector & operator[](int i)
Read-write access to the i-th Vector. Generates an error if the i-th block is read-only,...
void SetSizes(const Array< int > &vector_sizes)
Update the MultiVector according to the given vector_sizes.
MemoryType
Memory types supported by MFEM.