HPhi++  3.1.0
CalcSpectrum.cpp File Reference

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

#include "mltply.hpp"
#include "CalcSpectrum.hpp"
#include "CalcSpectrumByBiCG.hpp"
#include "CalcSpectrumByFullDiag.hpp"
#include "CalcTime.hpp"
#include "SingleEx.hpp"
#include "PairEx.hpp"
#include "wrapperMPI.hpp"
#include "FileIO.hpp"
#include "common/setmemory.hpp"
#include "readdef.hpp"
#include "sz.hpp"
#include "check.hpp"
#include "diagonalcalc.hpp"
#include <iostream>

Go to the source code of this file.

Functions

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...
 
int OutputSpectrum (struct EDMainCalStruct *X, int Nomega, int NdcSpectrum, std::complex< double > **dcSpectrum, std::complex< double > *dcomega)
 Output spectrum. More...
 
int GetExcitedState (struct BindStruct *X, int nstate, std::complex< double > **tmp_v0, std::complex< double > **tmp_v1, int iEx)
 Parent function to calculate the excited state. More...
 
int CalcSpectrum (struct EDMainCalStruct *X)
 A main function to calculate spectrum. More...
 

Detailed Description

File for givinvg functions of calculating spectrum.

Version
1.1
Author
Kazuyoshi Yoshimi (The University of Tokyo)

Definition in file CalcSpectrum.cpp.

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)

< Input vector to calculate spectrum function.

Definition at line 422 of file CalcSpectrum.cpp.

References EDMainCalStruct::Bind, CalcSpectrumByBiCG(), CalcSpectrumByFullDiag(), BindStruct::Check, childfopenALL(), DefineList::dcOmegaMax, DefineList::dcOmegaMin, DefineList::dcOmegaOrg, BindStruct::Def, diagonalcalc(), PhysList::doublon, PhysList::doublon2, PhysList::energy, exitMPI(), GetFileNameByKW(), GetlistSize(), I(), DefineList::iCalcType, CheckList::idim_max, CheckList::idim_maxOrg, DefineList::iFlagListModified, DefineList::iFlgCalcSpec, DefineList::iFlgSpecOmegaOrg, DefineList::iNOmega, LargeList::itr, BindStruct::Large, list_1, list_1buf, list_2_1, list_2_2, list_Diagonal, MakeExcitedList(), myrank, DefineList::Ndown, DefineList::NdownMPI, DefineList::Ne, DefineList::NeMPI, DefineList::NNPairExcitationOperator, DefineList::NNSingleExcitationOperator, DefineList::Nsite, DefineList::NsiteMPI, PhysList::num, PhysList::num2, PhysList::num_down, PhysList::num_up, DefineList::Nup, DefineList::NupMPI, OutputSpectrum(), BindStruct::Phys, PhysList::s2, SetOmega(), StartTimer(), stdoutMPI, StopTimer(), PhysList::Sz, PhysList::Sz2, TimeKeeper(), DefineList::Total2Sz, DefineList::Total2SzMPI, v0, v1, v1buf, and PhysList::var.

Referenced by main().

