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.

XXX_h0_v2.cc 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /****************************************************************
  2. This software is part of J.-S. Caux's C++ library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: XXX_h0_v2.cc
  6. Purpose: Defines all class procedures used for the XXX chain in zero field.
  7. Aims at calculating the full k, omega dependence in one go.
  8. ******************************************************************/
  9. #include "ABACUS.h"
  10. using namespace std;
  11. namespace ABACUS {
  12. DP Direct_J_integral (int Npts_p, DP req_prec, I_table Itable)
  13. {
  14. stringstream outfile_stringstream;
  15. string outfile_string;
  16. outfile_stringstream << "SF_4p_Np_" << Npts_p << "_prec_" << req_prec << ".raw";
  17. outfile_string = outfile_stringstream.str();
  18. const char* outfile_Cstr = outfile_string.c_str();
  19. ofstream outfile;
  20. outfile.open(outfile_Cstr);
  21. outfile.precision(16);
  22. stringstream src_stringstream;
  23. string src_string;
  24. src_stringstream << "SF_4p_Np_" << Npts_p << "_prec_" << req_prec << ".src";
  25. src_string = src_stringstream.str();
  26. const char* src_Cstr = src_string.c_str();
  27. ofstream srcfile;
  28. srcfile.open(src_Cstr);
  29. srcfile.precision(16);
  30. Vect_DP p(4);
  31. DP J_fn_cont = 0.0;
  32. DP sum_J_fn = 0.0;
  33. for (int ip0 = 0; ip0 < Npts_p; ++ip0) {
  34. p[0] = - (ip0 + 0.5) * PI/Npts_p;
  35. for (int ip1 = ip0 + 1; ip1 < Npts_p; ++ip1) {
  36. p[1] = - (ip1 + 0.5) * PI/Npts_p;
  37. for (int ip2 = ip1 + 1; ip2 < Npts_p; ++ip2) {
  38. p[2] = - (ip2 + 0.5) * PI/Npts_p;
  39. for (int ip3 = ip2 + 1; ip3 < Npts_p; ++ip3) {
  40. p[3] = - (ip3 + 0.5) * PI/Npts_p;
  41. J_fn_cont = J_fn (p, req_prec, Itable);
  42. sum_J_fn += J_fn_cont;
  43. if (p[0] > 0 || p[1] > 1 || p[2] > 2 || p[3] > 3) outfile << endl;
  44. outfile << p << "\t" << J_fn_cont;
  45. }
  46. }
  47. }
  48. }
  49. DP integral_J = Compute_C4 (req_prec) * 24.0 * sum_J_fn * pow(PI/Npts_p, 4.0);
  50. // 24: from using ordered p's
  51. srcfile << integral_J << "\t" << integral_J/(4.0 * PI * PI) << "\t" << integral_J/(PI * PI) << endl;
  52. outfile.close();
  53. srcfile.close();
  54. return(integral_J);
  55. }
  56. void Smoothen_raw_SF_4p (int Npts_p, int Npts_o, DP req_prec, DP width)
  57. {
  58. stringstream rawfile_stringstream;
  59. string rawfile_string;
  60. rawfile_stringstream << "SF_4p_Np_" << Npts_p << "_No_" << Npts_o << "_prec_" << req_prec << ".raw";
  61. rawfile_string = rawfile_stringstream.str();
  62. const char* rawfile_Cstr = rawfile_string.c_str();
  63. ifstream rawfile;
  64. rawfile.open(rawfile_Cstr);
  65. stringstream smfile_stringstream;
  66. string smfile_string;
  67. smfile_stringstream << "SF_4p_Np_" << Npts_p << "_No_" << Npts_o << "_prec_" << req_prec << "_w_" << width << ".dat";
  68. smfile_string = smfile_stringstream.str();
  69. const char* smfile_Cstr = smfile_string.c_str();
  70. ofstream smfile;
  71. smfile.open(smfile_Cstr);
  72. smfile.precision(16);
  73. DP* SF_4p_raw = new DP[(Npts_p + 1) * Npts_o];
  74. DP* SF_4p_sm = new DP[(Npts_p + 1) * Npts_o];
  75. for (int iw = 0; iw < Npts_o; ++iw)
  76. for (int ik = 0; ik <= Npts_p; ++ik)
  77. rawfile >> SF_4p_raw[Npts_o * ik + iw];
  78. rawfile.close();
  79. // We now broaden to a Gaussian:
  80. int iw_half_window = int(width/(2.0 * PI/Npts_o));
  81. if (iw_half_window == 0) ABACUSerror("width too small in Smoothen_raw_SF_4p");
  82. int iwstart, iwstop;
  83. DP domega_sq_over_width_sq = pow(2.0 * PI/(Npts_o * width), 2.0);
  84. DP exp_factor;
  85. for (int iw = 0; iw < Npts_o; ++iw) {
  86. iwstart = ABACUS::max(0, iw - 10 * iw_half_window);
  87. iwstop = ABACUS::min(Npts_o, iw + 10 * iw_half_window);
  88. for (int iwraw = iwstart; iwraw <= iwstop; ++iwraw) {
  89. exp_factor = exp(-(iwraw - iw) * (iwraw - iw) * domega_sq_over_width_sq);
  90. for (int ik = 0; ik <= Npts_p; ++ik)
  91. {
  92. SF_4p_sm[Npts_o * ik + iw] += SF_4p_raw[Npts_o * ik + iwraw] * exp_factor;
  93. }
  94. }
  95. }
  96. // Reset normalization from delta function and output data
  97. DP prefactor = 1.0/(sqrt(PI) * width);
  98. for (int iw = 0; iw < Npts_o; ++iw) {
  99. for (int ik = 0; ik <= Npts_p; ++ik)
  100. smfile << SF_4p_sm[Npts_o * ik + iw] * prefactor << "\t";
  101. smfile << endl;
  102. }
  103. smfile.close();
  104. }
  105. DP Direct_J_integral_bin (int Npts_p, int Npts_o, DP req_prec, I_table Itable)
  106. {
  107. // Produces binned file for J
  108. stringstream rawfile_stringstream;
  109. string rawfile_string;
  110. rawfile_stringstream << "SF_4p_Np_" << Npts_p << "_No_" << Npts_o << "_prec_" << req_prec << ".raw";
  111. rawfile_string = rawfile_stringstream.str();
  112. const char* rawfile_Cstr = rawfile_string.c_str();
  113. ofstream rawfile;
  114. rawfile.open(rawfile_Cstr);
  115. rawfile.precision(16);
  116. stringstream src_stringstream;
  117. string src_string;
  118. src_stringstream << "SF_4p_Np_" << Npts_p << "_No_" << Npts_o << "_prec_" << req_prec << ".src";
  119. src_string = src_stringstream.str();
  120. const char* src_Cstr = src_string.c_str();
  121. ofstream srcfile;
  122. srcfile.open(src_Cstr);
  123. srcfile.precision(16);
  124. Vect_DP p(4);
  125. DP J_fn_cont = 0.0;
  126. DP sum_J_fn = 0.0;
  127. DP* SF_4p_raw = new DP[(Npts_p + 1) * Npts_o];
  128. // labelling: index is Npts_o * ik + iomega
  129. DP omegamax = 2.0 * PI;
  130. Write_K_File (Npts_p, 0, Npts_p);
  131. Write_Omega_File (Npts_o, 0.0, omegamax);
  132. int ik;
  133. DP omega;
  134. int iomega;
  135. DP sinp0, sinp1, sinp2;
  136. for (int ip0 = 0; ip0 < Npts_p; ++ip0) {
  137. p[0] = - (ip0 + 0.5) * PI/Npts_p;
  138. sinp0 = sin(p[0]);
  139. for (int ip1 = ip0 + 1; ip1 < Npts_p; ++ip1) {
  140. p[1] = - (ip1 + 0.5) * PI/Npts_p;
  141. sinp1 = sin(p[1]);
  142. for (int ip2 = ip1 + 1; ip2 < Npts_p; ++ip2) {
  143. p[2] = - (ip2 + 0.5) * PI/Npts_p;
  144. sinp2 = sin(p[2]);
  145. for (int ip3 = ip2 + 1; ip3 < Npts_p; ++ip3) {
  146. p[3] = - (ip3 + 0.5) * PI/Npts_p;
  147. ik = ip0 + ip1 + ip2 + ip3;
  148. if (ik > 2 * Npts_p) ik -= 2*Npts_p; // guarantees 0 <= ik < 2Npts
  149. if (ik <= Npts_p) {
  150. omega = -0.5 * PI * (sinp0 + sinp1 + sinp2 + sin(p[3]));
  151. iomega = int(omega * Npts_o/omegamax);
  152. J_fn_cont = J_fn (p, req_prec, Itable);
  153. sum_J_fn += (ik == Npts_p ? 1.0 : 2.0) * J_fn_cont;
  154. SF_4p_raw[Npts_o * ik + iomega] += J_fn_cont;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. DP prefactor = Compute_C4 (req_prec) * 24.0 * pow(PI/Npts_p, 4.0);
  161. // 24: from using ordered p's
  162. DP integral_J = prefactor * sum_J_fn;
  163. // Output raw file
  164. for (int iw = 0; iw < Npts_o; ++iw) {
  165. for (int iK = 0; iK <= Npts_p; ++iK) rawfile << prefactor * SF_4p_raw[Npts_o * iK + iw] << "\t";
  166. rawfile << endl;
  167. }
  168. srcfile << integral_J << "\t" << integral_J/(4.0 * PI * PI) << "\t" << integral_J/(PI * PI) << endl;
  169. rawfile.close();
  170. srcfile.close();
  171. delete[] SF_4p_raw;
  172. return(integral_J);
  173. }
  174. } // namespace ABACUS