HΦ  3.2.0
CalcByLanczos.c File Reference

File for givinvg functions of calculating eigenvalues and eigenvectors by Lanczos method. More...

#include "expec_cisajs.h"
#include "expec_cisajscktaltdc.h"
#include "expec_totalspin.h"
#include "CG_EigenVector.h"
#include "expec_energy_flct.h"
#include "Lanczos_EigenValue.h"
#include "Lanczos_EigenVector.h"
#include "CalcByLanczos.h"
#include "FileIO.h"
#include "wrapperMPI.h"
#include "CalcTime.h"
+ Include dependency graph for CalcByLanczos.c:

Go to the source code of this file.

Functions

int CalcByLanczos (struct EDMainCalStruct *X)
 A main function to calculate eigenvalues and eigenvectors by Lanczos method. More...
 

Detailed Description

File for givinvg functions of calculating eigenvalues and eigenvectors by Lanczos method.

Version
0.1, 0.2
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition in file CalcByLanczos.c.

Function Documentation

◆ CalcByLanczos()

int CalcByLanczos ( struct EDMainCalStruct X)

A main function to calculate eigenvalues and eigenvectors by Lanczos method.

Parameters
[in,out]XCalcStruct list for getting and pushing calculation information
Return values
0normally finished
-1unnormally finished
Version
0.2
Date
2015/10/20 add function of using a flag of iCalcEigenVec
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition at line 54 of file CalcByLanczos.c.

References EDMainCalStruct::Bind, DefineList::CDataFileHead, cFileNameEnergy_CG, cFileNameEnergy_Lanczos, cFileNameInputEigen, cFileNameOutputEigen, cFileNameTimeKeep, CG_EigenVector(), BindStruct::Check, childfopenALL(), childfopenMPI(), cLogLanczos_EigenVecEnd, cLogLanczos_EigenVecStart, cOutputEigenVecFinish, cOutputEigenVecStart, cReadEigenVecFinish, cReadEigenVecStart, D_FileNameMax, BindStruct::Def, PhysList::doublon, PhysList::energy, eps_Energy, exitMPI(), expec_cisajs(), expec_cisajscktaltdc(), expec_energy_flct(), expec_totalSz(), FALSE, DefineList::iCalcEigenVec, DefineList::iCalcModel, CheckList::idim_max, CheckList::idim_maxMPI, DefineList::iFlgGeneralSpin, DefineList::iInputEigenVec, DefineList::initial_iv, initial_mode, DefineList::iOutputEigenVec, LargeList::itr, DefineList::k_exct, Lanczos_EigenValue(), Lanczos_EigenVector(), BindStruct::Large, myrank, BindStruct::Phys, DefineList::St, StartTimer(), stdoutMPI, step_i, StopTimer(), PhysList::Sz, PhysList::Target_CG_energy, PhysList::Target_energy, TimeKeeper(), TRUE, v0, v1, and PhysList::var.

Referenced by main().

