From 5835d5e0b3c6353092194d6015501fa904243fbe Mon Sep 17 00:00:00 2001 From: Adwait-Naravane Date: Mon, 9 Jun 2025 16:52:06 +0200 Subject: [PATCH 1/3] Add Honeycomb XC and Honeycomb YC crystals --- src/exports.jl | 4 +- src/lattices/lattices.jl | 113 +++++++++++++++++++++++++++++++++++++ test/base/test_lattices.jl | 14 +++++ 3 files changed, 130 insertions(+), 1 deletion(-) diff --git a/src/exports.jl b/src/exports.jl index 749a73c..bbe4f71 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -43,7 +43,9 @@ export LatticeBond, square_lattice, triangular_lattice, - + Honeycomb_XC, + Honeycomb_YC, + Honeycomb_sideways, # solvers TimeDependentSum, dmrg_x, diff --git a/src/lattices/lattices.jl b/src/lattices/lattices.jl index 8e1c973..0743638 100644 --- a/src/lattices/lattices.jl +++ b/src/lattices/lattices.jl @@ -138,3 +138,116 @@ function triangular_lattice(Nx::Int, Ny::Int; yperiodic=false)::Lattice end return latt end + +""" +Honeycomb_XC: if your 2D cylinder has a zigzag edge. +Open boundaries, but can be made periodic in the y direction +by specifying the keyword argument `yperiodic=true`. +""" +function Honeycomb_XC(Nx::Int, Ny::Int; kwargs...)::Lattice + mod(Ny, 4) == 0 || + throw(ArgumentError("Ny must be a multiple of 4 for Honeycomb_XC lattice.")) + yperiodic = get(kwargs, :yperiodic, false) + yperiodic = yperiodic && (Ny > 2) && (Ny % 2 == 0) + N = Nx * Ny + if (Ny % 2 == 0) + Nbond = N + (yperiodic ? 0 : -Nx) + (Nx - 1) * Ny / 2 + end + if (Ny % 2 == 1) + if (Nx % 2 == 1) + Nbond = N + (yperiodic ? 0 : -Nx) + (2 * floor(Ny / 2) + 1) * (Nx + 1) / 2 + end + if (Nx % 2 == 0) + Nbond = + N + + (yperiodic ? 0 : -Nx) + + (Nx / 2) * (floor(Ny / 2) + 1) + + (Nx / 2 - 1) * (floor(Ny / 2)) + end + end + Nbond = floor(Int64, Nbond) + latt = Lattice(undef, Nbond) + b = 0 + + for n in 1:N + x = div(n - 1, Ny) + 1 + y = mod(n - 1, Ny) + 1 + + if x < Nx + if ((x % 2 == 1) && (y % 2 == 1)) || ((x % 2 == 0) && (y % 2 == 0)) + latt[b += 1] = LatticeBond(n, n + Ny, x, y, x + 1, y) + end + end + + if Ny > 1 + if y < Ny + if ((x % 2 == 0) && (y % 2 == 0)) || ((x % 2 == 1) && (y % 2 == 1)) + latt[b += 1] = LatticeBond(n, n + 1, x, y, x, y + 1) + end + if ((x % 2 == 1) && (y % 2 == 0)) || ((x % 2 == 0) && (y % 2 == 1)) + latt[b += 1] = LatticeBond(n, n + 1, x, y, x, y + 1) + end + end + if yperiodic && y == 1 + if x % 2 == 1 + latt[b += 1] = LatticeBond(n, n + Ny - 1, x, y, x, y + Ny - 1) + end + if x % 2 == 0 + latt[b += 1] = LatticeBond(n, n + Ny - 1, x, y, x, y + Ny - 1) + end + end + end + end + return latt +end + +""" +Honeycomb_YC: if your cylinder has a armchair edge. +Open boundaries, but can be made periodic in the y direction +by specifying the keyword argument `yperiodic=true`. +""" +function Honeycomb_YC(Nx::Int, Ny::Int; kwargs...)::Lattice + mod(Ny, 4) == 0 || + throw(ArgumentError("Ny must be a multiple of 4 for Honeycomb_YC lattice.")) + Nx < 4 || throw(ArgumentError("Nx must be at least 4 for Honeycomb_YC lattice.")) + yperiodic = get(kwargs, :yperiodic, false) + yperiodic = yperiodic && (Ny > 2) && (Ny % 2 == 0) + N = Nx * Ny + Nbond = + N - Ny + + ((Nx % 2 == 0) ? Nx * (Ny - 1) / 2 : (Nx - 1) * (Ny - 1) / 2 + floor(Nx / 2)) + + (yperiodic ? floor(Nx / 2) : 0) + + Nbond = floor(Int64, Nbond) + latt = Lattice(undef, Nbond) + b = 0 + + for n in 1:N + x = div(n - 1, Ny) + 1 + y = mod(n - 1, Ny) + 1 + + if x < Nx + if ((x % 2 == 1) && (y % 2 == 1)) || ((x % 2 == 0) && (y % 2 == 0)) + latt[b += 1] = LatticeBond(n, n + Ny, x, y, x + 1, y) + end + if ((x % 2 == 0) && (y % 2 == 1)) || ((x % 2 == 1) && (y % 2 == 0)) + latt[b += 1] = LatticeBond(n, n + Ny, x, y, x + 1, y) + end + end + + if Ny > 1 + if y < Ny + if ((x % 2 == 0) && (y % 2 == 0)) || ((x % 2 == 1) && (y % 2 == 1)) + latt[b += 1] = LatticeBond(n, n + 1, x, y, x, y + 1) + end + end + if yperiodic && y == 1 + if ((x % 2 == 0)) + latt[b += 1] = LatticeBond(n, n + Ny - 1, x, y, x, y + Ny - 1) + end + end + end + end + + return latt +end diff --git a/test/base/test_lattices.jl b/test/base/test_lattices.jl index 0a86ae7..021f490 100644 --- a/test/base/test_lattices.jl +++ b/test/base/test_lattices.jl @@ -12,3 +12,17 @@ end tL = triangular_lattice(3, 4; yperiodic=true) @test length(tL) == 28 # inc. periodic vertical bonds end + +@testset "Honeycomb XC lattice" begin + hL = Honeycomb_XC(3, 4) + @test length(hL) == 13 + hL = Honeycomb_XC(3, 4; yperiodic=true) + @test length(hL) == 16 +end + +@testset "Honeycomb YC lattice" begin + hL = Honeycomb_YC(4, 4) + @test length(hL) == 18 + hL = Honeycomb_YC(4, 4; yperiodic=true) + @test length(hL) == 20 +end From 7a2f54dbd9d46eaaeffbb29b714387d081107a57 Mon Sep 17 00:00:00 2001 From: Adwait-Naravane Date: Mon, 9 Jun 2025 16:52:46 +0200 Subject: [PATCH 2/3] Remove unused scheme --- src/exports.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exports.jl b/src/exports.jl index bbe4f71..e6c6b1a 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -45,7 +45,7 @@ export triangular_lattice, Honeycomb_XC, Honeycomb_YC, - Honeycomb_sideways, + # solvers TimeDependentSum, dmrg_x, From 08baa4dfcc87890237a31dc11954298647775f78 Mon Sep 17 00:00:00 2001 From: Adwait-Naravane Date: Mon, 9 Jun 2025 16:57:58 +0200 Subject: [PATCH 3/3] Fix errors for Honeycomb_YC --- src/exports.jl | 2 +- src/lattices/lattices.jl | 2 +- test/base/test_lattices.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exports.jl b/src/exports.jl index e6c6b1a..af3771d 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -45,7 +45,7 @@ export triangular_lattice, Honeycomb_XC, Honeycomb_YC, - + # solvers TimeDependentSum, dmrg_x, diff --git a/src/lattices/lattices.jl b/src/lattices/lattices.jl index 0743638..0e47b53 100644 --- a/src/lattices/lattices.jl +++ b/src/lattices/lattices.jl @@ -209,7 +209,7 @@ by specifying the keyword argument `yperiodic=true`. function Honeycomb_YC(Nx::Int, Ny::Int; kwargs...)::Lattice mod(Ny, 4) == 0 || throw(ArgumentError("Ny must be a multiple of 4 for Honeycomb_YC lattice.")) - Nx < 4 || throw(ArgumentError("Nx must be at least 4 for Honeycomb_YC lattice.")) + Nx > 3 || throw(ArgumentError("Nx must be at least 4 for Honeycomb_YC lattice.")) yperiodic = get(kwargs, :yperiodic, false) yperiodic = yperiodic && (Ny > 2) && (Ny % 2 == 0) N = Nx * Ny diff --git a/test/base/test_lattices.jl b/test/base/test_lattices.jl index 021f490..44043a7 100644 --- a/test/base/test_lattices.jl +++ b/test/base/test_lattices.jl @@ -1,4 +1,4 @@ -using ITensors, Test +using ITensors, Test, ITensorMPS @test LatticeBond(1, 2) == LatticeBond(1, 2, 0.0, 0.0, 0.0, 0.0, "") @testset "Square lattice" begin