424  {
425  char sdt[D_FileNameMax];
426  char *defname;
427  long int i;
428  long int i_max = 0;
429  int i_stp, NdcSpectrum;
430  int iFlagListModified = FALSE;
431  FILE *fp;
432  std::complex<double> **v1Org;
434  //ToDo: Nomega should be given as a parameter
435  int Nomega;
436  std::complex<double> OmegaMax, OmegaMin;
437  std::complex<double> **dcSpectrum;
438  std::complex<double> *dcomega;
439  size_t byte_size;
440 
441  if (X->Bind.Def.iFlgCalcSpec == CALCSPEC_SCRATCH) {
442  X->Bind.Def.Nsite = X->Bind.Def.NsiteMPI;
444  X->Bind.Def.Ne = X->Bind.Def.NeMPI;
445  X->Bind.Def.Nup = X->Bind.Def.NupMPI;
446  X->Bind.Def.Ndown = X->Bind.Def.NdownMPI;
447  if (GetlistSize(&(X->Bind)) == TRUE) {
448  free_li_1d_allocate(list_1);
449  free_li_1d_allocate(list_2_1);
450  free_li_1d_allocate(list_2_2);
451  }
452  free_d_1d_allocate(list_Diagonal);
453  free_cd_2d_allocate(v0);
454  v1Org = cd_2d_allocate(X->Bind.Check.idim_max + 1, 1);
455  for (i = 1; i <= X->Bind.Check.idim_max; i++) v1Org[i][0] = v1[i][0];
456  free_cd_2d_allocate(v1);
457 #ifdef __MPI
458  free_li_1d_allocate(list_1buf);
459  free_cd_2d_allocate(v1buf);
460 #endif // MPI
461  free_d_1d_allocate(X->Bind.Phys.num_down);
462  free_d_1d_allocate(X->Bind.Phys.num_up);
463  free_d_1d_allocate(X->Bind.Phys.num);
464  free_d_1d_allocate(X->Bind.Phys.num2);
465  free_d_1d_allocate(X->Bind.Phys.energy);
466  free_d_1d_allocate(X->Bind.Phys.var);
467  free_d_1d_allocate(X->Bind.Phys.doublon);
468  free_d_1d_allocate(X->Bind.Phys.doublon2);
469  free_d_1d_allocate(X->Bind.Phys.Sz);
470  free_d_1d_allocate(X->Bind.Phys.Sz2);
471  free_d_1d_allocate(X->Bind.Phys.s2);
472  }/*if (X->Bind.Def.iFlgCalcSpec == CALCSPEC_SCRATCH)*/
473 
474  //set omega
475  if (SetOmega(&(X->Bind.Def)) != TRUE) {
476  fprintf(stderr, "Error: Fail to set Omega.\n");
477  exitMPI(-1);
478  }
479  else {
480  if (X->Bind.Def.iFlgSpecOmegaOrg == FALSE) {
481  X->Bind.Def.dcOmegaOrg = I * (X->Bind.Def.dcOmegaMax - X->Bind.Def.dcOmegaMin) / (double)X->Bind.Def.iNOmega;
482  }
483  }
484  /*
485  Set & malloc omega grid
486  */
487  Nomega = X->Bind.Def.iNOmega;
488  dcomega = cd_1d_allocate(Nomega);
489  OmegaMax = X->Bind.Def.dcOmegaMax + X->Bind.Def.dcOmegaOrg;
490  OmegaMin = X->Bind.Def.dcOmegaMin + X->Bind.Def.dcOmegaOrg;
491  for (i = 0; i < Nomega; i++) {
492  dcomega[i] = OmegaMin
493  + (OmegaMax - OmegaMin) / (std::complex<double>)Nomega * (std::complex<double>)i;
494  }
495 
496  fprintf(stdoutMPI, "\nFrequency range:\n");
497  fprintf(stdoutMPI, " Omega Max. : %15.5e %15.5e\n", real(OmegaMax), imag(OmegaMax));
498  fprintf(stdoutMPI, " Omega Min. : %15.5e %15.5e\n", real(OmegaMin), imag(OmegaMin));
499  fprintf(stdoutMPI, " Num. of Omega : %d\n", Nomega);
500 
501  if (X->Bind.Def.NNSingleExcitationOperator == 0) {
502  if (X->Bind.Def.NNPairExcitationOperator == 0) {
503  fprintf(stderr, "Error: Any excitation operators are not defined.\n");
504  exitMPI(-1);
505  }
506  else {
507  NdcSpectrum = X->Bind.Def.NNPairExcitationOperator - 1;
508  }
509  }
510  else if (X->Bind.Def.NNPairExcitationOperator == 0) {
511  NdcSpectrum = X->Bind.Def.NNSingleExcitationOperator - 1;
512  }
513  else {
514  fprintf(stderr, "Error: Both single and pair excitation operators exist.\n");
515  exitMPI(-1);
516  }
517  dcSpectrum = cd_2d_allocate(Nomega, NdcSpectrum);
518 
519  //Make New Lists
520  if (MakeExcitedList(&(X->Bind), &iFlagListModified) == FALSE) {
521  return FALSE;
522  }
523  X->Bind.Def.iFlagListModified = iFlagListModified;
524 
525  //Make excited state
526  StartTimer(6100);
527  if (X->Bind.Def.iFlgCalcSpec == RECALC_NOT ||
528  X->Bind.Def.iFlgCalcSpec == RECALC_OUTPUT_TMComponents_VEC ||
529  (X->Bind.Def.iFlgCalcSpec == RECALC_INOUT_TMComponents_VEC && X->Bind.Def.iCalcType == CG)) {
530  v1Org = cd_2d_allocate(X->Bind.Check.idim_maxOrg + 1, 1);
531  //input eigen vector
532  StartTimer(6101);
533  fprintf(stdoutMPI, " Start: An Eigenvector is inputted in CalcSpectrum.\n");
534  TimeKeeper(&(X->Bind), "%s_TimeKeeper.dat", "Reading an input Eigenvector starts: %s", "a");
535  GetFileNameByKW(KWSpectrumVec, &defname);
536  strcat(defname, "_rank_%d.dat");
537  // sprintf(sdt, "%s_eigenvec_%d_rank_%d.dat", X->Bind.Def.CDataFileHead, X->Bind.Def.k_exct - 1, myrank);
538  sprintf(sdt, defname, myrank);
539  childfopenALL(sdt, "rb", &fp);
540 
541  if (fp == NULL) {
542  fprintf(stderr, "Error: A file of Inputvector does not exist.\n");
543  return -1;
544  }
545 
546  byte_size = fread(&i_stp, sizeof(i_stp), 1, fp);
547  X->Bind.Large.itr = i_stp; //For TPQ
548  byte_size = fread(&i_max, sizeof(i_max), 1, fp);
549  if (i_max != X->Bind.Check.idim_maxOrg) {
550  fprintf(stderr, "Error: myrank=%d, i_max=%ld\n", myrank, i_max);
551  fprintf(stderr, "Error: A file of Input vector is incorrect.\n");
552  return -1;
553  }
554  byte_size = fread(&v1Org[0][0], sizeof(std::complex<double>), i_max + 1, fp);
555  fclose(fp);
556  StopTimer(6101);
557  if (byte_size == 0) printf("byte_size: %d \n", (int)byte_size);
558  }
559  StopTimer(6100);
560 
561  diagonalcalc(&(X->Bind));
562 
563  int iret = TRUE;
564  fprintf(stdoutMPI, " Start: Calculating a spectrum.\n\n");
565  TimeKeeper(&(X->Bind), "%s_TimeKeeper.dat", "Calculating a spectrum starts: %s", "a");
566  StartTimer(6200);
567  switch (X->Bind.Def.iCalcType) {
568  case CG:
569  iret = CalcSpectrumByBiCG(X, v0, v1, Nomega, NdcSpectrum, dcSpectrum, dcomega, v1Org);
570  if (iret != TRUE) {
571  return FALSE;
572  }
573  break;
574  case FullDiag:
575  iret = CalcSpectrumByFullDiag(X, Nomega, NdcSpectrum, dcSpectrum, dcomega, v1Org);
576  break;
577  default:
578  break;
579  }
580  StopTimer(6200);
581 
582  if (iret != TRUE) {
583  fprintf(stderr, " Error: The selected calculation type is not supported for calculating spectrum mode.\n");
584  return FALSE;
585  }
586 
587  fprintf(stdoutMPI, " End: Calculating a spectrum.\n\n");
588  TimeKeeper(&(X->Bind), "%s_TimeKeeper.dat", "Calculating a spectrum finishes: %s", "a");
589  iret = OutputSpectrum(X, Nomega, NdcSpectrum, dcSpectrum, dcomega);
590  free_cd_2d_allocate(dcSpectrum);
591  free_cd_1d_allocate(dcomega);
592  return TRUE;
593 
594 }/*int CalcSpectrum*/
double * doublon
Expectation value of the Doublon.
Definition: struct.hpp:357
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.cpp:86
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int NeMPI
Total number of electrons across process. Differ from DefineList::Ne .
Definition: struct.hpp:72
double * num_down
Expectation value of the number of down-spin electtrons.
Definition: struct.hpp:364
int CalcSpectrumByFullDiag(struct EDMainCalStruct *X, int Nomega, int NdcSpectrum, std::complex< double > **dcSpectrum, std::complex< double > *dcomega, std::complex< double > **v1Org)
Compute the Green function with the Lehmann representation and FD .
double * var
Expectation value of the Energy variance.
Definition: struct.hpp:367
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
long int * list_2_1
Definition: global.cpp:27
long int * list_2_2
Definition: global.cpp:28
int NupMPI
Total number of spin-up electrons across processes. Deffer from DefineList::Nup. Read from modpara in...
Definition: struct.hpp:60
int childfopenALL(const char *_cPathChild, const char *_cmode, FILE **_fp)
All processes open file in output/ directory.
Definition: FileIO.cpp:50
int itr
Iteration number.
Definition: struct.hpp:316
std::complex< double > ** v1buf
Definition: global.cpp:22
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 Total2Sz
Total in this process.
Definition: struct.hpp:69
int iFlagListModified
When the Hilbert space of excited state differs from the original one.
Definition: struct.hpp:219
std::complex< double > dcOmegaMin
Lower limit of the frequency for the spectrum.
Definition: struct.hpp:212
double * s2
Expectation value of the square of the total S.
Definition: struct.hpp:365
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
long int idim_maxOrg
The local Hilbert-space dimention of original state for the spectrum.
Definition: struct.hpp:307
std::complex< double > I(0.0, 1.0)
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.hpp:397
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
int SetOmega(struct DefineList *X)
Set target frequencies.
int diagonalcalc(struct BindStruct *X)
Calculate diagonal components and obtain the list, list_diagonal.
double * Sz
Expectation value of the Total Sz.
Definition: struct.hpp:361
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)...
long int * list_1buf
Definition: global.cpp:26
int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.hpp:57
int NNSingleExcitationOperator
Number of single excitaion operator for spectrum.
Definition: struct.hpp:182
std::complex< double > dcOmegaOrg
Origin limit of the frequency for the spectrum.
Definition: struct.hpp:213
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
double * num
Expectation value of the Number of electrons.
Definition: struct.hpp:359
double * energy
Expectation value of the total energy.
Definition: struct.hpp:356
int myrank
Process ID, defined in InitializeMPI()
Definition: global.cpp:73
int iNOmega
Number of frequencies for spectrum.
Definition: struct.hpp:214
std::complex< double > dcOmegaMax
Upper limit of the frequency for the spectrum.
Definition: struct.hpp:211
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.cpp:83
int iFlgSpecOmegaOrg
Whether DefineList::dcOmegaOrg is input or not.
Definition: struct.hpp:217
double * list_Diagonal
Definition: global.cpp:24
double * doublon2
Expectation value of the Square of doublon.
Definition: struct.hpp:358
int OutputSpectrum(struct EDMainCalStruct *X, int Nomega, int NdcSpectrum, std::complex< double > **dcSpectrum, std::complex< double > *dcomega)
Output spectrum.
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
double * num_up
Expectation value of the number of up-spin electtrons.
Definition: struct.hpp:363
int GetlistSize(struct BindStruct *X)
Set size of lists for the canonical ensemble.
Definition: xsetmem.cpp:220
int NdownMPI
Total number of spin-down electrons across processes. Deffer from DefineList::Ndown. Read from modpara in readdef.h.
Definition: struct.hpp:62
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.hpp:218
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
int CalcSpectrumByBiCG(struct EDMainCalStruct *X, std::complex< double > **v2, std::complex< double > **v4, int Nomega, int NdcSpectrum, std::complex< double > **dcSpectrum, std::complex< double > *dcomega, std::complex< double > **v1Org)
A main function to calculate spectrum by BiCG method In this function, the library is used...
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
int NNPairExcitationOperator
Number of pair excitaion operator for spectrum.
Definition: struct.hpp:189
long int * list_1
Definition: global.cpp:25
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 Total2SzMPI
Total across processes.
Definition: struct.hpp:70
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.hpp:194
void StartTimer(int n)
function for initializing elapse time [start]
Definition: time.cpp:71