57 {
58  char sdt[D_FileNameMax];
59  double diff_ene,var;
60  long int i_max=0;
61  FILE *fp;
62  size_t byte_size;
63 
64  if(X->Bind.Def.iInputEigenVec==FALSE){
65  // this part will be modified
66  switch(X->Bind.Def.iCalcModel){
67  case HubbardGC:
68  case SpinGC:
69  case KondoGC:
70  case SpinlessFermionGC:
71  initial_mode = 1; // 1 -> random initial vector
72  break;
73  case Hubbard:
74  case Kondo:
75  case Spin:
76  case SpinlessFermion:
77 
78  if(X->Bind.Def.iFlgGeneralSpin ==TRUE){
79  initial_mode=1;
80  }
81  else{
82  if(X->Bind.Def.initial_iv>0){
83  initial_mode = 0; // 0 -> only v[iv] = 1
84  }else{
85  initial_mode = 1; // 1 -> random initial vector
86  }
87  }
88  break;
89  default:
90  exitMPI(-1);
91  }
92 
93  StartTimer(4100);
94  int iret=0;
95  iret=Lanczos_EigenValue(&(X->Bind));
96  StopTimer(4100);
97  if(iret == 1) return(TRUE);//restart mode.
98  else if(iret != 0) return(FALSE);
99 
100  if(X->Bind.Def.iCalcEigenVec==CALCVEC_NOT){
101  fprintf(stdoutMPI, " Lanczos EigenValue = %.10lf \n ",X->Bind.Phys.Target_energy);
102  return(TRUE);
103  }
104 
105  fprintf(stdoutMPI, "%s", cLogLanczos_EigenVecStart);
106 
107  if(X->Bind.Check.idim_maxMPI != 1){
108  StartTimer(4200);
109  Lanczos_EigenVector(&(X->Bind));
110  StopTimer(4200);
111 
112  StartTimer(4300);
113  iret=expec_energy_flct(&(X->Bind));
114  StopTimer(4300);
115  if(iret != 0) return(FALSE);
116 
117  //check for the accuracy of the eigenvector
118  var = fabs(X->Bind.Phys.var-X->Bind.Phys.energy*X->Bind.Phys.energy)/fabs(X->Bind.Phys.var);
119  diff_ene = fabs(X->Bind.Phys.Target_CG_energy-X->Bind.Phys.energy)/fabs(X->Bind.Phys.Target_CG_energy);
120 
121  fprintf(stdoutMPI, "\n");
122  fprintf(stdoutMPI, " Accuracy check !!!\n");
123  fprintf(stdoutMPI, " LanczosEnergy = %.14e \n EnergyByVec = %.14e \n diff_ene = %.14e \n var = %.14e \n",X->Bind.Phys.Target_CG_energy,X->Bind.Phys.energy,diff_ene,var);
124  if(diff_ene < eps_Energy && var< eps_Energy){
125  fprintf(stdoutMPI, " Accuracy of Lanczos vectors is enough.\n");
126  fprintf(stdoutMPI, "\n");
127  }
128  else if(X->Bind.Def.iCalcEigenVec==CALCVEC_LANCZOSCG){
129  fprintf(stdoutMPI, " Accuracy of Lanczos vectors is NOT enough\n\n");
130  X->Bind.Def.St=1;
131  StartTimer(4400);
132  iret=CG_EigenVector(&(X->Bind));
133  StopTimer(4400);
134  if(iret != 0) return(FALSE);
135 
136  StartTimer(4300);
137  iret=expec_energy_flct(&(X->Bind));
138  StopTimer(4300);
139  if(iret != 0) return(FALSE);
140 
141  var = fabs(X->Bind.Phys.var-X->Bind.Phys.energy*X->Bind.Phys.energy)/fabs(X->Bind.Phys.var);
142  diff_ene = fabs(X->Bind.Phys.Target_CG_energy-X->Bind.Phys.energy)/fabs(X->Bind.Phys.Target_CG_energy);
143  fprintf(stdoutMPI, "\n");
144  fprintf(stdoutMPI, " CG Accuracy check !!!\n");
145  fprintf(stdoutMPI, " LanczosEnergy = %.14e\n EnergyByVec = %.14e\n diff_ene = %.14e\n var = %.14e \n ",X->Bind.Phys.Target_CG_energy,X->Bind.Phys.energy,diff_ene,var);
146  fprintf(stdoutMPI, "\n");
147  //}
148  }
149  }
150  else{//idim_max=1
151  v0[1]=1;
152  StartTimer(4300);
153  iret=expec_energy_flct(&(X->Bind));
154  StopTimer(4300);
155  if(iret != 0) return(FALSE);
156  }
157  }
158  else{// X->Bind.Def.iInputEigenVec=true :input v1:
159  fprintf(stdoutMPI, "An Eigenvector is inputted.\n");
160  StartTimer(4800);
162  StartTimer(4801);
163  sprintf(sdt, cFileNameInputEigen, X->Bind.Def.CDataFileHead, X->Bind.Def.k_exct-1, myrank);
164  childfopenALL(sdt, "rb", &fp);
165  if(fp==NULL){
166  fprintf(stderr, "Error: A file of Inputvector does not exist.\n");
167  exitMPI(-1);
168  }
169  byte_size = fread(&step_i, sizeof(int), 1, fp);
170  byte_size = fread(&i_max, sizeof(long int), 1, fp);
171  if(i_max != X->Bind.Check.idim_max){
172  fprintf(stderr, "Error: A file of Inputvector is incorrect.\n");
173  exitMPI(-1);
174  }
175  byte_size = fread(v1, sizeof(complex double),X->Bind.Check.idim_max+1, fp);
176  fclose(fp);
177  StopTimer(4801);
178  StopTimer(4800);
180  if (byte_size == 0) printf("byte_size: %d \n", (int)byte_size);
181  }
182 
183  fprintf(stdoutMPI, "%s", cLogLanczos_EigenVecEnd);
184  // v1 is eigen vector
185 
186  StartTimer(4500);
187  if(expec_cisajs(&(X->Bind), v1)!=0){
188  fprintf(stderr, "Error: calc OneBodyG.\n");
189  exitMPI(-1);
190  }
191  StopTimer(4500);
192  StartTimer(4600);
193  if(expec_cisajscktaltdc(&(X->Bind), v1)!=0){
194  fprintf(stderr, "Error: calc TwoBodyG.\n");
195  exitMPI(-1);
196  }
197  StopTimer(4600);
198 
199  if(expec_totalSz(&(X->Bind), v1)!=0){
200  fprintf(stderr, "Error: calc TotalSz.\n");
201  exitMPI(-1);
202  }
203 
204  if(X->Bind.Def.St==0){
205  sprintf(sdt, cFileNameEnergy_Lanczos, X->Bind.Def.CDataFileHead);
206  }else if(X->Bind.Def.St==1){
207  sprintf(sdt, cFileNameEnergy_CG, X->Bind.Def.CDataFileHead);
208  }
209 
210  if(childfopenMPI(sdt, "w", &fp)!=0){
211  exitMPI(-1);
212  }
213 
214  fprintf(fp,"Energy %.16lf \n",X->Bind.Phys.energy);
215  fprintf(fp,"Doublon %.16lf \n",X->Bind.Phys.doublon);
216  fprintf(fp,"Sz %.16lf \n",X->Bind.Phys.Sz);
217  // fprintf(fp,"total S^2 %.10lf \n",X->Bind.Phys.s2);
218  fclose(fp);
219 
220  if(X->Bind.Def.iOutputEigenVec==TRUE){
222  sprintf(sdt, cFileNameOutputEigen, X->Bind.Def.CDataFileHead, X->Bind.Def.k_exct-1, myrank);
223  if(childfopenALL(sdt, "wb", &fp)!=0){
224  exitMPI(-1);
225  }
226  fwrite(&X->Bind.Large.itr, sizeof(X->Bind.Large.itr),1,fp);
227  fwrite(&X->Bind.Check.idim_max, sizeof(X->Bind.Check.idim_max),1,fp);
228  fwrite(v1, sizeof(complex double),X->Bind.Check.idim_max+1, fp);
229  fclose(fp);
231  }
232 
233  return TRUE;
234 }
const char * cFileNameEnergy_CG
Definition: global.c:42
int childfopenALL(const char *_cPathChild, const char *_cmode, FILE **_fp)
All processes open file in output/ directory.
Definition: FileIO.c:50
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
const char * cOutputEigenVecStart
Definition: LogMessage.c:45
int itr
Iteration number.
Definition: struct.h:315
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
int initial_mode
Definition: global.h:60
const char * cFileNameInputEigen
Definition: global.c:50
double Target_CG_energy
Taget energy of CG-inversed iteration (NOT LOBCG) method.
Definition: struct.h:389
const char * cLogLanczos_EigenVecEnd
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.c:83
double complex * v1
Definition: global.h:35
#define D_FileNameMax
Definition: global.h:23
int iOutputEigenVec
ASwitch for outputting an eigenvector. 0: no output, 1:output.
Definition: struct.h:202
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.h:412
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 * cFileNameOutputEigen
Definition: global.c:49
struct PhysList Phys
Physical quantities.
Definition: struct.h:413
unsigned long int idim_maxMPI
The total dimension across process.
Definition: struct.h:304
#define TRUE
Definition: global.h:26
int expec_totalSz(struct BindStruct *X, double complex *vec)
int CG_EigenVector(struct BindStruct *X)
inversed power method with CG
const char * cOutputEigenVecFinish
Definition: LogMessage.c:46
const char * cLogLanczos_EigenVecStart
int expec_cisajs(struct BindStruct *X, double complex *vec)
function of calculation for one body green&#39;s function
Definition: expec_cisajs.c:69
double eps_Energy
Definition: global.h:156
const char * cReadEigenVecFinish
Definition: LogMessage.c:44
void Lanczos_EigenVector(struct BindStruct *X)
Calculate eigenvectors by the Lanczos method. The calculated tridiagonal matrix components are stor...
double var
Expectation value of the Energy variance.
Definition: struct.h:363
int iFlgGeneralSpin
Flag for the general (Sz/=1/2) spin.
Definition: struct.h:86
#define FALSE
Definition: global.h:25
int iCalcEigenVec
Switch for method to calculate eigenvectors. 0:Lanczos+CG, 1: Lanczos. default value is set as 0 in r...
Definition: struct.h:193
const char * cFileNameTimeKeep
Definition: global.c:23
const char * cReadEigenVecStart
Definition: LogMessage.c:43
int Lanczos_EigenValue(struct BindStruct *X)
Main function for calculating eigen values by Lanczos method. The energy convergence is judged by the...
double doublon
Expectation value of the Doublon.
Definition: struct.h:356
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.h:198
double Sz
Expectation value of the Total Sz.
Definition: struct.h:360
long int initial_iv
Seed of random number for initial guesss of wavefunctions.
Definition: struct.h:76
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.
double energy
Expectation value of the total energy.
Definition: struct.h:355
double complex * v0
Definition: global.h:34
int iInputEigenVec
Switch for reading an eigenvector. 0: no input, 1:input.
Definition: struct.h:203
const char * cFileNameEnergy_Lanczos
Definition: global.c:40
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
int step_i
Definition: global.h:66
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.h:42
struct BindStruct Bind
Binded struct.
Definition: struct.h:420
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
Definition: log.c:42
double Target_energy
Is it really used ???
Definition: struct.h:388
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165
unsigned int k_exct
Read from Calcmod in readdef.h.
Definition: struct.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function: