-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
250 lines (204 loc) · 7.47 KB
/
main.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* Copyright (C) 2012-2014 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 <algorithm>
#include <memory>
#include <sstream>
#include <boost/timer.hpp>
#include <getopt.h>
#include "ham.h"
#include "hamsparse.h"
#include "ham-mom.h"
#include "nonp-ham.h"
#include "ham-spin.h"
using namespace std;
int main(int argc, char **argv)
{
int L = 4; // number of sites
int Nu = 2; // number of up electrons
int Nd = 3; // number of down electrons
double J = 1.0; // hopping term
double U = 1.0; // on-site interaction strength
int whichS = -1;
bool exact = false;
bool lanczos = false;
bool momentum = false;
bool nonperiodic = false;
bool spin = false;
struct option long_options[] =
{
{"up", required_argument, 0, 'u'},
{"down", required_argument, 0, 'd'},
{"sites", required_argument, 0, 's'},
{"interaction", required_argument, 0, 'U'},
{"hopping", required_argument, 0, 'J'},
{"exact", no_argument, 0, 'e'},
{"lanczos", no_argument, 0, 'l'},
{"momentum", no_argument, 0, 'p'},
{"nonperiodic", no_argument, 0, 'n'},
{"symspin", no_argument, 0, 'z'},
{"spin", required_argument, 0, 'S'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int i,j;
while( (j = getopt_long (argc, argv, "hu:d:s:U:J:elpnzS:", long_options, &i)) != -1)
switch(j)
{
case 'h':
case '?':
cout << "Usage: " << argv[0] << " [OPTIONS]\n"
"\n"
" -s --sites=L The number of sites\n"
" -u --up=Nu The number of up electrons\n"
" -d --down=Nd The number of down electrons\n"
" -U --interaction=U The onsite interaction strength\n"
" -J --hopping=J The hopping strength\n"
" -e --exact Solve with exact diagonalisation\n"
" -l --lanczos Solve with Lanczos algorithm\n"
" -p --momentum Solve in the momentum basis\n"
" -n --nonperiodic Use non periodic boundary conditions\n"
" -z --symspin Use spin symmetry\n"
" -S --spin=S Limit to spin=S\n"
" -h, --help Display this help\n"
"\n";
return 0;
break;
case 'u':
Nu = atoi(optarg);
break;
case 'd':
Nd = atoi(optarg);
break;
case 's':
L = atoi(optarg);
break;
case 'U':
U = atof(optarg);
break;
case 'J':
J = atof(optarg);
break;
case 'l':
lanczos = true;
break;
case 'p':
momentum = true;
break;
case 'n':
nonperiodic = true;
break;
case 'z':
spin = true;
break;
case 'S':
whichS = atoi(optarg);
break;
case 'e':
exact = true;
break;
}
cout << "L = " << L << "; Nu = " << Nu << "; Nd = " << Nd << "; J = " << J << "; U = " << U << ";" << endl;
if(whichS!=-1)
cout << "Limiting to S=" << whichS << endl;
if(whichS!=-1 && !spin)
{
cerr << "Need to use spin symmetry to select a spin!" << endl;
return 1;
}
if(momentum && nonperiodic)
{
cerr << "Cannot use non periodic boundary conditions in the momentum base" << endl;
return 0;
}
cout.precision(10);
boost::timer tijd;
if(exact)
{
tijd.restart();
std::unique_ptr<BareHamiltonian> ham;
if(spin)
ham.reset(new SpinHamiltonian(L,Nu,Nd,J,U));
else if(momentum)
ham.reset(new MomHamiltonian(L,Nu,Nd,J,U));
else if(nonperiodic)
ham.reset(new NonPeriodicHamiltonian(L,Nu,Nd,J,U));
else
ham.reset(new Hamiltonian(L,Nu,Nd,J,U));
if(!spin)
{
cout << "Memory needed: " << ham->MemoryNeededFull()*1.0/1024*1.0/1024 << " MB" << endl;
cout << "Building base..." << endl;
ham->BuildBase();
cout << "Building hamiltonian..." << endl;
ham->BuildFullHam();
}
cout << "Dim: " << ham->getDim() << endl;
double Egroundstate = 0;
if(spin)
{
auto hampje = static_cast<SpinHamiltonian *>(ham.get());
hampje->BuildBase();
cout << "Building hamiltonian..." << endl;
if(whichS!=-1)
hampje->BuildHamWithS(whichS);
else
hampje->BuildFullHam();
auto E = hampje->ExactSpinDiagonalizeFull(false);
Egroundstate = std::get<2>(E[0]);
cout << "K\tS\tE" << endl;
for(auto p : E)
cout << std::get<0>(p) << "\t" << std::get<1>(p) << "\t" << std::get<2>(p) << endl;
// hampje->GenerateData(0,20,0.1,"data-S-6-3-3.h5");
}
else if(momentum)
{
auto E = (static_cast<MomHamiltonian *>(ham.get()))->ExactMomDiagonalizeFull(false);
cout << "Energy levels: " << endl;
for(auto p : E)
cout << p.second << "\t" << p.first << endl;
Egroundstate = E[0].second;
// (static_cast<MomHamiltonian *>(ham.get()))->GenerateData(0,10,1,"data-test.h5");
}
else
{
auto E = ham->ExactDiagonalizeFull(true);
cout << "Energy levels: " << endl;
for(auto p : E)
cout << p << endl;
Egroundstate = E[0];
}
cout << endl;
cout << "lowest E = " << Egroundstate << endl;
cout << "Time: " << tijd.elapsed() << " s" << endl;
}
if(lanczos)
{
tijd.restart();
std::unique_ptr<BareHamiltonian> sham;
if(nonperiodic)
sham.reset(new SparseHamiltonian<NonPeriodicHamiltonian>(L,Nu,Nd,J,U));
else
sham.reset(new SparseHamiltonian<Hamiltonian>(L,Nu,Nd,J,U));
cout << "Memory needed: " << sham->MemoryNeededArpack()*1.0/1024*1.0/1024 << " MB" << endl;
sham->BuildBase();
sham->BuildHam();
cout << "Dim: " << sham->getDim() << endl;
double E = sham->arpackDiagonalize();
cout << "E = " << E << endl;
cout << "Time: " << tijd.elapsed() << " s" << endl;
}
return 0;
}
/* vim: set ts=8 sw=4 tw=0 expandtab :*/