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.

JSC_Scan.h 62KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c).
  4. -----------------------------------------------------------
  5. File: JSC_Scan.h
  6. Purpose: Declares all classes and functions used in the
  7. ABACUS logic of scanning with threads.
  8. ***********************************************************/
  9. #ifndef _SCAN_
  10. #define _SCAN_
  11. #include "JSC.h"
  12. namespace JSC {
  13. const int MAX_STATE_LIST_SIZE = 10000;
  14. // Functions in src/UTILS/Data_File_Name.cc:
  15. void Data_File_Name (stringstream& name, char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, DP L2, string defaultname);
  16. void Data_File_Name (stringstream& name, char whichDSF, int iKmin, int iKmax, DP kBT, LiebLin_Bethe_State& State, LiebLin_Bethe_State& RefScanState, string defaultname);
  17. void Data_File_Name (stringstream& name, char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax, DP kBT, int N2, string defaultname);
  18. void Data_File_Name (stringstream& name, char whichDSF, int iKmin, int iKmax, DP kBT, Heis_Bethe_State& State, Heis_Bethe_State& RefScanState, string defaultname);
  19. void ODSLF_Data_File_Name (stringstream& name, char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax, DP kBT, int N2, string defaultname);
  20. void Data_File_Name (stringstream& name, char whichDSF, int iKmin, int iKmax, DP kBT, ODSLF_Bethe_State& State, ODSLF_Bethe_State& RefScanState, string defaultname);
  21. // Coding to convert ints to strings: for application in reduced labels
  22. //const int JSCcodingsize = 64; // use a multiple of 2 to accelerate divisions in labeling.
  23. //const char JSCcoding[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '?'};
  24. // From ABACUS++T_8 onwards: forbid special characters as |, :, !, ? and all capital letters in labels.
  25. // This is due to the capitalization-preserving but capitalization-insensitive HFS+ filesystem on Mac OS X.
  26. const int JSCcodingsize = 32;
  27. const char JSCcoding[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v'};
  28. const char LABELSEP = '_'; // was _
  29. const char TYPESEP = 'x'; // was |
  30. const char EXCSEP = 'y'; // was :
  31. const char INEXCSEP = 'z'; // was @
  32. struct State_Label_Data {
  33. //int ntypes; // how many types of particles are present in the state
  34. Vect<int> type; // integer type labels of the types present
  35. Vect<int> M; // how many particles of each type
  36. Vect<int> nexc; // how many excitations as compared to the reference state used
  37. Vect<Vect<int> > Ix2old; // which Ix2 will be excited
  38. Vect<Vect<int> > Ix2exc; // which Ix2 the excitation has shifted to
  39. State_Label_Data (const Vect<int>& type_ref, const Vect<int>& M_ref,
  40. const Vect<int>& nexc_ref, const Vect<Vect<int> >& Ix2old_ref, const Vect<Vect<int> >& Ix2exc_ref)
  41. {
  42. type = type_ref; M = M_ref; nexc = nexc_ref; Ix2old = Ix2old_ref; Ix2exc = Ix2exc_ref;
  43. }
  44. };
  45. // DEPRECATED ++G_5
  46. //State_Label_Data Read_State_Ulabel (string ulabel);
  47. //string Return_State_Ulabel (State_Label_Data data);
  48. //string Return_State_Ulabel (const Vect<Vect<int> >& ScanIx2, const Vect<Vect<int> >& OriginIx2);
  49. //string Return_State_Ulabel (const Vect<int>& ScanIx2, const Vect<int>& OriginIx2); // if there is only one type
  50. string Extract_Base_Label (string label); // works for labels and complabels
  51. string Extract_nexc_Label (string label);
  52. // For compressed labels: conversions between integers and char/strings.
  53. string Convert_POSINT_to_STR (int int_to_convert);
  54. int Convert_CHAR_to_POSINT (char char_to_convert);
  55. int Convert_STR_to_POSINT (string str_to_convert);
  56. State_Label_Data Read_Base_Label (string label);
  57. State_Label_Data Read_State_Label (string label, const Vect<Vect<int> >& OriginIx2);
  58. State_Label_Data Read_State_Label (string label, const Vect<int>& OriginIx2); // if there is only one type
  59. string Return_State_Label (State_Label_Data data, const Vect<Vect<int> >& OriginIx2);
  60. string Return_State_Label (State_Label_Data data, const Vect<int>& OriginIx2); // if there is only one type
  61. string Return_State_Label (const Vect<Vect<int> >& ScanIx2, const Vect<Vect<int> >& OriginIx2);
  62. string Return_State_Label (const Vect<int>& ScanIx2, const Vect<int>& OriginIx2); // if there is only one type
  63. Vect<Vect<int> > Return_Ix2_from_Label (string label_ref, const Vect<Vect<int> >& OriginIx2);
  64. Vect<int> Return_Ix2_from_Label (string label_ref, const Vect<int>& OriginIx2); // specialization to Lieb-Liniger
  65. //bool Set_to_Label (string label_ref, Vect<Vect<int> >& Ix2, const Vect<Vect<int> >& OriginIx2);
  66. // Functions for descending states: in SCAN/Descendents.cc
  67. //Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const Vect<Vect<int> >& OriginIx2, const Vect<Vect<int> >& BaseScanIx2, const Vect<int>& Ix2_min, const Vect<int>& Ix2_max);
  68. //Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const Vect<Vect<int> >& OriginIx2, const Vect<Vect<int> >& BaseScanIx2, const Vect<int>& Ix2_min, const Vect<int>& Ix2_max);
  69. //Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const Vect<Vect<int> >& OriginIx2, const Vect<Vect<int> >& BaseScanIx2, const Vect<int>& Ix2_min, const Vect<int>& Ix2_max);
  70. // Specialization for Lieb-Liniger case:
  71. // ++G_5
  72. //Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const Vect<int>& OriginIx2, const Vect<int>& BaseScanIx2);
  73. //Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const Vect<int>& OriginIx2, const Vect<int>& BaseScanIx2);
  74. //Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const Vect<int>& OriginIx2, const Vect<int>& BaseScanIx2);
  75. //Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const LiebLin_Bethe_State& OriginState);
  76. //Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const LiebLin_Bethe_State& OriginState);
  77. //Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const LiebLin_Bethe_State& OriginState);
  78. //Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const Heis_Bethe_State& OriginState);
  79. //Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const Heis_Bethe_State& OriginState);
  80. //Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const Heis_Bethe_State& OriginState);
  81. // ++G_6.0
  82. //Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc);
  83. //Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc);
  84. //Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc_up, bool disperse_only_current_exc_down);
  85. //Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc);
  86. //Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc);
  87. //Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc_up, bool disperse_only_current_exc_down);
  88. // ++G_6.1
  89. Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  90. Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  91. Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc_up, bool preserve_nexc_up, bool disperse_only_current_exc_down, bool preserve_nexc_down);
  92. Vect<string> Descendent_States_with_iK_Stepped_Up (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  93. Vect<string> Descendent_States_with_iK_Stepped_Down (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  94. Vect<string> Descendent_States_with_iK_Preserved (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc_up, bool preserve_nexc_up, bool disperse_only_current_exc_down, bool preserve_nexc_down);
  95. // For symmetric state scanning:
  96. Vect<string> Descendent_States_with_iK_Stepped_Up_rightIx2only
  97. (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  98. Vect<string> Descendent_States_with_iK_Stepped_Down_rightIx2only
  99. (string ScanIx2_label, const LiebLin_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  100. Vect<string> Descendent_States_with_iK_Stepped_Up_rightIx2only
  101. (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  102. Vect<string> Descendent_States_with_iK_Stepped_Down_rightIx2only
  103. (string ScanIx2_label, const Heis_Bethe_State& OriginState, bool disperse_only_current_exc, bool preserve_nexc);
  104. // Conversion between labels and complabels: DEPRECATED ++G_5
  105. //string Compress_Ulabel (string ulabel_ref, const Vect<Vect<int> >& OriginIx2);
  106. //string Compress_Ulabel (string ulabel_ref, const Vect<int>& OriginIx2); // if there is only one type
  107. //string Uncompress_Label (string complabel_ref, const Vect<Vect<int> >& OriginIx2);
  108. //string Uncompress_Label (string complabel_ref, const Vect<int>& OriginIx2); // if there is only one type
  109. // Functions in src/SCAN/General_Scan.cc:
  110. //template<class Tstate>
  111. //void General_Scan (char whichDSF, Tstate& RefState, int Max_Secs, bool refine);
  112. //void ScanLiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax,
  113. // int Max_Secs, DP target_sumrule, bool refine, int rank, int nr_processors);
  114. //void Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, int Max_Secs, bool refine);
  115. //void Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKneeded, int Max_Secs, bool refine);
  116. //void Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iK_UL, int Max_Secs, bool refine);
  117. // Finite temperature:
  118. //void Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, int Max_Secs, DP target_sumrule, bool refine, int rank, int nr_processors);
  119. void Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT,
  120. int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  121. void Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT,
  122. int Max_Secs, DP target_sumrule, bool refine);
  123. // Over arbitrary excited state:
  124. //void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultname, int iKmin, int iKmax, int Max_Secs, DP target_sumrule, bool refine, int rank, int nr_processors);
  125. void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultScanStatename, int iKmin, int iKmax,
  126. int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  127. void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultname, int iKmin, int iKmax,
  128. int Max_Secs, DP target_sumrule, bool refine);
  129. //void Scan_Heis (char whichDSF, DP Delta, DP N, int M, bool fixed_iK, int iKneeded, int Max_Secs, bool refine, int rank, int nr_processors);
  130. void Scan_Heis (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax,
  131. int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  132. void Scan_Heis (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax,
  133. int Max_Secs, DP target_sumrule, bool refine);
  134. //void Scan_Heis (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax, int Max_Secs, bool refine);
  135. //void Scan_Heis (char whichDSF, DP Delta, int N, int M, int iKneeded, int Max_Secs, bool refine);
  136. //void Scan_Heis (char whichDSF, DP Delta, int N, int M, int Max_Secs, bool refine);
  137. void Scan_Heis (char whichDSF, XXZ_Bethe_State& AveragingState, string defaultScanStatename, int iKmin, int iKmax,
  138. int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  139. void Scan_Heis (char whichDSF, XXX_Bethe_State& AveragingState, string defaultScanStatename, int iKmin, int iKmax,
  140. int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  141. void Scan_Heis (char whichDSF, XXZ_gpd_Bethe_State& AveragingState, string defaultScanStatename, int iKmin, int iKmax,
  142. int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  143. //void Scan_LiebLin_Geometric_Quench (DP c_int, DP L_1, int type_id_1, long long int id_1, DP L_2, int N, int iK_UL, int Max_Secs, bool refine);
  144. void Scan_LiebLin_Geometric_Quench (DP c_int, DP L_1, int type_id_1, long long int id_1, DP L_2, int N,
  145. int iK_UL, int Max_Secs, DP target_sumrule, bool refine);
  146. //void Scan_ODSLF (char whichDSF, DP Delta, DP N, int M, bool fixed_iK, int iKneeded, int Max_Secs, bool refine, int rank, int nr_processors);
  147. void Scan_ODSLF (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax,
  148. int Max_Secs, DP target_sumrule, bool refine, int rank, int nr_processors);
  149. void Scan_ODSLF (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax, int Max_Secs, bool refine);
  150. void Scan_ODSLF (char whichDSF, DP Delta, int N, int M, int iKneeded, int Max_Secs, bool refine);
  151. void Scan_ODSLF (char whichDSF, DP Delta, int N, int M, int Max_Secs, bool refine);
  152. // Functions to prepare and wrapup parallel scans:
  153. //void Prepare_Parallel_Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iK_UL, bool fixed_iK, int iKneeded,
  154. void Prepare_Parallel_Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT,
  155. string defaultname, int paralevel, Vect<int> rank_lower_paralevels, Vect<int> nr_processors_lower_paralevels,
  156. int nr_processors_at_newlevel);
  157. //void Wrapup_Parallel_Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iK_UL, bool fixed_iK, int iKneeded,
  158. void Wrapup_Parallel_Scan_LiebLin (char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT,
  159. string defaultname, int paralevel, Vect<int> rank_lower_paralevels, Vect<int> nr_processors_lower_paralevels,
  160. int nr_processors_at_newlevel);
  161. void Prepare_Parallel_Scan_Heis (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax,
  162. int paralevel, Vect<int> rank_lower_paralevels, Vect<int> nr_processors_lower_paralevels, int nr_processors_at_newlevel);
  163. void Wrapup_Parallel_Scan_Heis (char whichDSF, DP Delta, int N, int M, int iKmin, int iKmax,
  164. int paralevel, Vect<int> rank_lower_paralevels, Vect<int> nr_processors_lower_paralevels, int nr_processors_at_newlevel);
  165. void Sort_RAW_File (const char ffsq_file[], char optionchar);
  166. void Sort_RAW_File (const char ffsq_file[], char optionchar, char whichDSF);
  167. // Functions for data interpretation:
  168. DP Smoothen_RAW_into_SF (string prefix, int iKmin, int iKmax, int DiK,
  169. DP ommin, DP ommax, int Nom, DP gwidth, DP normalization, DP denom_sum_K);
  170. DP Smoothen_RAW_into_SF (string prefix, Vect<string> rawfilename, Vect<DP> weight, int iKmin, int iKmax, int DiK,
  171. DP ommin, DP ommax, int Nom, DP gwidth, DP normalization, DP denom_sum_K);
  172. //DP Smoothen_RAW_into_ASF (string prefix, int iKmin, int iKmax, DP ommin, DP ommax, int Nom, DP gwidth,
  173. // DP normalization, DP denom_sum_K); // for autocorrelation. Deprecated during ABACUS++T_8, now done automatically within Smoothen_RAW_into_ASF.
  174. void Write_K_File (DP Length, int iKmin, int iKmax);
  175. void Write_Omega_File (int Nout_omega, DP omegamin, DP omegamax);
  176. // Smoothen with gaussian width scaled with two-particle bandwidth
  177. DP Smoothen_RAW_into_SF_LiebLin_Scaled (string prefix, DP L, int N, int iKmin, int iKmax, int DiK, DP ommin, DP ommax, int Nom, DP width, DP normalization);
  178. //****************************************************************************
  179. struct Scan_Info {
  180. DP sumrule_obtained;
  181. //long long int Nfull;
  182. DP Nfull; // dimensionality of (sub)Hilbert space considered
  183. long long int Ninadm;
  184. long long int Ndata;
  185. long long int Ndata_conv;
  186. long long int Ndata_conv0;
  187. //long long int CPU_ticks;
  188. //long long int CPU_ticks_TOT; // including refine runs
  189. double TT; // total computation time in seconds
  190. public:
  191. Scan_Info(); // constructor, puts everything to zero
  192. //Scan_Info (DP sr, long long int Nf, long long int Ni, long long int Nd, long long int Ndc, long long int Ndc0, long long int t);
  193. Scan_Info (DP sr, DP Nf, long long int Ni, long long int Nd, long long int Ndc, long long int Ndc0, double t);
  194. void Save (const char* outfile_Cstr);
  195. void Load (const char* infile_Cstr);
  196. inline Scan_Info& operator = (const Scan_Info& ref_info)
  197. {
  198. sumrule_obtained = ref_info.sumrule_obtained;
  199. Nfull = ref_info.Nfull;
  200. Ninadm = ref_info.Ninadm;
  201. Ndata = ref_info.Ndata;
  202. Ndata_conv = ref_info.Ndata_conv;
  203. Ndata_conv0 = ref_info.Ndata_conv0;
  204. //CPU_ticks = ref_info.CPU_ticks;
  205. //CPU_ticks_TOT = ref_info.CPU_ticks_TOT;
  206. TT = ref_info.TT;
  207. return(*this);
  208. }
  209. inline Scan_Info& operator+= (const Scan_Info& ref_info)
  210. {
  211. if (this != &ref_info) {
  212. sumrule_obtained += ref_info.sumrule_obtained;
  213. Nfull += ref_info.Nfull;
  214. Ninadm += ref_info.Ninadm;
  215. Ndata += ref_info.Ndata;
  216. Ndata_conv += ref_info.Ndata_conv;
  217. Ndata_conv0 += ref_info.Ndata_conv0;
  218. //CPU_ticks += ref_info.CPU_ticks;
  219. //CPU_ticks_TOT += ref_info.CPU_ticks_TOT;
  220. TT += ref_info.TT;
  221. }
  222. return(*this);
  223. }
  224. inline Scan_Info& operator-= (const Scan_Info& ref_info)
  225. {
  226. if (this != &ref_info) {
  227. sumrule_obtained -= ref_info.sumrule_obtained;
  228. Nfull -= ref_info.Nfull;
  229. Ninadm -= ref_info.Ninadm;
  230. Ndata -= ref_info.Ndata;
  231. Ndata_conv -= ref_info.Ndata_conv;
  232. Ndata_conv0 -= ref_info.Ndata_conv0;
  233. //CPU_ticks -= ref_info.CPU_ticks;
  234. //CPU_ticks_TOT -= ref_info.CPU_ticks_TOT;
  235. TT -= ref_info.TT;
  236. }
  237. return(*this);
  238. }
  239. };
  240. std::ostream& operator<< (std::ostream& s, const Scan_Info& info);
  241. template<class Tstate>
  242. Scan_Info General_Scan (char whichDSF, int iKmin, int iKmax, int iKmod, DP kBT, Tstate& AveragingState, Tstate& SeedScanState,
  243. string defaultScanStatename, int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors);
  244. //****************************************************************************
  245. // Functions in src/SCAN/Descendents.cc:
  246. /*
  247. struct Descendent_Data {
  248. Vect<string> label;
  249. Vect<int> type;
  250. Descendent_Data();
  251. };
  252. */
  253. //Vect<string> Descendents (const LiebLin_Bethe_State& ScanState, const LiebLin_Bethe_State& OriginState);
  254. //Vect<string> Descendents (const Heis_Bethe_State& ScanState, const Heis_Bethe_State& OriginState);
  255. Vect<string> Descendents (const LiebLin_Bethe_State& ScanState, const LiebLin_Bethe_State& OriginState, int type_required);
  256. Vect<string> Descendents (const Heis_Bethe_State& ScanState, const Heis_Bethe_State& OriginState, int type_required);
  257. //Descendent_Data Descendents (const LiebLin_Bethe_State& ScanState, const LiebLin_Bethe_State& OriginState, int type_required);
  258. //Descendent_Data Descendents (const Heis_Bethe_State& ScanState, const Heis_Bethe_State& OriginState, int type_required);
  259. //****************************************************************************
  260. /* DEPRECATED IN ABACUS++G_7
  261. struct Scan_Thread_List {
  262. int dim; // Dimension of vectors
  263. int nthreads_tot; // Number of entries used; must be <= dim
  264. int nthreads_done; // how many threads have already been processed
  265. ////Vect_DP omega;
  266. //Vect<float> omega;
  267. //Vect_INT iK;
  268. //Vect_DP abs_data_value; // Measure used to optimize scanning. This can be either the energy ('Z'), MEsq, omega * MEsq, ...
  269. Vect<float> abs_data_value; // Measure used to optimize scanning. This can be either the energy ('Z'), MEsq, omega * MEsq, ...
  270. Vect<string> label;
  271. //Vect<int> sector_lowest_raisable;
  272. Vect<int> type; // which type of descendent is needed: 0 == same nr of ph exc, 1 == one more ph exc.
  273. Vect<bool> isdone; // whether the thread has been processed or not
  274. Scan_Thread_List (); //
  275. Scan_Thread_List (int Nentries);
  276. bool Increase_Size (int nr_to_add); // resizes the vectors to accommodate up to nr_to_add additional entries
  277. //void Include_Thread (DP omega_ref, int iK_ref, DP abs_data_value_ref, string label_ref, int type_ref);
  278. void Include_Thread (DP abs_data_value_ref, string label_ref, int type_ref);
  279. void Order_in_abs_data_value (); // orders in decreasing abs_data_value, for correlation functions
  280. //void Order_in_omega (); // orders in increasing omega, for partition function
  281. //DP Highest_abs_data_value_ordered (DP omega_MIN, DP omega_MAX); // returns highest abs_data_value in window omega_MIN to omega_MAX, assuming list is ordered
  282. //DP Highest_abs_data_value (DP omega_MIN, DP omega_MAX); // returns highest abs_data_value in window omega_MIN to omega_MAX
  283. DP Highest_abs_data_value (); // returns highest abs_data_value
  284. DP kth_highest_abs_data_value (int k);
  285. bool Exists_data_value_greater_than (DP value); // whether at least one thread exceeds this value
  286. //DP Lowest_omega (); // returns lowest omega
  287. void Merge (const Scan_Thread_List& reflist);
  288. //void Remove_Threads (int ithread_down, int ithread_up); // DEACTIVATED IN ABACUS++G_2
  289. //int Remove_Threads (const Vect<bool>& threads_done); // DEACTIVATED IN ABACUS++G_2
  290. void Remove_Done_Threads (); // removes done threads, replaces Remove_Threads (from ABACUS++G_2 onwards)
  291. void Clear ();
  292. void Save (const char* outfile_Cstr);
  293. void Load (const char* thrfile_Cstr);
  294. inline Scan_Thread_List& operator = (const Scan_Thread_List& reflist)
  295. {
  296. dim = reflist.dim;
  297. nthreads_tot = reflist.nthreads_tot;
  298. nthreads_done = reflist.nthreads_done;
  299. //omega = reflist.omega;
  300. //iK = reflist.iK;
  301. abs_data_value = reflist.abs_data_value;
  302. label = reflist.label;
  303. type = reflist.type;
  304. isdone = reflist.isdone;
  305. return(*this);
  306. }
  307. };
  308. */
  309. /*
  310. struct Scan_Thread_Set {
  311. // By convention, a Scan_Thread_Set contains a list of threads which are yet to be descended.
  312. int nlists = 6400; // number of threads lists, fixed to this number by convention.
  313. DP logscale = (1.0/64) * log(2.0); // each separate list contains threads differing by a scale factor of 2^{1/64} \approx 1.01.
  314. // The number of lists thus covers abs_data_values from 1 down to about 10^-30.
  315. // The list index of a thread is given by -log(data_value)/logscale, and forced between 0 and nlists -1.
  316. Vect<int> dim;
  317. Vect<int> nthreads_tot;
  318. Vect<int> nthreads_done;
  319. Vect<Vect<string> > label;
  320. Vect<Vect<int> > type; // which type of descendent is needed
  321. Vect<Vect<bool> > isdone; // whether the thread has been processed or not
  322. Scan_Thread_Set ();
  323. bool Increase_Size (int il, int nr_to_add);
  324. void Include_Thread (DP abs_data_value_ref, string label_ref, int type_ref);
  325. void Merge (const Scan_Thread_Set& refset);
  326. void Remove_Done_Threads (int il);
  327. void Remove_Done_Threads ();
  328. void Clear ();
  329. void Save (const char* outfile_Cstr);
  330. void Load (const char* thrfile_Cstr);
  331. };
  332. */
  333. struct Scan_Thread {
  334. string label;
  335. int type;
  336. Scan_Thread ();
  337. Scan_Thread (string label_ref, int type_ref) {
  338. label = label_ref;
  339. type = type_ref;
  340. }
  341. Scan_Thread& operator= (const Scan_Thread& RefThread);
  342. };
  343. struct Scan_Thread_Data {
  344. // By convention, a Scan_Thread_Data object handles a list of threads which are yet to be descended.
  345. // Improvement on Scan_Thread_Set used up to ABACUS++G_7, saving data to disk instead of holding it in memory.
  346. int nlists = 6400; // number of threads lists, fixed to this number by convention.
  347. DP logscale = (1.0/64) * log(2.0); // each separate list contains threads differing by a scale factor of 2^{1/64} \approx 1.01.
  348. //int nlists = 1600; // number of threads lists, fixed to this number by convention.
  349. //DP logscale = (1.0/16) * log(2.0); // each separate list contains threads differing by a scale factor of 2^{1/64} \approx 1.01.
  350. // The number of lists thus covers abs_data_values from 1 down to about 10^-30.
  351. // The list index of a thread is given by -log(data_value)/logscale, and forced between 0 and nlists -1.
  352. string thrdir_name; // directory in which threads files are saved.
  353. Vect<int> nthreads_total;
  354. Vect<int> nthreads_on_disk;
  355. int lowest_il_with_nthreads_neq_0;
  356. // In-memory storage, for adding threads efficiently without constantly writing to disk
  357. // These objects are saved to disk when Next_Scan_Threads are called.
  358. Vect<int> dim;
  359. Vect<int> nthreads_in_memory;
  360. Vect<Vect<string> > label;
  361. Vect<Vect<int> > type; // which type of descendent is needed
  362. Vect<string> filename;
  363. //Vect<fstream*> file;
  364. //Vect<bool> file_is_open;
  365. Scan_Thread_Data ();
  366. Scan_Thread_Data (string thrdir_name_ref, bool refine);
  367. ~Scan_Thread_Data ();
  368. bool Increase_Memory_Size (int il, int nr_to_add);
  369. void Include_Thread (DP abs_data_value_ref, string label_ref, int type_ref);
  370. void Include_Thread (int il, string label_ref, int type_ref);
  371. Vect<Scan_Thread> Extract_Next_Scan_Threads (); // returns a vector of the threads that are next in line. By defn, all threads with index il == lowest_il_with_nthreads_neq_0. These are removed from the object.
  372. Vect<Scan_Thread> Extract_Next_Scan_Threads (int min_nr); // as above, but returns a minimum of min_nr threads.
  373. void Flush_to_Disk (int il);
  374. void Save ();
  375. void Load ();
  376. };
  377. //****************************************************************************
  378. // To populate a list of states for scanning:
  379. inline void Scan_for_Possible_Bases (const Vect<int> SeedNrap, const Vect<int> Str_L,
  380. int Mdown_remaining, Vect<string>& possible_base_label, int& nfound, int nexc_max_used,
  381. int base_level_to_scan, Vect<int>& Nrapidities)
  382. {
  383. if (Mdown_remaining < 0) { JSCerror("Scan_for_Possible_Bases: shouldn't be here..."); } // reached inconsistent point
  384. //cout << "Called Scan_for_Possible_Bases with Mdown_remaining = " << Mdown_remaining
  385. //<< "\t" << possible_base_label << "\tnfound " << nfound << "\tnexc_max_used " << nexc_max_used
  386. //<< "\tbase_level_to_scan " << base_level_to_scan << "\tNrap " << Nrapidities << endl;
  387. if (base_level_to_scan == 0) {
  388. if (Str_L[0] != 1) JSCerror("Str_L[0] != 1 in JSC_Scan.h Scan_for_Possible_Bases.");
  389. Nrapidities[0] = Mdown_remaining;
  390. // Set label:
  391. stringstream M0out;
  392. M0out << Nrapidities[0];
  393. possible_base_label[nfound] = M0out.str();
  394. for (int itype = 1; itype < Nrapidities.size(); ++itype)
  395. if (Nrapidities[itype] > 0) {
  396. possible_base_label[nfound] += TYPESEP;
  397. stringstream typeout;
  398. typeout << itype;
  399. possible_base_label[nfound] += typeout.str();
  400. possible_base_label[nfound] += EXCSEP;
  401. stringstream Mout;
  402. Mout << Nrapidities[itype];
  403. possible_base_label[nfound] += Mout.str();
  404. }
  405. nfound++;
  406. }
  407. else {
  408. // Preserve the number of strings at this level as compared to SeedState:
  409. Nrapidities[base_level_to_scan] = SeedNrap[base_level_to_scan];
  410. if (Mdown_remaining - Str_L[base_level_to_scan] * Nrapidities[base_level_to_scan] >= 0)
  411. Scan_for_Possible_Bases (SeedNrap, Str_L, Mdown_remaining - Str_L[base_level_to_scan] * Nrapidities[base_level_to_scan],
  412. possible_base_label, nfound, nexc_max_used, base_level_to_scan - 1, Nrapidities);
  413. // Reduce number of strings at this level as compared to SeedState:
  414. //for (int i = 1; i <= JSC::min(SeedNrap[base_level_to_scan], (Str_L[base_level_to_scan] == 0 ? 0 : nexc_max_used/Str_L[base_level_to_scan])); ++i) {
  415. for (int i = 1; i <= JSC::min(SeedNrap[base_level_to_scan], nexc_max_used/Str_L[base_level_to_scan]); ++i) {
  416. Nrapidities[base_level_to_scan] = SeedNrap[base_level_to_scan] - i;
  417. if (Mdown_remaining - Str_L[base_level_to_scan] * Nrapidities[base_level_to_scan] >= 0)
  418. Scan_for_Possible_Bases (SeedNrap, Str_L, Mdown_remaining - Str_L[base_level_to_scan] * Nrapidities[base_level_to_scan],
  419. possible_base_label, nfound, nexc_max_used - i*Str_L[base_level_to_scan], base_level_to_scan - 1, Nrapidities);
  420. }
  421. // Increase the number of strings at this level as compared to SeedState:
  422. for (int i = 1; i <= JSC::min(Mdown_remaining/Str_L[base_level_to_scan], nexc_max_used/Str_L[base_level_to_scan]); ++i) {
  423. Nrapidities[base_level_to_scan] = SeedNrap[base_level_to_scan] + i;
  424. if (Mdown_remaining - Str_L[base_level_to_scan] * Nrapidities[base_level_to_scan] >= 0)
  425. Scan_for_Possible_Bases (SeedNrap, Str_L, Mdown_remaining - Str_L[base_level_to_scan] * Nrapidities[base_level_to_scan],
  426. possible_base_label, nfound, nexc_max_used - i*Str_L[base_level_to_scan], base_level_to_scan - 1, Nrapidities);
  427. }
  428. }
  429. }
  430. inline Vect<string> Possible_Bases (const Vect<int> SeedNrap, const Vect<int> Str_L, int Mdown)//const Heis_Bethe_State& SeedState)
  431. {
  432. //int nexc_max_used = JSC::min(NEXC_MAX_HEIS, 2*(Mdown/2)); // since each inner sector can contain at most N/2 holes.
  433. int nexc_max_used = NEXC_MAX_HEIS;
  434. Vect<string> possible_base_label (1000);
  435. int nfound = 0;
  436. Vect<int> Nrapidities = SeedNrap;
  437. int Mdown_remaining = Mdown;
  438. Scan_for_Possible_Bases (SeedNrap, Str_L, Mdown_remaining, possible_base_label, nfound, nexc_max_used, SeedNrap.size() - 1, Nrapidities);
  439. // Copy results into a clean vector:
  440. Vect<string> possible_base_label_found (nfound);
  441. for (int i = 0; i < nfound; ++i) possible_base_label_found[i] = possible_base_label[i];
  442. //cout << "In Possible_Bases: possible_base_label_found = " << possible_base_label_found << endl;
  443. return(possible_base_label_found);
  444. }
  445. //****************************************************************************
  446. template<class Tstate>
  447. class Scan_State_List {
  448. public:
  449. int ndef;
  450. Vect<Tstate> State;
  451. Vect<string> base_label;
  452. Vect<Scan_Info> info; // info for base and type of State[n]
  453. //Vect<bool> descended; // true only if base has been descended
  454. Vect<bool> flag_for_scan; // set to true, next round of scanning will use this base/type
  455. Vect<bool> scan_attempted; // whether this has already been attempted
  456. public:
  457. inline Scan_State_List (char whichDSF, const Tstate& SeedScanState);
  458. public:
  459. inline Tstate& Return_State (string base_label_ref); // returns a state corresponding to same base and type
  460. inline void Populate_List (char whichDSF, const Tstate& SeedScanState); // creates all types of states containing up to nexc_max excitations
  461. inline void Include_Info (Scan_Info& info_to_add, string base_label_ref);
  462. inline void Raise_Scanning_Flags (DP threshold); // checks whether base/type should be scanned based on simpler base/type combinations
  463. inline void Order_in_SRC ();
  464. inline void Save_Info (const char* sumfile_Cstr);
  465. inline void Load_Info (const char* sumfile_Cstr);
  466. };
  467. // Do the explicit class specializations:
  468. template<>
  469. //inline Scan_State_List<LiebLin_Bethe_State>::Scan_State_List (char whichDSF, const LiebLin_Bethe_State& RefState)
  470. inline Scan_State_List<LiebLin_Bethe_State>::Scan_State_List (char whichDSF, const LiebLin_Bethe_State& SeedScanState)
  471. : ndef(0), State(Vect<LiebLin_Bethe_State>(MAX_STATE_LIST_SIZE)), base_label(Vect<string>(MAX_STATE_LIST_SIZE)),
  472. info(Vect<Scan_Info>(MAX_STATE_LIST_SIZE)), flag_for_scan(Vect<bool>(false, MAX_STATE_LIST_SIZE)),
  473. scan_attempted(Vect<bool>(false, MAX_STATE_LIST_SIZE))
  474. {
  475. //if (whichDSF == 'Z' || whichDSF == 'd' || whichDSF == 'q' || whichDSF == '1')
  476. //State[0] = LiebLin_Bethe_State (RefState.c_int, RefState.L, RefState.N);
  477. //else if (whichDSF == 'g') State[0] = LiebLin_Bethe_State (RefState.c_int, RefState.L, RefState.N + 1);
  478. //else if (whichDSF == 'o') State[0] = LiebLin_Bethe_State (RefState.c_int, RefState.L, RefState.N - 1);
  479. //else JSCerror("Unknown whichDSF in Scan_State_List<LiebLin... constructor.");
  480. State[0] = SeedScanState;
  481. }
  482. template<>
  483. //inline Scan_State_List<XXZ_Bethe_State>::Scan_State_List (char whichDSF, const XXZ_Bethe_State& RefState)
  484. inline Scan_State_List<XXZ_Bethe_State>::Scan_State_List (char whichDSF, const XXZ_Bethe_State& SeedScanState)
  485. : ndef(0), State(Vect<XXZ_Bethe_State>(MAX_STATE_LIST_SIZE)), base_label(Vect<string>(MAX_STATE_LIST_SIZE)),
  486. info(Vect<Scan_Info>(MAX_STATE_LIST_SIZE)), flag_for_scan(Vect<bool>(false, MAX_STATE_LIST_SIZE)),
  487. scan_attempted(Vect<bool>(false, MAX_STATE_LIST_SIZE))
  488. {
  489. //if (whichDSF == 'Z' || whichDSF == 'z') State[0] = XXZ_Bethe_State(RefState.chain, RefState.base.Mdown);
  490. //else if (whichDSF == 'm') State[0] = XXZ_Bethe_State(RefState.chain, RefState.base.Mdown - 1);
  491. //else if (whichDSF == 'p') State[0] = XXZ_Bethe_State(RefState.chain, RefState.base.Mdown + 1);
  492. //else JSCerror("Unknown whichDSF in Scan_State_List<XXZ... constructor.");
  493. State[0] = SeedScanState;
  494. }
  495. template<>
  496. //inline Scan_State_List<XXX_Bethe_State>::Scan_State_List (char whichDSF, const XXX_Bethe_State& RefState)
  497. inline Scan_State_List<XXX_Bethe_State>::Scan_State_List (char whichDSF, const XXX_Bethe_State& SeedScanState)
  498. : ndef(0), State(Vect<XXX_Bethe_State>(MAX_STATE_LIST_SIZE)), base_label(Vect<string>(MAX_STATE_LIST_SIZE)),
  499. info(Vect<Scan_Info>(MAX_STATE_LIST_SIZE)), flag_for_scan(Vect<bool>(false, MAX_STATE_LIST_SIZE)),
  500. scan_attempted(Vect<bool>(false, MAX_STATE_LIST_SIZE))
  501. {
  502. //if (whichDSF == 'Z' || whichDSF == 'z' || whichDSF == 'a' || whichDSF == 'q') State[0] = XXX_Bethe_State(RefState.chain, RefState.base.Mdown);
  503. //else if (whichDSF == 'm' || whichDSF == 'b') State[0] = XXX_Bethe_State(RefState.chain, RefState.base.Mdown - 1);
  504. //else if (whichDSF == 'p') State[0] = XXX_Bethe_State(RefState.chain, RefState.base.Mdown + 1);
  505. //else if (whichDSF == 'c') State[0] = XXX_Bethe_State(RefState.chain, RefState.base.Mdown - 2);
  506. //else JSCerror("Unknown whichDSF in Scan_State_List<XXX... constructor.");
  507. State[0] = SeedScanState;
  508. }
  509. template<>
  510. //inline Scan_State_List<XXZ_gpd_Bethe_State>::Scan_State_List (char whichDSF, const XXZ_gpd_Bethe_State& RefState)
  511. inline Scan_State_List<XXZ_gpd_Bethe_State>::Scan_State_List (char whichDSF, const XXZ_gpd_Bethe_State& SeedScanState)
  512. : ndef(0), State(Vect<XXZ_gpd_Bethe_State>(MAX_STATE_LIST_SIZE)), base_label(Vect<string>(MAX_STATE_LIST_SIZE)),
  513. info(Vect<Scan_Info>(MAX_STATE_LIST_SIZE)), flag_for_scan(Vect<bool>(false, MAX_STATE_LIST_SIZE)),
  514. scan_attempted(Vect<bool>(false, MAX_STATE_LIST_SIZE))
  515. {
  516. //if (whichDSF == 'Z' || whichDSF == 'z') State[0] = XXZ_gpd_Bethe_State(RefState.chain, RefState.base.Mdown);
  517. //else if (whichDSF == 'm') State[0] = XXZ_gpd_Bethe_State(RefState.chain, RefState.base.Mdown - 1);
  518. //else if (whichDSF == 'p') State[0] = XXZ_gpd_Bethe_State(RefState.chain, RefState.base.Mdown + 1);
  519. //else JSCerror("Unknown whichDSF in Scan_State_List<XXZ_gpd... constructor.");
  520. State[0] = SeedScanState;
  521. }
  522. /*
  523. template<>
  524. inline Scan_State_List<ODSLF_XXZ_Bethe_State>::Scan_State_List (char whichDSF, const ODSLF_XXZ_Bethe_State& RefState)
  525. : ndef(0), State(Vect<ODSLF_XXZ_Bethe_State>(MAX_STATE_LIST_SIZE)), base_label(Vect<string>(MAX_STATE_LIST_SIZE)),
  526. info(Vect<Scan_Info>(MAX_STATE_LIST_SIZE)), flag_for_scan(Vect<bool>(false, MAX_STATE_LIST_SIZE)),
  527. scan_attempted(Vect<bool>(false, MAX_STATE_LIST_SIZE))
  528. {
  529. if (whichDSF == 'Z' || whichDSF == 'z') State[0] = ODSLF_XXZ_Bethe_State(RefState.chain, RefState.base.Mdown);
  530. else if (whichDSF == 'm') State[0] = ODSLF_XXZ_Bethe_State(RefState.chain, RefState.base.Mdown - 1);
  531. else if (whichDSF == 'p') State[0] = ODSLF_XXZ_Bethe_State(RefState.chain, RefState.base.Mdown + 1);
  532. else JSCerror("Unknown whichDSF in Scan_State_List<ODSLF_XXZ... constructor.");
  533. }
  534. */
  535. template<>
  536. inline LiebLin_Bethe_State& Scan_State_List<LiebLin_Bethe_State>::Return_State (string base_label_ref)
  537. {
  538. int n = 0;
  539. while (n < ndef && base_label_ref.compare(base_label[n]) != 0) n++;
  540. if (n == ndef) {
  541. State[n] = State[0];
  542. base_label[n] = base_label_ref;
  543. info[n].Nfull = 1LL; // Nfull not definable for LiebLin
  544. ndef++;
  545. }
  546. return(State[n]);
  547. }
  548. template<>
  549. inline XXZ_Bethe_State& Scan_State_List<XXZ_Bethe_State>::Return_State (string base_label_ref)
  550. {
  551. int n = 0;
  552. while (n < ndef && base_label_ref.compare(base_label[n]) != 0) n++;
  553. if (n == ndef) {
  554. Heis_Base checkbase (State[0].chain, base_label_ref);
  555. State[n] = XXZ_Bethe_State (State[0].chain, checkbase);
  556. info[n].Nfull = checkbase.dimH;
  557. ndef++;
  558. }
  559. return(State[n]);
  560. }
  561. template<>
  562. inline XXX_Bethe_State& Scan_State_List<XXX_Bethe_State>::Return_State (string base_label_ref)
  563. {
  564. int n = 0;
  565. while (n < ndef && base_label_ref.compare(base_label[n]) != 0) n++;
  566. if (n == ndef) {
  567. Heis_Base checkbase (State[0].chain, base_label_ref);
  568. State[n] = XXX_Bethe_State (State[0].chain, checkbase);
  569. info[n].Nfull = checkbase.dimH;
  570. ndef++;
  571. }
  572. return(State[n]);
  573. }
  574. template<>
  575. inline XXZ_gpd_Bethe_State& Scan_State_List<XXZ_gpd_Bethe_State>::Return_State (string base_label_ref)
  576. {
  577. int n = 0;
  578. while (n < ndef && base_label_ref.compare(base_label[n]) != 0) n++;
  579. if (n == ndef) {
  580. Heis_Base checkbase (State[0].chain, base_label_ref);
  581. State[n] = XXZ_gpd_Bethe_State (State[0].chain, checkbase);
  582. info[n].Nfull = checkbase.dimH;
  583. ndef++;
  584. }
  585. return(State[n]);
  586. }
  587. /*
  588. template<>
  589. inline ODSLF_XXZ_Bethe_State& Scan_State_List<ODSLF_XXZ_Bethe_State>::Return_State (long long int base_id_ref, long long int type_id_ref)
  590. {
  591. int n = 0;
  592. while (n < ndef && !(base_id_ref == State[n].base_id && type_id_ref == State[n].type_id)) n++;
  593. if (n == ndef) {
  594. State[n] = ODSLF_XXZ_Bethe_State (State[0].chain, base_id_ref, type_id_ref);
  595. info[n].Nfull = State[n].maxid + 1LL;
  596. ndef++;
  597. }
  598. return(State[n]);
  599. }
  600. */
  601. template<>
  602. //inline void Scan_State_List<LiebLin_Bethe_State>::Populate_List (char whichDSF, const LiebLin_Bethe_State& RefScanState)
  603. inline void Scan_State_List<LiebLin_Bethe_State>::Populate_List (char whichDSF, const LiebLin_Bethe_State& SeedScanState)
  604. {
  605. // For LiebLin_Bethe_State: only one base is used, so there is only one state here.
  606. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  607. stringstream baselabel;
  608. baselabel << State[0].N;
  609. base_label[0] = baselabel.str();
  610. stringstream label0;
  611. label0 << State[0].N << LABELSEP << JSCcoding[0] << LABELSEP;//"_0_";
  612. //State[0].Set_to_Label (label0.str(), RefScanState.Ix2);
  613. State[0].Set_to_Label (label0.str(), SeedScanState.Ix2);
  614. info[0].Nfull = 1LL; // Nfull not definable for LiebLin
  615. ndef = 1;
  616. }
  617. /*
  618. template<>
  619. //inline void Scan_State_List<XXZ_Bethe_State>::Populate_List (char whichDSF, const XXZ_Bethe_State& RefScanState)
  620. inline void Scan_State_List<XXZ_Bethe_State>::Populate_List_pre_plusplusG_8 (char whichDSF, const XXZ_Bethe_State& SeedScanState)
  621. {
  622. // creates all types of states containing up to nexc_max excitations
  623. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  624. //cout << "In Populate_List: " << State[0] << endl;
  625. //Vect<long long int> bases_id = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  626. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_id.size() << "\tPossible bases: " << bases_id << endl;
  627. Vect<string> bases_label = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  628. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_label.size() << "\tPossible bases: " << bases_label << endl;
  629. for (int ib = 0; ib < bases_label.size(); ++ib) {
  630. //cout << "ib = " << ib << "\tlabel " << bases_label[ib] << endl;
  631. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  632. //cout << "Done building base for label " << bases_label[ib] << endl;
  633. State[ndef] = XXZ_Bethe_State (State[0].chain, checkbase);
  634. base_label[ndef] = bases_label[ib];
  635. info[ndef].Nfull = 1LL;
  636. ndef++;
  637. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  638. }
  639. }
  640. */
  641. /*
  642. // ++G_7 versions:
  643. template<>
  644. //inline void Scan_State_List<XXZ_Bethe_State>::Populate_List (char whichDSF, const XXZ_Bethe_State& RefScanState)
  645. inline void Scan_State_List<XXZ_Bethe_State>::Populate_List (char whichDSF, const XXZ_Bethe_State& SeedScanState)
  646. {
  647. // creates all types of states containing up to nexc_max excitations
  648. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  649. //cout << "In Populate_List: " << State[0] << endl;
  650. //Vect<long long int> bases_id = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  651. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_id.size() << "\tPossible bases: " << bases_id << endl;
  652. Vect<string> bases_label = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  653. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_label.size() << "\tPossible bases: " << bases_label << endl;
  654. for (int ib = 0; ib < bases_label.size(); ++ib) {
  655. //cout << "ib = " << ib << "\tlabel " << bases_label[ib] << endl;
  656. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  657. //cout << "Done building base for label " << bases_label[ib] << endl;
  658. State[ndef] = XXZ_Bethe_State (State[0].chain, checkbase);
  659. base_label[ndef] = bases_label[ib];
  660. info[ndef].Nfull = 1LL;
  661. ndef++;
  662. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  663. }
  664. }
  665. template<>
  666. //inline void Scan_State_List<XXX_Bethe_State>::Populate_List (char whichDSF, const XXX_Bethe_State& RefScanState)
  667. inline void Scan_State_List<XXX_Bethe_State>::Populate_List (char whichDSF, const XXX_Bethe_State& SeedScanState)
  668. {
  669. // creates all types of states containing up to nexc_max excitations
  670. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  671. //cout << "In Populate_List: " << State[0] << endl;
  672. // To take infinite rapidities into account, we use intermediate states with up to 2 less finite rapidities (1 for Szz, 2 for Spm)
  673. int nrinfrapmax = 0;
  674. if (whichDSF == 'z') nrinfrapmax = 1;
  675. else if (whichDSF == 'p') nrinfrapmax = JSC::min(2, SeedScanState.base.Mdown);
  676. //if (whichDSF == 'z' && RefScanState.chain.Nsites == 2*RefScanState.base.Mdown)
  677. //if (whichDSF == 'z' && SeedScanState.chain.Nsites == 2*SeedScanState.base.Mdown)
  678. //JSCerror("Szz at zero field for XXX is simply Smp/2. Compute the latter instead.");
  679. //if (whichDSF == 'p' && RefScanState.chain.Nsites == 2*(RefScanState.base.Mdown + 1))
  680. //if (whichDSF == 'p' && SeedScanState.chain.Nsites/2 <= SeedScanState.base.Mdown)
  681. //JSCerror("Spm for XXX at M >= N/2 is not implemented.");
  682. for (int nrinfrap = 0; nrinfrap <= nrinfrapmax; ++nrinfrap) {
  683. //Vect<long long int> bases_id = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  684. Vect<string> bases_label = State[0].chain.Possible_Bases (State[0].base.Mdown - nrinfrap); // returns a vector of possible bases
  685. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_id.size() << "\tPossible bases: " << bases_id << endl;
  686. for (int ib = 0; ib < bases_label.size(); ++ib) {
  687. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  688. State[ndef] = XXX_Bethe_State (State[0].chain, checkbase);
  689. base_label[ndef] = bases_label[ib];
  690. //cout << "nrinfrap = " << nrinfrap << "\tIncluding base " << base_label[ndef] << endl;
  691. info[ndef].Nfull = 1LL;
  692. ndef++;
  693. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  694. }
  695. } // for nrinfrap
  696. //cout << "Done populating." << endl;
  697. }
  698. template<>
  699. //inline void Scan_State_List<XXZ_gpd_Bethe_State>::Populate_List (char whichDSF, const XXZ_gpd_Bethe_State& RefScanState)
  700. inline void Scan_State_List<XXZ_gpd_Bethe_State>::Populate_List (char whichDSF, const XXZ_gpd_Bethe_State& SeedScanState)
  701. {
  702. // creates all types of states containing up to nexc_max excitations
  703. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  704. //cout << "In Populate_List: " << State[0] << endl;
  705. //Vect<long long int> bases_id = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  706. Vect<string> bases_label = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  707. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_id.size() << "\tPossible bases: " << bases_id << endl;
  708. for (int ib = 0; ib < bases_label.size(); ++ib) {
  709. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  710. State[ndef] = XXZ_gpd_Bethe_State (State[0].chain, checkbase);
  711. base_label[ndef] = bases_label[ib];
  712. info[ndef].Nfull = 1LL;
  713. ndef++;
  714. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  715. }
  716. }
  717. */
  718. // ++G_8 versions:
  719. template<>
  720. //inline void Scan_State_List<XXZ_Bethe_State>::Populate_List (char whichDSF, const XXZ_Bethe_State& RefScanState)
  721. inline void Scan_State_List<XXZ_Bethe_State>::Populate_List (char whichDSF, const XXZ_Bethe_State& SeedScanState)
  722. {
  723. // creates all types of states containing up to nexc_max excitations
  724. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  725. // We assume that SeedScanState has quantum numbers which are set according to the relevant AveragingState.
  726. // This function creates a list of states with other bases in the vicinity of that of SeedScanState,
  727. // matching the quantum numbers as closely as possible.
  728. Vect<int> Str_L(SeedScanState.chain.Nstrings);
  729. for (int i = 0; i < SeedScanState.chain.Nstrings; ++i) Str_L[i] = SeedScanState.chain.Str_L[i];
  730. // First of all, we create a list of the possible bases themselves.
  731. Vect<string> bases_label = Possible_Bases (SeedScanState.base.Nrap, Str_L, SeedScanState.base.Mdown); // returns a vector of possible bases
  732. for (int ib = 0; ib < bases_label.size(); ++ib) {
  733. //cout << "ib = " << ib << "\tlabel " << bases_label[ib] << endl;
  734. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  735. //cout << "Done building base for label " << bases_label[ib] << endl;
  736. State[ndef] = XXZ_Bethe_State (State[0].chain, checkbase);
  737. State[ndef].Set_to_Closest_Matching_Ix2_fixed_Base (SeedScanState);
  738. State[ndef].Set_Label_from_Ix2 (State[ndef].Ix2); // sets to trivial label for this base
  739. //cout << "\tSet state label to " << State[ndef].label << endl;
  740. //cout << "\tSet state to " << State[ndef] << endl;
  741. base_label[ndef] = bases_label[ib];
  742. info[ndef].Nfull = State[ndef].base.dimH;
  743. ndef++;
  744. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  745. }
  746. }
  747. template<>
  748. //inline void Scan_State_List<XXX_Bethe_State>::Populate_List (char whichDSF, const XXX_Bethe_State& RefScanState)
  749. inline void Scan_State_List<XXX_Bethe_State>::Populate_List (char whichDSF, const XXX_Bethe_State& SeedScanState)
  750. {
  751. // creates all types of states containing up to nexc_max excitations
  752. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  753. // We assume that SeedScanState has quantum numbers which are set according to the relevant AveragingState.
  754. // This function creates a list of states with other bases in the vicinity of that of SeedScanState,
  755. // matching the quantum numbers as closely as possible.
  756. Vect<int> Str_L(SeedScanState.chain.Nstrings);
  757. for (int i = 0; i < SeedScanState.chain.Nstrings; ++i) Str_L[i] = SeedScanState.chain.Str_L[i];
  758. // To take infinite rapidities into account, we use intermediate states with up to 2 less finite rapidities (1 for Szz, 2 for Spm)
  759. int nrinfrapmax = 0;
  760. if (whichDSF == 'z') nrinfrapmax = 1;
  761. else if (whichDSF == 'p') nrinfrapmax = JSC::min(2, SeedScanState.base.Mdown);
  762. //if (whichDSF == 'z' && RefScanState.chain.Nsites == 2*RefScanState.base.Mdown)
  763. //if (whichDSF == 'z' && SeedScanState.chain.Nsites == 2*SeedScanState.base.Mdown)
  764. //JSCerror("Szz at zero field for XXX is simply Smp/2. Compute the latter instead.");
  765. //if (whichDSF == 'p' && RefScanState.chain.Nsites == 2*(RefScanState.base.Mdown + 1))
  766. //if (whichDSF == 'p' && SeedScanState.chain.Nsites/2 <= SeedScanState.base.Mdown)
  767. //JSCerror("Spm for XXX at M >= N/2 is not implemented.");
  768. Vect<int> Nrapmod = SeedScanState.base.Nrap;
  769. for (int nrinfrap = 0; nrinfrap <= nrinfrapmax; ++nrinfrap) {
  770. Nrapmod[0] = SeedScanState.base.Nrap[0] - nrinfrap;
  771. if (Nrapmod[0] < 0) JSCerror("Putting too many rapidities at infinity in JSC_Scan.h: Possible_Bases.");
  772. Vect<string> bases_label = Possible_Bases (Nrapmod, Str_L, SeedScanState.base.Mdown-nrinfrap); // returns a vector of possible bases
  773. for (int ib = 0; ib < bases_label.size(); ++ib) {
  774. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  775. State[ndef] = XXX_Bethe_State (State[0].chain, checkbase);
  776. State[ndef].Set_to_Closest_Matching_Ix2_fixed_Base (SeedScanState);
  777. //State[ndef].Set_Label_from_Ix2 (State[ndef].Ix2); // sets to trivial label for this base
  778. base_label[ndef] = bases_label[ib];
  779. //cout << "nrinfrap = " << nrinfrap << "\tIncluding base " << base_label[ndef] << endl;
  780. info[ndef].Nfull = State[ndef].base.dimH;
  781. ndef++;
  782. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  783. }
  784. } // for nrinfrap
  785. //cout << "Done populating." << endl;
  786. }
  787. template<>
  788. //inline void Scan_State_List<XXZ_gpd_Bethe_State>::Populate_List (char whichDSF, const XXZ_gpd_Bethe_State& RefScanState)
  789. inline void Scan_State_List<XXZ_gpd_Bethe_State>::Populate_List (char whichDSF, const XXZ_gpd_Bethe_State& SeedScanState)
  790. {
  791. // creates all types of states containing up to nexc_max excitations
  792. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  793. // We assume that SeedScanState has quantum numbers which are set according to the relevant AveragingState.
  794. // This function creates a list of states with other bases in the vicinity of that of SeedScanState,
  795. // matching the quantum numbers as closely as possible.
  796. Vect<int> Str_L(SeedScanState.chain.Nstrings);
  797. for (int i = 0; i < SeedScanState.chain.Nstrings; ++i) Str_L[i] = SeedScanState.chain.Str_L[i];
  798. // First of all, we create a list of the possible bases themselves.
  799. Vect<string> bases_label = Possible_Bases (SeedScanState.base.Nrap, Str_L, SeedScanState.base.Mdown); // returns a vector of possible bases
  800. for (int ib = 0; ib < bases_label.size(); ++ib) {
  801. Heis_Base checkbase (State[0].chain, bases_label[ib]);
  802. State[ndef] = XXZ_gpd_Bethe_State (State[0].chain, checkbase);
  803. State[ndef].Set_to_Closest_Matching_Ix2_fixed_Base (SeedScanState);
  804. //State[ndef].Set_Label_from_Ix2 (State[ndef].Ix2); // sets to trivial label for this base
  805. base_label[ndef] = bases_label[ib];
  806. info[ndef].Nfull = State[ndef].base.dimH;
  807. ndef++;
  808. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  809. }
  810. }
  811. /*
  812. template<>
  813. inline void Scan_State_List<ODSLF_XXZ_Bethe_State>::Populate_List ()
  814. {
  815. // creates all types of states containing up to nexc_max excitations
  816. if (ndef != 0) JSCerror("Please only populate a virgin Scan_State_List.");
  817. //cout << "In Populate_List: " << State[0] << endl;
  818. Vect<long long int> bases_id = State[0].chain.Possible_Bases (State[0].base.Mdown); // returns a vector of possible bases
  819. //cout << "Mdown = " << State[0].base.Mdown << "\tPossible bases size: " << bases_id.size() << "\tPossible bases: " << bases_id << endl;
  820. for (int ib = 0; ib < bases_id.size(); ++ib) {
  821. ODSLF_Base checkbase (State[0].chain, bases_id[ib]);
  822. Vect<long long int> types_id = checkbase.Possible_Types (); // returns a vector of possible types
  823. //cout << "For base_id " << bases_id[ib] << "\t found types " << types_id << endl;
  824. for (int it = 0; it < types_id.size(); ++it) {
  825. if (bases_id[ib] < 1000000) { // FUDGE: consider only one-strings
  826. //cout << "Populate list: constructing state: " << bases_id[ib] << "\t" << types_id[it] << endl;
  827. State[ndef] = ODSLF_XXZ_Bethe_State (State[0].chain, bases_id[ib], types_id[it]);
  828. //cout << "Populate list: before setting id: " << endl << State[ndef] << endl;
  829. State[ndef].Set_to_id(0LL);
  830. //cout << "Populate list: after setting id: " << endl << State[ndef] << endl;
  831. info[ndef].Nfull = State[ndef].maxid + 1LL;
  832. ndef++;
  833. if (ndef >= MAX_STATE_LIST_SIZE) JSCerror("Increase number of elements in ScanStateList.");
  834. }
  835. }
  836. }
  837. }
  838. */
  839. template<class Tstate>
  840. inline void Scan_State_List<Tstate>::Include_Info (Scan_Info& info_to_add, string base_label_ref)
  841. {
  842. int n = 0;
  843. while (n < ndef && base_label_ref.compare(base_label[n]) != 0) n++;
  844. if (n == ndef) {
  845. cout << "ndef = " << ndef << endl;
  846. for (int i = 0; i < ndef; ++i) cout << base_label[i] << "\t";
  847. cout << endl;
  848. cout << "base_label_ref " << base_label_ref << endl;
  849. JSCerror("Did not find base_label_ref in Scan_State_List::Include_Info.");
  850. }
  851. info[n] += info_to_add;
  852. return;
  853. }
  854. /*
  855. inline int Base_Distance (string base_label_1, string base_label_2)
  856. {
  857. int dist = 0;
  858. State_Label_Data labeldata1 = Extract_base_label_data (base_label_1);
  859. State_Label_Data labeldata2 = Extract_base_label_data (base_label_2);
  860. return(dist);
  861. }
  862. */
  863. /*
  864. inline int Type_Nr_Excitations (string base_label)
  865. {
  866. State_Label_Data labeldata = Extract_base_label_data (base_label);
  867. return(labeldata.nexc[0]);
  868. }
  869. */
  870. template<class Tstate>
  871. inline void Scan_State_List<Tstate>::Raise_Scanning_Flags (DP threshold)
  872. {
  873. flag_for_scan = true;
  874. }
  875. /*
  876. {
  877. // Reset whole flags vector:
  878. flag_for_scan = false;
  879. // We first flag all base/types having up to 1 higher string and up to 2 excitations in sectors 0-3
  880. for (int n = 0; n < ndef; ++n)
  881. //if (info[n].Nfull == 0LL && Base_Distance (State[n].base_id, 0LL) <= 1
  882. if (!scan_attempted[n] && Base_Distance (base_label[n], base_label[0]) <= 1
  883. && Type_Nr_Excitations(base_label[n]) <= 3)
  884. flag_for_scan[n] = true;
  885. // Second, if one base/type combination has given good results,
  886. // we flag as yet unopened but slightly more complex base/types:
  887. //cout << "Called Raise_Scanning_Flags: ndef = " << ndef << endl;
  888. for (int n = 0; n < ndef; ++n) {
  889. //cout << "Base/type " << State[n].base_id << "\t" << State[n].type_id << "\t" << info[n].sumrule_obtained << "\t" << threshold << endl;
  890. if (info[n].Nfull > 0LL && info[n].sumrule_obtained > threshold) {
  891. //cout << "Base/type " << State[n].base_id << "\t" << State[n].type_id << "\tflagging descendents:" << endl;
  892. for (int n2 = 0; n2 < ndef; ++n2) {
  893. //cout << "\tBase/type " << State[n2].base_id << "\t" << State[n2].type_id
  894. // << "\t" << !scan_attempted[n2] << "\t" << (Base_Distance (State[n].base_id, State[n2].base_id) <= 1)
  895. // << "\t" << (Type_Distance (State[n].type_id, State[n2].type_id) <= 2) << endl;
  896. //if (info[n2].Nfull == 0LL && Base_Distance (State[n].base_id, State[n2].base_id) <= 1
  897. if (!scan_attempted[n2] && Base_Distance (base_label[n], base_label[n2]) <= 1
  898. && Type_Distance (base_label[n], base_label[n2]) <= 2) {
  899. flag_for_scan[n2] = true;
  900. //cout << "Flagging base/type " << State[n2].base_id << "\t" << State[n2].type_id
  901. // << "\tfrom " << State[n].base_id << "\t" << State[n].type_id
  902. // << "\tBase_Distance " << Base_Distance (State[n].base_id, State[n2].base_id) << "\tType_Distance " << Type_Distance (State[n].type_id, State[n2].type_id) << endl;
  903. }
  904. }
  905. }
  906. }
  907. }
  908. */
  909. template<class Tstate>
  910. inline void Scan_State_List<Tstate>::Order_in_SRC ()
  911. {
  912. if (ndef > 0) {
  913. Vect_INT index(ndef);
  914. for (int i = 0; i < ndef; ++i) index[i] = i;
  915. Vect<DP> sr (ndef);
  916. for (int i = 0; i < ndef; ++i) sr[i] = info[i].sumrule_obtained;
  917. sr.QuickSort(index, 0, ndef - 1);
  918. Vect<Tstate> State_ordered(ndef);
  919. Vect<string> base_label_ordered(ndef);
  920. Vect<Scan_Info> info_ordered(ndef);
  921. Vect<bool> flag_for_scan_ordered(ndef);
  922. // Put data in proper order
  923. for (int i = 0; i < ndef; ++i) {
  924. State_ordered[i] = State[index[ndef - 1 - i] ];
  925. base_label_ordered[i] = base_label[index[ndef - 1 - i] ];
  926. info_ordered[i] = info[index[ndef - 1 - i] ];
  927. flag_for_scan_ordered[i] = flag_for_scan[index[ndef - 1 - i] ];
  928. }
  929. // Put back in *this object:
  930. for (int i = 0; i < ndef; ++i) {
  931. State[i] = State_ordered[i];
  932. base_label[i] = base_label_ordered[i];
  933. info[i] = info_ordered[i];
  934. flag_for_scan[i] = flag_for_scan_ordered[i];
  935. } // The rest are all simply 0.
  936. }
  937. // Done !
  938. }
  939. template<class Tstate>
  940. inline void Scan_State_List<Tstate>::Save_Info (const char* sumfile_Cstr)
  941. {
  942. ofstream outfile;
  943. outfile.open(sumfile_Cstr);
  944. if (outfile.fail()) JSCerror("Could not open outfile... ");
  945. outfile.setf(ios::fixed);
  946. //outfile.setf(ios::showpoint);
  947. outfile.precision(16);
  948. //outfile << "base\t\tsumrule_obtained\tNfull\tNinadm\tNdata\tconv\tconv0\tT\tTT.";
  949. //outfile << setw(20) << "base" << setw(25) << "sumrule_obtained" << setw(25) << "Nfull" << setw(10) << "Ninadm" << setw(10) << "Ndata" << setw(10) << "conv" << setw(10) << "conv0" << setw(10) << "T" << setw(10) << "TT.";
  950. outfile << setw(20) << "base" << setw(25) << "sumrule_obtained" << setw(25) << "Nfull" << setw(10) << "Ninadm" << setw(10) << "Ndata" << setw(10) << "conv" << setw(10) << "conv0" << setw(10) << "TT.";
  951. for (int i = 0; i < ndef; ++i)
  952. if (info[i].Nfull > 0.0) {
  953. int TT_hr = int(info[i].TT/3600);
  954. int TT_min = int((info[i].TT - 3600.0*TT_hr)/60);
  955. //outfile << endl << base_label[i] << "\t" << info[i].sumrule_obtained
  956. // << "\t" << info[i].Nfull << "\t" << info[i].Ninadm << "\t" << info[i].Ndata << "\t" << info[i].Ndata_conv << "\t"
  957. // << info[i].Ndata_conv0 << "\t" << info[i].CPU_ticks/CLOCKS_PER_SEC << "\t" << info[i].CPU_ticks_TOT/CLOCKS_PER_SEC;
  958. outfile << endl << setw(20) << base_label[i] << setw(25) << std::fixed << setprecision(20) << info[i].sumrule_obtained;
  959. if (info[i].Nfull < 1.0e+10) outfile << setw(25) << std::fixed << setprecision(0) << info[i].Nfull;
  960. else outfile << setw(25) << std::scientific << setprecision(16) << info[i].Nfull;
  961. //outfile << setw(10) << info[i].Ninadm << setw(10) << info[i].Ndata << setw(10) << info[i].Ndata_conv << setw(10) << info[i].Ndata_conv0 << setw(10) << info[i].CPU_ticks/CLOCKS_PER_SEC << setw(10) << info[i].CPU_ticks_TOT/CLOCKS_PER_SEC;
  962. //outfile << setw(10) << info[i].Ninadm << setw(10) << info[i].Ndata << setw(10) << info[i].Ndata_conv << setw(10) << info[i].Ndata_conv0 << setw(16) << std::fixed << std::showpoint << setprecision(3) << info[i].TT;
  963. outfile << setw(10) << info[i].Ninadm << setw(10) << info[i].Ndata << setw(10) << info[i].Ndata_conv << setw(10) << info[i].Ndata_conv0 << setw(10) << TT_hr << " h " << TT_min << " m " << std::fixed << std::showpoint << setprecision(3) << info[i].TT - 3600.0*TT_hr - 60.0*TT_min << " s";
  964. }
  965. outfile.close();
  966. }
  967. template<class Tstate>
  968. inline void Scan_State_List<Tstate>::Load_Info (const char* sumfile_Cstr)
  969. {
  970. ifstream infile;
  971. infile.open(sumfile_Cstr);
  972. if(infile.fail()) {
  973. cout << endl << sumfile_Cstr << endl;
  974. JSCerror("Could not open input file in Scan_State_List::Load_Info.");
  975. }
  976. // Load first line, containing informative text:
  977. char junk[256];
  978. infile.getline(junk, 256);
  979. // Now load the previous info's:
  980. string base_label_ref;
  981. //DP sr_ref, CPU_ref, CPU_TOT_ref;
  982. DP sr_ref;
  983. //long long int Nfull_ref, Ninadm_ref, Ndata_ref, conv_ref, conv0_ref;
  984. DP Nfull_ref;
  985. long long int Ninadm_ref, Ndata_ref, conv_ref, conv0_ref;
  986. DP TT_ref;
  987. int TT_hr, TT_min;
  988. DP TT_sec;
  989. char a;
  990. while (infile.peek() != EOF) {
  991. //infile >> base_label_ref >> sr_ref >> Nfull_ref >> Ninadm_ref >> Ndata_ref >> conv_ref >> conv0_ref >> CPU_ref >> CPU_TOT_ref;
  992. //infile >> base_label_ref >> sr_ref >> Nfull_ref >> Ninadm_ref >> Ndata_ref >> conv_ref >> conv0_ref >> TT_ref;
  993. infile >> base_label_ref >> sr_ref >> Nfull_ref >> Ninadm_ref >> Ndata_ref >> conv_ref >> conv0_ref >> TT_hr >> a >> TT_min >> a >> TT_sec >> a;
  994. TT_ref = 3600.0 * TT_hr + 60.0* TT_min + TT_sec;
  995. //Scan_Info info_ref (sr_ref, Nfull_ref, Ninadm_ref, Ndata_ref, conv_ref, conv0_ref, CPU_ref);
  996. Scan_Info info_ref (sr_ref, Nfull_ref, Ninadm_ref, Ndata_ref, conv_ref, conv0_ref, TT_ref);
  997. (*this).Include_Info (info_ref, base_label_ref);
  998. }
  999. infile.close();
  1000. return;
  1001. }
  1002. } // namespace JSC
  1003. #endif