VMPS++
Loading...
Searching...
No Matches
Basis.h
Go to the documentation of this file.
1#ifndef BASIS_H_
2#define BASIS_H_
3
11class Basis
12{
13public:
15 Basis() {};
16
17 Basis(std::vector<std::string> idents, Eigen::Index dim) {
18 Eigen::Index count = 0;
19 for(const auto& ident : idents) {
20 auto entry = std::make_tuple(ident,count);
21 data_.push_back(entry);
22 count++;
23 }
24 curr_dim += dim;
25 };
26
27 Basis(Eigen::Index dim) {
28 std::vector<std::string> idents(dim,"");
29 Basis(idents,dim);
30 };
31
32 Eigen::Index size() const {return data_.size();}
33
34 void push_back( const std::string& ident) {
35 data_.push_back(std::make_tuple(ident,curr_dim));
36 curr_dim++;
37 };
38
39 void push_back( const std::vector<std::string> &idents) {
40 for (const auto &ident:idents)
41 {
42 data_.push_back(std::make_tuple(ident,curr_dim));
43 curr_dim++;
44 }
45 };
46
47 bool find( std::string ident_in ) {
48 for(const auto& elem : data_) {auto [ident,num] = elem; if (ident == ident_in) {return true;}}
49 return false;
50 }
51 Eigen::Index location( std::string ident_in ) {
52 for(const auto& elem : data_) {auto [ident,num] = elem; if (ident == ident_in) {return num;}}
53 return std::numeric_limits<Eigen::Index>::max();
54 }
55
57 Basis add (const Basis& other) const;
58
63 Basis combine (const Basis& other) const;
64
66 std::string print() const;
67
68 std::vector<std::tuple<std::string,Eigen::Index> >::iterator begin() { return data_.begin(); }
69 std::vector<std::tuple<std::string,Eigen::Index> >::iterator end() { return data_.end(); }
70
71 std::vector<std::tuple<std::string,Eigen::Index> >::const_iterator cbegin() const { return data_.cbegin(); }
72 std::vector<std::tuple<std::string,Eigen::Index> >::const_iterator cend() const { return data_.cend(); }
73
74 bool operator==( const Basis& other ) const {return (this->data_ == other.data_);}
75
76 friend ostream& operator<<(ostream& os, const Basis &basis);
77
78//private:
79 struct fuseData
80 {
81 Eigen::Index dim1,dim2;
82 std::array<Eigen::Index,2> source(Eigen::Index combined_num) const
83 {
84 Eigen::Index tmp = combined_num / dim1;
85 return {{combined_num - dim1*tmp, tmp}};
86 };
87 };
88
89 std::vector<std::tuple<std::string,Eigen::Index> > data_;
90 Eigen::Index curr_dim = 0;
92};
93
95add (const Basis& other) const
96{
97 Basis out;
98
99 for (const auto &[ident,num] : data_)
100 {
101 out.push_back(ident);
102 }
103 for (const auto &[ident,num] : other.data_)
104 {
105 out.push_back(ident);
106 }
107 return out;
108}
109
111combine (const Basis& other) const
112{
113 Basis out;
114 out.history.dim1 = this->size();
115 out.history.dim2 = other.size();
116
117 for(const auto& [ident2,num2] : other.data_)
118 for(const auto& [ident1,num1] : this->data_)
119 {
120 // out.data_.push_back(std::make_tuple(ident1+"⊗"+ident2,num1 + this->size()*num2));
121 out.data_.push_back(std::make_tuple("",num1 + this->size()*num2));
122 }
123 return out;
124}
125
126std::string Basis::
127print() const
128{
129 std::stringstream out;
130 TextTable t( '-', '|', '+' );
131 t.add("num");
132 t.add("ident");
133 t.endOfRow();
134 for (const auto& [ident,num] : data_)
135 {
136 std::stringstream ss, tt;
137 ss << ident;
138 tt << num;
139 t.add(ss.str());
140 t.add(tt.str());
141 t.endOfRow();
142 }
143 out << t;
144 return out.str();
145}
146
147std::ostream& operator<<(std::ostream& os, const Basis &basis)
148{
149 os << basis.print();
150 return os;
151}
152#endif
std::ostream & operator<<(std::ostream &os, const Basis &basis)
Definition: Basis.h:147
size_t dim(const PivotMatrix0< Symmetry, Scalar, MpoScalar > &H)
Definition: Basis.h:12
Basis combine(const Basis &other) const
Definition: Basis.h:111
friend ostream & operator<<(ostream &os, const Basis &basis)
Eigen::Index size() const
Definition: Basis.h:32
Basis(Eigen::Index dim)
Definition: Basis.h:27
std::vector< std::tuple< std::string, Eigen::Index > >::iterator begin()
Definition: Basis.h:68
std::vector< std::tuple< std::string, Eigen::Index > >::iterator end()
Definition: Basis.h:69
Basis::fuseData history
Definition: Basis.h:91
Eigen::Index location(std::string ident_in)
Definition: Basis.h:51
Eigen::Index curr_dim
Definition: Basis.h:90
void push_back(const std::string &ident)
Definition: Basis.h:34
void push_back(const std::vector< std::string > &idents)
Definition: Basis.h:39
Basis()
Definition: Basis.h:15
Basis(std::vector< std::string > idents, Eigen::Index dim)
Definition: Basis.h:17
std::string print() const
Definition: Basis.h:127
std::vector< std::tuple< std::string, Eigen::Index > > data_
Definition: Basis.h:89
bool operator==(const Basis &other) const
Definition: Basis.h:74
bool find(std::string ident_in)
Definition: Basis.h:47
std::vector< std::tuple< std::string, Eigen::Index > >::const_iterator cbegin() const
Definition: Basis.h:71
Basis add(const Basis &other) const
Definition: Basis.h:95
std::vector< std::tuple< std::string, Eigen::Index > >::const_iterator cend() const
Definition: Basis.h:72
Eigen::Index dim1
Definition: Basis.h:81
std::array< Eigen::Index, 2 > source(Eigen::Index combined_num) const
Definition: Basis.h:82
Eigen::Index dim2
Definition: Basis.h:81