-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBlock.h
225 lines (169 loc) · 5.71 KB
/
Block.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#ifndef __TTNS_BLOCK_H
#define __TTNS_BLOCK_H
#include <iostream>
#include <vector>
#include <map>
#include <btas/SPARSE/SDArray.h>
#include "ttns_assert.h"
namespace ttns
{
typedef btas::SDArray<2> DmrgOperator;
typedef btas::TArray<DmrgOperator, 1> OpArray1d;
typedef btas::TArray<DmrgOperator, 2> OpArray2d;
/// Block operators
/// For some complications in OpComponents*.h, use SDArray, i.e. not quantum number-based array
/// This is not fully object-oriented, and thus, not really safe,
/// while, it can reduce overheads from quantum number contraction.
class Block
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize (Archive& ar, const unsigned int version)
{
ar & i_index_ & o_index_;
ar & op_Ham_;
ar & op_Cre_ & op_Cre_Comp_;
ar & op_Cre_Cre_ & op_Cre_Cre_Comp_;
ar & op_Cre_Des_ & op_Cre_Des_Comp_;
}
protected:
std::map<size_t, size_t> i_index_; ///< index belongs to this block
std::map<size_t, size_t> o_index_; ///< complement of i_index_
DmrgOperator op_Ham_;
OpArray1d op_Cre_;
OpArray1d op_Cre_Comp_;
OpArray2d op_Cre_Cre_;
OpArray2d op_Cre_Cre_Comp_;
OpArray2d op_Cre_Des_;
OpArray2d op_Cre_Des_Comp_;
template<class Archive>
void load (Archive& ar, const unsigned int version)
{
ar >> i_index_ >> o_index_;
ar >> op_Ham_;
ar >> op_Cre_ >> op_Cre_Comp_;
ar >> op_Cre_Cre_ >> op_Cre_Cre_Comp_;
ar >> op_Cre_Des_ >> op_Cre_Des_Comp_;
}
template<class Archive>
void save (Archive& ar, const unsigned int version)
{
ar << i_index_ << o_index_;
ar << op_Ham_;
ar << op_Cre_ << op_Cre_Comp_;
ar << op_Cre_Cre_ << op_Cre_Cre_Comp_;
ar << op_Cre_Des_ << op_Cre_Des_Comp_;
op_Ham_.clear();
op_Cre_.clear();
op_Cre_Comp_.clear();
op_Cre_Cre_.clear();
op_Cre_Cre_Comp_.clear();
op_Cre_Des_.clear();
op_Cre_Des_Comp_.clear();
}
private:
static size_t n_orbs_;
template<typename... Args>
void __resize_by_args(std::vector<size_t>& i_orbs, const size_t& i, const Args&... ids)
{
i_orbs.push_back(i);
__resize_by_args(i_orbs, ids...);
}
inline void __resize_by_args(std::vector<size_t>& i_orbs, const size_t& i)
{
i_orbs.push_back(i);
this->resize(i_orbs);
}
public:
static size_t& orbitals () { return n_orbs_; }
/// Default constructor
Block ();
/// Destructor
~Block ();
/// Copy constructor
Block (const Block& x)
: i_index_ (x.i_index_),
o_index_ (x.o_index_),
op_Ham_ (x.op_Ham_),
op_Cre_ (x.op_Cre_),
op_Cre_Comp_ (x.op_Cre_Comp_),
op_Cre_Cre_ (x.op_Cre_Cre_),
op_Cre_Cre_Comp_ (x.op_Cre_Cre_Comp_),
op_Cre_Des_ (x.op_Cre_Des_),
op_Cre_Des_Comp_ (x.op_Cre_Des_Comp_)
{ }
/// Copy assignment
Block& operator= (const Block& x);
/// Construct by arguments
template<typename... Args>
Block (const size_t& i, const Args&... ids)
{
std::vector<size_t> i_orbs;
__resize_by_args(i_orbs, i, ids...);
}
/// resize by orbitals inside
Block (const std::vector<size_t>& i_orbs);
/// resize by arguments
template<typename... Args>
void resize (const size_t& i, const Args&... ids)
{
std::vector<size_t> i_orbs;
__resize_by_args(i_orbs, i, ids...);
}
/// resize by orbitals inside
void resize (const std::vector<size_t>& i_orbs);
/// return size
inline size_t size () const { return i_index_.size(); }
/// return index inside
std::vector<size_t> inside () const;
/// return index outside
std::vector<size_t> outside () const;
/// return Ham
inline DmrgOperator& Ham ()
{ return op_Ham_; }
/// return Ham
inline const DmrgOperator& Ham () const
{ return op_Ham_; }
/// return Cre
inline DmrgOperator& Cre (size_t i)
{ return op_Cre_(i_index_.find(i)->second); }
/// return Cre
inline const DmrgOperator& Cre (size_t i) const
{ return op_Cre_(i_index_.find(i)->second); }
/// return Cre Comp
inline DmrgOperator& CreComp (size_t i)
{ return op_Cre_Comp_(o_index_.find(i)->second); }
/// return Cre Comp
inline const DmrgOperator& CreComp (size_t i) const
{ return op_Cre_Comp_(o_index_.find(i)->second); }
/// return Cre Cre
inline DmrgOperator& CreCre (size_t i, size_t j)
{ return op_Cre_Cre_(i_index_.find(i)->second, i_index_.find(j)->second); }
/// return Cre Cre
inline const DmrgOperator& CreCre (size_t i, size_t j) const
{ return op_Cre_Cre_(i_index_.find(i)->second, i_index_.find(j)->second); }
/// return Cre Cre Comp
inline DmrgOperator& CreCreComp (size_t i, size_t j)
{ return op_Cre_Cre_Comp_(o_index_.find(i)->second, o_index_.find(j)->second); }
/// return Cre Cre Comp
inline const DmrgOperator& CreCreComp (size_t i, size_t j) const
{ return op_Cre_Cre_Comp_(o_index_.find(i)->second, o_index_.find(j)->second); }
/// return Cre Des
inline DmrgOperator& CreDes (size_t i, size_t j)
{ return op_Cre_Des_(i_index_.find(i)->second, i_index_.find(j)->second); }
/// return Cre Des
inline const DmrgOperator& CreDes (size_t i, size_t j) const
{ return op_Cre_Des_(i_index_.find(i)->second, i_index_.find(j)->second); }
/// return Cre Des Comp
inline DmrgOperator& CreDesComp (size_t i, size_t j)
{ return op_Cre_Des_Comp_(o_index_.find(i)->second, o_index_.find(j)->second); }
/// return Cre Des Comp
inline const DmrgOperator& CreDesComp (size_t i, size_t j) const
{ return op_Cre_Des_Comp_(o_index_.find(i)->second, o_index_.find(j)->second); }
void clear ();
};
} // namespace ttns
/// printing function
std::ostream& operator<< (std::ostream& ost, const ttns::Block& block);
#endif // __TTNS_BLOCK_H