MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
multivector.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#include "multivector.hpp"
13
14namespace mfem
15{
16
18{
19 SetSizes(vector_sizes);
20}
21
23{
24 SetSizes(vector_sizes, mt);
25}
26
27MultiVector::MultiVector(Vector &base, const Array<int> &vector_sizes)
28{
29 MakeRef(base, vector_sizes);
30}
31
32void MultiVector::SetSizes(const Array<int> &vector_sizes)
33{
34 blocks.resize(vector_sizes.Size());
35 for (int i = 0; i < vector_sizes.Size(); i++)
36 {
37 operator[](i).SetSize(vector_sizes[i]);
38 }
39}
40
41void MultiVector::SetSizes(const Array<int> &vector_sizes, MemoryType mt)
42{
43 blocks.resize(vector_sizes.Size());
44 for (int i = 0; i < vector_sizes.Size(); i++)
45 {
46 operator[](i).SetSize(vector_sizes[i], mt);
47 }
48}
49
50void MultiVector::MakeRef(Vector &base, const Array<int> &vector_sizes)
51{
52 blocks.resize(vector_sizes.Size());
53 for (int offset = 0, i = 0; i < vector_sizes.Size(); i++)
54 {
55 blocks[i].emplace<0>(base, offset, vector_sizes[i]);
56 offset += vector_sizes[i];
57 }
58}
59
60} // namespace mfem
int Size() const
Return the logical size of the array.
Definition array.hpp:192
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.
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.
Vector data type.
Definition vector.hpp:82
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:633
MemoryType
Memory types supported by MFEM.