Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ jobs:

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="v1"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
id: format
Expand Down
1 change: 1 addition & 0 deletions src/MPSKitModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using LinearAlgebra: LinearAlgebra
export AbstractLattice
export InfiniteChain, FiniteChain
export InfiniteCylinder, InfiniteHelix, InfiniteStrip, InfiniteLadder
export FiniteCylinder, FiniteStrip
export HoneycombXC, HoneycombYC
export LatticePoint, linearize_index
export vertices, nearest_neighbours, next_nearest_neighbours, bipartition
Expand Down
23 changes: 17 additions & 6 deletions src/lattices/squarelattice.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
FiniteStrip(L::Int, N::Int)

An finite strip with `L` sites per rung and `N` sites per unit cell.
A finite strip with a width of `L` and a total number of `N` sites.

This representes an `L` by `N÷L` rectangular patch.
"""
struct FiniteStrip <: AbstractLattice{2}
L::Int
Expand Down Expand Up @@ -39,7 +41,7 @@
"""
FiniteCylinder(L::Int, N::Int)

An finite cylinder with `L` sites per rung and `N` sites per unit cell.
A cylinder with circumference `L` and `N` sites in total.
"""
struct FiniteCylinder <: AbstractLattice{2}
L::Int
Expand Down Expand Up @@ -79,7 +81,7 @@
"""
FiniteHelix(L::Integer, N::Integer)

An finite helix with `L` sites per rung and `N` sites per unit cell.
A finite helix with `L` sites per rung and `N` sites in total.
"""
struct FiniteHelix <: AbstractLattice{2}
L::Int
Expand Down Expand Up @@ -153,7 +155,7 @@
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)
for i in 1:(rows - 1), j in 1:cols)
return Iterators.flatten((horizontal, vertical))
return [horizontal..., vertical...]
end
function nearest_neighbours(lattice::FiniteCylinder)
rows = lattice.L
Expand All @@ -162,7 +164,7 @@
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)
for i in 1:rows, j in 1:cols)
return Iterators.flatten((horizontal, vertical))
return [horizontal..., vertical...]
end
function nearest_neighbours(lattice::FiniteHelix)
rows = lattice.L
Expand All @@ -171,7 +173,7 @@
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)
for i in 1:rows, j in 1:cols if (i != rows && j != cols))
return Iterators.flatten((horizontal, vertical))
return [horizontal..., vertical...]

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

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L176

Added line #L176 was not covered by tests
end
function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix})
V = vertices(lattice)
Expand All @@ -187,6 +189,15 @@
return neighbours
end

function next_nearest_neighbours(lattice::AbstractLattice{2})
diag1 = (i => i + (1, 1) for i in vertices(lattice) if checkbounds(Bool, lattice,
(i.coordinates .+
(1, 1))...))
diag2 = (i => i + (1, -1) for i in vertices(lattice) if checkbounds(Bool, lattice,
(i.coordinates .+
(1, -1))...))
return [diag1..., diag2...]
end
function next_nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,
InfiniteHelix})
V = vertices(lattice)
Expand Down
49 changes: 49 additions & 0 deletions test/lattices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,52 @@ end
@test_throws ArgumentError HoneycombYC(3)
@test_throws ArgumentError HoneycombYC(4, 6)
end

@testset "FiniteCylinder" begin
for L in 2:5
lattice = FiniteCylinder(L)
@test length(nearest_neighbours(lattice)) == L
@test length(next_nearest_neighbours(lattice)) == 0
for n in 2:4
lattice = FiniteCylinder(L, n * L)
V = vertices(lattice)
@test length(lattice) == length(V) == n * L
@test lattice[1, 1] == first(V)

NN = nearest_neighbours(lattice)
@test length(NN) == 2 * n * L - L
@test allunique(NN)

NNN = next_nearest_neighbours(lattice)
@test length(NNN) == 2 * (n - 1) * L

@test allunique(NNN)

@test_throws ArgumentError FiniteCylinder(L, n * L + 1)
end
end
end

@testset "FiniteStrip" begin
for L in 2:8, n in 2:4
N = n * L
lattice = FiniteStrip(L, N)
V = vertices(lattice)

# Test the number of vertices
@test length(lattice) == length(V) == N

# Test the first vertex
@test lattice[1, 1] == first(V)

# Test nearest neighbors
NN = nearest_neighbours(lattice)
@test length(NN) == 2N - L - n # coordination number 4 - edge effects
@test allunique(NN)

# Test next-nearest neighbors
NNN = next_nearest_neighbours(lattice)
@test length(NNN) == 2N - 2L - (2n - 2) # coordination number 4 - edge effects
@test allunique(NNN)
end
end
Loading