-
Notifications
You must be signed in to change notification settings - Fork 33
/
fciqmchelper.h
125 lines (106 loc) · 3.88 KB
/
fciqmchelper.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
#ifndef FCIQMC_HELPER_HEADER_H
#define FCIQMC_HELPER_HEADER_H
#include "global.h"
#include <vector>
#include "boost/shared_ptr.hpp"
#include "StateInfo.h"
#include "Operators.h"
#include "wavefunction.h"
#include "ObjectMatrix.h"
typedef unsigned long int ulong;
namespace SpinAdapted{
class QSTensor {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & allowedQuanta & leftQuanta & rightQuanta & data & nl & nr;
}
ObjectMatrix<char> allowedQuanta;
std::vector<SpinQuantum> leftQuanta, rightQuanta;
ObjectMatrix<Matrix> data;
int nl, nr;
public:
QSTensor():nl(0), nr(0) {}
QSTensor(int l, int r):nl(l), nr(r) {allowedQuanta.ReSize(nl, nr); data.ReSize(nl, nr);}
QSTensor(const std::vector<SpinQuantum>& lq, const std::vector<SpinQuantum>& rq):leftQuanta(lq), rightQuanta(rq), nl(lq.size()), nr(rq.size()) {
allowedQuanta.ReSize(nl, nr); data.ReSize(nl, nr);
}
void Init(int l, int r) {
nl = l;
nr = r;
allowedQuanta.ReSize(nl, nr); data.ReSize(nl, nr);
}
void Init(const std::vector<SpinQuantum>& lq, const std::vector<SpinQuantum>& rq) {
leftQuanta = lq;
rightQuanta = rq;
nl = lq.size();
nr = rq.size();
allowedQuanta.ReSize(nl, nr); data.ReSize(nl, nr);
}
bool allowed(int i, int j) const {return allowedQuanta(i,j);}
ObjectMatrix<char>& allowedMatrix() {return allowedQuanta;}
Matrix& operator() (int i, int j) {return data(i,j);}
const Matrix& operator() (int i, int j) const {return data(i,j);}
std::vector<SpinQuantum>& lQuanta() {return leftQuanta;}
const std::vector<SpinQuantum>& lQuanta() const {return leftQuanta;}
std::vector<SpinQuantum>& rQuanta() {return rightQuanta;}
const std::vector<SpinQuantum>& rQuanta() const {return rightQuanta;}
int lsize() const { return nl;}
int rsize() const { return nr;}
void CleanUp() {
data.ReSize(0,0);
allowedQuanta.ReSize(0,0);
leftQuanta.clear();
rightQuanta.clear();
nl = 0;
nr = 0;
}
void remove_empty();
friend ostream& operator<< (ostream& os, const QSTensor& q);
};
QSTensor TensorProduct(const QSTensor& A, const QSTensor& B);
void SaveQSTensor(const int& site, const QSTensor& m, int state);
void LoadQSTensor(const int& site, QSTensor& m, int state);
//the MPS is stored in the left canonical form
//LLLLL..LC
class MPS{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & SiteTensors \
& w & MPSrep;
}
std::vector< std::vector<Matrix> > SiteTensors; //these are the L matrices
std::vector<std::vector<QSTensor>> MPSrep;
Wavefunction w; //the last wavefunction
void Init(std::vector<bool>& occ);
public:
static int sweepIters;
static bool spinAdapted;
static std::vector<SpinBlock> siteBlocks;
// It is the site block with implicit transpose.
MPS() {};
MPS(int stateindex);
MPS(std::vector<bool>& occ);
MPS(ulong* occnum, int length);
void buildMPSrep();
std::vector<Matrix>& getSiteTensors(int i) {return SiteTensors[i];}
const std::vector<Matrix>& getSiteTensors(int i) const {return SiteTensors[i];}
const Wavefunction& getw() const {return w;}
void scale(double r) {Scale(r, w);}
void normalize() {int success; w.Normalise(&success);}
double get_coefficient(const vector<bool>& occ_strings);
void writeToDiskForDMRG(int state, bool writeStateAverage=false);
};
//statea is multiplied with Operator O|Mpsa> and then we compress it to get stateb
//void compressOperatorTimesMPS(const MPS& statea, MPS& stateb);
//calculate overlap between a and b <Mpsa|Mpsb>
double calculateOverlap (const MPS& a, const MPS& b);
//calculate hamiltonian matrix between a and b <Mpsa|H|Mpsb>
void calcHamiltonianAndOverlap(const MPS& statea, const MPS& stateb, double& h, double& o, bool sameStates=false) ;
}
#endif