forked from chengchen1987/ed_Nkpz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmatrix_dynamic.cpp
423 lines (372 loc) · 12.3 KB
/
hmatrix_dynamic.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <vector>
#include <tuple>
#include <algorithm>
#include <ctime>
using namespace std;
#include "basis.h"
#include "hmatrix.h"
#include "sparsemat.h"
template <>
void Ham_HardCoreBoson<double>::Cal_PIr_wfsq(double* wfsq, double* HamD_pk, double* PI_r)
{
for (my_int r = 0; r < LatticeSize + 1; r++)
{
PI_r[r] = 0;
for (my_int k = 0; k < Dim; k++)
{
if (1e-10 > abs(r - HamD_pk[k]))
{
PI_r[r] += wfsq[k];
}
}
}
}
template <>
void Ham_HardCoreBoson<double>::DenseMat_Evo_form_s(my_int id, my_int ind)
{
my_int L = LatticeSize;
my_int nt = Params.evo_time_steps;
// compute Fidelity
double* Fid_t = new double[nt];
double* ipr_t = new double[nt];
double* PI_r_t = new double[nt];
double* EE_t = new double[nt];
double* ni_t = new double[nt * L];
double* ni_s = new double[Dim * L];
for (my_int i = 0; i < L; i++) { Cal_H_ni_s(i, &ni_s[i * Dim]); }
double* ninj_t = new double[nt * L * L];
double* ninj_s = new double[Dim * L * L];
for (my_int i = 0; i < L; i++)
for (my_int j = 0; j < L; j++) { Cal_H_ninj_s(i, j, &ninj_s[(i * L + j) * Dim]); }
double* bibj_t = new double[nt * L * L];
SparseMat<double>* smat_bibj = new SparseMat<double>[L * L];
for (my_int i = 0; i < L; i++)
for (my_int j = 0; j < L; j++) { Cal_H_bibj_Smat(i, j, &smat_bibj[i * L + j]); }
for (my_int it = 0; it < nt; it++) {
double t = Params.time_vec[it];
double* wf_r = new double[Dim];
double* wf_i = new double[Dim];
double* wf_sq = new double[Dim];
DenseMat_Get_psi_t(ind, t, wf_r, wf_i);
for (my_int s = 0; s < Dim; s++) { wf_sq[s] = wf_r[s] * wf_r[s] + wf_i[s] * wf_i[s]; }
// compute Fidelity, ipr, nnr, bbr
// Fidelity
Fid_t[it] = wf_r[ind] * wf_r[ind] + wf_i[ind] * wf_i[ind];
// ipr
ipr_t[it] = Cal_IPR_wfsq(wf_sq);
// EE
my_cmplx ii(0, 1);
my_cmplx* wft = new my_cmplx[Dim];
for (my_int s = 0; s < Dim; s++) { wft[s] = wf_r[s] + ii * wf_i[s]; }
my_int* sites = new my_int[L / 2];
for (my_int i = 0; i < L / 2; i++) { sites[i] = i; }
EE_t[it] = Cal_EE_wf(wft, L / 2, sites);
// ni
for (my_int i = 0; i < L; i++)
{
ni_t[it * L + i] = cblas_ddot(Dim, wf_sq, 1, &ni_s[i * Dim], 1);
}
// ninj
for (my_int i = 0; i < L; i++)
{
ninj_t[it * L * L + i * L + i] = ni_t[it * L + i];
for (my_int j = i + 1; j < L; j++)
{
ninj_t[it * L * L + i * L + j] = cblas_ddot(Dim, wf_sq, 1, &ninj_s[(i * L + j) * Dim], 1);
ninj_t[it * L * L + j * L + i] = ninj_t[it * L * L + i * L + j];
}
}
// bibj
for (my_int i = 0; i < L; i++)
{
bibj_t[it * L * L + i * L + i] = ni_t[it * L + i];
for (my_int j = i + 1; j < L; j++)
{
bibj_t[it * L * L + i * L + j] = Cal_Ob_smat(wf_r, wf_i, &smat_bibj[i * L + j]);
bibj_t[it * L * L + j * L + i] = bibj_t[it * L * L + i * L + j];
}
}
delete[]wf_sq;
delete[]wf_r;
delete[]wf_i;
}
char fout[80];
sprintf(fout, "evo_ipr_id%d.bin", id);
Vec_fwrite_double(fout, ipr_t, nt);
sprintf(fout, "evo_Fid_id%d.bin", id);
Vec_fwrite_double(fout, Fid_t, nt);
sprintf(fout, "evo_EE_id%d.bin", id);
Vec_fwrite_double(fout, EE_t, nt);
sprintf(fout, "evo_ni_id%d.bin", id);
Vec_fwrite_double(fout, ni_t, nt * L);
sprintf(fout, "evo_ninj_id%d.bin", id);
Vec_fwrite_double(fout, ninj_t, nt * L * L);
sprintf(fout, "evo_bibj_id%d.bin", id);
Vec_fwrite_double(fout, bibj_t, nt * L * L);
delete[]ipr_t;
delete[]Fid_t;
delete[]EE_t;
delete[]ni_t;
delete[]ninj_t;
delete[]bibj_t;
for (my_int r = 0; r < L * L; r++)
{
smat_bibj[r].SparseMat_Clear();
}
delete[]ninj_s;
delete[]ni_s;
}
template <>
void Ham_HardCoreBoson<double>::DenseMat_Evo_form_inds(my_int id, const my_int& ns, my_int* inds)
{
double* wf0 = new double[Dim];
for (my_int i = 0; i < Dim; i++) { wf0[i] = 0; }
for (my_int i = 0; i < ns; i++) { wf0[inds[i]] = 1.0 / sqrt(ns); }
my_int L = LatticeSize;
my_int nt = Params.evo_time_steps;
// compute Fidelity
double* Fid_t = new double[nt];
double* ipr_t = new double[nt];
double* PI_r_t = new double[nt];
double* EE_t = new double[nt];
double* ni_t = new double[nt * L];
double* ni_s = new double[Dim * L];
for (my_int i = 0; i < L; i++) { Cal_H_ni_s(i, &ni_s[i * Dim]); }
double* ninj_t = new double[nt * L * L];
double* ninj_s = new double[Dim * L * L];
for (my_int i = 0; i < L; i++)
for (my_int j = 0; j < L; j++) { Cal_H_ninj_s(i, j, &ninj_s[(i * L + j) * Dim]); }
double* bibj_t = new double[nt * L * L];
SparseMat<double>* smat_bibj = new SparseMat<double>[L * L];
for (my_int i = 0; i < L; i++)
for (my_int j = 0; j < L; j++) { Cal_H_bibj_Smat(i, j, &smat_bibj[i * L + j]); }
for (my_int it = 0; it < nt; it++) {
double t = Params.time_vec[it];
double* wf_r = new double[Dim];
double* wf_i = new double[Dim];
double* wf_sq = new double[Dim];
DenseMat_Get_psi_t(inds, ns, t, wf_r, wf_i);
for (my_int s = 0; s < Dim; s++) { wf_sq[s] = wf_r[s] * wf_r[s] + wf_i[s] * wf_i[s]; }
// compute Fidelity, ipr, nnr, bbr
// Fidelity
Fid_t[it] = cblas_ddot(Dim, wf0, 1, wf_sq, 1) * sqrt(ns);
// ipr
ipr_t[it] = Cal_IPR_wfsq(wf_sq);
// EE
my_cmplx ii(0, 1);
my_cmplx* wft = new my_cmplx[Dim];
for (my_int s = 0; s < Dim; s++) { wft[s] = wf_r[s] + ii * wf_i[s]; }
my_int* sites = new my_int[L / 2];
for (my_int i = 0; i < L / 2; i++) { sites[i] = i; }
EE_t[it] = Cal_EE_wf(wft, L / 2, sites);
// ni
for (my_int i = 0; i < L; i++)
{
ni_t[it * L + i] = cblas_ddot(Dim, wf_sq, 1, &ni_s[i * Dim], 1);
}
// ninj
for (my_int i = 0; i < L; i++)
{
ninj_t[it * L * L + i * L + i] = ni_t[it * L + i];
for (my_int j = i + 1; j < L; j++)
{
ninj_t[it * L * L + i * L + j] = cblas_ddot(Dim, wf_sq, 1, &ninj_s[(i * L + j) * Dim], 1);
ninj_t[it * L * L + j * L + i] = ninj_t[it * L * L + i * L + j];
}
}
// bibj
for (my_int i = 0; i < L; i++)
{
bibj_t[it * L * L + i * L + i] = ni_t[it * L + i];
for (my_int j = i + 1; j < L; j++)
{
bibj_t[it * L * L + i * L + j] = Cal_Ob_smat(wf_r, wf_i, &smat_bibj[i * L + j]);
bibj_t[it * L * L + j * L + i] = bibj_t[it * L * L + i * L + j];
}
}
delete[]wf_sq;
delete[]wf_r;
delete[]wf_i;
}
char fout[80];
sprintf(fout, "evo_ipr_id%d_vec.bin", id);
Vec_fwrite_double(fout, ipr_t, nt);
sprintf(fout, "evo_Fid_id%d_vec.bin", id);
Vec_fwrite_double(fout, Fid_t, nt);
sprintf(fout, "evo_EE_id%d_vec.bin", id);
Vec_fwrite_double(fout, EE_t, nt);
sprintf(fout, "evo_ni_id%d_vec.bin", id);
Vec_fwrite_double(fout, ni_t, nt * L);
sprintf(fout, "evo_ninj_id%d_vec.bin", id);
Vec_fwrite_double(fout, ninj_t, nt * L * L);
sprintf(fout, "evo_bibj_id%d_vec.bin", id);
Vec_fwrite_double(fout, bibj_t, nt * L * L);
delete[]ipr_t;
delete[]Fid_t;
delete[]EE_t;
delete[]ni_t;
delete[]ninj_t;
delete[]bibj_t;
for (my_int r = 0; r < L * L; r++)
{
smat_bibj[r].SparseMat_Clear();
}
delete[]ninj_s;
delete[]ni_s;
}
template <>
void Ham_HardCoreBoson<double>::DenseMat_Evo_form_wf0(my_int id, double* wf0)
{
my_int L = LatticeSize;
my_int nt = Params.evo_time_steps;
// compute Fidelity
double* Fid_t = new double[nt];
double* ipr_t = new double[nt];
double* PI_r_t = new double[nt];
double* EE_t = new double[nt];
double* ni_t = new double[nt * L];
double* ni_s = new double[Dim * L];
for (my_int i = 0; i < L; i++) { Cal_H_ni_s(i, &ni_s[i * Dim]); }
double* ninj_t = new double[nt * L * L];
double* ninj_s = new double[Dim * L * L];
for (my_int i = 0; i < L; i++)
for (my_int j = 0; j < L; j++) { Cal_H_ninj_s(i, j, &ninj_s[(i * L + j) * Dim]); }
double* bibj_t = new double[nt * L * L];
SparseMat<double>* smat_bibj = new SparseMat<double>[L * L];
for (my_int i = 0; i < L; i++)
for (my_int j = 0; j < L; j++) { Cal_H_bibj_Smat(i, j, &smat_bibj[i * L + j]); }
for (my_int it = 0; it < nt; it++) {
double t = Params.time_vec[it];
double* wf_r = new double[Dim];
double* wf_i = new double[Dim];
double* wf_sq = new double[Dim];
//DenseMat_Get_psi_t(ind, t, wf_r, wf_i);
DenseMat_Get_psi_t(wf0, t, wf_r, wf_i);
for (my_int s = 0; s < Dim; s++) { wf_sq[s] = wf_r[s] * wf_r[s] + wf_i[s] * wf_i[s]; }
// compute Fidelity, ipr, nnr, bbr
// Fidelity
Fid_t[it] = Fid_t[it] = cblas_ddot(Dim, wf0, 1, wf_sq, 1);
// ipr
ipr_t[it] = Cal_IPR_wfsq(wf_sq);
// ni
for (my_int i = 0; i < L; i++)
{
ni_t[it * L + i] = cblas_ddot(Dim, wf_sq, 1, &ni_s[i * Dim], 1);
}
// EE
my_cmplx ii(0, 1);
my_cmplx* wft = new my_cmplx[Dim];
for (my_int s = 0; s < Dim; s++) { wft[s] = wf_r[s] + ii * wf_i[s]; }
my_int* sites = new my_int[L / 2];
for (my_int i = 0; i < L / 2; i++) { sites[i] = i; }
EE_t[it] = Cal_EE_wf(wft, L / 2, sites);
delete[]wft;
// ninj
for (my_int i = 0; i < L; i++)
{
ninj_t[it * L * L + i * L + i] = ni_t[it * L + i];
for (my_int j = i + 1; j < L; j++)
{
ninj_t[it * L * L + i * L + j] = cblas_ddot(Dim, wf_sq, 1, &ninj_s[(i * L + j) * Dim], 1);
ninj_t[it * L * L + j * L + i] = ninj_t[it * L * L + i * L + j];
}
}
// bibj
for (my_int i = 0; i < L; i++)
{
bibj_t[it * L * L + i * L + i] = ni_t[it * L + i];
for (my_int j = i + 1; j < L; j++)
{
bibj_t[it * L * L + i * L + j] = Cal_Ob_smat(wf_r, wf_i, &smat_bibj[i * L + j]);
bibj_t[it * L * L + j * L + i] = bibj_t[it * L * L + i * L + j];
}
}
delete[]wf_sq;
delete[]wf_r;
delete[]wf_i;
}
char fout[80];
sprintf(fout, "evo_ipr_id%d_span.bin", id);
Vec_fwrite_double(fout, ipr_t, nt);
sprintf(fout, "evo_Fid_id%d_span.bin", id);
Vec_fwrite_double(fout, Fid_t, nt);
sprintf(fout, "evo_EE_id%d_span.bin", id);
Vec_fwrite_double(fout, EE_t, nt);
sprintf(fout, "evo_ni_id%d_span.bin", id);
Vec_fwrite_double(fout, ni_t, nt * L);
sprintf(fout, "evo_ninj_id%d_span.bin", id);
Vec_fwrite_double(fout, ninj_t, nt * L * L);
sprintf(fout, "evo_bibj_id%d_span.bin", id);
Vec_fwrite_double(fout, bibj_t, nt * L * L);
delete[]ipr_t;
delete[]Fid_t;
delete[]EE_t;
delete[]ni_t;
delete[]ninj_t;
delete[]bibj_t;
for (my_int r = 0; r < L * L; r++)
{
smat_bibj[r].SparseMat_Clear();
}
delete[]ninj_s;
delete[]ni_s;
}
template<>
void Ham_HardCoreBoson<double>::DenseMat_Dynamic()
{
my_int L = LatticeSize;
Params.GetTimeVec();
char ft[80];
sprintf(ft, "evo_tvec.bin");
Vec_fwrite_double(ft, Params.time_vec, Params.evo_time_steps);
vector<my_int> ind_vec = Get_IniStates();
my_int n_ini = ind_vec.size();
char fout[80];
sprintf(fout, "evo_iniinfo.dat");
ofstream ofini(fout);
for (my_int ip = 0; ip < n_ini; ip++)
{
ofini << ip << " " << ind_vec[ip] << " " << basis->get_state(ind_vec[ip])
<< " " << H_diag[ind_vec[ip]] << " " << (H_diag[ind_vec[ip]] - spec[0]) / (spec[Dim - 1] - spec[0]) << endl;
}
ofini.close();
// evolution of initial states
//#pragma omp parallel for schedule(dynamic)
cout << "Evolutions: " << endl;
for (my_int ip = 0; ip < n_ini; ip++)
{
my_int ind = ind_vec[ip];
cout << ip << " " << ind_vec[ip] << " " << basis->get_state(ind_vec[ip])
<< " " << H_diag[ind_vec[ip]] << " " << (H_diag[ind_vec[ip]] - spec[0]) / (spec[Dim - 1] - spec[0]) << endl;
DenseMat_Evo_form_s(ip, ind);
// long-time limit average: O(t->infty) -> \sum_a c_a^2 <a|O|a>
// <a|O|a> is computed in DenseMat_Static and printed to file
// here we print c_a^2, and get O(t->infty) by postscripts
double* Csq_p_alpha = new double[Dim]; // <p|alpha>, overlaps of initial and eigen states
Cal_Csq_s_alpha(ind, Csq_p_alpha);
char fname[80];
sprintf(fname, "evo_csq_id%d.bin", ip);
Vec_fwrite_double(fname, Csq_p_alpha, Dim);
delete[]Csq_p_alpha;
}
// evolution of the combined states (spanned by kpz symetry operations)
my_int _k, _p, _z;
_k = 0; _p = 1; _z = 1;
Basis_kpz _basis_kpz(L, basis->get_nup(), _k, _p, _z);
//#pragma omp parallel for schedule(dynamic)
for (my_int ip = 0; ip < n_ini; ip++)
{
my_int ind = ind_vec[ip];
my_int s0 = basis->get_state(ind);
vector<my_int> inds = Get_Spanned_States(s0);
my_int ns = inds.size();
DenseMat_Evo_form_inds(ip, ns, &inds[0]);
}
}