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.

Offsets.cc 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: src/BETHE/Offsets.cc
  6. Purpose: defines functions in Offsets class.
  7. ***********************************************************/
  8. #include "ABACUS.h"
  9. using namespace std;
  10. namespace ABACUS {
  11. // Function definitions: class Offsets
  12. Offsets::Offsets () : base(), Tableau(Vect<Young_Tableau>()), type_id(0LL), id(0LL), maxid(0LL) {};
  13. Offsets::Offsets (const Offsets& RefOffset) // copy constructor
  14. : base(RefOffset.base), Tableau(Vect<Young_Tableau> (2 * base.Nrap.size() + 2)), type_id(RefOffset.type_id), id(RefOffset.id), maxid(RefOffset.maxid)
  15. {
  16. for (int i = 0; i < 2 * base.Nrap.size() + 2; ++i) Tableau[i] = RefOffset.Tableau[i];
  17. }
  18. Offsets::Offsets (const Heis_Base& RefBase, long long int req_type_id)
  19. // sets all tableaux to empty ones, with nparticles(req_type_id) at each level
  20. {
  21. // Build nparticles vector from req_type_id
  22. Vect<int> nparticles(0, 2* RefBase.Nrap.size() + 2);
  23. long long int factor = pow_ulli (10LL, nparticles.size() - 1);
  24. long long int id_eff = req_type_id;
  25. for (int i = 0; i < nparticles.size(); ++i) {
  26. nparticles[nparticles.size() - 1 - i] = id_eff/factor;
  27. id_eff -= factor * nparticles[nparticles.size() - 1 - i];
  28. factor /= 10LL;
  29. }
  30. // Check if we've got the right vector...
  31. long long int idcheck = Offsets_type_id (nparticles);
  32. if (idcheck != req_type_id) ABACUSerror("idcheck != req_type_id in Offsets constructor.");
  33. (*this) = Offsets(RefBase, nparticles);
  34. }
  35. Offsets::Offsets (const Heis_Base& RefBase, Vect<int> nparticles) // sets all tableaux to empty ones, with nparticles at each level
  36. : base(RefBase), Tableau(Vect<Young_Tableau> (2 * base.Nrap.size() + 2)), type_id(Offsets_type_id (nparticles)), id(0LL), maxid(0LL)
  37. {
  38. // Checks on nparticles vector:
  39. if (nparticles.size() != 2 * base.Nrap.size() + 2) ABACUSerror("Wrong nparticles.size in Offsets constructor.");
  40. //if (base.Nrap[0] != (nparticles[3] + nparticles[2] + base.Mdown - nparticles[0] - nparticles[1])) ABACUSerror("Wrong Nrap[0] in Offsets constructor.");
  41. if (nparticles[3] + nparticles[2] != nparticles[0] + nparticles[1]) {
  42. cout << nparticles[0] << "\t" << nparticles[1] << "\t" << nparticles[2] << "\t" << nparticles[3] << endl;
  43. ABACUSerror("Wrong Npar[0-3] in Offsets constructor.");
  44. }
  45. for (int base_level = 1; base_level < base.Nrap.size(); ++ base_level)
  46. if (base.Nrap[base_level] != nparticles[2*base_level + 2] + nparticles[2*base_level + 3]) {
  47. cout << base_level << "\t" << base.Nrap[base_level] << "\t" << nparticles[2*base_level + 2] << "\t" << nparticles[2*base_level + 3] << endl;
  48. ABACUSerror("Wrong Nrap[] in Offsets constructor.");
  49. }
  50. // nparticles[0,1]: number of holes on R and L side in GS interval
  51. if (nparticles[0] > (base.Nrap[0] + 1)/2) ABACUSerror("nparticles[0] too large in Offsets constructor.");
  52. if (nparticles[1] > base.Nrap[0]/2) ABACUSerror("nparticles[1] too large in Offsets constructor.");
  53. // nparticles[2,3]: number of particles of type 0 on R and L side out of GS interval
  54. if (nparticles[2] > (base.Ix2_max[0] - base.Nrap[0] + 1)/2) ABACUSerror("nparticles[2] too large in Offsets constructor.");
  55. if (nparticles[3] > (base.Ix2_max[0] - base.Nrap[0] + 1)/2) ABACUSerror("nparticles[3] too large in Offsets constructor.");
  56. for (int base_level = 1; base_level < base.Nrap.size(); ++ base_level)
  57. if ((nparticles[2*base_level + 2] > 0 && nparticles[2*base_level + 2] > (base.Ix2_max[base_level] - ((base.Nrap[base_level] + 1) % 2) + 2)/2)
  58. //|| (nparticles[2*base_level + 3] > 0 && nparticles[2*base_level + 3] > (base.Ix2_max[base_level] - (base.Nrap[base_level] % 2) - 1)/2)) {
  59. || (nparticles[2*base_level + 3] > 0
  60. && nparticles[2*base_level + 3] > base.Ix2_max[base_level] + 1 - (base.Ix2_max[base_level] - ((base.Nrap[base_level] + 1) % 2) + 2)/2)) {
  61. cout << base_level << "\t" << nparticles[2*base_level + 2] << "\t" << (base.Ix2_max[base_level] - ((base.Nrap[base_level] + 1) % 2) + 2)/2
  62. << "\t" << nparticles[2*base_level + 3] << "\t" << (base.Ix2_max[base_level] - (base.Nrap[base_level] % 2) - 1)/2
  63. << "\t" << (nparticles[2*base_level + 2] > 0) << "\t" << (nparticles[2*base_level + 2] > (base.Ix2_max[base_level] - ((base.Nrap[base_level] + 1) % 2) + 2)/2)
  64. //<< "\t" << (nparticles[2*base_level + 3] > 0) << "\t" << (nparticles[2*base_level + 3] > (base.Ix2_max[base_level] - (base.Nrap[base_level] % 2) - 1)/2)
  65. << "\t" << (nparticles[2*base_level + 3] > 0) << "\t"
  66. << (nparticles[2*base_level + 3] > base.Ix2_max[base_level] + 1 - (base.Ix2_max[base_level] - ((base.Nrap[base_level] + 1) % 2) + 2)/2)
  67. << endl;
  68. ABACUSerror("nparticles too large in Offsets constructor.");
  69. }
  70. // Check sum of rapidities
  71. // Holes in GS interval
  72. Tableau[0] = Young_Tableau(nparticles[0], (base.Nrap[0] + 1)/2 - nparticles[0]);
  73. Tableau[1] = Young_Tableau(nparticles[1], base.Nrap[0]/2 - nparticles[1], Tableau[0]);
  74. // Particles of type 0 out of GS interval
  75. Tableau[2] = Young_Tableau(nparticles[2], (base.Ix2_max[0] - base.Nrap[0] + 1)/2 - nparticles[2], Tableau[0]);
  76. Tableau[3] = Young_Tableau(nparticles[3], (base.Ix2_max[0] - base.Nrap[0] + 1)/2 - nparticles[3], Tableau[2]);
  77. // Tableaux of index i = 2,...: data about string type i/2-1.
  78. for (int base_level = 1; base_level < base.Nrap.size(); ++base_level) {
  79. Tableau[2*base_level + 2] = Young_Tableau(nparticles[2*base_level + 2],
  80. //(base.Ix2_max[base_level] - ((base.Nrap[base_level]) % 2) + 2)/2 - nparticles[2*base_level + 2], Tableau[2]);
  81. //(base.Ix2_max[base_level] - base.Nrap[base_level] % 2 + 2)/2 - nparticles[2*base_level + 2], Tableau[2]);
  82. (base.Ix2_max[base_level] - ((base.Nrap[base_level] + 1) % 2))/2 + 1 - nparticles[2*base_level + 2], Tableau[2]);
  83. Tableau[2*base_level + 3] = Young_Tableau(nparticles[2*base_level + 3],
  84. //(base.Ix2_max[base_level] - base.Nrap[base_level] % 2)/2 - nparticles[2*base_level + 3], Tableau[3]);
  85. (base.Ix2_max[base_level] - (base.Nrap[base_level] % 2) - 1)/2 + 1 - nparticles[2*base_level + 3], Tableau[3]);
  86. }
  87. maxid = 1LL;
  88. //id = Tableau[0].id;
  89. for (int i = 0; i < nparticles.size(); ++i) {
  90. maxid *= Tableau[i].maxid + 1LL;
  91. //id += maxid + Tableau[i].id;
  92. }
  93. maxid -= 1LL;
  94. }
  95. Offsets& Offsets::operator= (const Offsets& RefOffset)
  96. {
  97. if (this != &RefOffset) {
  98. base = RefOffset.base;
  99. Tableau = RefOffset.Tableau;
  100. type_id = RefOffset.type_id;
  101. id = RefOffset.id;
  102. maxid = RefOffset.maxid;
  103. }
  104. return(*this);
  105. }
  106. bool Offsets::operator<= (const Offsets& RefOffsets)
  107. {
  108. // Check whether all nonzero tableau row lengths in RefOffsets
  109. // are <= than those in *this
  110. bool answer = true;
  111. for (int level = 0; level < 4; ++level) { // check fundamental level only
  112. //for (int level = 0; level < 2 * base.Nrap.size() + 2; ++level) {
  113. // First check whether all rows which exist in both tableaux satisfy rule:
  114. for (int tableau_level = 0; tableau_level < ABACUS::min(Tableau[level].Nrows, RefOffsets.Tableau[level].Nrows); ++tableau_level)
  115. if (Tableau[level].Row_L[tableau_level] > RefOffsets.Tableau[level].Row_L[tableau_level])
  116. answer = false;
  117. // Now check whether there exist extra rows violating rule:
  118. for (int tableau_level = ABACUS::min(Tableau[level].Nrows, RefOffsets.Tableau[level].Nrows); tableau_level < Tableau[level].Nrows; ++tableau_level)
  119. if (Tableau[level].Row_L[tableau_level] > 0) answer = false;
  120. }
  121. return(answer);
  122. }
  123. bool Offsets::operator>= (const Offsets& RefOffsets)
  124. {
  125. // Check whether all nonzero tableau row lengths in RefOffsets
  126. // are >= than those in *this
  127. bool answer = true;
  128. for (int level = 0; level < 4; ++level) { // check fundamental level only
  129. //for (int level = 0; level < 2 * base.Nrap.size() + 2; ++level) {
  130. // First check whether all rows which exist in both tableaux satisfy rule:
  131. for (int tableau_level = 0; tableau_level < ABACUS::min(Tableau[level].Nrows, RefOffsets.Tableau[level].Nrows); ++tableau_level)
  132. if (Tableau[level].Row_L[tableau_level] < RefOffsets.Tableau[level].Row_L[tableau_level])
  133. answer = false;
  134. // Now check whether there exist extra rows violating rule:
  135. for (int tableau_level = ABACUS::min(Tableau[level].Nrows, RefOffsets.Tableau[level].Nrows); tableau_level < RefOffsets.Tableau[level].Nrows; ++tableau_level)
  136. if (RefOffsets.Tableau[level].Row_L[tableau_level] > 0) answer = false;
  137. }
  138. return(answer);
  139. }
  140. void Offsets::Compute_type_id ()
  141. {
  142. type_id = 0LL;
  143. for (int i = 0; i < 2*base.Nrap.size() + 2; ++i) {
  144. Tableau[i].Compute_id();
  145. type_id += Tableau[i].Nrows * pow_ulli(10LL, i);
  146. }
  147. }
  148. void Offsets::Set_to_id (long long int idnr)
  149. {
  150. // The idnr of the Offset is given by
  151. // sub_id[0] + (total number of tableaux of type 0) * (sub_id[1] + (total number of tableaux of type 1) * (sub_id[2] + ...
  152. // + total number of tableaux of type (2*base.Nrap.size()) * sub_id[2*base.Nrap.size() + 1]
  153. if (idnr > maxid) {
  154. cout << idnr << "\t" << maxid << endl;
  155. ABACUSerror("idnr too large in offsets.Set_to_id.");
  156. }
  157. id = idnr;
  158. Vect<long long int> sub_id(0LL, 2*base.Nrap.size() + 2);
  159. long long int idnr_eff = idnr;
  160. long long int temp_prod = 1LL;
  161. Vect<long long int> result_choose(2*base.Nrap.size() + 2);
  162. for (int i = 0; i <= 2*base.Nrap.size(); ++i) {
  163. //result_choose[i] = choose_lli(Tableau[i].Nrows + Tableau[i].Ncols, Tableau[i].Nrows);
  164. result_choose[i] = Tableau[i].maxid + 1LL;
  165. temp_prod *= result_choose[i];
  166. }
  167. for (int i = 2*base.Nrap.size() + 1; i > 0; --i) {
  168. sub_id[i] = idnr_eff/temp_prod;
  169. idnr_eff -= sub_id[i] * temp_prod;
  170. temp_prod /= result_choose[i-1];
  171. }
  172. sub_id[0] = idnr_eff; // what's left goes to the bottom...
  173. for (int i = 0; i <= 2*base.Nrap.size() + 1; ++i) {
  174. //cout << "level = " << i << " Tableau.id = " << sub_id[i] << endl;
  175. if ((Tableau[i].Nrows * Tableau[i].Ncols == 0) && (sub_id[i] != 0)) ABACUSerror("index too large in offset.Set_to_id.");
  176. if (Tableau[i].id != sub_id[i]) Tableau[i].Set_to_id(sub_id[i]);
  177. }
  178. Compute_type_id ();
  179. return;
  180. }
  181. void Offsets::Compute_id ()
  182. {
  183. long long int prod_maxid = 1LL;
  184. id = 0LL;
  185. for (int i = 0; i < 2*base.Nrap.size() + 2; ++i) {
  186. Tableau[i].Compute_id();
  187. id += Tableau[i].id * prod_maxid;
  188. prod_maxid *= Tableau[i].maxid + 1LL;
  189. }
  190. }
  191. Vect<long long int> Offsets::Descendents (bool fixed_iK)
  192. {
  193. // From a given vector of Young tableaux specifying a particular eigenstate,
  194. // this function provides the full set of descendents (either at the same momentum if
  195. // fixed_iK == true, or not) by returning a vector of all descendent id's (leaving the
  196. // base and type invariant), which can then be used for further calculations.
  197. // This set of descendents is meant to be used when calculating either partition functions
  198. // or zero-temperature correlation functions.
  199. // IMPORTANT ASSUMPTIONS:
  200. // - all even sectors consistently increase/decrease momentum for increasing tableau row length
  201. // - all odd sectors consistently decrease/increase momentum for increasing tableau row length
  202. // FOR FIXED MOMENTUM:
  203. // all tableau levels `above' the lowest occupied one are descended as for fixed_iK == false,
  204. // and the lowest sector's highest tableau level's row length is modified (increased or decreased by one
  205. // unit if possible) such that the iK of Tableau_desc == iK of Tableau_ref.
  206. // The logic behind this is that for a state with nexc excitations, we let run nexc - 1 of the
  207. // excitations, and the lowest one is fixed in place by the momentum constraint, if possible.
  208. Vect<Young_Tableau> Tableau_ref = (*this).Tableau;
  209. Vect<Young_Tableau> Tableau_desc = Tableau_ref;
  210. }
  211. } // namespace ABACUS