-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain2D.cpp
149 lines (121 loc) · 4.34 KB
/
main2D.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
/* 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/>.
*/
/**
* This program is for 2D Hubbard.
* @author Ward Poelmans <wpoely86@gmail.com>
* @date 20-06-2012
*/
#include <iostream>
#include <boost/timer.hpp>
#include <getopt.h>
#include "ham2D.h"
#include "hamsparse2D_CSR.h"
#include "hamsparse2D.h"
using namespace std;
int main(int argc, char **argv)
{
int L = 3; // The Length of the 2D grid
int D = 3; // The Depth of the 2D grid
int Nu = 4; // number of up electrons
int Nd = 5; // number of down electrons
double J = 1.0; // hopping term
double U = 1.0; // on-site interaction strength
bool exact = false;
bool lanczos = false;
struct option long_options[] =
{
{"up", required_argument, 0, 'u'},
{"down", required_argument, 0, 'd'},
{"length", required_argument, 0, 'L'},
{"depth", required_argument, 0, 'D'},
{"interaction", required_argument, 0, 'U'},
{"hopping", required_argument, 0, 'J'},
{"exact", no_argument, 0, 'e'},
{"lanczos", no_argument, 0, 'l'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int i,j;
while( (j = getopt_long (argc, argv, "hu:d:L:D:U:J:el", long_options, &i)) != -1)
switch(j)
{
case 'h':
case '?':
cout << "Usage: " << argv[0] << " [OPTIONS]\n"
"\n"
" -L --length=l The length of the 2D grid\n"
" -D --depth=d The depth of the 2D grid\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"
" -h, --help Display this help\n"
"\n";
return 0;
break;
case 'u':
Nu = atoi(optarg);
break;
case 'd':
Nd = atoi(optarg);
break;
case 'L':
L = atoi(optarg);
break;
case 'D':
D = atoi(optarg);
break;
case 'U':
U = atof(optarg);
break;
case 'J':
J = atof(optarg);
break;
case 'l':
lanczos = true;
break;
case 'e':
exact = true;
break;
}
cout << "L = " << L << "; D = " << D << "; Nu = " << Nu << "; Nd = " << Nd << "; J = " << J << "; U = " << U << ";" << endl;
cout.precision(10);
boost::timer tijd;
if(exact)
{
tijd.restart();
HubHam2D ham(L,D,Nu,Nd,J,U);
ham.BuildBase();
ham.BuildFullHam();
cout << "Dim: " << ham.getDim() << endl;
auto E = ham.ExactDiagonalizeFull();
cout << "E = " << E[0] << endl;
cout << "Time: " << tijd.elapsed() << " s" << endl;
}
if(lanczos)
{
tijd.restart();
SparseHamiltonian2D sham(L,D,Nu,Nd,J,U);
sham.BuildBase();
sham.BuildSparseHam();
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 :*/