DMRG-SquareLattice.cpp
1 
3 static char help[] =
4  "DMRG executable for the Spin-1/2 J1-J2 XY Model on a two-dimensional square lattice.\n";
5 
6 #include "DMRGBlock.hpp"
7 #include "Hamiltonians.hpp"
8 #include "DMRGBlockContainer.hpp"
9 
12 PetscErrorCode Correlators(DMRG_t& DMRG);
13 
15 int main(int argc, char **argv)
16 {
17  PetscErrorCode ierr;
18  PetscMPIInt nprocs, rank;
19  ierr = SlepcInitialize(&argc, &argv, (char*)0, help); CHKERRQ(ierr);
20  ierr = MPI_Comm_size(PETSC_COMM_WORLD, &nprocs); CHKERRQ(ierr);
21  ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
22  {
23  DMRG_t DMRG(PETSC_COMM_WORLD);
24  ierr = DMRG.Initialize(); CHKERRQ(ierr);
25 
26  /* Setup correlator measurements */
27  ierr = Correlators(DMRG); CHKERRQ(ierr);
28 
29  /* Perform DMRG steps */
30  ierr = DMRG.Warmup(); CHKERRQ(ierr);
31  ierr = DMRG.Sweeps(); CHKERRQ(ierr);
32 
33  ierr = DMRG.Destroy(); CHKERRQ(ierr);
34  }
35  ierr = SlepcFinalize(); CHKERRQ(ierr);
36  return(0);
37 }
38 
40 PetscErrorCode Correlators(DMRG_t& DMRG)
41 {
42  PetscErrorCode ierr;
43  /* Explicitly give a list of operators. */
44  PetscInt Lx = DMRG.HamiltonianRef().Lx();
45  PetscInt Ly = DMRG.HamiltonianRef().Ly();
46  PetscInt NumSitesSys = Lx*Ly/2;
47 
48  /* The magnetization at each site */
49  for(PetscInt idx=0; idx < NumSitesSys; ++idx)
50  {
51  std::vector< Op > OpList;
52  OpList.push_back({OpSz,idx});
53 
54  PetscInt ix, jy;
55  std::string desc;
56  ierr = DMRG.HamiltonianRef().To2D(idx,ix,jy); CHKERRQ(ierr);
57  desc += "< ";
58  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
59  desc += ">";
60  std::string name = "Magnetization(" + std::to_string(idx) + ")";
61  ierr = DMRG.SetUpCorrelation(OpList, name, desc); CHKERRQ(ierr);
62  }
63 
64  /* The pair-wise correlation of nearest neighbors (Sz-Sz, Sp-Sm, Sm-Sp) for calculating bond energies
65  for the corresponding Heisenberg model */
66  {
67  const std::vector< std::vector < PetscInt > > nnp = DMRG.HamiltonianRef().NeighborPairs();
68  for(const std::vector< PetscInt > pair : nnp)
69  {
70  if(pair.size()!=2) SETERRQ1(PETSC_COMM_WORLD,1,"Invalid 2-point correlator. Got %lu operators instead.", pair.size());
71  std::vector< std::vector< Op_t > > OpTypesList = { {OpSz, OpSz}, {OpSp, OpSm}, {OpSm, OpSp} };
72  for (const std::vector< Op_t >& OpTypes : OpTypesList)
73  {
74  std::vector< Op > OpList;
75  std::string desc = "< ";
76  std::string name = std::string("NearestNeighbor") + OpToStr(OpTypes[0]) + OpToStr(OpTypes[1]) + "( ";
77  for(PetscInt i=0; i < 2; ++i)
78  {
79  const PetscInt idx = pair.at(i);
80  const Op_t OpType = OpTypes.at(i);
81  OpList.push_back({OpType,idx});
82  PetscInt ix, jy;
83  ierr = DMRG.HamiltonianRef().To2D(idx,ix,jy); CHKERRQ(ierr);
84  desc += OpToStr(OpType) + "_{" + std::to_string(ix) + "," + std::to_string(jy) + "} ";
85  name += std::to_string(idx) + " ";
86  }
87  desc += ">";
88  name += ")";
89  ierr = DMRG.SetUpCorrelation(OpList, name, desc); CHKERRQ(ierr);
90  }
91  }
92  }
93 
94  /* The 1st row from the top <Sz_{0,0} Sz_{1,0} ... Sz_{Lx-1,0}> */
95  {
96  std::vector< Op > OpList;
97  std::string desc;
98  desc += "< ";
99  for(PetscInt i = 0; i < Lx; ++i){
100  const PetscInt ix = i;
101  const PetscInt jy = 1;
102  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
103  OpList.push_back({OpSz,idx});
104  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
105  }
106  desc += ">";
107  ierr = DMRG.SetUpCorrelation(OpList, "MagnetizationRowX1", desc); CHKERRQ(ierr);
108  }
109 
110  /* The second left-most column <Sz_{1,0} Sz_{1,1} ... Sz_{1,Ly-1}>. Equivalent to a Polyakov
111  loop when BCx is periodic */
112  {
113  std::vector< Op > OpList;
114  std::string desc;
115  desc += "< ";
116  for(PetscInt j = 0; j < Ly; ++j){
117  const PetscInt ix = 1;
118  const PetscInt jy = j;
119  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
120  OpList.push_back({OpSz,idx});
121  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
122  }
123  desc += ">";
124  ierr = DMRG.SetUpCorrelation(OpList, "Polyakov", desc); CHKERRQ(ierr);
125  }
126 
127  /* The second to the last left-most column <Sz_{Lx-2,0} Sz_{Lx-2,1} ... Sz_{Lx-2,Ly-1}>. Equivalent to a Polyakov
128  loop when BCx is periodic */
129  {
130  std::vector< Op > OpList;
131  std::string desc;
132  desc += "< ";
133  for(PetscInt j = 0; j < Ly; ++j){
134  const PetscInt ix = Lx-2;
135  const PetscInt jy = j;
136  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
137  OpList.push_back({OpSz,idx});
138  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
139  }
140  desc += ">";
141  ierr = DMRG.SetUpCorrelation(OpList, "Polyakov2", desc); CHKERRQ(ierr);
142  }
143 
144  /* We can also measure a Wilson loop of size (Lx-2)*(Ly-2) on the interior. */
145  {
146  std::vector< Op > OpList;
147  std::string desc;
148  desc += "< ";
149  for(PetscInt j = 1; j < Ly-2; ++j){
150  const PetscInt ix = 1;
151  const PetscInt jy = j;
152  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
153  OpList.push_back({OpSz,idx});
154  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
155  }
156  for(PetscInt i = 1; i < Lx-2; ++i){
157  const PetscInt ix = i;
158  const PetscInt jy = Ly-2;
159  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
160  OpList.push_back({OpSz,idx});
161  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
162  }
163  for(PetscInt j = Ly-2; j > 1; --j){
164  const PetscInt ix = Lx-2;
165  const PetscInt jy = j;
166  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
167  OpList.push_back({OpSz,idx});
168  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
169  }
170  for(PetscInt i = Lx-2; i > 1; --i){
171  const PetscInt ix = i;
172  const PetscInt jy = 1;
173  const PetscInt idx = DMRG.HamiltonianRef().To1D(ix,jy);
174  OpList.push_back({OpSz,idx});
175  desc += "Sz_{"+ std::to_string(ix) + "," + std::to_string(jy) + "} ";
176  }
177  desc += ">";
178  ierr = DMRG.SetUpCorrelation(OpList, "Wilson", desc); CHKERRQ(ierr);
179  }
180 
181  return(0);
182 }
PetscErrorCode SetUpCorrelation(const std::vector< Op > &OpList, const std::string &name, const std::string &desc)
Sets up measurement of correlation functions at the end of each sweep.
operator
Definition: DMRGBlock.hpp:25
Op_t
Identifies the three possible spin operators and also represents the shift associated to its action o...
Definition: DMRGBlock.hpp:21
operator
Definition: DMRGBlock.hpp:23
#define OpToStr(OP)
Convert the input Op_t to a C++ string.
Definition: DMRGBlock.hpp:41
operator
Definition: DMRGBlock.hpp:24
const Hamiltonian & HamiltonianRef() const
Const reference to the Hamiltonian object for extracting its parameters.
Contains and manipulates the system and environment blocks used in a single DMRG run.
This site was generated by Sphinx using Doxygen with a customized theme from doxygen-bootstrapped.