◆ GetExcitedState()

int GetExcitedState ( struct BindStruct X,
int  nstate,
std::complex< double > **  tmp_v0,
std::complex< double > **  tmp_v1,
int  iEx 
)

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 387 of file CalcSpectrum.cpp.

References BindStruct::Def, GetPairExcitedState(), GetSingleExcitedState(), DefineList::NNPairExcitationOperator, and DefineList::NNSingleExcitationOperator.

Referenced by CalcSpectrumByBiCG(), CalcSpectrumByFullDiag(), and OutputSpectrum().

394 {
395  if (X->Def.NNSingleExcitationOperator > 0) {
396  if (GetSingleExcitedState(X, nstate, tmp_v0, tmp_v1, iEx) != TRUE) {
397  return FALSE;
398  }
399  }
400  else if (X->Def.NNPairExcitationOperator > 0) {
401  if (GetPairExcitedState(X, nstate, tmp_v0, tmp_v1, iEx) != TRUE) {
402  return FALSE;
403  }
404  }
405  return TRUE;
406 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int GetPairExcitedState(struct BindStruct *X, int nstate, std::complex< double > **tmp_v0, std::complex< double > **tmp_v1, int iEx)
Calculating the pair excited state by the pair operator; , where indicates a creation (anti-creat...
Definition: PairEx.cpp:47
int NNSingleExcitationOperator
Number of single excitaion operator for spectrum.
Definition: struct.hpp:182
int GetSingleExcitedState(struct BindStruct *X, int nstate, std::complex< double > **tmp_v0, std::complex< double > **tmp_v1, int iEx)
Calculation of single excited state Target System: Hubbard, Kondo.
Definition: SingleEx.cpp:30
int NNPairExcitationOperator
Number of pair excitaion operator for spectrum.
Definition: struct.hpp:189

◆ 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 132 of file CalcSpectrum.cpp.

References check(), BindStruct::Check, BindStruct::Def, exitMPI(), FinalizeMPI(), GetlistSize(), DefineList::iCalcModel, CheckList::idim_max, CheckList::idim_maxMPI, CheckList::idim_maxMPIOrg, CheckList::idim_maxOrg, 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, MaxMPI_li(), myrank, DefineList::Ndown, DefineList::NdownOrg, DefineList::Ne, DefineList::NeMPI, DefineList::NNPairExcitationOperator, DefineList::NNSingleExcitationOperator, 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 v1buf.

Referenced by CalcSpectrum().

135  {
136  long int j;
137  *iFlgListModifed = FALSE;
138  //To Get Original space
139  if (check(X) == MPIFALSE) {
140  FinalizeMPI();
141  return -1;
142  }
143 
146 
147  if (X->Def.NNSingleExcitationOperator > 0) {
148  switch (X->Def.iCalcModel) {
149  case HubbardGC:
150  break;
151  case HubbardNConserved:
152  case KondoGC:
153  case Hubbard:
154  case Kondo:
155  *iFlgListModifed = TRUE;
156  break;
157  case Spin:
158  case SpinGC:
159  return FALSE;
160  }
161  }
162  else if (X->Def.NNPairExcitationOperator > 0) {
163  switch (X->Def.iCalcModel) {
164  case HubbardGC:
165  case SpinGC:
166  case HubbardNConserved:
167  break;
168  case KondoGC:
169  case Hubbard:
170  case Kondo:
171  case Spin:
172  if (X->Def.PairExcitationOperator[0][0][1] != X->Def.PairExcitationOperator[0][0][3]) {
173  *iFlgListModifed = TRUE;
174  }
175  break;
176  }
177  }
178  else {
179  return FALSE;
180  }
181 
182  if (*iFlgListModifed == TRUE) {
183  if (GetlistSize(X) == TRUE) {
184  list_1_org = li_1d_allocate(X->Check.idim_max + 1);
185 #ifdef __MPI
186  long int MAXidim_max;
187  MAXidim_max = MaxMPI_li(X->Check.idim_max);
188  list_1buf_org = li_1d_allocate(MAXidim_max + 1);
189 #endif // MPI
190  list_2_1_org = li_1d_allocate(X->Large.SizeOflist_2_1);
191  list_2_2_org = li_1d_allocate(X->Large.SizeOflist_2_2);
192  if (list_1_org == NULL
193  || list_2_1_org == NULL
194  || list_2_2_org == NULL
195  )
196  {
197  return -1;
198  }
199  for (j = 0; j < X->Large.SizeOflist_2_1; j++) {
200  list_2_1_org[j] = 0;
201  }
202  for (j = 0; j < X->Large.SizeOflist_2_2; j++) {
203  list_2_2_org[j] = 0;
204  }
205 
206  }
207 
208  if (sz(X, list_1_org, list_2_1_org, list_2_2_org) != 0) {
209  return FALSE;
210  }
211 
212  if (X->Def.NNSingleExcitationOperator > 0) {
213  switch (X->Def.iCalcModel) {
214  case HubbardGC:
215  break;
216  case HubbardNConserved:
217  if (X->Def.SingleExcitationOperator[0][0][2] == 1) { //cis
218  X->Def.Ne = X->Def.NeMPI + 1;
219  }
220  else {
221  X->Def.Ne = X->Def.NeMPI - 1;
222  }
223  break;
224  case KondoGC:
225  case Hubbard:
226  case Kondo:
227  if (X->Def.SingleExcitationOperator[0][0][2] == 1) { //cis
228  X->Def.Ne = X->Def.NeMPI + 1;
229  if (X->Def.SingleExcitationOperator[0][0][1] == 0) {//up
230  X->Def.Nup = X->Def.NupOrg + 1;
231  X->Def.Ndown = X->Def.NdownOrg;
232  }
233  else {//down
234  X->Def.Nup = X->Def.NupOrg;
235  X->Def.Ndown = X->Def.NdownOrg + 1;
236  }
237  }
238  else {//ajt
239  X->Def.Ne = X->Def.NeMPI - 1;
240  if (X->Def.SingleExcitationOperator[0][0][1] == 0) {//up
241  X->Def.Nup = X->Def.NupOrg - 1;
242  X->Def.Ndown = X->Def.NdownOrg;
243 
244  }
245  else {//down
246  X->Def.Nup = X->Def.NupOrg;
247  X->Def.Ndown = X->Def.NdownOrg - 1;
248  }
249  }
250  break;
251  case Spin:
252  case SpinGC:
253  return FALSE;
254  }
255  }
256  else if (X->Def.NNPairExcitationOperator > 0) {
257  X->Def.Ne = X->Def.NeMPI;
258  switch (X->Def.iCalcModel) {
259  case HubbardGC:
260  case SpinGC:
261  case HubbardNConserved:
262  break;
263  case KondoGC:
264  case Hubbard:
265  case Kondo:
266  if (X->Def.PairExcitationOperator[0][0][1] != X->Def.PairExcitationOperator[0][0][3]) {
267  if (X->Def.PairExcitationOperator[0][0][1] == 0) {//up
268  X->Def.Nup = X->Def.NupOrg + 1;
269  X->Def.Ndown = X->Def.NdownOrg - 1;
270  }
271  else {//down
272  X->Def.Nup = X->Def.NupOrg - 1;
273  X->Def.Ndown = X->Def.NdownOrg + 1;
274  }
275  }
276  break;
277  case Spin:
278  if (X->Def.PairExcitationOperator[0][0][1] != X->Def.PairExcitationOperator[0][0][3]) {
279  if (X->Def.iFlgGeneralSpin == FALSE) {
280  if (X->Def.PairExcitationOperator[0][0][1] == 0) {//down
281  X->Def.Nup = X->Def.NupOrg - 1;
282  X->Def.Ndown = X->Def.NdownOrg + 1;
283  }
284  else {//up
285  X->Def.Nup = X->Def.NupOrg + 1;
286  X->Def.Ndown = X->Def.NdownOrg - 1;
287  }
288  }
289  else {//for general spin
290  X->Def.Total2Sz = X->Def.Total2SzMPI + 2 * (X->Def.PairExcitationOperator[0][0][1] - X->Def.PairExcitationOperator[0][0][3]);
291  }
292  }
293  break;
294  }
295  }
296  else {
297  return FALSE;
298  }
299  //Update Infomation
300  X->Def.Nsite = X->Def.NsiteMPI;
301 
302  if (check(X) == MPIFALSE) {
303  FinalizeMPI();
304  return FALSE;
305  }
306  }
307 
308  //set memory
309  if (setmem_large(X) != 0) {
310  fprintf(stdoutMPI, "Error: Fail for memory allocation.\n");
311  exitMPI(-1);
312  }
313  if (sz(X, list_1, list_2_1, list_2_2) != 0) {
314  return FALSE;
315  }
316 #ifdef __MPI
317  long int MAXidim_max, MAXidim_maxOrg;
318  MAXidim_max = MaxMPI_li(X->Check.idim_max);
319  MAXidim_maxOrg = MaxMPI_li(X->Check.idim_maxOrg);
320  if (MAXidim_max < MAXidim_maxOrg) {
321  free_cd_2d_allocate(v1buf);
322  v1buf = cd_2d_allocate(MAXidim_maxOrg + 1, 1);
323  }
324 #endif // MPI
325 
326  if (X->Def.iCalcModel == HubbardNConserved) {
327  X->Def.iCalcModel = Hubbard;
328  }
329 
330 #ifdef _DEBUG
331  if (*iFlgListModifed == TRUE) {
332  for (j = 1; j <= X->Check.idim_maxOrg; j++) {
333  fprintf(stdout, "Debug1: myrank=%d, list_1_org[ %ld] = %ld\n",
334  myrank, j, list_1_org[j] + myrank * X->Def.OrgTpow[2 * X->Def.NsiteMPI - 1]);
335  }
336 
337  for (j = 1; j <= X->Check.idim_max; j++) {
338  fprintf(stdout, "Debug2: myrank=%d, list_1[ %ld] = %ld\n", myrank, j, list_1[j] + myrank * 64);
339  }
340  }
341 #endif
342  return TRUE;
343 }
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.cpp:86
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
long int idim_maxMPIOrg
The global Hilbert-space dimention of original state for the spectrum.
Definition: struct.hpp:308
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int NeMPI
Total number of electrons across process. Differ from DefineList::Ne .
Definition: struct.hpp:72
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
long int * list_2_1
Definition: global.cpp:27
long int * list_2_2
Definition: global.cpp:28
long int * OrgTpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:92
std::complex< double > ** v1buf
Definition: global.cpp:22
void FinalizeMPI()
MPI Finitialization wrapper.
Definition: wrapperMPI.cpp:74
int Total2Sz
Total in this process.
Definition: struct.hpp:69
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
long int idim_maxOrg
The local Hilbert-space dimention of original state for the spectrum.
Definition: struct.hpp:307
long int idim_maxMPI
The total dimension across process.
Definition: struct.hpp:306
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.hpp:397
long int SizeOflist_2_1
Size of list_2_1.
Definition: struct.hpp:319
long int MaxMPI_li(long int idim)
MPI wrapper function to obtain maximum unsigned long integer across processes.
Definition: wrapperMPI.cpp:171
long int * list_1_org
Definition: global.cpp:31
int sz(struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_)
generating Hilbert space
Definition: sz.cpp:908
int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.hpp:57
int NNSingleExcitationOperator
Number of single excitaion operator for spectrum.
Definition: struct.hpp:182
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
int NdownOrg
Number of spin-down electrons before exitation. Used only in the spectrum calculation. Read from modpara in readdef.h.
Definition: struct.hpp:66
long int * list_2_2_org
Definition: global.cpp:34
int myrank
Process ID, defined in InitializeMPI()
Definition: global.cpp:73
long int * list_2_1_org
Definition: global.cpp:33
int iFlgGeneralSpin
Flag for the general (Sz/=1/2) spin.
Definition: struct.hpp:86
int check(struct BindStruct *X)
A program to check size of dimension for Hilbert-space.
Definition: check.cpp:51
long int * list_1buf_org
Definition: global.cpp:32
int setmem_large(struct BindStruct *X)
Set size of memories for 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.cpp:154
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.hpp:200
int GetlistSize(struct BindStruct *X)
Set size of lists for the canonical ensemble.
Definition: xsetmem.cpp:220
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
int NupOrg
Number of spin-up electrons before exitation. Used only in the spectrum calculation. Read from modpara in readdef.h.
Definition: struct.hpp:64
int NNPairExcitationOperator
Number of pair excitaion operator for spectrum.
Definition: struct.hpp:189
int *** SingleExcitationOperator
[DefineList::NSingleExcitationOperator][3] Indices of single excitaion operator for spectrum...
Definition: struct.hpp:180
long int * list_1
Definition: global.cpp:25
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305
long int SizeOflist_2_2
Size of list_2_2.
Definition: struct.hpp:320
int *** PairExcitationOperator
[DefineList::NPairExcitationOperator][5] Indices of pair excitaion operator for spectrum. malloc in setmem_def().
Definition: struct.hpp:187
int Total2SzMPI
Total across processes.
Definition: struct.hpp:70

◆ OutputSpectrum()

int OutputSpectrum ( struct EDMainCalStruct X,
int  Nomega,
int  NdcSpectrum,
std::complex< double > **  dcSpectrum,
std::complex< double > *  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 351 of file CalcSpectrum.cpp.

References EDMainCalStruct::Bind, DefineList::CDataFileHead, childfopenMPI(), DefineList::dcOmegaOrg, BindStruct::Def, and GetExcitedState().

Referenced by CalcSpectrum().

357 {
358  FILE *fp;
359  char sdt[D_FileNameMax];
360  int iomega, idcSpectrum;
361 
362  //output spectrum
363  sprintf(sdt, "%s_DynamicalGreen.dat", X->Bind.Def.CDataFileHead);
364  if (childfopenMPI(sdt, "w", &fp) != 0) {
365  return FALSE;
366  }
367 
368  for (idcSpectrum = 0; idcSpectrum < NdcSpectrum; idcSpectrum++) {
369  for (iomega = 0; iomega < Nomega; iomega++) {
370  fprintf(fp, "%.10lf %.10lf %.10lf %.10lf \n",
371  real(dcomega[iomega] - X->Bind.Def.dcOmegaOrg), imag(dcomega[iomega] - X->Bind.Def.dcOmegaOrg),
372  real(dcSpectrum[iomega][idcSpectrum]), imag(dcSpectrum[iomega][idcSpectrum]));
373  }/*for (i = 0; i < Nomega; i++)*/
374  fprintf(fp, "\n");
375  }
376 
377  fclose(fp);
378  return TRUE;
379 }/*int OutputSpectrum*/
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
std::complex< double > dcOmegaOrg
Origin limit of the frequency for the spectrum.
Definition: struct.hpp:213
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.hpp:42
struct BindStruct Bind
Binded struct.
Definition: struct.hpp:405
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27

◆ 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 49 of file CalcSpectrum.cpp.

References DefineList::CDataFileHead, childfopenMPI(), DefineList::dcOmegaMax, DefineList::dcOmegaMin, fgetsMPI(), DefineList::iCalcType, DefineList::iFlgSpecOmegaMax, DefineList::iFlgSpecOmegaMin, LargeValue, DefineList::Nsite, and stdoutMPI.

Referenced by CalcSpectrum().

51  {
52  FILE *fp;
53  char sdt[D_FileNameMax], ctmp[256];
54  int istp = 4;
55  double E1, E2, E3, E4, Emax;
56  long int iline_countMax = 2;
57  long int iline_count = 2;
58 
59 
60  if (X->iFlgSpecOmegaMax == TRUE && X->iFlgSpecOmegaMin == TRUE) {
61  return TRUE;
62  }
63  else {
64  if (X->iCalcType == Lanczos || X->iCalcType == FullDiag) {
65  sprintf(sdt, "%s_Lanczos_Step.dat", X->CDataFileHead);
66  childfopenMPI(sdt, "r", &fp);
67  if (fp == NULL) {
68  fprintf(stdoutMPI, "Error: xx_Lanczos_Step.dat does not exist.\n");
69  return FALSE;
70  }
71  fgetsMPI(ctmp, 256, fp); //1st line is skipped
72  fgetsMPI(ctmp, 256, fp); //2nd line is skipped
73  while (fgetsMPI(ctmp, 256, fp) != NULL) {
74  iline_count++;
75  }
76  iline_countMax = iline_count;
77  iline_count = 2;
78  rewind(fp);
79  fgetsMPI(ctmp, 256, fp); //1st line is skipped
80  fgetsMPI(ctmp, 256, fp); //2nd line is skipped
81 
82  while (fgetsMPI(ctmp, 256, fp) != NULL) {
83  sscanf(ctmp, "stp=%d %lf %lf %lf %lf %lf\n",
84  &istp,
85  &E1,
86  &E2,
87  &E3,
88  &E4,
89  &Emax);
90  iline_count++;
91  if (iline_count == iline_countMax) break;
92  }
93  fclose(fp);
94  if (istp < 4) {
95  fprintf(stdoutMPI, "Error: Lanczos step must be greater than 4 for using spectrum calculation.\n");
96  return FALSE;
97  }
98  }/*if (X->iCalcType == Lanczos || X->iCalcType == FullDiag)*/
99  else
100  {
101  sprintf(sdt, "%s_energy.dat", X->CDataFileHead);
102  childfopenMPI(sdt, "r", &fp);
103  if (fp == NULL) {
104  fprintf(stdoutMPI, "Error: xx_energy.dat does not exist.\n");
105  return FALSE;
106  }/*if (fp == NULL)*/
107  fgetsMPI(ctmp, 256, fp); //1st line is skipped
108  fgetsMPI(ctmp, 256, fp); //1st line is skipped
109  sscanf(ctmp, " Energy %lf \n", &E1);
110  Emax = LargeValue;
111  }
112  //Read Lanczos_Step
113  if (X->iFlgSpecOmegaMax == FALSE) {
114  X->dcOmegaMax = Emax * (double)X->Nsite;
115  }
116  if (X->iFlgSpecOmegaMin == FALSE) {
117  X->dcOmegaMin = E1;
118  }
119  }/*Omegamax and omegamin is not specified in modpara*/
120 
121  return TRUE;
122 }
int iFlgSpecOmegaMin
Whether DefineList::dcOmegaMin is input or not.
Definition: struct.hpp:216
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
std::complex< double > dcOmegaMin
Lower limit of the frequency for the spectrum.
Definition: struct.hpp:212
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
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.cpp:122
double LargeValue
Definition: global.cpp:42
std::complex< double > dcOmegaMax
Upper limit of the frequency for the spectrum.
Definition: struct.hpp:211
int iFlgSpecOmegaMax
Whether DefineList::dcOmegaMax is input or not.
Definition: struct.hpp:215
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.hpp:42
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.hpp:194
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27