1+ """
2+ FiniteStrip(L::Int, N::Int)
3+
4+ An finite strip with `L` sites per rung and `N` sites per unit cell.
5+ """
6+ struct FiniteStrip <: AbstractLattice{2}
7+ L:: Int
8+ N:: Int
9+ function FiniteStrip (L:: Integer , N:: Integer = L)
10+ N > 0 || throw (ArgumentError (" period should be positive" ))
11+ mod (N, L) == 0 ||
12+ throw (ArgumentError (" period should be a multiple of circumference" ))
13+ return new (L, N)
14+ end
15+ end
16+ FiniteLadder (N:: Integer ) = FiniteStrip (2 , N)
17+ Base. axes (strip:: FiniteStrip ) = (1 : (strip. L), (1 : (strip. N ÷ strip. L)))
18+ Base. isfinite (:: Type{FiniteStrip} ) = true
19+
120"""
221 InfiniteStrip(L::Int, N::Int)
322
@@ -17,6 +36,27 @@ InfiniteLadder(N::Integer) = InfiniteStrip(2, N)
1736Base. axes (strip:: InfiniteStrip ) = (1 : (strip. L), (- typemax (Int)): typemax (Int))
1837Base. isfinite (:: Type{InfiniteStrip} ) = false
1938
39+ """
40+ FiniteCylinder(L::Int, N::Int)
41+
42+ An finite cylinder with `L` sites per rung and `N` sites per unit cell.
43+ """
44+ struct FiniteCylinder <: AbstractLattice{2}
45+ L:: Int
46+ N:: Int
47+ function FiniteCylinder (L:: Integer , N:: Integer = L)
48+ N > 0 || throw (ArgumentError (" period should be positive" ))
49+ mod (N, L) == 0 ||
50+ throw (ArgumentError (" period should be a multiple of circumference" ))
51+ return new (L, N)
52+ end
53+ end
54+
55+ function Base. axes (cylinder:: FiniteCylinder )
56+ return ((- typemax (Int)): typemax (Int), (1 : (cylinder. N ÷ cylinder. L)))
57+ end
58+ Base. isfinite (:: Type{FiniteCylinder} ) = true
59+
2060"""
2161 InfiniteCylinder(L::Int, N::Int)
2262
3676Base. axes (:: InfiniteCylinder ) = ((- typemax (Int)): typemax (Int), (- typemax (Int)): typemax (Int))
3777Base. isfinite (:: Type{InfiniteCylinder} ) = false
3878
79+ """
80+ FiniteHelix(L::Integer, N::Integer)
81+
82+ An finite helix with `L` sites per rung and `N` sites per unit cell.
83+ """
84+ struct FiniteHelix <: AbstractLattice{2}
85+ L:: Int
86+ N:: Int
87+ function FiniteHelix (L:: Integer , N:: Integer = 1 )
88+ N > 0 || error (" period should be positive" )
89+ return new (L, N)
90+ end
91+ end
92+
93+ Base. axes (helix:: FiniteHelix ) = ((- typemax (Int)): typemax (Int), (1 : (helix. N ÷ helix. L)))
94+ Base. isfinite (:: Type{FiniteHelix} ) = true
95+
3996"""
4097 InfiniteHelix(L::Integer, N::Integer)
4198
@@ -57,23 +114,65 @@ Base.isfinite(::Type{InfiniteHelix}) = false
57114
58115# ###########################################################################################
59116
117+ function linearize_index (lattice:: FiniteStrip , i:: Int , j:: Int )
118+ @assert (1 <= i <= lattice. L && 1 <= j <= lattice. N ÷ lattice. L) " lattice point out of bounds"
119+ return i + lattice. L * (j - 1 )
120+ end
60121function linearize_index (lattice:: InfiniteStrip , i:: Int , j:: Int )
61- @assert i <= lattice. L " lattice point out of bounds"
122+ @assert 1 <= i <= lattice. L " lattice point out of bounds"
123+ return i + lattice. L * (j - 1 )
124+ end
125+ function linearize_index (lattice:: FiniteCylinder , i:: Int , j:: Int )
126+ @assert 1 <= j <= lattice. N ÷ lattice. L " lattice point out of bounds"
62127 return mod1 (i, lattice. L) + lattice. L * (j - 1 )
63128end
64129function linearize_index (lattice:: InfiniteCylinder , i:: Int , j:: Int )
65130 return mod1 (i, lattice. L) + lattice. L * (j - 1 )
66131end
132+ function linearize_index (helix:: FiniteHelix , i:: Int , j:: Int )
133+ lin_ind = mod1 (i, helix. L) + helix. L * (j + (i - 1 ) ÷ helix. L - 1 )
134+ @assert (1 <= j <= lattice. N ÷ lattice. L && 1 <= lin_ind <= helix. N) " lattice point out of bounds"
135+ return mod1 (i, helix. L) + helix. L * (j + (i - 1 ) ÷ helix. L - 1 )
136+ end
67137function linearize_index (helix:: InfiniteHelix , i:: Int , j:: Int )
68138 return mod1 (i, helix. L) + helix. L * (j + (i - 1 ) ÷ helix. L - 1 )
69139end
70140
71- function vertices (lattice:: Union{InfiniteStrip,InfiniteCylinder} )
141+ function vertices (lattice:: Union{FiniteStrip, InfiniteStrip,FiniteCylinder ,InfiniteCylinder} )
72142 return (LatticePoint ((i, j), lattice) for i in 1 : (lattice. L),
73143 j in 1 : (lattice. N ÷ lattice. L))
74144end
75- vertices (lattice:: InfiniteHelix ) = (LatticePoint ((i, 1 ), lattice) for i in 1 : (lattice. N))
145+ function vertices (lattice:: Union{FiniteHelix,InfiniteHelix} )
146+ return (LatticePoint ((i, 1 ), lattice) for i in 1 : (lattice. N))
147+ end
76148
149+ function nearest_neighbours (lattice:: FiniteStrip )
150+ rows = lattice. L
151+ cols = lattice. N ÷ lattice. L
152+ horizontal = (LatticePoint ((i, j), lattice) => LatticePoint ((i, j + 1 ), lattice)
153+ for i in 1 : rows, j in 1 : (cols - 1 ))
154+ vertical = (LatticePoint ((i, j), lattice) => LatticePoint ((i + 1 , j), lattice)
155+ for i in 1 : (rows - 1 ), j in 1 : cols)
156+ return Iterators. flatten ((horizontal, vertical))
157+ end
158+ function nearest_neighbours (lattice:: FiniteCylinder )
159+ rows = lattice. L
160+ cols = lattice. N ÷ lattice. L
161+ horizontal = (LatticePoint ((i, j), lattice) => LatticePoint ((i, j + 1 ), lattice)
162+ for i in 1 : rows, j in 1 : (cols - 1 ))
163+ vertical = (LatticePoint ((i, j), lattice) => LatticePoint ((i + 1 , j), lattice)
164+ for i in 1 : rows, j in 1 : cols)
165+ return Iterators. flatten ((horizontal, vertical))
166+ end
167+ function nearest_neighbours (lattice:: FiniteHelix )
168+ rows = lattice. L
169+ cols = lattice. N ÷ lattice. L
170+ horizontal = (LatticePoint ((i, j), lattice) => LatticePoint ((i, j + 1 ), lattice)
171+ for i in 1 : rows, j in 1 : (cols - 1 ))
172+ vertical = (LatticePoint ((i, j), lattice) => LatticePoint ((i + 1 , j), lattice)
173+ for i in 1 : rows, j in 1 : cols if (i != rows && j != cols))
174+ return Iterators. flatten ((horizontal, vertical))
175+ end
77176function nearest_neighbours (lattice:: Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix} )
78177 V = vertices (lattice)
79178 neighbours = Pair{eltype (V),eltype (V)}[]
0 commit comments