-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathham2D.cpp
161 lines (132 loc) · 3.63 KB
/
ham2D.cpp
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
/* Copyright (C) 2012 Ward Poelmans
This file is part of Hubbard-GPU.
Hubbard-GPU is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Hubbard-GPU is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hubbard-GPU. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "ham2D.h"
/**
* Constructor of the HubHam2D class
* @param L The Length of the 2D grid
* @param D The depth of the 2D grid
* @param Nu Number of Up Electrons
* @param Nd Number of Down Electrons
* @param J The hopping strengh
* @param U The onsite interaction strength
*/
HubHam2D::HubHam2D(int L, int D, int Nu, int Nd, double J, double U)
: Hamiltonian(L*D,Nu,Nd,J,U)
{
this->L = L;
this->D = D;
}
/**
* Destructor of the HubHam2D class
*/
HubHam2D::~HubHam2D()
{
}
/**
* private method used to see if a hopping between state a and b is
* possible and with which sign: this is for 2D hubbard.
* @param a the bra to use
* @param b the ket to use
* @param jump does nothing, is set by default to zero, please ignore.
* @returns matrix element of the hopping term between the ket and the bra. You still
* have to multiply this with the hopping strength J
*/
int HubHam2D::hopping(myint a, myint b, int jump) const
{
int result(0), sign;
for(int i=0;i<L;i++)
if( a & 1<<i ) // is the i'th bit set?
{
int j;
// jump up
j = (i + L) % L;
if( (~a & 1<<j) && ((a ^ ((1<<i)+(1<<j)) ) == b ) )
{
if(j>i)
sign = CalcSign(i,j,a);
else
sign = CalcSign(j,i,a);
// a minus sign in the hamiltonian ( -J *)
result = -1 * sign;
break;
}
// jump down
j = (i - L + L) % L;
if( (~a & 1<<j) && ((a ^ ((1<<i)+(1<<j)) ) == b ) )
{
if(j>i)
sign = CalcSign(i,j,a);
else
sign = CalcSign(j,i,a);
result = -1 * sign;
break;
}
// jump right
j = L * (i/L) + (i + 1) % L;
if( (~a & 1<<j) && ((a ^ ((1<<i)+(1<<j)) ) == b ) )
{
if(j>i)
sign = CalcSign(i,j,a);
else
sign = CalcSign(j,i,a);
result = -1 * sign;
break;
}
// jump left
j = L * (i/L) + (i - 1 + L) % L;
if( (~a & 1<<j) && ((a ^ ((1<<i)+(1<<j)) ) == b ) )
{
if(j>i)
sign = CalcSign(i,j,a);
else
sign = CalcSign(j,i,a);
result = -1 * sign;
break;
}
}
return result;
}
/**
* Builds the full 2D Hubbard Hamiltonian matrix
*/
void HubHam2D::BuildFullHam()
{
if( !baseUp.size() || !baseDown.size() )
{
std::cerr << "Build base before building Hamiltonian" << std::endl;
return;
}
ham = new double[dim*dim];
int NumDown = CalcDim(L,Nd);
for(unsigned int a=0;a<baseUp.size();a++)
for(unsigned int b=0;b<baseDown.size();b++)
{
int i = a * NumDown + b;
for(unsigned int c=a;c<baseUp.size();c++)
for(unsigned int d=0;d<baseDown.size();d++)
{
int j = c * NumDown + d;
ham[j+dim*i] = 0;
if(b == d)
ham[j+dim*i] += J * hopping(baseUp[a], baseUp[c]);
if(a == c)
ham[j+dim*i] += J * hopping(baseDown[b], baseDown[d]);
ham[i+dim*j] = ham[j+dim*i];
}
// count number of double occupied states
ham[i+dim*i] = U * CountBits(baseUp[a] & baseDown[b]);
}
}
/* vim: set ts=8 sw=4 tw=0 expandtab :*/