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_ssf_to_Qsqx.cc 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_Qsqx.cc
  6. Purpose: Compute the Q(x)^2 expectation value for LiebLin, where Q(x) = \int_0^x dx \rho(x).
  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_Qsqx 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. if (whichDSF != 'd') ABACUSerror("Must use whichDSF == d in LiebLin_Fourier_ssf_to_Qsqx");
  37. stringstream filenameprefix;
  38. Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
  39. string prefix = filenameprefix.str();
  40. stringstream RAW_stringstream; string RAW_string;
  41. RAW_stringstream << prefix << ".raw";
  42. RAW_string = RAW_stringstream.str(); const char* RAW_Cstr = RAW_string.c_str();
  43. ifstream RAW_infile;
  44. RAW_infile.open(RAW_Cstr);
  45. if (RAW_infile.fail()) {
  46. cout << RAW_Cstr << endl;
  47. ABACUSerror("Could not open RAW_infile... ");
  48. }
  49. // We also read the f-sumrule file, to correct for missing intensity.
  50. stringstream FSR_stringstream; string FSR_string;
  51. FSR_stringstream << prefix << ".fsr";
  52. FSR_string = FSR_stringstream.str(); const char* FSR_Cstr = FSR_string.c_str();
  53. ifstream FSR_infile;
  54. FSR_infile.open(FSR_Cstr);
  55. if (FSR_infile.fail()) {
  56. cout << FSR_Cstr << endl;
  57. ABACUSerror("Could not open FSR_infile... ");
  58. }
  59. stringstream SFT_stringstream; string SFT_string;
  60. SFT_stringstream << prefix << ".Qsqx";
  61. SFT_string = SFT_stringstream.str(); const char* SFT_Cstr = SFT_string.c_str();
  62. ofstream SFT_outfile;
  63. SFT_outfile.open(SFT_Cstr);
  64. if (SFT_outfile.fail()) ABACUSerror("Could not open SFT_outfile... ");
  65. // First compute the static structure factor from the RAW data:
  66. Vect_DP SSF(0.0, iKmax - iKmin + 1);
  67. DP omega;
  68. int iK;
  69. DP FF;
  70. //int conv;
  71. DP dev;
  72. string label;
  73. while (RAW_infile.peek() != EOF) {
  74. RAW_infile >> omega >> iK >> FF >> dev >> label;
  75. if (iK >= iKmin && iK <= iKmax) {
  76. SSF[iK - iKmin] += FF * FF;
  77. }
  78. }
  79. RAW_infile.close();
  80. // Reset proper normalization:
  81. DP normalization = twoPI * L;
  82. for (int iK = 0; iK < iKmax - iKmin + 1; ++iK) SSF[iK] *= normalization/twoPI; // twoPI from integral over omega
  83. // Now define real-space coordinates: between 0 and L/2
  84. Vect_DP xlattice(Npts_x);
  85. for (int i = 0; i < Npts_x; ++i) xlattice[i] = (i + 0.5) * 0.5* L/Npts_x;
  86. // Now the correlation at x:
  87. Vect_DP FT(0.0, Npts_x);
  88. DP pioverL = PI/L;
  89. // Fourier transform:
  90. for (int ix = 0; ix < Npts_x; ++ix) {
  91. for (int iK = 1; iK <= iKmax; ++iK) {
  92. FT[ix] += SSF[iK - iKmin] * pow(sin(pioverL * iK * xlattice[ix])/iK, 2.0);
  93. }
  94. // Reset proper normalization: 1/L from space FT,
  95. FT[ix] *= 2.0*L/(PI * PI);
  96. // Outside of window iKmin, iKmax, we take the DSF to be a constant with delta function
  97. // at free energy k^2, so DSF = 2\pi N/L \delta(\omega - k^2) (to fit f-sumrule)
  98. // so SSF becomes N/L.
  99. // We thus need to correct above by adding
  100. // \frac{1}{L} \sum_{-\infty}^{iKmin - 1} SSF e^{ikx} + \frac{1}{L} \sum_{iKmax + 1}^\infty SSF e^{ikx}
  101. // Resumming carefully:
  102. //FTre[ix] += (sin(twopioverL * (iKmin - 0.5) * xlattice[ix]) - sin(twopioverL * (iKmax + 0.5) * xlattice[ix]))
  103. //* N/(2.0 * L*L * sin(PI * xlattice[ix]/L));
  104. //FTim[ix] += (-cos(twopioverL * (iKmin - 0.5) * xlattice[ix]) + cos(twopioverL * (iKmax + 0.5) * xlattice[ix]))
  105. //* N/(2.0 * L*L * sin(PI * xlattice[ix]/L));
  106. }
  107. // Output to file:
  108. for (int ix = 0; ix < Npts_x; ++ix) {
  109. if (ix > 0) SFT_outfile << endl;
  110. //SFT_outfile << xlattice[ix] << "\t" << FTre[ix] << "\t" << FTim[ix] << "\t" << FTreavg[ix] << "\t" << FTimavg[ix];
  111. SFT_outfile << xlattice[ix]/L << "\t" << FT[ix];
  112. }
  113. SFT_outfile.close();
  114. }
  115. return(0);
  116. }