Skip to content

Commit

Permalink
Add dimension for Momenta and Internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergu committed Dec 23, 2024
1 parent 13caaed commit b1ebfd2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/DegreesOfFreedom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ using DataStructures: OrderedDict
using Printf: @printf, @sprintf
using SparseArrays: SparseMatrixCSC, nnz
using StaticArrays: SVector
using ..QuantumLattices: add!, decompose, dimension
using ..QuantumLattices: add!, decompose
using ..QuantumOperators: ID, LinearTransformation, Operator, OperatorIndex, OperatorPack, Operators, QuantumOperator, scalartype, valuetolatextext
using ..Spatials: Bond, Point
using ..Toolkit: atol, efficientoperations, rtol, CompositeDict, Float, VectorSpace, VectorSpaceCartesian, VectorSpaceDirectProducted, VectorSpaceDirectSummed, VectorSpaceStyle, concatenate, fulltype, parametertype, rawtype, reparameter, tostr

import LaTeXStrings: latexstring
import ..QuantumLattices: , , expand, expand!, id, ishermitian, kind, permute, rank, reset!, update!, value
import ..QuantumLattices: , , dimension, expand, expand!, id, ishermitian, kind, permute, rank, reset!, update!, value
import ..QuantumOperators: idtype, operatortype, script
import ..Spatials: icoordinate, nneighbor, rcoordinate
import ..Toolkit: contentnames, getcontent, parameternames, shape
Expand Down Expand Up @@ -106,6 +106,13 @@ Internal space at a single point.
"""
abstract type Internal{I<:InternalIndex} <: VectorSpace{I} end

"""
dimension(i::Internal) -> Int
Get the dimension of an internal space at a single point.
"""
@inline dimension(i::Internal) = length(i)

"""
SimpleInternal{I<:SimpleInternalIndex} <: Internal{I}
Expand Down
3 changes: 2 additions & 1 deletion src/QuantumNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ abstract type RepresentationSpace{QN<:AbelianQuantumNumber} <: VectorSpace{QN} e
Get the degenerate dimension of the ith Abelian quantum number contained in a representation space.
"""
@inline dimension(rs::RepresentationSpace, i::Integer) = dimension(rs, CartesianIndex(i, rs))
@inline dimension(rs::RepresentationSpace, i::Integer) = dimension(rs, CartesianIndex(i, rs))

"""
range(rs::RepresentationSpace, i::Integer)
Expand Down Expand Up @@ -423,6 +423,7 @@ struct Momenta{P<:𝕂} <: RepresentationSpace{P} end
@inline Base.:(==)(ms₁::Momenta, ms₂::Momenta) = periods(eltype(ms₁))==periods(eltype(ms₂))
@inline Base.isequal(ms₁::Momenta, ms₂::Momenta) = isequal(periods(eltype(ms₁)), periods(eltype(ms₂)))
@inline Base.show(io::IO, ms::Momenta) = @printf io "Momenta(%s)" eltype(ms)
@inline dimension(m::Momenta) = length(m)

"""
regularize!(quantumnumbers::Vector{<:AbelianQuantumNumber}, dimensions::Vector{Int}; check::Bool=false) -> Tuple{typeof(quantumnumbers), typeof(dimensions), Vector{Int}}
Expand Down
5 changes: 4 additions & 1 deletion test/DegreesOfFreedom.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LaTeXStrings: latexstring
using LinearAlgebra: dot, ishermitian
using Printf: @printf
using QuantumLattices: , , expand, kind, rank, reset!, update!, value
using QuantumLattices: , , dimension, expand, kind, rank, reset!, update!, value
using QuantumLattices.DegreesOfFreedom
using QuantumLattices.QuantumOperators: ID, LaTeX, Operator, OperatorIndex, Operators, id, latexformat, sequence
using QuantumLattices.Spatials: Bond, Point, decompose, icoordinate, nneighbor, rcoordinate
Expand Down Expand Up @@ -76,6 +76,7 @@ end

@testset "SimpleInternal" begin
it = DFock(2)
@test dimension(it) == 2
@test string(it) == "DFock(nnambu=2)"
@test collect(it) == [𝕕(1), 𝕕(2)]
@test statistics(it) == statistics(typeof(it)) == :f
Expand All @@ -88,6 +89,7 @@ end
it₁, it₂ = DFock(2), DFock(3)

ci = InternalSum(it₁, it₂)
@test dimension(ci) == 5
@test eltype(ci) == eltype(typeof(ci)) == DID{Int}
@test rank(ci) == rank(typeof(ci)) == 2
@test string(ci) == "DFock(nnambu=2) ⊕ DFock(nnambu=3)"
Expand All @@ -100,6 +102,7 @@ end
@test filter(𝕕(1), typeof(ci)) == filter(DID, typeof(ci)) == typeof(ci)

ci = InternalProd(it₁, it₂)
@test dimension(ci) == 6
@test eltype(ci) == eltype(typeof(ci)) == InternalIndexProd{Tuple{DID{Int}, DID{Int}}}
@test rank(ci) == rank(typeof(ci)) == 2
@test string(ci) == "DFock(nnambu=2) ⊗ DFock(nnambu=3)"
Expand Down
1 change: 1 addition & 0 deletions test/QuantumNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ end
@test momenta[convert(CartesianIndex, momentum, momenta)] == momentum
end
@test string(momenta) == "Momenta(𝕂²{2, 3})"
@test dimension(momenta) == 6
end

@testset "regularize" begin
Expand Down

0 comments on commit b1ebfd2

Please sign in to comment.