HΦ  3.2.0
CalcSpectrum.c File Reference

File for givinvg functions of calculating spectrum. More...

#include "mltply.h"
#include "CalcSpectrum.h"
#include "CalcSpectrumByLanczos.h"
#include "CalcSpectrumByBiCG.h"
#include "CalcSpectrumByTPQ.h"
#include "CalcSpectrumByFullDiag.h"
#include "CalcTime.h"
#include "SingleEx.h"
#include "PairEx.h"
#include "wrapperMPI.h"
#include "FileIO.h"
#include "./common/setmemory.h"
#include "readdef.h"
#include "sz.h"
#include "check.h"
#include "diagonalcalc.h"
+ Include dependency graph for CalcSpectrum.c:

Go to the source code of this file.

Functions

int OutputSpectrum (struct EDMainCalStruct *X, int Nomega, double complex *dcSpectrum, double complex *dcomega)
 Output spectrum. More...
 
int CalcSpectrum (struct EDMainCalStruct *X)
 A main function to calculate spectrum. More...
 
int GetExcitedState (struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
 Parent function to calculate the excited state. More...
 
int SetOmega (struct DefineList *X)
 Set target frequencies. More...
 
int MakeExcitedList (struct BindStruct *X, int *iFlgListModifed)
 Make the lists for the excited state; list_1, list_2_1 and list_2_2 (for canonical ensemble). The original lists before the excitation are given by list_xxx_org. More...
 

Detailed Description

File for givinvg functions of calculating spectrum.

Version
1.1
Author
Kazuyoshi Yoshimi (The University of Tokyo)

Definition in file CalcSpectrum.c.

Function Documentation

◆ CalcSpectrum()

int CalcSpectrum ( struct EDMainCalStruct X)

A main function to calculate spectrum.

Parameters
X[in,out] CalcStruct list for getting and pushing calculation information
input: iFlgSpecOmegaOrg, dcOmegaMax, dcOmegaMin, iNOmega etc.
output: dcOmegaOrg, iFlagListModified.
Return values
0normally finished
-1unnormally finished
Version
1.1
Author
Kazuyoshi Yoshimi (The University of Tokyo)
Youhei Yamaji (The University of Tokyo)

Definition at line 90 of file CalcSpectrum.c.

References EDMainCalStruct::Bind, c_CalcExcitedStateEnd, c_CalcExcitedStateStart, c_CalcSpectrumEnd, c_CalcSpectrumStart, c_InputEigenVectorEnd, c_InputEigenVectorStart, CalcSpectrumByBiCG(), CalcSpectrumByFullDiag(), CalcSpectrumByLanczos(), CalcSpectrumByTPQ(), DefineList::CDataFileHead, cFileNameOutputExcitedVec, cFileNameTimeKeep, BindStruct::Check, childfopenALL(), D_FileNameMax, DefineList::dcOmegaMax, DefineList::dcOmegaMin, DefineList::dcOmegaOrg, BindStruct::Def, diagonalcalc(), exitMPI(), FALSE, GetExcitedState(), GetFileNameByKW(), DefineList::iCalcType, CheckList::idim_max, CheckList::idim_maxOrg, DefineList::iFlagListModified, DefineList::iFlgCalcSpec, DefineList::iFlgSpecOmegaOrg, DefineList::iNOmega, DefineList::iOutputExVec, LargeList::itr, BindStruct::Large, list_1_org, list_2_1_org, list_2_2_org, MakeExcitedList(), myrank, NormMPI_dc(), DefineList::NPairExcitationOperator, DefineList::NSingleExcitationOperator, OutputSpectrum(), SetOmega(), StartTimer(), stdoutMPI, StopTimer(), TimeKeeper(), TRUE, v0, v1, v1Org, and vg.

Referenced by main().

92  {
93  char sdt[D_FileNameMax];
94  char *defname;
95  unsigned long int i;
96  unsigned long int i_max = 0;
97  int i_stp;
98  int iFlagListModified = FALSE;
99  FILE *fp;
100  double dnorm;
101 
102  //ToDo: Nomega should be given as a parameter
103  int Nomega;
104  double complex OmegaMax, OmegaMin;
105  double complex *dcSpectrum;
106  double complex *dcomega;
107  size_t byte_size;
108 
109  //set omega
110  if (SetOmega(&(X->Bind.Def)) != TRUE) {
111  fprintf(stderr, "Error: Fail to set Omega.\n");
112  exitMPI(-1);
113  } else {
114  if (X->Bind.Def.iFlgSpecOmegaOrg == FALSE) {
115  X->Bind.Def.dcOmegaOrg = I*(X->Bind.Def.dcOmegaMax - X->Bind.Def.dcOmegaMin) / (double) X->Bind.Def.iNOmega;
116  }
117  }
118  /*
119  Set & malloc omega grid
120  */
121  Nomega = X->Bind.Def.iNOmega;
122  dcSpectrum = cd_1d_allocate(Nomega);
123  dcomega = cd_1d_allocate(Nomega);
124  OmegaMax = X->Bind.Def.dcOmegaMax + X->Bind.Def.dcOmegaOrg;
125  OmegaMin = X->Bind.Def.dcOmegaMin + X->Bind.Def.dcOmegaOrg;
126  for (i = 0; i < Nomega; i++) {
127  dcomega[i] = (OmegaMax - OmegaMin) / Nomega * i + OmegaMin;
128  }
129 
130  fprintf(stdoutMPI, "\nFrequency range:\n");
131  fprintf(stdoutMPI, " Omega Max. : %15.5e %15.5e\n", creal(OmegaMax), cimag(OmegaMax));
132  fprintf(stdoutMPI, " Omega Min. : %15.5e %15.5e\n", creal(OmegaMin), cimag(OmegaMin));
133  fprintf(stdoutMPI, " Num. of Omega : %d\n", Nomega);
134 
136  fprintf(stderr, "Error: Any excitation operators are not defined.\n");
137  exitMPI(-1);
138  }
139  //Make New Lists
140  if (MakeExcitedList(&(X->Bind), &iFlagListModified) == FALSE) {
141  return FALSE;
142  }
143  X->Bind.Def.iFlagListModified = iFlagListModified;
144 
145  //Set Memory
146  v1Org = cd_1d_allocate(X->Bind.Check.idim_maxOrg+1);
147  for(i=0; i<X->Bind.Check.idim_maxOrg+1; i++){
148  v1Org[i]=0;
149  }
150 
151  //Make excited state
152  StartTimer(6100);
153  if (X->Bind.Def.iFlgCalcSpec == RECALC_NOT ||
154  X->Bind.Def.iFlgCalcSpec == RECALC_OUTPUT_TMComponents_VEC ||
155  (X->Bind.Def.iFlgCalcSpec == RECALC_INOUT_TMComponents_VEC && X->Bind.Def.iCalcType == CG)) {
156  //input eigen vector
157  StartTimer(6101);
158  fprintf(stdoutMPI, " Start: An Eigenvector is inputted in CalcSpectrum.\n");
160  GetFileNameByKW(KWSpectrumVec, &defname);
161  strcat(defname, "_rank_%d.dat");
162 // sprintf(sdt, cFileNameInputEigen, X->Bind.Def.CDataFileHead, X->Bind.Def.k_exct - 1, myrank);
163  sprintf(sdt, defname, myrank);
164  childfopenALL(sdt, "rb", &fp);
165 
166  if (fp == NULL) {
167  fprintf(stderr, "Error: A file of Input vector does not exist.\n");
168  return -1;
169  }
170 
171  byte_size = fread(&i_stp, sizeof(i_stp), 1, fp);
172  X->Bind.Large.itr = i_stp; //For TPQ
173  byte_size = fread(&i_max, sizeof(i_max), 1, fp);
174  if (i_max != X->Bind.Check.idim_maxOrg) {
175  fprintf(stderr, "Error: myrank=%d, i_max=%ld\n", myrank, i_max);
176  fprintf(stderr, "Error: A file of Input vector is incorrect.\n");
177  return -1;
178  }
179  byte_size = fread(v1Org, sizeof(complex double), i_max + 1, fp);
180  fclose(fp);
181  StopTimer(6101);
182  if (byte_size == 0) printf("byte_size: %d \n", (int) byte_size);
183 
184  for (i = 0; i <= X->Bind.Check.idim_max; i++) {
185  v0[i] = 0;
186  }
187  fprintf(stdoutMPI, " End: An Input vector is inputted in CalcSpectrum.\n\n");
190  fprintf(stdoutMPI, " Start: Calculating an excited vector.\n");
191 
192  //Multiply Operator
193  StartTimer(6102);
194  GetExcitedState(&(X->Bind), v0, v1Org);
195  StopTimer(6102);
196 
197  //calculate norm
198  dnorm = NormMPI_dc(X->Bind.Check.idim_max, v0);
199  if (fabs(dnorm) < pow(10.0, -15)) {
200  fprintf(stderr, "Warning: Norm of an excited vector becomes 0.\n");
201  fprintf(stdoutMPI, " End: Calculating an excited vector.\n\n");
203  fprintf(stdoutMPI, " End: Calculating a spectrum.\n\n");
205  for (i = 0; i < Nomega; i++) {
206  dcSpectrum[i] = 0;
207  }
208  OutputSpectrum(X, Nomega, dcSpectrum, dcomega);
209  return TRUE;
210  }
211  //normalize vector
212 #pragma omp parallel for default(none) private(i) shared(v1, v0) firstprivate(i_max, dnorm, X)
213  for (i = 1; i <= X->Bind.Check.idim_max; i++) {
214  v1[i] = v0[i] / dnorm;
215  }
216 
217  //Output excited vector
218  if (X->Bind.Def.iOutputExVec == 1) {
219  fprintf(stdoutMPI, " Start: Output an excited vector.\n\n");
221  if(childfopenALL(sdt, "w", &fp)!=0){
222  return -1;
223  }
224  fprintf(fp, "%ld\n", X->Bind.Check.idim_max);
225  for (i = 1; i <= X->Bind.Check.idim_max; i++) {
226  fprintf(fp, "%.10lf, %.10lf\n", creal(v1[i]), cimag(v1[i]));
227  }
228  fclose(fp);
229  fprintf(stdoutMPI, " End: Output an excited vector.\n\n");
230  }
231 
232  fprintf(stdoutMPI, " End: Calculating an excited vector.\n\n");
234  }
235  StopTimer(6100);
236  //Reset list_1, list_2_1, list_2_2
237  if (iFlagListModified == TRUE) {
238  free(v1Org);
239  free(list_1_org);
240  free(list_2_1_org);
241  free(list_2_2_org);
242  }
243  //calculate Diagonal term
244  diagonalcalc(&(X->Bind));
245 
246 
247  int iret = TRUE;
248  fprintf(stdoutMPI, " Start: Calculating a spectrum.\n\n");
250  StartTimer(6200);
251  switch (X->Bind.Def.iCalcType) {
252  case Lanczos:
253 
254  iret = CalcSpectrumByLanczos(X, v1, dnorm, Nomega, dcSpectrum, dcomega);
255 
256  if (iret != TRUE) {
257  //Error Message will be added.
258  return FALSE;
259  }
260 
261  break;//Lanczos Spectrum
262 
263  case CG:
264 
265  iret = CalcSpectrumByBiCG(X, v0, v1, vg, Nomega, dcSpectrum, dcomega);
266 
267  if (iret != TRUE) {
268  //Error Message will be added.
269  return FALSE;
270  }
271 
272  break;//Lanczos Spectrum
273 
274  case TPQCalc:
275  fprintf(stderr, " Error: TPQ is not supported for calculating spectrum mode.\n");
276  return FALSE;//TPQ is not supprted.
277 #ifdef _CALCSPEC_TPQ
278  iret = CalcSpectrumByTPQ(X, v1, dnorm, Nomega, dcSpectrum, dcomega);
279  if (iret != TRUE) {
280  //Error Message will be added.
281  return FALSE;
282  }
283 #endif
284 
285  case FullDiag:
286  iret = CalcSpectrumByFullDiag(X, Nomega, dcSpectrum, dcomega);
287  break;
288 
289  default:
290  break;
291  }
292  StopTimer(6200);
293 
294  if (iret != TRUE) {
295  fprintf(stderr, " Error: The selected calculation type is not supported for calculating spectrum mode.\n");
296  return FALSE;
297  }
298 
299  fprintf(stdoutMPI, " End: Calculating a spectrum.\n\n");
301  iret = OutputSpectrum(X, Nomega, dcSpectrum, dcomega);
302  free_cd_1d_allocate(dcSpectrum);
303  free_cd_1d_allocate(dcomega);
304  return TRUE;
305 
306 }/*int CalcSpectrum*/
unsigned int NSingleExcitationOperator
Number of single excitaion operator for spectrum.
Definition: struct.h:182
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 MakeExcitedList(struct BindStruct *X, int *iFlgListModifed)
Make the lists for the excited state; list_1, list_2_1 and list_2_2 (for canonical ensemble)...
Definition: CalcSpectrum.c:434
void StartTimer(int n)
function for initializing elapse time [start]
Definition: time.c:71
double complex * v1Org
Definition: global.h:40
long unsigned int * list_2_1_org
Definition: global.h:55
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 CalcSpectrumByFullDiag(struct EDMainCalStruct *X, int Nomega, double complex *dcSpectrum, double complex *dcomega)
Compute the Green function with the Lehmann representation and FD .
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.c:83
const char * c_InputEigenVectorEnd
Definition: LogMessage.c:61
int iFlagListModified
When the Hilbert space of excited state differs from the original one.
Definition: struct.h:217
double complex * v1
Definition: global.h:35
double complex dcOmegaMax
Upper limit of the frequency for the spectrum.
Definition: struct.h:209
const char * c_CalcSpectrumEnd
Definition: LogMessage.c:65
#define D_FileNameMax
Definition: global.h:23
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.h:412
const char * cFileNameOutputExcitedVec
Definition: global.c:82
const char * c_CalcExcitedStateEnd
Definition: LogMessage.c:63
#define TRUE
Definition: global.h:26
const char * c_CalcSpectrumStart
Definition: LogMessage.c:64
int GetExcitedState(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Parent function to calculate the excited state.
Definition: CalcSpectrum.c:316
double NormMPI_dc(unsigned long int idim, double complex *_v1)
Compute norm of process-distributed vector .
Definition: wrapperMPI.c:289
long unsigned int * list_2_2_org
Definition: global.h:56
int CalcSpectrumByBiCG(struct EDMainCalStruct *X, double complex *vrhs, double complex *v2, double complex *v4, int Nomega, double complex *dcSpectrum, double complex *dcomega)
A main function to calculate spectrum by BiCG method In this function, the library is used...
const char * c_InputEigenVectorStart
Definition: LogMessage.c:60
int diagonalcalc(struct BindStruct *X)
Calculate diagonal components and obtain the list, list_diagonal.
Definition: diagonalcalc.c:85
int CalcSpectrumByLanczos(struct EDMainCalStruct *X, double complex *tmp_v1, double dnorm, int Nomega, double complex *dcSpectrum, double complex *dcomega)
A main function to calculate spectrum by continued fraction expansions.
unsigned long int idim_maxOrg
The local Hilbert-space dimention of original state for the spectrum.
Definition: struct.h:305
int CalcSpectrumByTPQ(struct EDMainCalStruct *X, double complex *tmp_v1, double dnorm, int Nomega, double complex *dcSpectrum, double complex *dcomega)
A main function to calculate spectrum by TPQ (Note: This method is trial)
const char * c_CalcExcitedStateStart
Definition: LogMessage.c:62
long unsigned int * list_1_org
Definition: global.h:53
int SetOmega(struct DefineList *X)
Set target frequencies.
Definition: CalcSpectrum.c:350
int iNOmega
Number of frequencies for spectrum.
Definition: struct.h:212
#define FALSE
Definition: global.h:25
int iFlgSpecOmegaOrg
Whether DefineList::dcOmegaOrg is input or not.
Definition: struct.h:215
unsigned int NPairExcitationOperator
Number of pair excitaion operator for spectrum.
Definition: struct.h:188
const char * cFileNameTimeKeep
Definition: global.c:23
double complex * vg
Definition: global.h:41
int iOutputExVec
Definition: struct.h:206
double complex dcOmegaOrg
Origin limit of the frequency for the spectrum.
Definition: struct.h:211
double complex dcOmegaMin
Lower limit of the frequency for the spectrum.
Definition: struct.h:210
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:163
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.h:216
int OutputSpectrum(struct EDMainCalStruct *X, int Nomega, double complex *dcSpectrum, double complex *dcomega)
Output spectrum.
Definition: CalcSpectrum.c:49
int GetFileNameByKW(int iKWidx, char **FileName)
function of getting file name labeled by the keyword
Definition: readdef.c:2715
double complex * v0
Definition: global.h:34
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
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
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.h:192
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExcitedState()

int GetExcitedState ( struct BindStruct X,
double complex *  tmp_v0,
double complex *  tmp_v1 
)

Parent function to calculate the excited state.

Parameters
X[in] Struct to get number of excitation operators.
tmp_v0[out] Result \( v_0 = H_{ex} v_1 \).
tmp_v1[in] The original state before excitation \( v_1 \).
Return values
FALSEFail to calculate the excited state.
TRUESuccess to calculate the excited state.

Definition at line 316 of file CalcSpectrum.c.

References BindStruct::Def, FALSE, GetPairExcitedState(), GetSingleExcitedState(), DefineList::NPairExcitationOperator, DefineList::NSingleExcitationOperator, SetOmega(), and TRUE.

Referenced by CalcSpectrum().

321 {
323  fprintf(stderr, "Error: Both single and pair excitation operators exist.\n");
324  return FALSE;
325  }
326 
327 
328  if(X->Def.NSingleExcitationOperator > 0){
329  if(GetSingleExcitedState(X,tmp_v0, tmp_v1)!=TRUE){
330  return FALSE;
331  }
332  }
333  else if(X->Def.NPairExcitationOperator >0){
334  if(GetPairExcitedState(X,tmp_v0, tmp_v1)!=TRUE){
335  return FALSE;
336  }
337  }
338 
339  return TRUE;
340 }
unsigned int NSingleExcitationOperator
Number of single excitaion operator for spectrum.
Definition: struct.h:182
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
#define TRUE
Definition: global.h:26
int GetPairExcitedState(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Calculating the pair excited state by the pair operator; , where indicates a creation (anti-creat...
Definition: PairEx.c:47
#define FALSE
Definition: global.h:25
unsigned int NPairExcitationOperator
Number of pair excitaion operator for spectrum.
Definition: struct.h:188
int GetSingleExcitedState(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Calculation of single excited state Target System: Hubbard, Kondo.
Definition: SingleEx.c:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeExcitedList()

int MakeExcitedList ( struct BindStruct X,
int *  iFlgListModifed 
)

Make the lists for the excited state; list_1, list_2_1 and list_2_2 (for canonical ensemble). The original lists before the excitation are given by list_xxx_org.

Parameters
X[in, out] Struct to get and give information to make the lists for the excited state.
Output: iCalcModel (From HubbardNConserved to Hubbard), {Ne, Nup, Ndown, Nsite, Total2Sz} (update for MPI)
iFlgListModifed[out] If the list is modified due to the excitation, the value becomes TRUE(1), otherwise FALSE(0).
Return values
-1fail to make lists.
0sucsess to make lists.

Definition at line 434 of file CalcSpectrum.c.

References cErrLargeMem, check(), BindStruct::Check, BindStruct::Def, exitMPI(), FALSE, FinalizeMPI(), GetlistSize(), DefineList::iCalcModel, CheckList::idim_max, CheckList::idim_maxMPI, CheckList::idim_maxMPIOrg, CheckList::idim_maxOrg, iErrCodeMem, DefineList::iFlgGeneralSpin, BindStruct::Large, list_1, list_1_org, list_1buf_org, list_2_1, list_2_1_org, list_2_2, list_2_2_org, MPIFALSE, myrank, DefineList::Ndown, DefineList::NdownOrg, DefineList::Ne, DefineList::NeMPI, DefineList::NPairExcitationOperator, DefineList::NSingleExcitationOperator, DefineList::Nsite, DefineList::NsiteMPI, DefineList::Nup, DefineList::NupOrg, DefineList::OrgTpow, DefineList::PairExcitationOperator, setmem_large(), DefineList::SingleExcitationOperator, LargeList::SizeOflist_2_1, LargeList::SizeOflist_2_2, stdoutMPI, sz(), DefineList::Total2Sz, DefineList::Total2SzMPI, and TRUE.

Referenced by CalcSpectrum().

437  {
438  long int j;
439  *iFlgListModifed = FALSE;
440  //To Get Original space
441  if (check(X) == MPIFALSE) {
442  FinalizeMPI();
443  return -1;
444  }
445 
448 
449  if (X->Def.NSingleExcitationOperator > 0) {
450  switch (X->Def.iCalcModel) {
451  case HubbardGC:
452  break;
453  case HubbardNConserved:
454  case KondoGC:
455  case Hubbard:
456  case Kondo:
457  *iFlgListModifed = TRUE;
458  break;
459  case Spin:
460  case SpinGC:
461  return FALSE;
462  }
463  } else if (X->Def.NPairExcitationOperator > 0) {
464  switch (X->Def.iCalcModel) {
465  case HubbardGC:
466  case SpinGC:
467  case HubbardNConserved:
468  break;
469  case KondoGC:
470  case Hubbard:
471  case Kondo:
472  case Spin:
473  if (X->Def.PairExcitationOperator[0][1] != X->Def.PairExcitationOperator[0][3]) {
474  *iFlgListModifed = TRUE;
475  }
476  break;
477  }
478  } else {
479  return FALSE;
480  }
481 
482  if (*iFlgListModifed == TRUE) {
483  if(GetlistSize(X)==TRUE) {
484  list_1_org = lui_1d_allocate(X->Check.idim_max + 1);
485 #ifdef MPI
486  list_1buf_org = lui_1d_allocate(X->Check.idim_maxMPI + 1);
487  //lui_malloc1(list_1buf_org, X->Check.idim_maxMPI + 1);
488 #endif // MPI
489  list_2_1_org = lui_1d_allocate(X->Large.SizeOflist_2_1);
490  list_2_2_org = lui_1d_allocate(X->Large.SizeOflist_2_2);
491  //lui_malloc1(list_2_1_org, X->Large.SizeOflist_2_1);
492  //lui_malloc1(list_2_2_org, X->Large.SizeOflist_2_2);
493  if(list_1_org==NULL
494  || list_2_1_org==NULL
495  || list_2_2_org==NULL
496  )
497  {
498  return -1;
499  }
500  for(j =0; j<X->Large.SizeOflist_2_1; j++){
501  list_2_1_org[j]=0;
502  }
503  for(j =0; j<X->Large.SizeOflist_2_2; j++){
504  list_2_2_org[j]=0;
505  }
506 
507  }
508 
509  if (sz(X, list_1_org, list_2_1_org, list_2_2_org) != 0) {
510  return FALSE;
511  }
512 
513  if (X->Def.NSingleExcitationOperator > 0) {
514  switch (X->Def.iCalcModel) {
515  case HubbardGC:
516  break;
517  case HubbardNConserved:
518  if (X->Def.SingleExcitationOperator[0][2] == 1) { //cis
519  X->Def.Ne = X->Def.NeMPI + 1;
520  }
521  else{
522  X->Def.Ne = X->Def.NeMPI - 1;
523  }
524  break;
525  case KondoGC:
526  case Hubbard:
527  case Kondo:
528  if (X->Def.SingleExcitationOperator[0][2] == 1) { //cis
529  X->Def.Ne = X->Def.NeMPI + 1;
530  if (X->Def.SingleExcitationOperator[0][1] == 0) {//up
531  X->Def.Nup = X->Def.NupOrg + 1;
532  X->Def.Ndown=X->Def.NdownOrg;
533  } else {//down
534  X->Def.Nup=X->Def.NupOrg;
535  X->Def.Ndown = X->Def.NdownOrg + 1;
536  }
537  } else {//ajt
538  X->Def.Ne = X->Def.NeMPI - 1;
539  if (X->Def.SingleExcitationOperator[0][1] == 0) {//up
540  X->Def.Nup = X->Def.NupOrg - 1;
541  X->Def.Ndown=X->Def.NdownOrg;
542 
543  } else {//down
544  X->Def.Nup=X->Def.NupOrg;
545  X->Def.Ndown = X->Def.NdownOrg - 1;
546  }
547  }
548  break;
549  case Spin:
550  case SpinGC:
551  return FALSE;
552  }
553  } else if (X->Def.NPairExcitationOperator > 0) {
554  X->Def.Ne=X->Def.NeMPI;
555  switch (X->Def.iCalcModel) {
556  case HubbardGC:
557  case SpinGC:
558  case HubbardNConserved:
559  break;
560  case KondoGC:
561  case Hubbard:
562  case Kondo:
563  if (X->Def.PairExcitationOperator[0][1] != X->Def.PairExcitationOperator[0][3]) {
564  if (X->Def.PairExcitationOperator[0][1] == 0) {//up
565  X->Def.Nup = X->Def.NupOrg + 1;
566  X->Def.Ndown = X->Def.NdownOrg - 1;
567  } else {//down
568  X->Def.Nup = X->Def.NupOrg - 1;
569  X->Def.Ndown = X->Def.NdownOrg + 1;
570  }
571  }
572  break;
573  case Spin:
574  if (X->Def.PairExcitationOperator[0][1] != X->Def.PairExcitationOperator[0][3]) {
575  if (X->Def.iFlgGeneralSpin == FALSE) {
576  if (X->Def.PairExcitationOperator[0][1] == 0) {//down
577  X->Def.Nup = X->Def.NupOrg - 1;
578  X->Def.Ndown = X->Def.NdownOrg + 1;
579  } else {//up
580  X->Def.Nup = X->Def.NupOrg + 1;
581  X->Def.Ndown = X->Def.NdownOrg - 1;
582  }
583  }
584  else{//for general spin
586  }
587  }
588  break;
589  }
590  } else {
591  return FALSE;
592  }
593  //Update Infomation
594  X->Def.Nsite=X->Def.NsiteMPI;
595 
596  if (check(X) == MPIFALSE) {
597  FinalizeMPI();
598  return FALSE;
599  }
600  }
601 
602  //set memory
603  if (setmem_large(X) != 0) {
605  exitMPI(-1);
606  }
607 
608  if (sz(X, list_1, list_2_1, list_2_2) != 0) {
609  return FALSE;
610  }
611 
612  if(X->Def.iCalcModel==HubbardNConserved){
613  X->Def.iCalcModel=Hubbard;
614  }
615 
616 #ifdef _DEBUG
617  if (*iFlgListModifed == TRUE) {
618  for(j=1; j<=X->Check.idim_maxOrg; j++){
619  fprintf(stdout, "Debug1: myrank=%d, list_1_org[ %ld] = %ld\n", myrank, j, list_1_org[j]+myrank*X->Def.OrgTpow[2*X->Def.NsiteMPI-1]);
620  }
621 
622  for(j=1; j<=X->Check.idim_max; j++){
623  fprintf(stdout, "Debug2: myrank=%d, list_1[ %ld] = %ld\n", myrank, j, list_1[j]+myrank* 64);
624  }
625  }
626 #endif
627 
628  return TRUE;
629 }
unsigned int NSingleExcitationOperator
Number of single excitaion operator for spectrum.
Definition: struct.h:182
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.c:86
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
long unsigned int * list_2_1_org
Definition: global.h:55
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
int sz(struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_)
generating Hilbert space
Definition: sz.c:63
int Total2Sz
Total in this process.
Definition: struct.h:69
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.h:412
unsigned long int idim_maxMPIOrg
The global Hilbert-space dimention of original state for the spectrum.
Definition: struct.h:306
unsigned int Nup
Number of spin-up electrons in this process.
Definition: struct.h:58
unsigned long int idim_maxMPI
The total dimension across process.
Definition: struct.h:304
long int SizeOflist_2_1
Size of list_2_1.
Definition: struct.h:318
int check(struct BindStruct *X)
A program to check size of dimension for Hilbert-space.
Definition: check.c:51
int setmem_large(struct BindStruct *X)
Set size of memories for Hamiltonian (Ham, L_vec), vectors(vg, v0, v1, v2, vec, alpha, beta), lists (list_1, list_2_1, list_2_2, list_Diagonal) and Phys(BindStruct.PhysList) struct in the case of Full Diag mode.
Definition: xsetmem.c:157
#define TRUE
Definition: global.h:26
long unsigned int * list_1buf_org
Definition: global.h:54
long unsigned int * OrgTpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.h:92
int iErrCodeMem
Error Message in HPhiMain.c.
Definition: ErrorMessage.c:20
unsigned int NupOrg
Number of spin-up electrons before exitation. Used only in the spectrum calculation. Read from modpara in readdef.h.
Definition: struct.h:64
long unsigned int * list_2_2_org
Definition: global.h:56
unsigned int NeMPI
Total number of electrons across process. Differ from DefineList::Ne .
Definition: struct.h:72
unsigned int Ndown
Number of spin-down electrons in this process.
Definition: struct.h:59
unsigned long int idim_maxOrg
The local Hilbert-space dimention of original state for the spectrum.
Definition: struct.h:305
unsigned int Nsite
Number of sites in the INTRA process region.
Definition: struct.h:56
#define MPIFALSE
Definition: global.h:24
long unsigned int * list_1_org
Definition: global.h:53
int ** SingleExcitationOperator
[DefineList::NSingleExcitationOperator][3] Indices of single excitaion operator for spectrum...
Definition: struct.h:180
long unsigned int * list_2_1
Definition: global.h:49
int GetlistSize(struct BindStruct *X)
Set size of lists for the canonical ensemble.
Definition: xsetmem.c:288
void FinalizeMPI()
MPI Finitialization wrapper.
Definition: wrapperMPI.c:74
char * cErrLargeMem
Definition: ErrorMessage.c:35
unsigned int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.h:57
int iFlgGeneralSpin
Flag for the general (Sz/=1/2) spin.
Definition: struct.h:86
#define FALSE
Definition: global.h:25
long unsigned int * list_1
Definition: global.h:47
unsigned int NPairExcitationOperator
Number of pair excitaion operator for spectrum.
Definition: struct.h:188
long unsigned int * list_2_2
Definition: global.h:50
int ** PairExcitationOperator
[DefineList::NPairExcitationOperator][5] Indices of pair excitaion operator for spectrum. malloc in setmem_def().
Definition: struct.h:186
unsigned int NdownOrg
Number of spin-down electrons before exitation. Used only in the spectrum calculation. Read from modpara in readdef.h.
Definition: struct.h:66
unsigned int Ne
Number of electrons in this process.
Definition: struct.h:71
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.h:198
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:163
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
long int SizeOflist_2_2
Size of list_2_2.
Definition: struct.h:319
int Total2SzMPI
Total across processes.
Definition: struct.h:70
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OutputSpectrum()

int OutputSpectrum ( struct EDMainCalStruct X,
int  Nomega,
double complex *  dcSpectrum,
double complex *  dcomega 
)

Output spectrum.

Parameters
X[in] Read information of the frequency origin.
Nomega[in] A total number of discrete frequencies.
dcSpectrum[in] Array of spectrum.
dcomega[in] Array of discrete frequencies.
Return values
FALSEFail to open the output file.
TRUESuccess to output the spectrum.

Definition at line 49 of file CalcSpectrum.c.

Referenced by CalcSpectrum().

54 {
55  FILE *fp;
56  char sdt[D_FileNameMax];
57  int i;
58 
59  //output spectrum
61  if(childfopenMPI(sdt, "w", &fp)!=0){
62  return FALSE;
63  }
64 
65  for (i = 0; i < Nomega; i++) {
66  fprintf(fp, "%.10lf %.10lf %.10lf %.10lf \n",
67  creal(dcomega[i]-X->Bind.Def.dcOmegaOrg), cimag(dcomega[i]-X->Bind.Def.dcOmegaOrg),
68  creal(dcSpectrum[i]), cimag(dcSpectrum[i]));
69  }/*for (i = 0; i < Nomega; i++)*/
70 
71  fclose(fp);
72  return TRUE;
73 }/*int OutputSpectrum*/
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
#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
#define TRUE
Definition: global.h:26
const char * cFileNameCalcDynamicalGreen
Definition: global.c:51
#define FALSE
Definition: global.h:25
double complex dcOmegaOrg
Origin limit of the frequency for the spectrum.
Definition: struct.h:211
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
+ Here is the caller graph for this function:

◆ SetOmega()

int SetOmega ( struct DefineList X)

Set target frequencies.

Parameters
X[in, out] Struct to give and get the information of target frequencies.
Output: dcOmegaMax, dcOmegaMin
Return values
FALSEFail to set frequencies.
TRUESuccess to set frequencies.

Definition at line 350 of file CalcSpectrum.c.

References DefineList::CDataFileHead, cFileNameEnergy_Lanczos, cFileNameLanczosStep, childfopenMPI(), D_FileNameMax, DefineList::dcOmegaMax, DefineList::dcOmegaMin, FALSE, fgetsMPI(), DefineList::iCalcType, DefineList::iFlgSpecOmegaMax, DefineList::iFlgSpecOmegaMin, LargeValue, DefineList::Nsite, stdoutMPI, and TRUE.

Referenced by CalcSpectrum(), and GetExcitedState().

352  {
353  FILE *fp;
354  char sdt[D_FileNameMax],ctmp[256];
355  int istp=4;
356  double E1, E2, E3, E4, Emax;
357  long unsigned int iline_countMax=2;
358  long unsigned int iline_count=2;
359 
360 
361  if(X->iFlgSpecOmegaMax == TRUE && X->iFlgSpecOmegaMin == TRUE){
362  return TRUE;
363  }
364  else{
365  if (X->iCalcType == Lanczos || X->iCalcType == FullDiag) {
366  sprintf(sdt, cFileNameLanczosStep, X->CDataFileHead);
367  childfopenMPI(sdt, "r", &fp);
368  if (fp == NULL) {
369  fprintf(stdoutMPI, "Error: xx_Lanczos_Step.dat does not exist.\n");
370  return FALSE;
371  }
372  fgetsMPI(ctmp, 256, fp); //1st line is skipped
373  fgetsMPI(ctmp, 256, fp); //2nd line is skipped
374  while (fgetsMPI(ctmp, 256, fp) != NULL) {
375  iline_count++;
376  }
377  iline_countMax = iline_count;
378  iline_count = 2;
379  rewind(fp);
380  fgetsMPI(ctmp, 256, fp); //1st line is skipped
381  fgetsMPI(ctmp, 256, fp); //2nd line is skipped
382 
383  while (fgetsMPI(ctmp, 256, fp) != NULL) {
384  sscanf(ctmp, "stp=%d %lf %lf %lf %lf %lf\n",
385  &istp,
386  &E1,
387  &E2,
388  &E3,
389  &E4,
390  &Emax);
391  iline_count++;
392  if (iline_count == iline_countMax) break;
393  }
394  fclose(fp);
395  if (istp < 4) {
396  fprintf(stdoutMPI, "Error: Lanczos step must be greater than 4 for using spectrum calculation.\n");
397  return FALSE;
398  }
399  }/*if (X->iCalcType == Lanczos || X->iCalcType == FullDiag)*/
400  else
401  {
402  sprintf(sdt, cFileNameEnergy_Lanczos, X->CDataFileHead);
403  childfopenMPI(sdt, "r", &fp);
404  if (fp == NULL) {
405  fprintf(stdoutMPI, "Error: xx_energy.dat does not exist.\n");
406  return FALSE;
407  }/*if (fp == NULL)*/
408  fgetsMPI(ctmp, 256, fp); //1st line is skipped
409  fgetsMPI(ctmp, 256, fp); //1st line is skipped
410  sscanf(ctmp, " Energy %lf \n", &E1);
411  Emax = LargeValue;
412  }
413  //Read Lanczos_Step
414  if(X->iFlgSpecOmegaMax == FALSE){
415  X->dcOmegaMax= Emax*(double)X->Nsite;
416  }
417  if(X->iFlgSpecOmegaMin == FALSE){
418  X->dcOmegaMin= E1;
419  }
420  }/*Omegamax and omegamin is not specified in modpara*/
421 
422  return TRUE;
423 }
int iFlgSpecOmegaMin
Whether DefineList::dcOmegaMin is input or not.
Definition: struct.h:214
double complex dcOmegaMax
Upper limit of the frequency for the spectrum.
Definition: struct.h:209
#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 * cFileNameLanczosStep
Definition: global.c:39
#define TRUE
Definition: global.h:26
unsigned int Nsite
Number of sites in the INTRA process region.
Definition: struct.h:56
#define FALSE
Definition: global.h:25
int iFlgSpecOmegaMax
Whether DefineList::dcOmegaMax is input or not.
Definition: struct.h:213
double complex dcOmegaMin
Lower limit of the frequency for the spectrum.
Definition: struct.h:210
char * fgetsMPI(char *InputString, int maxcount, FILE *fp)
MPI file I/O (get a line, fgets) wrapper. Only the root node (myrank = 0) reads and broadcast string...
Definition: wrapperMPI.c:122
const char * cFileNameEnergy_Lanczos
Definition: global.c:40
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.h:42
double LargeValue
Definition: global.h:64
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.h:192
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function: