diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 5e0277a..2838990 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -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 diff --git a/src/MPSKitModels.jl b/src/MPSKitModels.jl index e8b05f3..64e8064 100644 --- a/src/MPSKitModels.jl +++ b/src/MPSKitModels.jl @@ -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 diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 52a85ae..1bdb7b5 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -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 @@ -39,7 +41,7 @@ Base.isfinite(::Type{InfiniteStrip}) = false """ 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 @@ -79,7 +81,7 @@ Base.isfinite(::Type{InfiniteCylinder}) = false """ 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 @@ -153,7 +155,7 @@ function nearest_neighbours(lattice::FiniteStrip) 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 @@ -162,7 +164,7 @@ function nearest_neighbours(lattice::FiniteCylinder) 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 @@ -171,7 +173,7 @@ function nearest_neighbours(lattice::FiniteHelix) 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...] end function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix}) V = vertices(lattice) @@ -187,6 +189,15 @@ function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,Infini 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) diff --git a/test/lattices.jl b/test/lattices.jl index a28c849..a467d3a 100644 --- a/test/lattices.jl +++ b/test/lattices.jl @@ -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