Browse Source

Cleanup of source files: first pass, up to src/INTEG

master
J.-S. Caux 6 years ago
parent
commit
d337885305
75 changed files with 2900 additions and 4518 deletions
  1. 16
    49
      src/BETHE/Base.cc
  2. 2
    1
      src/BETHE/Bethe_State.cc
  3. 2
    0
      src/BETHE/Offsets.cc
  4. 9
    9
      src/COMBI/Combinatorics.cc
  5. 5
    4
      src/EXECS/2CBG_ThLim.cc
  6. 5
    3
      src/EXECS/Analyze_RAW_File.cc
  7. 91
    101
      src/EXECS/Check_RAW_File.cc
  8. 4
    86
      src/EXECS/Heis_DSF.cc
  9. 18
    15
      src/EXECS/Heis_DSF_GeneralState.cc
  10. 6
    11
      src/EXECS/Heis_DSF_par.cc
  11. 9
    4
      src/EXECS/Heis_DSF_par_Prepare.cc
  12. 6
    6
      src/EXECS/Heis_DSF_par_Run.cc
  13. 6
    4
      src/EXECS/Heis_DSF_par_Wrapup.cc
  14. 2
    8
      src/EXECS/LiebLin_Catalogue_Fixed_c_k_Nscaling.cc
  15. 4
    5
      src/EXECS/LiebLin_DSF.cc
  16. 6
    16
      src/EXECS/LiebLin_DSF_GeneralState.cc
  17. 11
    26
      src/EXECS/LiebLin_DSF_GeneralState_par_Prepare.cc
  18. 10
    18
      src/EXECS/LiebLin_DSF_GeneralState_par_Run.cc
  19. 9
    25
      src/EXECS/LiebLin_DSF_GeneralState_par_Wrapup.cc
  20. 4
    7
      src/EXECS/LiebLin_DSF_MosesState.cc
  21. 8
    10
      src/EXECS/LiebLin_DSF_MosesState_par.cc
  22. 9
    4
      src/EXECS/LiebLin_DSF_MosesState_par_Prepare.cc
  23. 8
    27
      src/EXECS/LiebLin_DSF_MosesState_par_Run.cc
  24. 7
    3
      src/EXECS/LiebLin_DSF_MosesState_par_Wrapup.cc
  25. 6
    11
      src/EXECS/LiebLin_DSF_over_Ensemble.cc
  26. 4
    36
      src/EXECS/LiebLin_DSF_over_Ensemble_par.cc
  27. 7
    9
      src/EXECS/LiebLin_DSF_par.cc
  28. 9
    4
      src/EXECS/LiebLin_DSF_par_Prepare.cc
  29. 6
    4
      src/EXECS/LiebLin_DSF_par_Run.cc
  30. 7
    3
      src/EXECS/LiebLin_DSF_par_Wrapup.cc
  31. 8
    10
      src/EXECS/LiebLin_DSF_tester.cc
  32. 8
    10
      src/EXECS/LiebLin_DSF_tester_Ix2.cc
  33. 6
    9
      src/EXECS/LiebLin_Data_Daemon.cc
  34. 6
    8
      src/EXECS/LiebLin_Data_Daemon_Nscaling.cc
  35. 2
    4
      src/EXECS/LiebLin_Fourier_ssf_to_Qsqx.cc
  36. 2
    1
      src/EXECS/LiebLin_Fourier_to_t_equal_x.cc
  37. 2
    6
      src/EXECS/LiebLin_Fourier_to_t_equal_x_from_RAW.cc
  38. 4
    5
      src/EXECS/LiebLin_Fourier_to_x_equal_t.cc
  39. 2
    16
      src/EXECS/LiebLin_Fourier_to_x_equal_t_from_RAW.cc
  40. 4
    3
      src/EXECS/LiebLin_Moses_tester.cc
  41. 6
    4
      src/EXECS/LiebLin_RAW_File_Stats.cc
  42. 0
    5
      src/EXECS/LiebLin_TBA.cc
  43. 0
    4
      src/EXECS/LiebLin_TBA_fixed_nbar.cc
  44. 2
    4
      src/EXECS/LiebLin_TBA_fixed_nbar_ebar.cc
  45. 4
    3
      src/EXECS/ODSLF_DSF.cc
  46. 0
    2
      src/EXECS/Produce_Sorted_RAW_File.cc
  47. 2
    1
      src/EXECS/RAW_File_Stats.cc
  48. 0
    4
      src/EXECS/Smoothen_Heis_DSF.cc
  49. 5
    11
      src/EXECS/Smoothen_LiebLin_DSF.cc
  50. 7
    15
      src/EXECS/Smoothen_LiebLin_DSF_GeneralState.cc
  51. 5
    14
      src/EXECS/Smoothen_LiebLin_DSF_MosesState.cc
  52. 5
    12
      src/EXECS/Smoothen_LiebLin_DSF_Scaled.cc
  53. 4
    9
      src/EXECS/Smoothen_LiebLin_DSF_over_Ensemble.cc
  54. 4
    4
      src/EXECS/Smoothen_ODSLF_DSF.cc
  55. 6
    3
      src/EXECS/XXZ_gpd_StagSz_h0.cc
  56. 98
    381
      src/HEIS/Heis.cc
  57. 2
    5
      src/HEIS/Heis_Chem_Pot.cc
  58. 31
    114
      src/HEIS/Heis_Matrix_Element_Contrib.cc
  59. 15
    24
      src/HEIS/Heis_Sumrules.cc
  60. 0
    3
      src/HEIS/M_vs_H.cc
  61. 27
    199
      src/HEIS/XXX_Bethe_State.cc
  62. 98
    116
      src/HEIS/XXZ_Bethe_State.cc
  63. 34
    291
      src/HEIS/XXZ_gpd_Bethe_State.cc
  64. 142
    181
      src/HEIS/ln_Overlap_XXX.cc
  65. 166
    180
      src/HEIS/ln_Smin_ME_XXX.cc
  66. 255
    265
      src/HEIS/ln_Smin_ME_XXZ.cc
  67. 216
    250
      src/HEIS/ln_Smin_ME_XXZ_gpd.cc
  68. 246
    244
      src/HEIS/ln_Smm_ME_XXX.cc
  69. 171
    175
      src/HEIS/ln_Sz_ME_XXX.cc
  70. 41
    51
      src/HEIS/ln_Sz_ME_XXZ.cc
  71. 214
    250
      src/HEIS/ln_Sz_ME_XXZ_gpd.cc
  72. 284
    428
      src/HEIS/ln_Szm_p_Smz_ME_XXX.cc
  73. 338
    331
      src/HEIS/ln_Szz_ME_XXX.cc
  74. 122
    349
      src/INTEG/Integration.cc
  75. 10
    5
      src/INTEG/Integration_par.cc

+ 16
- 49
src/BETHE/Base.cc View File

@@ -30,7 +30,8 @@ namespace ABACUS {
30 30
 
31 31
   Base::Base (const Base& RefBase)  // copy constructor
32 32
     : Charge(RefBase.Charge), Nrap(Vect<int>(RefBase.Nrap.size())), Nraptot(RefBase.Nraptot),
33
-      Ix2_infty(Vect<DP>(RefBase.Ix2_infty.size())), Ix2_max(Vect<int>(RefBase.Ix2_max.size())), id(RefBase.id)
33
+      Ix2_infty(Vect<DP>(RefBase.Ix2_infty.size())),
34
+      Ix2_max(Vect<int>(RefBase.Ix2_max.size())), id(RefBase.id)
34 35
   {
35 36
     for (int i = 0; i < Nrap.size(); ++i) {
36 37
       Nrap[i] = RefBase.Nrap[i];
@@ -39,36 +40,14 @@ namespace ABACUS {
39 40
     }
40 41
   }
41 42
 
42
-  /*
43
-  // DEPRECATED
44
-  Base::Base (const Heis_Chain& RefChain, int M)
45
-    : Charge(M), Nrap(Vect<int>(RefChain.Nstrings)), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings))
46
-  {
47
-    for (int i = 0; i < RefChain.Nstrings; ++i) Nrap[i] = 0;
48
-    Nrap[0] = M;
49
-
50
-    Nraptot = 0;
51
-    for (int i = 0; i < RefChain.Nstrings; ++i) Nraptot += Nrap[i];
52
-
53
-    // The id of this is zero by definition
54
-    id = 0LL;
55
-
56
-    // Now compute the Ix2_infty numbers
57
-
58
-    (*this).Compute_Ix2_limits(RefChain);
59
-
60
-  }
61
-  */
62 43
   Base::Base (const Heis_Chain& RefChain, const Vect<int>& Nrapidities)
63
-    : Charge(0), Nrap(Nrapidities), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings)),
44
+    : Charge(0), Nrap(Nrapidities), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)),
45
+      Ix2_max(Vect<int>(RefChain.Nstrings)),
64 46
       id (0LL)
65 47
   {
66
-
67 48
     // Check consistency of Nrapidities vector with RefChain
68
-
69
-    //if (RefChain.Nstrings != Nrapidities.size()) cout << "error:  Nstrings = " << RefChain.Nstrings << "\tNrap.size = " << Nrapidities.size() << endl;
70
-
71
-    if (RefChain.Nstrings != Nrapidities.size()) ABACUSerror("Incompatible Nrapidities vector used in Base constructor.");
49
+    if (RefChain.Nstrings != Nrapidities.size())
50
+      ABACUSerror("Incompatible Nrapidities vector used in Base constructor.");
72 51
 
73 52
     int Mcheck = 0;
74 53
     for (int i = 0; i < RefChain.Nstrings; ++i) Mcheck += RefChain.Str_L[i] * Nrap[i];
@@ -86,13 +65,12 @@ namespace ABACUS {
86 65
     }
87 66
 
88 67
     // Now compute the Ix2_infty numbers
89
-
90 68
     (*this).Compute_Ix2_limits(RefChain);
91
-
92 69
   }
93 70
 
94 71
   Base::Base (const Heis_Chain& RefChain, long long int id_ref)
95
-    : Charge(0), Nrap(Vect<int>(RefChain.Nstrings)), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings)),
72
+    : Charge(0), Nrap(Vect<int>(RefChain.Nstrings)), Nraptot(0),
73
+      Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings)),
96 74
       id (id_ref)
97 75
   {
98 76
     // Build Nrapidities vector from id_ref
@@ -106,14 +84,6 @@ namespace ABACUS {
106 84
     }
107 85
     Nrap[0] = id_eff;
108 86
 
109
-    //id = id_ref;
110
-
111
-    //cout << "In Base constructor:  id_ref = " << id_ref << " and Nrapidities = " << Nrap << endl;
112
-
113
-    // Check consistency of Nrapidities vector with RefChain
114
-
115
-    //if (RefChain.Nstrings != Nrap.size()) ABACUSerror("Incompatible Nrapidities vector used in Base constructor.");
116
-
117 87
     int Mcheck = 0;
118 88
     for (int i = 0; i < RefChain.Nstrings; ++i) Mcheck += RefChain.Str_L[i] * Nrap[i];
119 89
     Charge = Mcheck;
@@ -122,7 +92,6 @@ namespace ABACUS {
122 92
     for (int i = 0; i < RefChain.Nstrings; ++i) Nraptot += Nrap[i];
123 93
 
124 94
     // Now compute the Ix2_infty numbers
125
-
126 95
     (*this).Compute_Ix2_limits(RefChain);
127 96
   }
128 97
 
@@ -172,20 +141,23 @@ namespace ABACUS {
172 141
 
173 142
 	  sum2 = 0.0;
174 143
 
175
-	  sum2 += (RefChain.Str_L[j] == RefChain.Str_L[k]) ? 0.0 : 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
176
-										  - 0.5 * fabs(RefChain.Str_L[j] - RefChain.Str_L[k]) * RefChain.anis));
144
+	  sum2 += (RefChain.Str_L[j] == RefChain.Str_L[k]) ? 0.0 :
145
+	    2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
146
+			   - 0.5 * fabs(RefChain.Str_L[j] - RefChain.Str_L[k]) * RefChain.anis));
177 147
 	  sum2 += 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
178 148
 				 - 0.5 * (RefChain.Str_L[j] + RefChain.Str_L[k]) * RefChain.anis));
179 149
 
180 150
 	  for (int a = 1; a < ABACUS::min(RefChain.Str_L[j], RefChain.Str_L[k]); ++a)
181 151
 	    sum2 += 2.0 * 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
182
-					 - 0.5 * (fabs(RefChain.Str_L[j] - RefChain.Str_L[k]) + 2.0*a) * RefChain.anis));
152
+					 - 0.5 * (fabs(RefChain.Str_L[j] - RefChain.Str_L[k])
153
+						  + 2.0*a) * RefChain.anis));
183 154
 
184 155
 	  sum1 += (Nrap[k] - ((j == k) ? 1 : 0)) * sum2;
185 156
 	}
186 157
 
187
-	Ix2_infty[j] = (1.0/PI) * fabs(RefChain.Nsites * 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j])
188
-								      - 0.5 * RefChain.Str_L[j] * RefChain.anis)) - sum1);
158
+	Ix2_infty[j] = (1.0/PI) * fabs(RefChain.Nsites *
159
+				       2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j])
160
+						      - 0.5 * RefChain.Str_L[j] * RefChain.anis)) - sum1);
189 161
 
190 162
       }  // The Ix2_infty are now set.
191 163
 
@@ -293,9 +265,6 @@ namespace ABACUS {
293 265
 	  Ix2_max[j] -= 2;
294 266
 	}
295 267
 
296
-	// Fudge, for strings:
297
-	//if (RefChain.Str_L[j] >= 1) Ix2_max[j] += 2;
298
-	//Ix2_max[j] += 2;
299 268
       }
300 269
 
301 270
     } // if XXZ_gpd
@@ -303,6 +272,4 @@ namespace ABACUS {
303 272
   }
304 273
 
305 274
 
306
-
307
-
308 275
 } // namespace ABACUS

+ 2
- 1
src/BETHE/Bethe_State.cc View File

@@ -22,7 +22,8 @@ using namespace std;
22 22
 
23 23
 namespace ABACUS {
24 24
 
25
-  Bethe_State::Bethe_State (long long int base_id_ref, long long int type_id_ref, long long int id_ref, long long int maxid_ref) :
25
+  Bethe_State::Bethe_State (long long int base_id_ref, long long int type_id_ref,
26
+			    long long int id_ref, long long int maxid_ref) :
26 27
     base_id(base_id_ref), type_id(type_id_ref), id(id_ref), maxid(maxid_ref) {}
27 28
 
28 29
 } // namespace ABACUS

+ 2
- 0
src/BETHE/Offsets.cc View File

@@ -10,6 +10,8 @@ File:  src/BETHE/Offsets.cc
10 10
 
11 11
 Purpose:  defines functions in Offsets class.
12 12
 
13
+IN DEVELOPMENT
14
+
13 15
 ***********************************************************/
14 16
 
15 17
 #include "ABACUS.h"

+ 9
- 9
src/COMBI/Combinatorics.cc View File

@@ -8,7 +8,7 @@ Copyright (c) J.-S. Caux.
8 8
 
9 9
 Combinatorics.cc
10 10
 
11
-Defines all class related to combinatorics.
11
+Defines all classes related to combinatorics.
12 12
 
13 13
 ******************************************************************/
14 14
 
@@ -67,16 +67,16 @@ namespace ABACUS {
67 67
   }
68 68
 
69 69
   std::ostream& operator<< (std::ostream& s, Choose_Table& Ref_table)
70
-    {
71
-      s << endl;
72
-      for (int n = 0; n <= Ref_table.power(); ++n) {
73
-	for (int m = 0; m <= Ref_table.power(); ++m)
74
-	  s << Ref_table.choose(n, m) << " ";
75
-	s << endl;
76
-      }
70
+  {
71
+    s << endl;
72
+    for (int n = 0; n <= Ref_table.power(); ++n) {
73
+      for (int m = 0; m <= Ref_table.power(); ++m)
74
+	s << Ref_table.choose(n, m) << " ";
77 75
       s << endl;
78
-      return(s);
79 76
     }
77
+    s << endl;
78
+    return(s);
79
+  }
80 80
 
81 81
   Choose_Table::~Choose_Table()
82 82
   {

+ 5
- 4
src/EXECS/2CBG_ThLim.cc View File

@@ -20,7 +20,9 @@ using namespace ABACUS;
20 20
 int main(int argc, const char* argv[])
21 21
 {
22 22
 
23
-  if (argc != 7) ABACUSerror("Wrong number of arguments to 2CBG_ThLim executable.  Use c(best to set to 1), mu, Omega, kBT, TT(minutes), bool Save_data (0 == false).");
23
+  if (argc != 7) ABACUSerror("Wrong number of arguments to 2CBG_ThLim executable.  "
24
+			     "Use c (best to set to 1), mu, Omega, kBT, TT(minutes), "
25
+			     "bool Save_data (0 == false).");
24 26
 
25 27
   DP c_int = atof(argv[1]);
26 28
   DP mu = atof(argv[2]);
@@ -30,12 +32,11 @@ int main(int argc, const char* argv[])
30 32
   bool Save_data = bool(atoi(argv[6]));
31 33
 
32 34
   if (c_int <= 0.0) ABACUSerror("Give a strictly positive c.");
33
-  if (Omega <= 0.0) ABACUSerror("Give a strictly positive Omega, otherwise the algorithm cannot converge.");
35
+  if (Omega <= 0.0) ABACUSerror("Give a strictly positive Omega, "
36
+				"otherwise the algorithm cannot converge.");
34 37
   if (kBT <= 0.0) ABACUSerror("Negative T ?  You must be a string theorist.");
35 38
   if (Max_Secs < 10) ABACUSerror("Give more time.");
36 39
 
37
-  //cout << "Read c_int = " << c_int << "\tmu = " << mu << "\tOmega = " << Omega << "\tkBT = " << kBT << "\tMax_Secs = " << Max_Secs << endl;
38
-
39 40
   Solve_2CBG_TBAE_via_refinements (c_int, mu, Omega, kBT, Max_Secs, Save_data);
40 41
 
41 42
   return(0);

+ 5
- 3
src/EXECS/Analyze_RAW_File.cc View File

@@ -39,7 +39,6 @@ int main(int argc, char* argv[])
39 39
   DP omega;
40 40
   int iK;
41 41
   DP FF;
42
-  //int conv;
43 42
   DP dev;
44 43
   string label;
45 44
 
@@ -77,8 +76,11 @@ int main(int argc, char* argv[])
77 76
   cout << "Entropy: \t" << -(sumFFsqlnFFsq - sumFFsq * log(sumFFsq))/sumFFsq << endl;
78 77
 
79 78
   cout << "iK\tnFFatK\tIPRatiK\tentropyatiK:" << endl;
80
-  for (int iK = iKmin; iK <= iKmax; ++iK) cout << iK << "\t" << nFFatK[iK-iKmin] << "\t" << sumFF4atK[iK-iKmin]/(sumFFsqatK[iK - iKmin] * sumFFsqatK[iK - iKmin]) << "\t" << -(sumFFsqlnFFsqatK[iK-iKmin] - sumFFsqatK[iK-iKmin] * log(sumFFsqatK[iK-iKmin]))/sumFFsqatK[iK-iKmin]<< endl;
81
-
79
+  for (int iK = iKmin; iK <= iKmax; ++iK)
80
+    cout << iK << "\t" << nFFatK[iK-iKmin] << "\t"
81
+	 << sumFF4atK[iK-iKmin]/(sumFFsqatK[iK - iKmin] * sumFFsqatK[iK - iKmin]) << "\t"
82
+	 << -(sumFFsqlnFFsqatK[iK-iKmin] - sumFFsqatK[iK-iKmin] * log(sumFFsqatK[iK-iKmin])
83
+	      )/sumFFsqatK[iK-iKmin]<< endl;
82 84
 
83 85
   return(0);
84 86
 }

+ 91
- 101
src/EXECS/Check_RAW_File.cc View File

@@ -24,7 +24,8 @@ int main(int argc, char* argv[])
24 24
   if (argc != 7) { // print out some instructions
25 25
     cout << "Usage of Check_RAW_File executable:  provide the following arguments:" << endl;
26 26
     cout << "(sorted!) raw file name, iKmin, iKmax, sympoint, FFmin, check_option." << endl;
27
-    cout << "Check option:  0 == check for missing states,  1 == check for multiply-appearing states." << endl;
27
+    cout << "Check option:  0 == check for missing states,  "
28
+      "1 == check for multiply-appearing states." << endl;
28 29
   }
29 30
 
30 31
   char* rawfilename = argv[1];
@@ -34,113 +35,102 @@ int main(int argc, char* argv[])
34 35
   DP FFmin = atof(argv[5]);
35 36
   int check_option = atoi(argv[6]);
36 37
 
37
-    ifstream RAW_infile;
38
-    RAW_infile.open(rawfilename);
39
-    if (RAW_infile.fail()) {
40
-      cout << rawfilename << endl;
41
-      ABACUSerror("Could not open sorted RAW_infile... ");
42
-    }
38
+  ifstream RAW_infile;
39
+  RAW_infile.open(rawfilename);
40
+  if (RAW_infile.fail()) {
41
+    cout << rawfilename << endl;
42
+    ABACUSerror("Could not open sorted RAW_infile... ");
43
+  }
43 44
 
44
-    DP omega_next, omega, omega_prev;
45
-    int iK_next, iK, iK_prev;
46
-    DP FF_next, FF, FF_prev;
47
-    //int conv_next, conv, conv_prev;
48
-    DP dev_next, dev, dev_prev;
49
-    string label_next, label, label_prev;
50
-
51
-    if (check_option > 1) {
52
-      FF = 0.0;
53
-      FF_prev = 0.0;
54
-      FF_next = 0.0;
55
-      FFmin = -1.0;
56
-    }
45
+  DP omega_next, omega, omega_prev;
46
+  int iK_next, iK, iK_prev;
47
+  DP FF_next, FF, FF_prev;
48
+  DP dev_next, dev, dev_prev;
49
+  string label_next, label, label_prev;
50
+
51
+  if (check_option > 1) {
52
+    FF = 0.0;
53
+    FF_prev = 0.0;
54
+    FF_next = 0.0;
55
+    FFmin = -1.0;
56
+  }
57
+
58
+  RAW_infile >> omega >> iK;
59
+  if (check_option <= 1) RAW_infile >> FF;
60
+  RAW_infile >> dev;
61
+  RAW_infile >> label;
62
+  RAW_infile >> omega_next >> iK_next;
63
+  if (check_option <= 1) RAW_infile >> FF_next;
64
+  RAW_infile >> dev_next;
65
+  RAW_infile >> label_next;
66
+
67
+  int line = 1;
57 68
 
58
-    //RAW_infile >> omega >> iK >> FF >> conv >> label;
59
-    RAW_infile >> omega >> iK;
60
-    if (check_option <= 1) RAW_infile >> FF;
61
-    RAW_infile >> dev;
62
-    RAW_infile >> label;
63
-    //RAW_infile >> omega_next >> iK_next >> FF_next >> conv_next >> label_next;
69
+  char a;
70
+
71
+
72
+  while (fabs(FF) > FFmin && RAW_infile.peek() != EOF) {
73
+
74
+    omega_prev = omega; iK_prev = iK; FF_prev = FF; dev_prev = dev; label_prev = label;
75
+    omega = omega_next; iK = iK_next; FF = FF_next; dev = dev_next; label = label_next;
64 76
     RAW_infile >> omega_next >> iK_next;
65
-    if (check_option <= 1) RAW_infile >> FF_next;
77
+    if (check_option <= 1) RAW_infile >> FF_next; // for non-Z checks
66 78
     RAW_infile >> dev_next;
67 79
     RAW_infile >> label_next;
80
+    line++;
81
+
82
+    if (label.compare(label_next) == 0)
83
+      cout << "Identical labels around line " << line << ": " << endl
84
+	   << omega << "\t" << iK << "\t" << FF << "\t" << dev << "\t" << label << endl;
85
+
86
+    if (check_option == 0 && iK != 0 && iK != sympoint && iK >= iKmin && iK <= iKmax
87
+	&& fabs((FF - FF_prev)/(FF + FF_prev)) > 1.0e-6 && fabs((FF - FF_next)/(FF + FF_next)) > 1.0e-6) {
68 88
 
69
-    int line = 1;
70
-
71
-    char a;
72
-
73
-
74
-    while (fabs(FF) > FFmin && RAW_infile.peek() != EOF) {
75
-
76
-      //omega_prev = omega; iK_prev = iK; FF_prev = FF; conv_prev = conv; label_prev = label;
77
-      omega_prev = omega; iK_prev = iK; FF_prev = FF; dev_prev = dev; label_prev = label;
78
-      //omega = omega_next; iK = iK_next; FF = FF_next; conv = conv_next; label = label_next;
79
-      omega = omega_next; iK = iK_next; FF = FF_next; dev = dev_next; label = label_next;
80
-      //RAW_infile >> omega_next >> iK_next >> FF_next >> conv_next >> label_next;
81
-      RAW_infile >> omega_next >> iK_next;
82
-      if (check_option <= 1) RAW_infile >> FF_next; // for non-Z checks
83
-      RAW_infile >> dev_next;
84
-      RAW_infile >> label_next;
85
-      //cout << "checking line " << line << endl;
86
-      //cout << omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << label_prev << endl
87
-      //   << omega << "\t" << iK << "\t" << FF << "\t" << label << endl
88
-      //   << omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << label_next << endl;
89
-      line++;
90
-
91
-      if (label.compare(label_next) == 0)
92
-	cout << "Identical labels around line " << line << ": " << endl
93
-	     << omega << "\t" << iK << "\t" << FF << "\t" << dev << "\t" << label << endl;
94
-
95
-      if (check_option == 0 && iK != 0 && iK != sympoint && iK >= iKmin && iK <= iKmax
96
-	  && fabs((FF - FF_prev)/(FF + FF_prev)) > 1.0e-6 && fabs((FF - FF_next)/(FF + FF_next)) > 1.0e-6) {
97
-
98
-	cout << "State missing around line " << line << ": " << endl
99
-	  //<< omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << conv_prev << "\t" << label_prev << endl
100
-	     << omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << dev_prev << "\t" << label_prev << endl
101
-	  //<< omega << "\t" << iK << "\t" << FF << "\t" << conv << "\t" << label << endl
102
-	     << omega << "\t" << iK << "\t" << FF << "\t" << dev << "\t" << label << endl
103
-	  //<< omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << conv_next << "\t" << label_next << endl;
104
-	     << omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << dev_next << "\t" << label_next << endl;
105
-
106
-	cin >> a;
107
-	//break;
108
-      }
109
-
110
-      if (check_option == 1 && iK_prev == iK && iK == iK_next && fabs((omega - omega_prev)/(omega + omega_prev)) < 1.0e-8 && fabs((omega - omega_next)/(omega + omega_next)) < 1.0e-8 && fabs((FF - FF_prev)/(FF + FF_prev)) < 1.0e-8 && fabs((FF - FF_next)/(FF + FF_next)) < 1.0e-8) {
111
-
112
-	cout << "Triple state around line " << line << ": " << endl
113
-	  //<< omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << conv_prev << "\t" << label_prev << endl
114
-	     << omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << dev_prev << "\t" << label_prev << endl
115
-	  //<< omega << "\t" << iK << "\t" << FF << "\t" << conv << "\t" << label << endl
116
-	     << omega << "\t" << iK << "\t" << FF << "\t" << dev << "\t" << label << endl
117
-	  //<< omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << conv_next << "\t" << label_next << endl;
118
-	     << omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << dev_next << "\t" << label_next << endl;
119
-	cin >> a;
120
-      }
121
-
122
-      if (check_option == 2 && iK != 0 && iK != sympoint && iK >= iKmin && iK <= iKmax
123
-	  && fabs((omega - omega_prev)/(omega + omega_prev)) > 1.0e-6 && fabs((omega - omega_next)/(omega + omega_next)) > 1.0e-6) {
124
-
125
-	cout << "State missing around line " << line << ": " << endl
126
-	     << omega_prev << "\t" << iK_prev << "\t" << dev_prev << "\t" << label_prev << endl
127
-	     << omega << "\t" << iK << "\t" << dev << "\t" << label << endl
128
-	     << omega_next << "\t" << iK_next << "\t" << dev_next << "\t" << label_next << endl;
129
-
130
-	cin >> a;
131
-	//break;
132
-      }
133
-
134
-      if (check_option == 3 && iK_prev == iK && iK == iK_next && fabs((omega - omega_prev)/(omega + omega_prev)) < 1.0e-8 && fabs((omega - omega_next)/(omega + omega_next)) < 1.0e-8) {
135
-
136
-	cout << "Triple state around line " << line << ": " << endl
137
-	     << omega_prev << "\t" << iK_prev << "\t" << dev_prev << "\t" << label_prev << endl
138
-	     << omega << "\t" << iK << "\t" << dev << "\t" << label << endl
139
-	     << omega_next << "\t" << iK_next << "\t" << dev_next << "\t" << label_next << endl;
140
-	cin >> a;
141
-      }
89
+      cout << "State missing around line " << line << ": " << endl
90
+	   << omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << dev_prev << "\t" << label_prev << endl
91
+	   << omega << "\t" << iK << "\t" << FF << "\t" << dev << "\t" << label << endl
92
+	   << omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << dev_next << "\t" << label_next << endl;
142 93
 
94
+      cin >> a;
143 95
     }
144 96
 
145
-    return(0);
97
+    if (check_option == 1 && iK_prev == iK
98
+	&& iK == iK_next && fabs((omega - omega_prev)/(omega + omega_prev)) < 1.0e-8
99
+	&& fabs((omega - omega_next)/(omega + omega_next)) < 1.0e-8
100
+	&& fabs((FF - FF_prev)/(FF + FF_prev)) < 1.0e-8
101
+	&& fabs((FF - FF_next)/(FF + FF_next)) < 1.0e-8) {
102
+
103
+      cout << "Triple state around line " << line << ": " << endl
104
+	   << omega_prev << "\t" << iK_prev << "\t" << FF_prev << "\t" << dev_prev << "\t" << label_prev << endl
105
+	   << omega << "\t" << iK << "\t" << FF << "\t" << dev << "\t" << label << endl
106
+	   << omega_next << "\t" << iK_next << "\t" << FF_next << "\t" << dev_next << "\t" << label_next << endl;
107
+      cin >> a;
108
+    }
109
+
110
+    if (check_option == 2 && iK != 0 && iK != sympoint && iK >= iKmin && iK <= iKmax
111
+	&& fabs((omega - omega_prev)/(omega + omega_prev)) > 1.0e-6
112
+	&& fabs((omega - omega_next)/(omega + omega_next)) > 1.0e-6) {
113
+
114
+      cout << "State missing around line " << line << ": " << endl
115
+	   << omega_prev << "\t" << iK_prev << "\t" << dev_prev << "\t" << label_prev << endl
116
+	   << omega << "\t" << iK << "\t" << dev << "\t" << label << endl
117
+	   << omega_next << "\t" << iK_next << "\t" << dev_next << "\t" << label_next << endl;
118
+
119
+      cin >> a;
120
+    }
121
+
122
+    if (check_option == 3 && iK_prev == iK && iK == iK_next
123
+	&& fabs((omega - omega_prev)/(omega + omega_prev)) < 1.0e-8
124
+	&& fabs((omega - omega_next)/(omega + omega_next)) < 1.0e-8) {
125
+
126
+      cout << "Triple state around line " << line << ": " << endl
127
+	   << omega_prev << "\t" << iK_prev << "\t" << dev_prev << "\t" << label_prev << endl
128
+	   << omega << "\t" << iK << "\t" << dev << "\t" << label << endl
129
+	   << omega_next << "\t" << iK_next << "\t" << dev_next << "\t" << label_next << endl;
130
+      cin >> a;
131
+    }
132
+
133
+  }
134
+
135
+  return(0);
146 136
 }

+ 4
- 86
src/EXECS/Heis_DSF.cc View File

@@ -26,11 +26,12 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of Heis_DSF executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  "
30
+      "Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
30 31
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
31
-    cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
32
+    cout << "int N \t\t\t Length (number of sites) of the system:  "
33
+      "use positive even integer values only" << endl;
32 34
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
33
-    //cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
34 35
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
35 36
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
36 37
     cout << "bool refine \t\t Is this a refinement of a earlier calculations ?  (0 == false, 1 == true)" << endl;
@@ -44,8 +45,6 @@ int main(int argc, char* argv[])
44 45
     DP Delta = atof(argv[ctr++]);
45 46
     int N = atoi(argv[ctr++]);
46 47
     int M = atoi(argv[ctr++]);
47
-    //int iKmin = atoi(argv[5]);
48
-    //int iKmax = atoi(argv[6]);
49 48
     int Max_Secs = atoi(argv[ctr++]);
50 49
     DP target_sumrule = atof(argv[ctr++]);
51 50
     bool refine = (atoi(argv[ctr++]) == 1);
@@ -53,89 +52,8 @@ int main(int argc, char* argv[])
53 52
     // We systematically scan over all momentum integers (to avoid problems with Brillouin folding
54 53
     int iKmin = -1000*N;
55 54
     int iKmax = 1000*N;
56
-    //Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, Max_Secs, target_sumrule, refine, 0, 1);
57 55
     Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, Max_Secs, target_sumrule, refine);
58 56
   }
59 57
 
60
-
61
-
62
-  // The argument given is the name of the standard args_Heis_DSF arguments file
63
-
64
-  /*
65
-  if (argc == 2) { // Used an input file to provide the arguments
66
-
67
-    if (strcmp(argv[1],"help") == 0) { // Output some instructions
68
-      cout << "Usage of Heis_DSF executable: " << endl;
69
-      cout << endl << "Provide arguments by either using one of the three following options:" << endl << endl;
70
-      cout << "1) via an argument file (see the template `args_Heis_DSF' in directory src/EXECS/), for example" << endl << endl;
71
-      cout << "Heis_DSF args_Heis_DSF" << endl << endl;
72
-      cout << "2) with arguments (for general momenta scan) whichDSF Delta N M iKmin iKmax Max_Secs refine, for example" << endl << endl;
73
-      cout << "Heis_DSF z 0.9 100 40 0 50 600 0" << endl << endl;
74
-      cout << "3) with arguments (for general momenta scan) whichDSF Delta N M iKneeded Max_Secs refine, for example" << endl << endl;
75
-      cout << "Heis_DSF z 0.9 100 40 20 600 0" << endl << endl;
76
-    }
77
-
78
-    else { // read argument file
79
-
80
-      ifstream argsfile;
81
-      argsfile.open(argv[1]);
82
-      if (argsfile.fail()) {
83
-	cout << argv[1] << endl;
84
-	ABACUSerror("Could not open arguments file.");
85
-      }
86
-
87
-    char junk[256];
88
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
89
-    char whichDSF;  argsfile >> whichDSF;
90
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
91
-    DP Delta;  argsfile >> Delta;
92
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
93
-    int N; argsfile >> N;
94
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
95
-    int M; argsfile >> M;
96
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
97
-    //bool fixed_iK; argsfile >> fixed_iK;
98
-    //while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
99
-    //int iKneeded; argsfile >> iKneeded;
100
-    int iKmin, iKmax;  argsfile >> iKmin >> iKmax;
101
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
102
-    int Max_Secs; argsfile >> Max_Secs;
103
-    while (argsfile.peek() == '#' || argsfile.peek() == '\t' || argsfile.peek() == ' ' || argsfile.peek() == '\n') argsfile.getline(junk, 256);
104
-    bool refine;  argsfile >> refine;
105
-
106
-    Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, Max_Secs, refine);
107
-    }
108
-  } // if (argc == 2)
109
-
110
-  else if (argc == 8) { // fixed_iK
111
-    char whichDSF = *argv[1];
112
-    DP Delta = atof(argv[2]);
113
-    int N = atoi(argv[3]);
114
-    int M = atoi(argv[4]);
115
-    int iKneeded = atoi(argv[5]);
116
-    int Max_Secs = atoi(argv[6]);
117
-    bool refine = (atoi(argv[7]) == 1);
118
-
119
-    //Scan_Heis (whichDSF, Delta, N, M, iKneeded, Max_Secs, refine);
120
-    Scan_Heis (whichDSF, Delta, N, M, iKneeded, iKneeded, Max_Secs, refine);
121
-  }
122
-
123
-  else if (argc == 9) { // !fixed_iK
124
-    char whichDSF = *argv[1];
125
-    DP Delta = atof(argv[2]);
126
-    int N = atoi(argv[3]);
127
-    int M = atoi(argv[4]);
128
-    int iKmin = atoi(argv[5]);
129
-    int iKmax = atoi(argv[6]);
130
-    int Max_Secs = atoi(argv[7]);
131
-    bool refine = (atoi(argv[8]) == 1);
132
-
133
-    //Scan_Heis (whichDSF, Delta, N, M, iKneeded, Max_Secs, refine);
134
-    Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, Max_Secs, refine);
135
-  }
136
-
137
-  else ABACUSerror("Wrong number of arguments to Heis_DSF executable.");
138
-  */
139
-
140 58
   return(0);
141 59
 }

+ 18
- 15
src/EXECS/Heis_DSF_GeneralState.cc View File

@@ -26,12 +26,14 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of Heis_DSF executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  "
30
+      "Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
30 31
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
31
-    cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
32
+    cout << "int N \t\t\t Length (number of sites) of the system:  "
33
+      "use positive even integer values only" << endl;
32 34
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
33
-    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the AveragingState; used as defaultScanStatename" << endl;
34
-    //cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
35
+    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers "
36
+      "defining the AveragingState; used as defaultScanStatename" << endl;
35 37
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
36 38
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
37 39
     cout << "bool refine \t\t Is this a refinement of a earlier calculations ?  (0 == false, 1 == true)" << endl;
@@ -45,8 +47,6 @@ int main(int argc, char* argv[])
45 47
     int N = atoi(argv[ctr++]);
46 48
     int M = atoi(argv[ctr++]);
47 49
     char* Ix2filenameprefix = argv[ctr++];
48
-    //int iKmin = atoi(argv[5]);
49
-    //int iKmax = atoi(argv[6]);
50 50
     int Max_Secs = atoi(argv[ctr++]);
51 51
     DP target_sumrule = atof(argv[ctr++]);
52 52
     bool refine = (atoi(argv[ctr++]) == 1);
@@ -81,8 +81,6 @@ int main(int argc, char* argv[])
81 81
       Ix2_input_file >> Nrap_read[level];
82 82
       Ix2_read[level] = Vect<int> (Nrap_read[level]);
83 83
       for (int alpha = 0; alpha < Nrap_read[level]; ++alpha) Ix2_input_file >> Ix2_read[level][alpha];
84
-      //cout << "Read level = " << level << "\tNrap_read[level] = " << Nrap_read[level] << endl;
85
-      //cout << "\tIx2_read[level] = " << Ix2_read[level] << endl;
86 84
     } while (Ix2_input_file.peek() != EOF);
87 85
 
88 86
     // Construct the Averaging State:
@@ -95,36 +93,41 @@ int main(int argc, char* argv[])
95 93
     if (Delta > 0.0 && Delta < 1.0) {
96 94
       XXZ_Bethe_State AveragingState (chain, base);
97 95
       for (int il = 0; il < chain.Nstrings; ++il) {
98
-	if (Nrap_read[il] > 0) for (int alpha = 0; alpha < Nrap_read[il]; ++alpha) AveragingState.Ix2[il][alpha] = Ix2_read[il][alpha];
96
+	if (Nrap_read[il] > 0) for (int alpha = 0; alpha < Nrap_read[il]; ++alpha)
97
+				 AveragingState.Ix2[il][alpha] = Ix2_read[il][alpha];
99 98
       }
100 99
       AveragingState.Set_Label_from_Ix2(AveragingState.Ix2);
101 100
       AveragingState.Compute_All(true);
102 101
 
103
-      //cout << "AveragingState read from file: " << AveragingState << endl;
104 102
       // Perform the scan:
105
-      Scan_Heis (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
103
+      Scan_Heis (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax,
104
+		 Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
106 105
     }
107 106
     else if (Delta == 1.0) {
108 107
       XXX_Bethe_State AveragingState (chain, base);
109 108
       for (int il = 0; il < chain.Nstrings; ++il) {
110
-	for (int alpha = 0; alpha < Nrap_read[il]; ++alpha) AveragingState.Ix2[il][alpha] = Ix2_read[il][alpha];
109
+	for (int alpha = 0; alpha < Nrap_read[il]; ++alpha)
110
+	  AveragingState.Ix2[il][alpha] = Ix2_read[il][alpha];
111 111
       }
112 112
       AveragingState.Set_Label_from_Ix2(AveragingState.Ix2);
113 113
       AveragingState.Compute_All(true);
114 114
 
115 115
       // Perform the scan:
116
-      Scan_Heis (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
116
+      Scan_Heis (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax,
117
+		 Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
117 118
     }
118 119
     else if (Delta > 1.0) {
119 120
       XXZ_gpd_Bethe_State AveragingState (chain, base);
120 121
       for (int il = 0; il < chain.Nstrings; ++il) {
121
-	for (int alpha = 0; alpha < Nrap_read[il]; ++alpha) AveragingState.Ix2[il][alpha] = Ix2_read[il][alpha];
122
+	for (int alpha = 0; alpha < Nrap_read[il]; ++alpha)
123
+	  AveragingState.Ix2[il][alpha] = Ix2_read[il][alpha];
122 124
       }
123 125
       AveragingState.Set_Label_from_Ix2(AveragingState.Ix2);
124 126
       AveragingState.Compute_All(true);
125 127
 
126 128
       // Perform the scan:
127
-      Scan_Heis (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
129
+      Scan_Heis (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax,
130
+		 Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
128 131
     }
129 132
   }
130 133
 

+ 6
- 11
src/EXECS/Heis_DSF_par.cc View File

@@ -29,13 +29,16 @@ int main(int argc, char *argv[])
29 29
 
30 30
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
31 31
     cout << endl << "Usage of Heis_DSF_par executable: " << endl;
32
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the Heis_DSF executable) using the same model parameters." << endl;
32
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
33
+      "serial run (obtained using the Heis_DSF executable) using the same model parameters." << endl;
33 34
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
35
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
36
+      "m for S- S+, z for Sz Sz, p for S+ S-." << endl;
35 37
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
36 38
     cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
37 39
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
40
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
41
+      "recommended values:  0 and N" << endl;
39 42
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
40 43
     cout << endl << "EXAMPLE: " << endl << endl;
41 44
     cout << "mpiexec -np 8 Heis_DSF_par z 1.0 100 40 0 100 600" << endl << endl;
@@ -77,14 +80,10 @@ int main(int argc, char *argv[])
77 80
 
78 81
   while (tnow - tstart < Max_Secs - supercycle_time - 300) { // space for one more supercycle, + 5 minutes safety
79 82
 
80
-    //cout << "rank " << rank << " ready to prepare." << endl;
81
-
82 83
     if (rank == 0)
83 84
       // Split up thread list into chunks, one per processor
84 85
       Prepare_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, nr_processors);
85 86
 
86
-    //cout << "rank " << rank << " done preparing, ready to scan." << endl;
87
-
88 87
     // Barrier synchronization, to make sure other processes wait for process of rank 0
89 88
     // to have finished splitting up the thr file into pieces before starting:
90 89
     MPI_Barrier (MPI::COMM_WORLD);
@@ -93,8 +92,6 @@ int main(int argc, char *argv[])
93 92
     Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax,
94 93
 	       supercycle_time, target_sumrule, refine, rank, nr_processors);
95 94
 
96
-    //cout << "rank " << rank << " finished scanning, reached wrapup stage." << endl;
97
-
98 95
     // Another barrier synchronization
99 96
     MPI_Barrier (MPI::COMM_WORLD);
100 97
 
@@ -102,8 +99,6 @@ int main(int argc, char *argv[])
102 99
     if (rank == 0)
103 100
       Wrapup_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, nr_processors);
104 101
 
105
-    //cout << "rank " << rank << " passed wrapup stage." << endl;
106
-
107 102
     // Another barrier synchronization
108 103
     MPI_Barrier (MPI::COMM_WORLD);
109 104
 

+ 9
- 4
src/EXECS/Heis_DSF_par_Prepare.cc View File

@@ -29,13 +29,17 @@ int main(int argc, char *argv[])
29 29
 
30 30
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
31 31
     cout << endl << "Usage of Heis_DSF_par_Prepare executable: " << endl;
32
-    cout << endl << "This function prepares for ABACUSG in parallel mode, starting from a preexisting serial run (obtained using the Heis_DSF executable) using the same model parameters." << endl;
32
+    cout << endl << "This function prepares for ABACUSG in parallel mode, "
33
+      "starting from a preexisting serial run (obtained using the Heis_DSF executable) "
34
+      "using the same model parameters." << endl;
33 35
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
36
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  "
37
+      "Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
35 38
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
36 39
     cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
37 40
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
41
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
42
+      "recommended values:  0 and N" << endl;
39 43
     cout << "int paralevel" << endl;
40 44
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
41 45
     cout << "int nr_processors_at_new_level \t for this new parallelization level." << endl;
@@ -65,7 +69,8 @@ int main(int argc, char *argv[])
65 69
     string defaultScanStatename = "";
66 70
 
67 71
     // Split up thread list into chunks, one per processor
68
-    Prepare_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
72
+    Prepare_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, paralevel, rank_lower_paralevels,
73
+				nr_processors_lower_paralevels, nr_processors_at_newlevel);
69 74
 
70 75
   }
71 76
 

+ 6
- 6
src/EXECS/Heis_DSF_par_Run.cc View File

@@ -29,13 +29,16 @@ int main(int argc, char *argv[])
29 29
 
30 30
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
31 31
     cout << endl << "Usage of Heis_DSF_par_Run executable: " << endl;
32
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the Heis_DSF executable) using the same model parameters." << endl;
32
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
33
+      "serial run (obtained using the Heis_DSF executable) using the same model parameters." << endl;
33 34
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
35
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
36
+      "m for S- S+, z for Sz Sz, p for S+ S-." << endl;
35 37
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
36 38
     cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
37 39
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
40
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
41
+      "recommended values:  0 and N" << endl;
39 42
     cout << "int paralevel" << endl;
40 43
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
41 44
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
@@ -64,9 +67,6 @@ int main(int argc, char *argv[])
64 67
   }
65 68
   Max_Secs = atoi(argv[n++]);
66 69
   supercycle_time = atoi(argv[n++]);
67
-  //}
68
-
69
-  //DP supercycle_time = 600.0; // allotted time per supercycle
70 70
 
71 71
   if (Max_Secs <= supercycle_time) ABACUSerror("Please allow more time in Heis_DSF_par_Run.");
72 72
 

+ 6
- 4
src/EXECS/Heis_DSF_par_Wrapup.cc View File

@@ -13,7 +13,6 @@ Purpose:  Parallel version of ABACUS using MPICH.
13 13
 ***********************************************************/
14 14
 
15 15
 #include "ABACUS.h"
16
-//#include "mpi.h" // not needed for Prepare or Wrapup
17 16
 
18 17
 using namespace ABACUS;
19 18
 
@@ -31,11 +30,13 @@ int main(int argc, char *argv[])
31 30
     cout << endl << "Usage of Heis_DSF_par_Wrapup executable: " << endl;
32 31
     cout << endl << "This function wraps up an ABACUSG parallel mode run." << endl;
33 32
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
33
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
34
+      "m for S- S+, z for Sz Sz, p for S+ S-." << endl;
35 35
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
36 36
     cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
37 37
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
38
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
39
+      "recommended values:  0 and N" << endl;
39 40
     cout << "int paralevel" << endl;
40 41
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
41 42
     cout << "int nr_processors_at_new_level \t for this latest parallelization level." << endl;
@@ -65,7 +66,8 @@ int main(int argc, char *argv[])
65 66
     string defaultScanStatename = "";
66 67
 
67 68
     // Split up thread list into chunks, one per processor
68
-    Wrapup_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
69
+    Wrapup_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, paralevel, rank_lower_paralevels,
70
+			       nr_processors_lower_paralevels, nr_processors_at_newlevel);
69 71
 
70 72
   }
71 73
 

+ 2
- 8
src/EXECS/LiebLin_Catalogue_Fixed_c_k_Nscaling.cc View File

@@ -27,11 +27,9 @@ int main(int argc, char* argv[])
27 27
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
28 28
     cout << endl << "Usage of LiebLin_Catalogue_Fixed_c_k_Nscaling executable: " << endl;
29 29
     cout << endl << "Provide the following arguments:" << endl << endl;
30
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
31
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
31 32
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
32
-    //cout << "int Nc \t\t number of steps in interaction value" << endl;
33
-    //cout << "int Nstep \t\t\t Steps to be taken in number of particles:  use positive integer values only. Filling will be set to 1 (L == N)" << endl;
34
-    //cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over (in units of N == Nstep):  recommended values:  0 and 2*N" << endl;
35 33
     cout << "int kfact \t\t momentum factor: momemntum will be set to kfact * kF/4" << endl;
36 34
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
37 35
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
@@ -47,11 +45,8 @@ int main(int argc, char* argv[])
47 45
     DP target_sumrule = atof(argv[ia++]);
48 46
     int Max_Secs = atoi(argv[ia++]);
49 47
 
50
-
51
-    //clock_t StartTime = clock();
52 48
     double StartTime = omp_get_wtime();
53 49
 
54
-    //clock_t ActualTime = StartTime;
55 50
     double ActualTime = omp_get_wtime();
56 51
 
57 52
     int Secs_left = Max_Secs;
@@ -99,7 +94,6 @@ int main(int argc, char* argv[])
99 94
 
100 95
       ActualTime = omp_get_wtime();
101 96
 
102
-      //Secs_left = int(60*Max_minutes - double(ActualTime - StartTime)/CLOCKS_PER_SEC);
103 97
       Secs_left = int(Max_Secs - (ActualTime - StartTime));
104 98
       cout << "Done with N = " << N << ". Time left = " << Secs_left << " seconds." << endl;
105 99
 

+ 4
- 5
src/EXECS/LiebLin_DSF.cc View File

@@ -26,11 +26,13 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_Tgt0 executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
33
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
34
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
35
+      "recommended values:  -2*N and 2*N" << endl;
34 36
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
35 37
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
36 38
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
@@ -51,9 +53,6 @@ int main(int argc, char* argv[])
51 53
     DP target_sumrule = atof(argv[9]);
52 54
     bool refine = (atoi(argv[10]) == 1);
53 55
 
54
-    //cout << "target_sumrule = " << target_sumrule << endl;
55
-
56
-    //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, Max_Secs, target_sumrule, refine, 0, 1);
57 56
     Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, Max_Secs, target_sumrule, refine);
58 57
   }
59 58
 

+ 6
- 16
src/EXECS/LiebLin_DSF_GeneralState.cc View File

@@ -26,13 +26,15 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_Tgt0 executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
33
-    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the AveragingState; used as defaultScanStatename" << endl;
34
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
35
-    //cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
34
+    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the "
35
+      "AveragingState; used as defaultScanStatename" << endl;
36
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
37
+      "recommended values:  -2*N and 2*N" << endl;
36 38
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
37 39
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
38 40
     cout << "bool refine \t\t Is this a refinement of earlier calculations ?  (0 == false, 1 == true)" << endl;
@@ -49,7 +51,6 @@ int main(int argc, char* argv[])
49 51
     char* Ix2filenameprefix = argv[n++];
50 52
     int iKmin = atoi(argv[n++]);
51 53
     int iKmax = atoi(argv[n++]);
52
-    //DP kBT = atof(argv[n++]);
53 54
     int Max_Secs = atoi(argv[n++]);
54 55
     DP target_sumrule = atof(argv[n++]);
55 56
     bool refine = (atoi(argv[n++]) == 1);
@@ -70,7 +71,6 @@ int main(int argc, char* argv[])
70 71
     }
71 72
     for (int i = 0; i < N; ++i) {
72 73
       Ix2_input_file >> Ix2_input[i];
73
-      //cout << i << "\t" << Ix2_input[i] << endl;
74 74
     }
75 75
 
76 76
     // Now define the AveragingState
@@ -78,16 +78,6 @@ int main(int argc, char* argv[])
78 78
     AveragingState.Ix2 = Ix2_input;
79 79
     AveragingState.Compute_All(true);
80 80
 
81
-    //cout << "Averaging state: " << AveragingState << endl;
82
-
83
-    //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, Max_Secs, target_sumrule, refine, 0, 1);
84
-    //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, Max_Secs, target_sumrule, refine);
85
-
86
-    //void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultScanStatename, int iKmin, int iKmax,
87
-    //		  int Max_Secs, DP target_sumrule, bool refine, int paralevel, Vect<int> rank, Vect<int> nr_processors)
88
-    // Simplified function call of the above:
89
-    //void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultScanStatename, int iKmin, int iKmax,
90
-    //		  int Max_Secs, DP target_sumrule, bool refine)
91 81
     Scan_LiebLin (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs, target_sumrule, refine);
92 82
 
93 83
   }

+ 11
- 26
src/EXECS/LiebLin_DSF_GeneralState_par_Prepare.cc View File

@@ -30,15 +30,18 @@ int main(int argc, char *argv[])
30 30
 
31 31
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
32 32
     cout << endl << "Usage of LiebLin_DSF_par_Prepare executable: " << endl;
33
-    cout << endl << "This function prepares an ABACUS parallel mode run, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
33
+    cout << endl << "This function prepares an ABACUS parallel mode run, starting from a preexisting "
34
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
34 35
     cout << endl << "Provide the following arguments:" << endl << endl;
35
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
36
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
37
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
36 38
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
37 39
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
38 40
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
39
-    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the AveragingState; used as defaultScanStatename" << endl;
40
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
41
-    //cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
41
+    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the "
42
+      "AveragingState; used as defaultScanStatename" << endl;
43
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
44
+      "recommended values:  -2*N and 2*N" << endl;
42 45
     cout << "int paralevel" << endl;
43 46
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
44 47
     cout << "int nr_processors_at_new_level \t for this new parallelization level." << endl;
@@ -55,7 +58,6 @@ int main(int argc, char *argv[])
55 58
     Ix2filenameprefix = argv[n++];
56 59
     iKmin = atoi(argv[n++]);
57 60
     iKmax = atoi(argv[n++]);
58
-    //kBT = atof(argv[n++]);
59 61
     paralevel = atoi(argv[n++]); // paralevel == 1 means that we have one layer of parallelization, so no previous rank and nr_processors to specify
60 62
     if (argc != 10 + 2*(paralevel - 1)) ABACUSerror("Wrong nr of arguments in LiebLin_DSF_GeneralState_par_Prepare.");
61 63
 
@@ -75,28 +77,11 @@ int main(int argc, char *argv[])
75 77
     stringstream filenamestrstream;
76 78
     filenamestrstream << Ix2filenameprefix;
77 79
     string defaultScanStatename = filenamestrstream.str();
78
-    /*
79
-    filenamestrstream << ".Ix2";
80
-    string filenamestr = filenamestrstream.str();
81
-    const char* filename_Cstr = filenamestr.c_str();
82
-    Ix2_input_file.open(filename_Cstr);
83
-    if (Ix2_input_file.fail()) {
84
-      cout << filename_Cstr << endl;
85
-      ABACUSerror("Could not open Ix2 input file in LiebLin_DSF_GeneralState");
86
-    }
87
-    for (int i = 0; i < N; ++i) {
88
-      Ix2_input_file >> Ix2_input[i];
89
-      //cout << i << "\t" << Ix2_input[i] << endl;
90
-    }
91
-
92
-    // Define the AveragingState
93
-    LiebLin_Bethe_State AveragingState(c_int, L, N);
94
-    AveragingState.Ix2 = Ix2_input;
95
-    //AveragingState.Compute_All(true);
96
-    */
97 80
 
98 81
     // Split up thread list into chunks, one per processor
99
-    Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
82
+    Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename,
83
+				   paralevel, rank_lower_paralevels, nr_processors_lower_paralevels,
84
+				   nr_processors_at_newlevel);
100 85
 
101 86
   }
102 87
 

+ 10
- 18
src/EXECS/LiebLin_DSF_GeneralState_par_Run.cc View File

@@ -30,24 +30,25 @@ int main(int argc, char *argv[])
30 30
 
31 31
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
32 32
     cout << endl << "Usage of LiebLin_DSF_par executable: " << endl;
33
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
33
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
34
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
34 35
     cout << endl << "Provide the following arguments:" << endl << endl;
35
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
36
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
37
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
36 38
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
37 39
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
38 40
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
39
-    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the AveragingState; used as defaultScanStatename" << endl;
40
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
41
-    //cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
41
+    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the "
42
+      "AveragingState; used as defaultScanStatename" << endl;
43
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
44
+      "recommended values:  -2*N and 2*N" << endl;
42 45
     cout << "int paralevel" << endl;
43 46
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
44 47
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
45
-    //cout << "int supercycle_time \t\t time for one supercycle (in seconds)" << endl;
46 48
 
47 49
     return(0);
48 50
   }
49 51
 
50
-  //else { // correct nr of arguments
51 52
   int n = 1;
52 53
   whichDSF = *argv[n++];
53 54
   c_int = atof(argv[n++]);
@@ -56,7 +57,6 @@ int main(int argc, char *argv[])
56 57
   Ix2filenameprefix = argv[n++];
57 58
   iKmin = atoi(argv[n++]);
58 59
   iKmax = atoi(argv[n++]);
59
-  //kBT = atof(argv[n++]);
60 60
   paralevel = atoi(argv[n++]); // paralevel == 1 means that we have one layer of parallelization, so no previous rank and nr_processors to specify
61 61
   if (argc != 10 + 2*(paralevel - 1)) ABACUSerror("Wrong nr of arguments in LiebLin_DSF_par_Prepare.");
62 62
   Vect<int> rank_lower_paralevels(paralevel - 1);
@@ -66,10 +66,6 @@ int main(int argc, char *argv[])
66 66
     nr_processors_lower_paralevels[i] = atoi(argv[n++]);
67 67
   }
68 68
   Max_Secs = atoi(argv[n++]);
69
-  //  supercycle_time = atoi(argv[n++]);
70
-  //}
71
-
72
-  //DP supercycle_time = 600.0; // allotted time per supercycle
73 69
 
74 70
   if (Max_Secs <= 120) ABACUSerror("Please allow more time in LiebLin_DSF_par_Run.");
75 71
 
@@ -98,7 +94,6 @@ int main(int argc, char *argv[])
98 94
   }
99 95
   for (int i = 0; i < N; ++i) {
100 96
     Ix2_input_file >> Ix2_input[i];
101
-    //cout << i << "\t" << Ix2_input[i] << endl;
102 97
   }
103 98
 
104 99
   // Now define the AveragingState
@@ -126,17 +121,14 @@ int main(int argc, char *argv[])
126 121
   DP tnow = MPI::Wtime();
127 122
 
128 123
 
129
-  //while (tnow - tstart < Max_Secs - supercycle_time - 120) { // space for one more supercycle, + 2 minutes safety
130 124
   if (Max_Secs_used > 0) {
131 125
 
132 126
     // Barrier synchronization
133 127
     MPI_Barrier (MPI::COMM_WORLD);
134 128
 
135 129
     // then everybody gets going on their own chunk !
136
-    //Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
137
-    //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT,
138
-    //	       supercycle_time, target_sumrule, refine, paralevel, rank, nr_processors);
139
-    Scan_LiebLin (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs, target_sumrule, refine, paralevel, rank, nr_processors);
130
+    Scan_LiebLin (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs,
131
+		  target_sumrule, refine, paralevel, rank, nr_processors);
140 132
 
141 133
     // Another barrier synchronization
142 134
     MPI_Barrier (MPI::COMM_WORLD);

+ 9
- 25
src/EXECS/LiebLin_DSF_GeneralState_par_Wrapup.cc View File

@@ -32,13 +32,15 @@ int main(int argc, char *argv[])
32 32
     cout << endl << "Usage of LiebLin_DSF_par_Wrapup executable: " << endl;
33 33
     cout << endl << "This function wraps up an ABACUS parallel mode run." << endl;
34 34
     cout << endl << "Provide the following arguments:" << endl << endl;
35
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
36
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
36 37
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
37 38
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
38 39
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
39
-    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the AveragingState; used as defaultScanStatename" << endl;
40
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
41
-    //cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
40
+    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the "
41
+      "AveragingState; used as defaultScanStatename" << endl;
42
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
43
+      "recommended values:  -2*N and 2*N" << endl;
42 44
     cout << "int paralevel" << endl;
43 45
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
44 46
     cout << "int nr_processors_at_new_level \t for this latest parallelization level." << endl;
@@ -55,7 +57,6 @@ int main(int argc, char *argv[])
55 57
     Ix2filenameprefix = argv[n++];
56 58
     iKmin = atoi(argv[n++]);
57 59
     iKmax = atoi(argv[n++]);
58
-    //kBT = atof(argv[n++]);
59 60
     paralevel = atoi(argv[n++]); // paralevel == 1 means that we have one layer of parallelization, so no previous rank and nr_processors to specify
60 61
     if (argc != 10 + 2*(paralevel - 1)) ABACUSerror("Wrong nr of arguments in LiebLin_DSF_par_Prepare.");
61 62
 
@@ -73,28 +74,11 @@ int main(int argc, char *argv[])
73 74
     stringstream filenamestrstream;
74 75
     filenamestrstream << Ix2filenameprefix;
75 76
     string defaultScanStatename = filenamestrstream.str();
76
-    /*
77
-    filenamestrstream << ".Ix2";
78
-    string filenamestr = filenamestrstream.str();
79
-    const char* filename_Cstr = filenamestr.c_str();
80
-    Ix2_input_file.open(filename_Cstr);
81
-    if (Ix2_input_file.fail()) {
82
-      cout << filename_Cstr << endl;
83
-      ABACUSerror("Could not open Ix2 input file in LiebLin_DSF_GeneralState");
84
-    }
85
-    for (int i = 0; i < N; ++i) {
86
-      Ix2_input_file >> Ix2_input[i];
87
-      //cout << i << "\t" << Ix2_input[i] << endl;
88
-    }
89
-
90
-    // Define the AveragingState
91
-    LiebLin_Bethe_State AveragingState(c_int, L, N);
92
-    AveragingState.Ix2 = Ix2_input;
93
-    //AveragingState.Compute_All(true);
94
-    */
95 77
 
96 78
     // Digest files into a unique one for the latest paralevel:
97
-    Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
79
+    Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename,
80
+				  paralevel, rank_lower_paralevels, nr_processors_lower_paralevels,
81
+				  nr_processors_at_newlevel);
98 82
 
99 83
   }
100 84
 

+ 4
- 7
src/EXECS/LiebLin_DSF_MosesState.cc View File

@@ -26,15 +26,16 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_MosesState executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
33 34
     cout << "int Nl \t\t\t Number of particles in left Fermi sea (Nr is then N - Nl)" << endl;
34 35
     cout << "int DIl \t\t shift of left  sea as compared to its ground state position" << endl;
35 36
     cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
36
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
37
-    //cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
37
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
38
+      "recommended values:  -2*N and 2*N" << endl;
38 39
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
39 40
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
40 41
     cout << "bool refine \t\t Is this a refinement of earlier calculations ?  (0 == false, 1 == true)" << endl;
@@ -48,12 +49,10 @@ int main(int argc, char* argv[])
48 49
     DP L = atof(argv[3]);
49 50
     int N = atoi(argv[4]);
50 51
     int Nl = atoi(argv[5]);
51
-    //int Nr = N - Nl;
52 52
     int DIl = atoi(argv[6]);
53 53
     int DIr = atoi(argv[7]);
54 54
     int iKmin = atoi(argv[8]);
55 55
     int iKmax = atoi(argv[9]);
56
-    //DP kBT = atof(argv[7]);
57 56
     int Max_Secs = atoi(argv[10]);
58 57
     DP target_sumrule = atof(argv[11]);
59 58
     bool refine = (atoi(argv[12]) == 1);
@@ -67,8 +66,6 @@ int main(int argc, char* argv[])
67 66
 
68 67
     MosesState.Compute_All (true);
69 68
 
70
-    //cout << MosesState << endl;
71
-
72 69
     // Handy default name:
73 70
     stringstream defaultScanStatename_strstream;
74 71
     defaultScanStatename_strstream << "Moses_Nl_" << Nl << "_DIl_" << DIl << "_DIr_" << DIr;

+ 8
- 10
src/EXECS/LiebLin_DSF_MosesState_par.cc View File

@@ -31,16 +31,19 @@ int main(int argc, char *argv[])
31 31
 
32 32
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
33 33
     cout << endl << "Usage of LiebLin_DSF_MosesState_par executable: " << endl;
34
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
34
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
35
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
35 36
     cout << endl << "Provide the following arguments:" << endl << endl;
36
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
38
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37 39
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
38 40
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
39 41
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
40 42
     cout << "int Nl \t\t\t Number of particles in left Fermi sea (Nr is then N - Nl)" << endl;
41 43
     cout << "int DIl \t\t shift of left  sea as compared to its ground state position" << endl;
42 44
     cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
43
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
45
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
46
+      "recommended values:  -2*N and 2*N" << endl;
44 47
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
45 48
     cout << "int supercycle_time \t\t time for one supercycle (in seconds)" << endl;
46 49
     cout << endl << "EXAMPLE: " << endl << endl;
@@ -63,8 +66,6 @@ int main(int argc, char *argv[])
63 66
     supercycle_time = atoi(argv[11]);
64 67
   }
65 68
 
66
-  //DP supercycle_time = 600.0; // allotted time per supercycle
67
-
68 69
   if (Max_Secs <= supercycle_time) ABACUSerror("Please allow more time in LiebLin_DSF_par.");
69 70
 
70 71
   MPI::Init(argc, argv);
@@ -103,7 +104,6 @@ int main(int argc, char *argv[])
103 104
 
104 105
     if (rank == 0)
105 106
       // Split up thread list into chunks, one per processor
106
-      //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
107 107
       Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
108 108
 
109 109
     // Barrier synchronization, to make sure other processes wait for process of rank 0
@@ -111,9 +111,8 @@ int main(int argc, char *argv[])
111 111
     MPI_Barrier (MPI::COMM_WORLD);
112 112
 
113 113
     // then everybody gets going on their own chunk !
114
-    //Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
115
-    //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, supercycle_time, target_sumrule, refine, rank, nr_processors);
116
-    Scan_LiebLin (whichDSF, MosesState, defaultScanStatename, iKmin, iKmax, supercycle_time, target_sumrule, refine, rank, nr_processors);
114
+    Scan_LiebLin (whichDSF, MosesState, defaultScanStatename, iKmin, iKmax, supercycle_time,
115
+		  target_sumrule, refine, rank, nr_processors);
117 116
 
118 117
     // Another barrier synchronization
119 118
     MPI_Barrier (MPI::COMM_WORLD);
@@ -121,7 +120,6 @@ int main(int argc, char *argv[])
121 120
     // Now that everybody is done, digest data into unique files
122 121
 
123 122
     if (rank == 0)
124
-      //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
125 123
       Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
126 124
 
127 125
     // Another barrier synchronization

+ 9
- 4
src/EXECS/LiebLin_DSF_MosesState_par_Prepare.cc View File

@@ -31,16 +31,19 @@ int main(int argc, char *argv[])
31 31
 
32 32
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
33 33
     cout << endl << "Usage of LiebLin_DSF_MosesState_par_Prepare executable: " << endl;
34
-    cout << endl << "This function prepares an ABACUS parallel mode run, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
34
+    cout << endl << "This function prepares an ABACUS parallel mode run, starting from a preexisting "
35
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
35 36
     cout << endl << "Provide the following arguments:" << endl << endl;
36
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
38
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37 39
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
38 40
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
39 41
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
40 42
     cout << "int Nl \t\t\t Number of particles in left Fermi sea (Nr is then N - Nl)" << endl;
41 43
     cout << "int DIl \t\t shift of left  sea as compared to its ground state position" << endl;
42 44
     cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
43
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
45
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
46
+      "recommended values:  -2*N and 2*N" << endl;
44 47
     cout << "int paralevel" << endl;
45 48
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
46 49
     cout << "int nr_processors_at_new_level \t for this new parallelization level." << endl;
@@ -86,7 +89,9 @@ int main(int argc, char *argv[])
86 89
 
87 90
 
88 91
     // Split up thread list into chunks, one per processor
89
-    Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
92
+    Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename,
93
+				   paralevel, rank_lower_paralevels, nr_processors_lower_paralevels,
94
+				   nr_processors_at_newlevel);
90 95
 
91 96
   }
92 97
 

+ 8
- 27
src/EXECS/LiebLin_DSF_MosesState_par_Run.cc View File

@@ -31,16 +31,19 @@ int main(int argc, char *argv[])
31 31
 
32 32
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
33 33
     cout << endl << "Usage of LiebLin_DSF_MosesState_par_Run executable: " << endl;
34
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
34
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
35
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
35 36
     cout << endl << "Provide the following arguments:" << endl << endl;
36
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
38
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37 39
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
38 40
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
39 41
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
40 42
     cout << "int Nl \t\t\t Number of particles in left Fermi sea (Nr is then N - Nl)" << endl;
41 43
     cout << "int DIl \t\t shift of left  sea as compared to its ground state position" << endl;
42 44
     cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
43
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
45
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
46
+      "recommended values:  -2*N and 2*N" << endl;
44 47
     cout << "int paralevel" << endl;
45 48
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
46 49
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
@@ -70,9 +73,6 @@ int main(int argc, char *argv[])
70 73
   }
71 74
   Max_Secs = atoi(argv[n++]);
72 75
   supercycle_time = atoi(argv[n++]);
73
-  //}
74
-
75
-  //DP supercycle_time = 600.0; // allotted time per supercycle
76 76
 
77 77
   if (Max_Secs <= supercycle_time) ABACUSerror("Please allow more time in LiebLin_DSF_par_Run.");
78 78
 
@@ -83,8 +83,6 @@ int main(int argc, char *argv[])
83 83
   int rank_here = MPI::COMM_WORLD.Get_rank();
84 84
   int nr_processors_here = MPI::COMM_WORLD.Get_size();
85 85
 
86
-  //cout << "rank " << rank_here << " out of " << nr_processors_here << " ready to go." << endl;
87
-
88 86
   Vect<int> rank (paralevel);
89 87
   Vect<int> nr_processors (paralevel);
90 88
   for (int i = 0; i < paralevel - 1; ++i) {
@@ -117,35 +115,18 @@ int main(int argc, char *argv[])
117 115
   defaultScanStatename_strstream << "Moses_Nl_" << Nl << "_DIl_" << DIl << "_DIr_" << DIr;
118 116
   string defaultScanStatename = defaultScanStatename_strstream.str();
119 117
 
120
-  //cout << "rank " << rank_here << " out of " << nr_processors_here << " waiting at barrier." << endl;
121
-
122 118
   MPI_Barrier (MPI::COMM_WORLD);
123 119
 
124 120
 
125 121
   while (tnow - tstart < Max_Secs - supercycle_time - 120) { // space for one more supercycle, + 2 minutes safety
126 122
 
127
-    //if (rank == 0)
128
-      // Split up thread list into chunks, one per processor
129
-      //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
130
-      //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
131
-
132 123
     // Barrier synchronization, to make sure other processes wait for process of rank 0
133 124
     // to have finished splitting up the thr file into pieces before starting:
134 125
     MPI_Barrier (MPI::COMM_WORLD);
135 126
 
136 127
     // then everybody gets going on their own chunk !
137
-    //Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
138
-    //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, supercycle_time, target_sumrule, refine, paralevel, rank, nr_processors);
139
-    Scan_LiebLin (whichDSF, MosesState, defaultScanStatename, iKmin, iKmax, supercycle_time, target_sumrule, refine, paralevel, rank, nr_processors);
140
-
141
-    // Another barrier synchronization
142
-    MPI_Barrier (MPI::COMM_WORLD);
143
-
144
-    // Now that everybody is done, digest data into unique files
145
-
146
-    //if (rank == 0)
147
-      //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
148
-      //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
128
+    Scan_LiebLin (whichDSF, MosesState, defaultScanStatename, iKmin, iKmax, supercycle_time,
129
+		  target_sumrule, refine, paralevel, rank, nr_processors);
149 130
 
150 131
     // Another barrier synchronization
151 132
     MPI_Barrier (MPI::COMM_WORLD);

+ 7
- 3
src/EXECS/LiebLin_DSF_MosesState_par_Wrapup.cc View File

@@ -33,14 +33,16 @@ int main(int argc, char *argv[])
33 33
     cout << endl << "Usage of LiebLin_DSF_MosesState_par_Wrapup executable: " << endl;
34 34
     cout << endl << "This function wraps up an ABACUS parallel mode run." << endl;
35 35
     cout << endl << "Provide the following arguments:" << endl << endl;
36
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
36
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
37
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
37 38
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
38 39
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
39 40
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
40 41
     cout << "int Nl \t\t\t Number of particles in left Fermi sea (Nr is then N - Nl)" << endl;
41 42
     cout << "int DIl \t\t shift of left  sea as compared to its ground state position" << endl;
42 43
     cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
43
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
44
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
45
+      "recommended values:  -2*N and 2*N" << endl;
44 46
     cout << "int paralevel" << endl;
45 47
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
46 48
     cout << "int nr_processors_at_new_level \t for this new parallelization level." << endl;
@@ -86,7 +88,9 @@ int main(int argc, char *argv[])
86 88
 
87 89
 
88 90
     // Digest files into a unique one for the latest paralevel:
89
-    Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
91
+    Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename,
92
+				  paralevel, rank_lower_paralevels, nr_processors_lower_paralevels,
93
+				  nr_processors_at_newlevel);
90 94
 
91 95
   }
92 96
 

+ 6
- 11
src/EXECS/LiebLin_DSF_over_Ensemble.cc View File

@@ -26,15 +26,15 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_Tgt0 executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
33
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
34
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
35
+      "recommended values:  -2*N and 2*N" << endl;
34 36
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
35
-    //cout << "int nstates \t\t\t Number of states to be considered in the ensemble" << endl;
36 37
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
37
-    //cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
38 38
     cout << "bool refine \t\t Is this a refinement of earlier calculations ?  (0 == false, 1 == true)" << endl;
39 39
     cout << endl << "EXAMPLE: " << endl << endl;
40 40
     cout << "LiebLin_DSF_over_Ensemble d 1.0 100.0 100 0 200 0.56 10 600 0" << endl << endl;
@@ -48,7 +48,6 @@ int main(int argc, char* argv[])
48 48
     int iKmin = atoi(argv[5]);
49 49
     int iKmax = atoi(argv[6]);
50 50
     DP kBT = atof(argv[7]);
51
-    //int nstates_req = atoi(argv[8]);
52 51
     int Max_Secs = atoi(argv[8]);
53 52
     bool refine = (atoi(argv[9]) == 1);
54 53
 
@@ -57,13 +56,11 @@ int main(int argc, char* argv[])
57 56
     LiebLin_Diagonal_State_Ensemble ensemble;
58 57
 
59 58
     stringstream ensfilestrstream;
60
-    //ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << "_ns_" << nstates_req << ".ens";
61 59
     ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << ".ens";
62 60
     string ensfilestr = ensfilestrstream.str();
63 61
     const char* ensfile_Cstr = ensfilestr.c_str();
64 62
 
65 63
     if (!refine) { // Construct the state ensemble
66
-      //ensemble = LiebLin_Thermal_Saddle_Point_Ensemble (c_int, L, N, kBT, nstates_req);
67 64
       ensemble = LiebLin_Thermal_Saddle_Point_Ensemble (c_int, L, N, kBT);
68 65
       ensemble.Save(ensfile_Cstr); // Save the ensemble
69 66
     }
@@ -75,10 +72,8 @@ int main(int argc, char* argv[])
75 72
     // Now perform the DSF calculation over each state in the ensemble, distributing the time according to the weight
76 73
 
77 74
     for (int ns = 0; ns < ensemble.nstates; ++ns) {
78
-      //void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultScanStatename, int iKmin, int iKmax,
79
-      //int Max_Secs, DP target_sumrule, bool refine, int rank, int nr_processors)
80
-      //Scan_LiebLin (whichDSF, ensemble.state[ns], ensemble.state[ns].label, iKmin, iKmax, int(Max_Secs * ensemble.weight[ns]), 1.0e+6, refine, 0, 1);
81
-      Scan_LiebLin (whichDSF, ensemble.state[ns], ensemble.state[ns].label, iKmin, iKmax, int(Max_Secs * ensemble.weight[ns]), 1.0e+6, refine);
75
+      Scan_LiebLin (whichDSF, ensemble.state[ns], ensemble.state[ns].label, iKmin, iKmax,
76
+		    int(Max_Secs * ensemble.weight[ns]), 1.0e+6, refine);
82 77
     }
83 78
 
84 79
     // Evaluate the f-sumrule

+ 4
- 36
src/EXECS/LiebLin_DSF_over_Ensemble_par.cc View File

@@ -27,15 +27,15 @@ int main(int argc, char* argv[])
27 27
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
28 28
     cout << endl << "Usage of LiebLin_DSF_Tgt0 executable: " << endl;
29 29
     cout << endl << "Provide the following arguments:" << endl << endl;
30
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
31
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
31 32
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
32 33
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
33 34
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
34
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
35
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
36
+      "recommended values:  -2*N and 2*N" << endl;
35 37
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
36
-    //cout << "int nstates \t\t\t Number of states to be considered in the ensemble" << endl;
37 38
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
38
-    //cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
39 39
     cout << "bool refine \t\t Is this a refinement of earlier calculations ?  (0 == false, 1 == true)" << endl;
40 40
     cout << endl << "EXAMPLE: " << endl << endl;
41 41
     cout << "LiebLin_DSF_over_Ensemble d 1.0 100.0 100 0 200 0.56 10 600 0" << endl << endl;
@@ -49,7 +49,6 @@ int main(int argc, char* argv[])
49 49
     int iKmin = atoi(argv[5]);
50 50
     int iKmax = atoi(argv[6]);
51 51
     DP kBT = atof(argv[7]);
52
-    //int nstates_req = atoi(argv[8]);
53 52
     int Max_Secs = atoi(argv[8]);
54 53
     bool refine = (atoi(argv[9]) == 1);
55 54
 
@@ -70,13 +69,11 @@ int main(int argc, char* argv[])
70 69
     LiebLin_Diagonal_State_Ensemble ensemble;
71 70
 
72 71
     stringstream ensfilestrstream;
73
-    //ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << "_ns_" << nstates_req << ".ens";
74 72
     ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << ".ens";
75 73
     string ensfilestr = ensfilestrstream.str();
76 74
     const char* ensfile_Cstr = ensfilestr.c_str();
77 75
 
78 76
     if (!refine) { // Construct the state ensemble
79
-      //ensemble = LiebLin_Thermal_Saddle_Point_Ensemble (c_int, L, N, kBT, nstates_req);
80 77
       ensemble = LiebLin_Thermal_Saddle_Point_Ensemble (c_int, L, N, kBT);
81 78
       ensemble.Save(ensfile_Cstr); // Save the ensemble
82 79
     }
@@ -89,30 +86,6 @@ int main(int argc, char* argv[])
89 86
 
90 87
     // Now perform the DSF calculation over each state in the ensemble
91 88
 
92
-    /* Original implementation: Scan always called serially. Superseded by version below, using successive parallel scans on each state in the ensemble.
93
-    int nDSFperproc = ensemble.nstates/nr_processors + 1;
94
-    //if (ensemble.nstates % nr_processors) ABACUSerror("Use nr_processors * integer multiple == ensemble.nstates in LiebLin_DSF_over_Ensemble_par.");
95
-
96
-    // Processor with rank r does all
97
-
98
-    int ns;
99
-    int Max_Secs_used = Max_Secs/nDSFperproc;
100
-
101
-    for (int ir = 0; ir < nDSFperproc; ++ir) {
102
-      ns = rank + ir * nr_processors;
103
-      //void Scan_LiebLin (char whichDSF, LiebLin_Bethe_State AveragingState, string defaultScanStatename, int iKmin, int iKmax,
104
-      //int Max_Secs, DP target_sumrule, bool refine, int rank, int nr_processors)
105
-      if (ns < ensemble.nstates) {
106
-	//cout << "Processor rank " << rank << " going for ns = " << ns << " out of " << ensemble.nstates << endl;
107
-	Scan_LiebLin (whichDSF, ensemble.state[ns], ensemble.state[ns].label, iKmin, iKmax, Max_Secs_used, 1.0e+6, refine, 0, 1);
108
-      }
109
-    }
110
-    */
111
-
112
-    // Version 2013 04 24:
113
-    // Makes use of a parallel scan for each state in the ensemble, in succession.
114
-    // Code is simple adaptation of LiebLin_DSF_par executable code.
115
-
116 89
     int Max_Secs_used = Max_Secs/ensemble.nstates;
117 90
 
118 91
     DP supercycle_time = 600.0; // allotted time per supercycle
@@ -131,7 +104,6 @@ int main(int argc, char* argv[])
131 104
 
132 105
 	if (rank == 0)
133 106
 	  // Split up thread list into chunks, one per processor
134
-	  //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
135 107
 	  Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
136 108
 
137 109
 	// Barrier synchronization, to make sure other processes wait for process of rank 0
@@ -139,9 +111,6 @@ int main(int argc, char* argv[])
139 111
 	MPI_Barrier (MPI::COMM_WORLD);
140 112
 
141 113
 	// then everybody gets going on their own chunk !
142
-	//Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
143
-	//Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT,
144
-	//supercycle_time, target_sumrule, refine, rank, nr_processors);
145 114
 	Scan_LiebLin (whichDSF, ensemble.state[ns], ensemble.state[ns].label, iKmin, iKmax, supercycle_time, 1.0e+6, refine, rank, nr_processors);
146 115
 
147 116
 	// Another barrier synchronization
@@ -150,7 +119,6 @@ int main(int argc, char* argv[])
150 119
 	// Now that everybody is done, digest data into unique files
151 120
 
152 121
 	if (rank == 0)
153
-	  //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
154 122
 	  Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
155 123
 
156 124
 	// Another barrier synchronization

+ 7
- 9
src/EXECS/LiebLin_DSF_par.cc View File

@@ -29,13 +29,16 @@ int main(int argc, char *argv[])
29 29
 
30 30
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
31 31
     cout << endl << "Usage of LiebLin_DSF_par executable: " << endl;
32
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
32
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
33
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
33 34
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
36
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35 37
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
36 38
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
37 39
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
40
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
41
+      "recommended values:  -2*N and 2*N" << endl;
39 42
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
40 43
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
41 44
     cout << "int supercycle_time \t\t time for one supercycle (in seconds)" << endl;
@@ -57,8 +60,6 @@ int main(int argc, char *argv[])
57 60
     supercycle_time = atoi(argv[9]);
58 61
   }
59 62
 
60
-  //DP supercycle_time = 600.0; // allotted time per supercycle
61
-
62 63
   if (Max_Secs <= supercycle_time) ABACUSerror("Please allow more time in LiebLin_DSF_par.");
63 64
 
64 65
   MPI::Init(argc, argv);
@@ -83,7 +84,6 @@ int main(int argc, char *argv[])
83 84
 
84 85
     if (rank == 0)
85 86
       // Split up thread list into chunks, one per processor
86
-      //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
87 87
       Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
88 88
 
89 89
     // Barrier synchronization, to make sure other processes wait for process of rank 0
@@ -91,9 +91,8 @@ int main(int argc, char *argv[])
91 91
     MPI_Barrier (MPI::COMM_WORLD);
92 92
 
93 93
     // then everybody gets going on their own chunk !
94
-    //Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
95 94
     Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT,
96
-	       supercycle_time, target_sumrule, refine, rank, nr_processors);
95
+		  supercycle_time, target_sumrule, refine, rank, nr_processors);
97 96
 
98 97
     // Another barrier synchronization
99 98
     MPI_Barrier (MPI::COMM_WORLD);
@@ -101,7 +100,6 @@ int main(int argc, char *argv[])
101 100
     // Now that everybody is done, digest data into unique files
102 101
 
103 102
     if (rank == 0)
104
-      //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
105 103
       Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
106 104
 
107 105
     // Another barrier synchronization

+ 9
- 4
src/EXECS/LiebLin_DSF_par_Prepare.cc View File

@@ -29,13 +29,16 @@ int main(int argc, char *argv[])
29 29
 
30 30
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
31 31
     cout << endl << "Usage of LiebLin_DSF_par_Prepare executable: " << endl;
32
-    cout << endl << "This function prepares an ABACUS parallel mode run, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
32
+    cout << endl << "This function prepares an ABACUS parallel mode run, starting from a preexisting "
33
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
33 34
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
36
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35 37
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
36 38
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
37 39
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
40
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
41
+      "recommended values:  -2*N and 2*N" << endl;
39 42
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
40 43
     cout << "int paralevel" << endl;
41 44
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
@@ -67,7 +70,9 @@ int main(int argc, char *argv[])
67 70
     string defaultScanStatename = "";
68 71
 
69 72
     // Split up thread list into chunks, one per processor
70
-    Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
73
+    Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename,
74
+				   paralevel, rank_lower_paralevels, nr_processors_lower_paralevels,
75
+				   nr_processors_at_newlevel);
71 76
 
72 77
   }
73 78
 

+ 6
- 4
src/EXECS/LiebLin_DSF_par_Run.cc View File

@@ -29,13 +29,16 @@ int main(int argc, char *argv[])
29 29
 
30 30
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
31 31
     cout << endl << "Usage of LiebLin_DSF_par_Run executable: " << endl;
32
-    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
32
+    cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
33
+      "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
33 34
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
36
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35 37
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
36 38
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
37 39
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
40
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
41
+      "recommended values:  -2*N and 2*N" << endl;
39 42
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
40 43
     cout << "int paralevel" << endl;
41 44
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
@@ -101,7 +104,6 @@ int main(int argc, char *argv[])
101 104
     MPI_Barrier (MPI::COMM_WORLD);
102 105
 
103 106
     // then everybody gets going on their own chunk !
104
-    //Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
105 107
     Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT,
106 108
 		  Max_Secs_used, target_sumrule, refine, paralevel, rank, nr_processors);
107 109
 

+ 7
- 3
src/EXECS/LiebLin_DSF_par_Wrapup.cc View File

@@ -31,11 +31,13 @@ int main(int argc, char *argv[])
31 31
     cout << endl << "Usage of LiebLin_DSF_par_Wrapup executable: " << endl;
32 32
     cout << endl << "This function wraps up an ABACUS parallel mode run." << endl;
33 33
     cout << endl << "Provide the following arguments:" << endl << endl;
34
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
34
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
35
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
35 36
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
36 37
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
37 38
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
38
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
39
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
40
+      "recommended values:  -2*N and 2*N" << endl;
39 41
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
40 42
     cout << "int paralevel" << endl;
41 43
     cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
@@ -67,7 +69,9 @@ int main(int argc, char *argv[])
67 69
     string defaultScanStatename = "";
68 70
 
69 71
     // Digest files into a unique one for the latest paralevel:
70
-    Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, paralevel, rank_lower_paralevels, nr_processors_lower_paralevels, nr_processors_at_newlevel);
72
+    Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename,
73
+				  paralevel, rank_lower_paralevels, nr_processors_lower_paralevels,
74
+				  nr_processors_at_newlevel);
71 75
 
72 76
   }
73 77
 

+ 8
- 10
src/EXECS/LiebLin_DSF_tester.cc View File

@@ -26,7 +26,8 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_tester executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
@@ -42,13 +43,7 @@ int main(int argc, char* argv[])
42 43
     int N = atoi(argv[4]);
43 44
     DP kBT = atof(argv[5]);
44 45
 
45
-    //if (whichDSF != 'd') ABACUSerror("Other options not implemented yet in finite T Scan_LiebLin");
46
-
47
-    // Delta is the number of sites involved in the smoothing of the entropy
48
-    //int Delta = int(sqrt(N))/2;//6;//N/20;
49
-
50 46
     // Construct the finite-size saddle-point state:
51
-    //LiebLin_Bethe_State spstate = Canonical_Saddle_Point_State (c_int, L, N, kBT, Delta);
52 47
     LiebLin_Bethe_State spstate = Canonical_Saddle_Point_State (c_int, L, N, kBT);
53 48
     spstate.Compute_All(true);
54 49
 
@@ -74,11 +69,14 @@ int main(int argc, char* argv[])
74 69
       cout << spstate << endl;
75 70
       cout << estate;
76 71
       if (whichDSF == 'd')
77
-	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E << "\tME = " << real(exp(ln_Density_ME(spstate, estate))) << endl;
72
+	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E
73
+	     << "\tME = " << real(exp(ln_Density_ME(spstate, estate))) << endl;
78 74
       else if (whichDSF == 'o')
79
-	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E << "\tME = " << real(exp(ln_Psi_ME(estate, spstate))) << endl;
75
+	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E
76
+	     << "\tME = " << real(exp(ln_Psi_ME(estate, spstate))) << endl;
80 77
       else if (whichDSF == 'g')
81
-	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E << "\tME = " << real(exp(ln_Psi_ME(spstate, estate))) << endl;
78
+	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E
79
+	     << "\tME = " << real(exp(ln_Psi_ME(spstate, estate))) << endl;
82 80
 
83 81
       //cout << "Another try ? (1 == yes, 0 == no)" << endl;
84 82
       again = 1;

+ 8
- 10
src/EXECS/LiebLin_DSF_tester_Ix2.cc View File

@@ -26,7 +26,8 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_tester executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
@@ -42,13 +43,7 @@ int main(int argc, char* argv[])
42 43
     int N = atoi(argv[4]);
43 44
     DP kBT = atof(argv[5]);
44 45
 
45
-    //if (whichDSF != 'd') ABACUSerror("Other options not implemented yet in finite T Scan_LiebLin");
46
-
47
-    // Delta is the number of sites involved in the smoothing of the entropy
48
-    //int Delta = int(sqrt(N))/2;//6;//N/20;
49
-
50 46
     // Construct the finite-size saddle-point state:
51
-    //LiebLin_Bethe_State spstate = Canonical_Saddle_Point_State (c_int, L, N, kBT, Delta);
52 47
     LiebLin_Bethe_State spstate = Canonical_Saddle_Point_State (c_int, L, N, kBT);
53 48
     spstate.Compute_All(true);
54 49
 
@@ -74,11 +69,14 @@ int main(int argc, char* argv[])
74 69
       cout << spstate << endl;
75 70
       cout << estate;
76 71
       if (whichDSF == 'd')
77
-	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E << "\tME = " << real(exp(ln_Density_ME(spstate, estate))) << endl;
72
+	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E
73
+	     << "\tME = " << real(exp(ln_Density_ME(spstate, estate))) << endl;
78 74
       else if (whichDSF == 'o')
79
-	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E << "\tME = " << real(exp(ln_Psi_ME(estate, spstate))) << endl;
75
+	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E
76
+	     << "\tME = " << real(exp(ln_Psi_ME(estate, spstate))) << endl;
80 77
       else if (whichDSF == 'g')
81
-	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E << "\tME = " << real(exp(ln_Psi_ME(spstate, estate))) << endl;
78
+	cout << setprecision(16) << "estate.E - spstate.E = " << estate.E - spstate.E
79
+	     << "\tME = " << real(exp(ln_Psi_ME(spstate, estate))) << endl;
82 80
 
83 81
       cout << "Another try ? (1 == yes, 0 == no)" << endl;
84 82
       again = 1;

+ 6
- 9
src/EXECS/LiebLin_Data_Daemon.cc View File

@@ -27,13 +27,15 @@ int main(int argc, char* argv[])
27 27
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
28 28
     cout << endl << "Usage of LiebLin_Data_Daemon executable: " << endl;
29 29
     cout << endl << "Provide the following arguments:" << endl << endl;
30
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
31
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
31 32
     cout << "DP c_int_max \t\t Largest value of the interaction parameter:  use positive real values only" << endl;
32 33
     cout << "int Nc \t\t number of steps in interaction value" << endl;
33 34
     cout << "int cfact \t\t dividing factor (each new interaction value if 1/cfact times the previous)" << endl;
34 35
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
35 36
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
36
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
37
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
38
+      "recommended values:  -2*N and 2*N" << endl;
37 39
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
38 40
     cout << "int Max_Hrs \t\t Allowed computational time:  (in hours)" << endl;
39 41
   }
@@ -52,21 +54,17 @@ int main(int argc, char* argv[])
52 54
     int Max_Hrs = atoi(argv[ia++]);
53 55
 
54 56
     // Individual computations are split into chuncks of Max_Hrs/(Nc * 4)
55
-    //int Max_Secs = (Max_Hrs * 900)/Nc;
56 57
     int Max_Secs = (Max_Hrs * 2700)/Nc; // to minimize wrapping up & restarting time
57 58
 
58 59
     cout << "Data daemon will use chunks of " << Max_Secs << " seconds." << endl;
59 60
 
60
-    //clock_t StartTime = clock();
61 61
     double StartTime = omp_get_wtime();
62 62
 
63
-    //clock_t ActualTime = StartTime;
64 63
     double ActualTime = omp_get_wtime();
65 64
 
66 65
     DP c_int;
67 66
     DP target_sumrule = 1.0;
68 67
 
69
-    //while (double(ActualTime - StartTime)/CLOCKS_PER_SEC < double(3600 * Max_Hrs - Max_Secs)) {
70 68
     while (ActualTime - StartTime < double(3600 * Max_Hrs - Max_Secs)) {
71 69
 
72 70
       Vect<DP> srsat(0.0, Nc);
@@ -101,13 +99,12 @@ int main(int argc, char* argv[])
101 99
       } // for ic
102 100
 
103 101
       cout << "srsat min found: " << srmin << "\t for c = " << c_int_max/pow(cfact, icmin) << ". Now refining this."
104
-	//<< " Time left: " << 3600* Max_Hrs - (ActualTime - StartTime)/CLOCKS_PER_SEC << " seconds." << endl;
105 102
 	   << " Time left: " << 3600* Max_Hrs - (ActualTime - StartTime) << " seconds." << endl;
106 103
 
107 104
       // Improve the icmin calculation by one chunk:
108
-      Scan_LiebLin (whichDSF, c_int_max/pow(cfact, icmin), L, N, iKmin, iKmax, kBT, Max_Secs, target_sumrule, refine[icmin]);
105
+      Scan_LiebLin (whichDSF, c_int_max/pow(cfact, icmin), L, N, iKmin, iKmax, kBT, Max_Secs,
106
+		    target_sumrule, refine[icmin]);
109 107
 
110
-      //ActualTime = clock();
111 108
       ActualTime = omp_get_wtime();
112 109
 
113 110
     } // while there is time

+ 6
- 8
src/EXECS/LiebLin_Data_Daemon_Nscaling.cc View File

@@ -27,11 +27,13 @@ int main(int argc, char* argv[])
27 27
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
28 28
     cout << endl << "Usage of LiebLin_Data_Daemon_Nscaling executable: " << endl;
29 29
     cout << endl << "Provide the following arguments:" << endl << endl;
30
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
31
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
31 32
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
32
-    //cout << "int Nc \t\t number of steps in interaction value" << endl;
33
-    cout << "int Nstep \t\t\t Steps to be taken in number of particles:  use positive integer values only. Filling will be set to 1 (L == N)" << endl;
34
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over (in units of N == Nstep):  recommended values:  0 and 2*N" << endl;
33
+    cout << "int Nstep \t\t\t Steps to be taken in number of particles:  use positive integer "
34
+      "values only. Filling will be set to 1 (L == N)" << endl;
35
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over "
36
+      "(in units of N == Nstep):  recommended values:  0 and 2*N" << endl;
35 37
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
36 38
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
37 39
     cout << "int Max_minutes \t\t Allowed computational time:  (in minutes)" << endl;
@@ -48,11 +50,8 @@ int main(int argc, char* argv[])
48 50
     DP target_sumrule = atof(argv[ia++]);
49 51
     int Max_minutes = atoi(argv[ia++]);
50 52
 
51
-
52
-    //clock_t StartTime = clock();
53 53
     double StartTime = omp_get_wtime();
54 54
 
55
-    //clock_t ActualTime = StartTime;
56 55
     double ActualTime = omp_get_wtime();
57 56
 
58 57
     int Secs_left = 60* Max_minutes;
@@ -91,7 +90,6 @@ int main(int argc, char* argv[])
91 90
 
92 91
       ActualTime = clock();
93 92
 
94
-      //Secs_left = int(60*Max_minutes - double(ActualTime - StartTime)/CLOCKS_PER_SEC);
95 93
       Secs_left = int(60*Max_minutes - (ActualTime - StartTime));
96 94
 
97 95
       cout << "Done with N = " << N << ". Time left = " << Secs_left << " seconds." << endl;

+ 2
- 4
src/EXECS/LiebLin_Fourier_ssf_to_Qsqx.cc View File

@@ -25,7 +25,8 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of LiebLin_Fourier_to_Qsqx executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
@@ -43,8 +44,6 @@ int main(int argc, char* argv[])
43 44
     int iKmax = atoi(argv[6]);
44 45
     DP kBT = atof(argv[7]);
45 46
     int Npts_x = atoi(argv[8]);
46
-    // Force Npts_x
47
-    //Npts_x = L;
48 47
 
49 48
     if (whichDSF != 'd') ABACUSerror("Must use whichDSF == d in LiebLin_Fourier_ssf_to_Qsqx");
50 49
 
@@ -137,7 +136,6 @@ int main(int argc, char* argv[])
137 136
     // Output to file:
138 137
     for (int ix = 0; ix < Npts_x; ++ix) {
139 138
       if (ix > 0) SFT_outfile << endl;
140
-      //SFT_outfile << xlattice[ix] << "\t" << FTre[ix] << "\t" << FTim[ix] << "\t" << FTreavg[ix] << "\t" << FTimavg[ix];
141 139
       SFT_outfile << xlattice[ix]/L << "\t" << FT[ix];
142 140
     }
143 141
 

+ 2
- 1
src/EXECS/LiebLin_Fourier_to_t_equal_x.cc View File

@@ -25,7 +25,8 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of LiebLin_Fourier_to_x_equal_t executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;

+ 2
- 6
src/EXECS/LiebLin_Fourier_to_t_equal_x_from_RAW.cc View File

@@ -25,12 +25,12 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of LiebLin_Fourier_to_x_equal_t executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
32 33
     cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers scanned over" << endl;
33
-    //cout << "DP kBT \t\t Temperature" << endl;
34 34
     cout << "RAW file name" << endl;
35 35
     cout << "int Npts_t \t Number of points in time for the Fourier transform" << endl;
36 36
     cout << "DP t_max \t Max time to be used" << endl;
@@ -43,7 +43,6 @@ int main(int argc, char* argv[])
43 43
     int N = atoi(argv[4]);
44 44
     int iKmin = atoi(argv[5]);
45 45
     int iKmax = atoi(argv[6]);
46
-    //DP kBT = atof(argv[7]);
47 46
     char* rawfilename = argv[7];
48 47
     int Npts_t = atoi(argv[8]);
49 48
     DP t_max = atof(argv[9]);
@@ -52,10 +51,8 @@ int main(int argc, char* argv[])
52 51
     if (iKmin != 0) ABACUSerror("LiebLin_Fourier_to_t_equal_x only implemented for raw files with iKmin == 0.");
53 52
 
54 53
     ifstream RAW_infile;
55
-    //RAW_infile.open(RAW_Cstr);
56 54
     RAW_infile.open(rawfilename);
57 55
     if (RAW_infile.fail()) {
58
-      //cout << RAW_Cstr << endl;
59 56
       cout << rawfilename << endl;
60 57
       ABACUSerror("Could not open RAW_infile... ");
61 58
     }
@@ -74,7 +71,6 @@ int main(int argc, char* argv[])
74 71
     DP omega;
75 72
     int iK;
76 73
     DP FF;
77
-    //int conv;
78 74
     DP dev;
79 75
     string label;
80 76
 

+ 4
- 5
src/EXECS/LiebLin_Fourier_to_x_equal_t.cc View File

@@ -25,7 +25,8 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of LiebLin_Fourier_to_x_equal_t executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
@@ -43,8 +44,6 @@ int main(int argc, char* argv[])
43 44
     int iKmax = atoi(argv[6]);
44 45
     DP kBT = atof(argv[7]);
45 46
     int Npts_x = atoi(argv[8]);
46
-    // Force Npts_x
47
-    //Npts_x = L;
48 47
 
49 48
     stringstream filenameprefix;
50 49
     Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
@@ -85,7 +84,6 @@ int main(int argc, char* argv[])
85 84
     DP omega;
86 85
     int iK;
87 86
     DP FF;
88
-    //int conv;
89 87
     DP dev;
90 88
     string label;
91 89
 
@@ -174,7 +172,8 @@ int main(int argc, char* argv[])
174 172
       FTimavg[ix] /= (2*deltaix + 1);
175 173
     }
176 174
     */
177
-    if (whichDSF == 'd') cout << "g2(0) = dE0_dc/L = " << LiebLin_dE0_dc (c_int, L, N)/L << "\t" << LiebLin_dE0_dc (c_int, 2.0*L, 2*N)/(2.0*L) << endl;
175
+    if (whichDSF == 'd') cout << "g2(0) = dE0_dc/L = " << LiebLin_dE0_dc (c_int, L, N)/L
176
+			      << "\t" << LiebLin_dE0_dc (c_int, 2.0*L, 2*N)/(2.0*L) << endl;
178 177
 
179 178
     // Output to file:
180 179
     for (int ix = 0; ix < Npts_x; ++ix) {

+ 2
- 16
src/EXECS/LiebLin_Fourier_to_x_equal_t_from_RAW.cc View File

@@ -25,12 +25,12 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of LiebLin_Fourier_to_x_equal_t executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
32 33
     cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers scanned over" << endl;
33
-    //cout << "DP kBT \t\t Temperature" << endl;
34 34
     cout << "RAW file name" << endl;
35 35
     cout << "int Npts_x Number of points in space for the Fourier transform" << endl;
36 36
   }
@@ -42,24 +42,12 @@ int main(int argc, char* argv[])
42 42
     int N = atoi(argv[4]);
43 43
     int iKmin = atoi(argv[5]);
44 44
     int iKmax = atoi(argv[6]);
45
-    //DP kBT = atof(argv[7]);
46 45
     char* rawfilename = argv[7];
47 46
     int Npts_x = atoi(argv[8]);
48
-    // Force Npts_x
49
-    //Npts_x = L;
50 47
 
51
-    //stringstream filenameprefix;
52
-    //Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
53
-    //string prefix = filenameprefix.str();
54
-
55
-    //stringstream RAW_stringstream;    string RAW_string;
56
-    //RAW_stringstream << prefix << ".raw";
57
-    //RAW_string = RAW_stringstream.str();    const char* RAW_Cstr = RAW_string.c_str();
58 48
     ifstream RAW_infile;
59
-    //RAW_infile.open(RAW_Cstr);
60 49
     RAW_infile.open(rawfilename);
61 50
     if (RAW_infile.fail()) {
62
-      //cout << RAW_Cstr << endl;
63 51
       cout << rawfilename << endl;
64 52
       ABACUSerror("Could not open RAW_infile... ");
65 53
     }
@@ -80,7 +68,6 @@ int main(int argc, char* argv[])
80 68
     DP omega;
81 69
     int iK;
82 70
     DP FF;
83
-    //int conv;
84 71
     DP dev;
85 72
     string label;
86 73
 
@@ -135,7 +122,6 @@ int main(int argc, char* argv[])
135 122
     // Output to file:
136 123
     for (int ix = 0; ix < Npts_x; ++ix) {
137 124
       if (ix > 0) SFT_outfile << endl;
138
-      //SFT_outfile << xlattice[ix] << "\t" << FTre[ix] << "\t" << FTim[ix] << "\t" << FTreavg[ix] << "\t" << FTimavg[ix];
139 125
       SFT_outfile << xlattice[ix] << "\t" << FTre[ix] << "\t" << FTim[ix];
140 126
     }
141 127
 

+ 4
- 3
src/EXECS/LiebLin_Moses_tester.cc View File

@@ -26,7 +26,8 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << endl << "Usage of LiebLin_DSF_tester executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30 31
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
31 32
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
32 33
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
@@ -41,7 +42,6 @@ int main(int argc, char* argv[])
41 42
     DP L = atof(argv[3]);
42 43
     int N = atoi(argv[4]);
43 44
     int Nl = atoi(argv[5]);
44
-    //int Nr = N - Nl;
45 45
     int DIl = atoi(argv[6]);
46 46
     int DIr = atoi(argv[7]);
47 47
 
@@ -67,7 +67,8 @@ int main(int argc, char* argv[])
67 67
       for (int i = 0; i < estate.N; ++i) if (estate.Ix2[i] == Ix2old) estate.Ix2[i] = Ix2new;
68 68
       estate.Compute_All(false);
69 69
       cout << estate;
70
-      cout << setprecision(16) << "omega = " << estate.E - MosesState.E << "\t" << exp(real(ln_Density_ME(MosesState, estate))) << endl;
70
+      cout << setprecision(16) << "omega = " << estate.E - MosesState.E << "\t"
71
+	   << exp(real(ln_Density_ME(MosesState, estate))) << endl;
71 72
       cout << "Another try ? (0 == no)" << endl;
72 73
       cin >> again;
73 74
     } while (again != 0);

+ 6
- 4
src/EXECS/LiebLin_RAW_File_Stats.cc View File

@@ -27,11 +27,13 @@ int main(int argc, char* argv[])
27 27
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
28 28
     cout << endl << "Usage of LiebLin_RAW_File_Stats executable: " << endl;
29 29
     cout << endl << "Provide the following arguments:" << endl << endl;
30
-    cout << "char whichDSF \t\t Which structure factor?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
30
+    cout << "char whichDSF \t\t Which structure factor?  Options are:  "
31
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
31 32
     cout << "DP c_int \t\t Value of the interaction parameter:  use positive real values only" << endl;
32 33
     cout << "DP L \t\t\t Length of the system:  use positive real values only" << endl;
33 34
     cout << "int N \t\t\t Number of particles:  use positive integer values only" << endl;
34
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  -2*N and 2*N" << endl;
35
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
36
+      "recommended values:  -2*N and 2*N" << endl;
35 37
     cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
36 38
     cout << "int Aggregate size" << endl;
37 39
   }
@@ -74,7 +76,6 @@ int main(int argc, char* argv[])
74 76
     LiebLin_Bethe_State AveragingState = Canonical_Saddle_Point_State (c_int, L, N, whichDSF == 'Z' ? 0.0 : kBT);
75 77
 
76 78
     DP Chem_Pot = Chemical_Potential (AveragingState);
77
-    //DP sumrule_factor = Sumrule_Factor (whichDSF, AveragingState, Chem_Pot, fixed_iK, iKneeded);
78 79
     Vect<DP> sumrule_factor(iKmax - iKmin + 1);
79 80
     for (int ik = 0; ik < iKmax - iKmin + 1; ++ik)
80 81
       sumrule_factor[ik] = Sumrule_Factor (whichDSF, AveragingState, Chem_Pot, ik, ik);
@@ -117,7 +118,8 @@ int main(int argc, char* argv[])
117 118
       }
118 119
 
119 120
       if (naccounted >= AgSize) {
120
-	STATfile << nread << "\t" << maxsrcont << "\t" << totsrcont/AgSize << "\t" << totsrcont/(AgSize * (maxsrcont > 0.0 ? maxsrcont : 1.0)) << "\t" << accumulatedsrcont << endl;
121
+	STATfile << nread << "\t" << maxsrcont << "\t" << totsrcont/AgSize << "\t"
122
+		 << totsrcont/(AgSize * (maxsrcont > 0.0 ? maxsrcont : 1.0)) << "\t" << accumulatedsrcont << endl;
121 123
 	naccounted = 0;
122 124
 	maxsrcont = 0.0;
123 125
 	totsrcont = 0.0;

+ 0
- 5
src/EXECS/LiebLin_TBA.cc View File

@@ -19,8 +19,6 @@ using namespace ABACUS;
19 19
 
20 20
 int main(int argc, const char* argv[])
21 21
 {
22
-
23
-  //if (argc != 7) ABACUSerror("Wrong number of arguments to 2CBG_ThLim executable.  Use c(best to set to 1), nbar, ebar, req_diff, Max_Secs, bool Save_data (0 == false).");
24 22
   if (argc != 6) ABACUSerror("Wrong number of arguments.  Use c(best to set to 1), mu, kBT, req_diff, Max_Secs");
25 23
 
26 24
   DP c_int = atof(argv[1]);
@@ -33,11 +31,8 @@ int main(int argc, const char* argv[])
33 31
   if (kBT <= 0.0) ABACUSerror("Negative T ?  Not for the LiebLin gas.");
34 32
   if (Max_Secs < 10) ABACUSerror("Give more time.");
35 33
 
36
-  //cout << "Read c_int = " << c_int << "\tmu = " << mu << "\tOmega = " << Omega << "\tkBT = " << kBT << "\tMax_Secs = " << Max_Secs << endl;
37
-
38 34
   LiebLin_TBA_Solution  solution(c_int, mu, kBT, req_diff, Max_Secs);
39 35
 
40
-
41 36
   cout << solution.nbar << "\t" << solution.ebar << "\t" << solution.sbar << "\t";
42 37
 
43 38
   return(0);

+ 0
- 4
src/EXECS/LiebLin_TBA_fixed_nbar.cc View File

@@ -19,8 +19,6 @@ using namespace ABACUS;
19 19
 
20 20
 int main(int argc, const char* argv[])
21 21
 {
22
-
23
-  //if (argc != 7) ABACUSerror("Wrong number of arguments to 2CBG_ThLim executable.  Use c(best to set to 1), nbar, ebar, req_diff, Max_Secs, bool Save_data (0 == false).");
24 22
   if (argc != 6) ABACUSerror("Wrong number of arguments.  Use c(best to set to 1), nbar, kBT, req_diff, Max_Secs");
25 23
 
26 24
   DP c_int = atof(argv[1]);
@@ -33,8 +31,6 @@ int main(int argc, const char* argv[])
33 31
   if (kBT <= 0.0) ABACUSerror("Negative T ?  Not for the LiebLin gas.");
34 32
   if (Max_Secs < 10) ABACUSerror("Give more time.");
35 33
 
36
-  //cout << "Read c_int = " << c_int << "\tmu = " << mu << "\tOmega = " << Omega << "\tkBT = " << kBT << "\tMax_Secs = " << Max_Secs << endl;
37
-
38 34
   LiebLin_TBA_Solution solution = LiebLin_TBA_Solution_fixed_nbar (c_int, nbar, kBT, req_diff, Max_Secs);
39 35
 
40 36
   cout << solution.nbar << "\t" << solution.ebar << "\t" << solution.sbar << "\t";

+ 2
- 4
src/EXECS/LiebLin_TBA_fixed_nbar_ebar.cc View File

@@ -19,8 +19,8 @@ using namespace ABACUS;
19 19
 
20 20
 int main(int argc, const char* argv[])
21 21
 {
22
-
23
-  if (argc != 7) ABACUSerror("Wrong number of arguments.  Use c(best to set to 1), nbar, ebar, req_diff, Max_Secs, bool Save_data (0 == false).");
22
+  if (argc != 7) ABACUSerror("Wrong number of arguments.  Use c(best to set to 1), "
23
+			     "nbar, ebar, req_diff, Max_Secs, bool Save_data (0 == false).");
24 24
 
25 25
   DP c_int = atof(argv[1]);
26 26
   DP nbar = atof(argv[2]);
@@ -32,8 +32,6 @@ int main(int argc, const char* argv[])
32 32
   if (c_int <= 0.0) ABACUSerror("Give a strictly positive c.");
33 33
   if (Max_Secs < 10) ABACUSerror("Give more time.");
34 34
 
35
-  //cout << "Read c_int = " << c_int << "\tmu = " << mu << "\tOmega = " << Omega << "\tkBT = " << kBT << "\tMax_Secs = " << Max_Secs << endl;
36
-
37 35
   LiebLin_TBA_Solution solution = LiebLin_TBA_Solution_fixed_nbar_ebar(c_int, nbar, ebar, req_diff, Max_Secs);
38 36
 
39 37
   cout << solution.nbar << "\t" << solution.ebar << "\t" << solution.sbar << "\t";

+ 4
- 3
src/EXECS/ODSLF_DSF.cc View File

@@ -26,11 +26,13 @@ int main(int argc, char* argv[])
26 26
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
27 27
     cout << "Usage of ODSLF_DSF executable: " << endl;
28 28
     cout << endl << "Provide the following arguments:" << endl << endl;
29
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  m for S- S+, z for Sz Sz, p for S+ S-." << endl;
29
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
30
+      "m for S- S+, z for Sz Sz, p for S+ S-." << endl;
30 31
     cout << "DP Delta \t\t Value of the anisotropy:  use positive real values only" << endl;
31 32
     cout << "int N \t\t\t Length (number of sites) of the system:  use positive even integer values only" << endl;
32 33
     cout << "int M \t\t\t Number of down spins:  use positive integer values between 1 and N/2" << endl;
33
-    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  recommended values:  0 and N" << endl;
34
+    cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over:  "
35
+      "recommended values:  0 and N" << endl;
34 36
     cout << "int Max_Secs \t\t Allowed computational time:  (in seconds)" << endl;
35 37
     cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
36 38
     cout << "bool refine \t\t Is this a refinement of a earlier calculations ?  (0 == false, 1 == true)" << endl;
@@ -52,7 +54,6 @@ int main(int argc, char* argv[])
52 54
     Scan_ODSLF (whichDSF, Delta, N, M, iKmin, iKmax, Max_Secs, target_sumrule, refine, 0, 1);
53 55
   }
54 56
 
55
-
56 57
   else ABACUSerror("Wrong number of arguments to ODSLF_DSF executable.");
57 58
 
58 59
   return(0);

+ 0
- 2
src/EXECS/Produce_Sorted_RAW_File.cc View File

@@ -29,8 +29,6 @@ int main(int argc, char* argv[])
29 29
   char whichDSF = *argv[2];
30 30
   char whichsorting = *argv[3];
31 31
 
32
-
33
-  //cout << rawfilename << "\t" << whichDSF << "\t" << whichsorting << endl;
34 32
   Sort_RAW_File (rawfilename, whichsorting, whichDSF);
35 33
 
36 34
   return(0);

+ 2
- 1
src/EXECS/RAW_File_Stats.cc View File

@@ -82,7 +82,8 @@ int main(int argc, char* argv[])
82 82
       naccounted++;
83 83
 
84 84
       if (naccounted >= AgSize) {
85
-	STATfile << nread << "\t" << maxsrcont << "\t" << totsrcont/AgSize << "\t" << totsrcont/(AgSize * (maxsrcont > 0.0 ? maxsrcont : 1.0)) << "\t" << accumulatedsrcont << endl;
85
+	STATfile << nread << "\t" << maxsrcont << "\t" << totsrcont/AgSize << "\t"
86
+		 << totsrcont/(AgSize * (maxsrcont > 0.0 ? maxsrcont : 1.0)) << "\t" << accumulatedsrcont << endl;
86 87
 	naccounted = 0;
87 88
 	maxsrcont = 0.0;
88 89
 	totsrcont = 0.0;

+ 0
- 4
src/EXECS/Smoothen_Heis_DSF.cc View File

@@ -21,12 +21,10 @@ using namespace ABACUS;
21 21
 int main(int argc, char* argv[])
22 22
 {
23 23
   if (argc != 13 && argc != 14) { // Print out instructions
24
-    //if (strcmp(argv[1],"help") == 0) { // Output some instructions
25 24
     cout << "Usage of Smoothen_Heis_DSF executable: " << endl << endl;
26 25
     cout << "Provide arguments using one of the following options:" << endl << endl;
27 26
     cout << "1) (for general momenta) whichDSF Delta N M iKmin iKmax DiK kBT ommin ommax Nom gwidth" << endl << endl;
28 27
     cout << "2) (for fixed momentum) whichDSF Delta N M iKneeded ommin ommax Nom gwidth" << endl << endl;
29
-    //else ABACUSerror("Incomprehensible arguments in Smoothen_Heis_DSF executable.");
30 28
   }
31 29
 
32 30
   else if (argc == 13) { // !fixed_iK
@@ -84,7 +82,5 @@ int main(int argc, char* argv[])
84 82
   }
85 83
   */
86 84
 
87
-  //else ABACUSerror("Wrong number of arguments to Smoothen_Heis_DSF executable.");
88
-
89 85
   return(0);
90 86
 }

+ 5
- 11
src/EXECS/Smoothen_LiebLin_DSF.cc View File

@@ -25,13 +25,15 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of Smoothen_LiebLin_DSF executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
32 33
     cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers" << endl;
33 34
     cout << "DP kBT \t\t Temperature" << endl;
34
-    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
35
+    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; "
36
+      "DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
35 37
     cout << "DP ommin" << endl << "DP ommax \t\t Min and max frequencies to cover in smoothened DSF" << endl;
36 38
     cout << "Nom \t\t\t Number of frequency points used for discretization" << endl;
37 39
     cout << "DP width \t\t Gaussian width used in smoothing, in units of two-particle level spacing" << endl;
@@ -56,7 +58,6 @@ int main(int argc, char* argv[])
56 58
     DP width = atof(argv[12]);
57 59
 
58 60
     stringstream filenameprefix;
59
-    //void Data_File_Name (stringstream& name, char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, DP L2)
60 61
     Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
61 62
     string prefix = filenameprefix.str();
62 63
 
@@ -65,15 +66,10 @@ int main(int argc, char* argv[])
65 66
 
66 67
     Write_K_File (L, iKmin, iKmax);
67 68
     Write_Omega_File (Nom, ommin, ommax);
68
-    //cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization) << endl;
69
-    // We use the scaled width function as default:
70 69
 
70
+    // We use the scaled width function as default:
71 71
     DP sumcheck;
72
-    //if (kBT < 0.1)
73
-    //sumcheck = Smoothen_RAW_into_SF_LiebLin_Scaled (prefix, L, N, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization);
74 72
     sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization, denom_sum_K);
75
-      //else sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization);
76
-    //cout << "Smoothing:  sumcheck = " << sumcheck << endl;
77 73
   }
78 74
 
79 75
   /*
@@ -105,7 +101,5 @@ int main(int argc, char* argv[])
105 101
   }
106 102
   */
107 103
 
108
-  //else ABACUSerror("Wrong number of arguments to Smoothen_LiebLin_DSF executable.");
109
-
110 104
   return(0);
111 105
 }

+ 7
- 15
src/EXECS/Smoothen_LiebLin_DSF_GeneralState.cc View File

@@ -25,14 +25,16 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of Smoothen_LiebLin_DSF executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
32
-    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the AveragingState; used as defaultScanStatename" << endl;
33
+    cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the "
34
+      "AveragingState; used as defaultScanStatename" << endl;
33 35
      cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers" << endl;
34
-    //cout << "DP kBT \t\t Temperature" << endl;
35
-    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
36
+    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; "
37
+      "DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
36 38
     cout << "DP ommin" << endl << "DP ommax \t\t Min and max frequencies to cover in smoothened DSF" << endl;
37 39
     cout << "Nom \t\t\t Number of frequency points used for discretization" << endl;
38 40
     cout << "DP width \t\t Gaussian width used in smoothing, in units of two-particle level spacing" << endl;
@@ -51,7 +53,6 @@ int main(int argc, char* argv[])
51 53
     char* Ix2filenameprefix = argv[n++];
52 54
     int iKmin = atoi(argv[n++]);
53 55
     int iKmax = atoi(argv[n++]);
54
-    //DP kBT = atof(argv[7]);
55 56
     DP kBT = 0.0;
56 57
     int DiK = atoi(argv[n++]);
57 58
     DP ommin = atof(argv[n++]);
@@ -64,8 +65,6 @@ int main(int argc, char* argv[])
64 65
     string defaultScanStatename = filenamestrstream.str();
65 66
 
66 67
     stringstream filenameprefix;
67
-    //void Data_File_Name (stringstream& name, char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, DP L2)
68
-    //Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
69 68
     Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, defaultScanStatename);
70 69
     string prefix = filenameprefix.str();
71 70
 
@@ -74,15 +73,10 @@ int main(int argc, char* argv[])
74 73
 
75 74
     Write_K_File (L, iKmin, iKmax);
76 75
     Write_Omega_File (Nom, ommin, ommax);
77
-    //cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization) << endl;
78
-    // We use the scaled width function as default:
79 76
 
77
+    // We use the scaled width function as default:
80 78
     DP sumcheck;
81
-    //if (kBT < 0.1)
82
-    //sumcheck = Smoothen_RAW_into_SF_LiebLin_Scaled (prefix, L, N, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization);
83 79
     sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization, denom_sum_K);
84
-      //else sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization);
85
-    //cout << "Smoothing:  sumcheck = " << sumcheck << endl;
86 80
   }
87 81
 
88 82
   /*
@@ -114,7 +108,5 @@ int main(int argc, char* argv[])
114 108
   }
115 109
   */
116 110
 
117
-  //else ABACUSerror("Wrong number of arguments to Smoothen_LiebLin_DSF executable.");
118
-
119 111
   return(0);
120 112
 }

+ 5
- 14
src/EXECS/Smoothen_LiebLin_DSF_MosesState.cc View File

@@ -25,7 +25,8 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of Smoothen_LiebLin_DSF_MosesState executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
@@ -33,8 +34,8 @@ int main(int argc, char* argv[])
33 34
     cout << "int DIl \t\t shift of left  sea as compared to its ground state position" << endl;
34 35
     cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
35 36
     cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers" << endl;
36
-    //cout << "DP kBT \t\t Temperature" << endl;
37
-    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
37
+    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; "
38
+      "DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
38 39
     cout << "DP ommin" << endl << "DP ommax \t\t Min and max frequencies to cover in smoothened DSF" << endl;
39 40
     cout << "Nom \t\t\t Number of frequency points used for discretization" << endl;
40 41
     cout << "DP width \t\t Gaussian width used in smoothing, in units of two-particle level spacing" << endl;
@@ -50,12 +51,10 @@ int main(int argc, char* argv[])
50 51
     DP L = atof(argv[3]);
51 52
     int N = atoi(argv[4]);
52 53
     int Nl = atoi(argv[5]);
53
-    //int Nr = N - Nl;
54 54
     int DIl = atoi(argv[6]);
55 55
     int DIr = atoi(argv[7]);
56 56
     int iKmin = atoi(argv[8]);
57 57
     int iKmax = atoi(argv[9]);
58
-    //DP kBT = atof(argv[10]);
59 58
     DP kBT = 0.0;
60 59
     int DiK = atoi(argv[10]);
61 60
     DP ommin = atof(argv[11]);
@@ -69,7 +68,6 @@ int main(int argc, char* argv[])
69 68
     string defaultScanStatename = defaultScanStatename_strstream.str();
70 69
 
71 70
     stringstream filenameprefix;
72
-    //void Data_File_Name (stringstream& name, char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, DP L2)
73 71
     Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, defaultScanStatename);
74 72
     string prefix = filenameprefix.str();
75 73
 
@@ -80,18 +78,11 @@ int main(int argc, char* argv[])
80 78
 
81 79
     Write_K_File (L, iKmin, iKmax);
82 80
     Write_Omega_File (Nom, ommin, ommax);
83
-    //cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization) << endl;
84
-    // We use the scaled width function as default:
85 81
 
82
+    // We use the scaled width function as default:
86 83
     DP sumcheck;
87
-    //if (kBT < 0.1)
88
-    //sumcheck = Smoothen_RAW_into_SF_LiebLin_Scaled (prefix, L, N, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization);
89 84
     sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization, denom_sum_K);
90
-      //else sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization);
91
-    //cout << "Smoothing:  sumcheck = " << sumcheck << endl;
92 85
   }
93 86
 
94
-  //else ABACUSerror("Wrong number of arguments to Smoothen_LiebLin_DSF executable.");
95
-
96 87
   return(0);
97 88
 }

+ 5
- 12
src/EXECS/Smoothen_LiebLin_DSF_Scaled.cc View File

@@ -25,13 +25,15 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of Smoothen_LiebLin_DSF_Scaled executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
32 33
     cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers" << endl;
33 34
     cout << "DP kBT \t\t Temperature" << endl;
34
-    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
35
+    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; "
36
+      "DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
35 37
     cout << "DP ommin" << endl << "DP ommax \t\t Min and max frequencies to cover in smoothened DSF" << endl;
36 38
     cout << "Nom \t\t\t Number of frequency points used for discretization" << endl;
37 39
     cout << "DP width \t\t Gaussian width used in smoothing, in units of two-particle level spacing" << endl;
@@ -56,27 +58,18 @@ int main(int argc, char* argv[])
56 58
     DP width = atof(argv[12]);
57 59
 
58 60
     stringstream filenameprefix;
59
-    //void Data_File_Name (stringstream& name, char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, DP L2)
60 61
     Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
61 62
     string prefix = filenameprefix.str();
62 63
 
63 64
     DP normalization = twoPI * L;
64
-    //DP denom_sum_K = L;
65 65
 
66 66
     Write_K_File (L, iKmin, iKmax);
67 67
     Write_Omega_File (Nom, ommin, ommax);
68
-    //cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization) << endl;
69
-    // We use the scaled width function as default:
70 68
 
69
+    // We use the scaled width function as default:
71 70
     DP sumcheck;
72
-    //if (kBT < 0.1)
73 71
     sumcheck = Smoothen_RAW_into_SF_LiebLin_Scaled (prefix, L, N, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization);
74
-    //sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, DiK, ommin, ommax, Nom, width, normalization, denom_sum_K);
75
-      //else sumcheck = Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, width, normalization);
76
-    //cout << "Smoothing:  sumcheck = " << sumcheck << endl;
77 72
   }
78 73
 
79
-  //else ABACUSerror("Wrong number of arguments to Smoothen_LiebLin_DSF executable.");
80
-
81 74
   return(0);
82 75
 }

+ 4
- 9
src/EXECS/Smoothen_LiebLin_DSF_over_Ensemble.cc View File

@@ -25,18 +25,18 @@ int main(int argc, char* argv[])
25 25
     cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
26 26
     cout << endl << "Usage of Smoothen_LiebLin_DSF_over_Ensemble executable: " << endl;
27 27
     cout << endl << "Provide the following arguments:" << endl << endl;
28
-    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
28
+    cout << "char whichDSF \t\t Which structure factor should be calculated ?  Options are:  "
29
+      "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
29 30
     cout << "DP c_int \t\t Value of the interaction parameter" << endl;
30 31
     cout << "DP L \t\t\t Length of the system" << endl;
31 32
     cout << "int N \t\t\t Number of particles" << endl;
32 33
     cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers" << endl;
33 34
     cout << "DP kBT \t\t Temperature" << endl;
34
-    //cout << "int nstates \t\t\t Number of states considered in the ensemble" << endl;
35
-    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
35
+    cout << "int DiK \t\t\t Window of iK over which DSF is averaged (DiK == 0 means a single iK is used; "
36
+      "DiK == 1 means 3 are used (iK-1, iK, iK+1), etc.)" << endl;
36 37
     cout << "DP ommin" << endl << "DP ommax \t\t Min and max frequencies to cover in smoothened DSF" << endl;
37 38
     cout << "Nom \t\t\t Number of frequency points used for discretization" << endl;
38 39
     cout << "DP width \t\t Gaussian width used in smoothing, in units of two-particle level spacing" << endl;
39
-
40 40
     cout << endl << "EXAMPLE: " << endl << endl;
41 41
     cout << "Smoothen_LiebLin_DSF_over_Ensemble d 1.0 100.0 100 0 200 5.0 1 0.0 10.0 500 2.0" << endl << endl;
42 42
 
@@ -50,7 +50,6 @@ int main(int argc, char* argv[])
50 50
     int iKmin = atoi(argv[5]);
51 51
     int iKmax = atoi(argv[6]);
52 52
     DP kBT = atof(argv[7]);
53
-    //int nstates_req = atoi(argv[8]);
54 53
     int DiK = atoi(argv[8]);
55 54
     DP ommin = atof(argv[9]);
56 55
     DP ommax = atof(argv[10]);
@@ -58,7 +57,6 @@ int main(int argc, char* argv[])
58 57
     DP width = atof(argv[12]);
59 58
 
60 59
     stringstream filenameprefix;
61
-    //void Data_File_Name (stringstream& name, char whichDSF, DP c_int, DP L, int N, int iKmin, int iKmax, DP kBT, DP L2)
62 60
     Data_File_Name (filenameprefix, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
63 61
     string prefix = filenameprefix.str();
64 62
 
@@ -72,7 +70,6 @@ int main(int argc, char* argv[])
72 70
     LiebLin_Diagonal_State_Ensemble ensemble;
73 71
 
74 72
     stringstream ensfilestrstream;
75
-    //ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << "_ns_" << nstates_req << ".ens";
76 73
     ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << ".ens";
77 74
     string ensfilestr = ensfilestrstream.str();
78 75
     const char* ensfile_Cstr = ensfilestr.c_str();
@@ -85,12 +82,10 @@ int main(int argc, char* argv[])
85 82
     for (int ns = 0; ns < ensemble.nstates; ++ns) {
86 83
       // Define the raw input file name:
87 84
       stringstream filenameprefix;
88
-      //Data_File_Name (filenameprefix, whichDSF, iKmin, iKmax, kBT, ensemble.state[ns], ensemble.state[ns], ensemble.state[ns].label);
89 85
       Data_File_Name (filenameprefix, whichDSF, iKmin, iKmax, 0.0, ensemble.state[ns], ensemble.state[ns], ensemble.state[ns].label);
90 86
       string prefix = filenameprefix.str();
91 87
       stringstream RAW_stringstream;    string RAW_string;
92 88
       RAW_stringstream << prefix << ".raw";
93
-      //RAW_string = RAW_stringstream.str();    const char* RAW_Cstr = RAW_string.c_str();
94 89
       rawfilename[ns] = RAW_stringstream.str();
95 90
     }
96 91
 

+ 4
- 4
src/EXECS/Smoothen_ODSLF_DSF.cc View File

@@ -21,12 +21,10 @@ using namespace ABACUS;
21 21
 int main(int argc, char* argv[])
22 22
 {
23 23
   if (argc != 10 && argc != 11) { // Print out instructions
24
-    //if (strcmp(argv[1],"help") == 0) { // Output some instructions
25 24
     cout << "Usage of Smoothen_ODSLF_DSF executable: " << endl << endl;
26 25
     cout << "Provide arguments using one of the following options:" << endl << endl;
27 26
     cout << "1) (for general momenta) whichDSF Delta N M iKmin iKmax ommin ommax Nom gwidth" << endl << endl;
28 27
     cout << "2) (for fixed momentum) whichDSF Delta N M iKneeded ommin ommax Nom gwidth" << endl << endl;
29
-    //else ABACUSerror("Incomprehensible arguments in Smoothen_ODSLF_DSF executable.");
30 28
   }
31 29
 
32 30
   else if (argc == 11) { // !fixed_iK
@@ -47,7 +45,8 @@ int main(int argc, char* argv[])
47 45
 
48 46
     DP normalization = twoPI;
49 47
 
50
-    cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, gwidth, normalization) << endl;
48
+    cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax,
49
+							       Nom, gwidth, normalization) << endl;
51 50
 
52 51
     Write_K_File (N, iKmin, iKmax);
53 52
     Write_Omega_File (Nom, ommin, ommax);
@@ -75,7 +74,8 @@ int main(int argc, char* argv[])
75 74
     int iKmin = iKneeded;
76 75
     int iKmax = iKneeded;
77 76
 
78
-    cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax, Nom, gwidth, normalization) << endl;
77
+    cout << "Smoothing:  sumcheck = " << Smoothen_RAW_into_SF (prefix, iKmin, iKmax, ommin, ommax,
78
+							       Nom, gwidth, normalization) << endl;
79 79
   }
80 80
 
81 81
   else ABACUSerror("Wrong number of arguments to Smoothen_Heis_DSF executable.");

+ 6
- 3
src/EXECS/XXZ_gpd_StagSz_h0.cc View File

@@ -21,7 +21,8 @@ using namespace ABACUS;
21 21
 int main( int argc, char* argv[])
22 22
 {
23 23
   if (!(argc == 3 || argc == 5)) { // provide some info
24
-    cout << endl << "This code computes the (1/N) (-1)^j S^z_j on-site staggered magnetization for XXZ_gpd in zero field." << endl;
24
+    cout << endl << "This code computes the (1/N) (-1)^j S^z_j on-site staggered magnetization "
25
+      "for XXZ_gpd in zero field." << endl;
25 26
     cout << "First option: provide two arguments: anisotropy Delta (> 1) and system size N (even)." << endl;
26 27
     cout << "Second option: provide five arguments: system size N (even), Delta min, Delta max, NDelta." << endl;
27 28
     cout << "The output is Delta, N, stag mag, energy gap." << endl;
@@ -57,7 +58,8 @@ int main( int argc, char* argv[])
57 58
     if (!estate.conv) ABACUSerror("Umklapp state did not converge.");
58 59
     if (!estategap.conv) ABACUSerror("Gap state did not converge.");
59 60
 
60
-    cout << Delta << "\t" << N << "\t" << setprecision(12) << exp(real(ln_Sz_ME (gstate, estate)))/sqrt(N) << "\t" << estategap.E - gstate.E << endl;
61
+    cout << Delta << "\t" << N << "\t" << setprecision(12) << exp(real(ln_Sz_ME (gstate, estate)))/sqrt(N)
62
+	 << "\t" << estategap.E - gstate.E << endl;
61 63
 
62 64
   }
63 65
 
@@ -102,7 +104,8 @@ int main( int argc, char* argv[])
102 104
       if (!estate.conv) ABACUSerror("Umklapp state did not converge.");
103 105
       if (!estategap.conv) ABACUSerror("Gap state did not converge.");
104 106
 
105
-      cout << Delta << "\t" << N << "\t" << setprecision(12) << exp(real(ln_Sz_ME (gstate, estate)))/sqrt(N) << "\t" << estategap.E - gstate.E << endl;
107
+      cout << Delta << "\t" << N << "\t" << setprecision(12) << exp(real(ln_Sz_ME (gstate, estate)))/sqrt(N)
108
+	   << "\t" << estategap.E - gstate.E << endl;
106 109
 
107 110
     }
108 111
   }

+ 98
- 381
src/HEIS/Heis.cc View File

@@ -27,8 +27,9 @@ namespace ABACUS {
27 27
       si_n_anis_over_2(new DP[1]), co_n_anis_over_2(new DP[1]), ta_n_anis_over_2(new DP[1]), prec(ITER_REQ_PREC) {}
28 28
 
29 29
   Heis_Chain::Heis_Chain (DP JJ, DP DD, DP hh, int NN)
30
-    : J(JJ), Delta(DD), anis(0.0), hz(hh), Nsites(NN), Nstrings(MAXSTRINGS), Str_L(new int[MAXSTRINGS]), par(new int[MAXSTRINGS]),
31
-      si_n_anis_over_2(new DP[10*MAXSTRINGS]), co_n_anis_over_2(new DP[10*MAXSTRINGS]), ta_n_anis_over_2(new DP[10*MAXSTRINGS]), prec(ITER_REQ_PREC)
30
+    : J(JJ), Delta(DD), anis(0.0), hz(hh), Nsites(NN), Nstrings(MAXSTRINGS), Str_L(new int[MAXSTRINGS]),
31
+      par(new int[MAXSTRINGS]), si_n_anis_over_2(new DP[10*MAXSTRINGS]), co_n_anis_over_2(new DP[10*MAXSTRINGS]),
32
+      ta_n_anis_over_2(new DP[10*MAXSTRINGS]), prec(ITER_REQ_PREC)
32 33
   {
33 34
     // We restrict to even chains everywhere
34 35
 
@@ -43,7 +44,6 @@ namespace ABACUS {
43 44
       // Set the Str_L and par vectors:
44 45
 
45 46
       DP gammaoverpi = acos(DD)/PI;
46
-      //cout << "gammaoverpi = " << gammaoverpi << endl;
47 47
 
48 48
       Vect<int> Nu(MAXSTRINGS);
49 49
 
@@ -67,15 +67,11 @@ namespace ABACUS {
67 67
 	for (int p = 0; p < l; ++p) gammaoverpi_reached = Nu[l - p - 1] + 1.0/gammaoverpi_reached;
68 68
 	gammaoverpi_reached = 1.0/gammaoverpi_reached;
69 69
 
70
-	//cout << "gammaoverpi_reached = " << gammaoverpi_reached << "\tdiff = " << fabs(gammaoverpi - gammaoverpi_reached) << endl;
71
-	//cout << "ml_temp = " << ml_temp << "\tMAXSTRINGS = " << MAXSTRINGS << endl;
72
-
73 70
 	l++;
74 71
 
75 72
 	if (ml_temp > MAXSTRINGS) break;  // we defined Str_L and par as arrays of at most MAXSTRINGS elements, so we cut off here...
76 73
 
77 74
       }
78
-      //cout << "l = " << l << endl;
79 75
 
80 76
       // Check:  make sure the last Nu is greater than one:  if one, add 1 to previous Nu
81 77
 
@@ -253,86 +249,18 @@ namespace ABACUS {
253 249
     if (ta_n_anis_over_2 != 0) delete[] ta_n_anis_over_2;
254 250
   }
255 251
 
256
-  /* Deactivated in ++G_8
257
-  void Heis_Chain::Scan_for_Possible_Bases (int Mdown_remaining, Vect<string>& possible_base_label, int& nfound, int nexc_max_used,
258
-					    int base_level_to_scan, Vect<int>& Nrapidities)
259
-  {
260
-    if (Mdown_remaining < 0) { ABACUSerror("Scan_for_Possible_Bases:  shouldn't be here..."); }  // reached inconsistent point
261
-
262
-    //cout << "Mdown_remaining " << Mdown_remaining << "\t" << possible_base_id << "\tnfound " << nfound
263
-    // << "\tnexc_max_used " << nexc_max_used << "\tbase_level_to_scan " << base_level_to_scan << "\tNrap " << Nrapidities << endl;
264
-
265
-    if (base_level_to_scan == 0) {
266
-      Nrapidities[0] = Mdown_remaining;
267
-
268
-      // Set label:
269
-      stringstream M0out;
270
-      M0out << Nrapidities[0];
271
-      possible_base_label[nfound] = M0out.str();
272
-      for (int itype = 1; itype < Nrapidities.size(); ++itype)
273
-	if (Nrapidities[itype] > 0) {
274
-	  possible_base_label[nfound] += TYPESEP;
275
-	  stringstream typeout;
276
-	  typeout << itype;
277
-	  possible_base_label[nfound] += typeout.str();
278
-	  possible_base_label[nfound] += EXCSEP;
279
-	  stringstream Mout;
280
-	  Mout << Nrapidities[itype];
281
-	  possible_base_label[nfound] += Mout.str();
282
-	}
283
-      nfound++;
284
-    }
285
-
286
-    else {
287
-      // Remove all higher strings:
288
-      //Nrapidities[base_level_to_scan] = 0;
289
-      //Scan_for_Possible_Bases (Mdown_remaining, possible_base_id, nfound, nexc_max_used, base_level_to_scan - 1, Nrapidities);
290
-
291
-      for (int i = 0; i <= (Str_L[base_level_to_scan] == 0 ? 0 : nexc_max_used/Str_L[base_level_to_scan]); ++i) {
292
-	Nrapidities[base_level_to_scan] = i;
293
-	Scan_for_Possible_Bases (Mdown_remaining - i*Str_L[base_level_to_scan], possible_base_label, nfound,
294
-				 nexc_max_used - i*Str_L[base_level_to_scan], base_level_to_scan - 1, Nrapidities);
295
-      }
296
-
297
-    }
298
-  }
299
-
300
-
301
-  Vect<string> Heis_Chain::Possible_Bases (int Mdown)  // returns a vector of possible bases
302
-  {
303
-    // We partition Mdown into up to NEXC_MAX_HEIS excitations
304
-
305
-    int nexc_max_used = ABACUS::min(NEXC_MAX_HEIS, 2*(Mdown/2));  // since each inner sector can contain at most N/2 holes.
306
-
307
-    Vect<string> possible_base_label (1000);
308
-    int nfound = 0;
309
-    Vect<int> Nrapidities (0, Nstrings);
310
-
311
-    //cout << "In Possible_Bases:  start scan for Mdown = " << Mdown << endl;
312
-
313
-    (*this).Scan_for_Possible_Bases (Mdown, possible_base_label, nfound, nexc_max_used, Nstrings - 1, Nrapidities);
314
-
315
-    // Copy results into a clean vector:
316
-    Vect<string> possible_base_label_found (nfound);
317
-    for (int i = 0; i < nfound; ++i) possible_base_label_found[i] = possible_base_label[i];
318
-
319
-    //cout << "In Possible_Bases:  possible_base_label_found = " << possible_base_label_found << endl;
320
-
321
-    return(possible_base_label_found);
322
-  }
323
-  */
324 252
 
325 253
   //***************************************************************************************************
326 254
 
327 255
   // Function definitions:  class Heis_Base
328 256
 
329
-  Heis_Base::Heis_Base () : Mdown(0), Nrap(Vect<int>()), Nraptot(0),
330
-			    Ix2_infty(Vect<DP>()), Ix2_min(Vect<int>()), Ix2_max(Vect<int>()), dimH(0.0), baselabel("") {}
257
+  Heis_Base::Heis_Base () : Mdown(0), Nrap(Vect<int>()), Nraptot(0), Ix2_infty(Vect<DP>()),
258
+			    Ix2_min(Vect<int>()), Ix2_max(Vect<int>()), dimH(0.0), baselabel("") {}
331 259
 
332 260
   Heis_Base::Heis_Base (const Heis_Base& RefBase)  // copy constructor
333 261
     : Mdown(RefBase.Mdown), Nrap(Vect<int>(RefBase.Nrap.size())), Nraptot(RefBase.Nraptot),
334
-      Ix2_infty(Vect<DP>(RefBase.Nrap.size())), Ix2_min(Vect<int>(RefBase.Nrap.size())), Ix2_max(Vect<int>(RefBase.Nrap.size())),
335
-      baselabel(RefBase.baselabel)
262
+      Ix2_infty(Vect<DP>(RefBase.Nrap.size())), Ix2_min(Vect<int>(RefBase.Nrap.size())),
263
+      Ix2_max(Vect<int>(RefBase.Nrap.size())), baselabel(RefBase.baselabel)
336 264
   {
337 265
     for (int i = 0; i < Nrap.size(); ++i) {
338 266
       Nrap[i] = RefBase.Nrap[i];
@@ -344,8 +272,8 @@ namespace ABACUS {
344 272
   }
345 273
 
346 274
   Heis_Base::Heis_Base (const Heis_Chain& RefChain, int M)
347
-    : Mdown(M), Nrap(Vect<int>(RefChain.Nstrings)), Nraptot(0),
348
-      Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_min(Vect<int>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings))
275
+    : Mdown(M), Nrap(Vect<int>(RefChain.Nstrings)), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)),
276
+      Ix2_min(Vect<int>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings))
349 277
   {
350 278
     for (int i = 0; i < RefChain.Nstrings; ++i) Nrap[i] = 0;
351 279
     Nrap[0] = M;
@@ -363,20 +291,21 @@ namespace ABACUS {
363 291
     // Compute dimensionality of this sub-Hilbert space:
364 292
     complex<double> ln_dimH_cx = 0.0;
365 293
     for (int i = 0; i < RefChain.Nstrings; ++i)
366
-      if (Nrap[i] > 0) ln_dimH_cx += ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2)) - ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2 - Nrap[i])) - ln_Gamma(complex<double>(Nrap[i] + 1));
294
+      if (Nrap[i] > 0) ln_dimH_cx += ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2))
295
+			 - ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2 - Nrap[i]))
296
+			 - ln_Gamma(complex<double>(Nrap[i] + 1));
367 297
     dimH = exp(real(ln_dimH_cx));
368 298
   }
369 299
 
370 300
   Heis_Base::Heis_Base (const Heis_Chain& RefChain, const Vect<int>& Nrapidities)
371
-    : Mdown(0), Nrap(Nrapidities), Nraptot(0),
372
-      Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_min(Vect<int>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings))
301
+    : Mdown(0), Nrap(Nrapidities), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)),
302
+      Ix2_min(Vect<int>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings))
373 303
   {
374 304
 
375 305
     // Check consistency of Nrapidities vector with RefChain
376 306
 
377
-    //if (RefChain.Nstrings != Nrapidities.size()) cout << "error:  Nstrings = " << RefChain.Nstrings << "\tNrap.size = " << Nrapidities.size() << endl;
378
-
379
-    if (RefChain.Nstrings != Nrapidities.size()) ABACUSerror("Incompatible Nrapidities vector used in Heis_Base constructor.");
307
+    if (RefChain.Nstrings != Nrapidities.size())
308
+      ABACUSerror("Incompatible Nrapidities vector used in Heis_Base constructor.");
380 309
 
381 310
     int Mcheck = 0;
382 311
     for (int i = 0; i < RefChain.Nstrings; ++i) Mcheck += RefChain.Str_L[i] * Nrap[i];
@@ -385,33 +314,6 @@ namespace ABACUS {
385 314
     Nraptot = 0;
386 315
     for (int i = 0; i < RefChain.Nstrings; ++i) Nraptot += Nrap[i];
387 316
 
388
-    /*
389
-    // Compute id
390
-    id += Nrapidities[0];
391
-    long long int factor = 100000LL;
392
-    for (int i = 1; i < RefChain.Nstrings; ++i) {
393
-      id += factor * Nrapidities[i];
394
-      factor *= 100LL;
395
-    }
396
-    */
397
-
398
-    // Set label:
399
-    /*
400
-    stringstream baselabel_strstream;
401
-    baselabel_strstream << Nrapidities[0];
402
-    for (int itype = 1; itype < Nrapidities.size(); ++itype)
403
-      if (Nrapidities[itype] > 0) {
404
-	baselabel_strstream << TYPESEP;
405
-	stringstream typeout;
406
-	typeout << itype;
407
-	baselabel += typeout.str();
408
-	baselabel += 'EXCSEP';
409
-	stringstream Mout;
410
-	Mout << Nrapidities[itype];
411
-	baselabel += Mout.str();
412
-      }
413
-    */
414
-
415 317
     stringstream M0out;
416 318
     M0out << Nrapidities[0];
417 319
     baselabel = M0out.str();
@@ -433,14 +335,15 @@ namespace ABACUS {
433 335
     // Compute dimensionality of this sub-Hilbert space:
434 336
     complex<double> ln_dimH_cx = 0.0;
435 337
     for (int i = 0; i < RefChain.Nstrings; ++i)
436
-      if (Nrap[i] > 0) ln_dimH_cx += ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2)) - ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2 - Nrap[i])) - ln_Gamma(complex<double>(Nrap[i] + 1));
338
+      if (Nrap[i] > 0) ln_dimH_cx += ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2))
339
+			 - ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2 - Nrap[i]))
340
+			 - ln_Gamma(complex<double>(Nrap[i] + 1));
437 341
     dimH = exp(real(ln_dimH_cx));
438 342
   }
439 343
 
440 344
   Heis_Base::Heis_Base (const Heis_Chain& RefChain, string baselabel_ref)
441
-    : Mdown(0), Nrap(Vect<int>(0, RefChain.Nstrings)), Nraptot(0),
442
-      Ix2_infty(Vect<DP>(RefChain.Nstrings)), Ix2_min(Vect<int>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings)),
443
-      baselabel (baselabel_ref)
345
+    : Mdown(0), Nrap(Vect<int>(0, RefChain.Nstrings)), Nraptot(0), Ix2_infty(Vect<DP>(RefChain.Nstrings)),
346
+      Ix2_min(Vect<int>(RefChain.Nstrings)), Ix2_max(Vect<int>(RefChain.Nstrings)), baselabel (baselabel_ref)
444 347
   {
445 348
     // Build Nrapidities vector from baselabel_ref.
446 349
     // This is simply done by using the state label standard reading function after conveniently
@@ -448,10 +351,8 @@ namespace ABACUS {
448 351
     string label_ref = baselabel + "_0_";
449 352
     Vect<Vect<int> > dummyOriginIx2(1);
450 353
 
451
-    //cout << "Trying to build base from baselabel_ref " << baselabel_ref << "\t and label_ref " << label_ref << endl;
452 354
     //State_Label_Data labeldata = Read_State_Label (label_ref, dummyOriginIx2);
453 355
     State_Label_Data labeldata = Read_Base_Label (label_ref);
454
-    //cout << "Read data." << endl;
455 356
 
456 357
     // Initialize Nrap:
457 358
     for (int i = 0; i < labeldata.type.size(); ++i)
@@ -470,7 +371,9 @@ namespace ABACUS {
470 371
     // Compute dimensionality of this sub-Hilbert space:
471 372
     complex<double> ln_dimH_cx = 0.0;
472 373
     for (int i = 0; i < RefChain.Nstrings; ++i)
473
-      if (Nrap[i] > 0) ln_dimH_cx += ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2)) - ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2 - Nrap[i])) - ln_Gamma(complex<double>(Nrap[i] + 1));
374
+      if (Nrap[i] > 0) ln_dimH_cx += ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2))
375
+			 - ln_Gamma(complex<double>((Ix2_max[i] - Ix2_min[i])/2 + 2 - Nrap[i]))
376
+			 - ln_Gamma(complex<double>(Nrap[i] + 1));
474 377
     dimH = exp(real(ln_dimH_cx));
475 378
   }
476 379
 
@@ -521,8 +424,9 @@ namespace ABACUS {
521 424
 
522 425
 	  sum2 = 0.0;
523 426
 
524
-	  sum2 += (RefChain.Str_L[j] == RefChain.Str_L[k]) ? 0.0 : 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
525
-										  - 0.5 * fabs(RefChain.Str_L[j] - RefChain.Str_L[k]) * RefChain.anis));
427
+	  sum2 += (RefChain.Str_L[j] == RefChain.Str_L[k]) ? 0.0 :
428
+	    2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
429
+			   - 0.5 * fabs(RefChain.Str_L[j] - RefChain.Str_L[k]) * RefChain.anis));
526 430
 	  sum2 += 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j] * RefChain.par[k])
527 431
 				 - 0.5 * (RefChain.Str_L[j] + RefChain.Str_L[k]) * RefChain.anis));
528 432
 
@@ -533,8 +437,9 @@ namespace ABACUS {
533 437
 	  sum1 += (Nrap[k] - ((j == k) ? 1 : 0)) * sum2;
534 438
 	}
535 439
 
536
-	Ix2_infty[j] = (1.0/PI) * fabs(RefChain.Nsites * 2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j])
537
-								      - 0.5 * RefChain.Str_L[j] * RefChain.anis)) - sum1);
440
+	Ix2_infty[j] = (1.0/PI) * fabs(RefChain.Nsites *
441
+				       2.0 * atan(tan(0.25 * PI * (1.0 + RefChain.par[j])
442
+						      - 0.5 * RefChain.Str_L[j] * RefChain.anis)) - sum1);
538 443
 
539 444
       }  // The Ix2_infty are now set.
540 445
 
@@ -576,7 +481,6 @@ namespace ABACUS {
576 481
 	  sum1 += Nrap[k] * (2 * ABACUS::min(RefChain.Str_L[j], RefChain.Str_L[k]) - ((j == k) ? 1 : 0));
577 482
 	}
578 483
 
579
-	//Ix2_infty[j] = (RefChain.Nsites - 1.0 + 2.0 * RefChain.Str_L[j] - sum1);
580 484
 	Ix2_infty[j] = (RefChain.Nsites + 1.0 - sum1); // to get counting right...
581 485
 
582 486
       }  // The Ix2_infty are now set.
@@ -644,10 +548,6 @@ namespace ABACUS {
644 548
 	  Ix2_max[j] -= 2;
645 549
 	}
646 550
 
647
-	// Fudge, for strings:
648
-	//if (RefChain.Str_L[j] >= 1) Ix2_max[j] += 2;
649
-	//Ix2_max[j] += 2;
650
-
651 551
 	Ix2_min[j] = -Ix2_max[j];
652 552
       }
653 553
 
@@ -665,22 +565,17 @@ namespace ABACUS {
665 565
 
666 566
   Lambda::Lambda (const Heis_Chain& RefChain, int M)
667 567
     : Nstrings(1), Nrap(Vect<int>(M,1)), Nraptot(M), lambda(new DP*[1]) // single type of string here
668
-      //: lambda(Vect<Vect<DP> > (1))
669 568
   {
670 569
     lambda[0] = new DP[M];
671
-    //lambda[0] = Vect<DP> (M);
672 570
 
673 571
     for (int j = 0; j < M; ++j) lambda[0][j] = 0.0;
674 572
   }
675 573
 
676 574
   Lambda::Lambda (const Heis_Chain& RefChain, const Heis_Base& base)
677 575
     : Nstrings(RefChain.Nstrings), Nrap(base.Nrap), Nraptot(base.Nraptot), lambda(new DP*[RefChain.Nstrings])
678
-      //: lambda(Vect<Vect<DP> > (RefChain.Nstrings))
679 576
   {
680
-    //lambda[0] = new DP[base.Mdown];
681 577
     lambda[0] = new DP[base.Nraptot];
682 578
     for (int i = 1; i < RefChain.Nstrings; ++i) lambda[i] = lambda[i-1] + base[i-1];
683
-    //for (int i = 0; i < RefChain.Nstrings; ++i) lambda[i] = Vect<DP> (base[i]);
684 579
 
685 580
     for (int i = 0; i < RefChain.Nstrings; ++i) {
686 581
       for (int j = 0; j < base[i]; ++j) lambda[i][j] = 0.0;
@@ -704,7 +599,7 @@ namespace ABACUS {
704 599
       for (int i = 0; i < Nstrings; ++i)
705 600
 	for (int j = 0; j < Nrap[i]; ++j) lambda[i][j] = RefLambda.lambda[i][j];
706 601
 
707
-   }
602
+    }
708 603
     return(*this);
709 604
   }
710 605
 
@@ -722,56 +617,33 @@ namespace ABACUS {
722 617
   // Function definitions:  class Heis_Bethe_State
723 618
 
724 619
   Heis_Bethe_State::Heis_Bethe_State ()
725
-    : chain(Heis_Chain()), base(Heis_Base()), //offsets(Ix2_Offsets()),
726
-      //Ix2(Ix2_Config(chain, 1)),
727
-      Ix2(Vect<Vect<int> > (1)),
620
+    : chain(Heis_Chain()), base(Heis_Base()), Ix2(Vect<Vect<int> > (1)),
728 621
       lambda(Lambda(chain, 1)), BE(Lambda(chain, 1)), diffsq(0.0), conv(0), dev(1.0), iter(0), iter_Newton(0),
729
-      E(0.0), iK(0), K(0.0), lnnorm(-100.0), //base_id(0LL), type_id(0LL), id(0LL), maxid(0LL), nparticles(0)
730
-      label("")
622
+      E(0.0), iK(0), K(0.0), lnnorm(-100.0), label("")
731 623
   {
732 624
   };
733 625
 
734 626
   Heis_Bethe_State::Heis_Bethe_State (const Heis_Bethe_State& RefState) // copy constructor
735
-    //: chain(RefState.chain), base(RefState.base), offsets(RefState.offsets), Ix2(Ix2_Config(RefState.chain, RefState.base.Mdown)),
736
-    //  lambda(Lambda(RefState.chain, RefState.base.Mdown)), BE(Lambda(RefState.chain, RefState.base.Mdown)),
737
-    : chain(RefState.chain), base(RefState.base), //offsets(RefState.offsets),
738
-      //Ix2(Ix2_Config(RefState.chain, RefState.base)),
739
-      Ix2 (RefState.Ix2),
627
+    : chain(RefState.chain), base(RefState.base), Ix2(RefState.Ix2),
740 628
       lambda(Lambda(RefState.chain, RefState.base)), BE(Lambda(RefState.chain, RefState.base)),
741
-      diffsq(RefState.diffsq), conv(RefState.conv), dev(RefState.dev), iter(RefState.iter), iter_Newton(RefState.iter_Newton),
629
+      diffsq(RefState.diffsq), conv(RefState.conv), dev(RefState.dev),
630
+      iter(RefState.iter), iter_Newton(RefState.iter_Newton),
742 631
       E(RefState.E), iK(RefState.iK), K(RefState.K), lnnorm(RefState.lnnorm),
743
-      //id(RefState.id), maxid(RefState.maxid)
744
-      //base_id(RefState.base_id), type_id(RefState.type_id), id(RefState.id), maxid(RefState.maxid), nparticles(RefState.nparticles)
745 632
       label(RefState.label)
746 633
   {
747 634
     // copy arrays into new ones
748
-
749
-    /*
750
-    cout << "Here in Heis constructor state" << endl;
751
-    cout << "lambda " << lambda[0][0] << endl;
752
-    cout << "lambda OK" << endl;
753
-
754
-    cout << "RefConfig: " << endl << RefState.Ix2 << endl;
755
-    cout << "(*this).Ix2: " << endl << Ix2 << endl;
756
-    */
757 635
     for (int j = 0; j < RefState.chain.Nstrings; ++j) {
758 636
       for (int alpha = 0; alpha < RefState.base[j]; ++j) {
759
-	//Ix2[j][alpha] = RefState.Ix2[j][alpha]; // not needed anymore since Ix2 is Vect<Vect<int> >
760 637
 	lambda[j][alpha] = RefState.lambda[j][alpha];
761 638
       }
762 639
     }
763
-    //cout << "Heis constructor state OK" << endl;
764 640
   }
765 641
 
766 642
   Heis_Bethe_State::Heis_Bethe_State (const Heis_Chain& RefChain, int M)
767
-    : chain(RefChain), base(RefChain, M), //offsets(base, 0LL),
768
-      //Ix2(Ix2_Config(RefChain, M)),
769
-      Ix2 (Vect<Vect<int> > (1)),
643
+    : chain(RefChain), base(RefChain, M), Ix2(Vect<Vect<int> > (1)),
770 644
       lambda(Lambda(RefChain, M)),
771 645
       BE(Lambda(RefChain, M)), diffsq(1.0), conv(0), dev(1.0), iter(0), iter_Newton(0),
772 646
       E(0.0), iK(0), K(0.0), lnnorm(-100.0)
773
-      //id(0LL), maxid(0LL)
774
-      //base_id(0LL), type_id(0LL), id(0LL), maxid(offsets.maxid), nparticles(0)
775 647
   {
776 648
     Ix2[0] = Vect<int> (M);
777 649
     for (int j = 0; j < M; ++j) Ix2[0][j] = -(M - 1) + 2*j;
@@ -782,20 +654,12 @@ namespace ABACUS {
782 654
   }
783 655
 
784 656
   Heis_Bethe_State::Heis_Bethe_State (const Heis_Chain& RefChain, const Heis_Base& RefBase)
785
-    : chain(RefChain), base(RefBase), //offsets(RefBase, 0LL),
786
-      //Ix2(Ix2_Config(RefChain, RefBase)),
787
-      Ix2 (Vect<Vect<int> > (RefChain.Nstrings)),
657
+    : chain(RefChain), base(RefBase), Ix2 (Vect<Vect<int> > (RefChain.Nstrings)),
788 658
       lambda(Lambda(RefChain, RefBase)),
789
-      BE(Lambda(RefChain, RefBase)), diffsq(1.0), conv(0), dev(1.0), iter(0), iter_Newton(0), E(0.0), iK(0), K(0.0), lnnorm(-100.0)
790
-      //id(0LL), maxid(0LL)
791
-      //base_id(RefBase.id), type_id(0LL), id(0LL), maxid(offsets.maxid), nparticles(0)
659
+      BE(Lambda(RefChain, RefBase)), diffsq(1.0), conv(0), dev(1.0),
660
+      iter(0), iter_Newton(0), E(0.0), iK(0), K(0.0), lnnorm(-100.0)
792 661
   {
793 662
     // Check that the number of rapidities is consistent with Mdown
794
-
795
-    //cout << "Here in Heis constructor chain base" << endl;
796
-    //cout << "lambda " << lambda[0][0] << endl;
797
-    //cout << "lambda OK" << endl;
798
-
799 663
     int Mcheck = 0;
800 664
     for (int i = 0; i < RefChain.Nstrings; ++i) Mcheck += base[i] * RefChain.Str_L[i];
801 665
     if (RefBase.Mdown != Mcheck) ABACUSerror("Wrong M from Nrapidities input vector, in Heis_Bethe_State constructor.");
@@ -812,15 +676,8 @@ namespace ABACUS {
812 676
 
813 677
   void Heis_Bethe_State::Set_to_Label (string label_ref, const Vect<Vect<int> >& OriginIx2)
814 678
   {
815
-    //cout << "Called Set_to_Label with label_ref " << label_ref << " on state " << (*this) << endl;
816
-
817
-    //cout << "Check labeldata of label " << label_ref << endl;
818
-
819 679
     State_Label_Data labeldata = Read_State_Label (label_ref, OriginIx2);
820 680
 
821
-    //cout << "type: " << labeldata.type << endl << "M: " << labeldata.M << endl << "nexc: " << labeldata.nexc << endl;
822
-    //for (int i = 0; i < labeldata.Ix2old.size(); ++i) cout << "Ix2old[" << i << "] = " << labeldata.Ix2old[i] << endl << "Ix2exc[" << i << "] = " << labeldata.Ix2exc[i] << endl;
823
-
824 681
     label = label_ref;
825 682
 
826 683
     Vect<Vect<int> > OriginIx2ordered = OriginIx2;
@@ -835,26 +692,11 @@ namespace ABACUS {
835 692
       for (int iexc = 0; iexc < labeldata.nexc[it]; ++iexc)
836 693
 	for (int i = 0; i < labeldata.M[it]; ++i)
837 694
 	  if (Ix2[labeldata.type[it] ][i] == labeldata.Ix2old[it][iexc]) {
838
-	    //cout << it << "\t" << iexc << "\t" << i << endl;
839
-	    //cout << "\tSetting Ix2[" << labeldata.type[it] << "][" << i << "] to " << labeldata.Ix2exc[it][iexc] << endl;
840
-	    //cout << Ix2[labeldata.type[it] ][i] << "\t" << labeldata.Ix2old[it][iexc] << "\t" << labeldata.Ix2exc[it][iexc] << endl;
841 695
 	    Ix2[labeldata.type[it] ][i] = labeldata.Ix2exc[it][iexc];
842
-	    //cout << Ix2[labeldata.type[it] ][i] << "\t" << labeldata.Ix2old[it][iexc] << "\t" << labeldata.Ix2exc[it][iexc] << endl;
843 696
 	  }
844 697
 
845
-    //cout << "State obtained(1): " << (*this) << endl;
846
-
847 698
     // Now reorder the Ix2 to follow convention:
848 699
     for (int il = 0; il < Ix2.size(); ++il) Ix2[il].QuickSort();
849
-
850
-    //cout << "Setting label:" << label_ref << endl << "Ix2old = " << labeldata.Ix2old[0] << endl << "Ix2exc = " << labeldata.Ix2exc[0] << endl;
851
-    //cout << "on " << OriginStateIx2ordered << endl << "giving " << Ix2 << endl;
852
-
853
-    //cout << "State obtained(2): " << (*this) << endl;
854
-    //char a; cin >> a;
855
-
856
-    //(*this).Set_Label_from_Ix2 (OriginStateIx2ordered);
857
-    //(*this).Set_Label_Internals_from_Ix2 (OriginStateIx2ordered);
858 700
   }
859 701
 
860 702
   void Heis_Bethe_State::Set_Label_from_Ix2 (const Vect<Vect<int> >& OriginIx2)
@@ -865,11 +707,13 @@ namespace ABACUS {
865 707
     // (*this) has a base already identical to base of OriginIx2
866 708
 
867 709
     // First check that bases are consistent
868
-    if ((*this).chain.Nstrings != OriginIx2.size()) ABACUSerror("Inconsistent base sizes in Heis_Bethe_State::Set_Label_from_Ix2.");
710
+    if ((*this).chain.Nstrings != OriginIx2.size())
711
+      ABACUSerror("Inconsistent base sizes in Heis_Bethe_State::Set_Label_from_Ix2.");
869 712
 
870 713
     // Then check that the filling at each level is equal
871 714
     for (int il = 0; il < (*this).chain.Nstrings; ++il)
872
-      if ((*this).base.Nrap[il] != OriginIx2[il].size()) ABACUSerror("Inconsistent base filling in Heis_Bethe_State::Set_Label_from_Ix2.");
715
+      if ((*this).base.Nrap[il] != OriginIx2[il].size())
716
+	ABACUSerror("Inconsistent base filling in Heis_Bethe_State::Set_Label_from_Ix2.");
873 717
 
874 718
     // Determine how many types of particles are present
875 719
     int ntypes = 1; // level 0 always assumed present
@@ -891,7 +735,6 @@ namespace ABACUS {
891 735
     Vect<Vect<int> > Ix2exc_ref(ntypes);
892 736
 
893 737
     // Count nr of particle-holes at each level:
894
-    //itype = 0;
895 738
     itype = -1;
896 739
     for (int il = 0; il < chain.Nstrings; ++il) {
897 740
       if (il == 0 || base.Nrap[il] > 0) {
@@ -932,36 +775,16 @@ namespace ABACUS {
932 775
     bool symmetric_state = true;
933 776
     int arg, test1, test3;
934 777
 
935
-    //if (chain.Delta <= 1.0) {
936
-
937
-      for (int j = 0; j < chain.Nstrings; ++j) {
938
-	test1 = 0;
939
-	test3 = 0;
940
-	for (int alpha = 0; alpha < base[j]; ++alpha) {
941
-	  arg = (Ix2[j][alpha] != chain.Nsites) ? Ix2[j][alpha] : 0;  // since Ix2 = N is same as Ix2 = -N by periodicity, this is symmetric.
942
-	  test1 += arg;
943
-	  test3 += arg * arg * arg;  // to make sure that all I's are symmetrical...
944
-	}
945
-	if (!(symmetric_state && (test1 == 0) && (test3 == 0))) symmetric_state = false;
946
-      }
947
-      //}
948
-      /*
949
-    else if (chain.Delta > 1.0) {
950
-      // For the gapped antiferromagnet, we check symmetry *excluding* the Ix2_max values
951
-      // The state is then inadmissible is symmetric && -Ix2_max occupied
952
-      for (int j = 0; j < chain.Nstrings; ++j) {
953
-	test1 = 0;
954
-	test3 = 0;
955
-	for (int alpha = 0; alpha < base[j]; ++alpha) {
956
-	  arg = (Ix2[j][alpha] != chain.Nsites
957
-		 && abs(Ix2[j][alpha]) != base.Ix2_max[j]) ? Ix2[j][alpha] : 0;  // since Ix2 = N is same as Ix2 = -N by periodicity, this is symmetric.
958
-	  test1 += arg;
959
-	  test3 += arg * arg * arg;  // to make sure that all I's are symmetrical...
960
-	}
961
-	if (!(symmetric_state && (test1 == 0) && (test3 == 0))) symmetric_state = false;
778
+    for (int j = 0; j < chain.Nstrings; ++j) {
779
+      test1 = 0;
780
+      test3 = 0;
781
+      for (int alpha = 0; alpha < base[j]; ++alpha) {
782
+	arg = (Ix2[j][alpha] != chain.Nsites) ? Ix2[j][alpha] : 0;  // since Ix2 = N is same as Ix2 = -N by periodicity, this is symmetric.
783
+	test1 += arg;
784
+	test3 += arg * arg * arg;  // to make sure that all I's are symmetrical...
962 785
       }
786
+      if (!(symmetric_state && (test1 == 0) && (test3 == 0))) symmetric_state = false;
963 787
     }
964
-      */
965 788
 
966 789
     return symmetric_state;
967 790
   }
@@ -991,8 +814,6 @@ namespace ABACUS {
991 814
   {
992 815
     // This function finds the rapidities of the eigenstate
993 816
 
994
-    //cout << endl << "Find_Rapidities called: " << (*this) << endl;
995
-
996 817
     lnnorm = -100.0;  // sentinel value, recalculated if Newton method used in the last step of iteration.
997 818
 
998 819
     Lambda lambda_ref(chain, base);
@@ -1001,10 +822,7 @@ namespace ABACUS {
1001 822
 
1002 823
     if (reset_rapidities)
1003 824
       (*this).Set_Free_lambdas();
1004
-    //cout << endl << "After Set_Free_lambdas: " << (*this) << endl;
1005 825
     (*this).Compute_BE();
1006
-    //cout << endl << "After Compute_BE: " << (*this) << endl;
1007
-
1008 826
 
1009 827
     iter = 0;
1010 828
     iter_Newton = 0;
@@ -1037,7 +855,6 @@ namespace ABACUS {
1037 855
 				   || straight_improving || extrap_improving || Newton_improving)) {
1038 856
 
1039 857
       // If we haven't reset, first try a few Newton steps...
1040
-      //if (!reset_rapidities && iter_Newton == 0) (*this).Solve_BAE_Newton (chain.prec, 10);
1041 858
 
1042 859
       if (!Newton_improving) diffsq_iter_aim *= 1.0e-5;
1043 860
 
@@ -1060,9 +877,9 @@ namespace ABACUS {
1060 877
 
1061 878
 	iter_prec = diffsq * 0.1;
1062 879
 
1063
-	if (info_findrap) cout << "Straight iter:  iter " << iter << "\titer_factor " << iter_factor << "\tdiffsq " << diffsq << endl;
880
+	if (info_findrap) cout << "Straight iter:  iter " << iter << "\titer_factor " << iter_factor
881
+			       << "\tdiffsq " << diffsq << endl;
1064 882
 
1065
-	//} while (diffsq > chain.prec && !is_nan(diffsq) && diffsq_extrap_stop/diffsq_extrap_start < 0.01);
1066 883
       } while (diffsq > diffsq_iter_aim && !is_nan(diffsq) && diffsq_extrap_stop/diffsq_extrap_start < 0.01);
1067 884
 
1068 885
       straight_improving = (diffsq < diffsq_start);
@@ -1115,10 +932,6 @@ namespace ABACUS {
1115 932
 
1116 933
       Newton_improving = (diffsq < diffsq_Newton_start);
1117 934
 
1118
-      //if (diffsq > iter_prec) (*this).Solve_BAE_smackdown (0.1 * diffsq, 1);
1119
-
1120
-      //cout << "Before silk:  diffsq = " << diffsq << endl;
1121
-
1122 935
       // If none of the methods are improving the result, try the silk gloves...
1123 936
       if (!(straight_improving || extrap_improving || Newton_improving)) {
1124 937
 	if (info_findrap) cout << "Before silk gloves: diffsq " << diffsq << endl;
@@ -1138,14 +951,9 @@ namespace ABACUS {
1138 951
 
1139 952
     // Check convergence:
1140 953
 
1141
-    //cout << "Check_Rapidities: " << (*this).Check_Rapidities() << endl;
1142
-
1143
-    //conv = (diffsq < chain.prec && (*this).Check_Rapidities() && ((*this).String_delta() < HEIS_deltaprec)) ? 1 : 0;
1144 954
     conv = (diffsq < chain.prec && (*this).Check_Rapidities()) ? 1 : 0;
1145 955
     dev = (*this).String_delta();
1146 956
 
1147
-    //cout << "String delta: " << (*this).String_delta() << "\tBoolean: " << ((*this).String_delta() < HEIS_deltaprec) << endl;
1148
-
1149 957
     return;
1150 958
   }
1151 959
 
@@ -1167,7 +975,6 @@ namespace ABACUS {
1167 975
     DP BEleft, BEmid, BEright;
1168 976
     lambda[j][alpha] = lambdaleft;
1169 977
     (*this).Compute_BE (j, alpha);
1170
-    //cout << "lambda: " << lambda[j][alpha] << "\ttanhlambda: " << tanh(lambda[j][alpha]) << endl;
1171 978
     BEleft= BE[j][alpha];
1172 979
     lambda[j][alpha] = lambdaright;
1173 980
     (*this).Compute_BE (j, alpha);
@@ -1175,8 +982,6 @@ namespace ABACUS {
1175 982
 
1176 983
     if (BEleft * BEright > 0.0) {
1177 984
       lambda[j][alpha] = lambdajalphastart;
1178
-      //cout << lambdaleft << "\t" << lambdaright << "\t" << BEleft << "\t" << BEright << endl;
1179
-      //cout << "Could not bisect BE[" << j << "][" << alpha << "]" << endl;
1180 985
       return;
1181 986
     }
1182 987
 
@@ -1187,9 +992,6 @@ namespace ABACUS {
1187 992
       (*this).Compute_BE (j, alpha);
1188 993
       BEmid = BE[j][alpha];
1189 994
 
1190
-      //cout << "niter_here = " << niter_here << "\t" << lambdaleft << "\t" << lambdamid << "\t" << lambdaright << endl;
1191
-      //cout << BEleft << "\t" << BEmid << "\t" << BEright << endl;
1192
-
1193 995
       if (BEmid * BEleft < 0.0) { // root is to the left of mid
1194 996
 	lambdaright = lambdamid;
1195 997
 	BEright = BEmid;
@@ -1203,16 +1005,12 @@ namespace ABACUS {
1203 1005
       else if (BEmid * BEmid < req_prec) return;
1204 1006
 
1205 1007
       else {
1206
-	//cout << lambdaleft << "\t" << lambdamid << "\t" << lambdaright << endl;
1207
-	//cout << BEleft << "\t" << BEmid << "\t" << BEright << endl;
1208
-	//ABACUSerror("Problem in Solve_BAE_bisect.");
1209 1008
 	return; // this procedure has failed
1210 1009
       }
1211 1010
 
1212 1011
       prec_obtained = BEmid * BEmid;
1213 1012
       niter_here++;
1214 1013
 
1215
-      //cout << "bisect: " << lambdaleft << "\t" << lambdaright << "\t" << BEleft << "\t" << BEright << "\t" << prec_obtained << "\t" << req_prec << endl;
1216 1014
     }
1217 1015
 
1218 1016
     return;
@@ -1220,15 +1018,10 @@ namespace ABACUS {
1220 1018
 
1221 1019
   void Heis_Bethe_State::Iterate_BAE (DP iter_factor)
1222 1020
   {
1223
-    //DP lambda_old;
1224 1021
     for (int j = 0; j < chain.Nstrings; ++j) {
1225 1022
       for (int alpha = 0; alpha < base[j]; ++alpha)
1226 1023
 	{
1227
-	  //lambda_old = lambda[j][alpha];
1228
-	  //lambda[j][alpha] = Iterate_BAE (j, alpha);
1229 1024
 	  lambda[j][alpha] += iter_factor * (Iterate_BAE (j, alpha) - lambda[j][alpha]);
1230
-	  //cout << j << "\t" << alpha << "\t" << Ix2[j][alpha] << "\t" << lambda_old << "\t" << lambda[j][alpha] << "\t";
1231
-	  //if (j > 0) cout << j << "\t" << alpha << "\t" << Ix2[j][alpha] << "\t" << lambda_old << "\t" << lambda[j][alpha] << endl;
1232 1025
 	}
1233 1026
     }
1234 1027
 
@@ -1247,7 +1040,8 @@ namespace ABACUS {
1247 1040
     Lambda lambda_ref(chain, base);
1248 1041
     DP diffsq_ref = 1.0;
1249 1042
 
1250
-    for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1043
+    for (int j = 0; j < chain.Nstrings; ++j)
1044
+      for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1251 1045
     diffsq_ref = diffsq;
1252 1046
 
1253 1047
     // Now begin solving...
@@ -1257,16 +1051,14 @@ namespace ABACUS {
1257 1051
 
1258 1052
     while ((diffsq > straight_prec) && (max_iter > iter_done_here)) {
1259 1053
 
1260
-      //cout << "BEFORE ITERATION" << endl << (*this) << endl << endl;
1261 1054
       (*this).Iterate_BAE(iter_factor);
1262
-      //cout << "ITERATION " << iter_done_here << endl << (*this) << endl << endl;
1263 1055
       iter_done_here++;
1264 1056
     }
1265 1057
 
1266 1058
     if ((diffsq > diffsq_ref) || (is_nan(diffsq))) {
1267 1059
       // This procedure has failed.  We reset everything to begin values.
1268
-      //cout << "Straight iter failed: resetting." << endl;
1269
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
1060
+      for (int j = 0; j < chain.Nstrings; ++j)
1061
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
1270 1062
       (*this).Compute_BE();
1271 1063
       diffsq = diffsq_ref;
1272 1064
     }
@@ -1281,7 +1073,8 @@ namespace ABACUS {
1281 1073
     Lambda lambda_ref(chain, base);
1282 1074
     DP diffsq_ref = 1.0;
1283 1075
 
1284
-    for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1076
+    for (int j = 0; j < chain.Nstrings; ++j)
1077
+      for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1285 1078
     diffsq_ref = diffsq;
1286 1079
 
1287 1080
     // Now begin solving...
@@ -1300,20 +1093,21 @@ namespace ABACUS {
1300 1093
     while ((diffsq > extrap_prec) && (max_iter_extrap > iter_done_here)) {
1301 1094
 
1302 1095
       (*this).Iterate_BAE(iter_factor);
1303
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda1[j][alpha] = lambda[j][alpha];
1096
+      for (int j = 0; j < chain.Nstrings; ++j)
1097
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda1[j][alpha] = lambda[j][alpha];
1304 1098
       diffsq1 = diffsq;
1305 1099
       (*this).Iterate_BAE(iter_factor);
1306
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda2[j][alpha] = lambda[j][alpha];
1100
+      for (int j = 0; j < chain.Nstrings; ++j)
1101
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda2[j][alpha] = lambda[j][alpha];
1307 1102
       diffsq2 = diffsq;
1308 1103
       (*this).Iterate_BAE(iter_factor);
1309
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda3[j][alpha] = lambda[j][alpha];
1104
+      for (int j = 0; j < chain.Nstrings; ++j)
1105
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda3[j][alpha] = lambda[j][alpha];
1310 1106
       diffsq3 = diffsq;
1311 1107
       (*this).Iterate_BAE(iter_factor);
1312
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda4[j][alpha] = lambda[j][alpha];
1108
+      for (int j = 0; j < chain.Nstrings; ++j)
1109
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda4[j][alpha] = lambda[j][alpha];
1313 1110
       diffsq4 = diffsq;
1314
-      //(*this).Iterate_BAE(iter_factor);
1315
-      //for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda5[j][alpha] = lambda[j][alpha];
1316
-      //diffsq5 = diffsq;
1317 1111
 
1318 1112
       iter_done_here += 4;
1319 1113
 
@@ -1332,11 +1126,8 @@ namespace ABACUS {
1332 1126
 	    rap[1] = lambda2[j][alpha];
1333 1127
 	    rap[2] = lambda3[j][alpha];
1334 1128
 	    rap[3] = lambda4[j][alpha];
1335
-	    //rap[4] = lambda5[j][alpha];
1336 1129
 
1337 1130
 	    polint (oneoverP, rap, 0.0, lambda[j][alpha], deltalambda);
1338
-
1339
-	    //cout << j << "\t" << alpha << "\t" << rap << "\t" << lambda[j][alpha] << "\t" << deltalambda << endl;
1340 1131
 	  }
1341 1132
 
1342 1133
 	// Iterate once to stabilize result
@@ -1347,7 +1138,8 @@ namespace ABACUS {
1347 1138
 
1348 1139
     if ((diffsq >= diffsq_ref) || (is_nan(diffsq))) {
1349 1140
       // This procedure has failed.  We reset everything to begin values.
1350
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
1141
+      for (int j = 0; j < chain.Nstrings; ++j)
1142
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
1351 1143
       (*this).Compute_BE();
1352 1144
       diffsq = diffsq_ref;
1353 1145
     }
@@ -1365,7 +1157,8 @@ namespace ABACUS {
1365 1157
     Lambda lambda_ref(chain, base);
1366 1158
     DP diffsq_ref = 1.0;
1367 1159
 
1368
-    for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1160
+    for (int j = 0; j < chain.Nstrings; ++j)
1161
+      for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1369 1162
     diffsq_ref = diffsq;
1370 1163
 
1371 1164
     // Now begin solving...
@@ -1389,35 +1182,13 @@ namespace ABACUS {
1389 1182
 	  }
1390 1183
 	}
1391 1184
 
1392
-      //cout << "jmax = " << jmax << "\talphamax = " << alphamax << "\t" << lambda[jmax][alphamax] << "\tBE before " << BE[jmax][alphamax] << endl;
1393
-      // Now recalculate this max deviant rapidity,
1394
-      //cout <<  lambda[jmax][alphamax] << "\t" << Iterate_BAE (jmax, alphamax) << endl;
1395
-
1396
-      /*
1397
-      DP dlambda = 0.0;
1398
-      DP prevBEmax = 0.0;
1399
-      do {
1400
-	dlambda = Iterate_BAE (jmax, alphamax) - lambda[jmax][alphamax];
1401
-	lambda[jmax][alphamax] += iter_factor * dlambda;
1402
-	prevBEmax = BE[jmax][alphamax];
1403
-	(*this).Compute_BE();
1404
-	iter_done_here++;
1405
-	cout << "jmax = " << jmax << "\talphamax = " << alphamax << "\t" << lambda[jmax][alphamax] << "\t" << dlambda << "\tBE during " << BE[jmax][alphamax] << endl;
1406
-      } while (dlambda * dlambda > silk_prec && fabs(BE[jmax][alphamax]) < fabs(prevBEmax) && max_iter_silk > iter_done_here);
1407
-
1408
-      */
1409
-
1410 1185
       Solve_BAE_bisect (jmax, alphamax, silk_prec, max_iter_silk);
1411 1186
       iter_done_here++;
1412 1187
 
1413
-      //cout << "jmax = " << jmax << "\talphamax = " << alphamax << "\t" << lambda[jmax][alphamax] << "\tBE after " << BE[jmax][alphamax] << endl;
1414
-
1415 1188
       // and reset all important arrays.
1416 1189
       (*this).Compute_diffsq();
1417 1190
     }
1418 1191
 
1419
-    //cout << "Silk gloves: diffsq from " << diffsq_ref << "\tto " << diffsq << endl;
1420
-
1421 1192
     if ((diffsq > diffsq_ref) || (is_nan(diffsq))) {
1422 1193
       // This procedure has failed.  We reset everything to begin values.
1423 1194
       for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
@@ -1428,32 +1199,6 @@ namespace ABACUS {
1428 1199
     return;
1429 1200
   }
1430 1201
 
1431
-  /*
1432
-  void Heis_Bethe_State::BAE_smackdown (DP max_allowed)
1433
-  {
1434
-    // Re-solves for all rapidities lambda[j][alpha] such that BE[j][alpha]^2/N > max_allowed.
1435
-    // Assumes that BE[][] is up-to-date.
1436
-
1437
-    for (int j = 0; j < chain.Nstrings; ++j)
1438
-      for (int alpha = 0; alpha < base[j]; ++alpha)
1439
-	if (pow(BE[j][alpha], 2.0)/chain.Nsites > max_allowed) (*this).Solve_BAE (j, alpha, max_allowed, 100);
1440
-  }
1441
-
1442
-  void Heis_Bethe_State::Solve_BAE_smackdown (DP max_allowed, int maxruns)
1443
-  {
1444
-    int runs_done = 0;
1445
-
1446
-    (*this).Compute_BE();
1447
-    (*this).Compute_diffsq();
1448
-
1449
-    while (diffsq > chain.prec && diffsq > max_allowed && runs_done < maxruns) {
1450
-      (*this).BAE_smackdown (max_allowed);
1451
-      (*this).Compute_BE();
1452
-      (*this).Compute_diffsq();
1453
-      runs_done++;
1454
-    }
1455
-  }
1456
-  */
1457 1202
 
1458 1203
   void Heis_Bethe_State::Iterate_BAE_Newton ()
1459 1204
   {
@@ -1465,7 +1210,8 @@ namespace ABACUS {
1465 1210
     Vect_INT indx (base.Nraptot);
1466 1211
 
1467 1212
     Lambda lambda_ref(chain, base);
1468
-    for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1213
+    for (int j = 0; j < chain.Nstrings; ++j)
1214
+      for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1469 1215
 
1470 1216
     (*this).Build_Reduced_Gaudin_Matrix (Gaudin);
1471 1217
 
@@ -1488,16 +1234,14 @@ namespace ABACUS {
1488 1234
       return;
1489 1235
     }
1490 1236
 
1491
-    //cout << iter_Newton << "\t" << dlambda << endl;
1492
-
1493 1237
     // Regularize dlambda:  max step is +-1.0 to prevent rapidity flying off into outer space.
1494
-    for (int i = 0; i < base.Nraptot; ++i) if (fabs(real(dlambda[i])) > 1.0) dlambda[i] = 0.0;//(real(dlambda[i]) > 0) ? 1.0 : -1.0;
1238
+    for (int i = 0; i < base.Nraptot; ++i)
1239
+      if (fabs(real(dlambda[i])) > 1.0) dlambda[i] = 0.0;//(real(dlambda[i]) > 0) ? 1.0 : -1.0;
1495 1240
 
1496 1241
     index = 0;
1497 1242
     for (int j = 0; j < chain.Nstrings; ++j)
1498 1243
       for (int alpha = 0; alpha < base[j]; ++alpha) {
1499 1244
 	lambda[j][alpha] = lambda_ref[j][alpha] + real(dlambda[index]);
1500
-	//cout << j << "\t" << alpha << "\t" << dlambda[index] << "\t" << lambda_ref[j][alpha] << "\t" << lambda[j][alpha] << endl;
1501 1245
 	index++;
1502 1246
       }
1503 1247
 
@@ -1521,12 +1265,14 @@ namespace ABACUS {
1521 1265
   {
1522 1266
     // This function attempts to get convergence diffsq <= Newton_prec in at most max_iter_Newton steps.
1523 1267
 
1524
-    // The results are accepted if diffsq has decreased, otherwise the lambda's are reset to original values, defined as...
1268
+    // The results are accepted if diffsq has decreased,
1269
+    // otherwise the lambda's are reset to original values, defined as...
1525 1270
 
1526 1271
     Lambda lambda_ref(chain, base);
1527 1272
     DP diffsq_ref = 1.0;
1528 1273
 
1529
-    for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1274
+    for (int j = 0; j < chain.Nstrings; ++j)
1275
+      for (int alpha = 0; alpha < base[j]; ++alpha) lambda_ref[j][alpha] = lambda[j][alpha];
1530 1276
     diffsq_ref = diffsq;
1531 1277
 
1532 1278
     // Now begin solving...
@@ -1541,8 +1287,8 @@ namespace ABACUS {
1541 1287
 
1542 1288
     if ((diffsq > diffsq_ref) || (is_nan(diffsq))) {
1543 1289
       // This procedure has failed.  We reset everything to begin values.
1544
-      //cout << "Newton: failed, resetting." << "\t" << diffsq << endl;
1545
-      for (int j = 0; j < chain.Nstrings; ++j) for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
1290
+      for (int j = 0; j < chain.Nstrings; ++j)
1291
+	for (int alpha = 0; alpha < base[j]; ++alpha) lambda[j][alpha] = lambda_ref[j][alpha];
1546 1292
       (*this).Compute_BE();
1547 1293
       diffsq = diffsq_ref;
1548 1294
     }
@@ -1558,19 +1304,8 @@ namespace ABACUS {
1558 1304
       SQMat_CX Gaudin_Red(base.Nraptot);
1559 1305
 
1560 1306
       (*this).Build_Reduced_Gaudin_Matrix(Gaudin_Red);
1561
-      /*
1562
-      cout << endl << "Gaudin matrix: " << endl;
1563
-
1564
-      for (int j = 0; j < Gaudin_Red.size(); ++j) {
1565
-	for (int k = 0; k < Gaudin_Red.size(); ++k) cout << Gaudin_Red[j][k] << "  ";
1566
-	cout << endl;
1567
-      }
1568
-      cout << endl << endl;
1569
-      */
1570 1307
       complex<DP> lnnorm_check = lndet_LU_CX_dstry(Gaudin_Red);
1571
-      //cout << "Calculated lnnorm = " << lnnorm_check;
1572 1308
 
1573
-      //lnnorm = real(lndet_LU_CX_dstry(Gaudin_Red));
1574 1309
       lnnorm = real(lnnorm_check);
1575 1310
     }
1576 1311
 
@@ -1613,37 +1348,15 @@ namespace ABACUS {
1613 1348
     return;
1614 1349
   }
1615 1350
 
1616
-  /*
1617
-  bool Heis_Bethe_State::Boost_Momentum (int iKboost)
1618
-  {
1619
-    if (iKboost == 0) return(true);  // done
1620
-
1621
-    Ix2_Offsets offsets_here = offsets;
1622
-
1623
-    bool success = false;
1624
-
1625
-    if (iKboost < 0)
1626
-      success = offsets_here.Add_Boxes_From_Lowest(-iKboost, 0);  // add boxes in even sectors to decrease iK
1627
-
1628
-    else if (iKboost > 0)
1629
-      success = offsets_here.Add_Boxes_From_Lowest(iKboost, 1);  // add boxes in odd sectors to increase iK
1630
-
1631
-    if (success) (*this).Set_Ix2_Offsets(offsets_here);
1632
-
1633
-    return(success);
1634
-  }
1635
-  */
1636
-
1637 1351
 
1638 1352
   void Heis_Bethe_State::Set_to_Closest_Matching_Ix2_fixed_Base (const Heis_Bethe_State& StateToMatch)
1639 1353
   {
1640 1354
     // Given a state with given Ix2 distribution, set the Ix2 to closest match.
1641 1355
     // The base of (*this) is fixed, and does not necessarily match that of StateToMatch.
1642 1356
 
1643
-    //cout << "Matching Ix2 for base " << (*this).base.baselabel << " from base " << StateToMatch.base.baselabel << endl;
1644
-
1645 1357
     if ((*this).chain != StateToMatch.chain)
1646
-      ABACUSerror("Heis_Bethe_State::Find_Closest_Matching_Ix2_fixed_Base: trying to match Ix2 for two states with different chains.");
1358
+      ABACUSerror("Heis_Bethe_State::Find_Closest_Matching_Ix2_fixed_Base: "
1359
+		  "trying to match Ix2 for two states with different chains.");
1647 1360
 
1648 1361
     // Check level by level, match quantum numbers from center up.
1649 1362
     for (int il = 0; il < chain.Nstrings; ++il) {
@@ -1663,15 +1376,16 @@ namespace ABACUS {
1663 1376
 	  (*this).Ix2[il][a] = -(*this).base.Nrap[il] + 1 + 2*a;
1664 1377
 	int nleft = StateToMatch.base.Nrap[il]/2;
1665 1378
 	for (int a = 0; a < nleft; ++a)
1666
-	  if (StateToMatch.Ix2[il][a] - Ix2shift < (*this).Ix2[il][a]) (*this).Ix2[il][a] = StateToMatch.Ix2[il][a] - Ix2shift;
1379
+	  if (StateToMatch.Ix2[il][a] - Ix2shift < (*this).Ix2[il][a])
1380
+	    (*this).Ix2[il][a] = StateToMatch.Ix2[il][a] - Ix2shift;
1667 1381
 	for (int a = 0; a < StateToMatch.base.Nrap[il] - 1 - nleft; ++a)
1668
-	  if (StateToMatch.Ix2[il][StateToMatch.base.Nrap[il] - 1 - a] - Ix2shift > (*this).Ix2[il][(*this).base.Nrap[il] - 1 - a])
1669
-	    (*this).Ix2[il][(*this).base.Nrap[il] - 1 - a] = StateToMatch.Ix2[il][StateToMatch.base.Nrap[il] - 1 - a] - Ix2shift;
1382
+	  if (StateToMatch.Ix2[il][StateToMatch.base.Nrap[il] - 1 - a] - Ix2shift
1383
+	      > (*this).Ix2[il][(*this).base.Nrap[il] - 1 - a])
1384
+	    (*this).Ix2[il][(*this).base.Nrap[il] - 1 - a] = (StateToMatch.Ix2[il][StateToMatch.base.Nrap[il] - 1 - a]
1385
+							      - Ix2shift);
1670 1386
       }
1671 1387
     } // for il
1672 1388
 
1673
-    //cout << "StateToMatch:" << endl << StateToMatch << endl << "MatchingState:" << endl << (*this) << endl;
1674
-
1675 1389
   }
1676 1390
 
1677 1391
 
@@ -1679,16 +1393,19 @@ namespace ABACUS {
1679 1393
   {
1680 1394
     // sends all the state data to output stream
1681 1395
 
1682
-    s << endl << "******** Chain with Delta = " << state.chain.Delta << " Nsites = " << state.chain.Nsites << " Mdown = " << state.base.Mdown
1683
-      //<< ":  eigenstate with base_id " << state.base_id << ", type_id " << state.type_id << " id " << state.id << " maxid " << state.maxid << endl
1396
+    s << endl << "******** Chain with Delta = " << state.chain.Delta
1397
+      << " Nsites = " << state.chain.Nsites << " Mdown = " << state.base.Mdown
1684 1398
       << ":  eigenstate with label " << state.label << endl
1685 1399
       << "E = " << state.E << " K = " << state.K << " iK = " << state.iK << " lnnorm = " << state.lnnorm << endl
1686
-      << "conv = " << state.conv << " dev = " << state.dev << " iter = " << state.iter << " iter_Newton = " << state.iter_Newton << "\tdiffsq " << state.diffsq << endl;
1400
+      << "conv = " << state.conv << " dev = " << state.dev << " iter = " << state.iter
1401
+      << " iter_Newton = " << state.iter_Newton << "\tdiffsq " << state.diffsq << endl;
1687 1402
 
1688 1403
     for (int j = 0; j < state.chain.Nstrings; ++j) {
1689 1404
       if (state.base.Nrap[j] > 0) {
1690
-	s << "Type " << j << " Str_L = " << state.chain.Str_L[j] << " par = " << state.chain.par[j] << " M_j = " << state.base.Nrap[j]
1691
-	  << " Ix2_infty = " << state.base.Ix2_infty[j] << " Ix2_min = " << state.base.Ix2_min[j] << " Ix2_max = " << state.base.Ix2_max[j] << endl;
1405
+	s << "Type " << j << " Str_L = " << state.chain.Str_L[j] << " par = " << state.chain.par[j]
1406
+	  << " M_j = " << state.base.Nrap[j]
1407
+	  << " Ix2_infty = " << state.base.Ix2_infty[j] << " Ix2_min = " << state.base.Ix2_min[j]
1408
+	  << " Ix2_max = " << state.base.Ix2_max[j] << endl;
1692 1409
 	Vect_INT qnumbers(state.base.Nrap[j]);
1693 1410
 	Vect_DP rapidities(state.base.Nrap[j]);
1694 1411
 	for (int alpha = 0; alpha < state.base.Nrap[j]; ++alpha) {

+ 2
- 5
src/HEIS/Heis_Chem_Pot.cc View File

@@ -125,19 +125,16 @@ namespace ABACUS {
125 125
 	HZmax_actual = HZmin (Delta, N, M_actual - 1, Ezero);
126 126
 
127 127
 	M_found = (HZmin_actual < HZ && HZ <= HZmax_actual);
128
-
129
-	//cout << "M_actual = " << M_actual << "\tM_step = " << M_step
130
-	//   << "\tHZmin_actual = " << HZmin_actual << "\tHZmax_actual = " << HZmax_actual << "\tHZ = " << HZ << "\t" << M_found << endl;
131 128
       }
132 129
     }
133
-    //cout << "M found = " << M_actual << "\tHZmax = " << Ezero[M_actual] - Ezero[M_actual + 1] << "\tHZmin = " << Ezero[M_actual - 1] - Ezero[M_actual] << endl;
134 130
 
135 131
     return(M_actual);
136 132
   }
137 133
 
138 134
   DP Chemical_Potential (const Heis_Bethe_State& AveragingState)
139 135
   {
140
-    return(-H_vs_M (AveragingState.chain.Delta, AveragingState.chain.Nsites, AveragingState.base.Mdown));  // - sign since E_{M+1} - E_M = -H
136
+    return(-H_vs_M (AveragingState.chain.Delta, AveragingState.chain.Nsites, AveragingState.base.Mdown));
137
+    // - sign since E_{M+1} - E_M = -H
141 138
   }
142 139
 
143 140
 }

+ 31
- 114
src/HEIS/Heis_Matrix_Element_Contrib.cc View File

@@ -19,10 +19,6 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-  //DP Compute_Matrix_Element_Contrib (char whichDSF, bool fixed_iK, XXZ_Bethe_State& LeftState,
23
-				     //XXZ_Bethe_State& RightState, DP Chem_Pot, fstream& DAT_outfile)
24
-  //DP Compute_Matrix_Element_Contrib (char whichDSF, int iKmin, int iKmax, XXZ_Bethe_State& LeftState,
25
-  //				     XXZ_Bethe_State& RightState, DP Chem_Pot, fstream& DAT_outfile)
26 22
   DP Compute_Matrix_Element_Contrib (char whichDSF, int iKmin, int iKmax, XXZ_Bethe_State& LeftState,
27 23
 				     XXZ_Bethe_State& RightState, DP Chem_Pot, stringstream& DAT_outfile)
28 24
   {
@@ -43,7 +39,6 @@ namespace ABACUS {
43 39
       ME = exp(real(ln_Smin_ME (RightState, LeftState)));
44 40
     else if (whichDSF == 'z') {
45 41
       if (LeftState.label == RightState.label)
46
-	//MEsq = RightState.chain.Nsites * 0.25 * pow((1.0 - 2.0*RightState.base.Mdown/RightState.chain.Nsites), 2.0);
47 42
 	ME = sqrt(RightState.chain.Nsites * 0.25) * (1.0 - 2.0*RightState.base.Mdown/RightState.chain.Nsites);
48 43
       else ME = exp(real(ln_Sz_ME (RightState, LeftState)));
49 44
     }
@@ -53,8 +48,6 @@ namespace ABACUS {
53 48
 
54 49
     if (is_nan(ME)) ME = 0.0;
55 50
 
56
-    //if (LeftState.dev > 1.0e-16 || RightState.dev > 1.0e-16) ME = 0.0; // kill deviated contributions
57
-
58 51
     // Do the momentum business:
59 52
     int iKout = LeftState.iK - RightState.iK;
60 53
     while(iKout < 0) iKout += RightState.chain.Nsites;
@@ -64,17 +57,17 @@ namespace ABACUS {
64 57
     // Print information to fstream:
65 58
     if (iKout >= iKmin && iKout <= iKmax) {
66 59
       if (whichDSF == 'Z') {
67
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
60
+	DAT_outfile << endl << setprecision(16)
61
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
68 62
 		    << iKout << "\t"
69
-	  //<< LeftState.conv << "\t"
70 63
 		    << setprecision(3) << LeftState.dev << "\t"
71 64
 		    << LeftState.label;
72 65
       }
73 66
       else {
74
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
67
+	DAT_outfile << endl << setprecision(16)
68
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
75 69
 		    << iKout << "\t"
76 70
 		    << ME << "\t"
77
-	  //<< LeftState.conv << "\t"
78 71
 		    << setprecision(3) << LeftState.dev << "\t"
79 72
 		    << LeftState.label;
80 73
       }
@@ -82,7 +75,6 @@ namespace ABACUS {
82 75
 
83 76
     // Calculate and return the data_value:
84 77
     DP data_value = ME * ME;
85
-    //DP data_value = (iKout == 0 ? 1.0 : 2.0) * MEsq;
86 78
 
87 79
     if (whichDSF == 'Z') // use 1/(1 + omega)
88 80
       data_value = 1.0/(1.0 + LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot);
@@ -92,10 +84,7 @@ namespace ABACUS {
92 84
     return(data_value);
93 85
   }
94 86
 
95
-  //DP Compute_Matrix_Element_Contrib (char whichDSF, bool fixed_iK, XXX_Bethe_State& LeftState,
96
-                          //XXX_Bethe_State& RightState, DP Chem_Pot, fstream& DAT_outfile)
97
-  //DP Compute_Matrix_Element_Contrib (char whichDSF, int iKmin, int iKmax, XXX_Bethe_State& LeftState,
98
-  //XXX_Bethe_State& RightState, DP Chem_Pot, fstream& DAT_outfile)
87
+
99 88
   DP Compute_Matrix_Element_Contrib (char whichDSF, int iKmin, int iKmax, XXX_Bethe_State& LeftState,
100 89
 				     XXX_Bethe_State& RightState, DP Chem_Pot, stringstream& DAT_outfile)
101 90
   {
@@ -120,30 +109,35 @@ namespace ABACUS {
120 109
       ME = exp(real(ln_Smin_ME (RightState, LeftState)));
121 110
     else if (whichDSF == 'z') {
122 111
       // Recognize the presence of an infinite rapidity:
123
-      if (LeftState.base.Mdown == RightState.base.Mdown - 1) { // infinite rapidity present, use rescaled S^- matrix element instead of S^z one:
112
+      if (LeftState.base.Mdown == RightState.base.Mdown - 1) {
113
+	// infinite rapidity present, use rescaled S^- matrix element instead of S^z one:
124 114
 	nrinfrap = 1;
125 115
 	// Correction factor for MEsq: Smffsq to Szffsq = 1/(N - 2M + 2)
126
-	ME = sqrt(1.0/(RightState.chain.Nsites - 2*RightState.base.Mdown + 2)) * exp(real(ln_Smin_ME (RightState, LeftState)));
116
+	ME = sqrt(1.0/(RightState.chain.Nsites - 2*RightState.base.Mdown + 2))
117
+	  * exp(real(ln_Smin_ME (RightState, LeftState)));
127 118
       }
128 119
       else { // no infinite rapidity, use S^z matrix element:
129 120
 	if (LeftState.label == RightState.label)
130
-	  //MEsq = RightState.chain.Nsites * 0.25 * pow((1.0 - 2.0*RightState.base.Mdown/RightState.chain.Nsites), 2.0);
131 121
 	  ME = sqrt(RightState.chain.Nsites * 0.25) * (1.0 - 2.0*RightState.base.Mdown/RightState.chain.Nsites);
132 122
 	else ME = exp(real(ln_Sz_ME (RightState, LeftState)));
133 123
       }
134 124
     }
135 125
     else if (whichDSF == 'p') {
136 126
       // Recognize the presence of two infinite rapidities:
137
-      if (LeftState.base.Mdown == RightState.base.Mdown - 1) { // two infinite rapidities, use rescaled S^- matrix element instead of S^+
127
+      if (LeftState.base.Mdown == RightState.base.Mdown - 1) {
128
+	// two infinite rapidities, use rescaled S^- matrix element instead of S^+
138 129
 	nrinfrap = 2;
139 130
 	// Correction factor for MEsq: Smffsq to Spffsq = 2/((N - 2M + 2) (N - 2M + 1))
140
-	ME = sqrt(2.0/((RightState.chain.Nsites - 2*RightState.base.Mdown + 2.0) * (RightState.chain.Nsites - 2*RightState.base.Mdown + 1.0)))
131
+	ME = sqrt(2.0/((RightState.chain.Nsites - 2*RightState.base.Mdown + 2.0)
132
+		       * (RightState.chain.Nsites - 2*RightState.base.Mdown + 1.0)))
141 133
 	  * exp(real(ln_Smin_ME (RightState, LeftState)));
142 134
       }
143
-      else if (LeftState.base.Mdown == RightState.base.Mdown) { // one infinite rapidity, use rescaled S^z matrix element instead of S^+
135
+      else if (LeftState.base.Mdown == RightState.base.Mdown) {
136
+	// one infinite rapidity, use rescaled S^z matrix element instead of S^+
144 137
 	nrinfrap = 1;
145 138
 	// Correction factor for MEsq: Szffsq to Spffsq = 4/(N - 2M)
146
-	ME = sqrt(4.0/(RightState.chain.Nsites - 2* RightState.base.Mdown)) * exp(real(ln_Sz_ME (RightState, LeftState)));
139
+	ME = sqrt(4.0/(RightState.chain.Nsites - 2* RightState.base.Mdown))
140
+	  * exp(real(ln_Sz_ME (RightState, LeftState)));
147 141
       }
148 142
       else ME = exp(real(ln_Smin_ME (LeftState, RightState)));
149 143
     }
@@ -154,17 +148,12 @@ namespace ABACUS {
154 148
     else if (whichDSF == 'c') // S^-_j S^-{j+1} operator
155 149
       ME = exp(real(ln_Smm_ME (RightState, LeftState)));
156 150
     else if (whichDSF == 'q') // Geometric quench
157
-      //ME_CX = ln_Overlap (LeftState, RightState);
158 151
       ME_CX = ln_Overlap (RightState, LeftState);
159 152
     else ABACUSerror("Wrong whichDSF in Compute_Matrix_Element_Contrib.");
160 153
 
161 154
     if (is_nan(ME)) ME = 0.0;
162 155
     if (is_nan(norm(ME_CX))) ME_CX = -100.0;
163 156
 
164
-    //if (LeftState.dev > 1.0e-16 || RightState.dev > 1.0e-16) {
165
-    //ME = 0.0; ME_CX = (0.0,0.0); // kill deviated contributions
166
-    //}
167
-
168 157
     // Do the momentum business:
169 158
     int iKout = LeftState.iK - RightState.iK;
170 159
     while(iKout < 0) iKout += RightState.chain.Nsites;
@@ -174,26 +163,26 @@ namespace ABACUS {
174 163
     // Print information to fstream:
175 164
     if (iKout >= iKmin && iKout <= iKmax) {
176 165
       if (whichDSF == 'Z') {
177
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown + nrinfrap - RightState.base.Mdown) * Chem_Pot << "\t"
178
-		    << iKout << "\t"
179
-	  //<< LeftState.conv << "\t"
166
+	DAT_outfile << endl << setprecision(16)
167
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown + nrinfrap - RightState.base.Mdown) * Chem_Pot
168
+		    << "\t" << iKout << "\t"
180 169
 		    << setprecision(3) << LeftState.dev << "\t"
181 170
 		    << LeftState.label;
182 171
       }
183 172
       else if (whichDSF == 'q') {
184
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown + nrinfrap - RightState.base.Mdown) * Chem_Pot << "\t"
185
-		    << iKout << "\t"
173
+	DAT_outfile << endl << setprecision(16)
174
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown + nrinfrap - RightState.base.Mdown) * Chem_Pot
175
+		    << "\t" << iKout << "\t"
186 176
 		    << real(ME_CX) << "\t" << imag(ME_CX) - twoPI * int(imag(ME_CX)/twoPI + 1.0e-10) << "\t"
187
-	  //<< LeftState.conv << "\t"
188 177
 		    << setprecision(3) << LeftState.dev << "\t"
189 178
 		    << LeftState.label;
190 179
       }
191 180
 
192 181
       else {
193
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown + nrinfrap - RightState.base.Mdown) * Chem_Pot << "\t"
194
-		    << iKout << "\t"
182
+	DAT_outfile << endl << setprecision(16)
183
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown + nrinfrap - RightState.base.Mdown) * Chem_Pot
184
+		    << "\t" << iKout << "\t"
195 185
 		    << ME << "\t"
196
-	  //<< LeftState.conv << "\t"
197 186
 		    << setprecision(3) << LeftState.dev << "\t"
198 187
 		    << LeftState.label;
199 188
       }
@@ -201,7 +190,6 @@ namespace ABACUS {
201 190
 
202 191
     // Calculate and return the data_value:
203 192
     DP data_value = ME * ME;
204
-    //DP data_value = (iKout == 0 ? 1.0 : 2.0) * MEsq;
205 193
     if (whichDSF == 'Z') // use 1/(1 + omega)
206 194
       data_value = 1.0/(1.0 + LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot);
207 195
     else if (whichDSF == 'q')
@@ -212,10 +200,7 @@ namespace ABACUS {
212 200
     return(data_value);
213 201
   }
214 202
 
215
-  //DP Compute_Matrix_Element_Contrib (char whichDSF, bool fixed_iK, XXZ_gpd_Bethe_State& LeftState,
216
-  //XXZ_gpd_Bethe_State& RightState, DP Chem_Pot, fstream& DAT_outfile)
217
-  //DP Compute_Matrix_Element_Contrib (char whichDSF, int iKmin, int iKmax, XXZ_gpd_Bethe_State& LeftState,
218
-  //				     XXZ_gpd_Bethe_State& RightState, DP Chem_Pot, fstream& DAT_outfile)
203
+
219 204
   DP Compute_Matrix_Element_Contrib (char whichDSF, int iKmin, int iKmax, XXZ_gpd_Bethe_State& LeftState,
220 205
 				     XXZ_gpd_Bethe_State& RightState, DP Chem_Pot, stringstream& DAT_outfile)
221 206
   {
@@ -223,16 +208,6 @@ namespace ABACUS {
223 208
     // and returns a weighed `data_value' to be multiplied by sumrule_factor,
224 209
     // to determine if scanning along this thread should be continued.
225 210
 
226
-    /*
227
-    cout << "\t" << LeftState.label << endl << "\t" << LeftState.Ix2 << endl;
228
-    cout << "\t0: ";
229
-    for (int i = 0; i < LeftState.base.Nrap[0]; ++i) cout << LeftState.lambda[0][i]*2.0/PI << "\t";
230
-    cout << endl;
231
-    cout << "\t1: ";
232
-    for (int i = 0; i < LeftState.base.Nrap[1]; ++i) cout << LeftState.lambda[1][i]*2.0/PI << "\t";
233
-    cout << endl;
234
-    */
235
-
236 211
     bool fixed_iK = (iKmin == iKmax);
237 212
 
238 213
 
@@ -240,52 +215,6 @@ namespace ABACUS {
240 215
     bool rap_in_fundamental = true;
241 216
     int sum1 = 0;
242 217
     for (int j = 0; j < LeftState.chain.Nstrings; ++j) {
243
-      //for (int alpha = 0; alpha < LeftState.base.Nrap[j]; ++alpha) {
244
-	//if (LeftState.lambda[j][alpha] <= -0.5*PI || LeftState.lambda[j][alpha] > 0.5*PI)
245
-	//if (LeftState.lambda[j][alpha] <= -0.5*PI || LeftState.lambda[j][alpha] > 0.5*PI)
246
-      //rap_in_fundamental = false;
247
-      //}
248
-
249
-      /*
250
-      // TEST 2014 06 26: comment this out, replace by -\pi/2 \leq \lambda \leq \pi/2, see below
251
-      if (LeftState.base.Nrap[j] > 0 && LeftState.lambda[j][LeftState.base.Nrap[j] - 1] - LeftState.lambda[j][0] >= PI)
252
-      rap_in_fundamental = false;
253
-
254
-      sum1 = 0;
255
-      for (int k = 0; k < LeftState.chain.Nstrings; ++k)
256
-	sum1 += LeftState.base.Nrap[k] * (2 * ABACUS::min(LeftState.chain.Str_L[j], LeftState.chain.Str_L[k]) - ((j == k) ? 1 : 0));
257
-      // This almost does it:  only missing are the states with one on -PI/2 and one on PI/2
258
-      if (LeftState.base.Nrap[j] >= 1
259
-	  && (LeftState.Ix2[j][0] <= -(LeftState.chain.Nsites - sum1)
260
-	      || (LeftState.Ix2[j][LeftState.base.Nrap[j] - 1] - LeftState.Ix2[j][0])
261
-	      > 2*(LeftState.chain.Nsites - sum1)))
262
-	rap_in_fundamental = false;
263
-      */
264
-
265
-      // attempt 2014 06 26
266
-      //for (int alpha = 0; alpha < LeftState.base.Nrap[j]; ++alpha) {
267
-      //if (LeftState.lambda[j][alpha] < -0.5*PI || LeftState.lambda[j][alpha] > 0.5*PI)
268
-      //  rap_in_fundamental = false;
269
-      //}
270
-      /*
271
-      if (LeftState.base.Nrap[j] > 0 &&
272
-	  ((LeftState.lambda[j][LeftState.base.Nrap[j] - 1] - LeftState.lambda[j][0] >= PI)
273
-	   || LeftState.lambda[j][0] < -0.5*PI + 1.0e-10
274
-	   || LeftState.lambda[j][LeftState.base.Nrap[j] - 1] > 0.5*PI
275
-	   //|| LeftState.lambda[j][0] > 0.5*PI
276
-	   //((LeftState.lambda[j][LeftState.base.Nrap[j] - 1] - LeftState.lambda[j][0] >= PI - 1.0e-10)
277
-	   //|| LeftState.lambda[j][0] < -0.5*PI + 1.0e-10
278
-	   //|| LeftState.lambda[j][LeftState.base.Nrap[j] - 1] > 0.5*PI + 1.0e-10
279
-	   )) // include safety in limits
280
-	rap_in_fundamental = false;
281
-      */
282
-      /*
283
-      if (LeftState.base.Nrap[j] > 0 &&
284
-	  ((LeftState.lambda[j][LeftState.base.Nrap[j] - 1] - LeftState.lambda[j][0] >= PI)
285
-	   //|| (LeftState.base.Nrap[j] == 1 && fabs(LeftState.lambda[j][0]) > 0.5*PI)
286
-	   ))
287
-	rap_in_fundamental = false;
288
-      */
289 218
 
290 219
       // Logic: allow rapidities -PI/2 <= lambda <= PI/2 (including boundaries)
291 220
       if (LeftState.base.Nrap[j] > 0 &&
@@ -308,7 +237,6 @@ namespace ABACUS {
308 237
 
309 238
     // Identify which matrix element is needed from the number of particles in Left and Right states:
310 239
     DP ME = 0.0;
311
-    //if (!(LeftState.conv && RightState.conv)) ME = 0.0;
312 240
     if (!(LeftState.conv && RightState.conv && rap_in_fundamental)) ME = 0.0;
313 241
 
314 242
     else if (whichDSF == 'Z')
@@ -317,7 +245,6 @@ namespace ABACUS {
317 245
       ME = exp(real(ln_Smin_ME (RightState, LeftState)));
318 246
     else if (whichDSF == 'z') {
319 247
       if (LeftState.label == RightState.label)
320
-	//MEsq = RightState.chain.Nsites * 0.25 * pow((1.0 - 2.0*RightState.base.Mdown/RightState.chain.Nsites), 2.0);
321 248
 	ME = sqrt(RightState.chain.Nsites * 0.25) * (1.0 - 2.0*RightState.base.Mdown/RightState.chain.Nsites);
322 249
       else ME = exp(real(ln_Sz_ME (RightState, LeftState)));
323 250
     }
@@ -327,7 +254,6 @@ namespace ABACUS {
327 254
 
328 255
     if (is_nan(ME)) ME = 0.0;
329 256
 
330
-    //if (LeftState.dev > 1.0e+2 || RightState.dev > 1.0e+2) ME = 0.0; // kill deviated contributions
331 257
     if (fabs(ME) > 1.0) ME = 0.0;
332 258
 
333 259
     // Do the momentum business:
@@ -339,33 +265,24 @@ namespace ABACUS {
339 265
     // Print information to fstream:
340 266
     if (iKout >= iKmin && iKout <= iKmax) {
341 267
       if (whichDSF == 'Z') {
342
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
268
+	DAT_outfile << endl << setprecision(16)
269
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
343 270
 		    << iKout << "\t"
344
-	  //<< LeftState.conv << "\t"
345 271
 		    << setprecision(3) << LeftState.dev << "\t"
346 272
 		    << LeftState.label;
347 273
       }
348 274
       else {
349
-	DAT_outfile << endl << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
275
+	DAT_outfile << endl << setprecision(16)
276
+		    << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t"
350 277
 		    << iKout << "\t"
351 278
 		    << ME << "\t"
352
-	  //<< LeftState.conv << "\t"
353 279
 		    << setprecision(3) << LeftState.dev << "\t"
354 280
 		    << LeftState.label;
355
-
356
-	/*
357
-	  cout << setprecision(16) << LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot << "\t" << iKout << "\t" << ME << "\t" << setprecision(3) << LeftState.dev << "\t" << LeftState.label << "\t" << setprecision(16) << LeftState.lambda[0][0]/PI << "\t" << LeftState.Ix2[0][0] << "\t" << LeftState.lambda[0][LeftState.base.Nrap[0] - 1]/PI << "\t" << LeftState.Ix2[0][LeftState.base.Nrap[0] - 1];
358
-	  if (LeftState.base.Nrap[1] > 0) cout << "\t" << LeftState.lambda[1][0]/PI << "\t" << LeftState.Ix2[1][0];
359
-	  if (LeftState.lambda[0][0] < -0.5*PI + 1.0e-10 || LeftState.lambda[0][LeftState.base.Nrap[0] - 1] > 0.5*PI - 1.0e-10 || (LeftState.base.Nrap[1] > 0 && (LeftState.lambda[1][0] < -0.5*PI || LeftState.lambda[1][0] > 0.5*PI))) cout << "\t" << "*****";
360
-	  cout << endl;
361
-	*/
362
-
363 281
       }
364 282
     } // if iKmin <= iKout <= iKmax
365 283
 
366 284
     // Calculate and return the data_value:
367 285
     DP data_value = ME * ME;
368
-    //DP data_value = (iKout == 0 ? 1.0 : 2.0) * MEsq;
369 286
     if (whichDSF == 'Z') // use 1/(1 + omega)
370 287
       data_value = 1.0/(1.0 + LeftState.E - RightState.E - (LeftState.base.Mdown - RightState.base.Mdown) * Chem_Pot);
371 288
     else if (fixed_iK) // data value is MEsq * omega:

+ 15
- 24
src/HEIS/Heis_Sumrules.cc View File

@@ -99,7 +99,6 @@ namespace ABACUS {
99 99
     else ABACUSerror("Wrong anisotropy in S1_sumrule_factor.");
100 100
 
101 101
     DP answer = 0.0;
102
-    //if (xyorz == 'x' || xyorz == 'y') answer = 0.5 * (E0_Delta - Delta * (E0_Delta_eps - E0_Delta)/eps_Delta);
103 102
     if (xyorz == 'x' || xyorz == 'y') answer = 0.5 * (E0_Delta - Delta * (E0_Delta_eps - E0_Delta)/eps_Delta);
104 103
 
105 104
     // Careful for z !  Hamiltonian defined as S^z S^z - 1/4, so add back N/4:
@@ -118,8 +117,9 @@ namespace ABACUS {
118 117
 
119 118
     DP sumrule = 0.0;
120 119
 
121
-    if (mporz == 'm' || mporz == 'p') sumrule = - 4.0 * ((1.0 - Delta * cos((twoPI * iK)/N)) * X_x + (Delta - cos((twoPI * iK)/N)) * X_z + 0.5 * Chem_Pot * 0.5 *(N - 2*M))/N;
122
-    //if (mporz == 'm' || mporz == 'p') sumrule = - 1.0 * ((1.0 - Delta * cos((twoPI * iK)/N)) * 2.0 * X_x + (Delta - cos((twoPI * iK)/N)) * (X_x + X_z))/N;
120
+    if (mporz == 'm' || mporz == 'p')
121
+      sumrule = - 4.0 * ((1.0 - Delta * cos((twoPI * iK)/N)) * X_x + (Delta - cos((twoPI * iK)/N)) * X_z
122
+			 + 0.5 * Chem_Pot * 0.5 *(N - 2*M))/N;
123 123
 
124 124
     else if (mporz == 'z') sumrule = iK == 0 ? 1.0 : -2.0 * X_x * (1.0 - cos((twoPI * iK)/N))/N;
125 125
 
@@ -130,20 +130,16 @@ namespace ABACUS {
130 130
 
131 131
     else ABACUSerror("option not implemented in S1_sumrule_factor.");
132 132
 
133
-    //return(1.0/sumrule);
134
-    return(1.0/(sumrule + 1.0e-16)); // sumrule is 0 for iK == 0 or N
133
+    return(1.0/(sumrule + 1.0e-32)); // sumrule is 0 for iK == 0 or N
135 134
   }
136 135
 
137 136
   DP S1_sumrule_factor (char mporz, DP Delta, int N, int M, DP Chem_Pot, DP X_x, DP X_z, int iK)
138 137
   {
139
-
140
-    //DP X_x = X_avg ('x', Delta, N, M);
141
-    //DP X_z = X_avg ('z', Delta, N, M);
142
-
143 138
     DP sumrule = 0.0;
144 139
 
145
-    if (mporz == 'm' || mporz == 'p') sumrule = - 4.0 * ((1.0 - Delta * cos((twoPI * iK)/N)) * X_x + (Delta - cos((twoPI * iK)/N)) * X_z + 0.5 * Chem_Pot * 0.5 *(N - 2*M))/N;
146
-    //if (mporz == 'm' || mporz == 'p') sumrule = - 1.0 * ((1.0 - Delta * cos((twoPI * iK)/N)) * 2.0 * X_x + (Delta - cos((twoPI * iK)/N)) * (X_x + X_z))/N;
140
+    if (mporz == 'm' || mporz == 'p')
141
+      sumrule = - 4.0 * ((1.0 - Delta * cos((twoPI * iK)/N)) * X_x + (Delta - cos((twoPI * iK)/N)) * X_z
142
+			 + 0.5 * Chem_Pot * 0.5 *(N - 2*M))/N;
147 143
 
148 144
     else if (mporz == 'z') sumrule = -2.0 * X_x * (1.0 - cos((twoPI * iK)/N))/N;
149 145
 
@@ -154,15 +150,13 @@ namespace ABACUS {
154 150
 
155 151
     else ABACUSerror("option not implemented in S1_sumrule_factor.");
156 152
 
157
-    return(1.0/(sumrule + 1.0e-16)); // sumrule is 0 for iK == 0 or N
153
+    return(1.0/(sumrule + 1.0e-32)); // sumrule is 0 for iK == 0 or N
158 154
   }
159 155
 
160 156
 
161
-  //DP Sumrule_Factor (char whichDSF, Heis_Bethe_State& AveragingState, DP Chem_Pot, bool fixed_iK, int iKneeded)
162 157
   DP Sumrule_Factor (char whichDSF, Heis_Bethe_State& AveragingState, DP Chem_Pot, int iKmin, int iKmax)
163 158
   {
164 159
     DP sumrule_factor = 1.0;
165
-    //if (!fixed_iK) {
166 160
     if (iKmin != iKmax) {
167 161
       if (whichDSF == 'Z') sumrule_factor = 1.0;
168 162
       else if (whichDSF == 'm')
@@ -176,12 +170,11 @@ namespace ABACUS {
176 170
 
177 171
       else ABACUSerror("whichDSF option not consistent in Sumrule_Factor");
178 172
     }
179
-    //else if (fixed_iK) {
180 173
     else if (iKmin == iKmax) {
181 174
       if (whichDSF == 'Z') sumrule_factor = 1.0;
182 175
       else if (whichDSF == 'm' || whichDSF == 'z' || whichDSF == 'p')
183
-	//sumrule_factor = S1_sumrule_factor (whichDSF, AveragingState.chain.Delta, AveragingState.chain.Nsites, AveragingState.base.Mdown, iKneeded);
184
-	sumrule_factor = S1_sumrule_factor (whichDSF, AveragingState.chain.Delta, AveragingState.chain.Nsites, AveragingState.base.Mdown, Chem_Pot, iKmax);
176
+	sumrule_factor = S1_sumrule_factor (whichDSF, AveragingState.chain.Delta, AveragingState.chain.Nsites,
177
+					    AveragingState.base.Mdown, Chem_Pot, iKmax);
185 178
       else if (whichDSF == 'a') sumrule_factor = 1.0;
186 179
       else if (whichDSF == 'b') sumrule_factor = 1.0;
187 180
       else if (whichDSF == 'c') sumrule_factor = 1.0;
@@ -190,13 +183,12 @@ namespace ABACUS {
190 183
       else ABACUSerror("whichDSF option not consistent in Sumrule_Factor");
191 184
     }
192 185
 
193
-
194
-
195 186
     return(sumrule_factor);
196 187
   }
197 188
 
198 189
 
199
-  void Evaluate_F_Sumrule (string prefix, char whichDSF, const Heis_Bethe_State& AveragingState, DP Chem_Pot, int iKmin_ref, int iKmax_ref)
190
+  void Evaluate_F_Sumrule (string prefix, char whichDSF, const Heis_Bethe_State& AveragingState,
191
+			   DP Chem_Pot, int iKmin_ref, int iKmax_ref)
200 192
   {
201 193
 
202 194
     stringstream RAW_stringstream;    string RAW_string;
@@ -216,18 +208,15 @@ namespace ABACUS {
216 208
     int iKmod = AveragingState.chain.Nsites;
217 209
 
218 210
     // We run through the data file to chech the f sumrule at each positive momenta:
219
-    //Vect<DP> Sum_omega_MEsq(0.0, iKmax - iKmin + 1);
220 211
     Vect<DP> Sum_omega_MEsq(0.0, iKmax - iKmin + 1);
221 212
 
222 213
     DP omega, ME;
223 214
     int iK, iKexc;
224
-    //int conv;
225 215
     DP dev;
226 216
     string label;
227 217
 
228 218
     while (infile.peek() != EOF) {
229 219
       infile >> omega >> iK >> ME >> dev >> label;
230
-      //if (iK >= iKmin && iK <= iKmax) Sum_omega_MEsq[iK - iKmin] += omega * ME * ME;
231 220
       iKexc = iK;
232 221
       while (iKexc > iKmax && iKexc - iKmod >= iKmin) iKexc -= iKmod;
233 222
       while (iKexc < iKmin && iKexc + iKmod <= iKmax) iKexc += iKmod;
@@ -245,7 +234,9 @@ namespace ABACUS {
245 234
 
246 235
     for (int i = iKmin; i <= iKmax; ++i) {
247 236
       if (i > iKmin) outfile << endl;
248
-      outfile << i << "\t" << Sum_omega_MEsq[i] * S1_sumrule_factor (whichDSF, AveragingState.chain.Delta, AveragingState.chain.Nsites, AveragingState.base.Mdown, Chem_Pot, X_x, X_z, i);
237
+      outfile << i << "\t" << Sum_omega_MEsq[i]
238
+	* S1_sumrule_factor (whichDSF, AveragingState.chain.Delta, AveragingState.chain.Nsites,
239
+			     AveragingState.base.Mdown, Chem_Pot, X_x, X_z, i);
249 240
     }
250 241
 
251 242
     outfile.close();

+ 0
- 3
src/HEIS/M_vs_H.cc View File

@@ -126,11 +126,8 @@ namespace ABACUS {
126 126
 
127 127
 	M_found = (HZmin_actual < HZ && HZ <= HZmax_actual);
128 128
 
129
-	//cout << "M_actual = " << M_actual << "\tM_step = " << M_step
130
-	//   << "\tHZmin_actual = " << HZmin_actual << "\tHZmax_actual = " << HZmax_actual << "\tHZ = " << HZ << "\t" << M_found << endl;
131 129
       }
132 130
     }
133
-    //cout << "M found = " << M_actual << "\tHZmax = " << Ezero[M_actual] - Ezero[M_actual + 1] << "\tHZmin = " << Ezero[M_actual - 1] - Ezero[M_actual] << endl;
134 131
 
135 132
     return(M_actual);
136 133
   }

+ 27
- 199
src/HEIS/XXX_Bethe_State.cc View File

@@ -53,22 +53,12 @@ namespace ABACUS {
53 53
       ABACUSerror("Delta != 1.0 in XXX_Bethe_State constructor");
54 54
     }
55 55
   }
56
-  /*
57
-  XXX_Bethe_State::XXX_Bethe_State (const Heis_Chain& RefChain, long long int base_id_ref, long long int type_id_ref)
58
-    : Heis_Bethe_State(RefChain, base_id_ref, type_id_ref)
59
-  {
60
-    if (RefChain.Delta != 1.0) {
61
-      cout << setprecision(16) << RefChain.Delta << endl;
62
-      ABACUSerror("Delta != 1.0 in XXX_Bethe_State constructor");
63
-    }
64
-  }
65
-  */
56
+
66 57
   XXX_Bethe_State& XXX_Bethe_State::operator= (const XXX_Bethe_State& RefState)
67 58
   {
68 59
     if (this != &RefState) {
69 60
       chain = RefState.chain;
70 61
       base = RefState.base;
71
-      //offsets = RefState.offsets;
72 62
       Ix2 = RefState.Ix2;
73 63
       lambda = RefState.lambda;
74 64
       BE = RefState.BE;
@@ -80,11 +70,6 @@ namespace ABACUS {
80 70
       iK = RefState.iK;
81 71
       K = RefState.K;
82 72
       lnnorm = RefState.lnnorm;
83
-      //base_id = RefState.base_id;
84
-      //type_id = RefState.type_id;
85
-      //id = RefState.id;
86
-      //maxid = RefState.maxid;
87
-      //nparticles = RefState.nparticles;
88 73
       label = RefState.label;
89 74
     }
90 75
     return(*this);
@@ -115,15 +100,15 @@ namespace ABACUS {
115 100
     // and strings of equal length modulo 2 and parity with Ix2 = 0, meaning at least two equal roots in BAE.
116 101
 
117 102
     bool answer = true;
118
-    //int test1, test3;
119 103
     Vect<bool> Zero_at_level(false, chain.Nstrings); // whether there exists an Ix2 == 0 at a given level
120 104
 
121 105
     bool higher_string_on_zero = false;
122 106
 
123 107
     for (int j = 0; j < chain.Nstrings; ++j) {
124 108
       // The following line puts answer to true if there is at least one higher string with zero Ix2
125
-      for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] == 0) && (chain.Str_L[j] > 2) && !(chain.Str_L[j] % 2))
126
-	higher_string_on_zero = true;
109
+      for (int alpha = 0; alpha < base[j]; ++alpha)
110
+	if ((Ix2[j][alpha] == 0) && (chain.Str_L[j] > 2) && !(chain.Str_L[j] % 2))
111
+	  higher_string_on_zero = true;
127 112
       for (int alpha = 0; alpha < base[j]; ++alpha) if (Ix2[j][alpha] == 0) Zero_at_level[j] = true;
128 113
       // NOTE:  if base[j] == 0, Zero_at_level[j] remains false.
129 114
     }
@@ -137,18 +122,13 @@ namespace ABACUS {
137 122
 	if (Zero_at_level[j1] && Zero_at_level[j2] && (!((chain.Str_L[j1] + chain.Str_L[j2])%2)))
138 123
 	  string_coincidence = true;
139 124
     }
140
-    /*
141
-    bool onep_onem_on_zero = false;
142
-    if (option == 'm') { // for Smin, we also exclude symmetric states with 1+ and 1- strings on zero
143
-      if (Zero_at_level[0] && Zero_at_level[1]) onep_onem_on_zero = true;
144
-    }
145
-    */
146 125
     answer = !(symmetric_state && (higher_string_on_zero || string_coincidence /*|| onep_onem_on_zero*/));
147 126
 
148 127
     // Now check that no Ix2 is equal to +N (since we take -N into account, and I + N == I by periodicity of exp)
149 128
 
150 129
     for (int j = 0; j < chain.Nstrings; ++j)
151
-      for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] < -chain.Nsites) || (Ix2[j][alpha] >= chain.Nsites)) answer = false;
130
+      for (int alpha = 0; alpha < base[j]; ++alpha)
131
+	if ((Ix2[j][alpha] < -chain.Nsites) || (Ix2[j][alpha] >= chain.Nsites)) answer = false;
152 132
 
153 133
     if (!answer) {
154 134
       E = 0.0;
@@ -211,123 +191,9 @@ namespace ABACUS {
211 191
   {
212 192
     // Returns a new iteration value for lambda[j][alpha] given BE[j][alpha]
213 193
 
214
-    return(0.5 * chain.Str_L[j] * tan(0.5 *
215
-				      //(PI * Ix2[j][alpha] + sumtheta)/chain.Nsites
216
-				      (2.0 * atan(2.0 * lambda[j][alpha]/chain.Str_L[j]) - BE[j][alpha])
217
-				      ));
194
+    return(0.5 * chain.Str_L[j] * tan(0.5 * (2.0 * atan(2.0 * lambda[j][alpha]/chain.Str_L[j]) - BE[j][alpha])));
218 195
   }
219 196
 
220
-  /*
221
-  void XXX_Bethe_State::Iterate_BAE ()
222
-  {
223
-    // Recalculates the rapidities by iterating Bethe equations
224
-
225
-    Lambda New_lambda(chain, base);
226
-    DP sumtheta = 0.0;
227
-    DP arg = 0.0;
228
-
229
-    for (int j = 0; j < chain.Nstrings; ++j) {
230
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
231
-
232
-	sumtheta = 0.0;
233
-	for (int k = 0; k < chain.Nstrings; ++k) {
234
-	  for (int beta = 0; beta < base[k]; ++beta)
235
-
236
-	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
237
-	      sumtheta += atan(lambda[j][alpha] - lambda[k][beta]);
238
-
239
-	    else sumtheta += 0.5 * Theta_XXX(lambda[j][alpha] - lambda[k][beta], chain.Str_L[j], chain.Str_L[k]);
240
-	}
241
-	sumtheta *= 2.0;
242
-
243
-	New_lambda[j][alpha] = 0.5 * chain.Str_L[j] * tan((PI * 0.5 * Ix2[j][alpha] + 0.5 * sumtheta)/chain.Nsites);
244
-
245
-      }
246
-    }
247
-
248
-    DP New_diffsq = 0.0;
249
-
250
-    for (int j = 0; j < chain.Nstrings; ++j) {
251
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
252
-	New_diffsq += pow(New_lambda[j][alpha] - lambda[j][alpha], 2.0);
253
-	lambda[j][alpha] = 1.0 * New_lambda[j][alpha] + 0.0 * lambda[j][alpha];
254
-      }
255
-    }
256
-
257
-    diffsq = New_diffsq;
258
-    iter++;
259
-
260
-    return;
261
-  }
262
-  */
263
-  /*
264
-  void XXX_Bethe_State::Iterate_BAE_Newton ()
265
-  {
266
-    // does one step of a Newton method on the rapidities...
267
-
268
-    Vect_DP RHSBAE (0.0, base.Nraptot);  // contains RHS of BAEs
269
-    Vect_CX dlambda (0.0, base.Nraptot);  // contains delta lambda computed from Newton's method
270
-    SQMat_CX Gaudin (0.0, base.Nraptot);
271
-    Vect_INT indx (base.Nraptot);
272
-    DP sumtheta = 0.0;
273
-    DP arg = 0.0;
274
-    DP fn_arg = 0.0;
275
-    DP olddiffsq = diffsq;
276
-
277
-    // Compute the RHS of the BAEs:
278
-
279
-    int index = 0;
280
-
281
-    for (int j = 0; j < chain.Nstrings; ++j) {
282
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
283
-
284
-	sumtheta = 0.0;
285
-	for (int k = 0; k < chain.Nstrings; ++k) {
286
-	  for (int beta = 0; beta < base[k]; ++beta)
287
-
288
-	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
289
-	      sumtheta += atan(lambda[j][alpha] - lambda[k][beta]);
290
-
291
-	    else sumtheta += 0.5 * Theta_XXX((lambda[j][alpha] - lambda[k][beta]), chain.Str_L[j], chain.Str_L[k]);
292
-	}
293
-	sumtheta *= 2.0;
294
-
295
-	RHSBAE[index] = chain.Nsites * 2.0 * atan(2.0 * lambda[j][alpha]/chain.Str_L[j]) - sumtheta - PI*Ix2[j][alpha];
296
-	index++;
297
-      }
298
-    }
299
-
300
-    (*this).Build_Reduced_Gaudin_Matrix (Gaudin);
301
-
302
-    for (int i = 0; i < base.Nraptot; ++i) dlambda[i] = - RHSBAE[i];
303
-
304
-    DP d;
305
-    ludcmp_CX (Gaudin, indx, d);
306
-    lubksb_CX (Gaudin, indx, dlambda);
307
-
308
-    diffsq = 0.0;
309
-    for (int i = 0; i < base.Nraptot; ++i) diffsq += norm(dlambda[i]);
310
-
311
-    // if we've converged, calculate the norm here, since the work has been done...
312
-
313
-    if (diffsq < chain.prec) {
314
-      lnnorm = 0.0;
315
-      for (int j = 0; j < base.Nraptot; j++) lnnorm += log(abs(Gaudin[j][j]));
316
-    }
317
-
318
-    index = 0;
319
-    for (int j = 0; j < chain.Nstrings; ++j) {
320
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
321
-	lambda[j][alpha] += real(dlambda[index]);
322
-	index++;
323
-      }
324
-    }
325
-
326
-    iter_Newton++;
327
-
328
-    return;
329
-  }
330
-  */
331 197
   bool XXX_Bethe_State::Check_Rapidities()
332 198
   {
333 199
     bool nonan = true;
@@ -345,9 +211,8 @@ namespace ABACUS {
345 211
     DP delta = 0.0;
346 212
 
347 213
     int occupied_strings = 0;
348
-    for (int i = 0; i < (*this).chain.Nstrings; ++i) if ((*this).chain.Str_L[i] > 1) occupied_strings += (*this).base.Nrap[i];
349
-
350
-    //if ((*this).conv == 0) delta = 1.0;
214
+    for (int i = 0; i < (*this).chain.Nstrings; ++i)
215
+      if ((*this).chain.Str_L[i] > 1) occupied_strings += (*this).base.Nrap[i];
351 216
 
352 217
     if (occupied_strings == 0) delta = 0.0;
353 218
 
@@ -367,8 +232,9 @@ namespace ABACUS {
367 232
 
368 233
 	    if ((*this).chain.Str_L[j] > 1) {  // else the BAE are already 1
369 234
 
370
-	      log_BAE_reg = DP((*this).chain.Nsites) * log(((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a + 1.0))
371
-							 /((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a - 1.0)));
235
+	      log_BAE_reg = DP((*this).chain.Nsites)
236
+		* log(((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a + 1.0))
237
+		      /((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a - 1.0)));
372 238
 
373 239
 	      for (int k = 0; k < (*this).chain.Nstrings; ++k)
374 240
 		for (int beta = 0; beta < (*this).base[k]; ++beta)
@@ -376,15 +242,14 @@ namespace ABACUS {
376 242
 		    if ((j != k) || (alpha != beta) || (a != b - 1))
377 243
 
378 244
 		      log_BAE_reg += log((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a )
379
-				      - ((*this).lambda[k][beta] + 0.5 * II * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
380
-					 ) - II );
245
+					 - ((*this).lambda[k][beta] + 0.5 * II * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
246
+					    ) - II );
381 247
 
382 248
 		    if ((j != k) || (alpha != beta) || (a != b + 1))
383 249
 
384
-		      log_BAE_reg -= log(((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a )
385
-				       )
386
-				      - ((*this).lambda[k][beta] + 0.5 * II * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
387
-					 ) + II );
250
+		      log_BAE_reg -= log(((*this).lambda[j][alpha] + 0.5 * II * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a))
251
+					 - ((*this).lambda[k][beta] + 0.5 * II * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b))
252
+					 + II );
388 253
 		  }
389 254
 
390 255
 	      // The regular LHS of BAE is now defined.  Now sum up the deltas...
@@ -432,37 +297,11 @@ namespace ABACUS {
432 297
     return;
433 298
   }
434 299
 
435
-  /*
436
-  void XXX_Bethe_State::Compute_Momentum ()
437
-  {
438
-    int sum_Ix2 = 0;
439
-    DP sum_M = 0.0;
440
-
441
-    for (int j = 0; j < chain.Nstrings; ++j) {
442
-      sum_M += base[j];
443
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
444
-	sum_Ix2 += Ix2[j][alpha];
445
-      }
446
-    }
447
-
448
-    iK = (chain.Nsites/2) * int(sum_M) - (sum_Ix2/2);
449
-
450
-    while (iK >= chain.Nsites) iK -= chain.Nsites;
451
-    while (iK < 0) iK += chain.Nsites;
452
-
453
-    K = PI * sum_M - PI * sum_Ix2/chain.Nsites;
454
-
455
-    while (K >= 2.0*PI) K -= 2.0*PI;
456
-    while (K < 0.0) K += 2.0*PI;
457
-
458
-    return;
459
-  }
460
-  */
461
-
462 300
   void XXX_Bethe_State::Build_Reduced_Gaudin_Matrix (SQMat<complex<DP> >& Gaudin_Red)
463 301
   {
464 302
 
465
-    if (Gaudin_Red.size() != base.Nraptot) ABACUSerror("Passing matrix of wrong size in Build_Reduced_Gaudin_Matrix.");
303
+    if (Gaudin_Red.size() != base.Nraptot)
304
+      ABACUSerror("Passing matrix of wrong size in Build_Reduced_Gaudin_Matrix.");
466 305
 
467 306
     int index_jalpha;
468 307
     int index_kbeta;
@@ -489,8 +328,8 @@ namespace ABACUS {
489 328
 	      }
490 329
 
491 330
 	      Gaudin_Red[index_jalpha][index_kbeta]
492
-		= complex<DP> ( chain.Nsites * chain.Str_L[j]/(lambda[j][alpha] * lambda[j][alpha] + 0.25 * chain.Str_L[j] * chain.Str_L[j])
493
-				- sum_hbar_XXX);
331
+		= complex<DP> ( chain.Nsites * chain.Str_L[j]/(lambda[j][alpha] * lambda[j][alpha]
332
+							       + 0.25 * chain.Str_L[j] * chain.Str_L[j]) - sum_hbar_XXX);
494 333
 	    }
495 334
 
496 335
 	    else {
@@ -553,25 +392,12 @@ namespace ABACUS {
553 392
     DP result = (nj == nk) ? 0.0 : DP(n)/(lambda * lambda + 0.25 * n * n);
554 393
 
555 394
     for (int a = 1; a < ABACUS::min(nj, nk); ++a) result += 2.0 * (n + 2.0*a)
556
-      / (lambda * lambda + 0.25 * (n + 2.0*a) * (n + 2.0*a));
557
-
558
-    result += DP(nj + nk)/(lambda * lambda + 0.25 * (nj + nk) * (nj + nk));
559
-
560
-    return (result);
561
-  }
562
-  /*
563
-  DP ddlambda_Theta_XXX (DP lambda, int nj, int nk)
564
-  {
565
-    DP result = (nj == nk) ? 0.0 : DP(nj - nk)/(lambda * lambda + 0.25 * (nj - nk) * (nj - nk));
566
-
567
-    for (int a = 1; a < ABACUS::min(nj, nk); ++a) result += 2.0 * (nj - nk + 2.0*a) * (nj - nk + 2.0*a)
568
-      / (lambda * lambda + 0.25 * (nj - nk + 2.0*a) * (nj - nk + 2.0*a));
395
+						    / (lambda * lambda + 0.25 * (n + 2.0*a) * (n + 2.0*a));
569 396
 
570 397
     result += DP(nj + nk)/(lambda * lambda + 0.25 * (nj + nk) * (nj + nk));
571 398
 
572 399
     return (result);
573 400
   }
574
-  */
575 401
 
576 402
   XXX_Bethe_State Add_Particle_at_Center (const XXX_Bethe_State& RefState)
577 403
   {
@@ -593,7 +419,8 @@ namespace ABACUS {
593 419
     // and shift quantum numbers by half-integer away from added one:
594 420
     ReturnState.Ix2[0][RefState.base.Nrap[0]/2] = RefState.Ix2[0][RefState.base.Nrap[0]/2] - 1;
595 421
     for (int i = 0; i < RefState.base.Nrap[0] + 1; ++i)
596
-      ReturnState.Ix2[0][i + (i >= RefState.base.Nrap[0]/2)] = RefState.Ix2[0][i] - 1 + 2*(i >= RefState.base.Nrap[0]/2);
422
+      ReturnState.Ix2[0][i + (i >= RefState.base.Nrap[0]/2)]
423
+	= RefState.Ix2[0][i] - 1 + 2*(i >= RefState.base.Nrap[0]/2);
597 424
 
598 425
     return(ReturnState);
599 426
   }
@@ -617,10 +444,11 @@ namespace ABACUS {
617 444
 
618 445
     // Remove midmost and shift quantum numbers by half-integer towards removed one:
619 446
     for (int i = 0; i < RefState.base.Nrap[0]-1; ++i)
620
-      ReturnState.Ix2[0][i] = RefState.Ix2[0][i + (i >= RefState.base.Nrap[0]/2)] + 1 - 2*(i >= RefState.base.Nrap[0]/2);
447
+      ReturnState.Ix2[0][i]
448
+	= RefState.Ix2[0][i + (i >= RefState.base.Nrap[0]/2)] + 1 - 2*(i >= RefState.base.Nrap[0]/2);
621 449
 
622 450
     return(ReturnState);
623
-    }
451
+  }
624 452
 
625 453
 
626 454
 } // namespace ABACUS

+ 98
- 116
src/HEIS/XXZ_Bethe_State.cc View File

@@ -35,12 +35,12 @@ namespace ABACUS {
35 35
   {};
36 36
 
37 37
   XXZ_Bethe_State::XXZ_Bethe_State (const XXZ_Bethe_State& RefState) // copy constructor
38
-    : Heis_Bethe_State(RefState), sinhlambda(Lambda(RefState.chain, RefState.base)), coshlambda(Lambda(RefState.chain, RefState.base)),
38
+    : Heis_Bethe_State(RefState), sinhlambda(Lambda(RefState.chain, RefState.base)),
39
+      coshlambda(Lambda(RefState.chain, RefState.base)),
39 40
       tanhlambda(Lambda(RefState.chain, RefState.base))
40 41
   {
41 42
     // copy arrays into new ones
42 43
 
43
-    //cout << "Calling XXZ state copy constructor." << endl;
44 44
     for (int j = 0; j < RefState.chain.Nstrings; ++j) {
45 45
       for (int alpha = 0; alpha < RefState.base[j]; ++j) {
46 46
 	sinhlambda[j][alpha] = RefState.sinhlambda[j][alpha];
@@ -48,40 +48,29 @@ namespace ABACUS {
48 48
 	tanhlambda[j][alpha] = RefState.tanhlambda[j][alpha];
49 49
       }
50 50
     }
51
-    //cout << "Done calling XXZ state copy constructor." << endl;
52 51
   }
53 52
 
54 53
   XXZ_Bethe_State::XXZ_Bethe_State (const Heis_Chain& RefChain, int M)
55 54
     : Heis_Bethe_State(RefChain, M),
56 55
       sinhlambda(Lambda(RefChain, M)), coshlambda(Lambda(RefChain, M)), tanhlambda(Lambda(RefChain, M))
57 56
   {
58
-    //cout << "Here in XXZ BS constructor." << endl;
59
-    //cout << (*this).lambda[0][0] << endl;
60
-    //cout << "OK" << endl;
61
-    if ((RefChain.Delta <= -1.0) || (RefChain.Delta >= 1.0)) ABACUSerror("Delta out of range in XXZ_Bethe_State constructor");
57
+    if ((RefChain.Delta <= -1.0) || (RefChain.Delta >= 1.0))
58
+      ABACUSerror("Delta out of range in XXZ_Bethe_State constructor");
62 59
   }
63 60
 
64 61
   XXZ_Bethe_State::XXZ_Bethe_State (const Heis_Chain& RefChain, const Heis_Base& RefBase)
65 62
     : Heis_Bethe_State(RefChain, RefBase),
66 63
       sinhlambda(Lambda(RefChain, RefBase)), coshlambda(Lambda(RefChain, RefBase)), tanhlambda(Lambda(RefChain, RefBase))
67 64
   {
68
-    if ((RefChain.Delta <= -1.0) || (RefChain.Delta >= 1.0)) ABACUSerror("Delta out of range in XXZ_Bethe_State constructor");
65
+    if ((RefChain.Delta <= -1.0) || (RefChain.Delta >= 1.0))
66
+      ABACUSerror("Delta out of range in XXZ_Bethe_State constructor");
69 67
   }
70
-  /*
71
-  XXZ_Bethe_State::XXZ_Bethe_State (const Heis_Chain& RefChain, long long int base_id_ref, long long int type_id_ref)
72
-    : Heis_Bethe_State(RefChain, base_id_ref, type_id_ref),
73
-      sinhlambda(Lambda(chain, base)), coshlambda(Lambda(chain, base)), tanhlambda(Lambda(chain, base))
74
-  {
75
-    if ((RefChain.Delta <= -1.0) || (RefChain.Delta >= 1.0)) ABACUSerror("Delta out of range in XXZ_Bethe_State constructor");
76
-  }
77
-  */
78 68
 
79 69
   XXZ_Bethe_State& XXZ_Bethe_State::operator= (const XXZ_Bethe_State& RefState)
80 70
   {
81 71
     if (this != &RefState) {
82 72
       chain = RefState.chain;
83 73
       base = RefState.base;
84
-      //offsets = RefState.offsets;
85 74
       Ix2 = RefState.Ix2;
86 75
       lambda = RefState.lambda;
87 76
       BE = RefState.BE;
@@ -93,11 +82,6 @@ namespace ABACUS {
93 82
       iK = RefState.iK;
94 83
       K = RefState.K;
95 84
       lnnorm = RefState.lnnorm;
96
-      //base_id = RefState.base_id;
97
-      //type_id = RefState.type_id;
98
-      //id = RefState.id;
99
-      //maxid = RefState.maxid;
100
-      //nparticles = RefState.nparticles;
101 85
       label = RefState.label;
102 86
 
103 87
       sinhlambda = RefState.sinhlambda;
@@ -119,21 +103,16 @@ namespace ABACUS {
119 103
       for (int alpha = 0; alpha < base[i]; ++alpha) {
120 104
 
121 105
 	if (chain.par[i] == 1) {
122
-	  //lambda[i][alpha] = atanh(tan(chain.Str_L[i] * 0.5 * chain.anis) * tan(PI * 0.5 * Ix2[i][alpha]/chain.Nsites));
123 106
 	  x = tan(chain.Str_L[i] * 0.5 * chain.anis) * tan(PI * 0.5 * Ix2[i][alpha]/chain.Nsites);
124 107
 	  lambda[i][alpha] = atanh(x/sqrt(1.0 + x*x)); // lambda then always initiated real
125 108
 	}
126 109
 
127 110
 	else if (chain.par[i] == -1) {
128
-	  //lambda[i][alpha] = atanh(-tan(PI * 0.5 * Ix2[i][alpha]/chain.Nsites)/tan(chain.Str_L[i] * 0.5 * chain.anis));
129 111
 	  x = -tan(PI * 0.5 * Ix2[i][alpha]/chain.Nsites)/tan(chain.Str_L[i] * 0.5 * chain.anis);
130 112
 	  lambda[i][alpha] = atanh(x/sqrt(1.0 + x*x)); // lambda then always initiated real
131 113
 	}
132 114
 
133 115
 	else ABACUSerror("Invalid parities in Set_Free_lambdas.");
134
-	//cout << tan(chain.Str_L[i] * 0.5 * chain.anis) << endl;
135
-	//cout << "Set_Free_lambdas: " << i << "\t" << alpha << "\t" << lambda[i][alpha] << "\t" << tan(chain.Str_L[i] * 0.5 * chain.anis) * tan(PI * 0.5 * Ix2[i][alpha]/chain.Nsites) << endl;
136
-
137 116
       }
138 117
     }
139 118
 
@@ -179,8 +158,9 @@ namespace ABACUS {
179 158
     bool higher_string_on_zero = false;
180 159
     for (int j = 0; j < chain.Nstrings; ++j) {
181 160
       // The following line puts answer to true if there is at least one higher string with zero Ix2
182
-      for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] == 0) && (chain.Str_L[j] >= 2) /*&& !(chain.Str_L[j] % 2)*/)
183
-	higher_string_on_zero = true;
161
+      for (int alpha = 0; alpha < base[j]; ++alpha)
162
+	if ((Ix2[j][alpha] == 0) && (chain.Str_L[j] >= 2) /*&& !(chain.Str_L[j] % 2)*/)
163
+	  higher_string_on_zero = true;
184 164
       for (int alpha = 0; alpha < base[j]; ++alpha) if (Ix2[j][alpha] == 0) Zero_at_level[j] = true;
185 165
       // NOTE:  if base[j] == 0, Zero_at_level[j] remains false.
186 166
     }
@@ -192,14 +172,16 @@ namespace ABACUS {
192 172
     bool string_coincidence = false;
193 173
     for (int j1 = 0; j1 < chain.Nstrings; ++j1) {
194 174
       for (int j2 = j1 + 1; j2 < chain.Nstrings; ++j2)
195
-	if (Zero_at_level[j1] && Zero_at_level[j2] && (chain.par[j1] == chain.par[j2]) && (!((chain.Str_L[j1] + chain.Str_L[j2])%2)))
175
+	if (Zero_at_level[j1] && Zero_at_level[j2] && (chain.par[j1] == chain.par[j2])
176
+	    && (!((chain.Str_L[j1] + chain.Str_L[j2])%2)))
196 177
 	  string_coincidence = true;
197 178
     }
198 179
 
199 180
     bool M_odd_and_onep_on_zero = false;
200 181
     if (option == 'z') { // for Sz, if M is odd, exclude symmetric states with a 1+ on zero
201 182
                          // (zero rapidities in left and right states, so FF det not defined).
202
-      bool is_ground_state = base.Nrap[0] == base.Mdown && Ix2[0][0] == -(base.Mdown - 1) && Ix2[0][base.Mdown-1] == base.Mdown - 1;
183
+      bool is_ground_state = base.Nrap[0] == base.Mdown && Ix2[0][0] == -(base.Mdown - 1)
184
+	&& Ix2[0][base.Mdown-1] == base.Mdown - 1;
203 185
       if (Zero_at_level[0] && (base.Mdown % 2) && !is_ground_state) M_odd_and_onep_on_zero = true;
204 186
     }
205 187
 
@@ -208,12 +190,14 @@ namespace ABACUS {
208 190
       if (Zero_at_level[0] && Zero_at_level[1]) onep_onem_on_zero = true;
209 191
     }
210 192
 
211
-    answer = !(symmetric_state && (higher_string_on_zero || string_coincidence || onep_onem_on_zero || M_odd_and_onep_on_zero));
193
+    answer = !(symmetric_state && (higher_string_on_zero || string_coincidence
194
+				   || onep_onem_on_zero || M_odd_and_onep_on_zero));
212 195
 
213 196
     // Now check that no Ix2 is equal to +N (since we take -N into account, and I + N == I by periodicity of exp)
214 197
 
215 198
     for (int j = 0; j < chain.Nstrings; ++j)
216
-      for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] < -chain.Nsites) || (Ix2[j][alpha] >= chain.Nsites)) answer = false;
199
+      for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] < -chain.Nsites)
200
+							|| (Ix2[j][alpha] >= chain.Nsites)) answer = false;
217 201
 
218 202
     if (!answer) {
219 203
       E = 0.0;
@@ -237,17 +221,23 @@ namespace ABACUS {
237 221
       for (int beta = 0; beta < base[k]; ++beta) {
238 222
 	if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
239 223
 	  sumtheta += (chain.par[j] == chain.par[k])
240
-	    ? atan((tanhlambda[j][alpha] - tanhlambda[k][beta])/((1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
241
-	    : - atan(((tanhlambda[j][alpha] - tanhlambda[k][beta])/(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta])) * chain.ta_n_anis_over_2[2]) ;
242
-	else sumtheta += 0.5 * Theta_XXZ((tanhlambda[j][alpha] - tanhlambda[k][beta])/(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]),
243
-					 chain.Str_L[j], chain.Str_L[k], chain.par[j], chain.par[k], chain.ta_n_anis_over_2);
224
+	    ? atan((tanhlambda[j][alpha] - tanhlambda[k][beta])
225
+		   /((1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
226
+	    : - atan(((tanhlambda[j][alpha] - tanhlambda[k][beta])
227
+		      /(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta])) * chain.ta_n_anis_over_2[2]) ;
228
+	else sumtheta += 0.5 * Theta_XXZ((tanhlambda[j][alpha] - tanhlambda[k][beta])
229
+					 /(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]), chain.Str_L[j],
230
+					 chain.Str_L[k], chain.par[j], chain.par[k], chain.ta_n_anis_over_2);
244 231
       }
245 232
     sumtheta *= 2.0;
246 233
 
247
-    BE[j][alpha] = ((chain.par[j] == 1) ? 2.0 * atan(tanhlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
248
-		    : -2.0 * atan(tanhlambda[j][alpha] * chain.ta_n_anis_over_2[chain.Str_L[j]])) - (sumtheta + PI*Ix2[j][alpha])/chain.Nsites;
234
+    BE[j][alpha] = ((chain.par[j] == 1) ?
235
+		    2.0 * atan(tanhlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
236
+		    :
237
+		    -2.0 * atan(tanhlambda[j][alpha] * chain.ta_n_anis_over_2[chain.Str_L[j]]))
238
+      - (sumtheta + PI*Ix2[j][alpha])/chain.Nsites;
249 239
 
250
-   }
240
+  }
251 241
 
252 242
   void XXZ_Bethe_State::Compute_BE ()
253 243
   {
@@ -265,17 +255,21 @@ namespace ABACUS {
265 255
 	  for (int beta = 0; beta < base[k]; ++beta) {
266 256
 	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
267 257
 	      sumtheta += (chain.par[j] == chain.par[k])
268
-		? atan((tanhlambda[j][alpha] - tanhlambda[k][beta])/((1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
269
-		: - atan(((tanhlambda[j][alpha] - tanhlambda[k][beta])/(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta])) * chain.ta_n_anis_over_2[2]) ;
270
-	    else sumtheta += 0.5 * Theta_XXZ((tanhlambda[j][alpha] - tanhlambda[k][beta])/(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]),
271
-					     chain.Str_L[j], chain.Str_L[k], chain.par[j], chain.par[k], chain.ta_n_anis_over_2);
258
+		? atan((tanhlambda[j][alpha] - tanhlambda[k][beta])
259
+		       /((1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
260
+		: - atan(((tanhlambda[j][alpha] - tanhlambda[k][beta])
261
+			  /(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta])) * chain.ta_n_anis_over_2[2]) ;
262
+	    else sumtheta += 0.5 * Theta_XXZ((tanhlambda[j][alpha] - tanhlambda[k][beta])
263
+					     /(1.0 - tanhlambda[j][alpha] * tanhlambda[k][beta]), chain.Str_L[j],
264
+					     chain.Str_L[k], chain.par[j], chain.par[k], chain.ta_n_anis_over_2);
272 265
 	  }
273 266
 	sumtheta *= 2.0;
274 267
 
275
-	BE[j][alpha] = ((chain.par[j] == 1) ? 2.0 * atan(tanhlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
276
-			: -2.0 * atan(tanhlambda[j][alpha] * chain.ta_n_anis_over_2[chain.Str_L[j]])) - (sumtheta + PI*Ix2[j][alpha])/chain.Nsites;
277
-
278
-	//if (is_nan(BE[j][alpha])) cout << "BE nan: " << j << "\t" << alpha << "\t" << lambda[j][alpha] << "\t" << tanhlambda[j][alpha] << endl;
268
+	BE[j][alpha] = ((chain.par[j] == 1) ?
269
+			2.0 * atan(tanhlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
270
+			:
271
+			-2.0 * atan(tanhlambda[j][alpha] * chain.ta_n_anis_over_2[chain.Str_L[j]]))
272
+	  - (sumtheta + PI*Ix2[j][alpha])/chain.Nsites;
279 273
       }
280 274
   }
281 275
 
@@ -288,15 +282,14 @@ namespace ABACUS {
288 282
     DP arg = 0.0;
289 283
 
290 284
     if (chain.par[j] == 1) arg = chain.ta_n_anis_over_2[chain.Str_L[j]]
291
-      * tan(0.5 *
292
-	    //(PI * Ix2[j][alpha] + sumtheta)/chain.Nsites
293
-	    (2.0 * atan(tanhlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]]) - BE[j][alpha])
294
-	    );
285
+			     * tan(0.5 *
286
+				   (2.0 * atan(tanhlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]]) - BE[j][alpha])
287
+				   );
295 288
 
296 289
     else if (chain.par[j] == -1) arg = -tan(0.5 *
297
-					    //(PI * Ix2[j][alpha] + sumtheta)/chain.Nsites)
298
-					    (-2.0 * atan(tanhlambda[j][alpha] * chain.ta_n_anis_over_2[chain.Str_L[j]]) - BE[j][alpha]))
299
-      /chain.ta_n_anis_over_2[chain.Str_L[j]];
290
+					    (-2.0 * atan(tanhlambda[j][alpha] * chain.ta_n_anis_over_2[chain.Str_L[j]])
291
+					     - BE[j][alpha]))
292
+				   /chain.ta_n_anis_over_2[chain.Str_L[j]];
300 293
 
301 294
     if (fabs(arg) < 1.0) {
302 295
       new_lambda = atanh(arg);
@@ -316,15 +309,20 @@ namespace ABACUS {
316 309
 	  for (int beta = 0; beta < base[k]; ++beta)
317 310
 	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
318 311
 	      sumtheta += (chain.par[j] == chain.par[k])
319
-		? atan((new_tanhlambda - tanhlambda[k][beta])/((1.0 - new_tanhlambda * tanhlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
320
-		: - atan(((new_tanhlambda - tanhlambda[k][beta])/(1.0 - new_tanhlambda * tanhlambda[k][beta])) * chain.ta_n_anis_over_2[2]) ;
321
-	    else sumtheta += 0.5 * Theta_XXZ((new_tanhlambda - tanhlambda[k][beta])/(1.0 - new_tanhlambda * tanhlambda[k][beta]),
322
-					     chain.Str_L[j], chain.Str_L[k], chain.par[j], chain.par[k], chain.ta_n_anis_over_2);
312
+		? atan((new_tanhlambda - tanhlambda[k][beta])
313
+		       /((1.0 - new_tanhlambda * tanhlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
314
+		: - atan(((new_tanhlambda - tanhlambda[k][beta])
315
+			  /(1.0 - new_tanhlambda * tanhlambda[k][beta])) * chain.ta_n_anis_over_2[2]) ;
316
+	    else sumtheta += 0.5 * Theta_XXZ((new_tanhlambda - tanhlambda[k][beta])
317
+					     /(1.0 - new_tanhlambda * tanhlambda[k][beta]), chain.Str_L[j],
318
+					     chain.Str_L[k], chain.par[j], chain.par[k], chain.ta_n_anis_over_2);
323 319
 	}
324 320
 	sumtheta *= 2.0;
325
-	if (chain.par[j] == 1) arg = chain.ta_n_anis_over_2[chain.Str_L[j]] * tan(0.5 * (PI * Ix2[j][alpha] + sumtheta)/chain.Nsites);
321
+	if (chain.par[j] == 1) arg = chain.ta_n_anis_over_2[chain.Str_L[j]]
322
+				 * tan(0.5 * (PI * Ix2[j][alpha] + sumtheta)/chain.Nsites);
326 323
 
327
-	else if (chain.par[j] == -1) arg = -tan(0.5 * (PI * Ix2[j][alpha] + sumtheta)/chain.Nsites)/chain.ta_n_anis_over_2[chain.Str_L[j]];
324
+	else if (chain.par[j] == -1) arg = -tan(0.5 * (PI * Ix2[j][alpha] + sumtheta)
325
+						/chain.Nsites)/chain.ta_n_anis_over_2[chain.Str_L[j]];
328 326
 
329 327
 	else ABACUSerror("Invalid parities in Iterate_BAE.");
330 328
 
@@ -334,7 +332,6 @@ namespace ABACUS {
334 332
 	new_lambda = atanh(arg);
335 333
       }
336 334
 
337
-      //else cout << "Rapidity blows up !\t" << lambda[j][alpha] << "\t" << new_lambda << endl;
338 335
     } // else
339 336
 
340 337
     return(new_lambda);
@@ -357,9 +354,8 @@ namespace ABACUS {
357 354
     DP delta = 0.0;
358 355
 
359 356
     int occupied_strings = 0;
360
-    for (int i = 0; i < (*this).chain.Nstrings; ++i) if ((*this).chain.Str_L[i] > 1) occupied_strings += (*this).base.Nrap[i];
361
-
362
-    //if ((*this).conv == 0) delta = 1.0;
357
+    for (int i = 0; i < (*this).chain.Nstrings; ++i)
358
+      if ((*this).chain.Str_L[i] > 1) occupied_strings += (*this).base.Nrap[i];
363 359
 
364 360
     if (occupied_strings == 0) delta = 0.0;
365 361
 
@@ -379,28 +375,34 @@ namespace ABACUS {
379 375
 
380 376
 	    if ((*this).chain.Str_L[j] > 1) {  // else the BAE are already 1
381 377
 
382
-	      log_BAE_reg = DP((*this).chain.Nsites) * log(sinh((*this).lambda[j][alpha]
383
-							   + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a + 1.0)
384
-				 + 0.25 * II * PI * (1.0 - (*this).chain.par[j]))
385
-			    /sinh((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a - 1.0)
386
-				  + 0.25 * II * PI * (1.0 - (*this).chain.par[j])));
378
+	      log_BAE_reg = DP((*this).chain.Nsites)
379
+		* log(sinh((*this).lambda[j][alpha]
380
+			   + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a + 1.0)
381
+			   + 0.25 * II * PI * (1.0 - (*this).chain.par[j]))
382
+		      /sinh((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis
383
+			    * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a - 1.0)
384
+			    + 0.25 * II * PI * (1.0 - (*this).chain.par[j])));
387 385
 
388 386
 	      for (int k = 0; k < (*this).chain.Nstrings; ++k)
389 387
 		for (int beta = 0; beta < (*this).base[k]; ++beta)
390 388
 		  for (int b = 1; b <= (*this).chain.Str_L[k]; ++b) {
391 389
 		    if ((j != k) || (alpha != beta) || (a != b - 1))
392 390
 
393
-		      log_BAE_reg += log(sinh(((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a )
394
-				       + 0.25 * II * PI * (1.0 - (*this).chain.par[j]))
395
-				      - ((*this).lambda[k][beta] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
396
-					 + 0.25 * II * PI * (1.0 - (*this).chain.par[k])) - II * (*this).chain.anis));
391
+		      log_BAE_reg += log(sinh(((*this).lambda[j][alpha]
392
+					       + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a )
393
+					       + 0.25 * II * PI * (1.0 - (*this).chain.par[j]))
394
+					      - ((*this).lambda[k][beta]
395
+						 + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
396
+						 + 0.25 * II * PI * (1.0 - (*this).chain.par[k])) - II * (*this).chain.anis));
397 397
 
398 398
 		    if ((j != k) || (alpha != beta) || (a != b + 1))
399 399
 
400
-		      log_BAE_reg -= log(sinh(((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a )
401
-				       + 0.25 * II * PI * (1.0 - (*this).chain.par[j]))
402
-				      - ((*this).lambda[k][beta] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
403
-					 + 0.25 * II * PI * (1.0 - (*this).chain.par[k])) + II * (*this).chain.anis));
400
+		      log_BAE_reg -= log(sinh(((*this).lambda[j][alpha]
401
+					       + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a )
402
+					       + 0.25 * II * PI * (1.0 - (*this).chain.par[j]))
403
+					      - ((*this).lambda[k][beta]
404
+						 + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b )
405
+						 + 0.25 * II * PI * (1.0 - (*this).chain.par[k])) + II * (*this).chain.anis));
404 406
 		  }
405 407
 
406 408
 	      // The regular LHS of BAE is now defined.  Now sum up the deltas...
@@ -437,7 +439,8 @@ namespace ABACUS {
437 439
 
438 440
     for (int j = 0; j < chain.Nstrings; ++j) {
439 441
       for (int alpha = 0; alpha < base[j]; ++alpha) {
440
-	sum += sin(chain.Str_L[j] * chain.anis) / (chain.par[j] * cosh(2.0 * lambda[j][alpha]) - cos(chain.Str_L[j] * chain.anis));
442
+	sum += sin(chain.Str_L[j] * chain.anis)
443
+	  / (chain.par[j] * cosh(2.0 * lambda[j][alpha]) - cos(chain.Str_L[j] * chain.anis));
441 444
       }
442 445
     }
443 446
 
@@ -448,36 +451,11 @@ namespace ABACUS {
448 451
     return;
449 452
   }
450 453
 
451
-  /*
452
-  void XXZ_Bethe_State::Compute_Momentum ()
453
-  {
454
-    int sum_Ix2 = 0;
455
-    DP sum_M = 0.0;
456
-
457
-    for (int j = 0; j < chain.Nstrings; ++j) {
458
-      sum_M += 0.5 * (1.0 + chain.par[j]) * base[j];
459
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
460
-	sum_Ix2 += Ix2[j][alpha];
461
-      }
462
-    }
463
-
464
-    iK = (chain.Nsites/2) * int(sum_M + 0.1) - (sum_Ix2/2);  // + 0.1:  for safety...
465
-
466
-    while (iK >= chain.Nsites) iK -= chain.Nsites;
467
-    while (iK < 0) iK += chain.Nsites;
468
-
469
-    K = PI * sum_M - PI * sum_Ix2/chain.Nsites;
470
-
471
-    while (K >= 2.0*PI) K -= 2.0*PI;
472
-    while (K < 0.0) K += 2.0*PI;
473
-
474
-    return;
475
-  }
476
-  */
477 454
   void XXZ_Bethe_State::Build_Reduced_Gaudin_Matrix (SQMat<complex<DP> >& Gaudin_Red)
478 455
   {
479 456
 
480
-    if (Gaudin_Red.size() != base.Nraptot) ABACUSerror("Passing matrix of wrong size in Build_Reduced_Gaudin_Matrix.");
457
+    if (Gaudin_Red.size() != base.Nraptot)
458
+      ABACUSerror("Passing matrix of wrong size in Build_Reduced_Gaudin_Matrix.");
481 459
 
482 460
     int index_jalpha;
483 461
     int index_kbeta;
@@ -504,13 +482,14 @@ namespace ABACUS {
504 482
 		for (int betap = 0; betap < base[kp]; ++betap) {
505 483
 		  if (!((j == kp) && (alpha == betap)))
506 484
 		    sum_hbar_XXZ
507
-		      += ddlambda_Theta_XXZ (lambda[j][alpha] - lambda[kp][betap], chain.Str_L[j], chain.Str_L[kp], chain.par[j], chain.par[kp],
508
-					     chain.si_n_anis_over_2);
485
+		      += ddlambda_Theta_XXZ (lambda[j][alpha] - lambda[kp][betap], chain.Str_L[j],
486
+					     chain.Str_L[kp], chain.par[j], chain.par[kp], chain.si_n_anis_over_2);
509 487
 		}
510 488
 	      }
511 489
 
512 490
 	      Gaudin_Red[index_jalpha][index_kbeta]
513
-		= complex<DP> ( chain.Nsites * hbar_XXZ (lambda[j][alpha], chain.Str_L[j], chain.par[j], chain.si_n_anis_over_2) - sum_hbar_XXZ);
491
+		= complex<DP> ( chain.Nsites * hbar_XXZ (lambda[j][alpha], chain.Str_L[j], chain.par[j],
492
+							 chain.si_n_anis_over_2) - sum_hbar_XXZ);
514 493
 	    }
515 494
 
516 495
 	    else {
@@ -518,12 +497,13 @@ namespace ABACUS {
518 497
 		Gaudin_Red[index_jalpha][index_kbeta] =
519 498
 		  complex<DP> ((chain.par[j] * chain.par[k] == 1)
520 499
 			       ? chain.si_n_anis_over_2[4]/(pow(sinhlambda[j][alpha] * coshlambda[k][beta]
521
-								 - coshlambda[j][alpha] * sinhlambda[k][beta], 2.0) + sinzetasq)
500
+								- coshlambda[j][alpha] * sinhlambda[k][beta], 2.0) + sinzetasq)
522 501
 			       : chain.si_n_anis_over_2[4]/(-pow(coshlambda[j][alpha] * coshlambda[k][beta]
523
-								  - sinhlambda[j][alpha] * sinhlambda[k][beta], 2.0) + sinzetasq) );
502
+								 - sinhlambda[j][alpha] * sinhlambda[k][beta], 2.0) + sinzetasq) );
524 503
 	      else
525
-		Gaudin_Red[index_jalpha][index_kbeta] = complex<DP> (ddlambda_Theta_XXZ (lambda[j][alpha] - lambda[k][beta], chain.Str_L[j], chain.Str_L[k],
526
-											  chain.par[j], chain.par[k], chain.si_n_anis_over_2));
504
+		Gaudin_Red[index_jalpha][index_kbeta]
505
+		  = complex<DP> (ddlambda_Theta_XXZ (lambda[j][alpha] - lambda[k][beta], chain.Str_L[j], chain.Str_L[k],
506
+						     chain.par[j], chain.par[k], chain.si_n_anis_over_2));
527 507
 	    }
528 508
 	    index_kbeta++;
529 509
 	  }
@@ -561,7 +541,8 @@ namespace ABACUS {
561 541
 
562 542
       result = (nj == nk) ? 0.0 : fbar_XXZ(tanhlambda, parj*park, tannzetaover2[fabs(nj - nk)]);
563 543
 
564
-      for (int a = 1; a < ABACUS::min(nj, nk); ++a) result += 2.0 * fbar_XXZ(tanhlambda, parj*park, tannzetaover2[fabs(nj - nk) + 2*a]);
544
+      for (int a = 1; a < ABACUS::min(nj, nk); ++a)
545
+	result += 2.0 * fbar_XXZ(tanhlambda, parj*park, tannzetaover2[fabs(nj - nk) + 2*a]);
565 546
 
566 547
       result += fbar_XXZ(tanhlambda, parj*park, tannzetaover2[nj + nk]);
567 548
     }
@@ -586,7 +567,8 @@ namespace ABACUS {
586 567
   {
587 568
     DP result = (nj == nk) ? 0.0 : hbar_XXZ(lambda, fabs(nj - nk), parj*park, si_n_anis_over_2);
588 569
 
589
-    for (int a = 1; a < ABACUS::min(nj, nk); ++a) result += 2.0 * hbar_XXZ(lambda, fabs(nj - nk) + 2*a, parj*park, si_n_anis_over_2);
570
+    for (int a = 1; a < ABACUS::min(nj, nk); ++a)
571
+      result += 2.0 * hbar_XXZ(lambda, fabs(nj - nk) + 2*a, parj*park, si_n_anis_over_2);
590 572
 
591 573
     result += hbar_XXZ(lambda, nj + nk, parj*park, si_n_anis_over_2);
592 574
 
@@ -641,6 +623,6 @@ namespace ABACUS {
641 623
       ReturnState.Ix2[0][i] = RefState.Ix2[0][i + (i >= RefState.base.Nrap[0]/2)] + 1 - 2*(i >= RefState.base.Nrap[0]/2);
642 624
 
643 625
     return(ReturnState);
644
-    }
626
+  }
645 627
 
646 628
 } // namespace ABACUS

+ 34
- 291
src/HEIS/XXZ_gpd_Bethe_State.cc View File

@@ -64,20 +64,12 @@ namespace ABACUS {
64 64
   {
65 65
     if (RefChain.Delta <= 1.0) ABACUSerror("Delta too low in XXZ_gpd_Bethe_State constructor");
66 66
   }
67
-  /*
68
-  XXZ_gpd_Bethe_State::XXZ_gpd_Bethe_State (const Heis_Chain& RefChain, long long int base_id_ref, long long int type_id_ref)
69
-    : Heis_Bethe_State(RefChain, base_id_ref, type_id_ref),
70
-      sinlambda(Lambda(chain, base)), coslambda(Lambda(chain, base)), tanlambda(Lambda(chain, base))
71
-  {
72
-    if (RefChain.Delta <= 1.0) ABACUSerror("Delta too low in XXZ_gpd_Bethe_State constructor");
73
-  }
74
-  */
67
+
75 68
   XXZ_gpd_Bethe_State& XXZ_gpd_Bethe_State::operator= (const XXZ_gpd_Bethe_State& RefState)
76 69
   {
77 70
     if (this != &RefState) {
78 71
       chain = RefState.chain;
79 72
       base = RefState.base;
80
-      //offsets = RefState.offsets;
81 73
       Ix2 = RefState.Ix2;
82 74
       lambda = RefState.lambda;
83 75
       BE = RefState.BE;
@@ -89,11 +81,6 @@ namespace ABACUS {
89 81
       iK = RefState.iK;
90 82
       K = RefState.K;
91 83
       lnnorm = RefState.lnnorm;
92
-      //base_id = RefState.base_id;
93
-      //type_id = RefState.type_id;
94
-      //id = RefState.id;
95
-      //maxid = RefState.maxid;
96
-      //nparticles = RefState.nparticles;
97 84
       label = RefState.label;
98 85
 
99 86
       sinlambda = RefState.sinlambda;
@@ -146,7 +133,6 @@ namespace ABACUS {
146 133
 
147 134
       for (int alpha = 0; alpha < base[j]; ++alpha) {
148 135
 	tanlambda[j][alpha] = tan(lambda[j][alpha]);
149
-	//if (lambda[j][alpha] > 0.5*PI) cout << "Rapidity higher than 0.5*PI:  j = " << j << "\talpha = " << alpha << "\trap = " << lambda[j][alpha] << "\ttan = " << tanlambda[j][alpha] << endl;
150 136
       }
151 137
     }
152 138
     return;
@@ -161,75 +147,6 @@ namespace ABACUS {
161 147
     bool answer = true;
162 148
     Vect<bool> Zero_at_level(false, chain.Nstrings); // whether there exists an Ix2 == 0 at a given level
163 149
 
164
-    /*
165
-    Vect<bool> min_Ix2_max_busy(false, chain.Nstrings);
166
-    Vect<bool> plus_Ix2_max_busy(false, chain.Nstrings);
167
-    for (int j = 0; j < chain.Nstrings; ++j)
168
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
169
-	if (Ix2[j][alpha] == -base.Ix2_max[j]) min_Ix2_max_busy[j] = true;
170
-	if (Ix2[j][alpha] == base.Ix2_max[j]) plus_Ix2_max_busy[j] = true;
171
-      }
172
-    */
173
-    /*
174
-    // State is not admissible if this is false:  -N/2 + 1 \leq \sum I^j_{\alpha} \leq N
175
-    int sum_all_Ix2 = 0;
176
-    for (int j = 0; j < chain.Nstrings; ++j)
177
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
178
-	sum_all_Ix2 += Ix2[j][alpha];
179
-      }
180
-    if (sum_all_Ix2 > chain.Nsites || sum_all_Ix2 <= -chain.Nsites) {
181
-      cout << "\tSum Ix2 out of fundamental interval: sum_all_Ix2 = " << sum_all_Ix2 << "\tfor N = " << chain.Nsites << endl;
182
-      return(false);
183
-    }
184
-    */
185
-    //Deactivated 2014 06 11, put in Heis_Form_Factor_Entry.cc
186
-    /*
187
-    // State is not admissible if I_max > 1/2 (N - \sum_k t_{jk} M_k) or I_min < -1/2 (N - sum_k...) + 1 at any level:
188
-    int sum1 = 0;
189
-    for (int j = 0; j < chain.Nstrings; ++j) {
190
-      sum1 = 0;
191
-      for (int k = 0; k < chain.Nstrings; ++k) {
192
-	sum1 += base[k] * (2 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1 : 0));
193
-      }
194
-      // Define limits...
195
-      //if (!((Nrap[j] + Ix2_max[j]) % 2)) Ix2_max[j] -= 1;
196
-
197
-      // This almost does it:  only missing are the states with one on -PI/2 and one on PI/2
198
-      if (base[j] >= 1 && (Ix2[j][0] <= -(chain.Nsites - sum1) ||
199
-			   (Ix2[j][base[j] - 1] - Ix2[j][0]) > 2*(chain.Nsites - sum1))) {
200
-	//cout << "\tAn Ix2 is out of interval at level " << j << endl;
201
-	//cout << Ix2[j][base[j] - 1] << "\t" << Ix2[j][0] << "\t" << chain.Nsites << "\t" << sum1 << endl;
202
-	return(false);
203
-      }
204
-    }
205
-    */
206
-
207
-    /*
208
-    // State is not admissible if both a min_ and plus_Ix2_max are busy simultaneously:
209
-    bool is_a_min_Ix2_max_busy = false;
210
-    for (int j = 0; j < chain.Nstrings; ++j) if (min_Ix2_max_busy[j]) is_a_min_Ix2_max_busy = true;
211
-    bool is_a_plus_Ix2_max_busy = false;
212
-    for (int j = 0; j < chain.Nstrings; ++j) if (plus_Ix2_max_busy[j]) is_a_plus_Ix2_max_busy = true;
213
-    */
214
-    /*
215
-    // State is not admissible if all min_Ix2_max are busy simultaneously:
216
-    bool any_min_Ix2_max_free = false;
217
-    for (int j = 0; j < chain.Nstrings; ++j)
218
-      if (base[j] > 0 && !min_Ix2_max_busy[j]) any_min_Ix2_max_free = true;
219
-    if (!any_min_Ix2_max_free) return(false);
220
-    */
221
-    /*
222
-    // State is not admissible if -Ix2_max, -Ix2_max + 2, ..., -Ix2_max + 2*(Str_L - 1) are busy:
223
-    for (int j = 0; j < chain.Nstrings; ++j)
224
-      if (base[j] > 0 && Ix2[j][0] <= -base.Ix2_max[j] + 2*(chain.Str_L[j] - 1))
225
-	return(false);
226
-    // Almost correct with above !
227
-    // State is not admissible if Ix2_max - 2, ..., Ix2_max - 2*(Str_L - 2) are busy (NB:  one slot more than on left):
228
-    for (int j = 0; j < chain.Nstrings; ++j)
229
-      if (base[j] > 0 && Ix2[j][base[j] - 1] >= base.Ix2_max[j] - 2*(chain.Str_L[j] - 2))
230
-	return(false);
231
-    */
232
-
233 150
     // Check that at all at least doubly occupied levels, the difference between max and min quantum numbers
234 151
     // is strictly smaller than 2*Ix2_max - 2, so that lambda_max - lambda_min < PI at each level:
235 152
     //for (int j = 0; j < chain.Nstrings; ++j)
@@ -242,7 +159,7 @@ namespace ABACUS {
242 159
     for (int j = 0; j < chain.Nstrings; ++j) {
243 160
       // The following line puts answer to true if there is at least one higher string with zero Ix2
244 161
       for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] == 0) && (chain.Str_L[j] > 2) /*&& !(chain.Str_L[j] % 2)*/)
245
-	higher_string_on_zero = true;
162
+						      higher_string_on_zero = true;
246 163
       for (int alpha = 0; alpha < base[j]; ++alpha) if (Ix2[j][alpha] == 0) Zero_at_level[j] = true;
247 164
       // NOTE:  if base[j] == 0, Zero_at_level[j] remains false.
248 165
     }
@@ -262,8 +179,6 @@ namespace ABACUS {
262 179
     //if (Zero_at_level[0] && Zero_at_level[1]) onep_onem_on_zero = true;
263 180
     //}
264 181
 
265
-    //cout << min_Ix2_max_busy << "\t" << symmetric_state  << "\t" << higher_string_on_zero << "\t" << string_coincidence << "\t" << onep_onem_on_zero << endl;
266
-
267 182
     //answer = !((symmetric_state && (higher_string_on_zero || string_coincidence || onep_onem_on_zero)));
268 183
     answer = !(symmetric_state && (higher_string_on_zero || string_coincidence));
269 184
 
@@ -274,7 +189,8 @@ namespace ABACUS {
274 189
     // Now check that no Ix2 is equal to +N (since we take -N into account, and I + N == I by periodicity of exp)
275 190
 
276 191
     for (int j = 0; j < chain.Nstrings; ++j)
277
-      for (int alpha = 0; alpha < base[j]; ++alpha) if ((Ix2[j][alpha] < -chain.Nsites) || (Ix2[j][alpha] >= chain.Nsites)) answer = false;
192
+      for (int alpha = 0; alpha < base[j]; ++alpha)
193
+	if ((Ix2[j][alpha] < -chain.Nsites) || (Ix2[j][alpha] >= chain.Nsites)) answer = false;
278 194
 
279 195
     if (!answer) {
280 196
       E = 0.0;
@@ -300,14 +216,15 @@ namespace ABACUS {
300 216
     for (int k = 0; k < chain.Nstrings; ++k) {
301 217
       for (int beta = 0; beta < base[k]; ++beta)
302 218
 	if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1)) {
303
-	  sumtheta += atan ((tanlambda[j][alpha] - tanlambda[k][beta])/((1.0 + tanlambda[j][alpha] * tanlambda[k][beta])
304
-									* chain.ta_n_anis_over_2[2]))
219
+	  sumtheta += atan ((tanlambda[j][alpha] - tanlambda[k][beta])
220
+			    /((1.0 + tanlambda[j][alpha] * tanlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
305 221
 	    + PI * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
306 222
 	}
307
-	else sumtheta += 0.5 * Theta_XXZ_gpd((tanlambda[j][alpha] - tanlambda[k][beta])/(1.0 + tanlambda[j][alpha] * tanlambda[k][beta]),
223
+	else sumtheta += 0.5 * Theta_XXZ_gpd((tanlambda[j][alpha] - tanlambda[k][beta])
224
+					     /(1.0 + tanlambda[j][alpha] * tanlambda[k][beta]),
308 225
 					     chain.Str_L[j], chain.Str_L[k], chain.ta_n_anis_over_2)
309
-	  + PI * (2.0 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1.0 : 0))
310
-	  * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
226
+	       + PI * (2.0 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1.0 : 0))
227
+	       * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
311 228
     }
312 229
     sumtheta *= 2.0;
313 230
 
@@ -331,14 +248,15 @@ namespace ABACUS {
331 248
 	for (int k = 0; k < chain.Nstrings; ++k) {
332 249
 	  for (int beta = 0; beta < base[k]; ++beta)
333 250
 	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1)) {
334
-	      sumtheta += atan ((tanlambda[j][alpha] - tanlambda[k][beta])/((1.0 + tanlambda[j][alpha] * tanlambda[k][beta])
335
-									    * chain.ta_n_anis_over_2[2]))
251
+	      sumtheta += atan ((tanlambda[j][alpha] - tanlambda[k][beta])
252
+				/((1.0 + tanlambda[j][alpha] * tanlambda[k][beta]) * chain.ta_n_anis_over_2[2]))
336 253
 		+ PI * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
337 254
 	    }
338
-	    else sumtheta += 0.5 * Theta_XXZ_gpd((tanlambda[j][alpha] - tanlambda[k][beta])/(1.0 + tanlambda[j][alpha] * tanlambda[k][beta]),
255
+	    else sumtheta += 0.5 * Theta_XXZ_gpd((tanlambda[j][alpha] - tanlambda[k][beta])
256
+						 /(1.0 + tanlambda[j][alpha] * tanlambda[k][beta]),
339 257
 						 chain.Str_L[j], chain.Str_L[k], chain.ta_n_anis_over_2)
340
-	      + PI * (2.0 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1.0 : 0))
341
-	      * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
258
+		   + PI * (2.0 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1.0 : 0))
259
+		   * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
342 260
 	}
343 261
 	sumtheta *= 2.0;
344 262
 
@@ -355,170 +273,19 @@ namespace ABACUS {
355 273
 
356 274
     DP arg0 = 0.5 * (2.0 * (atan(tanlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
357 275
 			    + PI * floor(0.5 + lambda[j][alpha]/PI)) - BE[j][alpha]);
358
-    DP arg = chain.ta_n_anis_over_2[chain.Str_L[j]] * tan(
359
-							  arg0
360
-							  //0.5 *
361
-							  //(PI * Ix2[j][alpha] + sumtheta)/chain.Nsites
362
-							  //(2.0 * (atan(tanlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
363
-							  //  + PI * floor(0.5 + lambda[j][alpha]/PI)) - BE[j][alpha])
364
-							  );
365
-
366
-    return(atan(arg)
367
-	   //+ PI * floor(0.5 + arg0)
368
-				  //0.5 * (Ix2[j][alpha] + sumtheta/PI)/(chain.Nsites)
369
-	   + PI * floor(0.5 + arg0/PI)
370
-				  );
371
-
372
-  }
373
-  /*
374
-  void XXZ_gpd_Bethe_State::Iterate_BAE ()
375
-  {
376
-    // Recalculates the rapidities by iterating Bethe equations
276
+    DP arg = chain.ta_n_anis_over_2[chain.Str_L[j]] * tan(arg0);
377 277
 
378
-    Lambda New_lambda(chain, base);
379
-    DP sumtheta = 0.0;
380
-    DP arg = 0.0;
278
+    return(atan(arg) + PI * floor(0.5 + arg0/PI));
381 279
 
382
-    // First, compute the tan of rapidities:
383
-    (*this).Compute_tanlambda();
384
-
385
-    for (int j = 0; j < chain.Nstrings; ++j) {
386
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
387
-
388
-	sumtheta = 0.0;
389
-	for (int k = 0; k < chain.Nstrings; ++k) {
390
-	  for (int beta = 0; beta < base[k]; ++beta)
391
-	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
392
-	      sumtheta += atan((tanlambda[j][alpha] - tanlambda[k][beta])/((1.0 + tanlambda[j][alpha] * tanlambda[k][beta])
393
-									   * chain.ta_n_anis_over_2[2]))
394
-		+ PI * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
395
-
396
-	    else sumtheta += 0.5 * Theta_XXZ_gpd((tanlambda[j][alpha] - tanlambda[k][beta])/(1.0 + tanlambda[j][alpha] * tanlambda[k][beta]),
397
-					     chain.Str_L[j], chain.Str_L[k], chain.ta_n_anis_over_2)
398
-	      + PI * (2.0 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1.0 : 0))
399
-	      * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
400
-	}
401
-	sumtheta *= 2.0;
402
-
403
-	arg = chain.ta_n_anis_over_2[chain.Str_L[j]] * tan((PI * 0.5 * Ix2[j][alpha] + 0.5 * sumtheta)/chain.Nsites);
404
-
405
-	New_lambda[j][alpha] = atan(arg) + PI * floor(0.5 + (0.5 * Ix2[j][alpha] + 0.5 * sumtheta/PI)/(chain.Nsites));
406
-
407
-      }
408
-    }
409
-
410
-    DP New_diffsq = 0.0;
411
-
412
-    for (int j = 0; j < chain.Nstrings; ++j) {
413
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
414
-	//New_diffsq += pow(tan(New_lambda[j][alpha]) - tanlambda[j][alpha], 2.0);
415
-	New_diffsq += pow(New_lambda[j][alpha] - lambda[j][alpha], 2.0);
416
-	lambda[j][alpha] = 1.0 * New_lambda[j][alpha] + 0.0 * lambda[j][alpha];
417
-      }
418
-    }
419
-
420
-    diffsq = New_diffsq;
421
-    iter++;
422
-
423
-    return;
424 280
   }
425
-  */
426
-  /*
427
-  void XXZ_gpd_Bethe_State::Iterate_BAE_Newton ()
428
-  {
429
-    // does one step of a Newton method on the rapidities...
430
-
431
-    Vect_DP RHSBAE (0.0, base.Nraptot);  // contains RHS of BAEs
432
-    Vect_CX dlambda (0.0, base.Nraptot);  // contains delta lambda computed from Newton's method
433
-    SQMat_CX Gaudin (0.0, base.Nraptot);
434
-    Vect_INT indx (base.Nraptot);
435
-    DP sumtheta = 0.0;
436
-    DP arg = 0.0;
437
-    DP fn_arg = 0.0;
438
-    DP olddiffsq = diffsq;
439
-
440
-    // Compute the RHS of the BAEs:
441 281
 
442
-    int index = 0;
443
-
444
-    (*this).Compute_tanlambda();
445
-
446
-    for (int j = 0; j < chain.Nstrings; ++j) {
447
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
448
-
449
-	sumtheta = 0.0;
450
-	for (int k = 0; k < chain.Nstrings; ++k) {
451
-	  for (int beta = 0; beta < base[k]; ++beta)
452
-	    if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1)) {
453
-	      sumtheta += atan ((tanlambda[j][alpha] - tanlambda[k][beta])/((1.0 + tanlambda[j][alpha] * tanlambda[k][beta])
454
-									    * chain.ta_n_anis_over_2[2]))
455
-		+ PI * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
456
-	    }
457
-	    else sumtheta += 0.5 * Theta_XXZ_gpd((tanlambda[j][alpha] - tanlambda[k][beta])/(1.0 + tanlambda[j][alpha] * tanlambda[k][beta]),
458
-					     chain.Str_L[j], chain.Str_L[k], chain.ta_n_anis_over_2)
459
-	      + PI * (2.0 * ABACUS::min(chain.Str_L[j], chain.Str_L[k]) - ((j == k) ? 1.0 : 0))
460
-	      * floor(0.5 + (lambda[j][alpha] - lambda[k][beta])/PI);
461
-	}
462
-	sumtheta *= 2.0;
463
-
464
-	RHSBAE[index] = chain.Nsites * 2.0 * (atan(tanlambda[j][alpha]/chain.ta_n_anis_over_2[chain.Str_L[j]])
465
-       					      + PI * floor(0.5 + lambda[j][alpha]/PI))
466
-					      //					      )
467
-	  - sumtheta - PI*Ix2[j][alpha];
468
-	index++;
469
-      }
470
-    }
471
-
472
-    (*this).Build_Reduced_Gaudin_Matrix (Gaudin);
473
-
474
-    for (int i = 0; i < base.Nraptot; ++i) dlambda[i] = - RHSBAE[i];
475
-
476
-    DP d;
477
-    ludcmp_CX (Gaudin, indx, d);
478
-    lubksb_CX (Gaudin, indx, dlambda);
479
-
480
-    diffsq = 0.0;
481
-    //    for (int i = 0; i < base.Nraptot; ++i) diffsq += norm(dlambda[i]);
482
-    int ctr = 0;
483
-    for (int j = 0; j < chain.Nstrings; ++j) {
484
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
485
-	diffsq += norm(tan(lambda[j][alpha] + dlambda[ctr]) - tanlambda[j][alpha]);
486
-	//	cout << "lambda = " << lambda[j][alpha] << "\tdlambda = " << dlambda[ctr] << endl;
487
-	ctr++;
488
-      }
489
-    }
490
-
491
-    // if we've converged, calculate the norm here, since the work has been done...
492
-
493
-    if (diffsq < chain.prec) {
494
-      lnnorm = 0.0;
495
-      for (int j = 0; j < base.Nraptot; j++) lnnorm += log(abs(Gaudin[j][j]));
496
-    }
497
-
498
-    index = 0;
499
-    for (int j = 0; j < chain.Nstrings; ++j) {
500
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
501
-	lambda[j][alpha] += real(dlambda[index]);
502
-	index++;
503
-      }
504
-    }
505
-
506
-    iter_Newton++;
507
-
508
-    //    cout << "iter_N = " << iter_Newton << "\t" << diffsq << endl;
509
-
510
-    return;
511
-  }
512
-  */
513 282
   bool XXZ_gpd_Bethe_State::Check_Rapidities()
514 283
   {
515 284
     bool nonan = true;
516 285
 
517 286
     for (int j = 0; j < chain.Nstrings; ++j)
518
-      for (int alpha = 0; alpha < base[j]; ++alpha) if (nonan) nonan = ((!is_nan(lambda[j][alpha]))
519
-									//&& (lambda[j][alpha] > -0.5*PI*chain.Str_L[j])
520
-									//&& (lambda[j][alpha] <= 0.5*PI*chain.Str_L[j])
521
-									);
287
+      for (int alpha = 0; alpha < base[j]; ++alpha)
288
+	if (nonan) nonan = ((!is_nan(lambda[j][alpha])));
522 289
 
523 290
     bool all_within_pi_interval = true;
524 291
     DP min_lambda = 10.0;
@@ -544,9 +311,8 @@ namespace ABACUS {
544 311
     DP delta = 0.0;
545 312
 
546 313
     int occupied_strings = 0;
547
-    for (int i = 0; i < (*this).chain.Nstrings; ++i) if ((*this).chain.Str_L[i] > 1) occupied_strings += (*this).base.Nrap[i];
548
-
549
-    //if ((*this).conv == 0) delta = 1.0;
314
+    for (int i = 0; i < (*this).chain.Nstrings; ++i)
315
+      if ((*this).chain.Str_L[i] > 1) occupied_strings += (*this).base.Nrap[i];
550 316
 
551 317
     if (occupied_strings == 0) delta = 0.0;
552 318
 
@@ -567,8 +333,9 @@ namespace ABACUS {
567 333
 	    if ((*this).chain.Str_L[j] > 1) {  // else the BAE are already 1
568 334
 
569 335
 	      log_BAE_reg = DP((*this).chain.Nsites) * log(sin((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis
570
-							     * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a + 1.0))
571
-			    /sin((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a - 1.0)));
336
+							       * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a + 1.0))
337
+							   /sin((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis
338
+								* ((*this).chain.Str_L[j] + 1.0 - 2.0 * a - 1.0)));
572 339
 
573 340
 	      for (int k = 0; k < (*this).chain.Nstrings; ++k)
574 341
 		for (int beta = 0; beta < (*this).base[k]; ++beta)
@@ -576,13 +343,13 @@ namespace ABACUS {
576 343
 		    if ((j != k) || (alpha != beta) || (a != b - 1))
577 344
 
578 345
 		      log_BAE_reg += log(sin(((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a ))
579
-				      - ((*this).lambda[k][beta] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b ))
346
+					     - ((*this).lambda[k][beta] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b ))
580 347
 					     - II * (*this).chain.anis));
581 348
 
582 349
 		    if ((j != k) || (alpha != beta) || (a != b + 1))
583 350
 
584 351
 		      log_BAE_reg -= log(sin(((*this).lambda[j][alpha] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[j] + 1.0 - 2.0 * a ))
585
-				      - ((*this).lambda[k][beta] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b ))
352
+					     - ((*this).lambda[k][beta] + 0.5 * II * (*this).chain.anis * ((*this).chain.Str_L[k] + 1.0 - 2.0 * b ))
586 353
 					     + II * (*this).chain.anis));
587 354
 		  }
588 355
 
@@ -631,32 +398,6 @@ namespace ABACUS {
631 398
     return;
632 399
   }
633 400
 
634
-  /*
635
-  void XXZ_gpd_Bethe_State::Compute_Momentum ()
636
-  {
637
-    int sum_Ix2 = 0;
638
-    DP sum_M = 0.0;
639
-
640
-    for (int j = 0; j < chain.Nstrings; ++j) {
641
-      sum_M += base[j];
642
-      for (int alpha = 0; alpha < base[j]; ++alpha) {
643
-	sum_Ix2 += Ix2[j][alpha];
644
-      }
645
-    }
646
-
647
-    iK = (chain.Nsites/2) * int(sum_M) - (sum_Ix2/2);
648
-
649
-    while (iK >= chain.Nsites) iK -= chain.Nsites;
650
-    while (iK < 0) iK += chain.Nsites;
651
-
652
-    K = PI * sum_M - PI * sum_Ix2/chain.Nsites;
653
-
654
-    while (K >= 2.0*PI) K -= 2.0*PI;
655
-    while (K < 0.0) K += 2.0*PI;
656
-
657
-    return;
658
-  }
659
-  */
660 401
 
661 402
   void XXZ_gpd_Bethe_State::Build_Reduced_Gaudin_Matrix (SQMat<complex<DP> >& Gaudin_Red)
662 403
   {
@@ -689,7 +430,7 @@ namespace ABACUS {
689 430
 		  if (!((j == kp) && (alpha == betap)))
690 431
 		    sum_hbar_XXZ
691 432
 		      += ddlambda_Theta_XXZ_gpd (lambda[j][alpha] - lambda[kp][betap], chain.Str_L[j], chain.Str_L[kp],
692
-					     chain.si_n_anis_over_2);
433
+						 chain.si_n_anis_over_2);
693 434
 		}
694 435
 	      }
695 436
 
@@ -701,7 +442,7 @@ namespace ABACUS {
701 442
 	      if ((chain.Str_L[j] == 1) && (chain.Str_L[k] == 1))
702 443
 		Gaudin_Red[index_jalpha][index_kbeta] =
703 444
 		  complex<DP> (chain.si_n_anis_over_2[4]/(pow(sinlambda[j][alpha] * coslambda[k][beta]
704
-							       - coslambda[j][alpha] * sinlambda[k][beta], 2.0) + sinhetasq));
445
+							      - coslambda[j][alpha] * sinlambda[k][beta], 2.0) + sinhetasq));
705 446
 	      else
706 447
 		Gaudin_Red[index_jalpha][index_kbeta] = complex<DP> (ddlambda_Theta_XXZ_gpd (lambda[j][alpha] - lambda[k][beta], chain.Str_L[j],
707 448
 											     chain.Str_L[k], chain.si_n_anis_over_2));
@@ -736,7 +477,8 @@ namespace ABACUS {
736 477
 
737 478
       result = (nj == nk) ? 0.0 : fbar_XXZ_gpd(tanlambda, tanhnetaover2[fabs(nj - nk)]);
738 479
 
739
-      for (int a = 1; a < ABACUS::min(nj, nk); ++a) result += 2.0 * fbar_XXZ_gpd(tanlambda, tanhnetaover2[fabs(nj - nk) + 2*a]);
480
+      for (int a = 1; a < ABACUS::min(nj, nk); ++a)
481
+	result += 2.0 * fbar_XXZ_gpd(tanlambda, tanhnetaover2[fabs(nj - nk) + 2*a]);
740 482
 
741 483
       result += fbar_XXZ_gpd(tanlambda, tanhnetaover2[nj + nk]);
742 484
     }
@@ -753,7 +495,8 @@ namespace ABACUS {
753 495
   {
754 496
     DP result = (nj == nk) ? 0.0 : hbar_XXZ_gpd(lambda, fabs(nj - nk), si_n_anis_over_2);
755 497
 
756
-    for (int a = 1; a < ABACUS::min(nj, nk); ++a) result += 2.0 * hbar_XXZ_gpd(lambda, fabs(nj - nk) + 2*a, si_n_anis_over_2);
498
+    for (int a = 1; a < ABACUS::min(nj, nk); ++a)
499
+      result += 2.0 * hbar_XXZ_gpd(lambda, fabs(nj - nk) + 2*a, si_n_anis_over_2);
757 500
 
758 501
     result += hbar_XXZ_gpd(lambda, nj + nk, si_n_anis_over_2);
759 502
 
@@ -808,6 +551,6 @@ namespace ABACUS {
808 551
       ReturnState.Ix2[0][i] = RefState.Ix2[0][i + (i >= RefState.base.Nrap[0]/2)] + 1 - 2*(i >= RefState.base.Nrap[0]/2);
809 552
 
810 553
     return(ReturnState);
811
-    }
554
+  }
812 555
 
813 556
 } // namespace ABACUS

+ 142
- 181
src/HEIS/ln_Overlap_XXX.cc View File

@@ -19,240 +19,201 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
23
-{
24
-  complex<DP> ans = 0.0;
25
-
26
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
27
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
28
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
29
-
30
-	if (!((j == k) && (alpha == beta) && (a == b)))
31
-	  ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
32
-		     + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
22
+  inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
23
+  {
24
+    complex<DP> ans = 0.0;
25
+
26
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
27
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
28
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
29
+
30
+	  if (!((j == k) && (alpha == beta) && (a == b)))
31
+	    ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
32
+		       + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
33
+	}
33 34
       }
34 35
     }
35
-  }
36 36
 
37
-  return(ans);
38
-}
37
+    return(ans);
38
+  }
39 39
 
40
-inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
41
-{
42
-  complex<DP> ans = 0.0;
40
+  inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
41
+  {
42
+    complex<DP> ans = 0.0;
43 43
 
44
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
45
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
46
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
44
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
45
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
46
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
47 47
 
48
-	ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
49
-		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
48
+	  ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
49
+		     + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
50
+	}
50 51
       }
51 52
     }
53
+
54
+    return(ans);
52 55
   }
53 56
 
54
-  return(ans);
55
-}
56
-
57
-inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
58
-{
59
-  return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
60
-	       + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
61
-	      * (A.lambda[j][alpha] - B.lambda[k][beta]
62
-		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
63
-}
64
-
65
-inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
66
-{
67
-  return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
68
-		      + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
69
-		      ))
70
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
71
-}
72
-
73
-complex<DP> ln_Overlap (XXX_Bethe_State& A, XXX_Bethe_State& B)
74
-{
75
-  // This function returns the overlap of states A and B.
76
-  // The A and B states can contain strings.
77
-
78
-  // IMPORTANT ASSUMPTIONS:
79
-  // - State B is an eigenstate of the model on which the overlap measure is defined
80
-
81
-  // Check that A and B are compatible:  same Mdown
82
-
83
-  if (A.base.Mdown != B.base.Mdown) return(complex<DP>(-300.0));  // overlap vanishes
84
-
85
-  // Some convenient arrays
86
-
87
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
88
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
89
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
90
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
91
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
92
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
93
-
94
-  //complex<DP> ln_prod1 = 0.0;
95
-  //complex<DP> ln_prod2 = 0.0;
96
-  complex<DP> ln_prod3 = 0.0;
97
-  complex<DP> ln_prod4 = 0.0;
98
-
99
-  /*
100
-  for (int i = 0; i < A.chain.Nstrings; ++i)
101
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
102
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
103
-	ln_prod1 += log(norm((A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
104
-
105
-  for (int i = 0; i < B.chain.Nstrings; ++i)
106
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
107
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
108
-	if (norm((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))) > 100.0 * MACHINE_EPS_SQ)
109
-	  ln_prod2 += log(norm((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
110
-  */
111
-
112
-  // Define the F ones earlier...
113
-
114
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
115
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
116
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
117
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
118
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
119
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
120
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
121
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
122
-    }
57
+  inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
58
+  {
59
+    return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
60
+		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
61
+		* (A.lambda[j][alpha] - B.lambda[k][beta]
62
+		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
123 63
   }
124 64
 
125
-  // Define regularized products in prefactors
65
+  inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
66
+  {
67
+    return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
68
+		    + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
69
+		    ))
70
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
71
+  }
126 72
 
127
-  for (int j = 0; j < A.chain.Nstrings; ++j)
128
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
129
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
130
-	ln_prod3 += ln_Fn_F (A, j, alpha, a - 1);
73
+  complex<DP> ln_Overlap (XXX_Bethe_State& A, XXX_Bethe_State& B)
74
+  {
75
+    // This function returns the overlap of states A and B.
76
+    // The A and B states can contain strings.
131 77
 
132
-  //  ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.zeta)));
78
+    // IMPORTANT ASSUMPTIONS:
79
+    // - State B is an eigenstate of the model on which the overlap measure is defined
133 80
 
134
-  for (int k = 0; k < B.chain.Nstrings; ++k)
135
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
136
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
137
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
138
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
139
-    }
81
+    // Check that A and B are compatible:  same Mdown
140 82
 
141
-  //  ln_prod4 -= B.base.Mdown * log(abs(sin(B.chain.zeta)));
83
+    if (A.base.Mdown != B.base.Mdown) return(complex<DP>(-300.0));  // overlap vanishes
142 84
 
143
-  // Now proceed to build the Hm2P matrix
85
+    // Some convenient arrays
144 86
 
145
-  SQMat_CX Hm2P(0.0, A.base.Mdown);
87
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
88
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
89
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
90
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
91
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
92
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
146 93
 
147
-  int index_a = 0;
148
-  int index_b = 0;
94
+    complex<DP> ln_prod3 = 0.0;
95
+    complex<DP> ln_prod4 = 0.0;
149 96
 
150
-  complex<DP> sum1 = 0.0;
151
-  //complex<DP> sum2 = 0.0;
152
-  complex<DP> prod_num = 0.0;
153
-  complex<DP> Fn_K_0_G_0 = 0.0;
154
-  complex<DP> Prod_powerN = 0.0;
155
-  complex<DP> Fn_K_1_G_2 = 0.0;
156
-  //complex<DP> two_over_A_lambda_sq_plus_1over2sq;
97
+    // Define the F ones earlier...
157 98
 
158
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
159
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
160
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
99
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
100
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
101
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
102
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
103
+	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
104
+	im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
105
+	re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
106
+	im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
107
+      }
108
+    }
109
+
110
+    // Define regularized products in prefactors
111
+
112
+    for (int j = 0; j < A.chain.Nstrings; ++j)
113
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
114
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a)
115
+	  ln_prod3 += ln_Fn_F (A, j, alpha, a - 1);
161 116
 
162
-	index_b = 0;
117
+    //  ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.zeta)));
163 118
 
164
-	//two_over_A_lambda_sq_plus_1over2sq = 2.0/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *
165
-	//				  (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
119
+    for (int k = 0; k < B.chain.Nstrings; ++k)
120
+      for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
121
+	for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
122
+	  if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
123
+	  else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
124
+	}
166 125
 
167
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
168
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
169
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
126
+    // Now proceed to build the Hm2P matrix
170 127
 
171
-	      if (B.chain.Str_L[k] == 1) {
128
+    SQMat_CX Hm2P(0.0, A.base.Mdown);
172 129
 
173
-		// use simplified code for one-string here:  original form of Hm2P matrix
130
+    int index_a = 0;
131
+    int index_b = 0;
174 132
 
175
-		Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
176
-		  exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
177
-		Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
178
-		  exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
133
+    complex<DP> sum1 = 0.0;
134
+    complex<DP> prod_num = 0.0;
135
+    complex<DP> Fn_K_0_G_0 = 0.0;
136
+    complex<DP> Prod_powerN = 0.0;
137
+    complex<DP> Fn_K_1_G_2 = 0.0;
179 138
 
180
-		//Prod_powerN = pow((B.lambda[k][beta]  + 0.5 * II)/(B.lambda[k][beta] - 0.5 * II), complex<DP> (B.chain.Nsites));
181
-		Prod_powerN = pow((B.lambda[k][beta]  + 0.5 * II)/(B.lambda[k][beta] - 0.5 * II), complex<DP> (A.chain.Nsites));  // careful !
139
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
140
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
141
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
182 142
 
183
-		Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
184
-		  //- two_over_A_lambda_sq_plus_1over2sq * exp(II*im_ln_Fn_F_B_0[k][beta]);
185
-		  ;
186
-	      }
143
+	  index_b = 0;
187 144
 
188
-	      else {
145
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
146
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
147
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
189 148
 
190
-		if (b <= B.chain.Str_L[k] - 1) Hm2P[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
191
-		else if (b == B.chain.Str_L[k]) {
149
+		if (B.chain.Str_L[k] == 1) {
192 150
 
193
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
194
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
151
+		  // use simplified code for one-string here:  original form of Hm2P matrix
195 152
 
196
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
197
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
153
+		  Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
154
+		    exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
155
+		  Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
156
+		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
198 157
 
199
-		  sum1 = 0.0;
158
+		  Prod_powerN = pow((B.lambda[k][beta]  + 0.5 * II)/(B.lambda[k][beta] - 0.5 * II),
159
+				    complex<DP> (A.chain.Nsites));  // careful !
200 160
 
201
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
161
+		  Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
162
+		    ;
163
+		}
202 164
 
203
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
204
-		    * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
205
-			  - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
165
+		else {
206 166
 
207
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
167
+		  if (b <= B.chain.Str_L[k] - 1) Hm2P[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
168
+		  else if (b == B.chain.Str_L[k]) {
208 169
 
209
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
210
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
170
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
171
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
211 172
 
212
-		  //sum2 = 0.0;
173
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
174
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
213 175
 
214
-		  //for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
176
+		    sum1 = 0.0;
215 177
 
216
-		  prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]]);
178
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0)
179
+		      * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
217 180
 
218
-		  for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
219
-		    prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1))); // include all string contributions F_B_0 in this term
181
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
182
+		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
183
+			    - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
220 184
 
221
-		  //Hm2P[index_a][index_b] = prod_num * (sum1 - sum2 * two_over_A_lambda_sq_plus_1over2sq);
222
-		  Hm2P[index_a][index_b] = prod_num * sum1;
185
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
223 186
 
224
-		} // else if (b == B.chain.Str_L[k])
225
-	      } // else
187
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
188
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
226 189
 
227
-	      index_b++;
228
-	    }}} // sums over k, beta, b
190
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]]);
229 191
 
230
-	index_a++;
231
-      }}} // sums over j, alpha, a
192
+		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
193
+		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)));
194
+		    // include all string contributions F_B_0 in this term
232 195
 
233
-  //cout << "Matrix: " << endl;
234
-  //Hm2P.Print();
196
+		    Hm2P[index_a][index_b] = prod_num * sum1;
235 197
 
236
-  complex<DP> det = lndet_LU_CX_dstry(Hm2P);
198
+		  } // else if (b == B.chain.Str_L[k])
199
+		} // else
237 200
 
238
-  /*
239
-  complex<DP> ln_form_factor_sq = log(0.25 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
240
-    //    + 2.0 * real(lndet_LU_CX_dstry(Hm2P))
241
-    + 2.0 * det
242
-    - A.lnnorm - B.lnnorm;
201
+		index_b++;
202
+	      }}} // sums over k, beta, b
243 203
 
244
-  //cout << "ln_SZ: " << endl << ln_prod1 << "\t" << -ln_prod2 << "\t" << -ln_prod3 << "\t" << ln_prod4 << "\t" << 2.0 * det
245
-  //   << "\t" << -A.lnnorm << "\t" << -B.lnnorm << endl;
204
+	  index_a++;
205
+	}}} // sums over j, alpha, a
246 206
 
247
-  return(ln_form_factor_sq);
248
-  */
249
-  complex<DP> ln_overlap = 0.5 * (-ln_prod3 + ln_prod4) + det - 0.5 * (A.lnnorm + B.lnnorm);
250 207
 
251
-  cout << "ln_overlap: " << endl << -ln_prod3 << "\t" << ln_prod4 << "\t" << 2.0 * det
252
-       << "\t" << -A.lnnorm << "\t" << -B.lnnorm << endl;
208
+    complex<DP> det = lndet_LU_CX_dstry(Hm2P);
253 209
 
254
-  return(ln_overlap);
210
+    complex<DP> ln_overlap = 0.5 * (-ln_prod3 + ln_prod4) + det - 0.5 * (A.lnnorm + B.lnnorm);
255 211
 
256
-}
212
+    cout << "ln_overlap: " << endl << -ln_prod3 << "\t" << ln_prod4 << "\t" << 2.0 * det
213
+	 << "\t" << -A.lnnorm << "\t" << -B.lnnorm << endl;
214
+
215
+    return(ln_overlap);
216
+
217
+  }
257 218
 
258 219
 } // namespace ABACUS

+ 166
- 180
src/HEIS/ln_Smin_ME_XXX.cc View File

@@ -19,236 +19,222 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
23
-{
24
-  complex<DP> ans = 0.0;
25
-
26
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
27
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
28
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
29
-
30
-	if (!((j == k) && (alpha == beta) && (a == b)))
31
-	  ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
32
-		     + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
22
+  inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
23
+  {
24
+    complex<DP> ans = 0.0;
25
+
26
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
27
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
28
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
29
+
30
+	  if (!((j == k) && (alpha == beta) && (a == b)))
31
+	    ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
32
+		       + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
33
+	}
33 34
       }
34 35
     }
35
-  }
36 36
 
37
-  return(ans);
38
-}
37
+    return(ans);
38
+  }
39 39
 
40
-inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
41
-{
42
-  complex<DP> ans = 0.0;
40
+  inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
41
+  {
42
+    complex<DP> ans = 0.0;
43 43
 
44
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
45
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
46
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
44
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
45
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
46
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
47 47
 
48
-	ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
49
-		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
48
+	  ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
49
+		     + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
50
+	}
50 51
       }
51 52
     }
52
-  }
53 53
 
54
-  return(ans);
55
-}
56
-
57
-inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
58
-{
59
-  return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
60
-	       + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
61
-	      * (A.lambda[j][alpha] - B.lambda[k][beta]
62
-		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
63
-}
64
-
65
-inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
66
-{
67
-  return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
68
-		      + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
69
-		      ))
70
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
71
-}
72
-
73
-complex<DP> ln_Smin_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
74
-{
75
-  // This function returns the natural log of the S^- operator matrix element.
76
-  // The A and B states can contain strings.
77
-
78
-  // Check that the two states are compatible
79
-
80
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Smin matrix element.");
81
-
82
-  // Check that A and B are Mdown-compatible:
83
-
84
-  if (A.base.Mdown != B.base.Mdown + 1) ABACUSerror("Incompatible Mdown between the two states in Smin matrix element!");
85
-
86
-  // Some convenient arrays
87
-
88
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
89
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
90
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
91
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
92
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
93
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
94
-
95
-  complex<DP> ln_prod1 = 0.0;
96
-  complex<DP> ln_prod2 = 0.0;
97
-  complex<DP> ln_prod3 = 0.0;
98
-  complex<DP> ln_prod4 = 0.0;
99
-
100
-  for (int i = 0; i < A.chain.Nstrings; ++i)
101
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
102
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
103
-	ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
104
-
105
-  for (int i = 0; i < B.chain.Nstrings; ++i)
106
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
107
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
108
-	if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
109
-	  ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
110
-
111
-  // Define the F ones earlier...
112
-
113
-  complex<DP> ln_FB0, ln_FG0, ln_FG2;
114
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
115
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
116
-      //re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
117
-      //im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
118
-      ln_FB0 = ln_Fn_F(B, j, alpha, 0);
119
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_FB0);
120
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_FB0);
121
-      //re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
122
-      //im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
123
-      ln_FG0 = ln_Fn_G(A, B, j, alpha, 0);
124
-      re_ln_Fn_G_0[j][alpha] = real(ln_FG0);
125
-      im_ln_Fn_G_0[j][alpha] = imag(ln_FG0);
126
-      //re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
127
-      //im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
128
-      ln_FG2 = ln_Fn_G(A, B, j, alpha, 2);
129
-      re_ln_Fn_G_2[j][alpha] = real(ln_FG2);
130
-      im_ln_Fn_G_2[j][alpha] = imag(ln_FG2);
131
-    }
54
+    return(ans);
132 55
   }
133 56
 
134
-  // Define regularized products in prefactors
135
-
136
-  for (int j = 0; j < A.chain.Nstrings; ++j)
137
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
138
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
139
-	ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
57
+  inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
58
+  {
59
+    return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
60
+		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
61
+		* (A.lambda[j][alpha] - B.lambda[k][beta]
62
+		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
63
+  }
140 64
 
141
-  //  ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.zeta)));
65
+  inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
66
+  {
67
+    return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
68
+		    + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
69
+		    ))
70
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
71
+  }
142 72
 
143
-  for (int k = 0; k < B.chain.Nstrings; ++k)
144
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
145
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
146
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
147
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
73
+  complex<DP> ln_Smin_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
74
+  {
75
+    // This function returns the natural log of the S^- operator matrix element.
76
+    // The A and B states can contain strings.
77
+
78
+    // Check that the two states are compatible
79
+
80
+    if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Smin matrix element.");
81
+
82
+    // Check that A and B are Mdown-compatible:
83
+
84
+    if (A.base.Mdown != B.base.Mdown + 1)
85
+      ABACUSerror("Incompatible Mdown between the two states in Smin matrix element!");
86
+
87
+    // Some convenient arrays
88
+
89
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
90
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
91
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
92
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
93
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
94
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
95
+
96
+    complex<DP> ln_prod1 = 0.0;
97
+    complex<DP> ln_prod2 = 0.0;
98
+    complex<DP> ln_prod3 = 0.0;
99
+    complex<DP> ln_prod4 = 0.0;
100
+
101
+    for (int i = 0; i < A.chain.Nstrings; ++i)
102
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
103
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
104
+	  ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
105
+
106
+    for (int i = 0; i < B.chain.Nstrings; ++i)
107
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
108
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
109
+	  if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
110
+	    ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
111
+
112
+    // Define the F ones earlier...
113
+
114
+    complex<DP> ln_FB0, ln_FG0, ln_FG2;
115
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
116
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
117
+	ln_FB0 = ln_Fn_F(B, j, alpha, 0);
118
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_FB0);
119
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_FB0);
120
+	ln_FG0 = ln_Fn_G(A, B, j, alpha, 0);
121
+	re_ln_Fn_G_0[j][alpha] = real(ln_FG0);
122
+	im_ln_Fn_G_0[j][alpha] = imag(ln_FG0);
123
+	ln_FG2 = ln_Fn_G(A, B, j, alpha, 2);
124
+	re_ln_Fn_G_2[j][alpha] = real(ln_FG2);
125
+	im_ln_Fn_G_2[j][alpha] = imag(ln_FG2);
126
+      }
148 127
     }
149 128
 
150
-  //  ln_prod4 -= B.base.Mdown * log(abs(sin(B.chain.zeta)));
129
+    // Define regularized products in prefactors
151 130
 
152
-  // Now proceed to build the Hm matrix
131
+    for (int j = 0; j < A.chain.Nstrings; ++j)
132
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
133
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a)
134
+	  ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
153 135
 
154
-  SQMat_CX Hm(0.0, A.base.Mdown);
136
+    for (int k = 0; k < B.chain.Nstrings; ++k)
137
+      for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
138
+	for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
139
+	  if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
140
+	  else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
141
+	}
155 142
 
156
-  int index_a = 0;
157
-  int index_b = 0;
143
+    // Now proceed to build the Hm matrix
158 144
 
159
-  complex<DP> sum1 = 0.0;
160
-  complex<DP> sum2 = 0.0;
161
-  complex<DP> prod_num = 0.0;
162
-  complex<DP> Fn_K_0_G_0 = 0.0;
163
-  complex<DP> Prod_powerN = 0.0;
164
-  complex<DP> Fn_K_1_G_2 = 0.0;
165
-  complex<DP> one_over_A_lambda_sq_plus_1over2sq;
145
+    SQMat_CX Hm(0.0, A.base.Mdown);
166 146
 
167
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
168
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
169
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
147
+    int index_a = 0;
148
+    int index_b = 0;
170 149
 
171
-	index_b = 0;
150
+    complex<DP> sum1 = 0.0;
151
+    complex<DP> sum2 = 0.0;
152
+    complex<DP> prod_num = 0.0;
153
+    complex<DP> Fn_K_0_G_0 = 0.0;
154
+    complex<DP> Prod_powerN = 0.0;
155
+    complex<DP> Fn_K_1_G_2 = 0.0;
156
+    complex<DP> one_over_A_lambda_sq_plus_1over2sq;
172 157
 
173
-	one_over_A_lambda_sq_plus_1over2sq = 1.0/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *
174
-						  (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
158
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
159
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
160
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
175 161
 
176
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
177
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
178
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
162
+	  index_b = 0;
179 163
 
180
-	      if (B.chain.Str_L[k] == 1) {
164
+	  one_over_A_lambda_sq_plus_1over2sq = 1.0/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *
165
+						    (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
181 166
 
182
-		// use simplified code for one-string here:  original form of Hm2P matrix
167
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
168
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
169
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
183 170
 
184
-		Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
185
-		  exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
186
-		Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
187
-		  exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
171
+		if (B.chain.Str_L[k] == 1) {
188 172
 
189
-		Prod_powerN = pow((B.lambda[k][beta] + II * 0.5) /(B.lambda[k][beta] - II * 0.5), complex<DP> (B.chain.Nsites));
173
+		  // use simplified code for one-string here:  original form of Hm2P matrix
190 174
 
191
-		Hm[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2;
175
+		  Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
176
+		    exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
177
+		  Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
178
+		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
192 179
 
193
-	      } // if (B.chain.Str_L == 1)
180
+		  Prod_powerN = pow((B.lambda[k][beta] + II * 0.5) /(B.lambda[k][beta] - II * 0.5),
181
+				    complex<DP> (B.chain.Nsites));
194 182
 
195
-	      else {
183
+		  Hm[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2;
196 184
 
197
-		if (b <= B.chain.Str_L[k] - 1) Hm[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
198
-		else if (b == B.chain.Str_L[k]) {
185
+		} // if (B.chain.Str_L == 1)
199 186
 
200
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
201
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
187
+		else {
202 188
 
203
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
204
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
189
+		  if (b <= B.chain.Str_L[k] - 1) Hm[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
190
+		  else if (b == B.chain.Str_L[k]) {
205 191
 
206
-		  sum1 = 0.0;
192
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
193
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
207 194
 
208
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
195
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
196
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
209 197
 
210
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
211
-		    * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
212
-			  - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
198
+		    sum1 = 0.0;
213 199
 
214
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
200
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0)
201
+		      * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
215 202
 
216
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
217
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
203
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
204
+		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
205
+			    - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
218 206
 
219
-		  /*
220
-		  sum2 = 0.0;
207
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
221 208
 
222
-		  for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
209
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
210
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
223 211
 
224
-		  */
225
-		  prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]]);
212
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]]);
226 213
 
227
-		  for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
228
-		    prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)));
229
-		  // include all string contributions F_B_0 in this term
214
+		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
215
+		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)));
216
+		    // include all string contributions F_B_0 in this term
230 217
 
231
-		  Hm[index_a][index_b] = prod_num * sum1;
218
+		    Hm[index_a][index_b] = prod_num * sum1;
232 219
 
233
-		} // else if (b == B.chain.Str_L[k])
234
-	      } // else
220
+		  } // else if (b == B.chain.Str_L[k])
221
+		} // else
235 222
 
236
-	      index_b++;
237
-	    }}} // sums over k, beta, b
223
+		index_b++;
224
+	      }}} // sums over k, beta, b
238 225
 
239
-	// now define the elements Hm[a][M]
226
+	  // now define the elements Hm[a][M]
240 227
 
241
-	Hm[index_a][B.base.Mdown] = one_over_A_lambda_sq_plus_1over2sq;
228
+	  Hm[index_a][B.base.Mdown] = one_over_A_lambda_sq_plus_1over2sq;
242 229
 
243
-	index_a++;
244
-      }}} // sums over j, alpha, a
230
+	  index_a++;
231
+	}}} // sums over j, alpha, a
245 232
 
246
-  complex<DP> ln_ME_sq = log(1.0 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
247
-    + 2.0 * real(lndet_LU_CX_dstry(Hm)) - A.lnnorm - B.lnnorm;
233
+    complex<DP> ln_ME_sq = log(1.0 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
234
+      + 2.0 * real(lndet_LU_CX_dstry(Hm)) - A.lnnorm - B.lnnorm;
248 235
 
249
-  //return(ln_ME_sq);
250
-  return(0.5 * ln_ME_sq); // Return ME, not MEsq
236
+    return(0.5 * ln_ME_sq); // Return ME, not MEsq
251 237
 
252
-}
238
+  }
253 239
 
254 240
 } // namespace ABACUS

+ 255
- 265
src/HEIS/ln_Smin_ME_XXZ.cc View File

@@ -19,325 +19,315 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-inline complex<DP> ln_Fn_F (XXZ_Bethe_State& B, int k, int beta, int b)
23
-{
24
-  complex<DP> ans = 0.0;
25
-  complex<DP> prod_temp = 1.0;
26
-  int counter = 0;
27
-  int arg = 0;
28
-  int absarg = 0;
29
-  int par_comb_1, par_comb_2;
22
+  inline complex<DP> ln_Fn_F (XXZ_Bethe_State& B, int k, int beta, int b)
23
+  {
24
+    complex<DP> ans = 0.0;
25
+    complex<DP> prod_temp = 1.0;
26
+    int counter = 0;
27
+    int arg = 0;
28
+    int absarg = 0;
29
+    int par_comb_1, par_comb_2;
30
+
31
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
32
+
33
+      par_comb_1 = B.chain.par[j] == B.chain.par[k] ? 1 : 0;
34
+      par_comb_2 = B.chain.par[k] == B.chain.par[j] ? 0 : B.chain.par[k];
35
+
36
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
37
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
38
+
39
+	  if (!((j == k) && (alpha == beta) && (a == b))) {
40
+
41
+	    arg = B.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
42
+	    absarg = abs(arg);
43
+
44
+	    prod_temp *= ((B.sinhlambda[j][alpha] * B.coshlambda[k][beta]
45
+			   - B.coshlambda[j][alpha] * B.sinhlambda[k][beta])
46
+			  * (B.chain.co_n_anis_over_2[absarg] * par_comb_1
47
+			     - sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_2)
48
+			  + II * (B.coshlambda[j][alpha] * B.coshlambda[k][beta]
49
+				  - B.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
50
+			  * (sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_1
51
+			     + B.chain.co_n_anis_over_2[absarg] * par_comb_2));
52
+	  }
53
+
54
+	  if (counter++ > 100) {  // we do at most 100 products before taking a log
55
+	    ans += log(prod_temp);
56
+	    prod_temp = 1.0;
57
+	    counter = 0;
58
+	  }
59
+
60
+	}}}
61
+
62
+    return(ans + log(prod_temp));
63
+  }
30 64
 
31
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
65
+  inline complex<DP> ln_Fn_G (XXZ_Bethe_State& A, XXZ_Bethe_State& B, int k, int beta, int b)
66
+  {
67
+    complex<DP> ans = 0.0;
68
+    complex<DP> prod_temp = 1.0;
69
+    int counter = 0;
70
+    int arg = 0;
71
+    int absarg = 0;
72
+    int par_comb_1, par_comb_2;
32 73
 
33
-    par_comb_1 = B.chain.par[j] == B.chain.par[k] ? 1 : 0;
34
-    par_comb_2 = B.chain.par[k] == B.chain.par[j] ? 0 : B.chain.par[k];
74
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
35 75
 
36
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
37
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
76
+      par_comb_1 = A.chain.par[j] == B.chain.par[k] ? 1 : 0;
77
+      par_comb_2 = B.chain.par[k] == A.chain.par[j] ? 0 : B.chain.par[k];
38 78
 
39
-	if (!((j == k) && (alpha == beta) && (a == b))) {
79
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
80
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
40 81
 
41
-	  arg = B.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
82
+	  arg = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
42 83
 	  absarg = abs(arg);
43
-	  /*
44
-	  prod_temp *= 0.5 * //done later...
45
-	    ((B.sinhlambda[j][alpha] * B.coshlambda[k][beta] - B.coshlambda[j][alpha] * B.sinhlambda[k][beta])
46
-	     * (B.chain.co_n_anis_over_2[absarg] * (1.0 + B.chain.par[j] * B.chain.par[k])
47
-		- sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * (B.chain.par[k] - B.chain.par[j]))
48
-			+ II * (B.coshlambda[j][alpha] * B.coshlambda[k][beta] - B.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
49
-			* (sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * (1.0 + B.chain.par[j] * B.chain.par[k])
50
-			   + B.chain.co_n_anis_over_2[absarg] * (B.chain.par[k] - B.chain.par[j])) );
51
-	  */
52
-
53
-	  prod_temp *= ((B.sinhlambda[j][alpha] * B.coshlambda[k][beta] - B.coshlambda[j][alpha] * B.sinhlambda[k][beta])
54
-			* (B.chain.co_n_anis_over_2[absarg] * par_comb_1 - sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_2)
55
-			+ II * (B.coshlambda[j][alpha] * B.coshlambda[k][beta] - B.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
56
-			* (sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_1 + B.chain.co_n_anis_over_2[absarg] * par_comb_2));
57
-	}
84
+	  prod_temp *= ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta]
85
+			 - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
86
+			* (A.chain.co_n_anis_over_2[absarg] * par_comb_1
87
+			   - sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_2)
88
+			+ II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta]
89
+				- A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
90
+			* (sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_1
91
+			   + A.chain.co_n_anis_over_2[absarg] * par_comb_2));
92
+
93
+	  if (counter++ > 100) {  // we do at most 100 products before taking a log
94
+	    ans += log(prod_temp);
95
+	    prod_temp = 1.0;
96
+	    counter = 0;
97
+	  }
98
+	}}}
99
+
100
+    return(ans + log(prod_temp));
101
+  }
58 102
 
59
-	if (counter++ > 100) {  // we do at most 100 products before taking a log
60
-	  ans += log(prod_temp);
61
-	  prod_temp = 1.0;
62
-	  counter = 0;
63
-	}
103
+  inline complex<DP> Fn_K (XXZ_Bethe_State& A, int j, int alpha, int a, XXZ_Bethe_State& B, int k, int beta, int b)
104
+  {
105
+    int arg1 = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
106
+    int absarg1 = abs(arg1);
107
+    int arg2 = arg1 + 2;
108
+    int absarg2 = abs(arg2);
109
+
110
+    return(4.0/(
111
+		((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
112
+		 * (A.chain.co_n_anis_over_2[absarg1] * (1.0 + A.chain.par[j] * B.chain.par[k])
113
+		    - sgn_int(arg1) * A.chain.si_n_anis_over_2[absarg1] * (B.chain.par[k] - A.chain.par[j]))
114
+		 + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
115
+		 * (sgn_int(arg1) * A.chain.si_n_anis_over_2[absarg1] * (1.0 + A.chain.par[j] * B.chain.par[k])
116
+		    + A.chain.co_n_anis_over_2[absarg1] * (B.chain.par[k] - A.chain.par[j])) )
117
+		*
118
+		((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
119
+		 * (A.chain.co_n_anis_over_2[absarg2] * (1.0 + A.chain.par[j] * B.chain.par[k])
120
+		    - sgn_int(arg2) * A.chain.si_n_anis_over_2[absarg2] * (B.chain.par[k] - A.chain.par[j]))
121
+		 + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
122
+		 * (sgn_int(arg2) * A.chain.si_n_anis_over_2[absarg2] * (1.0 + A.chain.par[j] * B.chain.par[k])
123
+		    + A.chain.co_n_anis_over_2[absarg2] * (B.chain.par[k] - A.chain.par[j])) )
124
+		));
64 125
 
65
-      }}}
66
-
67
-  return(ans + log(prod_temp));
68
-}
69
-
70
-inline complex<DP> ln_Fn_G (XXZ_Bethe_State& A, XXZ_Bethe_State& B, int k, int beta, int b)
71
-{
72
-  complex<DP> ans = 0.0;
73
-  complex<DP> prod_temp = 1.0;
74
-  int counter = 0;
75
-  int arg = 0;
76
-  int absarg = 0;
77
-  int par_comb_1, par_comb_2;
78
-
79
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
80
-
81
-    par_comb_1 = A.chain.par[j] == B.chain.par[k] ? 1 : 0;
82
-    par_comb_2 = B.chain.par[k] == A.chain.par[j] ? 0 : B.chain.par[k];
83
-
84
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
85
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
86
-
87
-	arg = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
88
-	absarg = abs(arg);
89
-	/*
90
-	prod_temp *= 0.5 * //done later...
91
-	  ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
92
-		      * (A.chain.co_n_anis_over_2[absarg] * (1.0 + A.chain.par[j] * B.chain.par[k])
93
-			 - sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * (B.chain.par[k] - A.chain.par[j]))
94
-		      + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
95
-		      * (sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * (1.0 + A.chain.par[j] * B.chain.par[k])
96
-			 + A.chain.co_n_anis_over_2[absarg] * (B.chain.par[k] - A.chain.par[j])) );
97
-	*/
98
-	prod_temp *= ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
99
-		      * (A.chain.co_n_anis_over_2[absarg] * par_comb_1 - sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_2)
100
-		      + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
101
-		      * (sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_1 + A.chain.co_n_anis_over_2[absarg] * par_comb_2));
102
-
103
-	if (counter++ > 100) {  // we do at most 100 products before taking a log
104
-	  ans += log(prod_temp);
105
-	  prod_temp = 1.0;
106
-	  counter = 0;
107
-	}
108
-      }}}
109
-
110
-  return(ans + log(prod_temp));
111
-}
112
-
113
-inline complex<DP> Fn_K (XXZ_Bethe_State& A, int j, int alpha, int a, XXZ_Bethe_State& B, int k, int beta, int b)
114
-{
115
-  int arg1 = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
116
-  int absarg1 = abs(arg1);
117
-  int arg2 = arg1 + 2;
118
-  int absarg2 = abs(arg2);
119
-
120
-  return(4.0/(
121
-	      ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
122
-		      * (A.chain.co_n_anis_over_2[absarg1] * (1.0 + A.chain.par[j] * B.chain.par[k])
123
-			 - sgn_int(arg1) * A.chain.si_n_anis_over_2[absarg1] * (B.chain.par[k] - A.chain.par[j]))
124
-		      + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
125
-		      * (sgn_int(arg1) * A.chain.si_n_anis_over_2[absarg1] * (1.0 + A.chain.par[j] * B.chain.par[k])
126
-			 + A.chain.co_n_anis_over_2[absarg1] * (B.chain.par[k] - A.chain.par[j])) )
127
-	 *
128
-	 ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
129
-		      * (A.chain.co_n_anis_over_2[absarg2] * (1.0 + A.chain.par[j] * B.chain.par[k])
130
-			 - sgn_int(arg2) * A.chain.si_n_anis_over_2[absarg2] * (B.chain.par[k] - A.chain.par[j]))
131
-		      + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
132
-		      * (sgn_int(arg2) * A.chain.si_n_anis_over_2[absarg2] * (1.0 + A.chain.par[j] * B.chain.par[k])
133
-			 + A.chain.co_n_anis_over_2[absarg2] * (B.chain.par[k] - A.chain.par[j])) )
134
-	      ));
135
-
136
-}
137
-
138
-inline complex<DP> Fn_L (XXZ_Bethe_State& A, int j, int alpha, int a, XXZ_Bethe_State& B, int k, int beta, int b)
139
-{
140
-  return (sinh(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
141
-		      + 0.5 * II * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
142
-		      + 0.25 * II * PI * complex<DP>(-A.chain.par[j] + B.chain.par[k])))
143
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
144
-}
145
-
146
-complex<DP> ln_Smin_ME (XXZ_Bethe_State& A, XXZ_Bethe_State& B)
147
-{
148
-  // This function returns the natural log of the S^- operator matrix element.
149
-  // The A and B states can contain strings.
150
-
151
-  // Check that the two states are compatible
152
-
153
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXZ_Chains in Smin matrix element.");
154
-
155
-  // Check that A and B are Mdown-compatible:
156
-
157
-  if (A.base.Mdown != B.base.Mdown + 1) {
158
-    cout << "A.base.Mdown = " << A.base.Mdown << "\tB.base.Mdown = " << B.base.Mdown << endl;
159
-    cout << "A: " << A << endl << "B: " << B << endl;
160
-    ABACUSerror("Incompatible Mdown between the two states in Smin matrix element!");
161 126
   }
162 127
 
163
-  // Compute the sinh and cosh of rapidities
164
-
165
-  A.Compute_sinhlambda();
166
-  A.Compute_coshlambda();
167
-  B.Compute_sinhlambda();
168
-  B.Compute_coshlambda();
169
-
170
-  // Some convenient arrays
171
-
172
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
173
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
174
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
175
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
176
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
177
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
178
-
179
-  complex<DP> ln_prod1 = 0.0;
180
-  complex<DP> ln_prod2 = 0.0;
181
-  complex<DP> ln_prod3 = 0.0;
182
-  complex<DP> ln_prod4 = 0.0;
183
-
184
-  for (int i = 0; i < A.chain.Nstrings; ++i)
185
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
186
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
187
-	ln_prod1 += log(norm(sinh(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
188
-				  + 0.25 * II * PI * (1.0 - A.chain.par[i]))));
189
-
190
-  for (int i = 0; i < B.chain.Nstrings; ++i)
191
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
192
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
193
-	if (norm(sinh(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
194
-		      + 0.25 * II * PI * (1.0 - B.chain.par[i]))) > 100.0 * MACHINE_EPS_SQ)
195
-	  ln_prod2 += log(norm(sinh(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
196
-				    + 0.25 * II * PI * (1.0 - B.chain.par[i]))));
197
-
198
-  // Define the F ones earlier...
199
-
200
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
201
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
202
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
203
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
204
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
205
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
206
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
207
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
208
-    }
128
+  inline complex<DP> Fn_L (XXZ_Bethe_State& A, int j, int alpha, int a, XXZ_Bethe_State& B, int k, int beta, int b)
129
+  {
130
+    return (sinh(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
131
+			+ 0.5 * II * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
132
+			+ 0.25 * II * PI * complex<DP>(-A.chain.par[j] + B.chain.par[k])))
133
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
209 134
   }
210 135
 
211
-  DP logabssinzeta = log(abs(sin(A.chain.anis)));
136
+  complex<DP> ln_Smin_ME (XXZ_Bethe_State& A, XXZ_Bethe_State& B)
137
+  {
138
+    // This function returns the natural log of the S^- operator matrix element.
139
+    // The A and B states can contain strings.
212 140
 
213
-  // Define regularized products in prefactors
141
+    // Check that the two states are compatible
214 142
 
215
-  for (int j = 0; j < A.chain.Nstrings; ++j)
216
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
217
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
218
-	ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);  // assume only one-strings here
143
+    if (A.chain != B.chain) ABACUSerror("Incompatible XXZ_Chains in Smin matrix element.");
219 144
 
220
-  ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.anis)));
145
+    // Check that A and B are Mdown-compatible:
221 146
 
222
-  for (int k = 0; k < B.chain.Nstrings; ++k)
223
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
224
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
225
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
226
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
147
+    if (A.base.Mdown != B.base.Mdown + 1) {
148
+      cout << "A.base.Mdown = " << A.base.Mdown << "\tB.base.Mdown = " << B.base.Mdown << endl;
149
+      cout << "A: " << A << endl << "B: " << B << endl;
150
+      ABACUSerror("Incompatible Mdown between the two states in Smin matrix element!");
227 151
     }
228 152
 
229
-  ln_prod4 -= B.base.Mdown * log(abs(sin(B.chain.anis)));
153
+    // Compute the sinh and cosh of rapidities
154
+
155
+    A.Compute_sinhlambda();
156
+    A.Compute_coshlambda();
157
+    B.Compute_sinhlambda();
158
+    B.Compute_coshlambda();
159
+
160
+    // Some convenient arrays
161
+
162
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
163
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
164
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
165
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
166
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
167
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
168
+
169
+    complex<DP> ln_prod1 = 0.0;
170
+    complex<DP> ln_prod2 = 0.0;
171
+    complex<DP> ln_prod3 = 0.0;
172
+    complex<DP> ln_prod4 = 0.0;
173
+
174
+    for (int i = 0; i < A.chain.Nstrings; ++i)
175
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
176
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
177
+	  ln_prod1 += log(norm(sinh(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
178
+				    + 0.25 * II * PI * (1.0 - A.chain.par[i]))));
179
+
180
+    for (int i = 0; i < B.chain.Nstrings; ++i)
181
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
182
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
183
+	  if (norm(sinh(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
184
+			+ 0.25 * II * PI * (1.0 - B.chain.par[i]))) > 100.0 * MACHINE_EPS_SQ)
185
+	    ln_prod2 += log(norm(sinh(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
186
+				      + 0.25 * II * PI * (1.0 - B.chain.par[i]))));
187
+
188
+    // Define the F ones earlier...
189
+
190
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
191
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
192
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
193
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
194
+	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
195
+	im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
196
+	re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
197
+	im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
198
+      }
199
+    }
230 200
 
231
-  // Now proceed to build the Hm matrix
201
+    DP logabssinzeta = log(abs(sin(A.chain.anis)));
232 202
 
233
-  SQMat_CX Hm(0.0, A.base.Mdown);
203
+    // Define regularized products in prefactors
234 204
 
235
-  int index_a = 0;
236
-  int index_b = 0;
205
+    for (int j = 0; j < A.chain.Nstrings; ++j)
206
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
207
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a)
208
+	  ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);  // assume only one-strings here
237 209
 
238
-  complex<DP> sum1 = 0.0;
239
-  complex<DP> sum2 = 0.0;
240
-  complex<DP> prod_num = 0.0;
241
-  complex<DP> Fn_K_0_G_0 = 0.0;
242
-  complex<DP> Prod_powerN = 0.0;
243
-  complex<DP> Fn_K_1_G_2 = 0.0;
244
-  complex<DP> one_over_A_sinhlambda_sq_plus_sinzetaover2sq;
210
+    ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.anis)));
245 211
 
212
+    for (int k = 0; k < B.chain.Nstrings; ++k)
213
+      for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
214
+	for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
215
+	  if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
216
+	  else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
217
+	}
218
+
219
+    ln_prod4 -= B.base.Mdown * log(abs(sin(B.chain.anis)));
220
+
221
+    // Now proceed to build the Hm matrix
246 222
 
247
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
248
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
249
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
223
+    SQMat_CX Hm(0.0, A.base.Mdown);
250 224
 
251
-	index_b = 0;
225
+    int index_a = 0;
226
+    int index_b = 0;
252 227
 
253
-	one_over_A_sinhlambda_sq_plus_sinzetaover2sq = 1.0/((sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
254
-								  + 0.25 * II * PI * (1.0 - A.chain.par[j])))
255
-							    * (sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
256
-								  + 0.25 * II * PI * (1.0 - A.chain.par[j])))
257
-							    + pow(sin(0.5*A.chain.anis), 2.0));
228
+    complex<DP> sum1 = 0.0;
229
+    complex<DP> sum2 = 0.0;
230
+    complex<DP> prod_num = 0.0;
231
+    complex<DP> Fn_K_0_G_0 = 0.0;
232
+    complex<DP> Prod_powerN = 0.0;
233
+    complex<DP> Fn_K_1_G_2 = 0.0;
234
+    complex<DP> one_over_A_sinhlambda_sq_plus_sinzetaover2sq;
258 235
 
259
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
260
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
261
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
262 236
 
263
-	      if (B.chain.Str_L[k] == 1) {
237
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
238
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
239
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
264 240
 
265
-		// use simplified code for one-string here:  original form of Hm matrix
241
+	  index_b = 0;
266 242
 
267
-		Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
268
-		  exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinzeta);
269
-		Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
270
-		  exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinzeta);
243
+	  one_over_A_sinhlambda_sq_plus_sinzetaover2sq
244
+	    = 1.0/((sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
245
+			 + 0.25 * II * PI * (1.0 - A.chain.par[j])))
246
+		   * (sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
247
+			   + 0.25 * II * PI * (1.0 - A.chain.par[j])))
248
+		   + pow(sin(0.5*A.chain.anis), 2.0));
271 249
 
272
-		Prod_powerN = pow( B.chain.par[k] == 1 ?
273
-				   (B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1] + II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
274
-				   /(B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1] - II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
275
-				   :
276
-				   (B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1] + II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
277
-				   /(B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1] - II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
278
-				   , complex<DP> (B.chain.Nsites));
250
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
251
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
252
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
279 253
 
280
-		Hm[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2;
254
+		if (B.chain.Str_L[k] == 1) {
281 255
 
282
-	      } // if (B.chain.Str_L == 1)
256
+		  // use simplified code for one-string here:  original form of Hm matrix
283 257
 
284
-	      else {
258
+		  Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
259
+		    exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinzeta);
260
+		  Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
261
+		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinzeta);
285 262
 
286
-		if (b <= B.chain.Str_L[k] - 1) Hm[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
287
-		else if (b == B.chain.Str_L[k]) {
263
+		  Prod_powerN = pow( B.chain.par[k] == 1 ?
264
+				     (B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1]
265
+				      + II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
266
+				     /(B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1]
267
+				       - II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
268
+				     :
269
+				     (B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1]
270
+				      + II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
271
+				     /(B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1]
272
+				       - II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
273
+				     , complex<DP> (B.chain.Nsites));
288 274
 
289
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
290
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
275
+		  Hm[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2;
291 276
 
292
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
293
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
277
+		} // if (B.chain.Str_L == 1)
294 278
 
295
-		  sum1 = 0.0;
279
+		else {
296 280
 
297
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
281
+		  if (b <= B.chain.Str_L[k] - 1) Hm[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
282
+		  else if (b == B.chain.Str_L[k]) {
298 283
 
299
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
300
-		    * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
301
-			  - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
284
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
285
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
302 286
 
303
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
287
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
288
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
304 289
 
305
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
306
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
290
+		    sum1 = 0.0;
307 291
 
308
-		  /*
309
-		  sum2 = 0.0;
292
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0)
293
+		      * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
310 294
 
311
-		  for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
295
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
296
+		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
297
+			    - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
312 298
 
313
-		  */
314
-		  prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]] + logabssinzeta);
299
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
315 300
 
316
-		  for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
317
-		    prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)) + logabssinzeta);
318
-		  // include all string contributions F_B_0 in this term
301
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
302
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
319 303
 
320
-		  Hm[index_a][index_b] = prod_num * sum1;
304
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1]
305
+				   - ln_FunctionG[B.chain.Str_L[k]] + logabssinzeta);
321 306
 
322
-		} // else if (b == B.chain.Str_L[k])
323
-	      } // else
307
+		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
308
+		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)) + logabssinzeta);
309
+		    // include all string contributions F_B_0 in this term
324 310
 
325
-	      index_b++;
326
-	    }}} // sums over k, beta, b
311
+		    Hm[index_a][index_b] = prod_num * sum1;
327 312
 
328
-	// now define the elements Hm[a][M]
313
+		  } // else if (b == B.chain.Str_L[k])
314
+		} // else
329 315
 
330
-	Hm[index_a][B.base.Mdown] = one_over_A_sinhlambda_sq_plus_sinzetaover2sq;
316
+		index_b++;
317
+	      }}} // sums over k, beta, b
331 318
 
332
-	index_a++;
333
-      }}} // sums over j, alpha, a
319
+	  // now define the elements Hm[a][M]
334 320
 
335
-  complex<DP> ln_ME_sq = log(1.0 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
336
-    + 2.0 * real(lndet_LU_CX_dstry(Hm)) + logabssinzeta - A.lnnorm - B.lnnorm;
321
+	  Hm[index_a][B.base.Mdown] = one_over_A_sinhlambda_sq_plus_sinzetaover2sq;
337 322
 
338
-  //return(ln_ME_sq);
339
-  return(0.5 * ln_ME_sq); // Return ME, not MEsq
323
+	  index_a++;
324
+	}}} // sums over j, alpha, a
340 325
 
341
-}
326
+    complex<DP> ln_ME_sq = log(1.0 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
327
+      + 2.0 * real(lndet_LU_CX_dstry(Hm)) + logabssinzeta - A.lnnorm - B.lnnorm;
328
+
329
+    return(0.5 * ln_ME_sq); // Return ME, not MEsq
330
+
331
+  }
342 332
 
343 333
 } // namespace ABACUS

+ 216
- 250
src/HEIS/ln_Smin_ME_XXZ_gpd.cc View File

@@ -19,300 +19,266 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-inline complex<DP> ln_Fn_F (XXZ_gpd_Bethe_State& B, int k, int beta, int b)
23
-{
24
-  complex<DP> ans = 0.0;
25
-  complex<DP> prod_temp = 1.0;
26
-  int counter = 0;
27
-
28
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
29
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
30
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
31
-	/*
32
-	if (!((j == k) && (alpha == beta) && (a == b)))
33
-	  ans += log(-II * sin(B.lambda[j][alpha] - B.lambda[k][beta]
34
-			    + 0.5 * II * B.chain.eta * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))));
35
-	*/
36
-
37
-	if (!((j == k) && (alpha == beta) && (a == b))) {
38
-
39
-	  //	  arg = B.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
40
-	  //	  absarg = abs(arg);
41
-
42
-	  prod_temp *= -II * (B.sinlambda[j][alpha] * B.coslambda[k][beta] - B.coslambda[j][alpha] * B.sinlambda[k][beta])
43
-	    * cosh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
44
-	    (B.coslambda[j][alpha] * B.coslambda[k][beta] + B.sinlambda[j][alpha] * B.sinlambda[k][beta])
45
-	    * sinh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
22
+  inline complex<DP> ln_Fn_F (XXZ_gpd_Bethe_State& B, int k, int beta, int b)
23
+  {
24
+    complex<DP> ans = 0.0;
25
+    complex<DP> prod_temp = 1.0;
26
+    int counter = 0;
46 27
 
47
-	}
28
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
29
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
30
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
48 31
 
32
+	  if (!((j == k) && (alpha == beta) && (a == b))) {
49 33
 
50
-	if (counter++ > 10) {  // we do at most 10 products before taking a log
51
-	  ans += log(prod_temp);
52
-	  prod_temp = 1.0;
53
-	  counter = 0;
54
-	}
34
+	    prod_temp *= -II * (B.sinlambda[j][alpha] * B.coslambda[k][beta] - B.coslambda[j][alpha] * B.sinlambda[k][beta])
35
+	      * cosh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
36
+	      (B.coslambda[j][alpha] * B.coslambda[k][beta] + B.sinlambda[j][alpha] * B.sinlambda[k][beta])
37
+	      * sinh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
55 38
 
56
-      }}}
57
-
58
-  //  return(ans);
59
-  return(ans + log(prod_temp));
60
-}
61
-
62
-inline complex<DP> ln_Fn_G (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
63
-{
64
-  complex<DP> ans = 0.0;
65
-  complex<DP> prod_temp = 1.0;
66
-  int counter = 0;
67
-
68
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
69
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
70
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
71
-	/*
72
-	prod_temp *= -II * sin(A.lambda[j][alpha] - B.lambda[k][beta]
73
-		    + 0.5 * II * B.chain.eta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
74
-	*/
75
-
76
-	//	arg = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
77
-	//	absarg = abs(arg);
78
-
79
-	prod_temp *= -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
80
-	  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
81
-	  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
82
-	  * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
83
-
84
-	if (counter++ > 25) {  // we do at most 25 products before taking a log
85
-	  ans += log(prod_temp);
86
-	  prod_temp = 1.0;
87
-	  counter = 0;
88
-	}
89
-      }}}
90
-
91
-  //  return(ans);
92
-  return(ans + log(prod_temp));
93
-}
94
-
95
-inline complex<DP> Fn_K (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
96
-{
97
-  /*
98
-  return(-1.0/(sin(A.lambda[j][alpha] - B.lambda[k][beta]
99
-		    + 0.5 * II * B.chain.zeta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
100
-	      * sin(A.lambda[j][alpha] - B.lambda[k][beta]
101
-		    + 0.5 * II * B.chain.zeta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)))));
102
-  */
103
-
104
-  //  int arg1 = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
105
-  //  int absarg1 = abs(arg1);
106
-  //  int arg2 = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b - 1);
107
-  //  int arg2 = arg1 + 2;
108
-  //  int absarg2 = abs(arg2);
109
-
110
-  return(1.0/(( -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
111
-	  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
112
-	  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
113
-	       * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))) *
114
-	      (-II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
115
-	  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))) +
116
-	  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
117
-	       * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))))));
118
-
119
-}
120
-
121
-inline complex<DP> Fn_L (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
122
-{
123
-  /*
124
-  complex<DP> ans = -II * sin(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
125
-				+ 0.5 * II * B.chain.zeta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))));
126
-
127
-  return (ans * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
128
-  */
129
-  return (-II * sin(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
130
-		      + 0.5 * II * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))))
131
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
132
-}
133
-
134
-complex<DP> ln_Smin_ME (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B)
135
-{
136
-  // This function returns the natural log of the S^- operator matrix element.
137
-  // The A and B states can contain strings.
138
-
139
-  // Check that the two states refer to the same XXZ_gpd_Chain
140
-
141
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXZ_gpd_Chains in Smin matrix element.");
142
-
143
-  // Check that A and B are compatible:  same Mdown
144
-
145
-  if (A.base.Mdown != B.base.Mdown + 1) ABACUSerror("Incompatible Mdown between the two states in Smin matrix element!");
146
-
147
-  // Compute the sin and cos of rapidities
148
-
149
-  A.Compute_sinlambda();
150
-  A.Compute_coslambda();
151
-  B.Compute_sinlambda();
152
-  B.Compute_coslambda();
153
-
154
-  // Some convenient arrays
155
-
156
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
157
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
158
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
159
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
160
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
161
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
162
-
163
-  complex<DP> ln_prod1 = 0.0;
164
-  complex<DP> ln_prod2 = 0.0;
165
-  complex<DP> ln_prod3 = 0.0;
166
-  complex<DP> ln_prod4 = 0.0;
167
-
168
-  for (int i = 0; i < A.chain.Nstrings; ++i)
169
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
170
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
171
-	ln_prod1 += log(norm(sin(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
172
-
173
-  for (int i = 0; i < B.chain.Nstrings; ++i)
174
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
175
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
176
-	if (norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))) > 100.0 * MACHINE_EPS_SQ)
177
-	  ln_prod2 += log(norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
178
-
179
-  //  one_over_A_sinlambda_sq_plus_sinhetaover2sq[j][alpha] = 1.0/(pow(A.sinlambda[j][alpha], 2.0) + pow(sinh(0.5*A.chain.anis), 2.0));
180
-
181
-  // Define the F ones earlier...
182
-
183
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
184
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
185
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
186
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
187
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
188
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
189
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
190
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
191
-    }
39
+	  }
40
+
41
+
42
+	  if (counter++ > 10) {  // we do at most 10 products before taking a log
43
+	    ans += log(prod_temp);
44
+	    prod_temp = 1.0;
45
+	    counter = 0;
46
+	  }
47
+
48
+	}}}
49
+
50
+    //  return(ans);
51
+    return(ans + log(prod_temp));
192 52
   }
193 53
 
194
-  DP logabssinheta = log(abs(sinh(A.chain.anis)));
54
+  inline complex<DP> ln_Fn_G (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
55
+  {
56
+    complex<DP> ans = 0.0;
57
+    complex<DP> prod_temp = 1.0;
58
+    int counter = 0;
59
+
60
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
61
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
62
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
63
+
64
+	  prod_temp *= -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
65
+	    * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
66
+	    (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
67
+	    * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
68
+
69
+	  if (counter++ > 25) {  // we do at most 25 products before taking a log
70
+	    ans += log(prod_temp);
71
+	    prod_temp = 1.0;
72
+	    counter = 0;
73
+	  }
74
+	}}}
75
+
76
+    //  return(ans);
77
+    return(ans + log(prod_temp));
78
+  }
195 79
 
196
-  // Define regularized products in prefactors
80
+  inline complex<DP> Fn_K (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
81
+  {
82
+    return(1.0/(( -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
83
+		  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
84
+		  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
85
+		  * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))) *
86
+		(-II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
87
+		 * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))) +
88
+		 (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
89
+		 * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))))));
197 90
 
198
-  for (int j = 0; j < A.chain.Nstrings; ++j)
199
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
200
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
201
-	ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
91
+  }
202 92
 
203
-  ln_prod3 -= A.base.Mdown * log(abs(sinh(A.chain.anis)));
93
+  inline complex<DP> Fn_L (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
94
+  {
95
+    return (-II * sin(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
96
+			     + 0.5 * II * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))))
97
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
98
+  }
204 99
 
205
-  for (int k = 0; k < B.chain.Nstrings; ++k)
206
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
207
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
208
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
209
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
100
+  complex<DP> ln_Smin_ME (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B)
101
+  {
102
+    // This function returns the natural log of the S^- operator matrix element.
103
+    // The A and B states can contain strings.
104
+
105
+    // Check that the two states refer to the same XXZ_gpd_Chain
106
+
107
+    if (A.chain != B.chain)
108
+      ABACUSerror("Incompatible XXZ_gpd_Chains in Smin matrix element.");
109
+
110
+    // Check that A and B are compatible:  same Mdown
111
+
112
+    if (A.base.Mdown != B.base.Mdown + 1)
113
+      ABACUSerror("Incompatible Mdown between the two states in Smin matrix element!");
114
+
115
+    // Compute the sin and cos of rapidities
116
+
117
+    A.Compute_sinlambda();
118
+    A.Compute_coslambda();
119
+    B.Compute_sinlambda();
120
+    B.Compute_coslambda();
121
+
122
+    // Some convenient arrays
123
+
124
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
125
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
126
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
127
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
128
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
129
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
130
+
131
+    complex<DP> ln_prod1 = 0.0;
132
+    complex<DP> ln_prod2 = 0.0;
133
+    complex<DP> ln_prod3 = 0.0;
134
+    complex<DP> ln_prod4 = 0.0;
135
+
136
+    for (int i = 0; i < A.chain.Nstrings; ++i)
137
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
138
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
139
+	  ln_prod1 += log(norm(sin(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
140
+
141
+    for (int i = 0; i < B.chain.Nstrings; ++i)
142
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
143
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
144
+	  if (norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)))
145
+	      > 100.0 * MACHINE_EPS_SQ)
146
+	    ln_prod2 += log(norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
147
+
148
+    // Define the F ones earlier...
149
+
150
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
151
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
152
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
153
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
154
+	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
155
+	im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
156
+	re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
157
+	im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
158
+      }
210 159
     }
211 160
 
212
-  ln_prod4 -= B.base.Mdown * log(abs(sinh(B.chain.anis)));
161
+    DP logabssinheta = log(abs(sinh(A.chain.anis)));
162
+
163
+    // Define regularized products in prefactors
213 164
 
214
-  // Now proceed to build the Hm matrix
165
+    for (int j = 0; j < A.chain.Nstrings; ++j)
166
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
167
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a)
168
+	  ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
215 169
 
216
-  SQMat_CX Hm(0.0, A.base.Mdown);
170
+    ln_prod3 -= A.base.Mdown * log(abs(sinh(A.chain.anis)));
171
+
172
+    for (int k = 0; k < B.chain.Nstrings; ++k)
173
+      for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
174
+	for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
175
+	  if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
176
+	  else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
177
+	}
217 178
 
218
-  int index_a = 0;
219
-  int index_b = 0;
179
+    ln_prod4 -= B.base.Mdown * log(abs(sinh(B.chain.anis)));
220 180
 
221
-  complex<DP> sum1 = 0.0;
222
-  complex<DP> sum2 = 0.0;
223
-  complex<DP> prod_num = 0.0;
224
-  complex<DP> Fn_K_0_G_0 = 0.0;
225
-  complex<DP> Prod_powerN = 0.0;
226
-  complex<DP> Fn_K_1_G_2 = 0.0;
227
-  complex<DP> one_over_A_sinlambda_sq_plus_sinhetaover2sq = 0.0;
181
+    // Now proceed to build the Hm matrix
228 182
 
229
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
230
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
231
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
183
+    SQMat_CX Hm(0.0, A.base.Mdown);
232 184
 
233
-	index_b = 0;
185
+    int index_a = 0;
186
+    int index_b = 0;
234 187
 
235
-	one_over_A_sinlambda_sq_plus_sinhetaover2sq = -1.0/((sin(A.lambda[j][alpha] // minus sign:  from 1/(sinh^2... to -1/(sin^2...
236
-								 + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a))) *
237
-							    (sin(A.lambda[j][alpha] // minus sign:  from 1/(sinh^2... to -1/(sin^2...
238
-								 + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)))
239
-							    + pow(sinh(0.5*A.chain.anis), 2.0));
188
+    complex<DP> sum1 = 0.0;
189
+    complex<DP> sum2 = 0.0;
190
+    complex<DP> prod_num = 0.0;
191
+    complex<DP> Fn_K_0_G_0 = 0.0;
192
+    complex<DP> Prod_powerN = 0.0;
193
+    complex<DP> Fn_K_1_G_2 = 0.0;
194
+    complex<DP> one_over_A_sinlambda_sq_plus_sinhetaover2sq = 0.0;
240 195
 
241
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
242
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
243
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
196
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
197
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
198
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
244 199
 
245
-	      if (B.chain.Str_L[k] == 1) {
200
+	  index_b = 0;
246 201
 
247
-		// use simplified code for one-string here:  original form of Hm2P matrix
202
+	  one_over_A_sinlambda_sq_plus_sinhetaover2sq =
203
+	    -1.0/((sin(A.lambda[j][alpha] // -sign from 1/(sinh^2... to -1/(sin^2...
204
+		       + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a))) *
205
+		  (sin(A.lambda[j][alpha] // -sign from 1/(sinh^2... to -1/(sin^2...
206
+		       + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)))
207
+		  + pow(sinh(0.5*A.chain.anis), 2.0));
248 208
 
249
-		Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
250
-		  exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
251
-		Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
252
-		  exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
209
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
210
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
211
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
253 212
 
254
-		Prod_powerN = pow((B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1] + II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1])
255
-				  /(B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1] - II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1]),
256
-				  complex<DP> (B.chain.Nsites));
213
+		if (B.chain.Str_L[k] == 1) {
257 214
 
258
-		Hm[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2;
259
-	      }
215
+		  // use simplified code for one-string here:  original form of Hm2P matrix
260 216
 
261
-	      else {
217
+		  Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
218
+		    exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
219
+		  Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
220
+		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
262 221
 
263
-		if (b <= B.chain.Str_L[k] - 1) Hm[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
264
-		else if (b == B.chain.Str_L[k]) {
222
+		  Prod_powerN = pow((B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1]
223
+				     + II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1])
224
+				    /(B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1]
225
+				      - II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1]),
226
+				    complex<DP> (B.chain.Nsites));
265 227
 
266
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
267
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
228
+		  Hm[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2;
229
+		}
268 230
 
269
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
270
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
231
+		else {
271 232
 
272
-		  sum1 = 0.0;
233
+		  if (b <= B.chain.Str_L[k] - 1) Hm[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
234
+		  else if (b == B.chain.Str_L[k]) {
273 235
 
274
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
236
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
237
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
275 238
 
276
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
277
-		    * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
278
-			  - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
239
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
240
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
279 241
 
280
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
242
+		    sum1 = 0.0;
281 243
 
282
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
283
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
284
-		  /*
285
-		  sum2 = 0.0;
244
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
286 245
 
287
-		  for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
288
-		  */
289
-		  prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]] + logabssinheta);
246
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
247
+		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
248
+			    - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
290 249
 
291
-		  for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
292
-		    prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)) + logabssinheta);
293
-		  // include all string contributions F_B_0 in this term
250
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
294 251
 
295
-		  Hm[index_a][index_b] = prod_num * sum1;
252
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
253
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
296 254
 
297
-		} // else if (b == B.chain.Str_L[k])
298
-	      } // else
255
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1]
256
+				   - ln_FunctionG[B.chain.Str_L[k]] + logabssinheta);
299 257
 
300
-	      index_b++;
301
-	    }}} // sums over k, beta, b
258
+		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
259
+		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)) + logabssinheta);
260
+		    // include all string contributions F_B_0 in this term
302 261
 
303
-	// now define the elements Hm[a][M]
262
+		    Hm[index_a][index_b] = prod_num * sum1;
304 263
 
305
-	Hm[index_a][B.base.Mdown] = one_over_A_sinlambda_sq_plus_sinhetaover2sq;
264
+		  } // else if (b == B.chain.Str_L[k])
265
+		} // else
306 266
 
307
-	index_a++;
308
-      }}} // sums over j, alpha, a
267
+		index_b++;
268
+	      }}} // sums over k, beta, b
309 269
 
310
-  complex<DP> ln_ME_sq = log(1.0 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
311
-    + 2.0 * real(lndet_LU_CX_dstry(Hm)) + logabssinheta - A.lnnorm - B.lnnorm;
270
+	  // now define the elements Hm[a][M]
312 271
 
313
-  //return(ln_ME_sq);
314
-  return(0.5 * ln_ME_sq); // Return ME, not MEsq
272
+	  Hm[index_a][B.base.Mdown] = one_over_A_sinlambda_sq_plus_sinhetaover2sq;
315 273
 
316
-}
274
+	  index_a++;
275
+	}}} // sums over j, alpha, a
276
+
277
+    complex<DP> ln_ME_sq = log(1.0 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
278
+      + 2.0 * real(lndet_LU_CX_dstry(Hm)) + logabssinheta - A.lnnorm - B.lnnorm;
279
+
280
+    return(0.5 * ln_ME_sq); // Return ME, not MEsq
281
+
282
+  }
317 283
 
318 284
 } // namespace ABACUS

+ 246
- 244
src/HEIS/ln_Smm_ME_XXX.cc View File

@@ -18,305 +18,307 @@ using namespace std;
18 18
 using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21
-inline   complex<DP> phi(complex<DP> x){return x;}
22
-inline   complex<DP> a(complex<DP> x){return 1;}
23
-inline   complex<DP> b(complex<DP> x,complex<DP> y, complex<DP> eta){ return phi(x-y)/phi(x-y+complex<DP>(0.0,1.0)*eta);}
24
-inline   complex<DP> d(complex<DP> x, complex<DP> xi, complex<DP> eta, int N){return pow(b(x,xi,eta),N);}
21
+  inline   complex<DP> phi(complex<DP> x){return x;}
22
+  inline   complex<DP> a(complex<DP> x){return 1;}
23
+  inline   complex<DP> b(complex<DP> x,complex<DP> y, complex<DP> eta)
24
+  { return phi(x-y)/phi(x-y+complex<DP>(0.0,1.0)*eta);}
25
+  inline   complex<DP> d(complex<DP> x, complex<DP> xi, complex<DP> eta, int N)
26
+  {return pow(b(x,xi,eta),N);}
25 27
 
26 28
 
27
-inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
28
-{
29
-  complex<DP> ans = 0.0;
29
+  inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
30
+  {
31
+    complex<DP> ans = 0.0;
30 32
 
31
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
32
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
33
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
33
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
34
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
35
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
34 36
 
35
-	if (!((j == k) && (alpha == beta) && (a == b)))
36
-	  ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
37
-		     + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
37
+	  if (!((j == k) && (alpha == beta) && (a == b)))
38
+	    ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
39
+		       + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
40
+	}
38 41
       }
39 42
     }
40
-  }
41 43
 
42
-  return(ans);
43
-}
44
+    return(ans);
45
+  }
44 46
 
45
-inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
46
-{
47
-  complex<DP> ans = 0.0;
47
+  inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
48
+  {
49
+    complex<DP> ans = 0.0;
48 50
 
49
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
50
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
51
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
51
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
52
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
53
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
52 54
 
53
-	ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
54
-		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
55
+	  ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
56
+		     + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
55 57
 
58
+	}
56 59
       }
60
+
57 61
     }
58 62
 
63
+    return(ans);
59 64
   }
60 65
 
61
-  return(ans);
62
-}
63
-
64
-inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
65
-{
66
-
67
-  return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
68
-	       + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
69
-	      * (A.lambda[j][alpha] - B.lambda[k][beta]
70
-		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
71
-
72
-}
73
-
74
-inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
75
-{
76
-  return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
77
-		      + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
78
-		      ))
79
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
80
-}
81
-
82
-
83
-complex<DP> ln_Smm_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
84
-{
85
- const DP Zero_Center_Thres=1.0e-5;
86
-const DP real_dev=1.0e-14;
87
- const DP Diff_ME_Thres=1.e-6;
88
-
89
- //clock_t start_time_local = clock();
90
-
91
-  // This function returns the natural log of the S^z operator matrix element.
92
-  // The A and B states can contain strings.
93
-// A is the reference state.
94
-
95
-  // Check that the two states refer to the same XXX_Chain
96
-
97
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Smm matrix element.");
98
-
99
-  // Check that A and B are compatible:  same Mdown
100
-
101
-  if (A.base.Mdown != B.base.Mdown + 2) ABACUSerror("Incompatible Mdown between the two states in Smm matrix element!");
102
-
103
-  //if(B.String_delta()> HEIS_deltaprec) return(complex<DP>(-300.0)); // DEPRECATED in ++T_9
104
-
105
-
106
-  //if (B.type_id > 999999LL) return(complex<DP>(-300.0));
107
-
108
-  // Some convenient arrays
109
-  complex<DP> eta=-II;
110
-  complex<DP> ln_prod = complex<DP>(0.0,0.0);
111
-  complex<DP> result=-300;
112
-  complex<DP> prev_result=-300;
113
-
114
-XXX_Bethe_State B_origin; B_origin=B;
115
-  bool zero_string=false;
116
-  for (int j = 0; j < B_origin.chain.Nstrings; ++j)
117
-    for (int alpha = 0; alpha < B_origin.base.Nrap[j]; ++alpha)
118
-      if(abs(B_origin.lambda[j][alpha])<Zero_Center_Thres) zero_string=true;
119
-
120
-  // Some convenient arrays
121
-  bool real_dev_conv=false;
122
-  int dev=-1;
123
-  while(!real_dev_conv){
124
-    real_dev_conv=true;
125
-
126
-    dev++;
127
-    //add a delta to the origin of the centered strings
128
-    if(zero_string){
129
-      real_dev_conv=false;
130
-      for (int j = 0; j < B.chain.Nstrings; ++j)
131
-	for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha)
132
-	  if(abs(B_origin.lambda[j][alpha])<Zero_Center_Thres)
133
-	    B.lambda[j][alpha]=real_dev*pow(10.0,dev);
134
-    }
135
-
136
-    prev_result=result;
66
+  inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
67
+  {
137 68
 
69
+    return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
70
+		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
71
+		* (A.lambda[j][alpha] - B.lambda[k][beta]
72
+		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
138 73
 
74
+  }
139 75
 
140
-  result=log(B.chain.Nsites*1.0);
76
+  inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
77
+  {
78
+    return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
79
+		    + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
80
+		    ))
81
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
82
+  }
141 83
 
142
-  int sizeA=0;
143
-int sizeB=0;
144 84
 
145
-  for (int i = 0; i < A.chain.Nstrings; ++i)
146
-    sizeA+=A.base.Nrap[i]*A.chain.Str_L[i];
147
-  for (int i = 0; i < B.chain.Nstrings; ++i)
148
-    sizeB+=B.base.Nrap[i]*B.chain.Str_L[i];
85
+  complex<DP> ln_Smm_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
86
+  {
87
+    const DP Zero_Center_Thres=1.0e-5;
88
+    const DP real_dev=1.0e-14;
89
+    const DP Diff_ME_Thres=1.e-6;
90
+
91
+    // This function returns the natural log of the S^z operator matrix element.
92
+    // The A and B states can contain strings.
93
+    // A is the averaging state.
94
+
95
+    // Check that the two states refer to the same XXX_Chain
96
+
97
+    if (A.chain != B.chain)
98
+      ABACUSerror("Incompatible XXX_Chains in Smm matrix element.");
99
+
100
+    // Check that A and B are compatible:  same Mdown
101
+
102
+    if (A.base.Mdown != B.base.Mdown + 2)
103
+      ABACUSerror("Incompatible Mdown between the two states in Smm matrix element!");
104
+
105
+    // Some convenient arrays
106
+    complex<DP> eta=-II;
107
+    complex<DP> ln_prod = complex<DP>(0.0,0.0);
108
+    complex<DP> result=-300;
109
+    complex<DP> prev_result=-300;
110
+
111
+    XXX_Bethe_State B_origin; B_origin=B;
112
+    bool zero_string=false;
113
+    for (int j = 0; j < B_origin.chain.Nstrings; ++j)
114
+      for (int alpha = 0; alpha < B_origin.base.Nrap[j]; ++alpha)
115
+	if(abs(B_origin.lambda[j][alpha])<Zero_Center_Thres) zero_string=true;
116
+
117
+    // Some convenient arrays
118
+    bool real_dev_conv=false;
119
+    int dev=-1;
120
+    while(!real_dev_conv){
121
+      real_dev_conv=true;
122
+
123
+      dev++;
124
+      //add a delta to the origin of the centered strings
125
+      if(zero_string){
126
+	real_dev_conv=false;
127
+	for (int j = 0; j < B.chain.Nstrings; ++j)
128
+	  for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha)
129
+	    if(abs(B_origin.lambda[j][alpha])<Zero_Center_Thres)
130
+	      B.lambda[j][alpha]=real_dev*pow(10.0,dev);
131
+      }
149 132
 
150
-  complex<DP>* mu = new complex<DP>[sizeA];
151
-  complex<DP>* lam = new complex<DP>[sizeB];
152
-  int index=0;
153
-  for (int i = 0; i < A.chain.Nstrings; ++i)
154
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
155
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
156
-	{
157
-	  mu[index]=(A.lambda[i][alpha] + 0.5 * -eta * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
158
-	  index++;
133
+      prev_result=result;
134
+
135
+
136
+
137
+      result=log(B.chain.Nsites*1.0);
138
+
139
+      int sizeA=0;
140
+      int sizeB=0;
141
+
142
+      for (int i = 0; i < A.chain.Nstrings; ++i)
143
+	sizeA+=A.base.Nrap[i]*A.chain.Str_L[i];
144
+      for (int i = 0; i < B.chain.Nstrings; ++i)
145
+	sizeB+=B.base.Nrap[i]*B.chain.Str_L[i];
146
+
147
+      complex<DP>* mu = new complex<DP>[sizeA];
148
+      complex<DP>* lam = new complex<DP>[sizeB];
149
+      int index=0;
150
+      for (int i = 0; i < A.chain.Nstrings; ++i)
151
+	for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
152
+	  for (int a = 1; a <= A.chain.Str_L[i]; ++a)
153
+	    {
154
+	      mu[index]=(A.lambda[i][alpha] + 0.5 * -eta * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
155
+	      index++;
156
+	    }
157
+
158
+      index=0;
159
+      for (int i = 0; i < B.chain.Nstrings; ++i)
160
+	for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
161
+	  for (int a = 1; a <= B.chain.Str_L[i]; ++a)
162
+	    {
163
+	      lam[index]=(B.lambda[i][alpha] + 0.5 * -eta * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
164
+	      index++;
165
+	    }
166
+
167
+      Lambda re_ln_Fn_F_B_0(B.chain, B.base);
168
+      Lambda im_ln_Fn_F_B_0(B.chain, B.base);
169
+      Lambda re_ln_Fn_G_0(B.chain, B.base);
170
+      Lambda im_ln_Fn_G_0(B.chain, B.base);
171
+      Lambda re_ln_Fn_G_2(B.chain, B.base);
172
+      Lambda im_ln_Fn_G_2(B.chain, B.base);
173
+
174
+      for (int j = 0; j < B.chain.Nstrings; ++j) {
175
+	for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
176
+	  re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
177
+	  im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
178
+	  re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
179
+	  im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
180
+	  re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
181
+	  im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
159 182
 	}
183
+      }
160 184
 
161
-index=0;
162
-  for (int i = 0; i < B.chain.Nstrings; ++i)
163
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
164
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
165
-	{
166
-	  lam[index]=(B.lambda[i][alpha] + 0.5 * -eta * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
167
-	  index++;
168
-	}
185
+      complex<DP> ln_prod1 = 0.0;
186
+      complex<DP> ln_prod2 = 0.0;
187
+      complex<DP> ln_prod3 = 0.0;
188
+      complex<DP> ln_prod4 = 0.0;
169 189
 
170
- Lambda re_ln_Fn_F_B_0(B.chain, B.base);
171
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
172
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
173
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
174
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
175
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
176
-
177
-for (int j = 0; j < B.chain.Nstrings; ++j) {
178
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
179
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
180
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
181
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
182
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
183
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
184
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
185
-    }
186
-  }
190
+      for (int i = 0; i < A.chain.Nstrings; ++i)
191
+	for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
192
+	  for (int a = 1; a <= A.chain.Str_L[i]; ++a)
193
+	    ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
187 194
 
188
-  complex<DP> ln_prod1 = 0.0;
189
-  complex<DP> ln_prod2 = 0.0;
190
-  complex<DP> ln_prod3 = 0.0;
191
-  complex<DP> ln_prod4 = 0.0;
192
-
193
-  for (int i = 0; i < A.chain.Nstrings; ++i)
194
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
195
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
196
-	ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
197
-
198
-  for (int i = 0; i < B.chain.Nstrings; ++i)
199
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
200
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
201
-	if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
202
-	  ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
203
-
204
-  // Define regularized products in prefactors
205
-  for (int j = 0; j < A.chain.Nstrings; ++j)
206
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
207
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
208
-	ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
209
-
210
-  for (int k = 0; k < B.chain.Nstrings; ++k)
211
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
212
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
213
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
214
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
215
-    }
216
-  result += 2.0*real(ln_prod1 - ln_prod2) - real(ln_prod3)  + real(ln_prod4)  - A.lnnorm - B.lnnorm;
217
-// Define the F ones earlier...
195
+      for (int i = 0; i < B.chain.Nstrings; ++i)
196
+	for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
197
+	  for (int a = 1; a <= B.chain.Str_L[i]; ++a)
198
+	    if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
199
+	      ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
218 200
 
219
-  int index_a = 0;
220
-  int index_b = 0;
221
-  complex<DP> Prod_powerN;
201
+      // Define regularized products in prefactors
202
+      for (int j = 0; j < A.chain.Nstrings; ++j)
203
+	for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
204
+	  for (int a = 1; a <= A.chain.Str_L[j]; ++a)
205
+	    ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
222 206
 
223
-  //mu is the ground state!
224
-  //A -> mu, B -> lam
225
-SQMat_CX H(0.0, A.base.Mdown);
226
- index_a = 0;
207
+      for (int k = 0; k < B.chain.Nstrings; ++k)
208
+	for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
209
+	  for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
210
+	    if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
211
+	    else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
212
+	  }
213
+      result += 2.0*real(ln_prod1 - ln_prod2) - real(ln_prod3)  + real(ln_prod4)  - A.lnnorm - B.lnnorm;
214
+      // Define the F ones earlier...
227 215
 
228
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
229
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
230
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
216
+      int index_a = 0;
217
+      int index_b = 0;
218
+      complex<DP> Prod_powerN;
231 219
 
232
-	index_b = 0;
220
+      //mu is the ground state!
221
+      //A -> mu, B -> lam
222
+      SQMat_CX H(0.0, A.base.Mdown);
223
+      index_a = 0;
233 224
 
234
-	complex<DP> Da;
235
-	complex<DP> Ca;
236
-	Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
237
-	Ca=eta*((mu[index_a]-eta*0.5)+(mu[index_a]+eta*0.5))/pow(((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5)),2.0);
225
+      for (int j = 0; j < A.chain.Nstrings; ++j) {
226
+	for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
227
+	  for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
238 228
 
229
+	    index_b = 0;
239 230
 
240
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
241
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
242
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
231
+	    complex<DP> Da;
232
+	    complex<DP> Ca;
233
+	    Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
234
+	    Ca=eta*((mu[index_a]-eta*0.5)+(mu[index_a]+eta*0.5))/pow(((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5)),2.0);
243 235
 
244
-	      if (B.chain.Str_L[k] == 1) {
245 236
 
237
+	    for (int k = 0; k < B.chain.Nstrings; ++k) {
238
+	      for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
239
+		for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
246 240
 
247
-		complex<DP> prodplus= complex<DP>(1.0,0.0);
248
-		complex<DP> prodminus= complex<DP>(1.0,0.0);
241
+		  if (B.chain.Str_L[k] == 1) {
249 242
 
250
-		// use simplified code for one-string here:  original form of Hm2P matrix
251
-		prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
252
-		prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
253 243
 
254
-		prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
255
-	        prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
244
+		    complex<DP> prodplus= complex<DP>(1.0,0.0);
245
+		    complex<DP> prodminus= complex<DP>(1.0,0.0);
256 246
 
257
-		Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5), complex<DP> (B.chain.Nsites));
258
-		H[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
259
-	      } // if (B.chain.Str_L == 1)
247
+		    // use simplified code for one-string here:  original form of Hm2P matrix
248
+		    prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
249
+		    prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta]
250
+				   - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
260 251
 
261
-	      else {
262
-		// */{
252
+		    prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
253
+		    prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta]
254
+				    - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
263 255
 
264
-		if (b > 1){
265
-		  H[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)*exp(ln_Fn_G(A,B,k,beta,b-1))*exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
266
-		}
267
-		else if (b == 1) {
256
+		    Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5), complex<DP> (B.chain.Nsites));
257
+		    H[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
258
+		  } // if (B.chain.Str_L == 1)
268 259
 
269
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
270
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
260
+		  else {
261
+		    // */{
271 262
 
272
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
273
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
263
+		    if (b > 1){
264
+		      H[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)
265
+			*exp(ln_Fn_G(A,B,k,beta,b-1))
266
+			*exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
267
+		    }
268
+		    else if (b == 1) {
274 269
 
275
-		  complex<DP> sum1 = complex<DP>(0.0,0.0);
270
+		      Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
271
+		      for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
276 272
 
277
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1]
278
-			  - ln_FunctionF[0] - ln_FunctionF[1]);//sum term when i=0
273
+		      Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
274
+		      for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
279 275
 
280
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
281
-		    * exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
282
-			- ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]); //sum term when i=n
276
+		      complex<DP> sum1 = complex<DP>(0.0,0.0);
283 277
 
278
+		      sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1]
279
+									- ln_FunctionF[0] - ln_FunctionF[1]);//sum term when i=0
284 280
 
285
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum) {
286
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
287
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
281
+		      sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
282
+			* exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
283
+			       - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]); //sum term when i=n
288 284
 
289
-		  }
290 285
 
291
-		  H[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1))); //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
292
-		} // else if (b == B.chain.Str_L[k])
293
-	      } // else
294
-	      index_b++;
295
-	    }}} // sums over k, beta, b
286
+		      for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum) {
287
+			sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
288
+			  exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
289
+
290
+		      }
291
+
292
+		      H[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1])
293
+			* sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1)));
294
+		      //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
295
+		    } // else if (b == B.chain.Str_L[k])
296
+		  } // else
297
+		  index_b++;
298
+		}}} // sums over k, beta, b
296 299
 
297
-	// now define the elements H[a][M] & H[a][M-1]
298
-	H[index_a][B.base.Mdown]=Da;
299
-	H[index_a][B.base.Mdown+1]=Ca;
300
-	index_a++;
301
-	}}} // sums over j, alpha, a
300
+	    // now define the elements H[a][M] & H[a][M-1]
301
+	    H[index_a][B.base.Mdown]=Da;
302
+	    H[index_a][B.base.Mdown+1]=Ca;
303
+	    index_a++;
304
+	  }}} // sums over j, alpha, a
302 305
 
303
-  complex<DP> logF=lndet_LU_CX_dstry(H);
304
-  result+=2.0*real(logF);
305
-  result+=log(2.0)-log((A.chain.Nsites-A.base.Mdown*2+3.0)*((A.chain.Nsites-A.base.Mdown*2+4.0)));
306
-  if (!(real_dev_conv) && abs(exp(result)-exp(prev_result))<abs( Diff_ME_Thres*exp(result)))
307
-    real_dev_conv=true;
306
+      complex<DP> logF=lndet_LU_CX_dstry(H);
307
+      result+=2.0*real(logF);
308
+      result+=log(2.0)-log((A.chain.Nsites-A.base.Mdown*2+3.0)*((A.chain.Nsites-A.base.Mdown*2+4.0)));
309
+      if (!(real_dev_conv) && abs(exp(result)-exp(prev_result))<abs( Diff_ME_Thres*exp(result)))
310
+	real_dev_conv=true;
308 311
 
309
-  if (!(real_dev_conv) && dev >20){
310
-    result=-300;
311
-    real_dev_conv=true;
312
-  }
312
+      if (!(real_dev_conv) && dev >20){
313
+	result=-300;
314
+	real_dev_conv=true;
315
+      }
313 316
 
314
- delete[] mu;
315
- delete[] lam;
317
+      delete[] mu;
318
+      delete[] lam;
316 319
 
320
+    }
321
+    return(0.5 * result); // Return ME, not MEsq
317 322
   }
318
-  //return(result);
319
-  return(0.5 * result); // Return ME, not MEsq
320
-}
321 323
 
322 324
 } // namespace ABACUS

+ 171
- 175
src/HEIS/ln_Sz_ME_XXX.cc View File

@@ -19,234 +19,230 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
23
-{
24
-  complex<DP> ans = 0.0;
25
-
26
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
27
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
28
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
29
-
30
-	if (!((j == k) && (alpha == beta) && (a == b)))
31
-	  ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
32
-		     + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
22
+  inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
23
+  {
24
+    complex<DP> ans = 0.0;
25
+
26
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
27
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
28
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
29
+
30
+	  if (!((j == k) && (alpha == beta) && (a == b)))
31
+	    ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
32
+		       + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
33
+	}
33 34
       }
34 35
     }
35
-  }
36 36
 
37
-  return(ans);
38
-}
37
+    return(ans);
38
+  }
39 39
 
40
-inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
41
-{
42
-  complex<DP> ans = 0.0;
40
+  inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
41
+  {
42
+    complex<DP> ans = 0.0;
43 43
 
44
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
45
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
46
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
44
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
45
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
46
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
47 47
 
48
-	ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
49
-		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
48
+	  ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
49
+		     + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
50
+	}
50 51
       }
51 52
     }
53
+
54
+    return(ans);
52 55
   }
53 56
 
54
-  return(ans);
55
-}
56
-
57
-inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
58
-{
59
-  return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
60
-	       + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
61
-	      * (A.lambda[j][alpha] - B.lambda[k][beta]
62
-		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
63
-}
64
-
65
-inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
66
-{
67
-  return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
68
-		      + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
69
-		      ))
70
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
71
-}
72
-
73
-complex<DP> ln_Sz_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
74
-{
75
-  // This function returns the natural log of the S^z operator matrix element.
76
-  // The A and B states can contain strings.
77
-
78
-  // Check that the two states refer to the same XXX_Chain
79
-
80
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Sz matrix element.");
81
-
82
-  // Check that A and B are compatible:  same Mdown
83
-
84
-  if (A.base.Mdown != B.base.Mdown) ABACUSerror("Incompatible Mdown between the two states in Sz matrix element!");
85
-
86
-  //if (A.iK == B.iK && (A.label != B.label))
87
-  if (A.iK == B.iK && (A.label.compare(B.label) != 0))
88
-    return(-300.0); // matrix element identically vanishes
89
-
90
-  // Some convenient arrays
91
-
92
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
93
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
94
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
95
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
96
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
97
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
98
-
99
-  complex<DP> ln_prod1 = 0.0;
100
-  complex<DP> ln_prod2 = 0.0;
101
-  complex<DP> ln_prod3 = 0.0;
102
-  complex<DP> ln_prod4 = 0.0;
103
-
104
-  for (int i = 0; i < A.chain.Nstrings; ++i)
105
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
106
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
107
-	ln_prod1 += log(norm((A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
108
-
109
-  for (int i = 0; i < B.chain.Nstrings; ++i)
110
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
111
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
112
-	if (norm((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))) > 100.0 * MACHINE_EPS_SQ)
113
-	  ln_prod2 += log(norm((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
114
-
115
-  // Define the F ones earlier...
116
-
117
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
118
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
119
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
120
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
121
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
122
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
123
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
124
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
125
-    }
57
+  inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
58
+  {
59
+    return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
60
+		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
61
+		* (A.lambda[j][alpha] - B.lambda[k][beta]
62
+		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
126 63
   }
127 64
 
128
-  // Define regularized products in prefactors
65
+  inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
66
+  {
67
+    return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
68
+		    + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
69
+		    ))
70
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
71
+  }
72
+
73
+  complex<DP> ln_Sz_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
74
+  {
75
+    // This function returns the natural log of the S^z operator matrix element.
76
+    // The A and B states can contain strings.
77
+
78
+    // Check that the two states refer to the same XXX_Chain
79
+
80
+    if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Sz matrix element.");
81
+
82
+    // Check that A and B are compatible:  same Mdown
129 83
 
130
-  for (int j = 0; j < A.chain.Nstrings; ++j)
131
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
132
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
133
-	ln_prod3 += ln_Fn_F (A, j, alpha, a - 1);
84
+    if (A.base.Mdown != B.base.Mdown) ABACUSerror("Incompatible Mdown between the two states in Sz matrix element!");
134 85
 
135
-  //  ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.zeta)));
86
+    //if (A.iK == B.iK && (A.label != B.label))
87
+    if (A.iK == B.iK && (A.label.compare(B.label) != 0))
88
+      return(-300.0); // matrix element identically vanishes
136 89
 
137
-  for (int k = 0; k < B.chain.Nstrings; ++k)
138
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
139
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
140
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
141
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
90
+    // Some convenient arrays
91
+
92
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
93
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
94
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
95
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
96
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
97
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
98
+
99
+    complex<DP> ln_prod1 = 0.0;
100
+    complex<DP> ln_prod2 = 0.0;
101
+    complex<DP> ln_prod3 = 0.0;
102
+    complex<DP> ln_prod4 = 0.0;
103
+
104
+    for (int i = 0; i < A.chain.Nstrings; ++i)
105
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
106
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
107
+	  ln_prod1 += log(norm((A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
108
+
109
+    for (int i = 0; i < B.chain.Nstrings; ++i)
110
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
111
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
112
+	  if (norm((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))) > 100.0 * MACHINE_EPS_SQ)
113
+	    ln_prod2 += log(norm((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
114
+
115
+    // Define the F ones earlier...
116
+
117
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
118
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
119
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
120
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
121
+	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
122
+	im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
123
+	re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
124
+	im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
125
+      }
142 126
     }
143 127
 
144
-  //  ln_prod4 -= B.base.Mdown * log(abs(sin(B.chain.zeta)));
128
+    // Define regularized products in prefactors
129
+
130
+    for (int j = 0; j < A.chain.Nstrings; ++j)
131
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
132
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a)
133
+	  ln_prod3 += ln_Fn_F (A, j, alpha, a - 1);
145 134
 
146
-  // Now proceed to build the Hm2P matrix
135
+    //  ln_prod3 -= A.base.Mdown * log(abs(sin(A.chain.zeta)));
147 136
 
148
-  SQMat_CX Hm2P(0.0, A.base.Mdown);
137
+    for (int k = 0; k < B.chain.Nstrings; ++k)
138
+      for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
139
+	for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
140
+	  if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
141
+	  else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
142
+	}
149 143
 
150
-  int index_a = 0;
151
-  int index_b = 0;
144
+    //  ln_prod4 -= B.base.Mdown * log(abs(sin(B.chain.zeta)));
152 145
 
153
-  complex<DP> sum1 = 0.0;
154
-  complex<DP> sum2 = 0.0;
155
-  complex<DP> prod_num = 0.0;
156
-  complex<DP> Fn_K_0_G_0 = 0.0;
157
-  complex<DP> Prod_powerN = 0.0;
158
-  complex<DP> Fn_K_1_G_2 = 0.0;
159
-  complex<DP> two_over_A_lambda_sq_plus_1over2sq;
146
+    // Now proceed to build the Hm2P matrix
160 147
 
161
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
162
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
163
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
148
+    SQMat_CX Hm2P(0.0, A.base.Mdown);
164 149
 
165
-	index_b = 0;
150
+    int index_a = 0;
151
+    int index_b = 0;
166 152
 
167
-	two_over_A_lambda_sq_plus_1over2sq = 2.0/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *
168
-						  (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
153
+    complex<DP> sum1 = 0.0;
154
+    complex<DP> sum2 = 0.0;
155
+    complex<DP> prod_num = 0.0;
156
+    complex<DP> Fn_K_0_G_0 = 0.0;
157
+    complex<DP> Prod_powerN = 0.0;
158
+    complex<DP> Fn_K_1_G_2 = 0.0;
159
+    complex<DP> two_over_A_lambda_sq_plus_1over2sq;
169 160
 
170
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
171
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
172
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
161
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
162
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
163
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
173 164
 
174
-	      if (B.chain.Str_L[k] == 1) {
165
+	  index_b = 0;
175 166
 
176
-		// use simplified code for one-string here:  original form of Hm2P matrix
167
+	  two_over_A_lambda_sq_plus_1over2sq = 2.0/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *
168
+						    (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
177 169
 
178
-		Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
179
-		  exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
180
-		Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
181
-		  exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
170
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
171
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
172
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
182 173
 
183
-		Prod_powerN = pow((B.lambda[k][beta]  + 0.5 * II)/(B.lambda[k][beta] - 0.5 * II), complex<DP> (B.chain.Nsites));
174
+		if (B.chain.Str_L[k] == 1) {
184 175
 
185
-		Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
186
-		  - two_over_A_lambda_sq_plus_1over2sq * exp(II*im_ln_Fn_F_B_0[k][beta]);
176
+		  // use simplified code for one-string here:  original form of Hm2P matrix
187 177
 
188
-	      }
178
+		  Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
179
+		    exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
180
+		  Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
181
+		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
189 182
 
190
-	      else {
183
+		  Prod_powerN = pow((B.lambda[k][beta]  + 0.5 * II)/(B.lambda[k][beta] - 0.5 * II),
184
+				    complex<DP> (B.chain.Nsites));
191 185
 
192
-		if (b <= B.chain.Str_L[k] - 1) Hm2P[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
193
-		else if (b == B.chain.Str_L[k]) {
186
+		  Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
187
+		    - two_over_A_lambda_sq_plus_1over2sq * exp(II*im_ln_Fn_F_B_0[k][beta]);
194 188
 
195
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
196
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
189
+		}
197 190
 
198
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
199
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
191
+		else {
200 192
 
201
-		  sum1 = 0.0;
193
+		  if (b <= B.chain.Str_L[k] - 1) Hm2P[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
194
+		  else if (b == B.chain.Str_L[k]) {
202 195
 
203
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
196
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
197
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
204 198
 
205
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
206
-		    * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
207
-			  - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
199
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
200
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
208 201
 
209
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
202
+		    sum1 = 0.0;
210 203
 
211
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
212
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
204
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0)
205
+		      * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
213 206
 
214
-		  sum2 = 0.0;
207
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
208
+		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
209
+			    - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
215 210
 
216
-		  for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
211
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
217 212
 
218
-		  prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]]);
213
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
214
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
219 215
 
220
-		  for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
221
-		    prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1))); // include all string contributions F_B_0 in this term
216
+		    sum2 = 0.0;
222 217
 
223
-		  Hm2P[index_a][index_b] = prod_num * (sum1 - sum2 * two_over_A_lambda_sq_plus_1over2sq);
218
+		    for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)
219
+		      sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
224 220
 
225
-		} // else if (b == B.chain.Str_L[k])
226
-	      } // else
221
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]]);
227 222
 
228
-	      index_b++;
229
-	    }}} // sums over k, beta, b
223
+		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
224
+		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)));
225
+		    // include all string contributions F_B_0 in this term
230 226
 
231
-	index_a++;
232
-      }}} // sums over j, alpha, a
227
+		    Hm2P[index_a][index_b] = prod_num * (sum1 - sum2 * two_over_A_lambda_sq_plus_1over2sq);
233 228
 
234
-  //cout << "Matrix: " << endl;
235
-  //Hm2P.Print();
229
+		  } // else if (b == B.chain.Str_L[k])
230
+		} // else
236 231
 
237
-  DP det = real(lndet_LU_CX_dstry(Hm2P));
232
+		index_b++;
233
+	      }}} // sums over k, beta, b
238 234
 
239
-  complex<DP> ln_ME_sq = log(0.25 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
240
-    //    + 2.0 * real(lndet_LU_CX_dstry(Hm2P))
241
-    + 2.0 * det
242
-    - A.lnnorm - B.lnnorm;
235
+	  index_a++;
236
+	}}} // sums over j, alpha, a
243 237
 
244
-  //cout << "ln_Sz: " << endl << ln_prod1 << "\t" << -ln_prod2 << "\t" << -ln_prod3 << "\t" << ln_prod4 << "\t" << 2.0 * det
245
-  //   << "\t" << -A.lnnorm << "\t" << -B.lnnorm << endl;
238
+    DP det = real(lndet_LU_CX_dstry(Hm2P));
246 239
 
247
-  //return(ln_ME_sq);
248
-  return(0.5 * ln_ME_sq); // Return ME, not MEsq
240
+    complex<DP> ln_ME_sq = log(0.25 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
241
+      + 2.0 * det
242
+      - A.lnnorm - B.lnnorm;
249 243
 
250
-}
244
+    return(0.5 * ln_ME_sq); // Return ME, not MEsq
245
+
246
+  }
251 247
 
252 248
 } // namespace ABACUS

+ 41
- 51
src/HEIS/ln_Sz_ME_XXZ.cc View File

@@ -41,21 +41,15 @@ namespace ABACUS {
41 41
 
42 42
 	    arg = B.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
43 43
 	    absarg = abs(arg);
44
-	    /*
45
-	      prod_temp *= 0.5 *
46
-	      ((B.sinhlambda[j][alpha] * B.coshlambda[k][beta] - B.coshlambda[j][alpha] * B.sinhlambda[k][beta])
47
-	      * (B.chain.co_n_anis_over_2[absarg] * (1.0 + B.chain.par[j] * B.chain.par[k])
48
-	      - sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * (B.chain.par[k] - B.chain.par[j]))
49
-	      + II * (B.coshlambda[j][alpha] * B.coshlambda[k][beta] - B.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
50
-	      * (sgn_int(arg)
51
-	      * B.chain.si_n_anis_over_2[absarg] * (1.0 + B.chain.par[j] * B.chain.par[k])
52
-	      + B.chain.co_n_anis_over_2[absarg] * (B.chain.par[k] - B.chain.par[j])) );
53
-	    */
54
-	    prod_temp *= ((B.sinhlambda[j][alpha] * B.coshlambda[k][beta] - B.coshlambda[j][alpha] * B.sinhlambda[k][beta])
55
-			  * (B.chain.co_n_anis_over_2[absarg] * par_comb_1 - sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_2)
56
-			  + II * (B.coshlambda[j][alpha] * B.coshlambda[k][beta] - B.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
57
-			  * (sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_1 + B.chain.co_n_anis_over_2[absarg] * par_comb_2));
58 44
 
45
+	    prod_temp *= ((B.sinhlambda[j][alpha] * B.coshlambda[k][beta]
46
+			   - B.coshlambda[j][alpha] * B.sinhlambda[k][beta])
47
+			  * (B.chain.co_n_anis_over_2[absarg] * par_comb_1
48
+			     - sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_2)
49
+			  + II * (B.coshlambda[j][alpha] * B.coshlambda[k][beta]
50
+				  - B.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
51
+			  * (sgn_int(arg) * B.chain.si_n_anis_over_2[absarg] * par_comb_1
52
+			     + B.chain.co_n_anis_over_2[absarg] * par_comb_2));
59 53
 	  }
60 54
 
61 55
 	  if (counter++ > 100) {  // we do at most 100 products before taking a log
@@ -90,19 +84,14 @@ namespace ABACUS {
90 84
 	  arg = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
91 85
 	  absarg = abs(arg);
92 86
 
93
-	  /*
94
-	    prod_temp *= 0.5 *
95
-	    ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
96
-	    * (A.chain.co_n_anis_over_2[absarg] * (1.0 + A.chain.par[j] * B.chain.par[k])
97
-	    - sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * (B.chain.par[k] - A.chain.par[j]))
98
-	    + II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
99
-	    * (sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * (1.0 + A.chain.par[j] * B.chain.par[k])
100
-	    + A.chain.co_n_anis_over_2[absarg] * (B.chain.par[k] - A.chain.par[j])) );
101
-	  */
102
-	  prod_temp *= ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta] - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
103
-			* (A.chain.co_n_anis_over_2[absarg] * par_comb_1 - sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_2)
104
-			+ II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta] - A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
105
-			* (sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_1 + A.chain.co_n_anis_over_2[absarg] * par_comb_2));
87
+	  prod_temp *= ((A.sinhlambda[j][alpha] * B.coshlambda[k][beta]
88
+			 - A.coshlambda[j][alpha] * B.sinhlambda[k][beta])
89
+			* (A.chain.co_n_anis_over_2[absarg] * par_comb_1
90
+			   - sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_2)
91
+			+ II * (A.coshlambda[j][alpha] * B.coshlambda[k][beta]
92
+				- A.sinhlambda[j][alpha] * B.sinhlambda[k][beta])
93
+			* (sgn_int(arg) * A.chain.si_n_anis_over_2[absarg] * par_comb_1
94
+			   + A.chain.co_n_anis_over_2[absarg] * par_comb_2));
106 95
 
107 96
 	  if (counter++ > 100) {  // we do at most 100 products before taking a log
108 97
 	    ans += log(prod_temp);
@@ -213,8 +202,6 @@ namespace ABACUS {
213 202
     for (int j = 0; j < B.chain.Nstrings; ++j) {
214 203
       for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
215 204
 	ln_Fn_F_B_0 = ln_Fn_F(B, j, alpha, 0);
216
-	//re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
217
-	//im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
218 205
 	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F_B_0);
219 206
 	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F_B_0);
220 207
 	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
@@ -267,11 +254,12 @@ namespace ABACUS {
267 254
 
268 255
 	  index_b = 0;
269 256
 
270
-	  two_over_A_sinhlambda_sq_plus_sinzetaover2sq = 2.0/((sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
271
-								    + 0.25 * II * PI * (1.0 - A.chain.par[j])))
272
-							      * (sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
273
-								      + 0.25 * II * PI * (1.0 - A.chain.par[j])))
274
-							      + pow(sin(0.5*A.chain.anis), 2.0));
257
+	  two_over_A_sinhlambda_sq_plus_sinzetaover2sq
258
+	    = 2.0/((sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
259
+			 + 0.25 * II * PI * (1.0 - A.chain.par[j])))
260
+		   * (sinh(A.lambda[j][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)
261
+			   + 0.25 * II * PI * (1.0 - A.chain.par[j])))
262
+		   + pow(sin(0.5*A.chain.anis), 2.0));
275 263
 
276 264
 	  for (int k = 0; k < B.chain.Nstrings; ++k) {
277 265
 	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
@@ -287,16 +275,19 @@ namespace ABACUS {
287 275
 		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinzeta);
288 276
 
289 277
 		  Prod_powerN = pow( B.chain.par[k] == 1 ?
290
-				     (B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1] + II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
291
-				     /(B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1] - II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
278
+				     (B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1]
279
+				      + II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
280
+				     /(B.sinhlambda[k][beta] * B.chain.co_n_anis_over_2[1]
281
+				       - II * B.coshlambda[k][beta] * B.chain.si_n_anis_over_2[1])
292 282
 				     :
293
-				     (B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1] + II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
294
-				     /(B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1] - II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
283
+				     (B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1]
284
+				      + II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
285
+				     /(B.coshlambda[k][beta] * B.chain.co_n_anis_over_2[1]
286
+				       - II * B.sinhlambda[k][beta] * B.chain.si_n_anis_over_2[1])
295 287
 				     , complex<DP> (B.chain.Nsites));
296 288
 
297
-		  //cout << "Prod_powerN = " << Prod_powerN << "\t" << abs(Prod_powerN) << endl;
298
-
299
-		  Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2 - two_over_A_sinhlambda_sq_plus_sinzetaover2sq
289
+		  Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
290
+		    - two_over_A_sinhlambda_sq_plus_sinzetaover2sq
300 291
 		    * exp(II*im_ln_Fn_F_B_0[k][beta] + logabssinzeta);
301 292
 
302 293
 		}
@@ -314,7 +305,8 @@ namespace ABACUS {
314 305
 
315 306
 		    sum1 = 0.0;
316 307
 
317
-		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
308
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0)
309
+		      * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
318 310
 
319 311
 		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
320 312
 		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
@@ -327,9 +319,11 @@ namespace ABACUS {
327 319
 
328 320
 		    sum2 = 0.0;
329 321
 
330
-		    for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
322
+		    for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)
323
+		      sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
331 324
 
332
-		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]] + logabssinzeta);
325
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1]
326
+				   - ln_FunctionG[B.chain.Str_L[k]] + logabssinzeta);
333 327
 
334 328
 		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
335 329
 		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_FunctionF[jsum - 1]) + logabssinzeta);
@@ -348,12 +342,8 @@ namespace ABACUS {
348 342
     DP re_ln_det = real(lndet_LU_CX_dstry(Hm2P));
349 343
 
350 344
     complex<DP> ln_ME_sq = log(0.25 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
351
-      + 2.0 * /*real(lndet_LU_CX_dstry(Hm2P))*/ re_ln_det - A.lnnorm - B.lnnorm;
352
-
353
-    //cout << endl << ln_prod1 << "\t" << ln_prod2 << "\t" << ln_prod3 << "\t" << ln_prod4 << "\t" << A.lnnorm << "\t" << B.lnnorm
354
-    //<< "\t" << re_ln_det << "\t" << ln_ME_sq << endl;
345
+      + 2.0 * re_ln_det - A.lnnorm - B.lnnorm;
355 346
 
356
-    //return(ln_ME_sq);
357 347
     return(0.5 * ln_ME_sq); // Return ME, not MEsq
358 348
 
359 349
   }
@@ -405,14 +395,14 @@ namespace ABACUS {
405 395
       for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
406 396
 	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
407 397
 	  ln_prod1 += log(sinh(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
408
-				    + 0.25 * II * PI * (1.0 - A.chain.par[i])));
398
+			       + 0.25 * II * PI * (1.0 - A.chain.par[i])));
409 399
 
410 400
     complex<DP> shB;
411 401
     for (int i = 0; i < B.chain.Nstrings; ++i)
412 402
       for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
413 403
 	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
414 404
 	  if (norm(shB = sinh(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
415
-			+ 0.25 * II * PI * (1.0 - B.chain.par[i]))) > 100.0 * MACHINE_EPS_SQ)
405
+			      + 0.25 * II * PI * (1.0 - B.chain.par[i]))) > 100.0 * MACHINE_EPS_SQ)
416 406
 	    //ln_prod2 += log(norm(sinh(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)
417 407
 	    //			      + 0.25 * II * PI * (1.0 - B.chain.par[i]))));
418 408
 	    ln_prod2 += log(shB);

+ 214
- 250
src/HEIS/ln_Sz_ME_XXZ_gpd.cc View File

@@ -19,301 +19,265 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-inline complex<DP> ln_Fn_F (XXZ_gpd_Bethe_State& B, int k, int beta, int b)
23
-{
24
-  complex<DP> ans = 0.0;
25
-  complex<DP> prod_temp = 1.0;
26
-  int counter = 0;
27
-
28
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
29
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
30
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
31
-	/*
32
-	if (!((j == k) && (alpha == beta) && (a == b)))
33
-	  ans += log(-II * sin(B.lambda[j][alpha] - B.lambda[k][beta]
34
-			    + 0.5 * II * B.chain.eta * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))));
35
-	*/
36
-
37
-	if (!((j == k) && (alpha == beta) && (a == b))) {
38
-
39
-	  //	  arg = B.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
40
-	  //	  absarg = abs(arg);
41
-
42
-	  prod_temp *= -II * (B.sinlambda[j][alpha] * B.coslambda[k][beta] - B.coslambda[j][alpha] * B.sinlambda[k][beta])
43
-	    * cosh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
44
-	    (B.coslambda[j][alpha] * B.coslambda[k][beta] + B.sinlambda[j][alpha] * B.sinlambda[k][beta])
45
-	    * sinh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
22
+  inline complex<DP> ln_Fn_F (XXZ_gpd_Bethe_State& B, int k, int beta, int b)
23
+  {
24
+    complex<DP> ans = 0.0;
25
+    complex<DP> prod_temp = 1.0;
26
+    int counter = 0;
27
+
28
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
29
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
30
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
31
+	  if (!((j == k) && (alpha == beta) && (a == b))) {
32
+	    prod_temp *= -II * (B.sinlambda[j][alpha] * B.coslambda[k][beta] - B.coslambda[j][alpha] * B.sinlambda[k][beta])
33
+	      * cosh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
34
+	      (B.coslambda[j][alpha] * B.coslambda[k][beta] + B.sinlambda[j][alpha] * B.sinlambda[k][beta])
35
+	      * sinh(0.5 * B.chain.anis * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
36
+	  }
37
+
38
+	  if (counter++ > 10) {  // we do at most 10 products before taking a log
39
+	    ans += log(prod_temp);
40
+	    prod_temp = 1.0;
41
+	    counter = 0;
42
+	  }
43
+
44
+	}}}
45
+
46
+    return(ans + log(prod_temp));
47
+  }
46 48
 
47
-	}
49
+  inline complex<DP> ln_Fn_G (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
50
+  {
51
+    complex<DP> ans = 0.0;
52
+    complex<DP> prod_temp = 1.0;
53
+    int counter = 0;
54
+
55
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
56
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
57
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
58
+
59
+	  prod_temp *= -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
60
+	    * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
61
+	    (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
62
+	    * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
63
+
64
+	  if (counter++ > 25) {  // we do at most 25 products before taking a log
65
+	    ans += log(prod_temp);
66
+	    prod_temp = 1.0;
67
+	    counter = 0;
68
+	  }
69
+	}}}
70
+
71
+    return(ans + log(prod_temp));
72
+  }
48 73
 
74
+  inline complex<DP> Fn_K (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
75
+  {
76
+    return(1.0/(( -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
77
+		  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
78
+		  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
79
+		  * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))) *
80
+		(-II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
81
+		 * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))) +
82
+		 (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
83
+		 * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))))));
49 84
 
50
-	if (counter++ > 10) {  // we do at most 10 products before taking a log
51
-	  ans += log(prod_temp);
52
-	  prod_temp = 1.0;
53
-	  counter = 0;
54
-	}
85
+  }
55 86
 
56
-      }}}
57
-
58
-  //  return(ans);
59
-  return(ans + log(prod_temp));
60
-}
61
-
62
-inline complex<DP> ln_Fn_G (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
63
-{
64
-  complex<DP> ans = 0.0;
65
-  complex<DP> prod_temp = 1.0;
66
-  int counter = 0;
67
-
68
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
69
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
70
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
71
-	/*
72
-	prod_temp *= -II * sin(A.lambda[j][alpha] - B.lambda[k][beta]
73
-		    + 0.5 * II * B.chain.eta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
74
-	*/
75
-
76
-	//	arg = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
77
-	//	absarg = abs(arg);
78
-
79
-	prod_temp *= -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
80
-	  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
81
-	  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
82
-	  * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
83
-
84
-	if (counter++ > 25) {  // we do at most 25 products before taking a log
85
-	  ans += log(prod_temp);
86
-	  prod_temp = 1.0;
87
-	  counter = 0;
88
-	}
89
-      }}}
90
-
91
-  //  return(ans);
92
-  return(ans + log(prod_temp));
93
-}
94
-
95
-inline complex<DP> Fn_K (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
96
-{
97
-  /*
98
-  return(-1.0/(sin(A.lambda[j][alpha] - B.lambda[k][beta]
99
-		    + 0.5 * II * B.chain.zeta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
100
-	      * sin(A.lambda[j][alpha] - B.lambda[k][beta]
101
-		    + 0.5 * II * B.chain.zeta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)))));
102
-  */
103
-
104
-  //  int arg1 = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b);
105
-  //  int absarg1 = abs(arg1);
106
-  //  int arg2 = A.chain.Str_L[j] - B.chain.Str_L[k] - 2 * (a - b - 1);
107
-  //  int arg2 = arg1 + 2;
108
-  //  int absarg2 = abs(arg2);
109
-
110
-  return(1.0/(( -II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
111
-	  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b))) +
112
-	  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
113
-	       * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))) *
114
-	      (-II * (A.sinlambda[j][alpha] * B.coslambda[k][beta] - A.coslambda[j][alpha] * B.sinlambda[k][beta])
115
-	  * cosh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))) +
116
-	  (A.coslambda[j][alpha] * B.coslambda[k][beta] + A.sinlambda[j][alpha] * B.sinlambda[k][beta])
117
-	       * sinh(0.5 * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0))))));
118
-
119
-}
120
-
121
-inline complex<DP> Fn_L (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
122
-{
123
-  /*
124
-  complex<DP> ans = -II * sin(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
125
-				+ 0.5 * II * B.chain.zeta * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))));
126
-
127
-  return (ans * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
128
-  */
129
-  return (-II * sin(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
130
-		      + 0.5 * II * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))))
131
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
132
-}
133
-
134
-complex<DP> ln_Sz_ME (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B)
135
-{
136
-  // This function returns the natural log of the S^z operator matrix element.
137
-  // The A and B states can contain strings.
138
-
139
-  // Check that the two states refer to the same XXZ_gpd_Chain
140
-
141
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXZ_gpd_Chains in Sz matrix element.");
142
-
143
-  // Check that A and B are compatible:  same Mdown
144
-
145
-  if (A.base.Mdown != B.base.Mdown) ABACUSerror("Incompatible Mdown between the two states in Sz matrix element!");
146
-
147
-  if (A.iK == B.iK && (A.label != B.label))
148
-    return(-300.0); // matrix element identically vanishes
149
-
150
-  // Compute the sin and cos of rapidities
151
-
152
-  A.Compute_sinlambda();
153
-  A.Compute_coslambda();
154
-  B.Compute_sinlambda();
155
-  B.Compute_coslambda();
156
-
157
-  // Some convenient arrays
158
-
159
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
160
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
161
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
162
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
163
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
164
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
165
-
166
-  complex<DP> ln_prod1 = 0.0;
167
-  complex<DP> ln_prod2 = 0.0;
168
-  complex<DP> ln_prod3 = 0.0;
169
-  complex<DP> ln_prod4 = 0.0;
170
-
171
-  for (int i = 0; i < A.chain.Nstrings; ++i)
172
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
173
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
174
-	ln_prod1 += log(norm(sin(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
175
-
176
-  for (int i = 0; i < B.chain.Nstrings; ++i)
177
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
178
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
179
-	if (norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))) > 100.0 * MACHINE_EPS_SQ)
180
-	  ln_prod2 += log(norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
181
-
182
-  // Define the F ones earlier...
183
-
184
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
185
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
186
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
187
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
188
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
189
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
190
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
191
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
192
-    }
87
+  inline complex<DP> Fn_L (XXZ_gpd_Bethe_State& A, int j, int alpha, int a, XXZ_gpd_Bethe_State& B, int k, int beta, int b)
88
+  {
89
+    return (-II * sin(2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
90
+			     + 0.5 * II * B.chain.anis * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))))
91
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
193 92
   }
194 93
 
195
-  DP logabssinheta = log(abs(sinh(A.chain.anis)));
94
+  complex<DP> ln_Sz_ME (XXZ_gpd_Bethe_State& A, XXZ_gpd_Bethe_State& B)
95
+  {
96
+    // This function returns the natural log of the S^z operator matrix element.
97
+    // The A and B states can contain strings.
98
+
99
+    // Check that the two states refer to the same XXZ_gpd_Chain
100
+
101
+    if (A.chain != B.chain) ABACUSerror("Incompatible XXZ_gpd_Chains in Sz matrix element.");
102
+
103
+    // Check that A and B are compatible:  same Mdown
104
+
105
+    if (A.base.Mdown != B.base.Mdown)
106
+      ABACUSerror("Incompatible Mdown between the two states in Sz matrix element!");
107
+
108
+    if (A.iK == B.iK && (A.label != B.label))
109
+      return(-300.0); // matrix element identically vanishes
196 110
 
197
-  // Define regularized products in prefactors
111
+    // Compute the sin and cos of rapidities
198 112
 
199
-  for (int j = 0; j < A.chain.Nstrings; ++j)
200
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
201
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a)
202
-	ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
113
+    A.Compute_sinlambda();
114
+    A.Compute_coslambda();
115
+    B.Compute_sinlambda();
116
+    B.Compute_coslambda();
203 117
 
204
-  ln_prod3 -= A.base.Mdown * log(abs(sinh(A.chain.anis)));
118
+    // Some convenient arrays
205 119
 
206
-  for (int k = 0; k < B.chain.Nstrings; ++k)
207
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
208
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
209
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
210
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
120
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
121
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
122
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
123
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
124
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
125
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
126
+
127
+    complex<DP> ln_prod1 = 0.0;
128
+    complex<DP> ln_prod2 = 0.0;
129
+    complex<DP> ln_prod3 = 0.0;
130
+    complex<DP> ln_prod4 = 0.0;
131
+
132
+    for (int i = 0; i < A.chain.Nstrings; ++i)
133
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
134
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
135
+	  ln_prod1 += log(norm(sin(A.lambda[i][alpha] + 0.5 * II * A.chain.anis * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
136
+
137
+    for (int i = 0; i < B.chain.Nstrings; ++i)
138
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
139
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
140
+	  if (norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)))
141
+	      > 100.0 * MACHINE_EPS_SQ)
142
+	    ln_prod2 += log(norm(sin(B.lambda[i][alpha] + 0.5 * II * B.chain.anis * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0))));
143
+
144
+    // Define the F ones earlier...
145
+
146
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
147
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
148
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
149
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
150
+	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
151
+	im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
152
+	re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
153
+	im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
154
+      }
211 155
     }
212 156
 
213
-  ln_prod4 -= B.base.Mdown * log(abs(sinh(B.chain.anis)));
157
+    DP logabssinheta = log(abs(sinh(A.chain.anis)));
214 158
 
215
-  // Now proceed to build the Hm2P matrix
159
+    // Define regularized products in prefactors
216 160
 
217
-  SQMat_CX Hm2P(0.0, A.base.Mdown);
161
+    for (int j = 0; j < A.chain.Nstrings; ++j)
162
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
163
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a)
164
+	  ln_prod3 += ln_Fn_F(A, j, alpha, a - 1);
218 165
 
219
-  int index_a = 0;
220
-  int index_b = 0;
166
+    ln_prod3 -= A.base.Mdown * log(abs(sinh(A.chain.anis)));
221 167
 
222
-  complex<DP> sum1 = 0.0;
223
-  complex<DP> sum2 = 0.0;
224
-  complex<DP> prod_num = 0.0;
225
-  complex<DP> Fn_K_0_G_0 = 0.0;
226
-  complex<DP> Prod_powerN = 0.0;
227
-  complex<DP> Fn_K_1_G_2 = 0.0;
228
-  complex<DP> two_over_A_sinlambda_sq_plus_sinhetaover2sq = 0.0;
168
+    for (int k = 0; k < B.chain.Nstrings; ++k)
169
+      for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
170
+	for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
171
+	  if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
172
+	  else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
173
+	}
229 174
 
230
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
231
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
232
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
175
+    ln_prod4 -= B.base.Mdown * log(abs(sinh(B.chain.anis)));
233 176
 
234
-	index_b = 0;
177
+    // Now proceed to build the Hm2P matrix
235 178
 
236
-	two_over_A_sinlambda_sq_plus_sinhetaover2sq = -2.0/((sin(A.lambda[j][alpha] // minus sign:  from 1/(sinh^2... to -1/(sin^2...
237
-								 + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a))) *
238
-							    (sin(A.lambda[j][alpha] // minus sign:  from 1/(sinh^2... to -1/(sin^2...
239
-								 + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)))
240
-							   + pow(sinh(0.5*A.chain.anis), 2.0));
179
+    SQMat_CX Hm2P(0.0, A.base.Mdown);
241 180
 
242
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
243
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
244
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
181
+    int index_a = 0;
182
+    int index_b = 0;
245 183
 
246
-	      if (B.chain.Str_L[k] == 1) {
184
+    complex<DP> sum1 = 0.0;
185
+    complex<DP> sum2 = 0.0;
186
+    complex<DP> prod_num = 0.0;
187
+    complex<DP> Fn_K_0_G_0 = 0.0;
188
+    complex<DP> Prod_powerN = 0.0;
189
+    complex<DP> Fn_K_1_G_2 = 0.0;
190
+    complex<DP> two_over_A_sinlambda_sq_plus_sinhetaover2sq = 0.0;
247 191
 
248
-		// use simplified code for one-string here:  original form of Hm2P matrix
192
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
193
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
194
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
249 195
 
250
-		Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
251
-		  exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
252
-		Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
253
-		  exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
196
+	  index_b = 0;
254 197
 
255
-		Prod_powerN = pow((B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1] + II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1])
256
-				  /(B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1] - II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1]),
257
-				  complex<DP> (B.chain.Nsites));
198
+	  two_over_A_sinlambda_sq_plus_sinhetaover2sq
199
+	    = -2.0/((sin(A.lambda[j][alpha] // minus sign:  from 1/(sinh^2... to -1/(sin^2...
200
+			 + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a))) *
201
+		    (sin(A.lambda[j][alpha] // minus sign:  from 1/(sinh^2... to -1/(sin^2...
202
+			 + 0.5 * II * A.chain.anis * (A.chain.Str_L[j] + 1.0 - 2.0 * a)))
203
+		    + pow(sinh(0.5*A.chain.anis), 2.0));
258 204
 
259
-		Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
260
-		  - two_over_A_sinlambda_sq_plus_sinhetaover2sq * exp(II*im_ln_Fn_F_B_0[k][beta] + logabssinheta);
205
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
206
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
207
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
261 208
 
262
-	      }
209
+		if (B.chain.Str_L[k] == 1) {
263 210
 
264
-	      else {
211
+		  // use simplified code for one-string here:  original form of Hm2P matrix
265 212
 
266
-		if (b <= B.chain.Str_L[k] - 1) Hm2P[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
267
-		else if (b == B.chain.Str_L[k]) {
213
+		  Fn_K_0_G_0 = Fn_K (A, j, alpha, a, B, k, beta, 0) *
214
+		    exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
215
+		  Fn_K_1_G_2 = Fn_K (A, j, alpha, a, B, k, beta, 1) *
216
+		    exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta] + logabssinheta);
268 217
 
269
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
270
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
218
+		  Prod_powerN = pow((B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1]
219
+				     + II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1])
220
+				    /(B.sinlambda[k][beta] * B.chain.co_n_anis_over_2[1]
221
+				      - II * B.coslambda[k][beta] * B.chain.si_n_anis_over_2[1]),
222
+				    complex<DP> (B.chain.Nsites));
271 223
 
272
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
273
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
224
+		  Hm2P[index_a][index_b] = Fn_K_0_G_0 - Prod_powerN * Fn_K_1_G_2
225
+		    - two_over_A_sinlambda_sq_plus_sinhetaover2sq * exp(II*im_ln_Fn_F_B_0[k][beta] + logabssinheta);
274 226
 
275
-		  sum1 = 0.0;
227
+		}
276 228
 
277
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
229
+		else {
278 230
 
279
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
280
-		    * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
281
-			  - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
231
+		  if (b <= B.chain.Str_L[k] - 1) Hm2P[index_a][index_b] = Fn_K(A, j, alpha, a, B, k, beta, b);
232
+		  else if (b == B.chain.Str_L[k]) {
282 233
 
283
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
234
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
235
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
284 236
 
285
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
286
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
237
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
238
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
287 239
 
288
-		  sum2 = 0.0;
240
+		    sum1 = 0.0;
289 241
 
290
-		  for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)  sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
242
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0)
243
+		      * exp(ln_FunctionG[0] + ln_FunctionG[1] - ln_FunctionF[0] - ln_FunctionF[1]);
291 244
 
292
-		  prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1] - ln_FunctionG[B.chain.Str_L[k]] + logabssinheta);
245
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
246
+		      * exp(ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
247
+			    - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
293 248
 
294
-		  for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
295
-		    prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)) + logabssinheta);
296
-		  // include all string contributions F_B_0 in this term
249
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
297 250
 
298
-		  Hm2P[index_a][index_b] = prod_num * (sum1 - sum2 * two_over_A_sinlambda_sq_plus_sinhetaover2sq);
251
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
252
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
299 253
 
300
-		} // else if (b == B.chain.Str_L[k])
301
-	      } // else
254
+		    sum2 = 0.0;
302 255
 
303
-	      index_b++;
304
-	    }}} // sums over k, beta, b
305
-	index_a++;
306
-      }}} // sums over j, alpha, a
256
+		    for (int jsum = 1; jsum <= B.chain.Str_L[k]; ++jsum)
257
+		      sum2 += exp(ln_FunctionG[jsum] - ln_FunctionF[jsum]);
307 258
 
308
-  complex<DP> ln_ME_sq = log(0.25 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
309
-    + 2.0 * real(lndet_LU_CX_dstry(Hm2P)) - A.lnnorm - B.lnnorm;
259
+		    prod_num = exp(II * im_ln_Fn_F_B_0[k][beta] + ln_FunctionF[1]
260
+				   - ln_FunctionG[B.chain.Str_L[k]] + logabssinheta);
310 261
 
311
-  //cout << endl << ln_prod1 << "\t" << ln_prod2 << "\t" << ln_prod3 << "\t" << ln_prod4 << "\t" << A.lnnorm << "\t" << B.lnnorm << "\t"
312
-  //   << lndet_LU_CX(Hm2P) << endl;
262
+		    for (int jsum = 2; jsum <= B.chain.Str_L[k]; ++jsum)
263
+		      prod_num *= exp(ln_FunctionG[jsum] - real(ln_Fn_F(B, k, beta, jsum - 1)) + logabssinheta);
264
+		    // include all string contributions F_B_0 in this term
313 265
 
314
-  //return(ln_ME_sq);
315
-  return(0.5 * ln_ME_sq); // Return ME, not MEsq
266
+		    Hm2P[index_a][index_b] = prod_num * (sum1 - sum2 * two_over_A_sinlambda_sq_plus_sinhetaover2sq);
316 267
 
317
-}
268
+		  } // else if (b == B.chain.Str_L[k])
269
+		} // else
270
+
271
+		index_b++;
272
+	      }}} // sums over k, beta, b
273
+	  index_a++;
274
+	}}} // sums over j, alpha, a
275
+
276
+    complex<DP> ln_ME_sq = log(0.25 * A.chain.Nsites) + real(ln_prod1 - ln_prod2) - real(ln_prod3) + real(ln_prod4)
277
+      + 2.0 * real(lndet_LU_CX_dstry(Hm2P)) - A.lnnorm - B.lnnorm;
278
+
279
+    return(0.5 * ln_ME_sq); // Return ME, not MEsq
280
+
281
+  }
318 282
 
319 283
 } // namespace ABACUS

+ 284
- 428
src/HEIS/ln_Szm_p_Smz_ME_XXX.cc View File

@@ -20,499 +20,355 @@ using namespace ABACUS;
20 20
 
21 21
 
22 22
 namespace ABACUS {
23
- inline  complex<DP> phi(complex<DP> x){return x;}
24
-inline   complex<DP> a(complex<DP> x){return 1;}
25
-inline   complex<DP> b(complex<DP> x,complex<DP> y, complex<DP> eta){ return phi(x-y)/phi(x-y+complex<DP>(0.0,1.0)*eta);}
26
-inline   complex<DP> d(complex<DP> x, complex<DP> xi, complex<DP> eta, int N){return pow(b(x,xi,eta),N);}
23
+  inline  complex<DP> phi(complex<DP> x){return x;}
24
+  inline   complex<DP> a(complex<DP> x){return 1;}
25
+  inline   complex<DP> b(complex<DP> x,complex<DP> y, complex<DP> eta){ return phi(x-y)/phi(x-y+complex<DP>(0.0,1.0)*eta);}
26
+  inline   complex<DP> d(complex<DP> x, complex<DP> xi, complex<DP> eta, int N){return pow(b(x,xi,eta),N);}
27 27
 
28 28
 
29
-inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
30
-{
31
-  complex<DP> ans = 0.0;
29
+  inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
30
+  {
31
+    complex<DP> ans = 0.0;
32 32
 
33
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
34
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
35
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
33
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
34
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
35
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
36 36
 
37
-	if (!((j == k) && (alpha == beta) && (a == b)))
38
-	  ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
39
-		     + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
37
+	  if (!((j == k) && (alpha == beta) && (a == b)))
38
+	    ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
39
+		       + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
40
+	}
40 41
       }
41 42
     }
42
-  }
43 43
 
44
-  return(ans);
45
-}
44
+    return(ans);
45
+  }
46 46
 
47
-inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
48
-{
49
-  complex<DP> ans = 0.0;
47
+  inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
48
+  {
49
+    complex<DP> ans = 0.0;
50 50
 
51
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
52
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
53
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
51
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
52
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
53
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
54 54
 
55
-	ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
56
-		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
55
+	  ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
56
+		     + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
57
+	}
57 58
       }
58 59
     }
59
-  }
60
-
61
-  return(ans);
62
-}
63
-
64
-inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
65
-{
66
-  return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
67
-	       + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
68
-	      * (A.lambda[j][alpha] - B.lambda[k][beta]
69
-		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
70
-}
71
-
72
-inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
73
-{
74
-  return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
75
-		      + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
76
-		      ))
77
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
78
-}
79
-
80
-
81
-complex<DP> ln_Szm_p_Smz_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
82
-{
83
-  //clock_t start_time_local = clock();
84
-  //A has to be the ground state!
85
-
86
-  // This function returns the natural log of the S^z operator matrix element.
87
-  // The A and B states can contain strings.
88
-
89
-  // Check that the two states refer to the same XXX_Chain
90
-
91
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Szm_p_Smz matrix element.");
92
-
93
-  // Check that A and B are compatible:  same Mdown
94
-
95
-  if (A.base.Mdown != B.base.Mdown + 1) ABACUSerror("Incompatible Mdown between the two states in SzSm_p_SmSz matrix element!");
96
-
97
-  //if (B.type_id > 999999LL) return(complex<DP>(-300.0));
98
-
99
- //add a delta to the origin of the centered strings
100
- for (int i = 0; i < A.chain.Nstrings; ++i)
101
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
102
-      if(abs(A.lambda[i][alpha])<5.55112e-12)A.lambda[i][alpha]=5.55112e-12;
103
- for (int i = 0; i < B.chain.Nstrings; ++i)
104
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
105
-      if(abs(B.lambda[i][alpha])<5.55112e-5)B.lambda[i][alpha]=5.55112e-5;
106
-
107
-  // Some convenient arrays
108
-
109
-  complex<DP> i=complex<DP>(0.0,1.0);
110
-  complex<DP> eta=-i;
111
-  complex<DP> ln_prod = complex<DP>(0.0,0.0);
112
-  complex<DP> result;
113
-  result=log(B.chain.Nsites*1.0/4.0);
114
-
115
-  int sizeA=0;
116
-int sizeB=0;
117
-
118
-  for (int i = 0; i < A.chain.Nstrings; ++i)
119
-    sizeA+=A.base.Nrap[i]*A.chain.Str_L[i];
120
-  for (int i = 0; i < B.chain.Nstrings; ++i)
121
-    sizeB+=B.base.Nrap[i]*B.chain.Str_L[i];
122
-
123
-  complex<DP>* mu = new complex<DP>[sizeA];
124
-  complex<DP>* lam = new complex<DP>[sizeB];
125
-  int index=0;
126
-  for (int i = 0; i < A.chain.Nstrings; ++i)
127
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
128
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
129
-	{
130
-	 //  mu[index]=(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
131
-	  mu[index]=(A.lambda[i][alpha] + 0.5 * -eta * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
132
-	  index++;
133
-	}
134
-
135
-index=0;
136
-  for (int i = 0; i < B.chain.Nstrings; ++i)
137
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
138
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
139
-	{
140
-	 //  lam[index]=(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
141
-	  lam[index]=(B.lambda[i][alpha] + 0.5 * -eta * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
142
-	  index++;
143
-	}
144 60
 
145
- Lambda re_ln_Fn_F_B_0(B.chain, B.base);
146
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
147
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
148
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
149
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
150
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
151
-
152
-  complex<DP> ln_prod1 = 0.0;
153
-  complex<DP> ln_prod2 = 0.0;
154
-  complex<DP> ln_prod3 = 0.0;
155
-  complex<DP> ln_prod4 = 0.0;
156
-
157
-  for (int i = 0; i < A.chain.Nstrings; ++i)
158
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
159
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
160
-	ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
161
-
162
-  for (int i = 0; i < B.chain.Nstrings; ++i)
163
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
164
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
165
-	if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
166
-	  ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
167
-
168
-  // Define the F ones earlier...
169
-
170
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
171
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
172
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
173
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
174
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
175
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
176
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
177
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
178
-    }
61
+    return(ans);
179 62
   }
180 63
 
64
+  inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
65
+  {
66
+    return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
67
+		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
68
+		* (A.lambda[j][alpha] - B.lambda[k][beta]
69
+		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
70
+  }
181 71
 
72
+  inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
73
+  {
74
+    return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
75
+		    + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
76
+		    ))
77
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
78
+  }
182 79
 
183
-// for (int i = 0; i < A.chain.Nstrings; ++i)
184
-//     for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
185
-//       for (int a = 1; a <= A.chain.Str_L[i]; ++a)
186
-// 	ln_prod+=log(abs(phi((A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a))+eta*0.5)))
187
-
188
-//   for (int i = 0; i < B.chain.Nstrings; ++i)
189
-//     for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
190
-//       for (int a = 1; a <= B.chain.Str_L[i]; ++a)
191
-// 	ln_prod+=-log(abs(phi(-(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a))+eta*0.5)));
192
-
193
-// for (int i = 0; i < B.chain.Nstrings; ++i)
194
-//     for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
195
-//       for (int a = 1; a <= B.chain.Str_L[i]; ++a)
196
-// 	for (int j = 0; j < B.chain.Nstrings; ++j)
197
-// 	  for (int beta = 0; beta < B.base.Nrap[j]; ++beta)
198
-// 	    for (int b = 1; b <= B.chain.Str_L[j]; ++b)
199
-// 	      if(i!=j || alpha!=beta ||a!=b)ln_prod3+=-0.5*log(abs(phi((B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a))-(B.lambda[j][beta] + 0.5 * II * (B.chain.Str_L[j] + 1.0 - 2.0 * b))-eta)));
200
-
201
-//  for (int i = 0; i < A.chain.Nstrings; ++i)
202
-//    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
203
-//      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
204
-//        for (int j = 0; j < A.chain.Nstrings; ++j)
205
-// 	 for (int beta = 0; beta < A.base.Nrap[j]; ++beta)
206
-// 	   for (int b = 1; b <= A.chain.Str_L[j]; ++b)
207
-// 	     if(abs((A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a))-(A.lambda[j][beta] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * b))-eta)!=0 && (i!=j && alpha!=beta && a!=b))
208
-// 	       ln_prod3+=-0.5*log(abs((A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a))-(A.lambda[j][beta] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * b))-eta));
209
-
210
-
211
-
212
-//mu is the ground state!
213
-//A -> mu, B -> lam
214
-complex<DP> prod=complex<DP>(1.0,0.0);
215
-complex<DP> prod2=complex<DP>(1.0,0.0);
216
-complex<DP> prod3=complex<DP>(1.0,0.0);
217
- for(int l=0; l<sizeA;l++) prod*=phi(mu[l]+eta*0.5);
218
- for(int l=0; l<sizeB;l++) prod/=phi(lam[l]+eta*0.5);
219
-
220
- for(int l=0; l<sizeA;l++)
221
-    for(int m=0; m<sizeA;m++)
222
-      if(l!=m)prod2*=1.0/sqrt(abs(phi(mu[m]-mu[l]-eta)));
223
-  for(int l=0; l<sizeB;l++)
224
-    for(int m=0; m<sizeB;m++)
225
-      if(abs(lam[m]-lam[l]-eta)!=0 && l!=m)prod3*=1.0/sqrt(abs(phi(lam[m]-lam[l]-eta)));
226
-
227
-  result+=2.0*log(abs(prod))-2.0*log(prod3)+2.0*log(prod2) - A.lnnorm - B.lnnorm;// a factor prod3^2 is inserted in the determinant!
228
-//  cout<<"prod:"<<prod<<endl;
229
-  SQMat_CX Hm(0.0, A.base.Mdown);
230
-  //complex<DP> H[sizeA][sizeA];
231
-  // cout<<"mu[l]:";
232
-//   for(int l=0; l<sizeA;l++)
233
-//     cout<<mu[l]<<", ";
234
-//   cout<<endl;
235
-//   cout<<"lam[l]:";
236
-//   for(int l=0; l<sizeB;l++)
237
-//     cout<<lam[l]<<", ";
238
-//   cout<<endl;
239
-
240
-  int index_a = 0;
241
-  int index_b = 0;
242
-  complex<DP> Prod_powerN;
243
-
244
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
245
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
246
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
247
-
248
-        index_b = 0;
249
-
250
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
251
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
252
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
253
-
254
-	      if (B.chain.Str_L[k] == 1) {
255
-
256
-		complex<DP> prodplus= complex<DP>(1.0,0.0);
257
-		complex<DP> prodminus= complex<DP>(1.0,0.0);
258
-
259
-		// use simplified code for one-string here:  original form of Hm2P matrix
260
-
261
-		prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
262
-		prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
263
-		prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
264
-		prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
265
-
266
-		Prod_powerN = pow((B.lambda[k][beta] -eta*0.5) /(B.lambda[k][beta] +eta*0.5), complex<DP> (B.chain.Nsites));
267
-
268
-		Hm[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
269 80
 
270
-	      } // if (B.chain.Str_L == 1)
81
+  complex<DP> ln_Szm_p_Smz_ME (XXX_Bethe_State& A, XXX_Bethe_State& B)
82
+  {
83
+    //clock_t start_time_local = clock();
84
+    //A has to be the ground state!
85
+
86
+    // This function returns the natural log of the S^z operator matrix element.
87
+    // The A and B states can contain strings.
88
+
89
+    // Check that the two states refer to the same XXX_Chain
90
+
91
+    if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Szm_p_Smz matrix element.");
92
+
93
+    // Check that A and B are compatible:  same Mdown
94
+
95
+    if (A.base.Mdown != B.base.Mdown + 1)
96
+      ABACUSerror("Incompatible Mdown between the two states in SzSm_p_SmSz matrix element!");
97
+
98
+    //if (B.type_id > 999999LL) return(complex<DP>(-300.0));
99
+
100
+    //add a delta to the origin of the centered strings
101
+    for (int i = 0; i < A.chain.Nstrings; ++i)
102
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
103
+	if(abs(A.lambda[i][alpha])<5.55112e-12)A.lambda[i][alpha]=5.55112e-12;
104
+    for (int i = 0; i < B.chain.Nstrings; ++i)
105
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
106
+	if(abs(B.lambda[i][alpha])<5.55112e-5)B.lambda[i][alpha]=5.55112e-5;
107
+
108
+    // Some convenient arrays
109
+
110
+    complex<DP> i=complex<DP>(0.0,1.0);
111
+    complex<DP> eta=-i;
112
+    complex<DP> ln_prod = complex<DP>(0.0,0.0);
113
+    complex<DP> result;
114
+    result=log(B.chain.Nsites*1.0/4.0);
115
+
116
+    int sizeA=0;
117
+    int sizeB=0;
118
+
119
+    for (int i = 0; i < A.chain.Nstrings; ++i)
120
+      sizeA+=A.base.Nrap[i]*A.chain.Str_L[i];
121
+    for (int i = 0; i < B.chain.Nstrings; ++i)
122
+      sizeB+=B.base.Nrap[i]*B.chain.Str_L[i];
123
+
124
+    complex<DP>* mu = new complex<DP>[sizeA];
125
+    complex<DP>* lam = new complex<DP>[sizeB];
126
+    int index=0;
127
+    for (int i = 0; i < A.chain.Nstrings; ++i)
128
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
129
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
130
+	  {
131
+	    mu[index]=(A.lambda[i][alpha] + 0.5 * -eta * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
132
+	    index++;
133
+	  }
134
+
135
+    index=0;
136
+    for (int i = 0; i < B.chain.Nstrings; ++i)
137
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
138
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
139
+	  {
140
+	    lam[index]=(B.lambda[i][alpha] + 0.5 * -eta * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
141
+	    index++;
142
+	  }
143
+
144
+    Lambda re_ln_Fn_F_B_0(B.chain, B.base);
145
+    Lambda im_ln_Fn_F_B_0(B.chain, B.base);
146
+    Lambda re_ln_Fn_G_0(B.chain, B.base);
147
+    Lambda im_ln_Fn_G_0(B.chain, B.base);
148
+    Lambda re_ln_Fn_G_2(B.chain, B.base);
149
+    Lambda im_ln_Fn_G_2(B.chain, B.base);
150
+
151
+    complex<DP> ln_prod1 = 0.0;
152
+    complex<DP> ln_prod2 = 0.0;
153
+    complex<DP> ln_prod3 = 0.0;
154
+    complex<DP> ln_prod4 = 0.0;
155
+
156
+    for (int i = 0; i < A.chain.Nstrings; ++i)
157
+      for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
158
+	for (int a = 1; a <= A.chain.Str_L[i]; ++a)
159
+	  ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
160
+
161
+    for (int i = 0; i < B.chain.Nstrings; ++i)
162
+      for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
163
+	for (int a = 1; a <= B.chain.Str_L[i]; ++a)
164
+	  if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
165
+	    ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
166
+
167
+    // Define the F ones earlier...
168
+
169
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
170
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
171
+	re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
172
+	im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
173
+	re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
174
+	im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
175
+	re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
176
+	im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
177
+      }
178
+    }
271 179
 
272
-	      else {
180
+    //mu is the ground state!
181
+    //A -> mu, B -> lam
182
+    complex<DP> prod=complex<DP>(1.0,0.0);
183
+    complex<DP> prod2=complex<DP>(1.0,0.0);
184
+    complex<DP> prod3=complex<DP>(1.0,0.0);
185
+    for(int l=0; l<sizeA;l++) prod*=phi(mu[l]+eta*0.5);
186
+    for(int l=0; l<sizeB;l++) prod/=phi(lam[l]+eta*0.5);
273 187
 
274
-		if (b > 1) Hm[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)*exp(ln_Fn_G(A,B,k,beta,b-1))*exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
275
-		else if (b == 1) {
188
+    for(int l=0; l<sizeA;l++)
189
+      for(int m=0; m<sizeA;m++)
190
+	if(l!=m)prod2*=1.0/sqrt(abs(phi(mu[m]-mu[l]-eta)));
191
+    for(int l=0; l<sizeB;l++)
192
+      for(int m=0; m<sizeB;m++)
193
+	if(abs(lam[m]-lam[l]-eta)!=0 && l!=m)prod3*=1.0/sqrt(abs(phi(lam[m]-lam[l]-eta)));
276 194
 
277
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
278
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
195
+    result+=2.0*log(abs(prod))-2.0*log(prod3)+2.0*log(prod2) - A.lnnorm - B.lnnorm;// a factor prod3^2 is inserted in the determinant!
196
+    SQMat_CX Hm(0.0, A.base.Mdown);
279 197
 
280
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
281
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
198
+    int index_a = 0;
199
+    int index_b = 0;
200
+    complex<DP> Prod_powerN;
282 201
 
283
-		  complex<DP> sum1 = complex<DP>(0.0,0.0);
202
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
203
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
204
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
284 205
 
285
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1] //sum term when i=0
286
-			  - ln_FunctionF[0] - ln_FunctionF[1]);
206
+	  index_b = 0;
287 207
 
288
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k]) //sum term when i=n
289
-		    * exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
290
-			- ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
208
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
209
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
210
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
291 211
 
292
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
212
+		if (B.chain.Str_L[k] == 1) {
293 213
 
294
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
295
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
214
+		  complex<DP> prodplus= complex<DP>(1.0,0.0);
215
+		  complex<DP> prodminus= complex<DP>(1.0,0.0);
296 216
 
217
+		  // use simplified code for one-string here:  original form of Hm2P matrix
297 218
 
298
-		  Hm[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1))); //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
299
-		} // else if (b == B.chain.Str_L[k])
300
-	      } // else
301
-	      index_b++;
302
-	    }}} // sums over k, beta, b
219
+		  prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
220
+		  prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta]
221
+				 - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
222
+		  prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
223
+		  prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta]
224
+				  - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
303 225
 
304
-	// now define the elements Hm[a][M]
226
+		  Prod_powerN = pow((B.lambda[k][beta] -eta*0.5) /(B.lambda[k][beta] +eta*0.5), complex<DP> (B.chain.Nsites));
305 227
 
306
-	//Hm[index_a][B.base.Mdown] = one_over_A_lambda_sq_plus_1over2sq;
307
-	//Hm[index_a][B.base.Mdown] = eta/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *
308
-	//					  (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
309
-	Hm[index_a][B.base.Mdown] = eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
310
-	index_a++;
311
-      }}} // sums over j, alpha, a
228
+		  Hm[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
312 229
 
313
-//   cout<<"Hm:";
314
-//   for(int j=0; j<sizeA;j++){
315
-//     for(int k=0; k<sizeA;k++) cout<<"Hm["<<j<<"]["<<k<<"]:"<<Hm[j][k]<<", ";
316
-//     cout<<endl;
317
-//   }
230
+		} // if (B.chain.Str_L == 1)
318 231
 
319
-  complex<DP> F= complex<DP>(0.0,0.0);
232
+		else {
320 233
 
321
-  complex<DP> detmatrix;
322
-   detmatrix=exp(lndet_LU_CX_dstry(Hm));
323
-   //cout<<"exp(lndet_LU_CX(Hm)):"<<abs(detmatrix)<<endl;
324
-//  cout<<"exp(i*(A.K-B.K))+1.0):"<<exp(i*(A.K-B.K))+1.0<<"det(matrix):"<<detmatrix<<endl;
325
- //F=-(exp(-i*(A.K-B.K))+1.0)*detmatrix;
234
+		  if (b > 1) Hm[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)
235
+			       *exp(ln_Fn_G(A,B,k,beta,b-1))*exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
236
+		  else if (b == 1) {
326 237
 
327
-//mu is the ground state!
328
-//A -> mu, B -> lam
329
-SQMat_CX G(0.0, A.base.Mdown);
330
-SQMat_CX BbDa(0.0, A.base.Mdown);
331
- index_a = 0;
238
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
239
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
332 240
 
333
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
334
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
335
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
241
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
242
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
336 243
 
337
-	index_b = 0;
244
+		    complex<DP> sum1 = complex<DP>(0.0,0.0);
338 245
 
339
-	complex<DP> Da;
340
-	complex<DP> Ca;
341
-	Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
342
-	Ca=eta*((mu[index_a]-eta*0.5)+(mu[index_a]+eta*0.5))/pow(((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5)),2.0);
246
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1] //sum term when i=0
247
+								      - ln_FunctionF[0] - ln_FunctionF[1]);
343 248
 
249
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k]) //sum term when i=n
250
+		      * exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
251
+			     - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]);
344 252
 
345
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
346
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
347
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
253
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum)
348 254
 
349
-	      /*if (B.chain.Str_L[k] == 1) {
255
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
256
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
350 257
 
351
-		complex<DP> Bb;
352
-		Bb=-(phi(lam[index_b]+eta*0.5)+phi(lam[index_b]-eta*0.5));
353
-		complex<DP> product=complex<DP>(1.0,0.0);
354
-		for(int o=0; o<sizeB;o++)product*=phi(lam[o]-lam[index_b]+eta);
355
-		Bb*=product;
356 258
 
357
-		complex<DP> prodplus= complex<DP>(1.0,0.0);
358
-		complex<DP> prodminus= complex<DP>(1.0,0.0);
259
+		    Hm[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1))); //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
260
+		  } // else if (b == B.chain.Str_L[k])
261
+		} // else
262
+		index_b++;
263
+	      }}} // sums over k, beta, b
359 264
 
360
-		// use simplified code for one-string here:  original form of Hm2P matrix
361
-		prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
362
-		prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
363
-			//prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta]);// - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
364
-		prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
365
-	        prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
366
-		//	prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta]);// - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
265
+	  // now define the elements Hm[a][M]
367 266
 
368
-		Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5), complex<DP> (B.chain.Nsites));
267
+	  Hm[index_a][B.base.Mdown] = eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
268
+	  index_a++;
269
+	}}} // sums over j, alpha, a
369 270
 
370
-		G[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
371
-		BbDa[index_a][index_b]=Bb*Da*exp(- re_ln_Fn_F_B_0[k][beta]);
271
+    complex<DP> F= complex<DP>(0.0,0.0);
372 272
 
373
-	      } // if (B.chain.Str_L == 1)
273
+    complex<DP> detmatrix;
274
+    detmatrix=exp(lndet_LU_CX_dstry(Hm));
374 275
 
375
-	      else {
376
-	      */{
276
+    //mu is the ground state!
277
+    //A -> mu, B -> lam
278
+    SQMat_CX G(0.0, A.base.Mdown);
279
+    SQMat_CX BbDa(0.0, A.base.Mdown);
280
+    index_a = 0;
377 281
 
378
-		if (b > 1){
379
-		  G[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)*exp(ln_Fn_G(A,B,k,beta,b-1))*exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
380
-		  BbDa[index_a][index_b] =0 ;
381
-		}
382
-		else if (b == 1) {
282
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
283
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
284
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
383 285
 
384
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
385
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
286
+	  index_b = 0;
386 287
 
387
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
388
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
288
+	  complex<DP> Da;
289
+	  complex<DP> Ca;
290
+	  Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
291
+	  Ca=eta*((mu[index_a]-eta*0.5)+(mu[index_a]+eta*0.5))/pow(((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5)),2.0);
389 292
 
390
-		  complex<DP> sum1 = complex<DP>(0.0,0.0);
391
-		  complex<DP> sum2 = complex<DP>(0.0,0.0);
392 293
 
393
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1]
394
-			  - ln_FunctionF[0] - ln_FunctionF[1]);//sum term when i=0
395
-		  //sum2 doesn't have a i=0 term
294
+	  for (int k = 0; k < B.chain.Nstrings; ++k) {
295
+	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
296
+	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
396 297
 
397
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
398
-		    * exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
399
-			- ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]); //sum term when i=n
400
-		  sum2 +=  exp(ln_FunctionG[B.chain.Str_L[k]]- ln_FunctionF[B.chain.Str_L[k]] )
401
-		    * (phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * B.chain.Str_L[k]))-eta*0.5)
402
-		       + phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * B.chain.Str_L[k]))+eta*0.5) ); //sum term when i=n
298
+		{
403 299
 
404
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum) {
405
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
406
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
407
-		    sum2 += exp(ln_FunctionG[jsum]- ln_FunctionF[jsum] )
408
-		      * (phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * jsum))-eta*0.5)
409
-			 + phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * jsum))+eta*0.5) );
300
+		  if (b > 1){
301
+		    G[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)
302
+		      *exp(ln_Fn_G(A,B,k,beta,b-1))
303
+		      *exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
304
+		    BbDa[index_a][index_b] =0 ;
410 305
 		  }
411
-
412
-		  G[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1))); //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
413
-		  BbDa[index_a][index_b] = - Da* exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum2 * exp( - real(ln_Fn_F(B, k, beta, b - 1)));//the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
414
-		} // else if (b == B.chain.Str_L[k])
415
-	      } // else
416
-	      index_b++;
417
-	    }}} // sums over k, beta, b
418
-
419
-	// now define the elements Hm[a][M]
420
-
421
-
422
-	//Hm[index_a][B.base.Mdown] = eta/((A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) *  (A.lambda[j][alpha] + 0.5 * II * (A.chain.Str_L[j] + 1.0 - 2.0 * a)) + 0.25);
423
-	G[index_a][B.base.Mdown]=Ca;
424
-	BbDa[index_a][B.base.Mdown]=0;
425
-	index_a++;
306
+		  else if (b == 1) {
307
+
308
+		    Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
309
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
310
+
311
+		    Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
312
+		    for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
313
+
314
+		    complex<DP> sum1 = complex<DP>(0.0,0.0);
315
+		    complex<DP> sum2 = complex<DP>(0.0,0.0);
316
+
317
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1]
318
+								      - ln_FunctionF[0] - ln_FunctionF[1]);//sum term when i=0
319
+		    //sum2 doesn't have a i=0 term
320
+
321
+		    sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
322
+		      * exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
323
+			     - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]); //sum term when i=n
324
+		    sum2 +=  exp(ln_FunctionG[B.chain.Str_L[k]]- ln_FunctionF[B.chain.Str_L[k]] )
325
+		      * (phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * B.chain.Str_L[k]))-eta*0.5)
326
+			 + phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * B.chain.Str_L[k]))+eta*0.5) ); //sum term when i=n
327
+
328
+		    for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum) {
329
+		      sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
330
+			exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
331
+		      sum2 += exp(ln_FunctionG[jsum]- ln_FunctionF[jsum] )
332
+			* (phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * jsum))-eta*0.5)
333
+			   + phi((B.lambda[k][beta] + 0.5 * II * (B.chain.Str_L[k] + 1.0 - 2.0 * jsum))+eta*0.5) );
334
+		    }
335
+
336
+		    G[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1])
337
+		      * sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1))); //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
338
+		    BbDa[index_a][index_b] = - Da* exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1])
339
+		      * sum2 * exp( - real(ln_Fn_F(B, k, beta, b - 1)));//the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
340
+		  } // else if (b == B.chain.Str_L[k])
341
+		} // else
342
+		index_b++;
343
+	      }}} // sums over k, beta, b
344
+
345
+	  // now define the elements Hm[a][M]
346
+	  G[index_a][B.base.Mdown]=Ca;
347
+	  BbDa[index_a][B.base.Mdown]=0;
348
+	  index_a++;
426 349
 	}}} // sums over j, alpha, a
427 350
 
428
-SQMat_CX matrix(0.0, A.base.Mdown);
429
-  for(int a=0; a<sizeA;a++)
430
-    for(int b=0; b<sizeA;b++)
431
-      matrix[a][b]=G[a][b]+BbDa[a][b];
432
-
433
-//  cout<<"matrix:";
434
-//    for(int j=0; j<sizeA;j++){
435
-//      for(int k=0; k<sizeA;k++) cout<<"matrix["<<j<<"]["<<k<<"]:"<<matrix[j][k]<<", ";
436
-//      cout<<endl;
437
-//    }
438
-//  cout<<"matrixtest:";
439
-//    for(int j=0; j<sizeA;j++){
440
-//      for(int k=0; k<sizeA;k++) cout<<"matrixtest["<<j<<"]["<<k<<"]:"<<matrixtest[j][k]<<", ";
441
-//      cout<<endl;
442
-//    }
443
-
444
-// cout<<"BbDa[a][b]:";
445
-//    for(int j=0; j<sizeA;j++){
446
-//      for(int k=0; k<sizeA;k++) cout<<"BbDa["<<j<<"]["<<k<<"]:"<<BbDa[j][k]<<", ";
447
-//      cout<<endl;
448
-//    }
449
-//  cout<<"Bn[b]*Da[a]:";
450
-//    for(int j=0; j<sizeA;j++){
451
-//      for(int k=0; k<sizeA;k++) cout<<"test["<<j<<"]["<<k<<"]:"<<Bn[k]*Da[j]<<", ";
452
-//      cout<<endl;
453
-//    }
454
-
455
- //  cout<<"prod:"<<prod<<endl;
456
-//      cout<<"(exp(lndet_LU_CX_dstry(matrix))-exp(lndet_LU_CX_dstry(G))):"<<(exp(lndet_LU_CX(matrix))-exp(lndet_LU_CX(G)))<<endl;
457
-//      cout<<"(exp(lndet_LU_CX_dstry(matrix)):"<<(exp(lndet_LU_CX(matrix)))<<endl;
458
-
459
-  //cout<<" an(n):"<<an(n)<<" det(matrix):"<<det(matrix)<< " det(Gn):"<<det(Gn)<<" an(n)*(det(matrix)-det(Gn)):"<<an(n)*(det(matrix)-det(Gn))<<endl;
460
-     complex<DP> sum=prod*(exp(lndet_LU_CX_dstry(matrix))-exp(lndet_LU_CX_dstry(G)));
461
-     //sum=conj(prod)*(exp(lndet_LU_CX_dstry(matrix))-exp(lndet_LU_CX_dstry(G)));
462
-
463
-    //cout<<"an(n):"<< an(n)<< "det(matrix):"<<det(matrix)<<" det(Gn):"<<det(Gn)<<endl;
464
-
465
-  //sum_nm_test=(0.5*(lam[0]-lam[1])*(eta*eta+4.0*lam[0]*lam[1]))/pow((lam[0]-eta/2.0)*(lam[0]+eta/2.0)*(lam[1]-eta/2.0)*(lam[1]+eta/2.0),2.0)*(0.5*(mu[0]-mu[1])*(eta*eta+4.0*mu[0]*mu[1]))/pow((mu[0]-eta/2.0)*(mu[0]+eta/2.0)*(mu[1]-eta/2.0)*(mu[1]+eta/2.0),2.0);
466
- //sum_nm_test=(0.5*(lam[0]-lam[1])*(eta*eta+4.0*lam[0]*lam[1]))*(0.5*(mu[0]-mu[1])*(eta*eta+4.0*mu[0]*mu[1]))/pow((mu[0]-eta/2.0)*(mu[0]+eta/2.0)*(mu[1]-eta/2.0)*(mu[1]+eta/2.0),2.0);
467
- //cout<<"F1:"<<F<<endl;
468
-  // F+=4.0*pow(prod,2)*exp(i*(qlam+qmu))*sum_n;
469
-
470
-//  F+=+2.0*exp(i*(A.K-B.K))*sum;
471
-
472
-      complex<DP> F2=exp(eta*(B.K-A.K))*(-2.0*sum);
473
-      complex<DP> F3=(exp(eta*(B.K-A.K)))*(detmatrix);
474
-     F=detmatrix;
475
-   //   cout<<"F1:"<<F*sqrt(exp(result))<<" F2:"<<F2*sqrt(exp(result))<<" F3:"<<F3*sqrt(exp(result))<<endl;
476
-//      cout<<"abs(F1)^2:"<<abs(F*F*(exp(result)))<<" abs(F2)^2:"<<abs(F2*F2*(exp(result)))<<" abs(F3)^2:"<<abs(F3*F3*(exp(result)))<<endl;
477
-//         cout<<"arg(F1):"<<-i*log(F*sqrt(exp(result))/abs(F*sqrt(exp(result))))/M_PI<<" arg(F2):"<<-i*log(F2*sqrt(exp(result))/abs(F2*sqrt(exp(result))))/M_PI<<" arg(F3):"<<-i*log(F3*sqrt(exp(result))/abs(F3*sqrt(exp(result))))/M_PI<<endl;
478
-	//  cout<<"F:"<<(F)<<endl;
479
-  //    cout<<"Smff:"<<exp(result)*4.0*abs(detmatrix*detmatrix)<<endl;
480
-    F+=exp(i*(A.K-B.K))*(2.0*sum*(-1.0)+detmatrix);
351
+    SQMat_CX matrix(0.0, A.base.Mdown);
352
+    for(int a=0; a<sizeA;a++)
353
+      for(int b=0; b<sizeA;b++)
354
+	matrix[a][b]=G[a][b]+BbDa[a][b];
481 355
 
356
+    complex<DP> sum=prod*(exp(lndet_LU_CX_dstry(matrix))-exp(lndet_LU_CX_dstry(G)));
482 357
 
483
-// cout<<"sum:"<<sum<<endl;
484
-//  cout<<"exp(result):"<<exp(result)<<endl;
358
+    complex<DP> F2=exp(eta*(B.K-A.K))*(-2.0*sum);
359
+    complex<DP> F3=(exp(eta*(B.K-A.K)))*(detmatrix);
360
+    F=detmatrix;
361
+    F+=exp(i*(A.K-B.K))*(2.0*sum*(-1.0)+detmatrix);
485 362
 
486
-//TEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
487 363
     result+=2.0*log(abs(F));
488 364
     result-=log(A.chain.Nsites-A.base.Mdown*2+2.0);
489
- //result*=pow(abs((exp(i*(A.K-B.K))+1.0)*detmatrix),2);//*(exp(i*(A.K-B.K))+1.0)
490
- //result*=pow(abs(2.0*exp(i*(A.K-B.K))*sum),2);
491
-//result/=(B.chain.Nsites)*1/16.0;
492
-//cout<<"TEST::::::::::::::::::::::"<<"A.Check_Admissibility('a'):"<<A.Check_Admissibility('a')<<endl;
493
-//cout<<"mu:"<<mu<<" lam:"<<lam<<endl;
494
- // cout<<"an(n):"<<an<<endl;
495
- // cout<<"prod^2:"<<pow(abs(prod),2)<<endl;
496
- // cout<<"prod3:"<<prod3<<endl;
497
-//  cout<<"prod2:"<<prod2<<endl;
498
-
499
-
500
- // cout<<"normlam"<<"normmu:"<<(exp(A.lnnorm))<<":"<<(exp(B.lnnorm))<<endl;
501
-  // cout<<"abs(prod*prod*prod2*sum_n):"<<abs(prod*prod*prod2*sum_n)<<endl;
365
+    complex<DP> ln_ME_sq = result;
502 366
 
367
+    delete[] mu;
368
+    delete[] lam;
503 369
 
504
-    //cout<<"computation time for Szm:"<<clock()-start_time_local<<endl;
505
-complex<DP> ln_ME_sq = result;
370
+    return(0.5 * ln_ME_sq); // Return ME, not MEsq
506 371
 
507
-// if (real(ln_ME_sq) > 10.0) ln_ME_sq = complex<DP> (-300.0); // fix for artificial divergences
508
-
509
- delete[] mu;
510
- delete[] lam;
511
-
512
-
513
-//return(ln_ME_sq);
514
- return(0.5 * ln_ME_sq); // Return ME, not MEsq
515
-
516
-}
372
+  }
517 373
 
518 374
 } // namespace ABACUS

+ 338
- 331
src/HEIS/ln_Szz_ME_XXX.cc View File

@@ -19,62 +19,62 @@ using namespace ABACUS;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-complex<DP> phi(complex<DP> x){return x;}
23
-complex<DP> a(complex<DP> x){return 1;}
24
-complex<DP> b(complex<DP> x,complex<DP> y, complex<DP> eta){ return phi(x-y)/phi(x-y+complex<DP>(0.0,1.0)*eta);}
25
-complex<DP> d(complex<DP> x, complex<DP> xi, complex<DP> eta, int N){return pow(b(x,xi,eta),N);}
22
+  complex<DP> phi(complex<DP> x){return x;}
23
+  complex<DP> a(complex<DP> x){return 1;}
24
+  complex<DP> b(complex<DP> x,complex<DP> y, complex<DP> eta){ return phi(x-y)/phi(x-y+complex<DP>(0.0,1.0)*eta);}
25
+  complex<DP> d(complex<DP> x, complex<DP> xi, complex<DP> eta, int N){return pow(b(x,xi,eta),N);}
26 26
 
27 27
 
28
-inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
29
-{
30
-  complex<DP> ans = 0.0;
28
+  inline complex<DP> ln_Fn_F (XXX_Bethe_State& B, int k, int beta, int b)
29
+  {
30
+    complex<DP> ans = 0.0;
31 31
 
32
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
33
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
34
-      for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
32
+    for (int j = 0; j < B.chain.Nstrings; ++j) {
33
+      for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
34
+	for (int a = 1; a <= B.chain.Str_L[j]; ++a) {
35 35
 
36
-	if (!((j == k) && (alpha == beta) && (a == b)))
37
-	  ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
38
-		     + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
36
+	  if (!((j == k) && (alpha == beta) && (a == b)))
37
+	    ans += log(B.lambda[j][alpha] - B.lambda[k][beta]
38
+		       + 0.5 * II * (B.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
39
+	}
39 40
       }
40 41
     }
41
-  }
42 42
 
43
-  return(ans);
44
-}
43
+    return(ans);
44
+  }
45 45
 
46
-inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
47
-{
48
-  complex<DP> ans = 0.0;
46
+  inline complex<DP> ln_Fn_G (XXX_Bethe_State& A, XXX_Bethe_State& B, int k, int beta, int b)
47
+  {
48
+    complex<DP> ans = 0.0;
49 49
 
50
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
51
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
52
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
50
+    for (int j = 0; j < A.chain.Nstrings; ++j) {
51
+      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
52
+	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
53 53
 
54
-	ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
55
-		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
54
+	  ans += log(A.lambda[j][alpha] - B.lambda[k][beta]
55
+		     + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)));
56
+	}
56 57
       }
57 58
     }
59
+
60
+    return(ans);
58 61
   }
59 62
 
60
-  return(ans);
61
-}
62
-
63
-inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
64
-{
65
-  return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
66
-	       + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
67
-	      * (A.lambda[j][alpha] - B.lambda[k][beta]
68
-		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
69
-}
70
-
71
-inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
72
-{
73
-  return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
74
-		      + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
75
-		      ))
76
-	  * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
77
-}
63
+  inline complex<DP> Fn_K (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
64
+  {
65
+    return(1.0/((A.lambda[j][alpha] - B.lambda[k][beta]
66
+		 + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b)))
67
+		* (A.lambda[j][alpha] - B.lambda[k][beta]
68
+		   + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 1.0)) )));
69
+  }
70
+
71
+  inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_State& B, int k, int beta, int b)
72
+  {
73
+    return ((2.0 * (A.lambda[j][alpha] - B.lambda[k][beta]
74
+		    + 0.5 * II * (A.chain.Str_L[j] - B.chain.Str_L[k] - 2.0 * (a - b - 0.5))
75
+		    ))
76
+	    * pow(Fn_K (A, j, alpha, a, B, k, beta, b), 2.0));
77
+  }
78 78
 
79 79
   complex<DP> ln_Szz_ME (XXX_Bethe_State& A, XXX_Bethe_State& B){
80 80
     //clock_t start_time_local = clock();
@@ -83,350 +83,357 @@ inline complex<DP> Fn_L (XXX_Bethe_State& A, int j, int alpha, int a, XXX_Bethe_
83 83
     const DP real_dev=1.0e-14;
84 84
     const DP Diff_ME_Thres=1.e-6;
85 85
 
86
-  // This function returns the natural log of the S^z operator matrix element.
87
-  // The A and B states can contain strings.
88
-
89
-  // Check that the two states refer to the same XXX_Chain
90
-
91
-  if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Szz matrix element.");
92
-
93
-  // Check that A and B are compatible:  same Mdown
94
-
95
-  if (A.base.Mdown != B.base.Mdown) ABACUSerror("Incompatible Mdown between the two states in Szz matrix element!");
86
+    // This function returns the natural log of the S^z operator matrix element.
87
+    // The A and B states can contain strings.
96 88
 
97
-  complex<DP> eta=-II;
98
-  complex<DP> ln_prod = complex<DP>(0.0,0.0);
99
-  complex<DP> result=-300;
100
-  complex<DP> prev_result=-300;
89
+    // Check that the two states refer to the same XXX_Chain
101 90
 
102
-  //if(A.String_delta()> HEIS_deltaprec) return(complex<DP>(-300.0)); // DEPRECATED in ++T_9
91
+    if (A.chain != B.chain) ABACUSerror("Incompatible XXX_Chains in Szz matrix element.");
103 92
 
104
-if((A.E)==(B.E) && B.chain.Nsites ==B.base.Mdown*2){
105
-   return(2*log(abs((B.E+(B.chain.Nsites)/4.0)/(3.0*sqrt(B.chain.Nsites)))));
106
-}
93
+    // Check that A and B are compatible:  same Mdown
107 94
 
108
-  XXX_Bethe_State A_origin; A_origin=A;
109
-  bool zero_string=false;
110
-  for (int j = 0; j < A_origin.chain.Nstrings; ++j)
111
-    for (int alpha = 0; alpha < A_origin.base.Nrap[j]; ++alpha)
112
-      if(abs(A_origin.lambda[j][alpha])<Zero_Center_Thres) zero_string=true;
95
+    if (A.base.Mdown != B.base.Mdown) ABACUSerror("Incompatible Mdown between the two states in Szz matrix element!");
113 96
 
114
-  // Some convenient arrays
115
-  bool real_dev_conv=false;
116
-  int dev=-1;
117
-  while(!real_dev_conv){
118
-    real_dev_conv=true;
97
+    complex<DP> eta=-II;
98
+    complex<DP> ln_prod = complex<DP>(0.0,0.0);
99
+    complex<DP> result=-300;
100
+    complex<DP> prev_result=-300;
119 101
 
120
-    dev++;
121
-
122
-    //add a delta to the origin of the centered strings
123
-    if(zero_string){
124
-      real_dev_conv=false;
125
-      for (int j = 0; j < A.chain.Nstrings; ++j)
126
-	for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
127
-	  if(abs(A_origin.lambda[j][alpha])<Zero_Center_Thres)
128
-	    A.lambda[j][alpha]=real_dev*pow(10.0,dev);
102
+    if((A.E)==(B.E) && B.chain.Nsites ==B.base.Mdown*2){
103
+      return(2*log(abs((B.E+(B.chain.Nsites)/4.0)/(3.0*sqrt(B.chain.Nsites)))));
129 104
     }
130 105
 
106
+    XXX_Bethe_State A_origin; A_origin=A;
107
+    bool zero_string=false;
108
+    for (int j = 0; j < A_origin.chain.Nstrings; ++j)
109
+      for (int alpha = 0; alpha < A_origin.base.Nrap[j]; ++alpha)
110
+	if(abs(A_origin.lambda[j][alpha])<Zero_Center_Thres) zero_string=true;
111
+
112
+    // Some convenient arrays
113
+    bool real_dev_conv=false;
114
+    int dev=-1;
115
+    while(!real_dev_conv){
116
+      real_dev_conv=true;
117
+
118
+      dev++;
119
+
120
+      //add a delta to the origin of the centered strings
121
+      if(zero_string){
122
+	real_dev_conv=false;
123
+	for (int j = 0; j < A.chain.Nstrings; ++j)
124
+	  for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha)
125
+	    if(abs(A_origin.lambda[j][alpha])<Zero_Center_Thres)
126
+	      A.lambda[j][alpha]=real_dev*pow(10.0,dev);
127
+      }
131 128
 
132
-    prev_result=result;
133
-
134
- //add manualy the ground state value
135
-
136
-
137
-
138
-
139
-  int sizeA=0;
140
-int sizeB=0;
141
-
142
-  for (int i = 0; i < A.chain.Nstrings; ++i)
143
-    sizeA+=A.base.Nrap[i]*A.chain.Str_L[i];
144
-  for (int i = 0; i < B.chain.Nstrings; ++i)
145
-    sizeB+=B.base.Nrap[i]*B.chain.Str_L[i];
146 129
 
147
-  complex<DP>* mu = new complex<DP>[sizeA];
148
-  complex<DP>* lam = new complex<DP>[sizeB];
149
-  int index=0;
150
-  for (int i = 0; i < A.chain.Nstrings; ++i)
151
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
152
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
153
-	{
154
-	  mu[index]=(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
155
-	  index++;
130
+      prev_result=result;
131
+
132
+      //add manualy the ground state value
133
+
134
+      int sizeA=0;
135
+      int sizeB=0;
136
+
137
+      for (int i = 0; i < A.chain.Nstrings; ++i)
138
+	sizeA+=A.base.Nrap[i]*A.chain.Str_L[i];
139
+      for (int i = 0; i < B.chain.Nstrings; ++i)
140
+	sizeB+=B.base.Nrap[i]*B.chain.Str_L[i];
141
+
142
+      complex<DP>* mu = new complex<DP>[sizeA];
143
+      complex<DP>* lam = new complex<DP>[sizeB];
144
+      int index=0;
145
+      for (int i = 0; i < A.chain.Nstrings; ++i)
146
+	for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
147
+	  for (int a = 1; a <= A.chain.Str_L[i]; ++a)
148
+	    {
149
+	      mu[index]=(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a));
150
+	      index++;
151
+	    }
152
+
153
+      index=0;
154
+      for (int i = 0; i < B.chain.Nstrings; ++i)
155
+	for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
156
+	  for (int a = 1; a <= B.chain.Str_L[i]; ++a)
157
+	    {
158
+	      lam[index]=(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
159
+	      index++;
160
+	    }
161
+
162
+      Lambda re_ln_Fn_F_A_0(A.chain, A.base);
163
+      Lambda im_ln_Fn_F_A_0(A.chain, A.base);
164
+      Lambda re_ln_Fn_F_B_0(B.chain, B.base);
165
+      Lambda im_ln_Fn_F_B_0(B.chain, B.base);
166
+      Lambda re_ln_Fn_G_0(B.chain, B.base);
167
+      Lambda im_ln_Fn_G_0(B.chain, B.base);
168
+      Lambda re_ln_Fn_G_2(B.chain, B.base);
169
+      Lambda im_ln_Fn_G_2(B.chain, B.base);
170
+
171
+      complex<DP> ln_prod1 = 0.0;
172
+      complex<DP> ln_prod2 = 0.0;
173
+      complex<DP> ln_prod3 = 0.0;
174
+      complex<DP> ln_prod4 = 0.0;
175
+
176
+      for (int i = 0; i < A.chain.Nstrings; ++i)
177
+	for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
178
+	  for (int a = 1; a <= A.chain.Str_L[i]; ++a)
179
+	    ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
180
+
181
+      for (int i = 0; i < B.chain.Nstrings; ++i)
182
+	for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
183
+	  for (int a = 1; a <= B.chain.Str_L[i]; ++a)
184
+	    if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
185
+	      ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
186
+
187
+      // Define the F ones earlier...
188
+
189
+      for (int j = 0; j < A.chain.Nstrings; ++j) {
190
+	for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
191
+	  re_ln_Fn_F_A_0[j][alpha] = real(ln_Fn_F(A, j, alpha, 0));
192
+	  im_ln_Fn_F_A_0[j][alpha] = imag(ln_Fn_F(A, j, alpha, 0));
156 193
 	}
157
-
158
-index=0;
159
-  for (int i = 0; i < B.chain.Nstrings; ++i)
160
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
161
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
162
-	{
163
-	  lam[index]=(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a));
164
-	  index++;
194
+      }
195
+      for (int j = 0; j < B.chain.Nstrings; ++j) {
196
+	for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
197
+	  re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
198
+	  im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
199
+	  re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
200
+	  im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
201
+	  re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
202
+	  im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
165 203
 	}
166
-
167
-  Lambda re_ln_Fn_F_A_0(A.chain, A.base);
168
-  Lambda im_ln_Fn_F_A_0(A.chain, A.base);
169
-  Lambda re_ln_Fn_F_B_0(B.chain, B.base);
170
-  Lambda im_ln_Fn_F_B_0(B.chain, B.base);
171
-  Lambda re_ln_Fn_G_0(B.chain, B.base);
172
-  Lambda im_ln_Fn_G_0(B.chain, B.base);
173
-  Lambda re_ln_Fn_G_2(B.chain, B.base);
174
-  Lambda im_ln_Fn_G_2(B.chain, B.base);
175
-
176
-  complex<DP> ln_prod1 = 0.0;
177
-  complex<DP> ln_prod2 = 0.0;
178
-  complex<DP> ln_prod3 = 0.0;
179
-  complex<DP> ln_prod4 = 0.0;
180
-
181
-  for (int i = 0; i < A.chain.Nstrings; ++i)
182
-    for (int alpha = 0; alpha < A.base.Nrap[i]; ++alpha)
183
-      for (int a = 1; a <= A.chain.Str_L[i]; ++a)
184
-	ln_prod1 += log(norm(A.lambda[i][alpha] + 0.5 * II * (A.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
185
-
186
-  for (int i = 0; i < B.chain.Nstrings; ++i)
187
-    for (int alpha = 0; alpha < B.base.Nrap[i]; ++alpha)
188
-      for (int a = 1; a <= B.chain.Str_L[i]; ++a)
189
-	if (norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)) > 100.0 * MACHINE_EPS_SQ)
190
-	  ln_prod2 += log(norm(B.lambda[i][alpha] + 0.5 * II * (B.chain.Str_L[i] + 1.0 - 2.0 * a - 1.0)));
191
-
192
-  // Define the F ones earlier...
193
-
194
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
195
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
196
-      re_ln_Fn_F_A_0[j][alpha] = real(ln_Fn_F(A, j, alpha, 0));
197
-      im_ln_Fn_F_A_0[j][alpha] = imag(ln_Fn_F(A, j, alpha, 0));
198
-    }
199
-  }
200
-  for (int j = 0; j < B.chain.Nstrings; ++j) {
201
-    for (int alpha = 0; alpha < B.base.Nrap[j]; ++alpha) {
202
-      re_ln_Fn_F_B_0[j][alpha] = real(ln_Fn_F(B, j, alpha, 0));
203
-      im_ln_Fn_F_B_0[j][alpha] = imag(ln_Fn_F(B, j, alpha, 0));
204
-      re_ln_Fn_G_0[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 0));
205
-      im_ln_Fn_G_0[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 0));
206
-      re_ln_Fn_G_2[j][alpha] = real(ln_Fn_G(A, B, j, alpha, 2));
207
-      im_ln_Fn_G_2[j][alpha] = imag(ln_Fn_G(A, B, j, alpha, 2));
208
-    }
209
-  }
210
-
211
- // Define regularized products in prefactors
212
-
213
-for (int k = 0; k < A.chain.Nstrings; ++k)
214
-    for (int beta = 0; beta < A.base.Nrap[k]; ++beta)
215
-      for (int b = 1; b <= A.chain.Str_L[k]; ++b) {
216
-		if (b == 1)ln_prod3 +=  re_ln_Fn_F_A_0[k][beta];
217
-	else if (b > 1) ln_prod3 += ln_Fn_F(A, k, beta, b - 1);/*TEST*/
218 204
       }
219 205
 
220
-  for (int k = 0; k < B.chain.Nstrings; ++k)
221
-    for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
222
-      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
223
-	if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
224
-	else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
225
-    }
226
-
227
-
228
-complex<DP> prod=complex<DP>(1.0,0.0);
229
- for(int l=0; l<sizeA;l++) prod*=phi(mu[l]+eta*0.5);
230
- for(int l=0; l<sizeB;l++) prod/=phi(lam[l]+eta*0.5);
206
+      // Define regularized products in prefactors
231 207
 
232
- double factor = log((B.chain.Nsites)*1/16.0);
233
-  factor +=(2.0*log(abs(prod)) - real(ln_prod3) + real(ln_prod4) - A.lnnorm - B.lnnorm);// a factor prod4^-2 is inserted in the determinant!
208
+      for (int k = 0; k < A.chain.Nstrings; ++k)
209
+	for (int beta = 0; beta < A.base.Nrap[k]; ++beta)
210
+	  for (int b = 1; b <= A.chain.Str_L[k]; ++b) {
211
+	    if (b == 1)ln_prod3 +=  re_ln_Fn_F_A_0[k][beta];
212
+	    else if (b > 1) ln_prod3 += ln_Fn_F(A, k, beta, b - 1);/*TEST*/
213
+	  }
234 214
 
215
+      for (int k = 0; k < B.chain.Nstrings; ++k)
216
+	for (int beta = 0; beta < B.base.Nrap[k]; ++beta)
217
+	  for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
218
+	    if (b == 1) ln_prod4 += re_ln_Fn_F_B_0[k][beta];
219
+	    else if (b > 1) ln_prod4 += ln_Fn_F(B, k, beta, b - 1);
220
+	  }
235 221
 
236
-  int index_a = 0;
237
-  int index_b = 0;
238
-  complex<DP> Prod_powerN;
239 222
 
223
+      complex<DP> prod=complex<DP>(1.0,0.0);
224
+      for(int l=0; l<sizeA;l++) prod*=phi(mu[l]+eta*0.5);
225
+      for(int l=0; l<sizeB;l++) prod/=phi(lam[l]+eta*0.5);
240 226
 
241
-SQMat_CX H(0.0, A.base.Mdown);
242
-SQMat_CX P(0.0, A.base.Mdown);
243
- index_a = 0;
227
+      double factor = log((B.chain.Nsites)*1/16.0);
228
+      factor +=(2.0*log(abs(prod)) - real(ln_prod3) + real(ln_prod4) - A.lnnorm - B.lnnorm);
229
+      // a factor prod4^-2 is inserted in the determinant!
244 230
 
245
-  for (int j = 0; j < A.chain.Nstrings; ++j) {
246
-    for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
247
-      for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
248 231
 
249
-	index_b = 0;
232
+      int index_a = 0;
233
+      int index_b = 0;
234
+      complex<DP> Prod_powerN;
250 235
 
251
-	complex<DP> Da;
252
-	complex<DP> Ca;
253
-	Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
254 236
 
237
+      SQMat_CX H(0.0, A.base.Mdown);
238
+      SQMat_CX P(0.0, A.base.Mdown);
239
+      index_a = 0;
255 240
 
256
-	for (int k = 0; k < B.chain.Nstrings; ++k) {
257
-	  for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
258
-	    for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
241
+      for (int j = 0; j < A.chain.Nstrings; ++j) {
242
+	for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
243
+	  for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
259 244
 
260
-	      if (B.chain.Str_L[k] == 1) {
245
+	    index_b = 0;
261 246
 
262
-		complex<DP> Bb=complex<DP>(1.0,0.0);
263
-		for(int o=0; o<sizeB;o++)Bb*=phi(lam[o]-lam[index_b]+eta);
247
+	    complex<DP> Da;
248
+	    complex<DP> Ca;
249
+	    Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
264 250
 
265
-		complex<DP> prodplus= complex<DP>(1.0,0.0);
266
-		complex<DP> prodminus= complex<DP>(1.0,0.0);
267 251
 
268
-		// use simplified code for one-string here:  original form of Hm2P matrix
269
-	 	prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);
252
+	    for (int k = 0; k < B.chain.Nstrings; ++k) {
253
+	      for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
254
+		for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
270 255
 
271
-		prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
256
+		  if (B.chain.Str_L[k] == 1) {
272 257
 
273
-		prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);
258
+		    complex<DP> Bb=complex<DP>(1.0,0.0);
259
+		    for(int o=0; o<sizeB;o++)Bb*=phi(lam[o]-lam[index_b]+eta);
274 260
 
275
-	        prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
261
+		    complex<DP> prodplus= complex<DP>(1.0,0.0);
262
+		    complex<DP> prodminus= complex<DP>(1.0,0.0);
276 263
 
277
-		Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5), complex<DP> (B.chain.Nsites));
264
+		    // use simplified code for one-string here:  original form of Hm2P matrix
265
+		    prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);
278 266
 
279
-		H[index_a][index_b] = eta*(prodplus-prodminus*Prod_powerN);
280
-		P[index_a][index_b] = Bb*Da*exp(- re_ln_Fn_F_B_0[k][beta]);
267
+		    prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);
281 268
 
282
-	      } // if (B.chain.Str_L == 1)
269
+		    prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);
283 270
 
284
-	      else {
271
+		    prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);
285 272
 
286
-		if (b > 1){
287
-		   H[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)*exp(ln_Fn_G(A,B,k,beta,b-1))*exp(-real(ln_Fn_F(B, k, beta, b - 1)));//.../ prod_l!=k | phi(lam[l]-lam[k]) |
288
-		  P[index_a][index_b] =0 ;
289
-		}
290
-		else if (b == 1) {
273
+		    Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5),
274
+				      complex<DP> (B.chain.Nsites));
291 275
 
292
-		  Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
293
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
276
+		    H[index_a][index_b] = eta*(prodplus-prodminus*Prod_powerN);
277
+		    P[index_a][index_b] = Bb*Da*exp(- re_ln_Fn_F_B_0[k][beta]);
294 278
 
295
-		  Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
296
-		  for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
279
+		  } // if (B.chain.Str_L == 1)
297 280
 
298
-		  complex<DP> sum1 = complex<DP>(0.0,0.0);
299
-		  complex<DP> sum2 = complex<DP>(0.0,0.0);
281
+		  else {
300 282
 
301
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1]
302
-			  - ln_FunctionF[0] - ln_FunctionF[1]);//sum term when i=0
303
-		  //sum2 doesn't have a i=0 term
283
+		    if (b > 1){
284
+		      H[index_a][index_b] = eta* Fn_K(A, j, alpha, a, B, k, beta, b-1)
285
+			*exp(ln_Fn_G(A,B,k,beta,b-1))*exp(-real(ln_Fn_F(B, k, beta, b - 1)));
286
+		      //.../ prod_l!=k | phi(lam[l]-lam[k]) |
287
+		      P[index_a][index_b] =0 ;
288
+		    }
289
+		    else if (b == 1) {
304 290
 
305
-		  sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
306
-		    * exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
307
-			- ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]); //sum term when i=n
308
-		  sum2 +=  exp(ln_FunctionG[B.chain.Str_L[k]]- ln_FunctionF[B.chain.Str_L[k]] ); //sum term when i=n
291
+		      Vect_CX ln_FunctionF(B.chain.Str_L[k] + 2);
292
+		      for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionF[i] = ln_Fn_F (B, k, beta, i);
309 293
 
310
-		  for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum) {
311
-		    sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
312
-		      exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
313
-		    sum2 +=  exp(ln_FunctionG[jsum]- ln_FunctionF[jsum] );
314
-		  }
294
+		      Vect_CX ln_FunctionG(B.chain.Str_L[k] + 2);
295
+		      for (int i = 0; i < B.chain.Str_L[k] + 2; ++i) ln_FunctionG[i] = ln_Fn_G (A, B, k, beta, i);
315 296
 
316
-		  H[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1))); //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
317
-		  P[index_a][index_b] = - Da* exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1]) * sum2 * exp( - real(ln_Fn_F(B, k, beta, b - 1)));//the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
318
-		} // else if (b == B.chain.Str_L[k])
319
-	      } // else
320
-	      index_b++;
321
-	    }}} // sums over k, beta, b
297
+		      complex<DP> sum1 = complex<DP>(0.0,0.0);
298
+		      complex<DP> sum2 = complex<DP>(0.0,0.0);
322 299
 
323
-	index_a++;
324
-	}}} // sums over j, alpha, a
300
+		      sum1 += Fn_K (A, j, alpha, a, B, k, beta, 0) *exp(ln_FunctionG[0]+ ln_FunctionG[1]
301
+									- ln_FunctionF[0] - ln_FunctionF[1]);//sum term when i=0
302
+		      //sum2 doesn't have a i=0 term
325 303
 
326
-complex<DP> F= complex<DP>(0.0,0.0);
304
+		      sum1 += Fn_K (A, j, alpha, a, B, k, beta, B.chain.Str_L[k])
305
+			* exp( ln_FunctionG[B.chain.Str_L[k]] + ln_FunctionG[B.chain.Str_L[k] + 1]
306
+			       - ln_FunctionF[B.chain.Str_L[k]] - ln_FunctionF[B.chain.Str_L[k] + 1]); //sum term when i=n
307
+		      sum2 +=  exp(ln_FunctionG[B.chain.Str_L[k]]- ln_FunctionF[B.chain.Str_L[k]] ); //sum term when i=n
327 308
 
309
+		      for (int jsum = 1; jsum < B.chain.Str_L[k]; ++jsum) {
310
+			sum1 -= Fn_L (A, j, alpha, a, B, k, beta, jsum) *
311
+			  exp(ln_FunctionG[jsum] + ln_FunctionG[jsum + 1] - ln_FunctionF[jsum] - ln_FunctionF[jsum + 1]);
312
+			sum2 +=  exp(ln_FunctionG[jsum]- ln_FunctionF[jsum] );
313
+		      }
328 314
 
329
-SQMat_CX matrix(0.0, A.base.Mdown);
330
-for(int j=0; j<sizeA;j++)
331
-  for(int k=0; k<sizeA;k++){
332
-    matrix[j][k]=(H[j][k]-2.0*P[j][k]);
333
-  }
334
- complex<DP> detmatrix;
335
-  detmatrix=exp(lndet_LU_CX_dstry(matrix)+0.5*factor);
336
-
337
-SQMat_CX Gn(0.0, A.base.Mdown);
338
-
339
-  complex<DP> sum_n=complex<DP>(0.0,0.0);
340
-  for(int n=0; n<sizeA;n++){
341
-    complex<DP> An;
342
-      An=-phi(lam[n]-eta*0.5);
343
-      for(int m=0; m<sizeA;m++)
344
-	An*=phi(lam[m]-lam[n]+eta);
345
-
346
-    SQMat_CX Gn(0.0, A.base.Mdown);
347
-    SQMat_CX BnbDa(0.0, A.base.Mdown);
348
-    index_a = 0;
349
-
350
-    for (int j = 0; j < A.chain.Nstrings; ++j) {
351
-      for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
352
-	for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
353
-
354
-	  index_b = 0;
315
+		      H[index_a][index_b] = eta * exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1])
316
+			* sum1 * exp( - real(ln_Fn_F(B, k, beta, b - 1)));
317
+		      //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
318
+		      P[index_a][index_b] = - Da* exp(ln_FunctionF[0]+ ln_FunctionF[1] - ln_FunctionG[1])
319
+			* sum2 * exp( - real(ln_Fn_F(B, k, beta, b - 1)));
320
+		      //the absolute value prod_l!=k  phi(lam[l]-lam[k]) : real(ln_...)
321
+		    } // else if (b == B.chain.Str_L[k])
322
+		  } // else
323
+		  index_b++;
324
+		}}} // sums over k, beta, b
355 325
 
356
-	  complex<DP> Da;
357
-	  complex<DP> Ca;
358
-	  Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
359
-	  Ca=(eta)*((mu[index_a]-eta*0.5)+(mu[index_a]+eta*0.5))/pow(((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5)),2.0);
326
+	    index_a++;
327
+	  }}} // sums over j, alpha, a
360 328
 
361
-	  for (int k = 0; k < B.chain.Nstrings; ++k) {
362
-	    for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
363
-	      for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
364
-		if(index_b==n){
365
-		  Gn[index_a][index_b] = Ca*exp(-real(ln_Fn_F(B, k, beta, b - 1)));
366
-		  BnbDa[index_a][index_b] = 0;
367
-		} // else (index_b!=n)
368
-		else if (B.chain.Str_L[k] == 1) {
369
-		  complex<DP> Bnb;
370
-		  Bnb=-phi(lam[index_b]+eta*0.5)/phi(lam[n]-lam[index_b]-eta);
371
-		  complex<DP> product=complex<DP>(1.0,0.0);
372
-		  for(int o=0; o<sizeB;o++)product*=phi(lam[o]-lam[index_b]+eta);
373
-		  Bnb*=product;
329
+      complex<DP> F= complex<DP>(0.0,0.0);
374 330
 
375
-		  complex<DP> prodplus= complex<DP>(1.0,0.0);
376
-		  complex<DP> prodminus= complex<DP>(1.0,0.0);
377 331
 
378
-		  // use simplified code for one-string here:  original form of Hm2P matrix
379
-		  prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
380
-		  prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
381
-		  prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
382
-		  prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta] - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
383
-
384
-		  Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5), complex<DP> (B.chain.Nsites));
385
-
386
-		  Gn[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
387
-		  BnbDa[index_a][index_b]=Bnb*Da*exp(- re_ln_Fn_F_B_0[k][beta]);
388
-
389
-		} // if (B.chain.Str_L == 1)
390
-
391
-		else{
392
-		  ABACUSerror("The Szz matrix element computation is not able to handle string states in the B.state (second argument). This is in development...");
393
-
394
-		} // else
395
-		index_b++;
396
-	      }}} // sums over k, beta, b
397
-
398
-	  index_a++;
399
-	}}} // sums over j, alpha, a
400
-
401
-SQMat_CX matrix(0.0, A.base.Mdown);
402
- for(int a=0; a<sizeA;a++)
403
-   for(int b=0; b<sizeA;b++)
404
-     matrix[a][b]=Gn[a][b]+BnbDa[a][b];
405
- sum_n+=(exp(lndet_LU_CX_dstry(matrix)+0.5*factor+log(An))-exp(lndet_LU_CX_dstry(Gn)+0.5*factor+log(An)));
406
-  }// sum over n
407
-  sum_n*=prod;
408
-
409
-F=(exp(II*(A.K-B.K))+1.0)*detmatrix;
410
-F+=-4.0*exp(II*(A.K-B.K))*sum_n;
411
-
412
-result=2*log(abs(F));
332
+      SQMat_CX matrix(0.0, A.base.Mdown);
333
+      for(int j=0; j<sizeA;j++)
334
+	for(int k=0; k<sizeA;k++){
335
+	  matrix[j][k]=(H[j][k]-2.0*P[j][k]);
336
+	}
337
+      complex<DP> detmatrix;
338
+      detmatrix=exp(lndet_LU_CX_dstry(matrix)+0.5*factor);
339
+
340
+      SQMat_CX Gn(0.0, A.base.Mdown);
341
+
342
+      complex<DP> sum_n=complex<DP>(0.0,0.0);
343
+      for(int n=0; n<sizeA;n++){
344
+	complex<DP> An;
345
+	An=-phi(lam[n]-eta*0.5);
346
+	for(int m=0; m<sizeA;m++)
347
+	  An*=phi(lam[m]-lam[n]+eta);
348
+
349
+	SQMat_CX Gn(0.0, A.base.Mdown);
350
+	SQMat_CX BnbDa(0.0, A.base.Mdown);
351
+	index_a = 0;
352
+
353
+	for (int j = 0; j < A.chain.Nstrings; ++j) {
354
+	  for (int alpha = 0; alpha < A.base.Nrap[j]; ++alpha) {
355
+	    for (int a = 1; a <= A.chain.Str_L[j]; ++a) {
356
+
357
+	      index_b = 0;
358
+
359
+	      complex<DP> Da;
360
+	      complex<DP> Ca;
361
+	      Da=eta/((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5));
362
+	      Ca=(eta)*((mu[index_a]-eta*0.5)+(mu[index_a]+eta*0.5))/pow(((mu[index_a]-eta*0.5)*(mu[index_a]+eta*0.5)),2.0);
363
+
364
+	      for (int k = 0; k < B.chain.Nstrings; ++k) {
365
+		for (int beta = 0; beta < B.base.Nrap[k]; ++beta) {
366
+		  for (int b = 1; b <= B.chain.Str_L[k]; ++b) {
367
+		    if(index_b==n){
368
+		      Gn[index_a][index_b] = Ca*exp(-real(ln_Fn_F(B, k, beta, b - 1)));
369
+		      BnbDa[index_a][index_b] = 0;
370
+		    } // else (index_b!=n)
371
+		    else if (B.chain.Str_L[k] == 1) {
372
+		      complex<DP> Bnb;
373
+		      Bnb=-phi(lam[index_b]+eta*0.5)/phi(lam[n]-lam[index_b]-eta);
374
+		      complex<DP> product=complex<DP>(1.0,0.0);
375
+		      for(int o=0; o<sizeB;o++)product*=phi(lam[o]-lam[index_b]+eta);
376
+		      Bnb*=product;
377
+
378
+		      complex<DP> prodplus= complex<DP>(1.0,0.0);
379
+		      complex<DP> prodminus= complex<DP>(1.0,0.0);
380
+
381
+		      // use simplified code for one-string here:  original form of Hm2P matrix
382
+		      prodplus = Fn_K (A, j, alpha, a, B, k, beta, 0);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]+eta) )
383
+		      prodplus*= exp(re_ln_Fn_G_0[k][beta] + II * im_ln_Fn_G_0[k][beta]
384
+				     - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]+eta) / prod_l!=k  |phi(lam[l]-lam[k]) |;
385
+		      prodminus = Fn_K (A, j, alpha, a, B, k, beta, 1);// 1.0/ (phi(mu[l]-lam[k]) phi(mu[l]-lam[k]-eta) )
386
+		      prodminus*= exp(re_ln_Fn_G_2[k][beta] + II * im_ln_Fn_G_2[k][beta]
387
+				      - re_ln_Fn_F_B_0[k][beta]);//Prod phi(mu[l]-lam[k]-eta)/ prod_l!=k | phi(lam[l]-lam[k]) |;
388
+
389
+		      Prod_powerN = pow((B.lambda[k][beta] - eta*0.5) /(B.lambda[k][beta] + eta*0.5),
390
+					complex<DP> (B.chain.Nsites));
391
+
392
+		      Gn[index_a][index_b] =eta*(prodplus-prodminus*Prod_powerN);
393
+		      BnbDa[index_a][index_b]=Bnb*Da*exp(- re_ln_Fn_F_B_0[k][beta]);
394
+
395
+		    } // if (B.chain.Str_L == 1)
396
+
397
+		    else{
398
+		      ABACUSerror("The Szz matrix element computation is not able to handle string states "
399
+				  "in the B.state (second argument). This is in development...");
400
+
401
+		    } // else
402
+		    index_b++;
403
+		  }}} // sums over k, beta, b
404
+
405
+	      index_a++;
406
+	    }}} // sums over j, alpha, a
407
+
408
+	SQMat_CX matrix(0.0, A.base.Mdown);
409
+	for(int a=0; a<sizeA;a++)
410
+	  for(int b=0; b<sizeA;b++)
411
+	    matrix[a][b]=Gn[a][b]+BnbDa[a][b];
412
+	sum_n+=(exp(lndet_LU_CX_dstry(matrix)+0.5*factor+log(An))-exp(lndet_LU_CX_dstry(Gn)+0.5*factor+log(An)));
413
+      }// sum over n
414
+      sum_n*=prod;
415
+
416
+      F=(exp(II*(A.K-B.K))+1.0)*detmatrix;
417
+      F+=-4.0*exp(II*(A.K-B.K))*sum_n;
418
+
419
+      result=2*log(abs(F));
420
+
421
+      if (!(real_dev_conv) && abs(exp(result)-exp(prev_result))<abs( Diff_ME_Thres*exp(result))){
422
+	real_dev_conv=true;
423
+      }
413 424
 
414
- if (!(real_dev_conv) && abs(exp(result)-exp(prev_result))<abs( Diff_ME_Thres*exp(result))){
415
-   real_dev_conv=true;
416
-}
425
+      if (!(real_dev_conv) && dev >20){
426
+	result=-300;
427
+	real_dev_conv=true;
428
+      }
417 429
 
418
- if (!(real_dev_conv) && dev >20){
419
-   result=-300;
420
-   real_dev_conv=true;
421
- }
430
+      delete[] mu;
431
+      delete[] lam;
422 432
 
423
- delete[] mu;
424
- delete[] lam;
433
+    }
425 434
 
435
+    //return(result);
436
+    return(0.5 * result); // Return ME, not MEsq
426 437
   }
427 438
 
428
-  //return(result);
429
-  return(0.5 * result); // Return ME, not MEsq
430
-}
431
-
432 439
 } // namespace ABACUS

+ 122
- 349
src/INTEG/Integration.cc View File

@@ -30,8 +30,6 @@ namespace ABACUS {
30 30
       rhomin = rhomin_ref;
31 31
       rhomax = rhomax_ref;
32 32
       prec = req_prec;
33
-      //rho_tbl = Vect_DP (Nvals + 1);
34
-      //I_tbl = Vect_DP (Nvals + 1);
35 33
       rho_tbl = new DP[Nvals + 1];
36 34
       I_tbl = new DP[Nvals + 1];
37 35
 
@@ -40,7 +38,6 @@ namespace ABACUS {
40 38
 
41 39
       for (int i = 0; i <= Nvals ; ++i) {
42 40
 	rho_tbl[i] = rhomin * pow(alpha, DP(i));
43
-	//I_tbl[i] = I_integral (rho_tbl[i], req_prec);
44 41
 	I_tbl[i] = function (rho_tbl[i], req_prec);
45 42
       }
46 43
 
@@ -51,14 +48,11 @@ namespace ABACUS {
51 48
 
52 49
   DP I_table::Return_val (DP req_rho) {
53 50
 
54
-    //cout << "requesting I of " << req_rho << endl;
55
-
56 51
     DP used_rho = fabs(req_rho);
57 52
 
58 53
     if (used_rho < rhomin || used_rho >= rhomax)
59 54
       {
60 55
 	cerr << "requesting I of " << setprecision(16) << used_rho << " with rho_min = " << rhomin << endl;
61
-	//return (I_integral (used_rho, req_prec));
62 56
 	return (function (used_rho, prec));
63 57
       }
64 58
 
@@ -67,7 +61,8 @@ namespace ABACUS {
67 61
 
68 62
       // Do linear interpolation between values at index and index + 1
69 63
 
70
-      return((rho_tbl[index + 1] - used_rho) * I_tbl[index] + (used_rho - rho_tbl[index]) * I_tbl[index + 1])/(rho_tbl[index + 1] - rho_tbl[index]);
64
+      return((rho_tbl[index + 1] - used_rho) * I_tbl[index] + (used_rho - rho_tbl[index]) * I_tbl[index + 1])
65
+	/(rho_tbl[index + 1] - rho_tbl[index]);
71 66
 
72 67
     }
73 68
   }
@@ -75,7 +70,8 @@ namespace ABACUS {
75 70
   void I_table::Save () {
76 71
 
77 72
     stringstream outfile_strstream;
78
-    outfile_strstream << "I_rhomin_" << rhomin << "_rhomax_" << rhomax << "_Nvals_" << Nvals << "_prec_" << prec << ".dat";
73
+    outfile_strstream << "I_rhomin_" << rhomin << "_rhomax_" << rhomax
74
+		      << "_Nvals_" << Nvals << "_prec_" << prec << ".dat";
79 75
     string outfile_str = outfile_strstream.str();
80 76
     const char* outfilename = outfile_str.c_str();
81 77
 
@@ -92,7 +88,8 @@ namespace ABACUS {
92 88
   bool I_table::Load (DP rhomin_ref, DP rhomax_ref, int Nvals_ref, DP req_prec) {
93 89
 
94 90
     stringstream infile_strstream;
95
-    infile_strstream << "I_rhomin_" << rhomin_ref << "_rhomax_" << rhomax_ref << "_Nvals_" << Nvals_ref << "_prec_" << req_prec << ".dat";
91
+    infile_strstream << "I_rhomin_" << rhomin_ref << "_rhomax_" << rhomax_ref
92
+		     << "_Nvals_" << Nvals_ref << "_prec_" << req_prec << ".dat";
96 93
     string infile_str = infile_strstream.str();
97 94
     const char* infilename = infile_str.c_str();
98 95
 
@@ -105,8 +102,6 @@ namespace ABACUS {
105 102
     rhomin = rhomin_ref;
106 103
     rhomax = rhomax_ref;
107 104
     prec = req_prec;
108
-    //rho_tbl = Vect_DP (Nvals + 1);
109
-    //I_tbl = Vect_DP (Nvals + 1);
110 105
     rho_tbl = new DP[Nvals + 1];
111 106
     I_tbl = new DP[Nvals + 1];
112 107
 
@@ -157,8 +152,6 @@ namespace ABACUS {
157 152
 
158 153
   DP Integral_table::Return_val (DP req_rho) {
159 154
 
160
-    //cout << "requesting I of " << req_rho << endl;
161
-
162 155
     if (req_rho < rhomin || req_rho >= rhomax)
163 156
       {
164 157
 	cerr << "Requesting I of " << setprecision(16) << req_rho << " with rho_min = " << rhomin << endl;
@@ -192,10 +185,12 @@ namespace ABACUS {
192 185
     outfile.close();
193 186
   }
194 187
 
195
-  bool Integral_table::Load (const char* filenameprefix, DP rhomin_ref, DP rhomax_ref, int Nvals_ref, DP req_prec, int max_nr_pts) {
188
+  bool Integral_table::Load (const char* filenameprefix, DP rhomin_ref, DP rhomax_ref,
189
+			     int Nvals_ref, DP req_prec, int max_nr_pts) {
196 190
 
197 191
     stringstream infile_strstream;
198
-    infile_strstream << "Integral_table_" << filenameprefix << "_rhomin_" << rhomin_ref << "_rhomax_" << rhomax_ref << "_Nvals_" << Nvals_ref << "_prec_" << req_prec << "_maxnrpts_" << max_nr_pts << ".dat";
192
+    infile_strstream << "Integral_table_" << filenameprefix << "_rhomin_" << rhomin_ref << "_rhomax_" << rhomax_ref
193
+		     << "_Nvals_" << Nvals_ref << "_prec_" << req_prec << "_maxnrpts_" << max_nr_pts << ".dat";
199 194
     string infile_str = infile_strstream.str();
200 195
     const char* infilename = infile_str.c_str();
201 196
 
@@ -203,7 +198,6 @@ namespace ABACUS {
203 198
     infile.open(infilename);
204 199
 
205 200
     if (infile.fail()) {
206
-      //cout << "Failed to load file " << infilename << endl;
207 201
       return (false);
208 202
     }
209 203
 
@@ -238,8 +232,6 @@ namespace ABACUS {
238 232
   {
239 233
     if (xmax < xmin) return(-Integrate_Riemann (function, args, arg_to_integ, xmax, xmin, Npts));
240 234
 
241
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
242
-
243 235
     DP dx = (xmax - xmin)/Npts;
244 236
 
245 237
     DP result = 0.0;
@@ -258,8 +250,6 @@ namespace ABACUS {
258 250
   {
259 251
     if (xmax < xmin) return(-Integrate_Riemann_using_table (function, args, arg_to_integ, Itable, xmax, xmin, Npts));
260 252
 
261
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
262
-
263 253
     DP dx = (xmax - xmin)/Npts;
264 254
 
265 255
     DP result = 0.0;
@@ -279,15 +269,9 @@ namespace ABACUS {
279 269
 
280 270
   DP Integrate_rec_main (DP (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin, DP xmax, DP req_prec, int rec_level, int max_rec_level, DP* f)
281 271
   {
282
-    //cout << "Recursion level " << rec_level << endl;
283
-
284
-    //cout << "Calling Integrate_rec on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
285
-
286 272
     if (rec_level > max_rec_level) {
287
-      //cout << "Warning:  integral didn't converge between " << setprecision(10) << xmin << " and " << xmax << endl;
288 273
       return((xmax - xmin) * (f[0] + f[1] + f[2])/3.0);
289 274
     }
290
-    //if (rec_level > 16) ABACUSerror("Recursion level too high in Integrate_rec.");
291 275
 
292 276
     DP* f1 = new DP[9];
293 277
 
@@ -313,31 +297,33 @@ namespace ABACUS {
313 297
     DP I1 = dx * (f1[0] + f1[1] + f1[2]);
314 298
 
315 299
     if (fabs(I1 - I1_pre) > req_prec || rec_level < 5)
316
-      I1 = Integrate_rec_main (function, args, arg_to_integ, xmin, xmin + 3.0 * dx, req_prec, rec_level + 1, max_rec_level, f1);
300
+      I1 = Integrate_rec_main (function, args, arg_to_integ, xmin, xmin + 3.0 * dx,
301
+			       req_prec, rec_level + 1, max_rec_level, f1);
317 302
 
318 303
     DP I2_pre = 3.0 * dx * f[1];
319 304
     DP I2 = dx * (f1[3] + f1[4] + f1[5]);
320 305
 
321 306
     if (fabs(I2 - I2_pre) > req_prec || rec_level < 5)
322
-      I2 = Integrate_rec_main (function, args, arg_to_integ, xmin + 3.0 * dx, xmin + 6.0 * dx, req_prec, rec_level + 1, max_rec_level, &f1[3]);
307
+      I2 = Integrate_rec_main (function, args, arg_to_integ, xmin + 3.0 * dx, xmin + 6.0 * dx,
308
+			       req_prec, rec_level + 1, max_rec_level, &f1[3]);
323 309
 
324 310
     DP I3_pre = 3.0 * dx * f[2];
325 311
     DP I3 = dx * (f1[6] + f1[7] + f1[8]);
326 312
 
327 313
     if (fabs(I3 - I3_pre) > req_prec || rec_level < 5)
328
-      I3 = Integrate_rec_main (function, args, arg_to_integ, xmin + 6.0 * dx, xmax, req_prec, rec_level + 1, max_rec_level, &f1[6]);
314
+      I3 = Integrate_rec_main (function, args, arg_to_integ, xmin + 6.0 * dx, xmax,
315
+			       req_prec, rec_level + 1, max_rec_level, &f1[6]);
329 316
 
330 317
     delete[] f1;
331 318
 
332 319
     return(I1 + I2 + I3);
333 320
   }
334 321
 
335
-  DP Integrate_rec (DP (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin, DP xmax, DP req_prec, int max_rec_level)
322
+  DP Integrate_rec (DP (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin, DP xmax,
323
+		    DP req_prec, int max_rec_level)
336 324
   {
337 325
     if (xmax < xmin) return(-Integrate_rec(function, args, arg_to_integ, xmax, xmin, req_prec, max_rec_level));
338 326
 
339
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
340
-
341 327
     DP* f = new DP[3];
342 328
     DP dx = (xmax - xmin)/3.0;
343 329
 
@@ -351,8 +337,6 @@ namespace ABACUS {
351 337
 
352 338
     DP req_prec_rec = sum_fabs_f > 1.0 ? sum_fabs_f * req_prec : req_prec;
353 339
 
354
-    //cout << "In Integrate:  sum_fabs_f = " << sum_fabs_f << endl;
355
-
356 340
     DP answer = Integrate_rec_main (function, args, arg_to_integ, xmin, xmax, req_prec_rec, 0, max_rec_level, f);
357 341
 
358 342
     delete[] f;
@@ -363,15 +347,9 @@ namespace ABACUS {
363 347
   DP Integrate_rec_main_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable,
364 348
 				     DP xmin, DP xmax, DP req_prec, int rec_level, int max_rec_level, DP* f)
365 349
   {
366
-    //cout << "Recursion level " << rec_level << endl;
367
-
368
-    //cout << "Calling Integrate_rec on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
369
-
370 350
     if (rec_level > max_rec_level) {
371
-      //cout << "Warning:  integral didn't converge between " << setprecision(10) << xmin << " and " << xmax << endl;
372 351
       return((xmax - xmin) * (f[0] + f[1] + f[2])/3.0);
373 352
     }
374
-    //if (rec_level > 16) ABACUSerror("Recursion level too high in Integrate_rec.");
375 353
 
376 354
     DP* f1 = new DP[9];
377 355
 
@@ -397,19 +375,22 @@ namespace ABACUS {
397 375
     DP I1 = dx * (f1[0] + f1[1] + f1[2]);
398 376
 
399 377
     if (fabs(I1 - I1_pre) > req_prec || rec_level < 5)
400
-      I1 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmin + 3.0 * dx, req_prec, rec_level + 1, max_rec_level, f1);
378
+      I1 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmin + 3.0 * dx,
379
+					   req_prec, rec_level + 1, max_rec_level, f1);
401 380
 
402 381
     DP I2_pre = 3.0 * dx * f[1];
403 382
     DP I2 = dx * (f1[3] + f1[4] + f1[5]);
404 383
 
405 384
     if (fabs(I2 - I2_pre) > req_prec || rec_level < 5)
406
-      I2 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 3.0 * dx, xmin + 6.0 * dx, req_prec, rec_level + 1, max_rec_level, &f1[3]);
385
+      I2 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 3.0 * dx, xmin + 6.0 * dx,
386
+					   req_prec, rec_level + 1, max_rec_level, &f1[3]);
407 387
 
408 388
     DP I3_pre = 3.0 * dx * f[2];
409 389
     DP I3 = dx * (f1[6] + f1[7] + f1[8]);
410 390
 
411 391
     if (fabs(I3 - I3_pre) > req_prec || rec_level < 5)
412
-      I3 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 6.0 * dx, xmax, req_prec, rec_level + 1, max_rec_level, &f1[6]);
392
+      I3 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 6.0 * dx, xmax,
393
+					   req_prec, rec_level + 1, max_rec_level, &f1[6]);
413 394
 
414 395
     delete[] f1;
415 396
 
@@ -419,9 +400,8 @@ namespace ABACUS {
419 400
   DP Integrate_rec_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable,
420 401
 				DP xmin, DP xmax, DP req_prec, int max_rec_level)
421 402
   {
422
-    if (xmax < xmin) return(-Integrate_rec_using_table (function, args, arg_to_integ, Itable, xmax, xmin, req_prec, max_rec_level));
423
-
424
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
403
+    if (xmax < xmin) return(-Integrate_rec_using_table (function, args, arg_to_integ, Itable, xmax, xmin,
404
+							req_prec, max_rec_level));
425 405
 
426 406
     DP* f = new DP[3];
427 407
     DP dx = (xmax - xmin)/3.0;
@@ -436,9 +416,8 @@ namespace ABACUS {
436 416
 
437 417
     DP req_prec_rec = sum_fabs_f > 1.0 ? sum_fabs_f * req_prec : req_prec;
438 418
 
439
-    //cout << "In Integrate:  sum_fabs_f = " << sum_fabs_f << endl;
440
-
441
-    DP answer = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmax, req_prec_rec, 0, max_rec_level, f);
419
+    DP answer = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmax,
420
+						req_prec_rec, 0, max_rec_level, f);
442 421
 
443 422
     delete[] f;
444 423
 
@@ -448,15 +427,9 @@ namespace ABACUS {
448 427
   DP Integrate_rec_main_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable,
449 428
 				     DP xmin, DP xmax, DP req_prec, int rec_level, int max_rec_level, DP* f, ofstream& outfile)
450 429
   {
451
-    //cout << "Recursion level " << rec_level << endl;
452
-
453
-    //cout << "Calling Integrate_rec on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
454
-
455 430
     if (rec_level > max_rec_level) {
456
-      //cout << "Warning:  integral didn't converge between " << setprecision(10) << xmin << " and " << xmax << endl;
457 431
       return((xmax - xmin) * (f[0] + f[1] + f[2])/3.0);
458 432
     }
459
-    //if (rec_level > 16) ABACUSerror("Recursion level too high in Integrate_rec.");
460 433
 
461 434
     DP* f1 = new DP[9];
462 435
 
@@ -464,49 +437,46 @@ namespace ABACUS {
464 437
 
465 438
     args[arg_to_integ] = xmin + 0.5 * dx;
466 439
     f1[0] = function (args, Itable);
467
-    //outfile << args[arg_to_integ] << "\t" << f1[0] << endl;
468 440
     outfile << args << "\t" << f1[0] << endl;
469 441
     f1[1] = f[0];
470 442
     args[arg_to_integ] = xmin + 2.5 * dx;
471 443
     f1[2] = function (args, Itable);
472
-    //outfile << args[arg_to_integ] << "\t" << f1[2] << endl;
473 444
     outfile << args << "\t" << f1[2] << endl;
474 445
     args[arg_to_integ] = xmin + 3.5 * dx;
475 446
     f1[3] = function (args, Itable);
476
-    //outfile << args[arg_to_integ] << "\t" << f1[3] << endl;
477 447
     outfile << args << "\t" << f1[3] << endl;
478 448
     f1[4] = f[1];
479 449
     args[arg_to_integ] = xmin + 5.5 * dx;
480 450
     f1[5] = function (args, Itable);
481
-    //outfile << args[arg_to_integ] << "\t" << f1[5] << endl;
482 451
     outfile << args << "\t" << f1[5] << endl;
483 452
     args[arg_to_integ] = xmin + 6.5 * dx;
484 453
     f1[6] = function (args, Itable);
485
-    //outfile << args[arg_to_integ] << "\t" << f1[6] << endl;
486 454
     outfile << args << "\t" << f1[6] << endl;
487 455
     f1[7] = f[2];
488 456
     args[arg_to_integ] = xmin + 8.5 * dx;
489 457
     f1[8] = function (args, Itable);
490
-    //outfile << args[arg_to_integ] << "\t" << f1[8] << endl;
491 458
     outfile << args << "\t" << f1[8] << endl;
492 459
 
493 460
     DP I1_pre = 3.0 * dx * f[0];
494 461
     DP I1 = dx * (f1[0] + f1[1] + f1[2]);
495 462
 
496 463
     if (fabs(I1 - I1_pre) > req_prec || rec_level < 5)
497
-      I1 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmin + 3.0 * dx, req_prec, rec_level + 1, max_rec_level, f1, outfile);
464
+      I1 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmin + 3.0 * dx,
465
+					   req_prec, rec_level + 1, max_rec_level, f1, outfile);
498 466
 
499 467
     DP I2_pre = 3.0 * dx * f[1];
500 468
     DP I2 = dx * (f1[3] + f1[4] + f1[5]);
501 469
 
502 470
     if (fabs(I2 - I2_pre) > req_prec || rec_level < 5)
503
-      I2 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 3.0 * dx, xmin + 6.0 * dx, req_prec, rec_level + 1, max_rec_level, &f1[3], outfile);
471
+      I2 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 3.0 * dx, xmin + 6.0 * dx,
472
+					   req_prec, rec_level + 1, max_rec_level, &f1[3], outfile);
504 473
 
505 474
     DP I3_pre = 3.0 * dx * f[2];
506 475
     DP I3 = dx * (f1[6] + f1[7] + f1[8]);
507 476
 
508 477
     if (fabs(I3 - I3_pre) > req_prec || rec_level < 5)
509
-      I3 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 6.0 * dx, xmax, req_prec, rec_level + 1, max_rec_level, &f1[6], outfile);
478
+      I3 = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin + 6.0 * dx, xmax,
479
+					   req_prec, rec_level + 1, max_rec_level, &f1[6], outfile);
510 480
 
511 481
     delete[] f1;
512 482
 
@@ -516,9 +486,8 @@ namespace ABACUS {
516 486
   DP Integrate_rec_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable,
517 487
 				DP xmin, DP xmax, DP req_prec, int max_rec_level, ofstream& outfile)
518 488
   {
519
-    if (xmax < xmin) return(-Integrate_rec_using_table (function, args, arg_to_integ, Itable, xmax, xmin, req_prec, max_rec_level, outfile));
520
-
521
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
489
+    if (xmax < xmin) return(-Integrate_rec_using_table (function, args, arg_to_integ, Itable, xmax, xmin,
490
+							req_prec, max_rec_level, outfile));
522 491
 
523 492
     DP* f = new DP[3];
524 493
     DP dx = (xmax - xmin)/3.0;
@@ -528,34 +497,28 @@ namespace ABACUS {
528 497
     for (int i = 0; i < 3; ++i) {
529 498
       args[arg_to_integ] = xmin + (i + 0.5) * dx;
530 499
       f[i] = function (args, Itable);
531
-      //outfile << args[arg_to_integ] << "\t" << f[i] << endl;
532 500
       outfile << args << "\t" << f[i] << endl;
533 501
       sum_fabs_f += fabs(f[i]);
534 502
     }
535 503
 
536 504
     DP req_prec_rec = sum_fabs_f > 1.0 ? sum_fabs_f * req_prec : req_prec;
537 505
 
538
-    //cout << "In Integrate:  sum_fabs_f = " << sum_fabs_f << endl;
539
-
540
-    DP answer = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmax, req_prec_rec, 0, max_rec_level, f, outfile);
506
+    DP answer = Integrate_rec_main_using_table (function, args, arg_to_integ, Itable, xmin, xmax,
507
+						req_prec_rec, 0, max_rec_level, f, outfile);
541 508
 
542 509
     delete[] f;
543 510
 
544 511
     return(answer);
545 512
   }
546 513
 
547
-  DP Integrate_rec_main_using_table_and_file (DP (*function) (Vect_DP, I_table, ofstream&), Vect_DP& args, int arg_to_integ, I_table Itable,
548
-					      DP xmin, DP xmax, DP req_prec, int rec_level, int max_rec_level, DP* f, ofstream& outfile)
514
+  DP Integrate_rec_main_using_table_and_file (DP (*function) (Vect_DP, I_table, ofstream&),
515
+					      Vect_DP& args, int arg_to_integ, I_table Itable,
516
+					      DP xmin, DP xmax, DP req_prec, int rec_level, int max_rec_level,
517
+					      DP* f, ofstream& outfile)
549 518
   {
550
-    //cout << "Recursion level " << rec_level << endl;
551
-
552
-    //cout << "Calling Integrate_rec on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
553
-
554 519
     if (rec_level > max_rec_level) {
555
-      //cout << "Warning:  integral didn't converge between " << setprecision(10) << xmin << " and " << xmax << endl;
556 520
       return((xmax - xmin) * (f[0] + f[1] + f[2])/3.0);
557 521
     }
558
-    //if (rec_level > 16) ABACUSerror("Recursion level too high in Integrate_rec.");
559 522
 
560 523
     DP* f1 = new DP[9];
561 524
 
@@ -563,61 +526,58 @@ namespace ABACUS {
563 526
 
564 527
     args[arg_to_integ] = xmin + 0.5 * dx;
565 528
     f1[0] = function (args, Itable, outfile);
566
-    //outfile << args[arg_to_integ] << "\t" << f1[0] << endl;
567 529
     outfile << args << "\t" << f1[0] << endl;
568 530
     f1[1] = f[0];
569 531
     args[arg_to_integ] = xmin + 2.5 * dx;
570 532
     f1[2] = function (args, Itable, outfile);
571
-    //outfile << args[arg_to_integ] << "\t" << f1[2] << endl;
572 533
     outfile << args << "\t" << f1[2] << endl;
573 534
     args[arg_to_integ] = xmin + 3.5 * dx;
574 535
     f1[3] = function (args, Itable, outfile);
575
-    //outfile << args[arg_to_integ] << "\t" << f1[3] << endl;
576 536
     outfile << args << "\t" << f1[3] << endl;
577 537
     f1[4] = f[1];
578 538
     args[arg_to_integ] = xmin + 5.5 * dx;
579 539
     f1[5] = function (args, Itable, outfile);
580
-    //outfile << args[arg_to_integ] << "\t" << f1[5] << endl;
581 540
     outfile << args << "\t" << f1[5] << endl;
582 541
     args[arg_to_integ] = xmin + 6.5 * dx;
583 542
     f1[6] = function (args, Itable, outfile);
584
-    //outfile << args[arg_to_integ] << "\t" << f1[6] << endl;
585 543
     outfile << args << "\t" << f1[6] << endl;
586 544
     f1[7] = f[2];
587 545
     args[arg_to_integ] = xmin + 8.5 * dx;
588 546
     f1[8] = function (args, Itable, outfile);
589
-    //outfile << args[arg_to_integ] << "\t" << f1[8] << endl;
590 547
     outfile << args << "\t" << f1[8] << endl;
591 548
 
592 549
     DP I1_pre = 3.0 * dx * f[0];
593 550
     DP I1 = dx * (f1[0] + f1[1] + f1[2]);
594 551
 
595 552
     if (fabs(I1 - I1_pre) > req_prec || rec_level < 5)
596
-      I1 = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin, xmin + 3.0 * dx, req_prec, rec_level + 1, max_rec_level, f1, outfile);
553
+      I1 = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin, xmin + 3.0 * dx,
554
+						    req_prec, rec_level + 1, max_rec_level, f1, outfile);
597 555
 
598 556
     DP I2_pre = 3.0 * dx * f[1];
599 557
     DP I2 = dx * (f1[3] + f1[4] + f1[5]);
600 558
 
601 559
     if (fabs(I2 - I2_pre) > req_prec || rec_level < 5)
602
-      I2 = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin + 3.0 * dx, xmin + 6.0 * dx, req_prec, rec_level + 1, max_rec_level, &f1[3], outfile);
560
+      I2 = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin + 3.0 * dx, xmin + 6.0 * dx,
561
+						    req_prec, rec_level + 1, max_rec_level, &f1[3], outfile);
603 562
 
604 563
     DP I3_pre = 3.0 * dx * f[2];
605 564
     DP I3 = dx * (f1[6] + f1[7] + f1[8]);
606 565
 
607 566
     if (fabs(I3 - I3_pre) > req_prec || rec_level < 5)
608
-      I3 = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin + 6.0 * dx, xmax, req_prec, rec_level + 1, max_rec_level, &f1[6], outfile);
567
+      I3 = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin + 6.0 * dx, xmax,
568
+						    req_prec, rec_level + 1, max_rec_level, &f1[6], outfile);
609 569
 
610 570
     delete[] f1;
611 571
 
612 572
     return(I1 + I2 + I3);
613 573
   }
614 574
 
615
-  DP Integrate_rec_using_table_and_file (DP (*function) (Vect_DP, I_table, ofstream&), Vect_DP& args, int arg_to_integ, I_table Itable,
616
-					 DP xmin, DP xmax, DP req_prec, int max_rec_level, ofstream& outfile)
575
+  DP Integrate_rec_using_table_and_file (DP (*function) (Vect_DP, I_table, ofstream&), Vect_DP& args, int arg_to_integ,
576
+					 I_table Itable, DP xmin, DP xmax, DP req_prec, int max_rec_level, ofstream& outfile)
617 577
   {
618
-    if (xmax < xmin) return(-Integrate_rec_using_table_and_file (function, args, arg_to_integ, Itable, xmax, xmin, req_prec, max_rec_level, outfile));
619
-
620
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
578
+    if (xmax < xmin)
579
+      return(-Integrate_rec_using_table_and_file (function, args, arg_to_integ, Itable, xmax, xmin,
580
+						  req_prec, max_rec_level, outfile));
621 581
 
622 582
     DP* f = new DP[3];
623 583
     DP dx = (xmax - xmin)/3.0;
@@ -627,16 +587,14 @@ namespace ABACUS {
627 587
     for (int i = 0; i < 3; ++i) {
628 588
       args[arg_to_integ] = xmin + (i + 0.5) * dx;
629 589
       f[i] = function (args, Itable, outfile);
630
-      //outfile << args[arg_to_integ] << "\t" << f[i] << endl;
631 590
       outfile << args << "\t" << f[i] << endl;
632 591
       sum_fabs_f += fabs(f[i]);
633 592
     }
634 593
 
635 594
     DP req_prec_rec = sum_fabs_f > 1.0 ? sum_fabs_f * req_prec : req_prec;
636 595
 
637
-    //cout << "In Integrate:  sum_fabs_f = " << sum_fabs_f << endl;
638
-
639
-    DP answer = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin, xmax, req_prec_rec, 0, max_rec_level, f, outfile);
596
+    DP answer = Integrate_rec_main_using_table_and_file (function, args, arg_to_integ, Itable, xmin, xmax,
597
+							 req_prec_rec, 0, max_rec_level, f, outfile);
640 598
 
641 599
     delete[] f;
642 600
 
@@ -645,20 +603,14 @@ namespace ABACUS {
645 603
 
646 604
   // THESE TWO FUNCTIONS HAVE NOT BEEN TESTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
647 605
 
648
-  DP Integrate_exp_rec_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable,
649
-				    DP xmin, DP xmax, DP eta_old, DP req_prec, int rec_level, int max_rec_level, DP* f, ofstream& outfile)
606
+  DP Integrate_exp_rec_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
607
+				    I_table Itable, DP xmin, DP xmax, DP eta_old, DP req_prec, int rec_level,
608
+				    int max_rec_level, DP* f, ofstream& outfile)
650 609
   {
651
-    //cout << "Recursion level " << rec_level << endl;
652
-
653
-    //cout << "Calling Integrate_rec on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
654
-
655 610
     DP dx_over_x_old = 0.5 * (eta_old - 1.0/eta_old);
656 611
     if (rec_level > max_rec_level) {
657
-      //cout << "Warning:  integral didn't converge between " << setprecision(10) << xmin << " and " << xmax << endl;
658
-      //return((xmax - xmin) * (f[0] + f[1] + f[2])/3.0);
659 612
       return(dx_over_x_old * xmin * eta_old * (f[0] + eta_old * (f[1] + eta_old * f[2])));
660 613
     }
661
-    //if (rec_level > 16) ABACUSerror("Recursion level too high in Integrate_rec.");
662 614
 
663 615
     DP* f1 = new DP[9];
664 616
     DP* x_pts = new DP[9];
@@ -695,19 +647,22 @@ namespace ABACUS {
695 647
     DP I1 = dx_over_x * (x_pts[0] * f1[0] + x_pts[1] * f1[1] + x_pts[2] * f1[2]);
696 648
 
697 649
     if (fabs(I1 - I1_pre) > req_prec || rec_level < 5)
698
-      I1 = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, xmin, x_pts[2] * eta, eta, req_prec, rec_level + 1, max_rec_level, f1, outfile);
650
+      I1 = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, xmin, x_pts[2] * eta, eta,
651
+					  req_prec, rec_level + 1, max_rec_level, f1, outfile);
699 652
 
700 653
     DP I2_pre = dx_over_x_old * x_pts[4] * f1[4];
701 654
     DP I2 = dx_over_x * (x_pts[3] * f1[3] + x_pts[4] * f1[4] + x_pts[5] * f1[5]);
702 655
 
703 656
     if (fabs(I2 - I2_pre) > req_prec || rec_level < 5)
704
-      I2 = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, x_pts[2] * eta, x_pts[5] * eta, eta, req_prec, rec_level + 1, max_rec_level, &f1[3], outfile);
657
+      I2 = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, x_pts[2] * eta, x_pts[5] * eta, eta,
658
+					  req_prec, rec_level + 1, max_rec_level, &f1[3], outfile);
705 659
 
706 660
     DP I3_pre = dx_over_x_old * f1[7];
707 661
     DP I3 = dx_over_x * (x_pts[6] * f1[6] + x_pts[7] * f1[7] + x_pts[8] * f1[8]);
708 662
 
709 663
     if (fabs(I3 - I3_pre) > req_prec || rec_level < 5)
710
-      I3 = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, x_pts[5] * eta, xmax, eta, req_prec, rec_level + 1, max_rec_level, &f1[6], outfile);
664
+      I3 = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, x_pts[5] * eta, xmax, eta,
665
+					  req_prec, rec_level + 1, max_rec_level, &f1[6], outfile);
711 666
 
712 667
     delete[] f1;
713 668
 
@@ -715,20 +670,18 @@ namespace ABACUS {
715 670
   }
716 671
 
717 672
   DP Integrate_exp_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable,
718
-			    DP xmin, DP xmax, DP req_prec, int max_rec_level, ofstream& outfile)
673
+				DP xmin, DP xmax, DP req_prec, int max_rec_level, ofstream& outfile)
719 674
   {
720 675
     // This uses an exponential progression of sampling points.
721 676
 
722 677
     if (xmin <= 0.0) ABACUSerror("Use xmin > 0.0 in Integrate_exp.");
723 678
     if (xmax <= 0.0) ABACUSerror("Use xmax > 0.0 in Integrate_exp.");
724 679
 
725
-    if (xmax < xmin) return(-Integrate_exp_using_table (function, args, arg_to_integ, Itable, xmax, xmin, req_prec, max_rec_level, outfile));
726
-
727
-    //cout << "Calling Integrate on argument " << arg_to_integ << " between " << xmin << " and " << xmax << " to prec " << req_prec << endl;
680
+    if (xmax < xmin) return(-Integrate_exp_using_table (function, args, arg_to_integ, Itable, xmax, xmin,
681
+							req_prec, max_rec_level, outfile));
728 682
 
729 683
     DP* f = new DP[3];
730 684
     DP eta = pow(xmax/xmin, 1.0/6.0);
731
-    //DP dx_over_x = 0.5 * (eta - 1.0/eta);
732 685
 
733 686
     DP sum_fabs_f = 0.0;
734 687
 
@@ -747,9 +700,8 @@ namespace ABACUS {
747 700
 
748 701
     DP req_prec_rec = sum_fabs_f > 1.0 ? sum_fabs_f * req_prec : req_prec;
749 702
 
750
-    //cout << "In Integrate:  sum_fabs_f = " << sum_fabs_f << endl;
751
-
752
-    DP answer = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, xmin, xmax, eta, req_prec_rec, 0, max_rec_level, f, outfile);
703
+    DP answer = Integrate_exp_rec_using_table (function, args, arg_to_integ, Itable, xmin, xmax, eta,
704
+					       req_prec_rec, 0, max_rec_level, f, outfile);
753 705
 
754 706
     delete[] f;
755 707
 
@@ -761,11 +713,11 @@ namespace ABACUS {
761 713
   // *********************************** Adaptive Riemann sum (better implementation) *******************************************
762 714
 
763 715
   std::ostream& operator<< (std::ostream& s, const Integral_result& res)
764
-    {
765
-      s << res.integ_est << "\t" << res.abs_prec << "\t" << res.rel_prec << "\t" << res.n_vals;
716
+  {
717
+    s << res.integ_est << "\t" << res.abs_prec << "\t" << res.rel_prec << "\t" << res.n_vals;
766 718
 
767
-      return(s);
768
-    }
719
+    return(s);
720
+  }
769 721
 
770 722
   Integral_data::~Integral_data()
771 723
   {
@@ -803,12 +755,10 @@ namespace ABACUS {
803 755
     }
804 756
 
805 757
     integ_res.rel_prec = integ_res.abs_prec/integ_res.integ_est;
806
-
807
-    //for (int in = 0; in < n_vals; ++in)
808
-    //cout << in << "\t" << data[in].x << "\t" << data[in].f << "\t" << data[in].dx << endl;
809 758
   }
810 759
 
811
-  Integral_data::Integral_data (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable, DP xmin_ref, DP xmax_ref)
760
+  Integral_data::Integral_data (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
761
+				I_table Itable, DP xmin_ref, DP xmax_ref)
812 762
   {
813 763
     xmin = xmin_ref;
814 764
     xmax = xmax_ref;
@@ -838,12 +788,10 @@ namespace ABACUS {
838 788
     }
839 789
 
840 790
     integ_res.rel_prec = integ_res.abs_prec/integ_res.integ_est;
841
-
842
-    //for (int in = 0; in < n_vals; ++in)
843
-    //cout << in << "\t" << data[in].x << "\t" << data[in].f << "\t" << data[in].dx << endl;
844 791
   }
845 792
 
846
-  Integral_data::Integral_data (DP (*function) (Vect_DP, Integral_table), Vect_DP& args, int arg_to_integ, Integral_table Itable, DP xmin_ref, DP xmax_ref)
793
+  Integral_data::Integral_data (DP (*function) (Vect_DP, Integral_table), Vect_DP& args, int arg_to_integ,
794
+				Integral_table Itable, DP xmin_ref, DP xmax_ref)
847 795
   {
848 796
     xmin = xmin_ref;
849 797
     xmax = xmax_ref;
@@ -873,9 +821,6 @@ namespace ABACUS {
873 821
     }
874 822
 
875 823
     integ_res.rel_prec = integ_res.abs_prec/integ_res.integ_est;
876
-
877
-    //for (int in = 0; in < n_vals; ++in)
878
-    //cout << in << "\t" << data[in].x << "\t" << data[in].f << "\t" << data[in].dx << endl;
879 824
   }
880 825
 
881 826
   void Integral_data::Save (ofstream& outfile)
@@ -960,9 +905,12 @@ namespace ABACUS {
960 905
 	args[arg_to_integ] = new_data[index_new + 8].x;
961 906
 	new_data[index_new + 8].f = function(args);
962 907
 
963
-	new_abs_d2f_dx[index_new/3] = fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
964
-	new_abs_d2f_dx[index_new/3 + 1] = fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
965
-	new_abs_d2f_dx[index_new/3 + 2] = fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
908
+	new_abs_d2f_dx[index_new/3] =
909
+	  fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
910
+	new_abs_d2f_dx[index_new/3 + 1] =
911
+	  fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
912
+	new_abs_d2f_dx[index_new/3 + 2] =
913
+	  fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
966 914
 
967 915
 	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3]);
968 916
 	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3 + 1]);
@@ -995,7 +943,8 @@ namespace ABACUS {
995 943
     return;
996 944
   }
997 945
 
998
-  void Integral_data::Improve_estimate (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable, int max_nr_pts)
946
+  void Integral_data::Improve_estimate (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
947
+					I_table Itable, int max_nr_pts)
999 948
   {
1000 949
     // We generate a max of 3* n_vals points
1001 950
     data_pt* new_data = new data_pt[3* integ_res.n_vals];
@@ -1066,9 +1015,12 @@ namespace ABACUS {
1066 1015
 	args[arg_to_integ] = new_data[index_new + 8].x;
1067 1016
 	new_data[index_new + 8].f = function(args, Itable);
1068 1017
 
1069
-	new_abs_d2f_dx[index_new/3] = fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
1070
-	new_abs_d2f_dx[index_new/3 + 1] = fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
1071
-	new_abs_d2f_dx[index_new/3 + 2] = fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
1018
+	new_abs_d2f_dx[index_new/3] =
1019
+	  fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
1020
+	new_abs_d2f_dx[index_new/3 + 1] =
1021
+	  fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
1022
+	new_abs_d2f_dx[index_new/3 + 2] =
1023
+	  fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
1072 1024
 
1073 1025
 	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3]);
1074 1026
 	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3 + 1]);
@@ -1101,7 +1053,8 @@ namespace ABACUS {
1101 1053
     return;
1102 1054
   }
1103 1055
 
1104
-  void Integral_data::Improve_estimate (DP (*function) (Vect_DP, Integral_table), Vect_DP& args, int arg_to_integ, Integral_table Itable, int max_nr_pts)
1056
+  void Integral_data::Improve_estimate (DP (*function) (Vect_DP, Integral_table), Vect_DP& args, int arg_to_integ,
1057
+					Integral_table Itable, int max_nr_pts)
1105 1058
   {
1106 1059
     // We generate a max of 3* n_vals points
1107 1060
     data_pt* new_data = new data_pt[3* integ_res.n_vals];
@@ -1172,9 +1125,12 @@ namespace ABACUS {
1172 1125
 	args[arg_to_integ] = new_data[index_new + 8].x;
1173 1126
 	new_data[index_new + 8].f = function(args, Itable);
1174 1127
 
1175
-	new_abs_d2f_dx[index_new/3] = fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
1176
-	new_abs_d2f_dx[index_new/3 + 1] = fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
1177
-	new_abs_d2f_dx[index_new/3 + 2] = fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
1128
+	new_abs_d2f_dx[index_new/3] =
1129
+	  fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
1130
+	new_abs_d2f_dx[index_new/3 + 1] =
1131
+	  fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
1132
+	new_abs_d2f_dx[index_new/3 + 2] =
1133
+	  fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
1178 1134
 
1179 1135
 	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3]);
1180 1136
 	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3 + 1]);
@@ -1207,35 +1163,31 @@ namespace ABACUS {
1207 1163
     return;
1208 1164
   }
1209 1165
 
1210
-  Integral_result Integrate_optimal (DP (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1166
+  Integral_result Integrate_optimal (DP (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin, DP xmax,
1167
+				     DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1211 1168
   {
1212 1169
     if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
1213 1170
 
1214 1171
     Integral_data integ_dat (function, args, arg_to_integ, xmin, xmax);
1215 1172
 
1216
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
1217
-
1173
+    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec)
1174
+	   && integ_dat.integ_res.n_vals < max_nr_pts) {
1218 1175
       integ_dat.Improve_estimate (function, args, arg_to_integ, max_nr_pts);
1219 1176
     }
1220 1177
 
1221
-    // REMOVE next four line
1222
-    //ofstream outfile;
1223
-    //outfile.open("testoptimal.dat");
1224
-    //outfile.precision(16);
1225
-    //integ_dat.Save(outfile);
1226
-
1227 1178
     return(integ_dat.integ_res);
1228 1179
   }
1229 1180
 
1230 1181
   Integral_result Integrate_optimal_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
1231
-						 I_table Itable, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1182
+						 I_table Itable, DP xmin, DP xmax,
1183
+						 DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1232 1184
   {
1233 1185
     if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
1234 1186
 
1235 1187
     Integral_data integ_dat (function, args, arg_to_integ, Itable, xmin, xmax);
1236 1188
 
1237
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
1238
-
1189
+    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec)
1190
+	   && integ_dat.integ_res.n_vals < max_nr_pts) {
1239 1191
       integ_dat.Improve_estimate (function, args, arg_to_integ, Itable, max_nr_pts);
1240 1192
     }
1241 1193
 
@@ -1243,13 +1195,15 @@ namespace ABACUS {
1243 1195
   }
1244 1196
 
1245 1197
   Integral_result Integrate_optimal_using_table (DP (*function) (Vect_DP, Integral_table), Vect_DP& args, int arg_to_integ,
1246
-						 Integral_table Itable, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1198
+						 Integral_table Itable, DP xmin, DP xmax,
1199
+						 DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1247 1200
   {
1248 1201
     if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
1249 1202
 
1250 1203
     Integral_data integ_dat (function, args, arg_to_integ, Itable, xmin, xmax);
1251 1204
 
1252
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
1205
+    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec)
1206
+	   && integ_dat.integ_res.n_vals < max_nr_pts) {
1253 1207
 
1254 1208
       integ_dat.Improve_estimate (function, args, arg_to_integ, Itable, max_nr_pts);
1255 1209
     }
@@ -1258,13 +1212,15 @@ namespace ABACUS {
1258 1212
   }
1259 1213
 
1260 1214
   Integral_result Integrate_optimal_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
1261
-						 I_table Itable, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts, ofstream& outfile)
1215
+						 I_table Itable, DP xmin, DP xmax,
1216
+						 DP req_rel_prec, DP req_abs_prec, int max_nr_pts, ofstream& outfile)
1262 1217
   {
1263 1218
     if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
1264 1219
 
1265 1220
     Integral_data integ_dat (function, args, arg_to_integ, Itable, xmin, xmax);
1266 1221
 
1267
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
1222
+    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec)
1223
+	   && integ_dat.integ_res.n_vals < max_nr_pts) {
1268 1224
 
1269 1225
       integ_dat.Improve_estimate (function, args, arg_to_integ, Itable, max_nr_pts);
1270 1226
 
@@ -1280,11 +1236,12 @@ namespace ABACUS {
1280 1236
   // *********************************** Adaptive Riemann sum (better implementation) *******************************************
1281 1237
 
1282 1238
   std::ostream& operator<< (std::ostream& s, const Integral_result_CX& res)
1283
-    {
1284
-      s << real(res.integ_est) << "\t" << imag(res.integ_est) << "\t" << res.abs_prec << "\t" << res.rel_prec << "\t" << res.n_vals;
1239
+  {
1240
+    s << real(res.integ_est) << "\t" << imag(res.integ_est) << "\t"
1241
+      << res.abs_prec << "\t" << res.rel_prec << "\t" << res.n_vals;
1285 1242
 
1286
-      return(s);
1287
-    }
1243
+    return(s);
1244
+  }
1288 1245
 
1289 1246
   Integral_data_CX::~Integral_data_CX()
1290 1247
   {
@@ -1292,7 +1249,8 @@ namespace ABACUS {
1292 1249
     if (abs_d2f_dx != 0) delete[] abs_d2f_dx;
1293 1250
   }
1294 1251
 
1295
-  Integral_data_CX::Integral_data_CX (complex<DP> (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin_ref, DP xmax_ref)
1252
+  Integral_data_CX::Integral_data_CX (complex<DP> (*function) (Vect_DP), Vect_DP& args, int arg_to_integ,
1253
+				      DP xmin_ref, DP xmax_ref)
1296 1254
   {
1297 1255
     xmin = xmin_ref;
1298 1256
     xmax = xmax_ref;
@@ -1322,48 +1280,9 @@ namespace ABACUS {
1322 1280
     }
1323 1281
 
1324 1282
     integ_res.rel_prec = integ_res.abs_prec/abs(integ_res.integ_est);
1325
-
1326
-    //for (int in = 0; in < n_vals; ++in)
1327
-    //cout << in << "\t" << data[in].x << "\t" << data[in].f << "\t" << data[in].dx << endl;
1328 1283
   }
1329 1284
 
1330 1285
   // No implementation with I_table yet for complex...
1331
-  /*
1332
-  Integral_data::Integral_data (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable, DP xmin_ref, DP xmax_ref)
1333
-  {
1334
-    xmin = xmin_ref;
1335
-    xmax = xmax_ref;
1336
-    integ_res.n_vals = 9;
1337
-
1338
-    data = new data_pt[integ_res.n_vals];
1339
-    abs_d2f_dx = new DP[integ_res.n_vals/3];
1340
-
1341
-    integ_res.integ_est = 0.0;
1342
-
1343
-    // Initialize x, f and dx:
1344
-    DP dx = (xmax - xmin)/9.0;
1345
-    for (int i = 0; i < 9; ++i) {
1346
-      data[i].x = xmin + (i + 0.5) * dx;
1347
-      args[arg_to_integ] = data[i].x;
1348
-      data[i].f = function (args, Itable);
1349
-      data[i].dx = dx;
1350
-      integ_res.integ_est += data[i].dx * data[i].f;
1351
-    }
1352
-
1353
-    max_abs_d2f_dx = 0.0;
1354
-    integ_res.abs_prec = 0.0;
1355
-    for (int j = 0; j < 3; ++j) {
1356
-      abs_d2f_dx[j] = dx * fabs(data[3*j].f - 2.0 * data[3*j + 1].f + data[3*j + 2].f);
1357
-      max_abs_d2f_dx = ABACUS::max(max_abs_d2f_dx, abs_d2f_dx[j]);
1358
-      integ_res.abs_prec += abs_d2f_dx[j];
1359
-    }
1360
-
1361
-    integ_res.rel_prec = integ_res.abs_prec/integ_res.integ_est;
1362
-
1363
-    //for (int in = 0; in < n_vals; ++in)
1364
-    //cout << in << "\t" << data[in].x << "\t" << data[in].f << "\t" << data[in].dx << endl;
1365
-  }
1366
-  */
1367 1286
   void Integral_data_CX::Save (ofstream& outfile)
1368 1287
   {
1369 1288
     // Reset file writing position
@@ -1482,114 +1401,6 @@ namespace ABACUS {
1482 1401
   }
1483 1402
 
1484 1403
   // No implementation with I_table yet for complex...
1485
-  /*
1486
-  void Integral_data::Improve_estimate (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable, int max_nr_pts)
1487
-  {
1488
-    // We generate a max of 3* n_vals points
1489
-    data_pt* new_data = new data_pt[3* integ_res.n_vals];
1490
-    DP* new_abs_d2f_dx = new DP[integ_res.n_vals];
1491
-
1492
-    // Check points in batches of 3;  if needed, improve
1493
-    int threei = 0;
1494
-    int index_new = 0;
1495
-    int i, j;
1496
-
1497
-    integ_res.abs_prec = 0.0;
1498
-    integ_res.integ_est = 0.0;
1499
-
1500
-    DP new_max_abs_d2f_dx = 0.0;
1501
-
1502
-    for (i = 0; i < integ_res.n_vals/3; ++i) {
1503
-
1504
-      threei = 3 * i;
1505
-
1506
-      if (abs_d2f_dx[i] <= 0.1 * max_abs_d2f_dx || index_new + integ_res.n_vals - threei > max_nr_pts) {
1507
-
1508
-	// simply transfer the data points into new_data
1509
-	new_abs_d2f_dx[index_new/3] = abs_d2f_dx[i];
1510
-	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3]);
1511
-	for (j = 0; j < 3; ++j) {
1512
-	  new_data[index_new].x = data[threei + j].x;
1513
-	  new_data[index_new].f = data[threei + j].f;
1514
-	  new_data[index_new].dx = data[threei + j].dx;
1515
-	  integ_res.integ_est += new_data[index_new].dx * new_data[index_new].f;
1516
-	  index_new++;
1517
-	}
1518
-	integ_res.abs_prec += abs_d2f_dx[i];
1519
-
1520
-      }
1521
-
1522
-      else {  // create six new entries and transfer the three existing ones
1523
-
1524
-	new_data[index_new].dx = data[threei].dx/3.0;
1525
-	for (j = 1; j < 9; ++j) new_data[index_new + j].dx = new_data[index_new].dx;
1526
-
1527
-	new_data[index_new].x = data[threei].x - new_data[index_new].dx;
1528
-	new_data[index_new + 1].x = data[threei].x;
1529
-	new_data[index_new + 2].x = data[threei].x + new_data[index_new].dx;
1530
-
1531
-	new_data[index_new + 3].x = data[threei + 1].x - new_data[index_new].dx;
1532
-	new_data[index_new + 4].x = data[threei + 1].x;
1533
-	new_data[index_new + 5].x = data[threei + 1].x + new_data[index_new].dx;
1534
-
1535
-	new_data[index_new + 6].x = data[threei + 2].x - new_data[index_new].dx;
1536
-	new_data[index_new + 7].x = data[threei + 2].x;
1537
-	new_data[index_new + 8].x = data[threei + 2].x + new_data[index_new].dx;
1538
-
1539
-	args[arg_to_integ] = new_data[index_new].x;
1540
-	new_data[index_new].f = function(args, Itable);
1541
-	new_data[index_new + 1].f = data[threei].f;
1542
-	args[arg_to_integ] = new_data[index_new + 2].x;
1543
-	new_data[index_new + 2].f = function(args, Itable);
1544
-
1545
-	args[arg_to_integ] = new_data[index_new + 3].x;
1546
-	new_data[index_new + 3].f = function(args, Itable);
1547
-	new_data[index_new + 4].f = data[threei + 1].f;
1548
-	args[arg_to_integ] = new_data[index_new + 5].x;
1549
-	new_data[index_new + 5].f = function(args, Itable);
1550
-
1551
-	args[arg_to_integ] = new_data[index_new + 6].x;
1552
-	new_data[index_new + 6].f = function(args, Itable);
1553
-	new_data[index_new + 7].f = data[threei + 2].f;
1554
-	args[arg_to_integ] = new_data[index_new + 8].x;
1555
-	new_data[index_new + 8].f = function(args, Itable);
1556
-
1557
-	new_abs_d2f_dx[index_new/3] = fabs(new_data[index_new].dx * (new_data[index_new].f - 2.0 * new_data[index_new + 1].f + new_data[index_new + 2].f));
1558
-	new_abs_d2f_dx[index_new/3 + 1] = fabs(new_data[index_new].dx * (new_data[index_new + 3].f - 2.0 * new_data[index_new + 4].f + new_data[index_new + 5].f));
1559
-	new_abs_d2f_dx[index_new/3 + 2] = fabs(new_data[index_new].dx * (new_data[index_new + 6].f - 2.0 * new_data[index_new + 7].f + new_data[index_new + 8].f));
1560
-
1561
-	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3]);
1562
-	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3 + 1]);
1563
-	new_max_abs_d2f_dx = ABACUS::max(new_max_abs_d2f_dx, new_abs_d2f_dx[index_new/3 + 2]);
1564
-
1565
-	integ_res.integ_est += new_data[index_new].dx * (new_data[index_new].f + new_data[index_new + 1].f + new_data[index_new + 2].f
1566
-							 + new_data[index_new + 3].f + new_data[index_new + 4].f + new_data[index_new + 5].f
1567
-							 + new_data[index_new + 6].f + new_data[index_new + 7].f + new_data[index_new + 8].f);
1568
-
1569
-	integ_res.abs_prec += new_abs_d2f_dx[index_new/3] + new_abs_d2f_dx[index_new/3 + 1] + new_abs_d2f_dx[index_new/3 + 2];
1570
-
1571
-	index_new += 9;
1572
-
1573
-      } // else
1574
-
1575
-    } // for (i < nvals/3)
1576
-
1577
-    integ_res.rel_prec = integ_res.abs_prec/integ_res.integ_est;
1578
-
1579
-    integ_res.n_vals = index_new;
1580
-
1581
-    delete[] data;
1582
-    data = new_data;
1583
-
1584
-    max_abs_d2f_dx = new_max_abs_d2f_dx;
1585
-
1586
-    delete[] abs_d2f_dx;
1587
-    abs_d2f_dx = new_abs_d2f_dx;
1588
-
1589
-    return;
1590
-  }
1591
-  */
1592
-
1593 1404
   Integral_result_CX Integrate_optimal (complex<DP> (*function) (Vect_DP), Vect_DP& args, int arg_to_integ, DP xmin, DP xmax,
1594 1405
 					DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1595 1406
   {
@@ -1605,43 +1416,5 @@ namespace ABACUS {
1605 1416
     return(integ_dat.integ_res);
1606 1417
   }
1607 1418
 
1608
-  // No implementation with I_table yet for complex...
1609
-  /*
1610
-  Integral_result Integrate_optimal_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
1611
-						 I_table Itable, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts)
1612
-  {
1613
-    if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
1614
-
1615
-    Integral_data integ_dat (function, args, arg_to_integ, Itable, xmin, xmax);
1616
-
1617
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
1618
-
1619
-      integ_dat.Improve_estimate (function, args, arg_to_integ, Itable, max_nr_pts);
1620
-    }
1621
-
1622
-    return(integ_dat.integ_res);
1623
-  }
1624
-  */
1625
-
1626
-  // No implementation with I_table yet for complex...
1627
-  /*
1628
-  Integral_result Integrate_optimal_using_table (DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
1629
-						 I_table Itable, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts, ofstream& outfile)
1630
-  {
1631
-    if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
1632
-
1633
-    Integral_data integ_dat (function, args, arg_to_integ, Itable, xmin, xmax);
1634
-
1635
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
1636
-
1637
-      integ_dat.Improve_estimate (function, args, arg_to_integ, Itable, max_nr_pts);
1638
-
1639
-      integ_dat.Save (outfile);
1640
-
1641
-    }
1642
-
1643
-    return(integ_dat.integ_res);
1644
-  }
1645
-  */
1646 1419
 
1647 1420
 } // namespace ABACUS

+ 10
- 5
src/INTEG/Integration_par.cc View File

@@ -19,7 +19,8 @@ using namespace std;
19 19
 
20 20
 namespace ABACUS {
21 21
 
22
-  void Improve_estimate_par (MPI_Comm comm, Integral_data& integdat, DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ, I_table Itable, int max_nr_pts)
22
+  void Improve_estimate_par (MPI_Comm comm, Integral_data& integdat, DP (*function) (Vect_DP, I_table),
23
+			     Vect_DP& args, int arg_to_integ, I_table Itable, int max_nr_pts)
23 24
   {
24 25
     // This function is only ever called by process rank 0.
25 26
 
@@ -41,7 +42,8 @@ namespace ABACUS {
41 42
 
42 43
       threei = 3 * i;
43 44
 
44
-      if (integdat.abs_d2f_dx[i] <= 0.1 * integdat.max_abs_d2f_dx || index_new + integdat.integ_res.n_vals - threei > max_nr_pts) {
45
+      if (integdat.abs_d2f_dx[i] <= 0.1 * integdat.max_abs_d2f_dx
46
+	  || index_new + integdat.integ_res.n_vals - threei > max_nr_pts) {
45 47
 
46 48
 	// simply transfer the data points into new_data
47 49
 	new_abs_d2f_dx[index_new/3] = integdat.abs_d2f_dx[i];
@@ -128,14 +130,17 @@ namespace ABACUS {
128 130
   }
129 131
 
130 132
 
131
-  Integral_result Integrate_optimal_par_using_table (MPI_Comm comm, DP (*function) (Vect_DP, I_table), Vect_DP& args, int arg_to_integ,
132
-						     I_table Itable, DP xmin, DP xmax, DP req_rel_prec, DP req_abs_prec, int max_nr_pts, ofstream& outfile)
133
+  Integral_result Integrate_optimal_par_using_table (MPI_Comm comm, DP (*function) (Vect_DP, I_table),
134
+						     Vect_DP& args, int arg_to_integ,
135
+						     I_table Itable, DP xmin, DP xmax,
136
+						     DP req_rel_prec, DP req_abs_prec, int max_nr_pts, ofstream& outfile)
133 137
   {
134 138
     if (xmax < xmin) ABACUSerror("Use xmax > xmin in Integrate.");
135 139
 
136 140
     Integral_data integ_dat (function, args, arg_to_integ, Itable, xmin, xmax);
137 141
 
138
-    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec) && integ_dat.integ_res.n_vals < max_nr_pts) {
142
+    while ((integ_dat.integ_res.rel_prec > req_rel_prec || integ_dat.integ_res.abs_prec > req_abs_prec)
143
+	   && integ_dat.integ_res.n_vals < max_nr_pts) {
139 144
 
140 145
       Improve_estimate_par (comm, integ_dat, function, args, arg_to_integ, Itable, max_nr_pts);
141 146
 

Loading…
Cancel
Save