-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSquareLattice.cpp
More file actions
50 lines (47 loc) · 1.37 KB
/
SquareLattice.cpp
File metadata and controls
50 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "SquareLattice.h"
#include "linalg.h"
#include <iomanip>
#include <sstream>
#include <initializer_list>
using namespace std;
SquareLattice::SquareLattice(size_t Lx, size_t Ly)
:Lattice(Lx,Ly)
{
// By convention we store the lattice sites row-wise
// create vertices
vector<Vertex*> non_const;
for(size_t y=0;y<Ly;++y){
for(size_t x=0;x<Lx;++x){
non_const.push_back(new Vertex(non_const.size(),{ size_t(x), size_t(y) },{ double(0), double(0) }));
vertices.push_back(non_const.back());
}
}
// create edges
for(size_t x=0; x<Lx; ++x){
for(size_t y=0; y<Ly; ++y){
edges.push_back(new Edge(non_const[y*Lx+x],non_const[linalg::mod(y+1,Ly)*Lx+x]));
edges.push_back(new Edge(non_const[y*Lx+x],non_const[y*Lx+linalg::mod(x+1,Lx)]));
}
}
}
string SquareLattice::str(std::vector<string> st) const
{
if(!st.size())
st=vector<string>(vertices.size());
ostringstream out;
for(size_t y=0;y<m_Ly;++y){
for(size_t x=0;x<m_Lx;++x){
out<<setfill('.')<<setw(3)<<st[y*m_Lx+x];
if(x!=m_Lx-1) out<<'-';
}
if(y!=m_Ly-1){
out<<endl;
for(size_t x=0;x<m_Lx;++x){
out<<" | ";
if(x!=m_Lx-1) out<<" ";
}
out<<endl;
}
}
return out.str();
}