Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 102 additions & 3 deletions src/lattices/squarelattice.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
"""
FiniteStrip(L::Int, N::Int)

An finite strip with `L` sites per rung and `N` sites per unit cell.
"""
struct FiniteStrip <: AbstractLattice{2}
L::Int
N::Int
function FiniteStrip(L::Integer, N::Integer=L)
N > 0 || throw(ArgumentError("period should be positive"))
mod(N, L) == 0 ||

Check warning on line 11 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L9-L11

Added lines #L9 - L11 were not covered by tests
throw(ArgumentError("period should be a multiple of circumference"))
return new(L, N)

Check warning on line 13 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L13

Added line #L13 was not covered by tests
end
end
FiniteLadder(N::Integer) = FiniteStrip(2, N)
Base.axes(strip::FiniteStrip) = (1:(strip.L), (1:(strip.N ÷ strip.L)))
Base.isfinite(::Type{FiniteStrip}) = true

Check warning on line 18 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L16-L18

Added lines #L16 - L18 were not covered by tests

"""
InfiniteStrip(L::Int, N::Int)

Expand All @@ -17,6 +36,27 @@
Base.axes(strip::InfiniteStrip) = (1:(strip.L), (-typemax(Int)):typemax(Int))
Base.isfinite(::Type{InfiniteStrip}) = false

"""
FiniteCylinder(L::Int, N::Int)

An finite cylinder with `L` sites per rung and `N` sites per unit cell.
"""
struct FiniteCylinder <: AbstractLattice{2}
L::Int
N::Int
function FiniteCylinder(L::Integer, N::Integer=L)
N > 0 || throw(ArgumentError("period should be positive"))
mod(N, L) == 0 ||

Check warning on line 49 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L47-L49

Added lines #L47 - L49 were not covered by tests
throw(ArgumentError("period should be a multiple of circumference"))
return new(L, N)

Check warning on line 51 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L51

Added line #L51 was not covered by tests
end
end

function Base.axes(cylinder::FiniteCylinder)
return ((-typemax(Int)):typemax(Int), (1:(cylinder.N ÷ cylinder.L)))

Check warning on line 56 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L55-L56

Added lines #L55 - L56 were not covered by tests
end
Base.isfinite(::Type{FiniteCylinder}) = true

Check warning on line 58 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L58

Added line #L58 was not covered by tests

"""
InfiniteCylinder(L::Int, N::Int)

Expand All @@ -36,6 +76,23 @@
Base.axes(::InfiniteCylinder) = ((-typemax(Int)):typemax(Int), (-typemax(Int)):typemax(Int))
Base.isfinite(::Type{InfiniteCylinder}) = false

"""
FiniteHelix(L::Integer, N::Integer)

An finite helix with `L` sites per rung and `N` sites per unit cell.
"""
struct FiniteHelix <: AbstractLattice{2}
L::Int
N::Int
function FiniteHelix(L::Integer, N::Integer=1)
N > 0 || error("period should be positive")
return new(L, N)

Check warning on line 89 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L87-L89

Added lines #L87 - L89 were not covered by tests
end
end

Base.axes(helix::FiniteHelix) = ((-typemax(Int)):typemax(Int), (1:(helix.N ÷ helix.L)))
Base.isfinite(::Type{FiniteHelix}) = true

Check warning on line 94 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L93-L94

Added lines #L93 - L94 were not covered by tests

