-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsnakepattern.jl
More file actions
65 lines (52 loc) · 1.9 KB
/
snakepattern.jl
File metadata and controls
65 lines (52 loc) · 1.9 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
SnakePattern(lattice, pattern)
Represents a given lattice with a linear order that is provided by `pattern`.
"""
struct SnakePattern{N,G<:AbstractLattice{N},F} <: AbstractLattice{N}
lattice::G
pattern::F
end
SnakePattern(lattice) = SnakePattern(lattice, identity)
Base.axes(lattice::SnakePattern) = axes(lattice.lattice)
Base.isfinite(::Type{SnakePattern{N,G}}) where {N,G} = isfinite(G)
function linearize_index(snake::SnakePattern, i...)
return snake.pattern(linearize_index(snake.lattice, i...))
end
function vertices(snake::SnakePattern)
return map(x -> LatticePoint(x.coordinates, snake), vertices(snake.lattice))
end
function nearest_neighbours(snake::SnakePattern)
return map(nearest_neighbours(snake.lattice)) do (x, y)
return LatticePoint(x.coordinates, snake), LatticePoint(y.coordinates, snake)
end
end
bipartition(snake::SnakePattern) = bipartition(snake.lattice)
"""
backandforth_pattern(cylinder)
pattern that alternates directions between different rungs of a cylinder
"""
function backandforth_pattern(cylinder::InfiniteCylinder)
L = cylinder.L
N = cylinder.N
iseven(cylinder.N) || error("backandforth only defined for even period")
inds = Iterators.flatten((1:L, reverse((L + 1):(2L))) .+ (L * (i - 1)) for i in 1:2:N)
return pattern(i::Integer) = inds[i]
end
"""
frontandback_pattern(cylinder)
pattern that alternates between a site on the first half of a rung and a site on the second
half of a rung.
"""
function frontandback_pattern(cylinder::InfiniteCylinder)
L = cylinder.L
N = cylinder.N
if iseven(L)
edge = L / 2
rung = Iterators.flatten(zip(1:edge, (edge + 1):L))
else
edge = (L + 1) / 2
rung = Iterators.flatten((Iterators.flatten(zip(1:edge, (edge + 1):L)), edge))
end
inds = Iterators.flatten((rung .+ (L * (i - 1)) for i in 1:N))
return pattern(i::Integer) = inds[i]
end