-
Notifications
You must be signed in to change notification settings - Fork 12
/
csf.h
168 lines (142 loc) · 4.91 KB
/
csf.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
/*
Developed by Sandeep Sharma and Garnet K.-L. Chan, 2012
Copyright (c) 2012, Garnet K.-L. Chan
This program is integrated in Molpro with the permission of
Sandeep Sharma and Garnet K.-L. Chan
*/
#ifndef SPIN_CSF_HEADER
#define SPIN_CSF_HEADER
#include "orbstring.h"
#include <iostream>
#include "global.h"
#include <map>
#include "slater.h"
#include "Symmetry.h"
#include <boost/functional/hash.hpp>
#include <boost/shared_ptr.hpp>
#include "IrrepVector.h"
#include "tensor_operator.h"
namespace SpinAdapted{
struct Csf
{
map<Slater, double> det_rep;
int n;
SpinSpace S;
int Sz;
IrrepVector irrep;
public:
inline Csf () {}
Csf( const map<Slater, double>& p_dets, const int p_n, const SpinSpace p_S, const int p_Sz, const IrrepVector pirrep);
Csf (const Csf& s) : det_rep(s.det_rep), n(s.n), S(s.S), Sz(s.Sz), irrep(s.irrep){}
//void operator= (const Csf& s) { if (this != &s) {det_rep =s.det_rep; n = s.n; S = s.S; Sz = s.Sz; sym=s.sym;}}
// accessors
inline int size () const { return det_rep.size (); }
inline int n_is () const { return n; }
inline SpinSpace S_is () const { return S; }
inline int Sz_is () const { return Sz; }
inline int row() const {return irrep.getrow();}
inline IrrepSpace sym_is() const {
return IrrepSpace(irrep.getirrep());
}
void set_det_rep(map<Slater, double> p_det, SpinSpace pS, IrrepVector pirrep){
det_rep = p_det;
S = pS;
map<Slater, double>::iterator it = det_rep.begin();
n = it->first.n_is();
Sz = it->first.Sz_is();
irrep = pirrep;
}
void set_n(int p_n){n = p_n;}
void set_S(SpinSpace p_S){S = p_S;}
void set_Sz(int p_Sz){Sz = p_Sz;}
void set_irrep(IrrepVector p_irrep) {irrep = p_irrep;}
inline map<Slater, double> c (int i)
{
Slater s;
double d;
map<Slater, double> dets;
for (map<Slater, double>::iterator it = det_rep.begin(); it!= det_rep.end(); it++) {
s = (*it).first;
d = (*it).second;
s.c(i);
dets[s] = d;
}
return dets;
}
inline map<Slater, double> d (int i)
{
Slater s;
double d;
map<Slater, double> dets;
for (map<Slater, double>::iterator it = det_rep.begin(); it!= det_rep.end(); it++) {
s = (*it).first;
d = (*it).second;
s.d(i);
dets[s] = d;
}
return dets;
}
void applySplus(Csf& output);
void applySminus(Csf& output);
void applyRowminus(Csf& output, int orbL);
vector<Csf> spinLadder(int k);
void outerProd(const Csf& csf, double factor, map<Slater, double>& output) const;
void normalize()
{
double norm=0;
map<Slater, double>::iterator it = det_rep.begin();
for (; it!= det_rep.end(); it++)
norm += pow((*it).second,2);
for (it = det_rep.begin(); it!= det_rep.end(); it++)
(*it).second /= sqrt(norm);
}
double norm()
{
double norm=0;
map<Slater, double >::iterator it = det_rep.begin();
for (; it!= det_rep.end(); it++)
norm += pow((*it).second,2);
return norm;
}
bool isempty()
{
for (map<Slater, double>::iterator it = det_rep.begin(); it!= det_rep.end(); it++)
if (!(*it).first.alpha.isempty())
return false;
return true;
}
bool operator== (const Csf& s) const
{
if (SpinQuantum(n, S, sym_is()) == SpinQuantum(s.n, s.S, s.sym_is()))
return true;
else
return false;
}
bool operator< (const Csf& s) const;
friend ostream& operator<< (ostream& os, const Csf& s)
{
os <<"n: "<<s.n<<" S: "<<s.S<<" Sz: "<<s.Sz<<" Irrep: "<<s.irrep<<","<<s.row()<<endl;
map<Slater, double>::const_iterator it = s.det_rep.begin();
for (; it!= s.det_rep.end(); it++)
os<<(*it).second<<" "<<(*it).first;
return os;
}
static std::vector< Csf > distribute (const int n, const int s, const IrrepVector &sym, const int left, const int right, const int edge, int integralIndex);
static std::vector<Csf> distributeNonSpinAdapted (const int n, const int sp, const IrrepVector &sym, const int left, const int right, const int edge, int integralIndex);
};
namespace CSFUTIL {
std::vector< Csf > spinfockstrings(const std::vector<int>& orbs, std::vector<std::vector<Csf> >& ladders);
std::vector< Csf > spinfockstrings(const std::vector<int>& orbs);
void TensorProduct(Csf& lhs, vector<Csf>& lhs_csfs, Csf& rhs, vector<Csf>& rhs_csfs, vector< Csf >& output, vector< vector<Csf> >& outputladder);
void TensorProduct(Csf& lhs, Csf& rhs, vector< Csf >& output);
Csf applyTensorOp(const TensorOp& newop, int spinL);
vector< vector<int> > generate_partitions(int k);
}
struct Csfcompare
{
Csfcompare(){};
bool operator() (const boost::shared_ptr<Csf>& c1, const boost::shared_ptr<Csf>& c2) const {return (*c1 < *c2);}
};
double csf_energy (const Csf& s, int integralIndex);
}
#endif