-
Notifications
You must be signed in to change notification settings - Fork 0
/
defLatt.py
executable file
·86 lines (63 loc) · 2.1 KB
/
defLatt.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#Classes and functions needed for the deffinition of a lattice
import scipy
class Lattice:
"""
Lattice class
"""
def __init__(self, N=10, dim=2):
"""
Calls SetHop
"""
self.SetHop(N,dim)
def SetHop(self, N, dim):
"""
Sets self.N to N and self.dim to dim
Calls SetHop for the appropiate dimension
"""
self.N = N
self.dim = dim
if dim==1:
self.SetHop1d(N)
elif dim==2:
self.SetHop2d(N)
else:
print "SetHop not defined for such dimensions"
return None
def SetHop1d(self, N):
"""
Builds AgGrid lattice array and hop dictionary for 1d lattices
"""
self.Hop = {}
self.Nag = N
self.AgGrid = scipy.array(range(N),int)
#print "[Lattice.SetHop1d] AgGrid: ", self.AgGrid
for i in self.AgGrid:
preM = (i, 1)
prem = (i, -1)
self.Hop[preM] = (i+1)%N
self.Hop[prem] = (i-1)%N
#print "[Lattice.SetHop1d] Hop: ", self.Hop
def SetHop2d(self, N):
"""
Builds AgGrid lattice array and hop dictionary for 1d lattices
"""
self.Hop = {}
self.Nag = N**2
self.AgGrid = scipy.zeros((N,N), int)
count = 0
for i in range(N):
for j in range (N):
self.AgGrid[i,j]= count
count = count + 1
print "[Lattice.SetHop2d] AgGrid: ", self.AgGrid
for i in range(N):
for j in range(N):
preM1 = (self.AgGrid[i,j], 1)
prem1 = (self.AgGrid[i,j], -1)
preM2 = (self.AgGrid[i,j], 2)
prem2 = (self.AgGrid[i,j], -2)
self.Hop[preM1] = self.AgGrid[(i+1)%N,j]
self.Hop[prem1] = self.AgGrid[(i-1)%N,j]
self.Hop[preM2] = self.AgGrid[i,(j+1)%N]
self.Hop[prem2] = self.AgGrid[i,(j+1)%N]
print "[Lattice.SetHop2d] Hop: ", self.Hop