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_VOA.cc 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. /****************************************************************
  2. This software is part of J.-S. Caux's C++ library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: XXX_VOA.cc
  6. Defines all class procedures used for the XXX chain in zero field.
  7. ******************************************************************/
  8. #include "ABACUS.h"
  9. using namespace std;
  10. namespace ABACUS {
  11. DP I_integral (DP rho, DP req_prec)
  12. {
  13. DP t1 = 1.0; // delimiter between two integrals
  14. DP tinf = 24.0; // such that exp(-2tinf) << machine_eps
  15. DP Euler_Mascheroni = 0.577215664901532860606;
  16. DP rho_used = fabs(rho);
  17. if (rho_used > 10000.0) return(-PI * rho_used - 2.0 * Euler_Mascheroni);
  18. Vect_DP args(2);
  19. args[0] = 0.0;
  20. args[1] = rho_used;
  21. DP answer = -2.0 * Euler_Mascheroni - 2.0 * log(4.0 * rho_used * t1)
  22. + 2.0 * Integrate_rec (Integrand_11, args, 0, 0.0, t1, req_prec, 12)
  23. - 2.0 * Integrate_rec (Integrand_12, args, 0, t1, tinf, req_prec, 12)
  24. - Integrate_rec (Integrand_2, args, 0, 0.0, tinf, req_prec, 12);
  25. return(answer);
  26. }
  27. /********************* TWO SPINONS ********************/
  28. DP SF_2p (DP k, DP omega, I_table Itable)
  29. {
  30. // Careful ! This is S(k, omega) = S (k, w) |dw/domega| = 2 S(k, w)
  31. DP w = 2.0 * omega;
  32. // Rescale energies by factor 2 because of definitions of H_XXX (omega: S.S; w: 0.5 * sigma.sigma = 2 S.S)
  33. DP wu = twoPI * sin(0.5 * k);
  34. DP wl = PI * fabs(sin(k));
  35. // Factor of 2: return S(k, omega), not S(k, w)
  36. // 0.25 factor: 1/4 * 2 * 1/2, where 1/4 comes from Bougourzi, 2 is the Jacobian |dw/domega|
  37. // and 1/2 is S^{zz} = 1/2 * S^{+-}
  38. return(w < wu && w > wl ? 2.0 * 0.5
  39. * exp(-Itable.Return_val (acosh(sqrt((wu * wu - wl * wl)/(w * w - wl * wl)))/PI))/sqrt(wu * wu - w * w) : 0.0);
  40. }
  41. DP SF_2p (Vect_DP args, I_table Itable)
  42. {
  43. // Careful ! This is S(k, w) !
  44. // This uses args[0] = k, args[1] = w.
  45. DP wu = twoPI * sin(0.5 * args[0]);
  46. DP wl = PI * fabs(sin(args[0]));
  47. // 0.5 factor: 1 from Bougourzi, and 1/2 is S^{zz} = 1/2 * S^{+-}
  48. return(args[1] < wu && args[1] > wl ?
  49. 0.5 * exp(-Itable.Return_val (acosh(sqrt((wu * wu - wl * wl)/(args[1] * args[1] - wl * wl)))
  50. /PI))/sqrt(wu * wu - args[1] * args[1]) : 0.0);
  51. }
  52. DP SF_2p_alt (Vect_DP args, I_table Itable)
  53. {
  54. // Careful ! This is S(k, w) !
  55. // This uses args[0] = k, args[1] = alpha.
  56. DP wu = twoPI * sin(0.5 * args[0]);
  57. DP wl = PI * fabs(sin(args[0]));
  58. DP w = wl * cosh(args[1]);
  59. if (w >= wu || w <= wl) return(0.0);
  60. DP factor = sqrt((w * w - wl * wl)/(wu * wu - w * w));
  61. // 0.5 factor: 1 from Bougourzi, and 1/2 is S^{zz} = 1/2 * S^{+-}
  62. return(factor * 0.5 * exp(-Itable.Return_val (acosh(sqrt((wu * wu - wl * wl)/(w * w - wl * wl)))/PI)));
  63. }
  64. DP SF_2p_w (Vect_DP args, I_table Itable)
  65. {
  66. return(args[1] * SF_2p (args, Itable));
  67. }
  68. DP SF_2p_w_alt (Vect_DP args, I_table Itable)
  69. {
  70. DP wu = twoPI * sin(0.5 * args[0]);
  71. DP wl = PI * fabs(sin(args[0]));
  72. DP w = wl * cosh(args[1]);
  73. DP factor = sqrt((w * w - wl * wl)/(wu * wu - w * w));
  74. // 0.5 factor: 1 from Bougourzi, and 1/2 is S^{zz} = 1/2 * S^{+-}
  75. return(w * factor * 0.5 * exp(-Itable.Return_val (acosh(sqrt((wu * wu - wl * wl)/(w * w - wl * wl)))/PI)));
  76. }
  77. DP SF_2p_intw (Vect_DP args, I_table Itable)
  78. {
  79. // This returns \int_0^2PI dw/2PI S(k, w)
  80. DP k = args[0];
  81. DP req_prec = args[1];
  82. int max_rec = int(args[2]);
  83. DP wu = twoPI * sin(0.5 * k);
  84. DP wl = PI * fabs(sin(k));
  85. Vect_DP args_to_SF_2p(2);
  86. args_to_SF_2p[0] = k;
  87. args_to_SF_2p[1] = 0.0; // this will be w
  88. args_to_SF_2p[2] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  89. return(Integrate_rec_using_table (SF_2p, args_to_SF_2p, 1, Itable, wl, wu, req_prec, max_rec)/twoPI);
  90. }
  91. DP SF_2p_intw_alt (Vect_DP args, I_table Itable)
  92. {
  93. // This returns \int_0^2PI dw/2PI S(k, w)
  94. DP k = args[0];
  95. DP req_prec = args[1];
  96. int max_rec = int(args[2]);
  97. DP wu = twoPI * sin(0.5 * k);
  98. DP wl = PI * fabs(sin(k));
  99. Vect_DP args_to_SF_2p(2);
  100. args_to_SF_2p[0] = k;
  101. args_to_SF_2p[1] = 0.0; // this will be w
  102. args_to_SF_2p[2] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  103. return(Integrate_rec_using_table (SF_2p_alt, args_to_SF_2p, 1, Itable, 0.0, acosh(wu/wl), req_prec, max_rec)/twoPI);
  104. }
  105. DP SF_2p_check_sumrule (DP req_prec, int max_rec, I_table Itable)
  106. {
  107. // It's better to use the ..._alt function below.
  108. Vect_DP args_to_SF_2p_intw (3);
  109. args_to_SF_2p_intw[0] = 0.0; // this will be k
  110. args_to_SF_2p_intw[1] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  111. args_to_SF_2p_intw[2] = DP(max_rec);
  112. // Factor 2: int[0, 2PI] = 2 int[0, PI]
  113. return(4.0 * 2.0 * Integrate_rec_using_table (SF_2p_intw, args_to_SF_2p_intw, 0, Itable,
  114. 0.0, PI, req_prec, max_rec)/twoPI);
  115. // 4 : because full integral gives 1/4, return value here is sr fraction obtained.
  116. }
  117. DP SF_2p_check_sumrule_alt (DP req_prec, int max_rec, I_table Itable)
  118. {
  119. // This is the preferred version.
  120. Vect_DP args_to_SF_2p_intw (3);
  121. args_to_SF_2p_intw[0] = 0.0; // this will be k
  122. args_to_SF_2p_intw[1] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  123. args_to_SF_2p_intw[2] = DP(max_rec);
  124. // Factor 2: int[0, 2PI] = 2 int[0, PI]
  125. return(4.0 * 2.0 * Integrate_rec_using_table (SF_2p_intw_alt, args_to_SF_2p_intw, 0, Itable,
  126. 0.0, PI, req_prec, max_rec)/twoPI);
  127. // 4 : because full integral gives 1/4, return value here is sr fraction obtained.
  128. }
  129. DP Fixed_k_sumrule_w (DP k)
  130. {
  131. // This is K_1 (k) = \int dw/2PI w S(k, w) = 2 K_1^{KarbachPRB55} (k) = 4 E_G (1-cosk)/3N with E_G = -N(ln2 - 1/4).
  132. return(4.0 * (log(2.0) - 0.25) * (1.0 - cos(k))/3.0);
  133. }
  134. DP Fixed_k_sumrule_omega (DP k)
  135. {
  136. return(0.5 * Fixed_k_sumrule_w(k));
  137. }
  138. DP SF_2p_check_fixed_k_sumrule (DP k, DP req_prec, int max_rec, I_table Itable)
  139. {
  140. // It's better to use the ..._alt function below.
  141. DP wu = twoPI * sin(0.5 * k);
  142. DP wl = PI * fabs(sin(k));
  143. Vect_DP args_to_SF_2p(2);
  144. args_to_SF_2p[0] = k;
  145. args_to_SF_2p[1] = 0.0; // this will be w
  146. args_to_SF_2p[2] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  147. return((Integrate_rec_using_table (SF_2p_w, args_to_SF_2p, 1,
  148. Itable, wl, wu, req_prec, max_rec)/twoPI)/Fixed_k_sumrule_w(k));
  149. }
  150. DP SF_2p_check_fixed_k_sumrule_alt (DP k, DP req_prec, int max_rec, I_table Itable)
  151. {
  152. // This is the preferred version.
  153. DP wu = twoPI * sin(0.5 * k);
  154. DP wl = PI * fabs(sin(k));
  155. Vect_DP args_to_SF_2p(2);
  156. args_to_SF_2p[0] = k;
  157. args_to_SF_2p[1] = 0.0; // this will be alpha
  158. args_to_SF_2p[2] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  159. return((Integrate_rec_using_table (SF_2p_w_alt, args_to_SF_2p, 1, Itable, 0.0, acosh(wu/wl),
  160. req_prec, max_rec)/twoPI)/Fixed_k_sumrule_w(k));
  161. }
  162. DP SF_2p_check_fixed_k_sumrule_opt (DP k, DP req_prec, int Npts, I_table Itable)
  163. {
  164. // This is the preferred version.
  165. DP wu = twoPI * sin(0.5 * k);
  166. DP wl = PI * fabs(sin(k));
  167. Vect_DP args_to_SF_2p(2);
  168. args_to_SF_2p[0] = k;
  169. args_to_SF_2p[1] = 0.0; // this will be alpha
  170. args_to_SF_2p[2] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  171. return(((Integrate_optimal_using_table (SF_2p_w_alt, args_to_SF_2p, 1, Itable, 0.0, acosh(wu/wl),
  172. req_prec, 1.0e-32, Npts)).integ_est/twoPI)/Fixed_k_sumrule_w(k));
  173. }
  174. /********************** FOUR SPINONS **********************/
  175. DP Sum_norm_gl (Vect_DP rho, DP req_prec)
  176. {
  177. complex<DP> g[4];
  178. for (int l = 0; l < 4; ++l) g[l] = 0.0;
  179. complex<DP> Plm[4];
  180. complex<DP> Pm[4];
  181. DP den = 0.0;
  182. for (int j = 0; j < 4; ++j) {
  183. Pm[j] = cosh(twoPI * rho[j]);
  184. den = 1.0;
  185. for (int i = 0; i < 4; ++i) if (i != j) den *= sinh(PI * (rho[j] - rho[i]));
  186. Pm[j] /= den;
  187. }
  188. complex<DP> irhoj0[4];
  189. complex<DP> irhoj1[4];
  190. complex<DP> irhoj2[4];
  191. complex<DP> irhoj3[4];
  192. for (int j = 0; j < 4; ++j) {
  193. irhoj0[j] = II * (rho[j] - rho[0]);
  194. irhoj1[j] = II * (rho[j] - rho[1]);
  195. irhoj2[j] = II * (rho[j] - rho[2]);
  196. irhoj3[j] = II * (rho[j] - rho[3]);
  197. }
  198. // Do m = 0 terms:
  199. for (int j = 0; j < 4; ++j) {
  200. // Calling only Gamma (z) for Re(z) >= 0.5, in view of Lanczos method:
  201. Pm[j] *= exp(ln_Gamma(0.5 + irhoj0[j]) - ln_Gamma(1.0 + irhoj0[j])
  202. + ln_Gamma(0.5 + irhoj1[j]) - ln_Gamma(1.0 + irhoj1[j])
  203. + ln_Gamma(0.5 + irhoj2[j]) - ln_Gamma(1.0 + irhoj2[j])
  204. + ln_Gamma(0.5 + irhoj3[j]) - ln_Gamma(1.0 + irhoj3[j]))
  205. /((-0.5 + irhoj0[j]) * (-0.5 + irhoj1[j]) * (-0.5 + irhoj2[j]) * (-0.5 + irhoj3[j]));
  206. for (int l = 0; l < 4; ++l) {
  207. Plm[j] = 1.0;
  208. for (int i = 0; i < 4; ++i) if (i != l) Plm[j] *= ((l > i ? -0.5 : 0.0) + II * (rho[j] - rho[i]));
  209. if (j <= l) g[l] += Plm[j] * Pm[j]; // otherwise no m = 0 term
  210. }
  211. }
  212. DP sum_norm_gl = norm(g[0]) + norm(g[1]) + norm(g[2]) + norm(g[3]);
  213. DP old_sum_norm_gl = sum_norm_gl;
  214. // Do m = 1, 2, ... terms:
  215. int m = 1;
  216. int m_to_reach = 1;
  217. do {
  218. old_sum_norm_gl = sum_norm_gl;
  219. // We increase m by ten steps before checking sum_norm
  220. m_to_reach = m + 10;
  221. do {
  222. for (int j = 0; j < 4; ++j) {
  223. Pm[j] *= (m - 1.5 + irhoj0[j]) * (m - 1.5 + irhoj1[j]) * (m - 1.5 + irhoj2[j]) * (m - 1.5 + irhoj3[j])
  224. / ((DP(m) + irhoj0[j]) * (DP(m) + irhoj1[j]) * (DP(m) + irhoj2[j]) * (DP(m) + irhoj3[j]));
  225. // FASTER: unwrap l, i loops
  226. // l = 0:
  227. g[0] += (DP(m) + irhoj1[j]) * (DP(m) + irhoj2[j]) * (DP(m) + irhoj3[j]) * Pm[j];
  228. // l = 1;
  229. g[1] += (m - 0.5 + irhoj0[j]) * (DP(m) + irhoj2[j]) * (DP(m) + irhoj3[j]) * Pm[j];
  230. // l = 2;
  231. g[2] += (m - 0.5 + irhoj0[j]) * (m - 0.5 + irhoj1[j]) * (DP(m) + irhoj3[j]) * Pm[j];
  232. // l = 3;
  233. g[3] += (m - 0.5 + irhoj0[j]) * (m - 0.5 + irhoj1[j]) * (m - 0.5 + irhoj2[j]) * Pm[j];
  234. }
  235. m++;
  236. } while (m < m_to_reach);
  237. sum_norm_gl = norm(g[0]) + norm(g[1]) + norm(g[2]) + norm(g[3]);
  238. } while (m < 10 || sum_norm_gl/old_sum_norm_gl - 1.0 > req_prec && m < 100000);
  239. return(norm(g[0]) + norm(g[1]) + norm(g[2]) + norm(g[3]));
  240. }
  241. DP Compute_C4 (DP req_prec)
  242. {
  243. Vect_DP args(2);
  244. DP answer = exp(-8.0 * real(ln_Gamma (0.25)) - 9.0 * log(2.0)
  245. + 8.0 * Integrate_rec (Integrand_A, args, 0, 0.0, 50.0, req_prec, 16))/3.0;
  246. return(answer);
  247. }
  248. DP SF_contrib (Vect_DP p, DP req_prec, I_table Itable)
  249. {
  250. Vect_DP rho(4);
  251. DP W, Wu, sum_I_integrals, sum_norm_g;
  252. for (int i = 0; i < 4; ++i) rho[i] = asinh(1.0/tan(p[i]))/twoPI;
  253. Wu = twoPI* fabs(sin(0.5*(p[0] + p[1])));
  254. W = -PI* (sin(p[0]) + sin(p[1]));
  255. sum_I_integrals = 0.0;
  256. for (int i1 = 0; i1 < 3; ++i1) for (int i2 = i1+1; i2 < 4; ++i2) {
  257. sum_I_integrals += Itable.Return_val (rho[i1] - rho[i2]);
  258. }
  259. sum_norm_g = Sum_norm_gl (rho, req_prec);
  260. return(exp(-sum_I_integrals) * sum_norm_g/sqrt(Wu * Wu - W * W));
  261. }
  262. DP J_fn (Vect_DP p, DP req_prec, I_table Itable)
  263. {
  264. Vect_DP rho(4);
  265. DP sum_I_integrals, sum_norm_g;
  266. for (int i = 0; i < 4; ++i) rho[i] = asinh(1.0/tan(p[i]))/twoPI;
  267. sum_I_integrals = 0.0;
  268. for (int i1 = 0; i1 < 3; ++i1) for (int i2 = i1+1; i2 < 4; ++i2) {
  269. if (fabs(rho[i1] - rho[i2]) < 1.0e-10 || fabs(rho[i1] - rho[i2]) >= 1000.0) return(0.0); // safety here
  270. sum_I_integrals += Itable.Return_val (rho[i1] - rho[i2]);
  271. }
  272. sum_norm_g = Sum_norm_gl (rho, req_prec);
  273. return(exp(-sum_I_integrals) * sum_norm_g);
  274. }
  275. bool Set_p_given_kwKW (DP k, DP w, DP K, DP W, Vect_DP& p)
  276. {
  277. // Returns false if any of the p_i are out of -PI, 0
  278. DP argacos1, argacos2;
  279. if (fabs(argacos1 = W/(twoPI * sin(0.5*K))) > 1.0
  280. || fabs(argacos2 = (w - W)/(twoPI * sin (0.5 * fabs(k - K)))) > 1.0) return(false);
  281. DP acos1 = acos(argacos1);
  282. DP acos2 = acos(argacos2);
  283. p[0] = -0.5 * K + acos1;
  284. p[1] = -0.5 * K - acos1;
  285. if (K <= k) {
  286. p[2] = 0.5 * (K-k) + acos2;
  287. p[3] = 0.5 * (K-k) - acos2;
  288. }
  289. else {
  290. p[2] = 0.5 * (K-k) - PI + acos2;
  291. p[3] = 0.5 * (K-k) - PI - acos2;
  292. }
  293. for (int i = 0; i < 4; ++i) if (p[i] < -PI || p[i] > 0.0) return(false);
  294. return(true);
  295. }
  296. DP G_fn (Vect_DP args_to_G, I_table Itable)
  297. {
  298. Vect_DP p(4);
  299. if (!Set_p_given_kwKW (args_to_G[0], args_to_G[1], args_to_G[2], args_to_G[3], p)) return(0.0);
  300. DP answer = Jacobian_p3p4_KW (args_to_G[0], args_to_G[1], args_to_G[2], args_to_G[3])
  301. * SF_contrib (p, args_to_G[4], Itable);
  302. return(answer);
  303. }
  304. DP G1_fn (Vect_DP args_to_G, I_table Itable)
  305. {
  306. Vect_DP p(4);
  307. DP W = twoPI * sin(0.5*args_to_G[2]) * cos(args_to_G[3]);
  308. if (!Set_p_given_kwKW (args_to_G[0], args_to_G[1], args_to_G[2], W, p)) return(0.0);
  309. return(J_fn (p, args_to_G[4], Itable)/sqrt(pow(twoPI * sin(0.5*(args_to_G[0] - args_to_G[2])), 2.0)
  310. - pow(args_to_G[1] - W, 2.0)));
  311. }
  312. DP G2_fn (Vect_DP args_to_G, I_table Itable)
  313. {
  314. Vect_DP p(4);
  315. DP W = args_to_G[1] - twoPI * fabs(sin(0.5*(args_to_G[0] - args_to_G[2]))) * cos(args_to_G[3]);
  316. if (!Set_p_given_kwKW (args_to_G[0], args_to_G[1], args_to_G[2], W, p)) return(0.0);
  317. return(J_fn (p, args_to_G[4], Itable)/sqrt(pow(twoPI * sin(0.5*args_to_G[2]), 2.0) - W * W));
  318. }
  319. DP G1_fn_mid (Vect_DP args_to_G, I_table Itable)
  320. {
  321. // Called by H_fn_mid.
  322. // For the lower half of W interval
  323. // Translation of arguments to G:
  324. // args_to_G[0] = k;
  325. // args_to_G[1] = w;
  326. // args_to_G[2] = K;
  327. // args_to_G[3] = alpha;
  328. // args_to_G[4] = req_prec;
  329. // args_to_G[5] = max_rec;
  330. // args_to_G[6] = Wmid;
  331. // args_to_G[7] = Wmax_used;
  332. // args_to_G[8] = Wu_sq;
  333. // args_to_G[9] = Wut_sq;
  334. Vect_DP p(4);
  335. DP W = args_to_G[6] * (args_to_G[3] > 1.0e-4 ? 1.0 - cos(args_to_G[3]) : 2.0 * pow(sin(0.5 * args_to_G[3]), 2));
  336. // W = Wmid (1 - cos(alpha)), ensure some precision if alpha small
  337. if (!Set_p_given_kwKW (args_to_G[0], args_to_G[1], args_to_G[2], W, p)) return(0.0);
  338. DP answer = J_fn (p, args_to_G[4], Itable)
  339. * sqrt(W * (2.0 * args_to_G[6] - W)/((args_to_G[8] - W * W) * (args_to_G[9] - pow(args_to_G[1] - W, 2.0))));
  340. if (is_nan(answer)) {
  341. cerr << setprecision(10) << "args_to_G1_fn_mid = " << args_to_G << "G1 = " << answer << "\tPut to zero..." << endl;
  342. answer = 0.0;
  343. }
  344. return(answer);
  345. }
  346. DP G2_fn_mid (Vect_DP args_to_G, I_table Itable)
  347. {
  348. // Called by H_fn_mid.
  349. // For the upper half of W interval
  350. // See above for translation of arguments to G.
  351. Vect_DP p(4);
  352. DP W = args_to_G[7] * cos(args_to_G[3]); // W = Wmax cos(alpha)
  353. if (!Set_p_given_kwKW (args_to_G[0], args_to_G[1], args_to_G[2], W, p)) return(0.0);
  354. DP answer = J_fn (p, args_to_G[4], Itable)
  355. * args_to_G[7] * sin(args_to_G[3]) /sqrt((args_to_G[8] - W * W) * (args_to_G[9] - pow(args_to_G[1] - W, 2.0)));
  356. if (is_nan(answer)) {
  357. cerr << setprecision(10) << "args_to_G2_fn_mid = " << args_to_G << "G2 = " << answer << endl;
  358. cerr << W << "\t" << (args_to_G[7] * args_to_G[7] - W * W) << "\t" << (args_to_G[8] - W * W)
  359. << "\t" << (args_to_G[9] - pow(args_to_G[1] - W, 2.0)) << endl;
  360. answer = 0.0;
  361. }
  362. return(answer);
  363. }
  364. DP G_fn_alt (Vect_DP args_to_G, I_table Itable)
  365. {
  366. Vect_DP p(4);
  367. DP Wmin = args_to_G[4];
  368. DP W = Wmin * cosh(args_to_G[3]);
  369. if (!Set_p_given_kwKW (args_to_G[0], args_to_G[1], args_to_G[2], W, p)) return(0.0);
  370. DP Wu1 = args_to_G[6];
  371. DP Wu2 = args_to_G[7];
  372. return(J_fn (p, args_to_G[8], Itable)
  373. * sqrt((W * W - Wmin * Wmin)/((Wu1 * Wu1 - W * W) * (Wu2 * Wu2 - (args_to_G[1] - W) * (args_to_G[1] - W)))));
  374. }
  375. DP H_fn (Vect_DP args_to_H, I_table Itable)
  376. {
  377. // Translate arguments to more readable form
  378. DP k = args_to_H[0];
  379. DP w = args_to_H[1];
  380. DP K = args_to_H[2];
  381. DP req_prec = ABACUS::max(1.0e-14, args_to_H[3]);
  382. int max_rec = int(args_to_H[4]);
  383. Vect_DP args_to_G(6);
  384. args_to_G[0] = k;
  385. args_to_G[1] = w;
  386. args_to_G[2] = K;
  387. args_to_G[3] = 0.0;
  388. args_to_G[4] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  389. args_to_G[5] = DP(max_rec);
  390. DP Wmin_used = Wmin (k, w, K);
  391. DP Wmax_used = Wmax (k, w, K);
  392. return(Wmax_used > Wmin_used ?
  393. Integrate_rec_using_table (G_fn, args_to_G, 3, Itable, Wmin_used, Wmax_used, req_prec, max_rec) : 0.0);
  394. }
  395. DP H2_fn (Vect_DP args_to_H, I_table Itable)
  396. {
  397. // Translate arguments to more readable form
  398. DP k = args_to_H[0];
  399. DP w = args_to_H[1];
  400. DP K = args_to_H[2];
  401. DP req_prec = ABACUS::max(1.0e-14, args_to_H[3]);
  402. int max_rec = int(args_to_H[4]);
  403. DP Wmin_used = Wmin (k, w, K);
  404. DP Wmax_used = Wmax (k, w, K);
  405. if (Wmax_used <= Wmin_used) return(0.0);
  406. Vect_DP args_to_G(6);
  407. args_to_G[0] = k;
  408. args_to_G[1] = w;
  409. args_to_G[2] = K;
  410. args_to_G[3] = 0.0; // this will be the alpha parameter
  411. args_to_G[4] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  412. args_to_G[5] = DP(max_rec);
  413. DP Wmid = 0.5 * (Wmin_used + Wmax_used);
  414. DP answer = 0.0;
  415. DP alpha_L1 = acos(ABACUS::min(1.0, Wmax_used/(twoPI * sin(0.5*K)))); // to prevent nan
  416. DP alpha_U1 = acos(Wmid/(twoPI * sin(0.5*K)));
  417. DP alpha_L2 = acos(ABACUS::min(1.0, (w - Wmin_used)/(twoPI * fabs(sin(0.5*(k - K))))));
  418. DP alpha_U2 = acos((w - Wmid)/(twoPI * fabs(sin(0.5*(k - K)))));
  419. answer += Integrate_rec_using_table (G1_fn, args_to_G, 3, Itable, alpha_L1, alpha_U1, req_prec, max_rec);
  420. answer += Integrate_rec_using_table (G2_fn, args_to_G, 3, Itable, alpha_L2, alpha_U2, req_prec, max_rec);
  421. return(answer);
  422. }
  423. DP H_fn_mid (Vect_DP args_to_H, I_table Itable)
  424. {
  425. // For W in [Wmin, Wmid] we use the parametrization W = Wmid sin(alpha), alpha in [0, PI/2]
  426. // such that dW = Wmid cos(alpha) dalpha is approx. 0 around alpha = PI/2 (W = 0).
  427. // For W in [Wmid, Wmax] we use W = Wmax cos(alpha), alpha in [0, acos(Wmid/Wmax)]
  428. // such that dW = -Wmax sin(alpha) dalpha is approx 0 around alpha = 0 (W = Wmax).
  429. // Translation of args_to_H:
  430. // args_to_H[0] = k;
  431. // args_to_H[1] = w;
  432. // args_to_H[2] = K; <------ integrated over, so newly set here
  433. // args_to_H[3] = req_prec;
  434. // args_to_H[4] = max_rec;
  435. DP Wmin_used = Wmin (args_to_H[0], args_to_H[1], args_to_H[2]);
  436. DP Wmax_used = Wmax (args_to_H[0], args_to_H[1], args_to_H[2]);
  437. DP Wu_sq = pow(twoPI * sin(0.5 * args_to_H[2]), 2.0);
  438. DP Wut_sq = pow(twoPI * sin(0.5 * (args_to_H[0] - args_to_H[2])), 2.0);
  439. if (Wmax_used <= Wmin_used) return(0.0);
  440. DP Wmid = 0.5 * (Wmin_used + Wmax_used);
  441. Vect_DP args_to_G(10);
  442. args_to_G[0] = args_to_H[0];
  443. args_to_G[1] = args_to_H[1];
  444. args_to_G[2] = args_to_H[2];
  445. args_to_G[3] = 0.0; // this will be the alpha parameter
  446. args_to_G[4] = ABACUS::max(1.0e-14, 0.01 * args_to_H[3]);
  447. args_to_G[5] = args_to_H[4];
  448. args_to_G[6] = Wmid;
  449. args_to_G[7] = Wmax_used;
  450. args_to_G[8] = Wu_sq;
  451. args_to_G[9] = Wut_sq;
  452. DP answer = 0.0;
  453. DP alpha_L1 = 0.0;
  454. DP alpha_U1 = 0.5 * PI;
  455. DP alpha_L2 = 0.0;
  456. DP alpha_U2 = acos(Wmid/Wmax_used);
  457. answer += Integrate_rec_using_table (G1_fn_mid, args_to_G, 3, Itable, alpha_L1,
  458. alpha_U1, args_to_H[3], int(args_to_H[4]));
  459. answer += Integrate_rec_using_table (G2_fn_mid, args_to_G, 3, Itable, alpha_L2,
  460. alpha_U2, args_to_H[3], int(args_to_H[4]));
  461. return(answer);
  462. }
  463. DP H_fn_mid_opt (Vect_DP args_to_H, I_table Itable)
  464. {
  465. // For W in [Wmin, Wmid] we use the parametrization W = Wmid sin(alpha), alpha in [0, PI/2]
  466. // such that dW = Wmid cos(alpha) dalpha is approx. 0 around alpha = PI/2 (W = 0).
  467. // For W in [Wmid, Wmax] we use W = Wmax cos(alpha), alpha in [0, acos(Wmid/Wmax)]
  468. // such that dW = -Wmax sin(alpha) dalpha is approx 0 around alpha = 0 (W = Wmax).
  469. // Translation of args_to_H:
  470. // args_to_H[0] = k;
  471. // args_to_H[1] = w;
  472. // args_to_H[2] = K; <------ integrated over, so newly set here
  473. // args_to_H[3] = req_prec;
  474. // args_to_H[4] = Npts;
  475. DP Wmin_used = Wmin (args_to_H[0], args_to_H[1], args_to_H[2]);
  476. DP Wmax_used = Wmax (args_to_H[0], args_to_H[1], args_to_H[2]);
  477. DP Wu_sq = pow(twoPI * sin(0.5 * args_to_H[2]), 2.0);
  478. DP Wut_sq = pow(twoPI * sin(0.5 * (args_to_H[0] - args_to_H[2])), 2.0);
  479. if (Wmax_used <= Wmin_used) return(0.0);
  480. DP Wmid = 0.5 * (Wmin_used + Wmax_used);
  481. Vect_DP args_to_G(10);
  482. args_to_G[0] = args_to_H[0];
  483. args_to_G[1] = args_to_H[1];
  484. args_to_G[2] = args_to_H[2];
  485. args_to_G[3] = 0.0; // this will be the alpha parameter
  486. args_to_G[4] = ABACUS::max(1.0e-14, 0.01 * args_to_H[3]);
  487. args_to_G[5] = args_to_H[4];
  488. args_to_G[6] = Wmid;
  489. args_to_G[7] = Wmax_used;
  490. args_to_G[8] = Wu_sq;
  491. args_to_G[9] = Wut_sq;
  492. DP answer = 0.0;
  493. DP alpha_L1 = 0.0;
  494. DP alpha_U1 = 0.5 * PI;
  495. DP alpha_L2 = 0.0;
  496. DP alpha_U2 = acos(Wmid/Wmax_used);
  497. answer += (Integrate_optimal_using_table (G1_fn_mid, args_to_G, 3, Itable, alpha_L1, alpha_U1,
  498. args_to_H[3], 1.0e-32, int(args_to_H[4]))).integ_est;
  499. answer += (Integrate_optimal_using_table (G2_fn_mid, args_to_G, 3, Itable, alpha_L2, alpha_U2,
  500. args_to_H[3], 1.0e-32, int(args_to_H[4]))).integ_est;
  501. return(answer);
  502. }
  503. DP H_fn_alt (Vect_DP args_to_H, I_table Itable)
  504. {
  505. // Translate arguments to more readable form
  506. DP k = args_to_H[0];
  507. DP w = args_to_H[1];
  508. DP K = args_to_H[2];
  509. DP req_prec = ABACUS::max(1.0e-14, args_to_H[3]);
  510. int max_rec = int(args_to_H[4]);
  511. DP Wmin_used = Wmin (k, w, K);
  512. DP Wmax_used = Wmax (k, w, K);
  513. if (Wmax_used <= Wmin_used) return(0.0);
  514. Vect_DP args_to_G(10);
  515. args_to_G[0] = k;
  516. args_to_G[1] = w;
  517. args_to_G[2] = K;
  518. args_to_G[3] = 0.0; // this will become alpha
  519. args_to_G[4] = Wmin_used;
  520. args_to_G[5] = Wmax_used;
  521. args_to_G[6] = twoPI * fabs(sin(0.5*args_to_G[2])); // Wu1
  522. args_to_G[7] = twoPI * fabs(sin(0.5*(args_to_G[0] - args_to_G[2]))); // Wu2
  523. args_to_G[8] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  524. args_to_G[9] = DP(max_rec);
  525. return(Integrate_rec_using_table (G_fn_alt, args_to_G, 3, Itable, 0.0, acosh(Wmax_used/Wmin_used), req_prec, max_rec));
  526. }
  527. DP SF_4p_kwKW (Vect_DP args, I_table Itable)
  528. {
  529. // Translate:
  530. // args[0] = k;
  531. // args[1] = omega;
  532. // args[2] = req_prec;
  533. // args[3] = max_rec;
  534. DP k = args[0];
  535. DP omega = args[1];
  536. DP req_prec = args[2];
  537. int max_rec = int(args[3]);
  538. Vect_DP args_to_H(5);
  539. args_to_H[0] = k; // shift of PI in Bougourzi: because they do FM case.
  540. // We want AFM, so SF_4p (k, omega) is correctly obtained directly from the RHS of their formula.
  541. DP w = 2.0 * omega;
  542. // Rescale energies by factor 2 because of definitions of H_XXX (omega: S.S; w: 0.5 * sigma.sigma = 2 S.S)
  543. args_to_H[1] = w;
  544. args_to_H[2] = 0.0; // this is K
  545. args_to_H[3] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  546. args_to_H[4] = DP(max_rec);
  547. if (w > wmax_4p(k) || w < wmin_4p(k)) {
  548. return(0.0);
  549. }
  550. DP prefactor = 2.0 * 0.5 * 4.0 * Compute_C4 (req_prec); // 4 comes from using p1 > p2 & p3 > p4 instead of whole interval.
  551. // 2 from Jacobian |dw/domega|
  552. // 0.5 from S^{zz} = S^{pm}/2
  553. // Define the K integral domain
  554. Domain<DP> Kdomain;
  555. // First, the inclusions:
  556. if (w <= twoPI * sin(0.5*k)) Kdomain.Include (0.0, twoPI);
  557. else {
  558. if (w < 4.0*PI * sin(0.25 * k)) {
  559. DP K1bm = 0.5 * k - 2.0 * acos (w/(4.0*PI * sin(0.25 * k)));
  560. DP K1bp = 0.5 * k + 2.0 * acos (w/(4.0*PI * sin(0.25 * k)));
  561. Kdomain.Include (K1bm, K1bp);
  562. }
  563. if (w < 4.0*PI * cos(0.25 * k)) {
  564. DP K1am = 0.5 * k + PI - 2.0 * acos (w/(4.0*PI * cos(0.25 * k)));
  565. DP K1ap = 0.5 * k + PI + 2.0 * acos (w/(4.0*PI * cos(0.25 * k)));
  566. Kdomain.Include (K1am, K1ap);
  567. }
  568. }
  569. // Now the exclusions:
  570. if (w < twoPI * sin(0.5*k)) {
  571. DP K2dm = 0.5 * k - acos (w/(twoPI * sin (0.5 * k)));
  572. DP K2dp = 0.5 * k + acos (w/(twoPI * sin (0.5 * k)));
  573. Kdomain.Exclude (K2dm, K2dp);
  574. DP K3cm = K2dm + PI;
  575. DP K3cp = K2dp + PI;
  576. Kdomain.Exclude (K3cm, K3cp);
  577. }
  578. if (w < twoPI * cos(0.5*k)) {
  579. DP K2cm = 0.5 * k + asin(w/(twoPI * cos(0.5*k)));
  580. DP K2cp = 0.5 * k + PI - asin(w/(twoPI * cos(0.5*k)));
  581. Kdomain.Exclude (K2cm, K2cp);
  582. DP K3em = K2cm + PI;
  583. DP K3ep = K2cp + PI;
  584. Kdomain.Exclude (K3em, K3ep);
  585. }
  586. // Use (K,W) -> (k-K, w-W) symmetry to restrict to K in [k/2, k/2+PI]
  587. Kdomain.Exclude (0.0, 0.5 * k);
  588. Kdomain.Exclude (0.5 * k + PI, twoPI);
  589. prefactor *= 2.0;
  590. DP answer = 0.0;
  591. for (int idom = 0; idom < Kdomain.Ndomains(); ++idom)
  592. answer += Integrate_rec_using_table (H_fn_mid, args_to_H, 2, Itable, Kdomain.xmin(idom), Kdomain.xmax(idom),
  593. req_prec, max_rec);
  594. return (prefactor * answer);
  595. }
  596. DP SF_4p_kwKW_opt (Vect_DP args, I_table Itable)
  597. {
  598. // Translate:
  599. // args[0] = k;
  600. // args[1] = omega;
  601. // args[2] = req_prec;
  602. // args[3] = Npts_K;
  603. // args[4] = Npts_W;
  604. DP k = args[0];
  605. DP omega = args[1];
  606. DP req_prec = args[2];
  607. int Npts_K = int(args[3]);
  608. int Npts_W = int(args[4]);
  609. Vect_DP args_to_H(5);
  610. args_to_H[0] = k; // shift of PI in Bougourzi: because they do FM case.
  611. // We want AFM, so SF_4p (k, omega) is correctly obtained directly from the RHS of their formula.
  612. DP w = 2.0 * omega;
  613. // Rescale energies by factor 2 because of definitions of H_XXX (omega: S.S; w: 0.5 * sigma.sigma = 2 S.S)
  614. args_to_H[1] = w;
  615. args_to_H[2] = 0.0; // this is K
  616. args_to_H[3] = ABACUS::max(1.0e-14, 0.01 * req_prec);
  617. args_to_H[4] = DP(Npts_W);
  618. if (w > wmax_4p(k) || w < wmin_4p(k)) {
  619. return(0.0);
  620. }
  621. DP prefactor = 2.0 * 0.5 * 4.0 * Compute_C4 (req_prec);
  622. // 4 comes from using p1 > p2 & p3 > p4 instead of whole interval.
  623. // 2 from Jacobian |dw/domega|
  624. // 0.5 from S^{zz} = S^{pm}/2
  625. // Define the K integral domain
  626. Domain<DP> Kdomain;
  627. // First, the inclusions:
  628. if (w <= twoPI * sin(0.5*k)) Kdomain.Include (0.0, twoPI);
  629. else {
  630. if (w < 4.0*PI * sin(0.25 * k)) {
  631. DP K1bm = 0.5 * k - 2.0 * acos (w/(4.0*PI * sin(0.25 * k)));
  632. DP K1bp = 0.5 * k + 2.0 * acos (w/(4.0*PI * sin(0.25 * k)));
  633. Kdomain.Include (K1bm, K1bp);
  634. }
  635. if (w < 4.0*PI * cos(0.25 * k)) {
  636. DP K1am = 0.5 * k + PI - 2.0 * acos (w/(4.0*PI * cos(0.25 * k)));
  637. DP K1ap = 0.5 * k + PI + 2.0 * acos (w/(4.0*PI * cos(0.25 * k)));
  638. Kdomain.Include (K1am, K1ap);
  639. }
  640. }
  641. // Now the exclusions:
  642. if (w < twoPI * sin(0.5*k)) {
  643. DP K2dm = 0.5 * k - acos (w/(twoPI * sin (0.5 * k)));
  644. DP K2dp = 0.5 * k + acos (w/(twoPI * sin (0.5 * k)));
  645. Kdomain.Exclude (K2dm, K2dp);
  646. DP K3cm = K2dm + PI;
  647. DP K3cp = K2dp + PI;
  648. Kdomain.Exclude (K3cm, K3cp);
  649. }
  650. if (w < twoPI * cos(0.5*k)) {
  651. DP K2cm = 0.5 * k + asin(w/(twoPI * cos(0.5*k)));
  652. DP K2cp = 0.5 * k + PI - asin(w/(twoPI * cos(0.5*k)));
  653. Kdomain.Exclude (K2cm, K2cp);
  654. DP K3em = K2cm + PI;
  655. DP K3ep = K2cp + PI;
  656. Kdomain.Exclude (K3em, K3ep);
  657. }
  658. // Use (K,W) -> (k-K, w-W) symmetry to restrict to K in [k, k+PI]
  659. Kdomain.Exclude (0.0, 0.5 * k);
  660. Kdomain.Exclude (0.5 * k + PI, twoPI);
  661. prefactor *= 2.0;
  662. DP answer = 0.0;
  663. for (int idom = 0; idom < Kdomain.Ndomains(); ++idom)
  664. answer += (Integrate_optimal_using_table (H_fn_mid_opt, args_to_H, 2, Itable, Kdomain.xmin(idom),
  665. Kdomain.xmax(idom), req_prec, 1.0e-32, Npts_K)).integ_est;
  666. return (prefactor * answer);
  667. }
  668. DP SF_4p_kwKW_alpha (Vect_DP args, I_table Itable)
  669. {
  670. // Better version for fixed k sum rule
  671. // Translate:
  672. // args[0] = k;
  673. // args[1] = alpha; <-- integration variable, omega = omegamin + (omegamax - omegamin) (1-cos(alpha))
  674. // args[2] = req_prec;
  675. // args[3] = max_rec;
  676. Vect_DP args_to_SF_4p_kwKW = args;
  677. DP omegamin = 0.5 * wmin_4p (args[0]);
  678. DP omegamax = 0.5 * wmax_4p (args[0]);
  679. args_to_SF_4p_kwKW[1] = omegamin + (omegamax - omegamin) * (1.0 - cos(args[1]));
  680. return((omegamax - omegamin) * sin(args[1]) * SF_4p_kwKW (args_to_SF_4p_kwKW, Itable));
  681. }
  682. DP SF_4p_kwKW_alpha_opt (Vect_DP args, I_table Itable)
  683. {
  684. // Better version for fixed k sum rule
  685. // Translate:
  686. // args[0] = k;
  687. // args[1] = alpha; <-- integration variable, omega = omegamin + (omegamax - omegamin) (1-cos(alpha))
  688. // args[2] = req_prec;
  689. // args[3] = Npts_K;
  690. // args[4] = Npts_W;
  691. Vect_DP args_to_SF_4p_kwKW = args;
  692. DP omegamin = 0.5 * wmin_4p (args[0]);
  693. DP omegamax = 0.5 * wmax_4p (args[0]);
  694. args_to_SF_4p_kwKW[1] = omegamin + (omegamax - omegamin) * (1.0 - cos(args[1]));
  695. return((omegamax - omegamin) * sin(args[1]) * SF_4p_kwKW_opt (args_to_SF_4p_kwKW, Itable));
  696. }
  697. DP SF_4p_kwKW_cosh_alpha_opt (Vect_DP args, I_table Itable)
  698. {
  699. // Better version for fixed k sum rule
  700. // Translate:
  701. // args[0] = k;
  702. // args[1] = alpha; <-- integration variable, omega = omegamin * cosh(alpha)
  703. // args[2] = req_prec;
  704. // args[3] = Npts_K;
  705. // args[4] = Npts_W;
  706. Vect_DP args_to_SF_4p_kwKW = args;
  707. DP omegamin = 0.5 * wmin_4p (args[0]);
  708. args_to_SF_4p_kwKW[1] = omegamin * cosh(args[1]);
  709. return(omegamin * sinh(args[1]) * SF_4p_kwKW_opt (args_to_SF_4p_kwKW, Itable));
  710. }
  711. /******************************************************************************************/
  712. // Interface to used version:
  713. DP SF_4p_rec (DP k, DP omega, DP req_prec, int max_rec, I_table Itable)
  714. {
  715. // CAREFUL !! This is S(k, omega) = 2 S(k, w)
  716. Vect_DP args_to_SF(4);
  717. args_to_SF[0] = k;
  718. args_to_SF[1] = omega;
  719. args_to_SF[2] = req_prec;
  720. args_to_SF[3] = DP(max_rec);
  721. return(2.0 * SF_4p_kwKW (args_to_SF, Itable));
  722. }
  723. DP SF_4p (DP k, DP omega, I_table Itable)
  724. {
  725. // Fixes req_prec and max_rec to default values
  726. return(SF_4p_rec (k, omega, default_req_prec, default_max_rec, Itable));
  727. }
  728. // Interface to used version:
  729. DP SF_4p_opt (DP k, DP omega, DP req_prec, int Npts_K, int Npts_W, I_table Itable)
  730. {
  731. // CAREFUL !! This is S(k, omega) = 2 S(k, w)
  732. Vect_DP args_to_SF(5);
  733. args_to_SF[0] = k;
  734. args_to_SF[1] = omega;
  735. args_to_SF[2] = req_prec;
  736. args_to_SF[3] = DP(Npts_K);
  737. args_to_SF[4] = DP(Npts_W);
  738. return(2.0 * SF_4p_kwKW_opt (args_to_SF, Itable));
  739. }
  740. /******************************************************************************************/
  741. void Translate_raw_4p_data (DP k, int dim_w, const char* SFraw_Cstr, const char* SF_Cstr,
  742. const char* SFsrc_Cstr, I_table Itable)
  743. {
  744. DP omegamin = 0.5 * wmin_4p (k); // Correct for factor of 2 in E between me & Bougourzi
  745. DP omegamax = 0.5 * wmax_4p (k);
  746. DP alpha_in;
  747. DP SF_in;
  748. DP alpha_in_old = -1.0;
  749. DP SF_in_old = -1.0;
  750. DP* alpha = new DP[dim_w];
  751. DP* omega = new DP[dim_w];
  752. DP* SF_4p_dat = new DP[dim_w];
  753. DP* SF_2p_dat = new DP[dim_w];
  754. int* index = new int[dim_w];
  755. ifstream SFraw;
  756. SFraw.open(SFraw_Cstr);
  757. if (SFraw.fail()) ABACUSerror("Couldn't open SFraw file in Translate.");
  758. int i = 0;
  759. for (i = 0; i < dim_w; ++i) {
  760. if (SFraw.peek() == EOF) ABACUSerror("Not enough data points in file...");
  761. index[i] = i;
  762. SFraw >> alpha_in >> SF_in;
  763. alpha[i] = alpha_in;
  764. omega[i] = omegamin + (omegamax - omegamin) * (1.0 - cos(alpha_in));
  765. // CAREFUL !!! SF_in is S (k, w), and we want S (k, omega) = 2 S(k, w)
  766. SF_4p_dat[i] = 2.0 * SF_in/((omegamax - omegamin) * sin(alpha_in));
  767. SF_2p_dat[i] = SF_2p (k, omega[i], Itable); // This already is S(k, omega)
  768. alpha_in_old = alpha_in;
  769. SF_in_old = SF_in;
  770. }
  771. SFraw.close();
  772. if (i != dim_w) {
  773. ABACUSerror("Incorrect number of data points in file.");
  774. }
  775. QuickSort (omega, index, 0, dim_w - 1);
  776. DP fixed_k_sr_2p = 0.0;
  777. DP fixed_k_sr_4p = 0.0;
  778. DP full_sr_2p = 0.0;
  779. DP full_sr_4p = 0.0;
  780. DP Jac_dalpha = 0.0; // This is domega = (omegamax - omegamin) sin alpha dalpha
  781. ofstream SF;
  782. SF.open(SF_Cstr);
  783. for (int j = 0; j < dim_w; ++j)
  784. SF << setprecision(16) << omega[j] << "\t" << SF_4p_dat[index[j] ] << "\t" << SF_2p_dat[index[j] ] << "\t"
  785. << SF_4p_dat[index[j] ] + SF_2p_dat[index[j] ] << endl;
  786. SF.close();
  787. // Compute first moment sum rule
  788. Jac_dalpha = (omegamax - omegamin) * sin(alpha[index[1] ]) * 0.5 * (alpha[index[2] ] - alpha[index[0] ]);
  789. fixed_k_sr_4p += Jac_dalpha * (omega[0] * SF_4p_dat[index[0] ] + omega[1] * SF_4p_dat[index[1] ]);
  790. fixed_k_sr_2p += Jac_dalpha * (omega[0] * SF_2p_dat[index[0] ] + omega[1] * SF_2p_dat[index[1] ]);
  791. full_sr_4p += Jac_dalpha * (SF_4p_dat[index[0] ] + SF_4p_dat[index[1] ]);
  792. full_sr_2p += Jac_dalpha * (SF_2p_dat[index[0] ] + SF_2p_dat[index[1] ]);
  793. for (int i = 2; i < dim_w - 2; ++i) {
  794. Jac_dalpha = (omegamax - omegamin) * sin(alpha[index[i] ]) * 0.5 * (alpha[index[i + 1] ] - alpha[index[i - 1] ]);
  795. fixed_k_sr_4p += Jac_dalpha * omega[i] * SF_4p_dat[index[i] ];
  796. fixed_k_sr_2p += Jac_dalpha * omega[i] * SF_2p_dat[index[i] ];
  797. full_sr_4p += Jac_dalpha * SF_4p_dat[index[i] ];
  798. full_sr_2p += Jac_dalpha * SF_2p_dat[index[i] ];
  799. }
  800. Jac_dalpha = (omegamax - omegamin) * sin(alpha[index[dim_w - 2] ])
  801. * 0.5 * (alpha[index[dim_w - 1] ] - alpha[index[dim_w - 3] ]);
  802. fixed_k_sr_4p += Jac_dalpha * (omega[dim_w - 2] * SF_4p_dat[index[dim_w - 2] ]
  803. + omega[dim_w - 1] * SF_4p_dat[index[dim_w - 1] ]);
  804. fixed_k_sr_2p += Jac_dalpha * (omega[dim_w - 2] * SF_2p_dat[index[dim_w - 2] ]
  805. + omega[dim_w - 1] * SF_2p_dat[index[dim_w - 1] ]);
  806. full_sr_4p += Jac_dalpha * (SF_4p_dat[index[dim_w - 2] ] + SF_4p_dat[index[dim_w - 1] ]);
  807. full_sr_2p += Jac_dalpha * (SF_2p_dat[index[dim_w - 2] ] + SF_2p_dat[index[dim_w - 1] ]);
  808. ofstream SFsrc;
  809. SFsrc.open(SFsrc_Cstr);
  810. // Reintroduce 1/PI since \int domega/2PI
  811. full_sr_4p /= twoPI;
  812. full_sr_2p /= twoPI;
  813. fixed_k_sr_4p /= twoPI;
  814. fixed_k_sr_2p /= twoPI;
  815. SFsrc << setprecision(16) << fixed_k_sr_4p << "\t"
  816. << fixed_k_sr_2p << "\t"
  817. << fixed_k_sr_4p + fixed_k_sr_2p << "\t"
  818. << fixed_k_sr_4p/Fixed_k_sumrule_omega(k) << "\t"
  819. << fixed_k_sr_2p/Fixed_k_sumrule_omega(k) << "\t"
  820. << (fixed_k_sr_4p + fixed_k_sr_2p)/Fixed_k_sumrule_omega(k) << endl;
  821. SFsrc << setprecision(16) << full_sr_4p << "\t" << full_sr_2p << "\t" << full_sr_4p + full_sr_2p << "\t"
  822. << 0.25 * full_sr_4p << "\t" << 0.25 * full_sr_2p << "\t" << 0.25 * (full_sr_4p + full_sr_2p) << endl;
  823. SFsrc.close();
  824. delete[] omega;
  825. delete[] SF_4p_dat;
  826. delete[] SF_2p_dat;
  827. delete[] index;
  828. return;
  829. }
  830. void Translate_raw_4p_data_cosh (DP k, int dim_w, const char* SFraw_Cstr, const char* SF_Cstr,
  831. const char* SFsrc_Cstr, I_table Itable)
  832. {
  833. // Here, omega = omegamin * cosh(alpha)
  834. DP omegamin = 0.5 * wmin_4p (k); // Correct for factor of 2 in E between me & Bougourzi
  835. DP alpha_in;
  836. DP SF_in;
  837. DP alpha_in_old = -1.0;
  838. DP SF_in_old = -1.0;
  839. DP* alpha = new DP[dim_w];
  840. DP* omega = new DP[dim_w];
  841. DP* SF_4p_dat = new DP[dim_w];
  842. DP* SF_2p_dat = new DP[dim_w];
  843. int* index = new int[dim_w];
  844. ifstream SFraw;
  845. SFraw.open(SFraw_Cstr);
  846. if (SFraw.fail()) ABACUSerror("Couldn't open SFraw file in Translate.");
  847. int i = 0;
  848. for (i = 0; i < dim_w; ++i) {
  849. if (SFraw.peek() == EOF) ABACUSerror("Not enough data points in file...");
  850. index[i] = i;
  851. SFraw >> alpha_in >> SF_in;
  852. alpha[i] = alpha_in;
  853. omega[i] = omegamin * cosh(alpha_in);
  854. // CAREFUL !!! SF_in is S (k, w), and we want S (k, omega) = 2 S(k, w)
  855. SF_4p_dat[i] = 2.0 * SF_in/(omegamin * sinh(alpha_in));
  856. SF_2p_dat[i] = SF_2p (k, omega[i], Itable); // This already is S(k, omega)
  857. alpha_in_old = alpha_in;
  858. SF_in_old = SF_in;
  859. }
  860. SFraw.close();
  861. if (i != dim_w) {
  862. ABACUSerror("Incorrect number of data points in file.");
  863. }
  864. QuickSort (omega, index, 0, dim_w - 1);
  865. DP fixed_k_sr_2p = 0.0;
  866. DP fixed_k_sr_4p = 0.0;
  867. DP full_sr_2p = 0.0;
  868. DP full_sr_4p = 0.0;
  869. DP Jac_dalpha = 0.0; // This is domega = omegamin sinh alpha dalpha
  870. ofstream SF;
  871. SF.open(SF_Cstr);
  872. for (int j = 0; j < dim_w; ++j)
  873. SF << setprecision(16) << omega[j] << "\t" << SF_4p_dat[index[j] ] << "\t" << SF_2p_dat[index[j] ] << "\t"
  874. << SF_4p_dat[index[j] ] + SF_2p_dat[index[j] ] << endl;
  875. SF.close();
  876. // Compute first moment sum rule
  877. Jac_dalpha = omegamin * sinh(alpha[index[1] ]) * 0.5 * (alpha[index[2] ] - alpha[index[0] ]);
  878. fixed_k_sr_4p += Jac_dalpha * (omega[0] * SF_4p_dat[index[0] ] + omega[1] * SF_4p_dat[index[1] ]);
  879. fixed_k_sr_2p += Jac_dalpha * (omega[0] * SF_2p_dat[index[0] ] + omega[1] * SF_2p_dat[index[1] ]);
  880. full_sr_4p += Jac_dalpha * (SF_4p_dat[index[0] ] + SF_4p_dat[index[1] ]);
  881. full_sr_2p += Jac_dalpha * (SF_2p_dat[index[0] ] + SF_2p_dat[index[1] ]);
  882. for (int i = 2; i < dim_w - 2; ++i) {
  883. Jac_dalpha = omegamin * sinh(alpha[index[i] ]) * 0.5 * (alpha[index[i + 1] ] - alpha[index[i - 1] ]);
  884. fixed_k_sr_4p += Jac_dalpha * omega[i] * SF_4p_dat[index[i] ];
  885. fixed_k_sr_2p += Jac_dalpha * omega[i] * SF_2p_dat[index[i] ];
  886. full_sr_4p += Jac_dalpha * SF_4p_dat[index[i] ];
  887. full_sr_2p += Jac_dalpha * SF_2p_dat[index[i] ];
  888. }
  889. Jac_dalpha = omegamin * sinh(alpha[index[dim_w - 2] ]) * 0.5 * (alpha[index[dim_w - 1] ] - alpha[index[dim_w - 3] ]);
  890. fixed_k_sr_4p += Jac_dalpha * (omega[dim_w - 2] * SF_4p_dat[index[dim_w - 2] ]
  891. + omega[dim_w - 1] * SF_4p_dat[index[dim_w - 1] ]);
  892. fixed_k_sr_2p += Jac_dalpha * (omega[dim_w - 2] * SF_2p_dat[index[dim_w - 2] ]
  893. + omega[dim_w - 1] * SF_2p_dat[index[dim_w - 1] ]);
  894. full_sr_4p += Jac_dalpha * (SF_4p_dat[index[dim_w - 2] ] + SF_4p_dat[index[dim_w - 1] ]);
  895. full_sr_2p += Jac_dalpha * (SF_2p_dat[index[dim_w - 2] ] + SF_2p_dat[index[dim_w - 1] ]);
  896. ofstream SFsrc;
  897. SFsrc.open(SFsrc_Cstr);
  898. // Reintroduce 1/PI since \int domega/2PI
  899. full_sr_4p /= twoPI;
  900. full_sr_2p /= twoPI;
  901. fixed_k_sr_4p /= twoPI;
  902. fixed_k_sr_2p /= twoPI;
  903. SFsrc << setprecision(16) << fixed_k_sr_4p << "\t"
  904. << fixed_k_sr_2p << "\t"
  905. << fixed_k_sr_4p + fixed_k_sr_2p << "\t"
  906. << fixed_k_sr_4p/Fixed_k_sumrule_omega(k) << "\t"
  907. << fixed_k_sr_2p/Fixed_k_sumrule_omega(k) << "\t"
  908. << (fixed_k_sr_4p + fixed_k_sr_2p)/Fixed_k_sumrule_omega(k) << endl;
  909. SFsrc << setprecision(16) << full_sr_4p << "\t" << full_sr_2p << "\t" << full_sr_4p + full_sr_2p << "\t"
  910. << 0.25 * full_sr_4p << "\t" << 0.25 * full_sr_2p << "\t" << 0.25 * (full_sr_4p + full_sr_2p) << endl;
  911. SFsrc.close();
  912. delete[] omega;
  913. delete[] SF_4p_dat;
  914. delete[] SF_2p_dat;
  915. delete[] index;
  916. return;
  917. }
  918. // Function producing a fixed k scan, with data file
  919. DP SF_4p_rec (DP k, DP req_prec, int max_rec_w, int max_rec, I_table Itable)
  920. {
  921. stringstream SFraw_stringstream;
  922. string SFraw_string;
  923. SFraw_stringstream << "SF_4p_k_" << k << "_prec_" << req_prec << "_max_rec_w_" << max_rec_w
  924. << "_max_rec_" << max_rec << ".raw";
  925. SFraw_string = SFraw_stringstream.str();
  926. const char* SFraw_Cstr = SFraw_string.c_str();
  927. stringstream SF_stringstream;
  928. string SF_string;
  929. SF_stringstream << "SF_4p_k_" << k << "_prec_" << req_prec << "_max_rec_w_" << max_rec_w
  930. << "_max_rec_" << max_rec << ".dat";
  931. SF_string = SF_stringstream.str();
  932. const char* SF_Cstr = SF_string.c_str();
  933. stringstream SFsrc_stringstream;
  934. string SFsrc_string;
  935. SFsrc_stringstream << "SF_4p_k_" << k << "_prec_" << req_prec << "_max_rec_w_" << max_rec_w
  936. << "_max_rec_" << max_rec << ".src";
  937. SFsrc_string = SFsrc_stringstream.str();
  938. const char* SFsrc_Cstr = SFsrc_string.c_str();
  939. ofstream SFraw_outfile;
  940. SFraw_outfile.open(SFraw_Cstr);
  941. ofstream SFsrc_outfile;
  942. SFsrc_outfile.open(SFsrc_Cstr, ofstream::app);
  943. Vect_DP args_to_SF(4);
  944. args_to_SF[0] = k;
  945. args_to_SF[1] = 0.0; // integration variable
  946. args_to_SF[2] = req_prec;
  947. args_to_SF[3] = DP(max_rec);
  948. // Version using omega = omegamin + (omegamax - omegamin) * (1-cos(alpha))
  949. DP answer = Integrate_rec_using_table (SF_4p_kwKW_alpha, args_to_SF, 1, Itable, 0.0, 0.5*PI, req_prec, max_rec_w, SFraw_outfile)/twoPI;
  950. SFraw_outfile.close();
  951. SFsrc_outfile << answer << endl;
  952. SFsrc_outfile.close();
  953. // Translate raw data into SF_4p (k,omega) data
  954. Translate_raw_4p_data (k, int(pow(3.0, max_rec_w + 2)), SFraw_Cstr, SF_Cstr, SFsrc_Cstr, Itable);
  955. return(answer);
  956. }
  957. Integral_result SF_4p_opt (DP k, DP req_prec, int Npts_w, int Npts_K, int Npts_W, I_table Itable)
  958. {
  959. stringstream SFraw_stringstream;
  960. string SFraw_string;
  961. SFraw_stringstream << "SF_4p_k_" << k << "_prec_" << req_prec << "_Npts_" << Npts_w << "_"
  962. << Npts_K << "_" << Npts_W << ".raw";
  963. SFraw_string = SFraw_stringstream.str();
  964. const char* SFraw_Cstr = SFraw_string.c_str();
  965. stringstream SF_stringstream;
  966. string SF_string;
  967. SF_stringstream << "SF_4p_k_" << k << "_prec_" << req_prec << "_Npts_" << Npts_w << "_"
  968. << Npts_K << "_" << Npts_W << ".dat";
  969. SF_string = SF_stringstream.str();
  970. const char* SF_Cstr = SF_string.c_str();
  971. stringstream SFsrc_stringstream;
  972. string SFsrc_string;
  973. SFsrc_stringstream << "SF_4p_k_" << k << "_prec_" << req_prec << "_Npts_" << Npts_w << "_"
  974. << Npts_K << "_" << Npts_W << ".src";
  975. SFsrc_string = SFsrc_stringstream.str();
  976. const char* SFsrc_Cstr = SFsrc_string.c_str();
  977. ofstream SFraw_outfile;
  978. SFraw_outfile.open(SFraw_Cstr);
  979. ofstream SFsrc_outfile;
  980. SFsrc_outfile.open(SFsrc_Cstr);
  981. Vect_DP args_to_SF(5);
  982. args_to_SF[0] = k;
  983. args_to_SF[1] = 0.0; // integration variable
  984. args_to_SF[2] = req_prec;
  985. args_to_SF[3] = DP(Npts_K);
  986. args_to_SF[4] = DP(Npts_W);
  987. // Version using omega = omegamin + (omegamax - omegamin) * (1-cos(alpha))
  988. Integral_result answer = Integrate_optimal_using_table (SF_4p_kwKW_alpha_opt, args_to_SF, 1,
  989. Itable, 0.0, 0.5*PI, req_prec, 1.0e-32, Npts_w, SFraw_outfile);
  990. // Version using omega = omegamin * cosh(alpha)
  991. //Integral_result answer = Integrate_optimal_using_table (SF_4p_kwKW_cosh_alpha_opt, args_to_SF, 1, Itable, 0.0,
  992. //acosh(wmax_4p(k)/wmin_4p(k)), req_prec, 1.0e-32, Npts_w, SFraw_outfile);
  993. answer.integ_est /= twoPI;
  994. answer.abs_prec /= twoPI;
  995. SFraw_outfile.close();
  996. SFsrc_outfile << answer << endl;
  997. SFsrc_outfile.close();
  998. // Translate raw data into SF_4p (k,omega) data
  999. Translate_raw_4p_data (k, answer.n_vals, SFraw_Cstr, SF_Cstr, SFsrc_Cstr, Itable);
  1000. return(answer);
  1001. }
  1002. Integral_result SF_4p_opt (DP k, DP req_prec, int Npts_w, int Npts_KW, I_table Itable)
  1003. {
  1004. return(SF_4p_opt (k, req_prec, Npts_w, Npts_KW, Npts_KW, Itable));
  1005. }
  1006. Integral_result SF_4p_opt (DP k, DP req_prec, int Npts, I_table Itable)
  1007. {
  1008. return(SF_4p_opt (k, req_prec, Npts, Npts, Npts, Itable));
  1009. }
  1010. //******************************** Functions to produce files similar to ABACUS **********************************
  1011. void Produce_SF_2p_file (int N, int Nomega, DP omegamax, I_table Itable)
  1012. {
  1013. // IMPORTANT NOTE: this produces a file with Szz !!
  1014. DP ABACUS_factor = 1.0;
  1015. if (N % 2) ABACUSerror("Please use N even in Produce_SF_2p_file.");
  1016. stringstream SF_stringstream;
  1017. string SF_string;
  1018. SF_stringstream << "SF_2p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << ".dat";
  1019. SF_string = SF_stringstream.str();
  1020. const char* SF_Cstr = SF_string.c_str();
  1021. Write_K_File (N, 0, N);
  1022. Write_Omega_File (Nomega, 0.0, omegamax);
  1023. int dim_K = N/2 + 1;
  1024. DP* K = new DP[dim_K];
  1025. for (int iK = 0; iK < dim_K; ++iK) K[iK] = (twoPI * iK)/N;
  1026. DP* omega = new DP[Nomega];
  1027. for (int iw = 0; iw < Nomega; ++iw) omega[iw] = omegamax * (iw + 0.5)/Nomega;
  1028. DP* SF_2p_dat = new DP[dim_K * Nomega];
  1029. DP srtot = 0.0;
  1030. Vect_DP sr1(0.0, dim_K);
  1031. for (int iK = 0; iK < dim_K; ++iK)
  1032. for (int iw = 0; iw < Nomega; ++iw) {
  1033. SF_2p_dat[dim_K * iw + iK] = ABACUS_factor * SF_2p (K[iK], omega[iw], Itable);
  1034. srtot += (iK == N/2 ? 1.0 : 2.0) * SF_2p_dat[dim_K * iw + iK];
  1035. sr1[iK] += omega[iw] * SF_2p_dat[dim_K * iw + iK];
  1036. }
  1037. ofstream SF_outfile;
  1038. SF_outfile.open(SF_Cstr);
  1039. SF_outfile.precision(14);
  1040. for (int iw = 0; iw < Nomega; ++iw) {
  1041. for (int iK = 0; iK < dim_K; ++iK)
  1042. SF_outfile << SF_2p_dat[dim_K * iw + iK] << "\t";
  1043. for (int iKt = dim_K - 2; iKt >= 0; --iKt) // put K in [PI, 2PI] back in
  1044. SF_outfile << SF_2p_dat[dim_K * iw + iKt] << "\t";
  1045. SF_outfile << endl;
  1046. }
  1047. SF_outfile.close();
  1048. // Do sum rule files:
  1049. stringstream SRC_stringstream;
  1050. string SRC_string;
  1051. SRC_stringstream << "SF_2p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << ".src";
  1052. SRC_string = SRC_stringstream.str();
  1053. const char* SRC_Cstr = SRC_string.c_str();
  1054. ofstream SRC_outfile;
  1055. SRC_outfile.open(SRC_Cstr);
  1056. SRC_outfile.precision(14);
  1057. SRC_outfile << srtot * omegamax/(twoPI * Nomega * N) << "\t" << srtot * 4.0 * omegamax/(twoPI * Nomega * N) << endl;
  1058. SRC_outfile.close();
  1059. stringstream SR1_stringstream;
  1060. string SR1_string;
  1061. SR1_stringstream << "SF_2p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << ".sr1";
  1062. SR1_string = SR1_stringstream.str();
  1063. const char* SR1_Cstr = SR1_string.c_str();
  1064. ofstream SR1_outfile;
  1065. SR1_outfile.open(SR1_Cstr);
  1066. SR1_outfile.precision(14);
  1067. for (int iK = 1; iK < dim_K; ++iK)
  1068. SR1_outfile << iK << "\t" << K[iK] << "\t" << sr1[iK] * omegamax/(twoPI * Nomega)
  1069. << "\t" << -((1.0 - cos(K[iK])) * 2.0 * (0.25 - log(2.0))/3.0) << "\t"
  1070. << -sr1[iK] * omegamax/(twoPI * Nomega)/((1.0 - cos(K[iK])) * 2.0 * (0.25 - log(2.0))/3.0) << endl;
  1071. SR1_outfile.close();
  1072. return;
  1073. }
  1074. void Produce_SF_4p_file (int N, int Nomega, DP omegamax, DP req_prec, int max_rec, I_table Itable)
  1075. {
  1076. // IMPORTANT NOTE: this produces a file with the same normalization as Smp from ABACUS,
  1077. // so we use a factor of 2 (for Szz -> Smp) and 2PI.
  1078. DP ABACUS_factor = 1.0;
  1079. if (N % 2) ABACUSerror("Please use N even in Produce_SF_2p_file.");
  1080. stringstream SF_stringstream;
  1081. string SF_string;
  1082. SF_stringstream << "SF_4p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << "_prec_" << req_prec
  1083. << "_max_rec_" << max_rec << ".dat";
  1084. SF_string = SF_stringstream.str();
  1085. const char* SF_Cstr = SF_string.c_str();
  1086. Write_K_File (N, 0, N);
  1087. Write_Omega_File (Nomega, 0.0, omegamax);
  1088. int dim_K = N/2 + 1;
  1089. DP* K = new DP[dim_K];
  1090. for (int iK = 0; iK < dim_K; ++iK) K[iK] = (twoPI * iK)/N;
  1091. DP* omega = new DP[Nomega];
  1092. for (int iw = 0; iw < Nomega; ++iw) omega[iw] = omegamax * (iw + 0.5)/Nomega;
  1093. DP* SF_4p_dat = new DP[dim_K * Nomega];
  1094. DP srtot = 0.0;
  1095. Vect_DP sr1(0.0, dim_K);
  1096. for (int iK = 0; iK < dim_K; ++iK)
  1097. for (int iw = 0; iw < Nomega; ++iw) {
  1098. SF_4p_dat[dim_K * iw + iK] = ABACUS_factor * SF_4p_rec (K[iK], omega[iw], req_prec, max_rec, Itable);
  1099. srtot += (iK == N/2 ? 1.0 : 2.0) * SF_4p_dat[dim_K * iw + iK];
  1100. sr1[iK] += omega[iw] * SF_4p_dat[dim_K * iw + iK];
  1101. }
  1102. ofstream SF_outfile;
  1103. SF_outfile.open(SF_Cstr);
  1104. SF_outfile.precision(14);
  1105. for (int iw = 0; iw < Nomega; ++iw) {
  1106. for (int iK = 0; iK < dim_K; ++iK)
  1107. SF_outfile << SF_4p_dat[dim_K * iw + iK] << "\t";
  1108. for (int iKt = dim_K - 2; iKt >= 0; --iKt) // put K in [PI, 2PI] back in
  1109. SF_outfile << SF_4p_dat[dim_K * iw + iKt] << "\t";
  1110. SF_outfile << endl;
  1111. }
  1112. SF_outfile.close();
  1113. // Do sum rule files:
  1114. stringstream SRC_stringstream;
  1115. string SRC_string;
  1116. SRC_stringstream << "SF_4p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << "_prec_" << req_prec
  1117. << "_max_rec_" << max_rec << ".src";
  1118. SRC_string = SRC_stringstream.str();
  1119. const char* SRC_Cstr = SRC_string.c_str();
  1120. ofstream SRC_outfile;
  1121. SRC_outfile.open(SRC_Cstr);
  1122. SRC_outfile.precision(14);
  1123. SRC_outfile << srtot * omegamax/(twoPI * Nomega * N) << "\t" << srtot * 4.0 * omegamax/(twoPI * Nomega * N) << endl;
  1124. SRC_outfile.close();
  1125. stringstream SR1_stringstream;
  1126. string SR1_string;
  1127. SR1_stringstream << "SF_4p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << "_prec_" << req_prec
  1128. << "_max_rec_" << max_rec << ".sr1";
  1129. SR1_string = SR1_stringstream.str();
  1130. const char* SR1_Cstr = SR1_string.c_str();
  1131. ofstream SR1_outfile;
  1132. SR1_outfile.open(SR1_Cstr);
  1133. SR1_outfile.precision(14);
  1134. for (int iK = 1; iK < dim_K; ++iK)
  1135. SR1_outfile << iK << "\t" << K[iK] << "\t" << sr1[iK] * omegamax/(twoPI * Nomega)
  1136. << "\t" << -((1.0 - cos(K[iK])) * 2.0 * (0.25 - log(2.0))/3.0) << "\t"
  1137. << -sr1[iK] * omegamax/(twoPI * Nomega)/((1.0 - cos(K[iK])) * 2.0 * (0.25 - log(2.0))/3.0) << endl;
  1138. SR1_outfile.close();
  1139. return;
  1140. }
  1141. void Produce_SF_4p_file (int N, int Nomega, DP omegamax, DP req_prec, int Npts_K, int Npts_W, I_table Itable)
  1142. {
  1143. // IMPORTANT NOTE: this produces a file with the same normalization as Smp from ABACUS,
  1144. // so we use a factor of 2 (for Szz -> Smp) and 2PI.
  1145. DP ABACUS_factor = 1.0;
  1146. if (N % 2) ABACUSerror("Please use N even in Produce_SF_2p_file.");
  1147. stringstream SF_stringstream;
  1148. string SF_string;
  1149. SF_stringstream << "SF_4p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << "_prec_" << req_prec
  1150. << "_Npts_K_" << Npts_K << "_Npts_W_" << Npts_W << ".dat";
  1151. SF_string = SF_stringstream.str();
  1152. const char* SF_Cstr = SF_string.c_str();
  1153. Write_K_File (N, 0, N);
  1154. Write_Omega_File (Nomega, 0.0, omegamax);
  1155. int dim_K = N/2 + 1;
  1156. DP* K = new DP[dim_K];
  1157. for (int iK = 0; iK < dim_K; ++iK) K[iK] = (twoPI * iK)/N;
  1158. DP* omega = new DP[Nomega];
  1159. for (int iw = 0; iw < Nomega; ++iw) omega[iw] = omegamax * (iw + 0.5)/Nomega;
  1160. DP* SF_4p_dat = new DP[dim_K * Nomega];
  1161. DP srtot = 0.0;
  1162. Vect_DP sr1(0.0, dim_K);
  1163. for (int iK = 0; iK < dim_K; ++iK)
  1164. for (int iw = 0; iw < Nomega; ++iw) {
  1165. SF_4p_dat[dim_K * iw + iK] = ABACUS_factor * SF_4p_opt (K[iK], omega[iw], req_prec, Npts_K, Npts_W, Itable);
  1166. srtot += (iK == N/2 ? 1.0 : 2.0) * SF_4p_dat[dim_K * iw + iK];
  1167. sr1[iK] += omega[iw] * SF_4p_dat[dim_K * iw + iK];
  1168. }
  1169. // Output SF:
  1170. ofstream SF_outfile;
  1171. SF_outfile.open(SF_Cstr);
  1172. SF_outfile.precision(14);
  1173. for (int iw = 0; iw < Nomega; ++iw) {
  1174. for (int iK = 0; iK < dim_K; ++iK)
  1175. SF_outfile << SF_4p_dat[dim_K * iw + iK] << "\t";
  1176. for (int iKt = dim_K - 2; iKt >= 0; --iKt) // put K in [PI, 2PI] back in
  1177. SF_outfile << SF_4p_dat[dim_K * iw + iKt] << "\t";
  1178. SF_outfile << endl;
  1179. }
  1180. SF_outfile.close();
  1181. // Do sum rule files:
  1182. stringstream SRC_stringstream;
  1183. string SRC_string;
  1184. SRC_stringstream << "SF_4p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << "_prec_" << req_prec
  1185. << "_Npts_K_" << Npts_K << "_Npts_W_" << Npts_W << ".src";
  1186. SRC_string = SRC_stringstream.str();
  1187. const char* SRC_Cstr = SRC_string.c_str();
  1188. ofstream SRC_outfile;
  1189. SRC_outfile.open(SRC_Cstr);
  1190. SRC_outfile.precision(14);
  1191. SRC_outfile << srtot * omegamax/(twoPI * Nomega * N) << "\t" << srtot * 4.0 * omegamax/(twoPI * Nomega * N) << endl;
  1192. SRC_outfile.close();
  1193. stringstream SR1_stringstream;
  1194. string SR1_string;
  1195. SR1_stringstream << "SF_4p_N_" << N << "_Nw_" << Nomega << "_wmax_" << omegamax << "_prec_" << req_prec
  1196. << "_Npts_K_" << Npts_K << "_Npts_W_" << Npts_W << ".sr1";
  1197. SR1_string = SR1_stringstream.str();
  1198. const char* SR1_Cstr = SR1_string.c_str();
  1199. ofstream SR1_outfile;
  1200. SR1_outfile.open(SR1_Cstr);
  1201. SR1_outfile.precision(14);
  1202. for (int iK = 1; iK < dim_K; ++iK)
  1203. SR1_outfile << iK << "\t" << K[iK] << "\t" << sr1[iK] * omegamax/(twoPI * Nomega)
  1204. << "\t" << -((1.0 - cos(K[iK])) * 2.0 * (0.25 - log(2.0))/3.0) << "\t"
  1205. << -sr1[iK] * omegamax/(twoPI * Nomega)/((1.0 - cos(K[iK])) * 2.0 * (0.25 - log(2.0))/3.0) << endl;
  1206. SR1_outfile.close();
  1207. return;
  1208. }
  1209. } // namespace ABACUS