From ffc371584f394145fe0301691ee9660e2314d18b Mon Sep 17 00:00:00 2001 From: Pablo San-Jose Date: Thu, 12 Oct 2023 17:52:41 +0200 Subject: [PATCH] allow empty sublats --- src/types.jl | 6 ------ test/test_greenfunction.jl | 5 ++++- test/test_lattice.jl | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/types.jl b/src/types.jl index f70d9fe7..976f4c09 100644 --- a/src/types.jl +++ b/src/types.jl @@ -5,10 +5,6 @@ struct Sublat{T<:AbstractFloat,E} sites::Vector{SVector{E,T}} name::Symbol - function Sublat{T,E}(sites, name) where {T<:AbstractFloat,E} - isempty(sites) && argerror("Sublattices cannot be empty") - return new(sites, name) - end end struct Unitcell{T<:AbstractFloat,E} @@ -41,8 +37,6 @@ end #region ## Constructors ## -Sublat(sites::Vector{SVector{E,T}}, name::Symbol) where {T,E} = Sublat{T,E}(sites, name) - Bravais(::Type{T}, E, m) where {T} = Bravais(T, Val(E), m) Bravais(::Type{T}, ::Val{E}, m::Tuple{}) where {T,E} = Bravais{T,E,0}(sanitize_Matrix(T, E, ())) diff --git a/test/test_greenfunction.jl b/test/test_greenfunction.jl index e273b00c..d34156ab 100644 --- a/test/test_greenfunction.jl +++ b/test/test_greenfunction.jl @@ -22,7 +22,7 @@ function testgreen(h, s; kw...) return nothing end -@testset "bare greenfunctions" begin +@testset "basic greenfunctions" begin h0 = LP.honeycomb() |> hamiltonian(hopping(SA[0 1; 1 0]), orbitals = 2) |> supercell(region = RP.circle(10)) s0 = GS.SparseLU() h1 = LP.square() |> hamiltonian(@onsite((; o = 1) -> o*I) + hopping(SA[0 1; 1 0]), orbitals = 2) |> supercell((1,0), region = r -> abs(r[2]) < 2) @@ -66,6 +66,9 @@ end testgreen(oh, s) end end + # contacts that don't include all sublattices + h = lattice(sublat(0, name = :L), sublat(1, name = :R)) |> hamiltonian + @test h |> attach(onsite(ω->1), sublats = :L) |> greenfunction isa GreenFunction end @testset "greenfunction KPM" begin diff --git a/test/test_lattice.jl b/test/test_lattice.jl index 261c7732..627709ef 100644 --- a/test/test_lattice.jl +++ b/test/test_lattice.jl @@ -31,7 +31,7 @@ end end @test sublat((3,)) isa Sublat{Float64,1} @test sublat(()) isa Sublat{Float64,0} - @test_throws ArgumentError sublat(SVector{3,Float64}[]) + @test sublat(SVector{3,Float64}[]) isa Sublat{Float64,3} end @testset "lattice construction" begin