Guest User

Untitled

a guest
Sep 2nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.80 KB | None | 0 0
  1. auto sites = Hubbard(Nspins); // Conserving all QNs
  2.  
  3. //The code below generates the Hubbard Hamiltonian for different U's
  4. void generate_H()
  5. {
  6.  
  7.   for (int ii=0; ii<=15; ii++)
  8.   {
  9.     double U = UU + ii*0.5;
  10.     auto ampo = AutoMPO(sites);
  11.  
  12.         for(int b = 1; b < Nspins; ++b)
  13.             {
  14.                 ampo += -1.0,"Cdagup",b,"Cup",b+1; //Hopping for spin up
  15.                 ampo += -1.0,"Cdagup",b+1,"Cup",b; // <-
  16.                 ampo += -1.0,"Cdagdn",b,"Cdn",b+1; //Hopping for spin down
  17.                 ampo += -1.0,"Cdagdn",b+1,"Cdn",b;// <-
  18.                 ampo += U, "Nup", b, "Ndn", b;
  19.             }
  20.                 ampo += U, "Nup", Nspins, "Ndn", Nspins;
  21.                 ampo += -1.0,"Cdagup",1,"Cup",Nspins; //Hopping for spin up
  22.                 ampo += -1.0,"Cdagup",Nspins,"Cup",1; // <-
  23.                 ampo += -1.0,"Cdagdn",1,"Cdn",Nspins; //Hopping for spin down
  24.                 ampo += -1.0,"Cdagdn",Nspins,"Cdn",1;// <-
  25.     MPO H_ = toMPO(ampo);
  26.     H.at(ii) = H_;
  27.   }
  28. }
  29.  
  30. //Here the Phi_0 states on which I want to act upon with c_p!c_q. It is a product of dimers.
  31. double create_state(const gsl_vector *cicoeff, void *params)
  32. {
  33.     int N = ((params_t *) params)->N;
  34.     int index = ((params_t *) params)->index;
  35.  
  36.     auto psi = MPS(sites);
  37.     double normalization;
  38.  
  39.     for(int n = 1; n <= N; n += 2)
  40.         {
  41.  
  42.         auto s1 = sites(n);
  43.         auto s2 = sites(n+1);
  44.  
  45.         normalization = 0;
  46.         int pos = n/2*ms;
  47.         for (int i=pos; i<=pos+ms-1; i++)
  48.           normalization += pow(gsl_vector_get(cicoeff,i),2);
  49.  
  50.         auto wf = ITensor(s1,s2);
  51.         wf.set(s1(2),s2(3), gsl_vector_get(cicoeff, pos)/sqrt(normalization));
  52.         wf.set(s1(3),s2(2), gsl_vector_get(cicoeff, pos+1)/sqrt(normalization));
  53.         wf.set(s1(1),s2(4), gsl_vector_get(cicoeff, pos+2)/sqrt(normalization));
  54.         wf.set(s1(4),s2(1), gsl_vector_get(cicoeff, pos+3)/sqrt(normalization));
  55.  
  56.         psi.ref(n) = ITensor(s1);
  57.         psi.ref(n+1) = ITensor(s2);
  58.         auto [U,S,V] = svd(wf,{inds(psi.ref(n))},{"Cutoff=",1E-8});
  59.         psi.ref(n) = U;
  60.         psi.ref(n+1) = S*V;
  61.  
  62.       }
  63.  
  64. //The code below is for swapping the indices of the dimers in case they are not nearest-neighbors.
  65.       int swaps = 1;
  66.       vector<pair <int,int>> swaps_;
  67.       vector <int> dimer;
  68.       for (int i=0; i<N; i++)
  69.         dimer.push_back(dimers[index][i]);
  70.  
  71.       while (swaps > 0)
  72.       {
  73.         swaps = 0;
  74.         pair <int,int> pair1;
  75.         for (int i=1; i<N; i++)
  76.         {
  77.           int pos1, pos2;
  78.           pos1 = find_index(dimer, i);
  79.           pos2 = find_index(dimer, i+1);
  80.           if (pos1 > pos2)
  81.           {
  82.             pair1.first = dimer[pos1];
  83.             pair1.second = dimer[pos2];
  84.             swaps_.push_back(pair1);
  85.             swaps += 1;
  86.             int temp = dimer[pos1];
  87.             dimer[pos1] = dimer[pos2];
  88.             dimer[pos2] = temp;
  89.             continue;
  90.           }
  91.         }
  92.       }
  93.       auto s1 = vector<Index>(1);
  94.       auto s2 = vector<Index>(1);
  95.       int ar1, ar2;
  96.       ITensor wf, S,V,U;
  97.       for (int i=swaps_.size()-1; i>=0; i--){
  98.         ar1 = swaps_[i].first;
  99.         ar2 = swaps_[i].second;
  100.         s1.clear(); s1.push_back(siteIndex(psi,ar1));
  101.         s2.clear(); s2.push_back(siteIndex(psi,ar2));
  102.         auto is1 = IndexSet(s1);
  103.         auto is2 = IndexSet(s2);
  104.  
  105.         psi.position(ar1);
  106.         wf = psi.A(ar1)*psi.A(ar2);
  107.         wf.swapInds(is1,is2);
  108.         wf.noPrime();
  109.         U = psi.A(ar1);
  110.         svd(wf,U,S,V,{"Cutoff=",1E-8});
  111.         psi.setA(ar1,U);
  112.         psi.setA(ar2,S*V);
  113.       }
  114.       states.at(index) = psi;
  115.       int point = ((params_t *) params)->point;
  116.       return inner(states.at(index),H[point],states.at(index));
  117. }
  118.  
  119. //Here is the code where all the problems arise.
  120. void computeG(gsl_matrix *G, int point, int ind)
  121. {
  122. //The first few lines are for generating C!_pC_q with up's and down's.
  123.         for (int i=1; i<=Nspins; i++)
  124.         {
  125.                 for (int j=1; j<=Nspins; j++)
  126.                 {
  127.                         for (int sgi=0; sgi<=1; sgi+=1) {
  128.                                 for (int sgj=0; sgj<=1; sgj+=1) {
  129.                                          char Cd[7] = "Cdag"; char C[4] = "C";
  130.                                         char Sgi[3], Sgj[3]; char up[3]="up"; char dn[3]="dn";
  131.         if (sgi == 0) {
  132.             strcpy(Sgi,"dn");
  133.         }
  134.         if (sgj == 0) {
  135.             strcpy(Sgj,"dn");
  136.         }
  137.         if (sgi == 1) {
  138.             strcpy(Sgi,"up");
  139.         }
  140.         if (sgj == 1) {
  141.             strcpy(Sgj, "up");
  142.         }
  143.                                         MPS Phi_0 = removeQNs(states.at(ind)); //This is one of the state that is a product
  144.                                                                                 of dimers.
  145.                                         MPO h = H[point]; //This is the Hubbard Hamiltonian for a specific U.
  146.                                         auto ampo = AutoMPO(sites);
  147.                                         if (sgi == sgj) {
  148.                                         ampo += convertToString(Cd)+convertToString(Sgi), i,                ConvertToString(C)+convertToString(Sgj), j; //Generating C!_pC_q
  149.                                         MPO cc = toMPO(ampo);
  150.                                         MPS h_mps = applyMPO(h,Phi_0); MPS cc_mps = applyMPO(cc,Phi_0); //Acting with H and C!C
  151.                                      cout << " " << inner(Phi_0,cc,h_mps) << " " << inner(Phi_0, h, cc_mps) << " " << i << j << endl;
  152.                                         double elem = -(inner(Phi_0, h, cc_mps) - inner(Phi_0,cc,h_mps));
  153.                                         gsl_matrix_set(G, 2*(i-1)+sgi,2*(j-1)+sgj,elem);}
  154.                                 }
  155.                         }
  156.                 }
  157.         }
  158. }
  159.  
Advertisement
Add Comment
Please, Sign In to add comment