You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LiebLin_Fourier_to_x_equal_t.cc 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: LiebLin_Fourier_to_x_equal_t.cc
  6. Purpose: Fourier transform to static space correlator for LiebLin.
  7. ***********************************************************/
  8. #include "ABACUS.h"
  9. using namespace std;
  10. using namespace ABACUS;
  11. int main(int argc, char* argv[])
  12. {
  13. if (argc != 9) { // provide some info
  14. cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
  15. cout << endl << "Usage of LiebLin_Fourier_to_x_equal_t executable: " << endl;
  16. cout << endl << "Provide the following arguments:" << endl << endl;
  17. cout << "char whichDSF \t\t Which structure factor ? Options are: d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
  18. cout << "DP c_int \t\t Value of the interaction parameter" << endl;
  19. cout << "DP L \t\t\t Length of the system" << endl;
  20. cout << "int N \t\t\t Number of particles" << endl;
  21. cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers scanned over" << endl;
  22. cout << "DP kBT \t\t Temperature" << endl;
  23. cout << "int Npts_x Number of points in space for the Fourier transform" << endl;
  24. }
  25. else { // (argc == 9), correct nr of arguments
  26. char whichDSF = *argv[1];
  27. DP c_int = atof(argv[2]);
  28. DP L = atof(argv[3]);
  29. int N = atoi(argv[4]);
  30. int iKmin = atoi(argv[5]);
  31. int iKmax = atoi(argv[6]);
  32. DP kBT = atof(argv[7]);
  33. int Npts_x = atoi(argv[8]);
  34. // Force Npts_x
  35. //Npts_x = L;
  36. stringstream filenameprefix;
  37. Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
  38. string prefix = filenameprefix.str();
  39. stringstream RAW_stringstream; string RAW_string;
  40. RAW_stringstream << prefix << ".raw";
  41. RAW_string = RAW_stringstream.str(); const char* RAW_Cstr = RAW_string.c_str();
  42. ifstream RAW_infile;
  43. RAW_infile.open(RAW_Cstr);
  44. if (RAW_infile.fail()) {
  45. cout << RAW_Cstr << endl;
  46. ABACUSerror("Could not open RAW_infile... ");
  47. }
  48. // We also read the f-sumrule file, to correct for missing intensity.
  49. stringstream FSR_stringstream; string FSR_string;
  50. FSR_stringstream << prefix << ".fsr";
  51. FSR_string = FSR_stringstream.str(); const char* FSR_Cstr = FSR_string.c_str();
  52. ifstream FSR_infile;
  53. FSR_infile.open(FSR_Cstr);
  54. if (FSR_infile.fail()) {
  55. cout << FSR_Cstr << endl;
  56. ABACUSerror("Could not open FSR_infile... ");
  57. }
  58. stringstream SFT_stringstream; string SFT_string;
  59. SFT_stringstream << prefix << ".sft";
  60. SFT_string = SFT_stringstream.str(); const char* SFT_Cstr = SFT_string.c_str();
  61. ofstream SFT_outfile;
  62. SFT_outfile.open(SFT_Cstr);
  63. if (SFT_outfile.fail()) ABACUSerror("Could not open SFT_outfile... ");
  64. // First compute the static structure factor from the RAW data:
  65. Vect_DP SSF(0.0, iKmax - iKmin + 1);
  66. DP omega;
  67. int iK;
  68. DP FF;
  69. //int conv;
  70. DP dev;
  71. string label;
  72. while (RAW_infile.peek() != EOF) {
  73. RAW_infile >> omega >> iK >> FF >> dev >> label;
  74. if (iK >= iKmin && iK <= iKmax) {
  75. SSF[iK - iKmin] += FF * FF;
  76. }
  77. }
  78. RAW_infile.close();
  79. // Reset proper normalization:
  80. DP normalization = twoPI * L;
  81. for (int iK = 0; iK < iKmax - iKmin + 1; ++iK) SSF[iK] *= normalization/twoPI; // twoPI from integral over omega
  82. // We now refine the SSF in the following way.
  83. // First, we read off the f-sumrule saturation from the FSR file.
  84. // Then, we put back the missing weight, assuming that it lives
  85. // on the free k^2 dispersion relation (so the DSF is then simply 2\pi N/L \delta(\omega - k^2)).
  86. Vect_DP FSRsaturated(0.0, iKmax - iKmin + 1);
  87. int dummyint;
  88. DP dummy;
  89. for (int i = iKmin; i <= iKmax; ++i)
  90. FSR_infile >> dummyint >> FSRsaturated[i - iKmin] >> dummy;
  91. FSR_infile.close();
  92. // Now correct the SSF by the missing piece:
  93. //for (int iK = iKmin; iK <= iKmax; ++iK)
  94. //SSF[iK - iKmin] += (1.0 - FSRsaturated[iK - iKmin]) * N/L;
  95. //cout << FSRsaturated << endl;
  96. //cout << SSF << endl;
  97. // Now define real-space coordinates: between 0 and L
  98. Vect_DP xlattice(Npts_x);
  99. for (int i = 0; i < Npts_x; ++i) xlattice[i] = (i + 0.5) * L/Npts_x;
  100. // Now the correlation at x:
  101. Vect_DP FTre(0.0, Npts_x);
  102. Vect_DP FTim(0.0, Npts_x);
  103. DP twopioverL = twoPI/L;
  104. // Fourier transform:
  105. for (int ix = 0; ix < Npts_x; ++ix) {
  106. for (int iK = iKmin; iK <= iKmax; ++iK) {
  107. FTre[ix] += SSF[iK - iKmin] * cos(twopioverL * iK * xlattice[ix]);
  108. FTim[ix] += SSF[iK - iKmin] * sin(twopioverL * iK * xlattice[ix]);
  109. }
  110. // Reset proper normalization: 1/L from space FT,
  111. FTre[ix] /= L;
  112. FTim[ix] /= L;
  113. // Outside of window iKmin, iKmax, we take the DSF to be a constant with delta function
  114. // at free energy k^2, so DSF = 2\pi N/L \delta(\omega - k^2) (to fit f-sumrule)
  115. // so SSF becomes N/L.
  116. // We thus need to correct above by adding
  117. // \frac{1}{L} \sum_{-\infty}^{iKmin - 1} SSF e^{ikx} + \frac{1}{L} \sum_{iKmax + 1}^\infty SSF e^{ikx}
  118. // Resumming carefully:
  119. if (whichDSF == 'd') {
  120. FTre[ix] += (sin(twopioverL * (iKmin - 0.5) * xlattice[ix]) - sin(twopioverL * (iKmax + 0.5) * xlattice[ix]))
  121. * N/(2.0 * L*L * sin(PI * xlattice[ix]/L));
  122. FTim[ix] += (-cos(twopioverL * (iKmin - 0.5) * xlattice[ix]) + cos(twopioverL * (iKmax + 0.5) * xlattice[ix]))
  123. * N/(2.0 * L*L * sin(PI * xlattice[ix]/L));
  124. }
  125. }
  126. // Since iKmax and iKmin are finite, we need to average over an interval of
  127. // deltax such that (2\pi/L) iKmax deltax = 2\pi, with deltax == deltaix * L/Npts_x
  128. // so deltaix = (Npts_x/L) * (L/iKmax)
  129. /*
  130. int deltaix = 0*int(Npts_x/(2.0*iKmax));
  131. cout << "deltaix = " << deltaix << endl;
  132. Vect_DP FTreavg(0.0, Npts_x);
  133. Vect_DP FTimavg(0.0, Npts_x);
  134. for (int ix = 0; ix < Npts_x; ++ix) {
  135. for (int ix2 = -deltaix; ix2 < deltaix; ++ix2) {
  136. FTreavg[ix] += FTre[ABACUS::min(ABACUS::max(0, ix + ix2), Npts_x - 1)];
  137. FTimavg[ix] += FTim[ABACUS::min(ABACUS::max(0, ix + ix2), Npts_x - 1)];
  138. }
  139. FTreavg[ix] /= (2*deltaix + 1);
  140. FTimavg[ix] /= (2*deltaix + 1);
  141. }
  142. */
  143. if (whichDSF == 'd') cout << "g2(0) = dE0_dc/L = " << LiebLin_dE0_dc (c_int, L, N)/L << "\t" << LiebLin_dE0_dc (c_int, 2.0*L, 2*N)/(2.0*L) << endl;
  144. // Output to file:
  145. for (int ix = 0; ix < Npts_x; ++ix) {
  146. if (ix > 0) SFT_outfile << endl;
  147. //SFT_outfile << xlattice[ix] << "\t" << FTre[ix] << "\t" << FTim[ix] << "\t" << FTreavg[ix] << "\t" << FTimavg[ix];
  148. SFT_outfile << xlattice[ix] << "\t" << FTre[ix] << "\t" << FTim[ix];
  149. }
  150. SFT_outfile.close();
  151. }
  152. return(0);
  153. }