HΦ  3.2.0
CalcByTPQ.c
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 "FirstMultiply.h"
17 #include "Multiply.h"
18 #include "expec_energy_flct.h"
19 #include "expec_cisajs.h"
20 #include "expec_cisajscktaltdc.h"
21 #include "CalcByTPQ.h"
22 #include "FileIO.h"
23 #include "wrapperMPI.h"
24 #include "CalcTime.h"
25 
26 
53  const int NumAve,
54  const int ExpecInterval,
55  struct EDMainCalStruct *X
56 )
57 {
58  char sdt[D_FileNameMax];
59  char sdt_phys[D_FileNameMax];
60  char sdt_norm[D_FileNameMax];
61  char sdt_flct[D_FileNameMax];
62  int rand_i, rand_max, iret;
63  unsigned long int i_max;
64  int step_iO=0;
65  FILE *fp;
66  double inv_temp, Ns;
67  struct TimeKeepStruct tstruct;
68  size_t byte_size;
69 
70  tstruct.tstart=time(NULL);
71 
72  rand_max = NumAve;
73  step_spin = ExpecInterval;
74  X->Bind.Def.St=0;
75  fprintf(stdoutMPI, "%s", cLogTPQ_Start);
76  for (rand_i = 0; rand_i<rand_max; rand_i++){
77  sprintf(sdt_phys, cFileNameSSRand, rand_i);
78  sprintf(sdt_norm, cFileNameNormRand, rand_i);
79  sprintf(sdt_flct, cFileNameFlctRand, rand_i);
80  Ns = 1.0 * X->Bind.Def.NsiteMPI;
81  fprintf(stdoutMPI, cLogTPQRand, rand_i+1, rand_max);
82  iret=0;
83  X->Bind.Def.irand=rand_i;
84 
85  //Make or Read initial vector
86  if(X->Bind.Def.iReStart==RESTART_INOUT || X->Bind.Def.iReStart==RESTART_IN) {
87  StartTimer(3600);
89  fprintf(stdoutMPI, "%s", cLogInputVecStart);
90  sprintf(sdt, cFileNameInputVector, rand_i, myrank);
91  childfopenALL(sdt, "rb", &fp);
92  if(fp==NULL){
93  fprintf(stdout, "A file of Inputvector does not exist.\n");
94  fprintf(stdout, "Start to calculate in normal procedure.\n");
95  iret=1;
96  }
97  byte_size = fread(&step_i, sizeof(step_i), 1, fp);
98  byte_size = fread(&i_max, sizeof(long int), 1, fp);
99  if(i_max != X->Bind.Check.idim_max){
100  fprintf(stderr, "Error: A file of Inputvector is incorrect.\n");
101  exitMPI(-1);
102  }
103  byte_size = fread(v0, sizeof(complex double), X->Bind.Check.idim_max+1, fp);
105  fprintf(stdoutMPI, "%s", cLogInputVecFinish);
106  fclose(fp);
107  StopTimer(3600);
108  X->Bind.Def.istep=step_i;
109  StartTimer(3200);
110  iret=expec_energy_flct(&(X->Bind));
111  StopTimer(3200);
112  if(iret != 0) return -1;
113 
114  step_iO=step_i-1;
115  if (byte_size == 0) printf("byte_size: %d \n", (int)byte_size);
116  }
117 
118  if(X->Bind.Def.iReStart==RESTART_NOT || X->Bind.Def.iReStart==RESTART_OUT || iret ==1) {
119  StartTimer(3600);
120  if (childfopenMPI(sdt_phys, "w", &fp) != 0) {
121  return -1;
122  }
123  fprintf(fp, "%s", cLogSSRand);
124  fclose(fp);
125 // for norm
126  if (childfopenMPI(sdt_norm, "w", &fp) != 0) {
127  return -1;
128  }
129  fprintf(fp, "%s", cLogNormRand);
130  fclose(fp);
131 // for fluctuations
132  if (childfopenMPI(sdt_flct, "w", &fp) != 0) {
133  return -1;
134  }
135  fprintf(fp, "%s", cLogFlctRand);
136  fclose(fp);
137 
138  StopTimer(3600);
139 
140  step_i = 0;
141 
142  StartTimer(3100);
143  if(rand_i==0){
145  }
146  else{
148  }
152  FirstMultiply(rand_i, &(X->Bind));
153  inv_temp = 0.0;
154  StopTimer(3100);
155  if (childfopenMPI(sdt_phys, "a", &fp) != 0) {
156  return -1;
157  }
158  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %d\n", inv_temp, X->Bind.Phys.energy, X->Bind.Phys.var,
159  X->Bind.Phys.doublon, X->Bind.Phys.num, step_i);
160  fclose(fp);
161  // for norm
162  if (childfopenMPI(sdt_norm, "a", &fp) != 0) {
163  return -1;
164  }
165  fprintf(fp, "%.16lf %.16lf %.16lf %d\n", inv_temp, global_1st_norm, global_1st_norm, step_i);
166  fclose(fp);
170  X->Bind.Def.istep = 0;
171  StartTimer(3300);
172  iret=expec_cisajs(&(X->Bind), v1);
173  StopTimer(3300);
174  if(iret !=0) return -1;
175 
176  StartTimer(3400);
177  iret=expec_cisajscktaltdc(&(X->Bind), v1);
178  StopTimer(3400);
179  if(iret !=0) return -1;
180 
184  StartTimer(3200);
185  iret=expec_energy_flct(&(X->Bind)); //v0 = H*v1
186  StopTimer(3200);
187  if(iret !=0) return -1;
188  step_i += 1;
189  inv_temp = (2.0 / Ns) / (LargeValue - X->Bind.Phys.energy / Ns);
190  StartTimer(3600);
191  if (childfopenMPI(sdt_phys, "a", &fp) != 0) {
192  return -1;
193  }
194  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %d\n", inv_temp, X->Bind.Phys.energy, X->Bind.Phys.var,
195  X->Bind.Phys.doublon, X->Bind.Phys.num, step_i);
196  fclose(fp);
197 // for norm
198  if (childfopenMPI(sdt_norm, "a", &fp) != 0) {
199  return -1;
200  }
201  fprintf(fp, "%.16lf %.16lf %.16lf %d\n", inv_temp, global_norm, global_1st_norm, step_i);
202  fclose(fp);
203 // for fluctuations
204  if (childfopenMPI(sdt_flct, "a", &fp) != 0) {
205  return -1;
206  }
207  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %.16lf %.16lf %d\n", inv_temp,X->Bind.Phys.num,X->Bind.Phys.num2, X->Bind.Phys.doublon,X->Bind.Phys.doublon2, X->Bind.Phys.Sz,X->Bind.Phys.Sz2,step_i);
208  fclose(fp);
209 //
210  StopTimer(3600);
211  step_i +=1;
212  X->Bind.Def.istep = step_i;
213  step_iO=0;
214  }
215 
216  for (step_i = X->Bind.Def.istep; step_i<X->Bind.Def.Lanczos_max; step_i++){
217  X->Bind.Def.istep=step_i;
218  if(step_i %((X->Bind.Def.Lanczos_max-step_iO)/10)==0){
220  }
221  X->Bind.Def.istep=step_i;
222  StartTimer(3600);
224  StopTimer(3600);
225  StartTimer(3500);
226  Multiply(&(X->Bind));
227  StopTimer(3500);
228 
229  StartTimer(3200);
230  iret=expec_energy_flct(&(X->Bind));
231  StopTimer(3200);
232  if(iret !=0) return -1;
233 
234 //
235  inv_temp = (2.0*step_i / Ns) / (LargeValue - X->Bind.Phys.energy / Ns);
236 
237  StartTimer(3600);
238  if(childfopenMPI(sdt_phys, "a", &fp)!=0){
239  return FALSE;
240  }
241  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %d\n", inv_temp, X->Bind.Phys.energy, X->Bind.Phys.var, X->Bind.Phys.doublon, X->Bind.Phys.num ,step_i);
242 // for
243  fclose(fp);
244 
245  if(childfopenMPI(sdt_norm, "a", &fp)!=0){
246  return FALSE;
247  }
248  fprintf(fp, "%.16lf %.16lf %.16lf %d\n", inv_temp, global_norm, global_1st_norm, step_i);
249  fclose(fp);
250 
251 // for fluctuations
252  if (childfopenMPI(sdt_flct, "a", &fp) != 0) {
253  return -1;
254  }
255  fprintf(fp, "%.16lf %.16lf %.16lf %.16lf %.16lf %.16lf %.16lf %d\n", inv_temp,X->Bind.Phys.num,X->Bind.Phys.num2, X->Bind.Phys.doublon,X->Bind.Phys.doublon2, X->Bind.Phys.Sz,X->Bind.Phys.Sz2,step_i);
256  fclose(fp);
257 //
258  StopTimer(3600);
259 
260 
261  if (step_i%step_spin == 0){
262  StartTimer(3300);
263  iret=expec_cisajs(&(X->Bind),v1);
264  StopTimer(3300);
265  if(iret !=0) return -1;
266 
267  StartTimer(3400);
268  iret=expec_cisajscktaltdc(&(X->Bind), v1);
269  StopTimer(3400);
270  if(iret !=0) return -1;
271  }
272  }
273 
274  if(X->Bind.Def.iReStart== RESTART_OUT || X->Bind.Def.iReStart==RESTART_INOUT){
276  fprintf(stdoutMPI, "%s", cLogOutputVecStart);
277  sprintf(sdt, cFileNameOutputVector, rand_i, myrank);
278  if(childfopenALL(sdt, "wb", &fp)!=0){
279  exitMPI(-1);
280  }
281  fwrite(&step_i, sizeof(step_i), 1, fp);
282  fwrite(&X->Bind.Check.idim_max, sizeof(X->Bind.Check.idim_max),1,fp);
283  fwrite(v1, sizeof(complex double),X->Bind.Check.idim_max+1, fp);
284  fclose(fp);
286  fprintf(stdoutMPI, "%s", cLogOutputVecFinish);
287  }
288  }
289  fprintf(stdoutMPI, "%s", cLogTPQ_End);
290 
291  tstruct.tend=time(NULL);
292  fprintf(stdoutMPI, cLogTPQEnd, (int)(tstruct.tend-tstruct.tstart));
293  return TRUE;
294 }
int step_spin
Definition: global.h:69
int childfopenALL(const char *_cPathChild, const char *_cmode, FILE **_fp)
All processes open file in output/ directory.
Definition: FileIO.c:50
int irand
Input keyword TargetTPQRand ???
Definition: struct.h:79
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.c:86
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
int expec_cisajscktaltdc(struct BindStruct *X, double complex *vec)
Parent function to calculate two-body green&#39;s functions.
int St
0 or 1, but it affects nothing.
Definition: struct.h:80
void StartTimer(int n)
function for initializing elapse time [start]
Definition: time.c:71
Time keeping.
Definition: struct.h:425
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
int iReStart
Definition: struct.h:221
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.c:83
double complex * v1
Definition: global.h:35
const char * cTPQStep
Definition: LogMessage.c:79
int NumAve
Definition: global.h:65
#define D_FileNameMax
Definition: global.h:23
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.c:27
const char * cLogInputVecFinish
Definition: LogMessage.c:150
struct PhysList Phys
Physical quantities.
Definition: struct.h:413
int Multiply(struct BindStruct *X)
Function of calculating the i-th step norm as and update the i+1-th wave vector as for TPQ calculat...
Definition: Multiply.c:43
int FirstMultiply(int rand_i, struct BindStruct *X)
Multiplication at the first step for TPQ mode ( is the random or inputted vector).
Definition: FirstMultiply.c:40
double Sz2
Expectation value of the Square of total Sz.
Definition: struct.h:361
#define TRUE
Definition: global.h:26
double global_norm
Definition: global.h:67
Bind.
Definition: struct.h:419
const char * cLogInputVecStart
Definition: LogMessage.c:149
double num
Expectation value of the Number of electrons.
Definition: struct.h:358
const char * cFileNameNormRand
Definition: global.c:58
const char * cLogSSRand
Definition: LogMessage.c:143
int CalcByTPQ(const int NumAve, const int ExpecInterval, struct EDMainCalStruct *X)
A main function to calculate physical quqntities by TPQ method.
Definition: CalcByTPQ.c:52
const char * cLogNormRand
Definition: LogMessage.c:144
int expec_cisajs(struct BindStruct *X, double complex *vec)
function of calculation for one body green&#39;s function
Definition: expec_cisajs.c:69
const char * cOutputVecStart
Definition: LogMessage.c:153
const char * cLogTPQ_Start
const char * cFileNameInputVector
Definition: global.c:65
unsigned int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.h:57
const char * cLogOutputVecStart
Definition: LogMessage.c:151
double var
Expectation value of the Energy variance.
Definition: struct.h:363
time_t tend
End time.
Definition: struct.h:428
#define FALSE
Definition: global.h:25
const char * cFileNameFlctRand
Definition: global.c:59
const char * cLogFlctRand
Definition: LogMessage.c:145
const char * cOutputVecFinish
Definition: LogMessage.c:154
int istep
Index of TPQ step ???
Definition: struct.h:78
const char * cFileNameTPQStep
Definition: global.c:57
time_t tstart
Start time.
Definition: struct.h:426
const char * cLogTPQ_End
const char * cLogOutputVecFinish
Definition: LogMessage.c:152
struct EDMainCalStruct X
Definition: struct.h:432
const char * cLogTPQEnd
Definition: LogMessage.c:147
double doublon
Expectation value of the Doublon.
Definition: struct.h:356
const char * cLogTPQRand
Definition: LogMessage.c:142
double Sz
Expectation value of the Total Sz.
Definition: struct.h:360
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:163
int expec_energy_flct(struct BindStruct *X)
Parent function to calculate expected values of energy and physical quantities.
const char * cLogTPQStep
Definition: LogMessage.c:146
const char * cFileNameSSRand
Definition: global.c:56
const char * cFileNameOutputVector
Definition: global.c:64
double energy
Expectation value of the total energy.
Definition: struct.h:355
double global_1st_norm
Definition: global.h:68
double complex * v0
Definition: global.h:34
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
double num2
Expectation value of the quare of the number of electrons.
Definition: struct.h:359
int step_i
Definition: global.h:66
double LargeValue
Definition: global.h:64
struct BindStruct Bind
Binded struct.
Definition: struct.h:420
double doublon2
Expectation value of the Square of doublon.
Definition: struct.h:357
int TimeKeeperWithRandAndStep(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType, const int irand, const int istep)
Functions for writing a time log.
Definition: log.c:117
unsigned int Lanczos_max
Maximum number of iterations.
Definition: struct.h:74
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165