RealTimeTransport 1.0.0
Real-time simulation of quantum transport processes
Loading...
Searching...
No Matches
BlockVector.h
1//
2// This Source Code Form is subject to the terms of the Mozilla Public
3// License, v. 2.0. If a copy of the MPL was not distributed with this
4// file, You can obtain one at https://mozilla.org/MPL/2.0/.
5//
6
7#ifndef REAL_TIME_TRANSPORT_BLOCK_MATRICES_BLOCK_VECTOR_H
8#define REAL_TIME_TRANSPORT_BLOCK_MATRICES_BLOCK_VECTOR_H
9
10#include <vector>
11
12#include "../extern/boost_unordered.hpp"
13
14#include <SciCore/Definitions.h>
15
16#include "../Error.h"
17#include "../RealTimeTransport_export.h"
18
19namespace RealTimeTransport
20{
21
22// A vector of matrices, but most vector elements are zero. In this sense the vector is "sparse".
23class REALTIMETRANSPORT_EXPORT BlockVector
24{
25 public:
26 using Scalar = SciCore::Complex;
27 using MatrixType = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
28 using UnorderedElementMap = boost::unordered_flat_map<int, MatrixType>;
29
30 BlockVector() noexcept;
31 BlockVector(UnorderedElementMap&& elements) noexcept;
32
33 BlockVector& operator+=(const BlockVector& other);
34
35 void reserve(size_t s);
36 void emplace(int index, MatrixType&& A);
37
38 UnorderedElementMap::iterator begin() noexcept;
39 UnorderedElementMap::iterator end() noexcept;
40
41 UnorderedElementMap::const_iterator begin() const noexcept;
42 UnorderedElementMap::const_iterator end() const noexcept;
43
44 int size() const noexcept;
45 bool contains(int i) const;
46
47 UnorderedElementMap::iterator find(int i);
48 UnorderedElementMap::const_iterator find(int i) const;
49
50 void eraseZeroes(SciCore::Real prec = Eigen::NumTraits<Scalar>::dummy_precision());
51 void addToBlock(int i, MatrixType&& A);
52
53 private:
54 UnorderedElementMap _elements;
55};
56
57} // namespace RealTimeTransport
58
59#endif // REAL_TIME_TRANSPORT_BLOCK_MATRICES_BLOCK_VECTOR_H
#define REALTIMETRANSPORT_EXPORT
Definition RealTimeTransport_export.h:15