forked from sanshar/Block
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpinQuantum.C
146 lines (124 loc) · 4.33 KB
/
SpinQuantum.C
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
/*
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
*/
#include "SpinQuantum.h"
#include "global.h"
namespace SpinAdapted{
SpinQuantum::SpinQuantum () : particleNumber (0), totalSpin (0), orbitalSymmetry (0) {}
SpinQuantum::SpinQuantum (const int p, const SpinSpace s, const IrrepSpace orbS) : particleNumber (p), totalSpin (s), orbitalSymmetry(orbS) {}
int SpinQuantum::insertionNum(const SpinQuantum& ql, const SpinQuantum& qr) const
{
int index = 0;
vector<SpinSpace> spins = ql.totalSpin+qr.totalSpin;
vector<IrrepSpace> vec = ql.orbitalSymmetry+qr.orbitalSymmetry;
for (int i=0; i< spins.size(); i++) {
for (int j=0; j<vec.size(); j++) {
if (*this == SpinQuantum(ql.particleNumber+qr.particleNumber, spins[i], vec[j]))
return index;
else
index++;
}
}
return -1;
}
vector<SpinQuantum> SpinQuantum::spinToNonSpin() const
{
vector<SpinQuantum> quanta;
if(totalSpin.getirrep() < 0 ) {
pout << "The quanta is already nonspinAdapted"<<endl;
exit(0);
}
if (dmrginp.spinAdapted()) {
quanta.push_back(*this);
return quanta;
}
else {
for (int i=-totalSpin.getirrep(); i<=totalSpin.getirrep(); i+=2)
quanta.push_back(SpinQuantum(particleNumber, SpinSpace(i), orbitalSymmetry));
return quanta;
}
}
vector<SpinQuantum> SpinQuantum::operator+ (const SpinQuantum q) const
{
vector<SpinQuantum> quanta;
vector<SpinSpace> spins = totalSpin+q.totalSpin;
vector<IrrepSpace> vec = orbitalSymmetry+q.orbitalSymmetry;
for (int i=0; i< spins.size(); i++)
for (int j=0; j<vec.size(); j++)
quanta.push_back(SpinQuantum(particleNumber+q.particleNumber, spins[i], vec[j]));
return quanta;
}
vector<SpinQuantum> SpinQuantum::operator- (const SpinQuantum q) const
{
SpinQuantum negative = -q;
return *this+negative;
}
SpinQuantum SpinQuantum::operator-() const
{
return SpinQuantum(-particleNumber, -totalSpin, -orbitalSymmetry);
}
bool SpinQuantum::allow(const SpinQuantum s1, const SpinQuantum s2) const
{
std::vector<SpinQuantum> sumQ = s1+s2;
for (int i=0; i<sumQ.size(); i++)
if (*this == sumQ[i])
return true;
return false;
}
bool SpinQuantum::operator== (const SpinQuantum q) const
{
return ((particleNumber == q.particleNumber) && (totalSpin == q.totalSpin) && (orbitalSymmetry == q.orbitalSymmetry));
}
bool SpinQuantum::operator!= (const SpinQuantum q) const
{
return ((particleNumber != q.particleNumber) || (totalSpin != q.totalSpin) || (orbitalSymmetry != q.orbitalSymmetry));
}
bool SpinQuantum::operator< (const SpinQuantum q) const
{
return ((particleNumber < q.particleNumber) || ((particleNumber == q.particleNumber) && (totalSpin < q.totalSpin)) ||
((particleNumber == q.particleNumber) && (totalSpin == q.totalSpin) && (orbitalSymmetry < q.orbitalSymmetry)));
}
bool IsFermion (const SpinQuantum q)
{
return (q.particleNumber & 1);
}
ostream& operator<< (ostream& os, const SpinQuantum q)
{
os << q.particleNumber << ":" << q.totalSpin << ":" << q.orbitalSymmetry;
return os;
}
bool SpinQuantum::can_complement (SpinQuantum q)
{
int q_try = dmrginp.total_particle_number() - q.get_n();
int s_try = abs(dmrginp.total_spin_number().getirrep() - q.get_s().getirrep());
return (abs(s_try) <= q_try);
}
vector<SpinQuantum> SpinQuantum::get_complement () const
{
vector<SpinQuantum> quanta;
vector<int> ns;
if (dmrginp.hamiltonian() == BCS) {
for (int n = 0; n <= dmrginp.total_particle_number(); n+=2) {
if (n-particleNumber < 0) continue;
ns.push_back(n-particleNumber);
}
} else {
ns.push_back(dmrginp.total_particle_number() - particleNumber);
}
vector<SpinSpace> spins = dmrginp.total_spin_number() + (- totalSpin);
vector<IrrepSpace> vec = dmrginp.total_symmetry_number() + (- orbitalSymmetry);
for (int n_idx = 0; n_idx < ns.size(); ++n_idx) {
int n = ns[n_idx];
for (int i=0; i< spins.size(); i++) {
if (abs(i) <= n) {
for (int j=0; j<vec.size(); j++)
quanta.push_back(SpinQuantum(n, spins[i], vec[j]));
}
}
}
return quanta;
}
}