Hamiltonians.cpp
1 #include "Hamiltonians.hpp"
2 
4 #define SSNAKE_2D_1D(ix,jy,_Lx,_Ly) (((ix)*(_Ly)+jy)*(1-((ix)%2)) + ((ix+1)*(_Ly) - (jy+1))*((ix)%2))
5 
6 PetscInt Hamiltonians::J1J2XXZModel_SquareLattice::To1D(
7  const PetscInt ix,
8  const PetscInt jy
9  ) const
10 {
11  return SSNAKE_2D_1D(ix,jy,_Lx,_Ly);
12 }
13 
14 PetscErrorCode Hamiltonians::J1J2XXZModel_SquareLattice::To2D(
15  const PetscInt idx,
16  PetscInt& ix,
17  PetscInt& jy
18  ) const
19 {
20  ix = idx / _Ly;
21  const PetscInt t1 = ix % 2;
22  jy = (idx % _Ly) * (1 - 2*t1) + (_Ly - 1)*t1;
23  return(0);
24 }
25 
27  const PetscInt& ix, const PetscInt& jy, const PetscInt& nsites_in
28  ) const
29 {
30  std::vector<PetscInt> nn(0);
31  /* Above */
32  if(((0 <= jy) && (jy < (_Ly-1))) || ((jy == (_Ly-1)) && (_BCy == PeriodicBC)))
33  {
34  const PetscInt jy_above = (jy+1)%_Ly;
35  const PetscInt nn1d = SSNAKE_2D_1D(ix,jy_above,_Lx,_Ly);
36  if(nn1d < nsites_in && jy_above != jy) nn.push_back(nn1d);
37  }
38  /* Right */
39  if(((0 <= ix) && (ix < (_Lx-1))) || ((ix == (_Lx-1)) && (_BCx == PeriodicBC)))
40  {
41  const PetscInt ix_right = (ix+1)%_Lx;
42  const PetscInt nn1d = SSNAKE_2D_1D(ix_right,jy,_Lx,_Ly);
43  if(nn1d < nsites_in && ix_right != ix) nn.push_back(nn1d);
44  }
45  return nn;
46 }
47 
49  const PetscInt& ix, const PetscInt& jy, const PetscInt& nsites_in
50  ) const
51 {
52  std::vector<PetscInt> nnn(0);
53  /* Upper-left */
54  if( (((1 <= ix) && (ix < _Lx )) || ((ix == 0) && (_BCx == PeriodicBC))) &&
55  (((0 <= jy) && (jy < _Ly-1)) || ((jy == (_Ly-1)) && (_BCy == PeriodicBC))) )
56  {
57  const PetscInt nnn1d = SSNAKE_2D_1D((ix+_Lx-1)%_Lx,(jy+1)%_Ly,_Lx,_Ly);
58  if(nnn1d < nsites_in) nnn.push_back(nnn1d);
59  }
60  /* Upper-right */
61  if( (((0 <= ix) && (ix < _Lx-1)) || ((ix == (_Lx-1)) && (_BCx == PeriodicBC))) &&
62  (((0 <= jy) && (jy < _Ly-1)) || ((jy == (_Ly-1)) && (_BCy == PeriodicBC))) )
63  {
64  const PetscInt nnn1d = SSNAKE_2D_1D((ix+1)%_Lx,(jy+1)%_Ly,_Lx,_Ly);
65  if(nnn1d < nsites_in) nnn.push_back(nnn1d);
66  }
67  return nnn;
68 }
69 
70 std::vector< Hamiltonians::Term > Hamiltonians::J1J2XXZModel_SquareLattice::H(const PetscInt& nsites_in)
71 {
72  PetscInt ns = (nsites_in == PETSC_DEFAULT) ? _Lx*_Ly : nsites_in;
73  PetscBool full_lattice = PetscBool(nsites_in == _Lx*_Ly);
74  if(full_lattice && H_full_filled){
75  return H_full;
76  };
77  std::vector< Hamiltonians::Term > Terms(0);
78  Terms.reserve(ns*4*2); /* Assume the maximum when all sites have all 4 interactions and 2 terms each */
79  for (PetscInt is = 0; is < ns; ++is)
80  {
81  const PetscInt ix = is / _Ly;
82  const PetscInt jy = (is % _Ly)*(1 - 2 * (ix % 2)) + (_Ly - 1)*(ix % 2);
83  /* Get nearest neighbors */
84  if(_J1 != 0.0 || _Jz1 != 0.0)
85  {
86  const std::vector<PetscInt> nn = GetNearestNeighbors(ix,jy,ns);
87  for(const PetscInt& in: nn)
88  {
89  /* Ensure that 1d block indices are ordered */
90  PetscInt ia = (in < is) ? in : is;
91  PetscInt ib = (in > is) ? in : is;
92  /* Append the terms into the Hamiltonian */
93  if(_J1 != 0.0) Terms.push_back({ _J1, OpSp, ia, OpSm, ib }); /* J1 S^+_ia S^-_ib */
94  if(_J1 != 0.0) Terms.push_back({ _J1, OpSm, ia, OpSp, ib }); /* J1 S^-_ia S^+_ib */
95  if(_Jz1 != 0.0) Terms.push_back({ _Jz1, OpSz, ia, OpSz, ib }); /* Jz1 S^z_ia S^z_ib */
96  }
97  }
98  /* Get next-nearest neighbors */
99  /* FIXME: Verify that on a one-dimensional chain, there are no next-nearest neighbors */
100  /* When _J2==0 do not generate any terms */
101  if((_J2 != 0.0 && _Jz2 != 0.0) && _Lx > 1 && _Ly > 1)
102  {
103  const std::vector<PetscInt> nnn = GetNextNearestNeighbors(ix,jy,ns);
104  for(const PetscInt& in: nnn)
105  {
106  /* Ensure that 1d block indices are ordered */
107  PetscInt il = (in < is) ? in : is;
108  PetscInt ir = (in > is) ? in : is;
109  /* Append the terms into the Hamiltonian */
110  if(_J2 != 0.0) Terms.push_back({ _J2, OpSp, il, OpSm, ir }); /* J2 S^+_ia S^-_ib */
111  if(_J2 != 0.0) Terms.push_back({ _J2, OpSm, il, OpSp, ir }); /* J2 S^-_ia S^+_ib */
112  if(_Jz2 != 0.0) Terms.push_back({ _Jz2, OpSz, il, OpSz, ir }); /* Jz2 S^z_ia S^z_ib */
113  }
114  }
115  }
116  if(full_lattice && !H_full_filled){
117  H_full = Terms;
118  H_full_filled = PETSC_TRUE;
119  return H_full;
120  }
121  return Terms;
122 }
123 
124 std::vector< std::vector< PetscInt > > Hamiltonians::J1J2XXZModel_SquareLattice::NeighborPairs(
125  const PetscInt d
126  ) const
127 {
128  if(d!=1) CPP_CHKERRQ_MSG(1, "Only d=1 supported.");
129  std::vector< std::vector< PetscInt > > nnp;
130  PetscInt ns = _Lx*_Ly;
131  for (PetscInt is = 0; is < ns; ++is)
132  {
133  const PetscInt ix = is / _Ly;
134  const PetscInt jy = (is % _Ly)*(1 - 2 * (ix % 2)) + (_Ly - 1)*(ix % 2);
135  /* Get nearest neighbors */
136  const std::vector<PetscInt> nn = GetNearestNeighbors(ix,jy,ns);
137  for(const PetscInt& in: nn)
138  {
139  /* Ensure that 1d block indices are ordered */
140  PetscInt ia = (in < is) ? in : is;
141  PetscInt ib = (in > is) ? in : is;
142  /* Append the pair */
143  nnp.push_back({ia,ib});
144  }
145  }
146  return nnp;
147 }
std::vector< PetscInt > GetNextNearestNeighbors(const PetscInt &ix, const PetscInt &jy, const PetscInt &nsites_in) const
Given the 2d lattice coordinates, this function retrieves the next-nearest neighbors&#39; 1D coordinates...
BC_t _BCx
Boundary conditions for the longitudinal direction (defaults to cylindrical BC)
BC_t _BCy
Boundary conditions for the transverse direction (defaults to cylindrical BC)
PetscScalar _Jz2
Transverse anisotropy for next-nearest-neighbor interactions.
operator
Definition: DMRGBlock.hpp:25
std::vector< PetscInt > GetNearestNeighbors(const PetscInt &ix, const PetscInt &jy, const PetscInt &nsites_in) const
Given the 2d lattice coordinates, this function retrieves the nearest neighbors&#39; 1D coordinates...
PetscScalar _Jz1
Transverse anisotropy for nearest-neighbor interactions.
PetscInt _Ly
Length along (fixed) transverse direction.
PetscScalar _J1
Coupling strength for nearest-neighbor interactions.
std::vector< std::vector< PetscInt > > NeighborPairs(const PetscInt d=1) const
Returns all pairs of nearest-neighbors in the full square lattice.
std::vector< Term > H(const PetscInt &nsites)
Returns the object used to construct the Hamiltonian using sites counted from the left side of the la...
operator
Definition: DMRGBlock.hpp:23
std::vector< Term > H_full
Contains the Hamiltonian involving the entire lattice.
PetscScalar _J2
Coupling strength for next-nearest-neighbor interactions.
PetscInt _Lx
Length along (growing) longitudinal direction.
operator
Definition: DMRGBlock.hpp:24
PetscBool H_full_filled
Tells whether H_full has been constructed.
This site was generated by Sphinx using Doxygen with a customized theme from doxygen-bootstrapped.