HPhi++  3.1.0
CalcByTEM.cpp
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 #include "Common.hpp"
17 #include "readdef.hpp"
18 #include "FirstMultiply.hpp"
19 #include "Multiply.hpp"
20 #include "diagonalcalc.hpp"
21 #include "expec_energy_flct.hpp"
22 #include "expec_cisajs.hpp"
23 #include "expec_cisajscktaltdc.hpp"
24 #include "CalcByTEM.hpp"
25 #include "FileIO.hpp"
26 #include "wrapperMPI.hpp"
27 #include "HPhiTrans.hpp"
28 #include "common/setmemory.hpp"
29 #include <iostream>
33 void MakeTEDTransfer(struct BindStruct *X, const int timeidx) {
37  int i, j;
38  //Clear values
39  for (i = 0; i < X->Def.NTETransferMax; i++) {
40  for (j = 0; j < 4; j++) {
41  X->Def.EDGeneralTransfer[i + X->Def.EDNTransfer][j] = 0;
42  }
43  X->Def.EDParaGeneralTransfer[i + X->Def.EDNTransfer] = 0.0;
44  }
45 
46  //Input values
47  for (i = 0; i < X->Def.NTETransfer[timeidx]; i++) {
48  for (j = 0; j < 4; j++) {
49  X->Def.EDGeneralTransfer[i + X->Def.EDNTransfer][j] = X->Def.TETransfer[timeidx][i][j];
50  }
51  X->Def.EDParaGeneralTransfer[i + X->Def.EDNTransfer] = X->Def.ParaTETransfer[timeidx][i];
52  }
53  X->Def.EDNTransfer += X->Def.NTETransfer[timeidx];
54 }
58 void MakeTEDInterAll(struct BindStruct *X, const int timeidx) {
59  int i, j;
60  //Clear values
61  for (i = 0; i < X->Def.NTEInterAllMax; i++) {
62  for (j = 0; j < 8; j++) {
64  }
66  }
67  //Input values
68  for (i = 0; i < X->Def.NTEInterAllOffDiagonal[timeidx]; i++) {
69  for (j = 0; j < 8; j++) {
71  }
73  }
75 }
88  const int ExpecInterval,
89  struct EDMainCalStruct *X
90 ) {
91  size_t byte_size;
92  char *defname;
93  char sdt[D_FileNameMax];
94  char sdt_phys[D_FileNameMax];
95  char sdt_norm[D_FileNameMax];
96  char sdt_flct[D_FileNameMax];
97  int rand_i = 0;
98  int step_initial = 0;
99  long int i_max = 0;
100  FILE *fp;
101  double Time = X->Bind.Def.Param.Tinit;
102  double dt = ((X->Bind.Def.NLaser == 0) ? 0.0 : X->Bind.Def.Param.TimeSlice);
103  std::complex<double> **v2;
105  global_norm = d_1d_allocate(1);
106 
107  if (X->Bind.Def.NTETimeSteps < X->Bind.Def.Lanczos_max) {
108  fprintf(stdoutMPI, "Error: NTETimeSteps must be larger than Lanczos_max.\n");
109  return -1;
110  }
111  step_spin = ExpecInterval;
112  X->Bind.Def.St = 0;
113  fprintf(stdoutMPI, "%s", "###### Start: TimeEvolution by Taylor Expansion. ######\n\n");
114  if (X->Bind.Def.iInputEigenVec == FALSE) {
115  fprintf(stderr, "Error: A file of Inputvector is not inputted.\n");
116  return -1;
117  }
118  else {
119  //input v1
120  fprintf(stdoutMPI, "%s", "An Initial Vector is inputted.\n");
121  TimeKeeper(&(X->Bind), "%s_TimeKeeper.dat", "Reading an input Eigenvector starts: %s", "a");
122  GetFileNameByKW(KWSpectrumVec, &defname);
123  strcat(defname, "_rank_%d.dat");
124  sprintf(sdt, defname, myrank);
125  childfopenALL(sdt, "rb", &fp);
126  if (fp == NULL) {
127  fprintf(stderr, "Error: A file of Inputvector does not exist.\n");
128  fclose(fp);
129  exitMPI(-1);
130  }
131  byte_size = fread(&step_initial, sizeof(int), 1, fp);
132  byte_size = fread(&i_max, sizeof(long int), 1, fp);
133  if (i_max != X->Bind.Check.idim_max) {
134  fprintf(stderr, "Error: A file of Inputvector is incorrect.\n");
135  fclose(fp);
136  printf("byte_size : %d\n", (int)byte_size);
137  exitMPI(-1);
138  }
139  byte_size = fread(&v1[0][0], sizeof(std::complex<double>), X->Bind.Check.idim_max + 1, fp);
140  fclose(fp);
141  if (X->Bind.Def.iReStart == RESTART_NOT || X->Bind.Def.iReStart == RESTART_OUT) {
142  step_initial = 0;
143  }
144  }
145 
146  sprintf(sdt_phys, "%s", "SS.dat");
147  if (childfopenMPI(sdt_phys, "w", &fp) != 0) {
148  return -1;
149  }
150  fprintf(fp, "%s", " # time, energy, phys_var, phys_doublon, phys_num, step_i\n");
151  fclose(fp);
152 
153  sprintf(sdt_norm, "%s", "Norm.dat");
154  if (childfopenMPI(sdt_norm, "w", &fp) != 0) {
155  return -1;
156  }
157  fprintf(fp, "%s", " # time, norm, step_i \n");
158  fclose(fp);
159 
160  sprintf(sdt_flct, "%s", "Flct.dat");
161  if (childfopenMPI(sdt_flct, "w", &fp) != 0) {
162  return -1;
163  }
164  fprintf(fp, "%s", " # time, N, N^2, D, D^2, Sz, Sz^2, step_i \n");
165  fclose(fp);
166 
167 
168  int iInterAllOffDiagonal_org = X->Bind.Def.NInterAll_OffDiagonal;
169  int iTransfer_org = X->Bind.Def.EDNTransfer;
170  v2 = cd_2d_allocate(X->Bind.Check.idim_max + 1, 1);
171  for (step_i = step_initial; step_i < X->Bind.Def.Lanczos_max; step_i++) {
172  X->Bind.Def.istep = step_i;
173 
174  //Reset total number of interactions (changed in MakeTED***function.)
175  X->Bind.Def.EDNTransfer = iTransfer_org;
176  X->Bind.Def.NInterAll_OffDiagonal = iInterAllOffDiagonal_org;
177 
178  if (step_i % (X->Bind.Def.Lanczos_max / 10) == 0) {
179  fprintf(stdoutMPI, " step_i/total_step = %d/%d \n", step_i, X->Bind.Def.Lanczos_max);
180  }
181 
182  if (X->Bind.Def.NLaser != 0) {
183  TransferWithPeierls(&(X->Bind), Time);
184  }
185  else {
186  // common procedure
187  Time = X->Bind.Def.TETime[step_i];
188  if (step_i == 0) dt = 0.0;
189  else {
190  dt = X->Bind.Def.TETime[step_i] - X->Bind.Def.TETime[step_i - 1];
191  }
192  X->Bind.Def.Param.TimeSlice = dt;
193 
194  // Set interactions
195  if (X->Bind.Def.NTETransferMax != 0 && X->Bind.Def.NTEInterAllMax != 0) {
196  fprintf(stdoutMPI,
197  "Error: Time Evoluation mode does not support TEOneBody and TETwoBody interactions at the same time. \n");
198  return -1;
199  }
200  else if (X->Bind.Def.NTETransferMax > 0) { //One-Body type
201  MakeTEDTransfer(&(X->Bind), step_i);
202  }
203  else if (X->Bind.Def.NTEInterAllMax > 0) { //Two-Body type
204  MakeTEDInterAll(&(X->Bind), step_i);
205  }
206  //[e] Yoshimi
207  }
208 
209  if (step_i == step_initial) {
210  TimeKeeperWithStep(&(X->Bind), "%s_Time_TE_Step.dat", "step %d:TE begins: %s", "w", step_i);
211  }
212  else {
213  TimeKeeperWithStep(&(X->Bind), "%s_Time_TE_Step.dat", "step %d:TE begins: %s", "a", step_i);
214  }
215  MultiplyForTEM(&(X->Bind), v2);
216  //Add Diagonal Parts
217  //Multiply Diagonal
218  expec_energy_flct(&(X->Bind), 1, v0, v1);
219 
220  if (X->Bind.Def.NLaser > 0) Time += dt;
221  if (childfopenMPI(sdt_phys, "a", &fp) != 0) {
222  return -1;
223  }
224  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %d\n",
225  Time, X->Bind.Phys.energy[0], X->Bind.Phys.var[0],
226  X->Bind.Phys.doublon[0], X->Bind.Phys.num[0], step_i);
227  fclose(fp);
228 
229  if (childfopenMPI(sdt_norm, "a", &fp) != 0) {
230  return -1;
231  }
232  fprintf(fp, "%.16lf %.16lf %d\n", Time, global_norm[0], step_i);
233  fclose(fp);
234 
235  if (childfopenMPI(sdt_flct, "a", &fp) != 0) {
236  return -1;
237  }
238  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %.16lf %.16lf %d\n",
239  Time, X->Bind.Phys.num[0], X->Bind.Phys.num2[0], X->Bind.Phys.doublon[0],
240  X->Bind.Phys.doublon2[0], X->Bind.Phys.Sz[0], X->Bind.Phys.Sz2[0], step_i);
241  fclose(fp);
242 
243  if (step_i % step_spin == 0) {
244  expec_cisajs(&(X->Bind), 1, v2, v1);
245  expec_cisajscktaltdc(&(X->Bind), 1, v2, v1);
246  }
247  if (X->Bind.Def.iOutputEigenVec == TRUE) {
248  if (step_i % X->Bind.Def.Param.OutputInterval == 0) {
249  sprintf(sdt, "%s_eigenvec_%d_rank_%d.dat", X->Bind.Def.CDataFileHead, step_i, myrank);
250  if (childfopenALL(sdt, "wb", &fp) != 0) {
251  fclose(fp);
252  exitMPI(-1);
253  }
254  fwrite(&step_i, sizeof(step_i), 1, fp);
255  fwrite(&X->Bind.Check.idim_max, sizeof(long int), 1, fp);
256  fwrite(&v1[0][0], sizeof(std::complex<double>), X->Bind.Check.idim_max + 1, fp);
257  fclose(fp);
258  }
259  }
260  }/*for (step_i = step_initial; step_i < X->Bind.Def.Lanczos_max; step_i++)*/
261  free_cd_2d_allocate(v2);
262 
263  if (X->Bind.Def.iOutputEigenVec == TRUE) {
264  sprintf(sdt, "%s_eigenvec_%d_rank_%d.dat", X->Bind.Def.CDataFileHead, rand_i, myrank);
265  if (childfopenALL(sdt, "wb", &fp) != 0) {
266  fclose(fp);
267  exitMPI(-1);
268  }
269  fwrite(&step_i, sizeof(step_i), 1, fp);
270  fwrite(&X->Bind.Check.idim_max, sizeof(long int), 1, fp);
271  fwrite(&v1[0][0], sizeof(std::complex<double>), X->Bind.Check.idim_max + 1, fp);
272  fclose(fp);
273  }
274 
275  fprintf(stdoutMPI, "%s", "###### End : TimeEvolution by Taylor Expansion. ######\n\n");
276  return 0;
277 }
double * doublon
Expectation value of the Doublon.
Definition: struct.hpp:357
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.cpp:86
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
std::complex< double > * EDParaGeneralTransfer
Value of general transfer integrals by a def file. malloc in setmem_def(). Data Format [DefineList::N...
Definition: struct.hpp:116
double * var
Expectation value of the Energy variance.
Definition: struct.hpp:367
int St
0 or 1, but it affects nothing.
Definition: struct.hpp:80
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
std::complex< double > ** ParaTETransfer
Definition: struct.hpp:266
int expec_cisajscktaltdc(struct BindStruct *X, int nstate, std::complex< double > **Xvec, std::complex< double > **vec)
Parent function to calculate two-body green&#39;s functions.
int childfopenALL(const char *_cPathChild, const char *_cmode, FILE **_fp)
All processes open file in output/ directory.
Definition: FileIO.cpp:50
int expec_energy_flct(struct BindStruct *X, int nstate, std::complex< double > **tmp_v0, std::complex< double > **tmp_v1)
Parent function to calculate expected values of energy and physical quantities.
int iReStart
Definition: struct.hpp:223
int GetFileNameByKW(int iKWidx, char **FileName)
function of getting file name labeled by the keyword
Definition: readdef.cpp:2853
std::complex< double > ** v0
Definition: global.cpp:20
int TimeKeeperWithStep(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType, const int istep)
Functions for writing a time log.
Definition: log.cpp:78
int iOutputEigenVec
ASwitch for outputting an eigenvector. 0: no output, 1:output.
Definition: struct.hpp:204
double * TETime
Definition: struct.hpp:249
int CalcByTEM(const int ExpecInterval, struct EDMainCalStruct *X)
main function of time evolution calculation
Definition: CalcByTEM.cpp:87
int step_spin
Definition: global.cpp:47
double * num2
Expectation value of the quare of the number of electrons.
Definition: struct.hpp:360
int ** EDGeneralTransfer
Index of transfer integrals for calculation. malloc in setmem_def(). Data Format [DefineList::NTransf...
Definition: struct.hpp:110
struct PhysList Phys
Physical quantities.
Definition: struct.hpp:398
double * Sz2
Expectation value of the Square of total Sz.
Definition: struct.hpp:362
std::complex< double > ** v1
Definition: global.cpp:21
double * Sz
Expectation value of the Total Sz.
Definition: struct.hpp:361
int ** InterAll_OffDiagonal
[DefineList::NinterAll_OffDiagonal][8] Interacted quartet
Definition: struct.hpp:161
void MakeTEDInterAll(struct BindStruct *X, const int timeidx)
Set interall interactions at timeidx-th time.
Definition: CalcByTEM.cpp:58
int MultiplyForTEM(struct BindStruct *X, std::complex< double > **v2)
Function of multiplying Hamiltonian for Time Evolution.
Definition: Multiply.cpp:80
int * NTEInterAllOffDiagonal
Definition: struct.hpp:275
int EDNTransfer
Number of transfer integrals for calculation.
Definition: struct.hpp:105
void MakeTEDTransfer(struct BindStruct *X, const int timeidx)
Set transfer integrals at timeidx-th time.
Definition: CalcByTEM.cpp:36
double * num
Expectation value of the Number of electrons.
Definition: struct.hpp:359
Bind.
Definition: struct.hpp:394
int NLaser
Definition: struct.hpp:252
double TimeSlice
Definition: struct.hpp:33
int * NTETransfer
Definition: struct.hpp:258
int Lanczos_max
Maximum number of iterations.
Definition: struct.hpp:74
double * energy
Expectation value of the total energy.
Definition: struct.hpp:356
double * global_norm
Definition: global.cpp:45
int myrank
Process ID, defined in InitializeMPI()
Definition: global.cpp:73
int expec_cisajs(struct BindStruct *X, int nstate, std::complex< double > **Xvec, std::complex< double > **vec)
function of calculation for one body green&#39;s function
int step_i
Definition: global.cpp:44
int *** TETransfer
Definition: struct.hpp:262
struct ParamList Param
Definition: struct.hpp:243
std::complex< double > * ParaInterAll_OffDiagonal
[DefineList::NInterAll_OffDiagonal] Coupling constant of off-diagonal inter-all term. malloc in setmem_def().
Definition: struct.hpp:170
int NTETransferMax
Definition: struct.hpp:257
int NInterAll_OffDiagonal
Number of interall term (off-diagonal)
Definition: struct.hpp:165
int TransferWithPeierls(struct BindStruct *X, const double time)
Function of getting transfer with peierls.
Definition: HPhiTrans.cpp:93
int istep
Index of TPQ step ???
Definition: struct.hpp:78
double * doublon2
Expectation value of the Square of doublon.
Definition: struct.hpp:358
double Tinit
Definition: struct.hpp:32
int OutputInterval
Definition: struct.hpp:34
int NTETimeSteps
Definition: struct.hpp:248
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
Definition: log.cpp:42
int *** TEInterAllOffDiagonal
Definition: struct.hpp:283
int iInputEigenVec
Switch for reading an eigenvector. 0: no input, 1:input.
Definition: struct.hpp:205
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.hpp:42
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305
struct BindStruct Bind
Binded struct.
Definition: struct.hpp:405
int NTEInterAllMax
Definition: struct.hpp:272
std::complex< double > ** ParaTEInterAllOffDiagonal
Definition: struct.hpp:290
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27