"""
InfiniteHelix(L::Integer, N::Integer)

Expand All @@ -57,23 +114,65 @@

############################################################################################

function linearize_index(lattice::FiniteStrip, i::Int, j::Int)
@assert (1 <= i <= lattice.L && 1 <= j <= lattice.N ÷ lattice.L) "lattice point out of bounds"
return i + lattice.L * (j - 1)

Check warning on line 119 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L117-L119

Added lines #L117 - L119 were not covered by tests
end
function linearize_index(lattice::InfiniteStrip, i::Int, j::Int)
@assert i <= lattice.L "lattice point out of bounds"
@assert 1 <= i <= lattice.L "lattice point out of bounds"
return i + lattice.L * (j - 1)

Check warning on line 123 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L122-L123

Added lines #L122 - L123 were not covered by tests
end
function linearize_index(lattice::FiniteCylinder, i::Int, j::Int)
@assert 1 <= j <= lattice.N ÷ lattice.L "lattice point out of bounds"

Check warning on line 126 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L125-L126

Added lines #L125 - L126 were not covered by tests
return mod1(i, lattice.L) + lattice.L * (j - 1)
end
function linearize_index(lattice::InfiniteCylinder, i::Int, j::Int)
return mod1(i, lattice.L) + lattice.L * (j - 1)
end
function linearize_index(helix::FiniteHelix, i::Int, j::Int)
lin_ind = mod1(i, helix.L) + helix.L * (j + (i - 1) ÷ helix.L - 1)
@assert (1 <= j <= lattice.N ÷ lattice.L && 1 <= lin_ind <= helix.N) "lattice point out of bounds"
return mod1(i, helix.L) + helix.L * (j + (i - 1) ÷ helix.L - 1)

Check warning on line 135 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L132-L135

Added lines #L132 - L135 were not covered by tests
end
function linearize_index(helix::InfiniteHelix, i::Int, j::Int)
return mod1(i, helix.L) + helix.L * (j + (i - 1) ÷ helix.L - 1)
end

function vertices(lattice::Union{InfiniteStrip,InfiniteCylinder})
function vertices(lattice::Union{FiniteStrip,InfiniteStrip,FiniteCylinder,InfiniteCylinder})
return (LatticePoint((i, j), lattice) for i in 1:(lattice.L),
j in 1:(lattice.N ÷ lattice.L))
end
vertices(lattice::InfiniteHelix) = (LatticePoint((i, 1), lattice) for i in 1:(lattice.N))
function vertices(lattice::Union{FiniteHelix,InfiniteHelix})
return (LatticePoint((i, 1), lattice) for i in 1:(lattice.N))
end

function nearest_neighbours(lattice::FiniteStrip)
rows = lattice.L
cols = lattice.N ÷ lattice.L
horizontal = (LatticePoint((i, j), lattice) => LatticePoint((i, j + 1), lattice)

Check warning on line 152 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L149-L152

Added lines #L149 - L152 were not covered by tests
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)

Check warning on line 154 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L154

Added line #L154 was not covered by tests
for i in 1:(rows - 1), j in 1:cols)
return Iterators.flatten((horizontal, vertical))

Check warning on line 156 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L156

Added line #L156 was not covered by tests
end
function nearest_neighbours(lattice::FiniteCylinder)
rows = lattice.L
cols = lattice.N ÷ lattice.L
horizontal = (LatticePoint((i, j), lattice) => LatticePoint((i, j + 1), lattice)

Check warning on line 161 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L158-L161

Added lines #L158 - L161 were not covered by tests
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)

Check warning on line 163 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L163

Added line #L163 was not covered by tests
for i in 1:rows, j in 1:cols)
return Iterators.flatten((horizontal, vertical))

Check warning on line 165 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L165

Added line #L165 was not covered by tests
end
function nearest_neighbours(lattice::FiniteHelix)
rows = lattice.L
cols = lattice.N ÷ lattice.L
horizontal = (LatticePoint((i, j), lattice) => LatticePoint((i, j + 1), lattice)

Check warning on line 170 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L167-L170

Added lines #L167 - L170 were not covered by tests
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)

Check warning on line 172 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L172

Added line #L172 was not covered by tests
for i in 1:rows, j in 1:cols if (i != rows && j != cols))
return Iterators.flatten((horizontal, vertical))

Check warning on line 174 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L174

Added line #L174 was not covered by tests
end
function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix})
V = vertices(lattice)
neighbours = Pair{eltype(V),eltype(V)}[]
Expand Down
Loading