forked from chengchen1987/ed_Nkpz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hmatrix_k.cpp
162 lines (151 loc) · 5.2 KB
/
hmatrix_k.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
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#include "basis.h"
#include "hmatrix.h"
void Ham_HardCoreBoson<double>::DenseMat_Build_k()
{
my_int matlen = (my_int)Dim * (my_int)Dim;
cout << "Dim*Dim = " << matlen << endl;
cout << "Estimated memory cost of the dense matrix: " << matlen * 8 / 1e9 << " GB" << endl;
double kk = basis_k->get_k() * 2 * PI / LatticeSize;
DMat = new double[matlen];
for (my_int s = 0; s < matlen; s++) DMat[s] = 0;
//omp_set_num_threads(NUMTHREADS);
// #pragma omp parallel for schedule(dynamic)
/*-------------------------------------------------------------------
H = -t*sum_{i < j}[b_i^+ b_j^- + b_i^- b_j^+]
+ V * sum_{i < j} (i,r) r^(-3) n_i n_{i+r}
--------------------------------------------------------------------*/
for (my_int s = 0; s < Dim; s++) {
my_int state_s;
state_s = basis_k->get_state(s);
double Ra = basis_k->get_Rs(s);
// diagoanl term
// V * sum_{i < j} (i,r) r^(-3) n_i n_{i+r}
my_int diag_index = s + s * Dim;
for (my_int ib = 0; ib < N_ints; ib++)
{
my_int i = std::get<0>(ints[ib]);
my_int j = std::get<1>(ints[ib]);
my_int s_i = ((state_s >> i) & 1);
my_int s_j = ((state_s >> j) & 1);
if (s_i & s_j) DMat[diag_index] += std::get<2>(ints[ib]);
}
// offdiagonal term
// -t*sum_{i < j}[b_i^+ b_j^- + b_i^- b_j^+]
for (my_int ib = 0; ib < N_hops; ib++)
{
my_int i = std::get<0>(hops[ib]);
my_int j = std::get<1>(hops[ib]);
my_int s_i = ((state_s >> i) & 1);
my_int s_j = ((state_s >> j) & 1);
if ((s_i) ^ (s_j))
//if ((s_i) && (!s_j))
{
my_int state_s1b = state_s ^ (1 << i) ^ (1 << j);
my_int state_s1;
my_int lb;
basis_k->Representative(state_s1b, state_s1, lb);
double Rb = basis_k->CheckState_Ra(state_s1);
if (-1 != Rb) {
my_int s1 = basis_k->get_index(state_s1);
DMat[s * Dim + s1] += std::get<2>(hops[ib]) * sqrt(Ra / Rb) * cos(kk * lb);
/*
cout << s << " ";
Bits_Print(state_s,LatticeSize);
cout << s1 << " ";
Bits_Print(state_s1b,LatticeSize);
cout << "i = " << i << ", j = " << j << endl;
cout << std::get<2>(hops[ib]) * sqrt(Ra / Rb) * cos(2 * PI * Params.k * lb / LatticeSize) << " " << std::get<2>(hops[ib]) << " " << sqrt(Ra / Rb) << " " << cos(2 * PI * Params.k * lb / LatticeSize) << endl;
*/
}
//cout << "x" << endl;
}
}
}
/*
cout << "Dense matrix of H:" << endl;
for (my_int i = 0; i < Dim; i++)
{
for (my_int j = 0; j < Dim; j++)
{
cout << setw(8) << setprecision(4) << DMat[i * Dim + j];
}
cout << endl;
}
*/
}
void Ham_HardCoreBoson<my_cmplx>::DenseMat_Build_k()
{
my_cmplx II(0, 1);
my_int matlen = (my_int)Dim * (my_int)Dim;
cout << "Dim*Dim = " << matlen << endl;
cout << "Estimated memory cost of the dense matrix: " << matlen * 8 / 1e9 << " GB" << endl;
double kk = basis_k->get_k() * 2 * PI / LatticeSize;
DMat = new my_cmplx[matlen];
for (my_int s = 0; s < matlen; s++) DMat[s] = 0;
//omp_set_num_threads(NUMTHREADS);
// #pragma omp parallel for schedule(dynamic)
/*-------------------------------------------------------------------
H = -t*sum_{i < j}[b_i^+ b_j^- + b_i^- b_j^+]
+ V * sum_{i < j} (i,r) r^(-3) n_i n_{i+r}
--------------------------------------------------------------------*/
//double kk = Params.k
for (my_int s = 0; s < Dim; s++) {
my_int state_s;
state_s = basis_k->get_state(s);
double Ra = basis_k->get_Rs(s);
// diagoanl term
// V * sum_{i < j} (i,r) r^(-3) n_i n_{i+r}
my_int diag_index = s + s * Dim;
for (my_int ib = 0; ib < N_ints; ib++)
{
my_int i = std::get<0>(ints[ib]);
my_int j = std::get<1>(ints[ib]);
my_int s_i = ((state_s >> i) & 1);
my_int s_j = ((state_s >> j) & 1);
if (s_i & s_j) DMat[diag_index] += std::get<2>(ints[ib]);
}
// offdiagonal term
// -t*sum_{i < j}[b_i^+ b_j^- + b_i^- b_j^+]
for (my_int ib = 0; ib < N_hops; ib++)
{
my_int i = std::get<0>(hops[ib]);
my_int j = std::get<1>(hops[ib]);
my_int s_i = ((state_s >> i) & 1);
my_int s_j = ((state_s >> j) & 1);
if ((s_i) ^ (s_j))
//if ((s_i) && (!s_j))
{
my_int state_s1b = state_s ^ (1 << i) ^ (1 << j);
my_int state_s1;
my_int lb;
basis_k->Representative(state_s1b, state_s1, lb);
double Rb = basis_k->CheckState_Ra(state_s1);
if (-1 != Rb) {
my_int s1 = basis_k->get_index(state_s1);
DMat[s * Dim + s1] += std::get<2>(hops[ib]) * sqrt(Ra / Rb) * cos(kk * lb);
DMat[s * Dim + s1] += std::get<2>(hops[ib]) * sqrt(Ra / Rb) * sin(kk * lb) * II;
/*
cout << s << " ";
Bits_Print(state_s, LatticeSize);
cout << s1 << " ";
Bits_Print(state_s1b, LatticeSize);
cout << "i = " << i << ", j = " << j << endl;
cout << std::get<2>(hops[ib]) * sqrt(Ra / Rb) * cos(2 * PI * Params.k * lb / LatticeSize) << " " << std::get<2>(hops[ib]) << " " << sqrt(Ra / Rb) << " " << cos(2 * PI * Params.k * lb / LatticeSize) << endl;
*/
}
//cout << "x" << endl;
}
}
}
}