HPhi++  3.1.0
CalcByTEM.cpp File Reference

File to define functions to calculate expected values by Time evolution method. More...

#include "Common.hpp"
#include "readdef.hpp"
#include "FirstMultiply.hpp"
#include "Multiply.hpp"
#include "diagonalcalc.hpp"
#include "expec_energy_flct.hpp"
#include "expec_cisajs.hpp"
#include "expec_cisajscktaltdc.hpp"
#include "CalcByTEM.hpp"
#include "FileIO.hpp"
#include "wrapperMPI.hpp"
#include "HPhiTrans.hpp"
#include "common/setmemory.hpp"
#include <iostream>

Go to the source code of this file.

Functions

void MakeTEDTransfer (struct BindStruct *X, const int timeidx)
 Set transfer integrals at timeidx-th time. More...
 
void MakeTEDInterAll (struct BindStruct *X, const int timeidx)
 Set interall interactions at timeidx-th time. More...
 
int CalcByTEM (const int ExpecInterval, struct EDMainCalStruct *X)
 main function of time evolution calculation More...
 

Detailed Description

File to define functions to calculate expected values by Time evolution method.

Definition in file CalcByTEM.cpp.

Function Documentation

◆ CalcByTEM()

int CalcByTEM ( const int  ExpecInterval,
struct EDMainCalStruct X 
)

main function of time evolution calculation

Parameters
ExpecIntervalinterval to output expected values
Xstruct to get information of calculations.
Returns
0 normally finished
-1 unnormally finished
Author
Kota Ido (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

< Ttemporary vector for time evolution calculation, \( v2 = H*v1 = H^coef |psi(t)>\).

Definition at line 87 of file CalcByTEM.cpp.

References EDMainCalStruct::Bind, DefineList::CDataFileHead, BindStruct::Check, childfopenALL(), childfopenMPI(), BindStruct::Def, PhysList::doublon, PhysList::doublon2, DefineList::EDNTransfer, PhysList::energy, exitMPI(), expec_cisajs(), expec_cisajscktaltdc(), expec_energy_flct(), GetFileNameByKW(), global_norm, CheckList::idim_max, DefineList::iInputEigenVec, DefineList::iOutputEigenVec, DefineList::iReStart, DefineList::istep, DefineList::Lanczos_max, MakeTEDInterAll(), MakeTEDTransfer(), MultiplyForTEM(), myrank, DefineList::NInterAll_OffDiagonal, DefineList::NLaser, DefineList::NTEInterAllMax, DefineList::NTETimeSteps, DefineList::NTETransferMax, PhysList::num, PhysList::num2, ParamList::OutputInterval, DefineList::Param, BindStruct::Phys, DefineList::St, stdoutMPI, step_i, step_spin, PhysList::Sz, PhysList::Sz2, DefineList::TETime, TimeKeeper(), TimeKeeperWithStep(), ParamList::TimeSlice, ParamList::Tinit, TransferWithPeierls(), v0, v1, and PhysList::var.

Referenced by main().

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
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
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 step_spin
Definition: global.cpp:47
double * num2
Expectation value of the quare of the number of electrons.
Definition: struct.hpp:360
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
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 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
int NLaser
Definition: struct.hpp:252
double TimeSlice
Definition: struct.hpp:33
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
struct ParamList Param
Definition: struct.hpp:243
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 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
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27

◆ MakeTEDInterAll()

void MakeTEDInterAll ( struct BindStruct X,
const int  timeidx 
)

Set interall interactions at timeidx-th time.

Parameters
Xstruct for getting information of interall interactions
timeidxindex of time

Definition at line 58 of file CalcByTEM.cpp.

References BindStruct::Def, DefineList::InterAll_OffDiagonal, DefineList::NInterAll_OffDiagonal, DefineList::NTEInterAllMax, DefineList::NTEInterAllOffDiagonal, DefineList::ParaInterAll_OffDiagonal, DefineList::ParaTEInterAllOffDiagonal, and DefineList::TEInterAllOffDiagonal.

Referenced by CalcByTEM().

58  {
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 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int ** InterAll_OffDiagonal
[DefineList::NinterAll_OffDiagonal][8] Interacted quartet
Definition: struct.hpp:161
int * NTEInterAllOffDiagonal
Definition: struct.hpp:275
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 NInterAll_OffDiagonal
Number of interall term (off-diagonal)
Definition: struct.hpp:165
int *** TEInterAllOffDiagonal
Definition: struct.hpp:283
int NTEInterAllMax
Definition: struct.hpp:272
std::complex< double > ** ParaTEInterAllOffDiagonal
Definition: struct.hpp:290

◆ MakeTEDTransfer()

void MakeTEDTransfer ( struct BindStruct X,
const int  timeidx 
)

Set transfer integrals at timeidx-th time.

Parameters
Xstruct for getting information of transfer integrals
timeidxindex of time

Definition at line 36 of file CalcByTEM.cpp.

Referenced by CalcByTEM().

36  {
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 }
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
std::complex< double > ** ParaTETransfer
Definition: struct.hpp:266
int ** EDGeneralTransfer
Index of transfer integrals for calculation. malloc in setmem_def(). Data Format [DefineList::NTransf...
Definition: struct.hpp:110
int EDNTransfer
Number of transfer integrals for calculation.
Definition: struct.hpp:105
int * NTETransfer
Definition: struct.hpp:258
int *** TETransfer
Definition: struct.hpp:262
int NTETransferMax
Definition: struct.hpp:257