v2DM-DOCI  1.0
gen-hubbard.cpp
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Copyright (C) 2014-2015 Ward Poelmans
5  *
6  * This file is part of v2DM-DOCI.
7  *
8  * v2DM-DOCI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Foobar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @END LICENSE
22  */
23 
24 #include <iostream>
25 #include <cmath>
26 #include <getopt.h>
27 
28 // from CheMPS2
29 #include "Hamiltonian.h"
30 #include "OptIndex.h"
31 
32 
39 int main(int argc,char **argv)
40 {
41  using std::cout;
42  using std::endl;
43 
44  std::string output;
45  int L = 0;
46  int N = 0;
47  double U = 0;
48  bool momspace = false;
49 
50  struct option long_options[] =
51  {
52  {"output", required_argument, 0, 'o'},
53  {"interaction", required_argument, 0, 'U'},
54  {"sites", required_argument, 0, 'L'},
55  {"particles", required_argument, 0, 'N'},
56  {"momspace", no_argument, 0, 'm'},
57  {"help", no_argument, 0, 'h'},
58  {0, 0, 0, 0}
59  };
60 
61  int i,j;
62 
63  while( (j = getopt_long (argc, argv, "ho:U:L:N:m", long_options, &i)) != -1)
64  switch(j)
65  {
66  case 'h':
67  case '?':
68  cout << "Usage: " << argv[0] << " [OPTIONS]\n"
69  "\n"
70  " -o, --output=output-filename Set the output filename\n"
71  " -L, --sites=L Set the number of sites\n"
72  " -N, --particles=N Set the number of particles\n"
73  " -U, --interaction=U Set the on-site interaction\n"
74  " -m, --momspace Work in momentum space\n"
75  " -h, --help Display this help\n"
76  "\n";
77  return 0;
78  break;
79  case 'o':
80  output = optarg;
81  break;
82  case 'U':
83  U = atof(optarg);
84  break;
85  case 'L':
86  L = atoi(optarg);
87  break;
88  case 'N':
89  N = atoi(optarg);
90  break;
91  case 'm':
92  momspace = true;
93  break;
94  }
95 
96  if(! (L && N))
97  {
98  std::cerr << "You need to specifiy the system!" << endl;
99  return 1;
100  }
101 
102  cout << "Creating for L= " << L << " N= " << N << " U= " << U << endl;
103 
104  const std::vector<int> orb2irrep (L, 0);
105 
106  CheMPS2::Hamiltonian ham(L, 0, orb2irrep.data());
107  // put everything to zero
108  ham.reset();
109  ham.setNe(N);
110  ham.setEconst(0);
111 
112  if(momspace)
113  {
114  // Don't forget: you cannot rotate states of different momentum!
115 
116  // one-particle integrals
117  for(int i=0;i<L;i++)
118  ham.setTmat(i, i, -2*std::cos(2*M_PI/(1.0*L)*i));
119 
120  // two-particle integrals
121  for(int k1=0;k1<L;k1++)
122  for(int k2=0;k2<L;k2++)
123  for(int k3=0;k3<L;k3++)
124  for(int k4=0;k4<L;k4++)
125  if((k1+k2)%L == (k3+k4)%L)
126  ham.setVmat(k1,k2,k3,k4, U*1.0/L);
127 
128  } else
129  {
130  // one-particle integrals
131  for(int i=1;i<(L-1);i++)
132  {
133  ham.setTmat(i, i+1, -1);
134  ham.setTmat(i, i-1, -1);
135  }
136  ham.setTmat(0, 1, -1);
137  ham.setTmat(L-1, L-2, -1);
138 
139  // periodic boundary condition
140  ham.setTmat(0, L-1, -1);
141  ham.setTmat(L-1, 0, -1);
142 
143  // two-particle integrals
144  for(int i=0;i<L;i++)
145  ham.setVmat(i, i, i, i, U);
146  }
147 
148  if(output.empty())
149  {
150  output = "hub-integrals-";
151  if(momspace)
152  output += "mom-";
153 
154  output += std::to_string(L) + "-" + std::to_string(N) + "-" + std::to_string(U) + ".h5";
155  }
156 
157  cout << "Writing Hamiltonian to " << output << endl;
158 
159  ham.save2(output);
160 
161  return 0;
162 }
163 
164 /* vim: set ts=3 sw=3 expandtab :*/
void reset()
set everything to zero
int main(int argc, char **argv)
Definition: gen-hubbard.cpp:39