Commit 04b51cf9 authored by Manuel Schrauth's avatar Manuel Schrauth
Browse files

unify 1D and 2D SSH lattice

parent c0b873d9
Pipeline #9966 failed with stage
in 3 minutes and 49 seconds
#ifndef SSHLATTE_H
#define SSHLATTE_H
// covers the 1+1 dimensional and the 2+1 dimensional case
// note that the dimension is set via the proceessor statement SSH_2D
class SSHLattice
{
public:
......@@ -13,22 +16,54 @@ class SSHLattice
SSHLattice(int l, int ltau, int d) : len(l), lentime(ltau), dim(d) // dim is the spatial dimension!
{
vol = dim * pow(len, dim); // spatial volume (number of bonds in a time slice)
nsites = vol * lentime; // total volume (number of sites)
// dim from config file will be ignored (improve me!)
#ifdef SSH_2D
dim = 2;
#else
dim = 1;
#endif
vol = dim * pow(len, dim); // spatial volume (number of bonds in a time slice)
nsites = vol * lentime; // total volume (number of sites)
}
// illustration of the bond arrangement in 2+1 dimensions
// horizontal and vertical bonds are arranged in an alternating fashion
// shown are the time slices t=0 and t=1 for a lattice of size L=3
// X's denote the coordinate grid, numbers represent the bonds
//
// o o o o o o
// | | | | | |
// 15 16 17 33 34 35
// | | | | | |
// X---12--X---13--X---14--o X---30--X---31--X---32--o
// | | | | | |
// 9 10 11 27 28 29
// | | | | | |
// X---6---X---7---X---8---o X---24--X---25--X---26--o
// | | | | | |
// 3 4 5 21 22 23
// | | | | | |
// X---0---X---1---X---2---o X---18--X---19--X---20--o
value_type getnbrs(int a, int i) const
{
value_type retval;
const int k = i / vol;
const int offset = i % vol;
int tslice = i / vol; // time slice
int offset = i % vol; // position (offset) in time slice
switch(a)
{
// returns the (two) neighbours along the time direction
case 0:
retval = {((k-1+lentime)%lentime)*vol+offset, ((k+1)%lentime)*vol+offset};
retval = {((tslice-1+lentime)%lentime)*vol+offset, ((tslice+1)%lentime)*vol+offset};
break;
// returns the entire lattice
case 1:
retval.reserve(this->nsites);
for(int j = 0; j < i; ++j)
......@@ -42,44 +77,47 @@ class SSHLattice
}
// spatial ordering for a 2+1 dimensional setting (L=3, Ltime>3)
// | | | | | | | | |
// | | . | | . | | .
// | . 24 | . 25 | . 26
// . 21. . 22. . 23.
// 18. | 19. | 20. |
// . | | . | | . | |
// | | | | | | | | |
// | | . | | . | | .
// | . 15 | . 16 | . 17
// . 12. . 13 . 14.
// 9 . | 10. | 11 .|
// . | | . | | . | |
// | | | | | | | | |
// | | . | | . | | .
// | . 6 | . 7 | . 8
// . 3 . 4 . 5
// 0 1 2
std::vector<double> getcrds(int i) const
{
// returns bond coordinates, which is five numbers in 2+1 dimension
// (xstart, xend, ystart, yend, time)
// and only three numbers in 1+1 dimension (xstart, xend, time)
const int tslice = i / vol; // time slice
const int offset = i % vol; // position (offset) in time slice
// e.g. getnbrs(a=0, 10): 1, 19
#ifdef SSH_2D
const int yslice = offset / len; // y-row
const int xpos = offset % len; // position in y-row
// since horizontal and vertical bonds are arranged in an alternating fashion (designers choice!)
// we require to extract the actual y coordinate
int yreal = yslice/2;
if (yslice%2 == 0)
{
const int left = xpos;
const int right = (xpos+1)%len; // account for p.b.c in x
return {left, right, yreal, yreal, tslice};
}
else
{
const int lower = yreal;
const int upper = (yreal+1)%len; // account for p.b.c in y
return {xpos, xpos, lower, upper, tslice};
}
std::vector<double> getcrds(int k) const
{
// transform one-dimensional index to n-d coordinates
std::vector<int> indices = IndexOfRect(k, dim, len, lentime);
std::vector<double> retval(dim,0);
for (int i=0; i<retval.size(); i++)
{
retval[i] = double(indices[i]); ///len;
// retval[i] += 0.5/len;
}
return retval;
#else
const int left = offset;
const int right = (offset+1)%len;
return {left, right, tslice};
#endif
}
value_type getbnds(int a, int i) const
{
......
#ifndef SSHLATTE_H
#define SSHLATTE_H
class SSHLattice
{
public:
int counter = 0;
typedef std::vector<int> value_type;
SSHLattice() {}
SSHLattice(int l, int ltau, int d) : len(l), lentime(ltau), dim(d) // dim is the spatial dimension!
{
vol = dim * pow(len, dim); // spatial volume (number of bonds in a time slice)
nsites = vol * lentime; // total volume (number of sites)
}
//# illustration of the bond arrangement in 2+1 dimensions
//# horizontal and vertical bonds are arranged in an alternating fashion
//# shown are the time slices t=0 and t=1 for a lattice of size L=3
//# X's denote the coordinate grid, numbers represent the bonds
//#
//# o o o o o o
//# | | | | | |
//# 15 16 17 33 34 35
//# | | | | | |
//# X---12--X---13--X---14--o X---30--X---31--X---32--o
//# | | | | | |
//# 9 10 11 27 28 29
//# | | | | | |
//# X---6---X---7---X---8---o X---24--X---25--X---26--o
//# | | | | | |
//# 3 4 5 21 22 23
//# | | | | | |
//# X---0---X---1---X---2---o X---18--X---19--X---20--o
value_type getnbrs(int a, int i) const
{
value_type retval;
int tslice = i / vol; // time slice
int offset = i % vol; // position (offset) in time slice
switch(a)
{
case 0: // returns the numbers along the time direction
{
int n1 = ((tslice-1+lentime)%lentime)*vol+offset;
int n2 = ((tslice+1)%lentime)*vol+offset;
retval = {n1,n2};
}
break;
case 1:
retval.reserve(this->nsites);
for(int j = 0; j < i; ++j)
retval.push_back(j);
for(int j = i+1; j < this->nsites; ++j)
retval.push_back(j);
break;
}
return retval;
}
std::vector<double> getcrds(int i) const
{
// returns bond coordinates, which is five numbers in 2+1 dimension
// (xstart, xend, ystart, yend, time)
int tslice = i / vol; // time slice
int offset = i % vol; // position (offset) in time slice
int yslice = offset / len; // y-row
int xpos = offset % len; // position in y-row
// since horizontal and vertical bonds are arranged in an alternating fashion (designers choice!)
// we require to extract the actual y coordinate
int yreal = yslice/2;
if (yslice%2 == 0)
{
int left = xpos;
int right = (xpos+1)%len; // account for p.b.c in x
return {left, right, yreal, yreal, tslice};
}
else
{
int lower = yreal;
int upper = (yreal+1)%len; // account for p.b.c in y
return {xpos, xpos, lower, upper, tslice};
}
}
value_type getbnds(int a, int i) const
{
value_type retval;
switch(a)
{
case 0:
retval = {1,1};
break;
case 1:
cout << "This should not have happened!" << endl;
retval.reserve(this->nsites);
for(int j = 0; j < i; ++j)
retval.push_back(1.0);
for(int j = i+1; j < this->nsites; ++j)
retval.push_back(1.0);
break;
}
return retval;
}
std::size_t size() const {return nsites;}
int len, lentime, vol;
int dim;
std::size_t nsites;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment