1 #include "Hamiltonians.hpp" 4 #define SSNAKE_2D_1D(ix,jy,_Lx,_Ly) (((ix)*(_Ly)+jy)*(1-((ix)%2)) + ((ix+1)*(_Ly) - (jy+1))*((ix)%2)) 6 PetscInt Hamiltonians::J1J2XXZModel_SquareLattice::To1D(
11 return SSNAKE_2D_1D(ix,jy,
_Lx,
_Ly);
14 PetscErrorCode Hamiltonians::J1J2XXZModel_SquareLattice::To2D(
21 const PetscInt t1 = ix % 2;
22 jy = (idx %
_Ly) * (1 - 2*t1) + (
_Ly - 1)*t1;
27 const PetscInt& ix,
const PetscInt& jy,
const PetscInt& nsites_in
30 std::vector<PetscInt> nn(0);
32 if(((0 <= jy) && (jy < (
_Ly-1))) || ((jy == (
_Ly-1)) && (
_BCy == PeriodicBC)))
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);
39 if(((0 <= ix) && (ix < (
_Lx-1))) || ((ix == (
_Lx-1)) && (
_BCx == PeriodicBC)))
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);
49 const PetscInt& ix,
const PetscInt& jy,
const PetscInt& nsites_in
52 std::vector<PetscInt> nnn(0);
54 if( (((1 <= ix) && (ix <
_Lx )) || ((ix == 0) && (
_BCx == PeriodicBC))) &&
55 (((0 <= jy) && (jy <
_Ly-1)) || ((jy == (
_Ly-1)) && (
_BCy == PeriodicBC))) )
58 if(nnn1d < nsites_in) nnn.push_back(nnn1d);
61 if( (((0 <= ix) && (ix <
_Lx-1)) || ((ix == (
_Lx-1)) && (
_BCx == PeriodicBC))) &&
62 (((0 <= jy) && (jy <
_Ly-1)) || ((jy == (
_Ly-1)) && (
_BCy == PeriodicBC))) )
64 const PetscInt nnn1d = SSNAKE_2D_1D((ix+1)%
_Lx,(jy+1)%
_Ly,
_Lx,
_Ly);
65 if(nnn1d < nsites_in) nnn.push_back(nnn1d);
72 PetscInt ns = (nsites_in == PETSC_DEFAULT) ?
_Lx*
_Ly : nsites_in;
73 PetscBool full_lattice = PetscBool(nsites_in ==
_Lx*
_Ly);
77 std::vector< Hamiltonians::Term > Terms(0);
78 Terms.reserve(ns*4*2);
79 for (PetscInt is = 0; is < ns; ++is)
81 const PetscInt ix = is /
_Ly;
82 const PetscInt jy = (is %
_Ly)*(1 - 2 * (ix % 2)) + (_Ly - 1)*(ix % 2);
87 for(
const PetscInt& in: nn)
90 PetscInt ia = (in < is) ? in : is;
91 PetscInt ib = (in > is) ? in : is;
101 if((
_J2 != 0.0 &&
_Jz2 != 0.0) &&
_Lx > 1 && _Ly > 1)
104 for(
const PetscInt& in: nnn)
107 PetscInt il = (in < is) ? in : is;
108 PetscInt ir = (in > is) ? in : is;
128 if(d!=1) CPP_CHKERRQ_MSG(1,
"Only d=1 supported.");
129 std::vector< std::vector< PetscInt > > nnp;
131 for (PetscInt is = 0; is < ns; ++is)
133 const PetscInt ix = is /
_Ly;
134 const PetscInt jy = (is %
_Ly)*(1 - 2 * (ix % 2)) + (_Ly - 1)*(ix % 2);
137 for(
const PetscInt& in: nn)
140 PetscInt ia = (in < is) ? in : is;
141 PetscInt ib = (in > is) ? in : is;
143 nnp.push_back({ia,ib});
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' 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.
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' 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...
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.
PetscBool H_full_filled
Tells whether H_full has been constructed.