Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number of spins or pols #63

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/QEDbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export AbstractDefinitePolarization, AbstractIndefinitePolarization
export PolarizationX, PolX, PolarizationY, PolY, AllPolarization, AllPol
export AbstractDefiniteSpin, AbstractIndefiniteSpin
export SpinUp, SpinDown, AllSpin
export number_of_spin_pol

using StaticArrays
using LinearAlgebra
Expand Down
12 changes: 12 additions & 0 deletions src/particles/particle_spin_pol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,15 @@ y-polarized
struct PolarizationY <: AbstractDefinitePolarization end
const PolY = PolarizationY
Base.show(io::IO, ::MIME"text/plain", ::PolY) = print(io, "y-polarized")

"""
number_of_spin_pol(spin_or_pol)

Return the number of spins or polarizations respresented by `spin_or_pol`, e.g. `number_of_spin_pol(SpinUp()) == 1`.

"""
function number_of_spin_pol end
number_of_spin_pol(::AbstractDefinitePolarization) = 1
number_of_spin_pol(::AbstractDefiniteSpin) = 1
number_of_spin_pol(::AbstractIndefinitePolarization) = 2
number_of_spin_pol(::AbstractIndefiniteSpin) = 2
AntonReinhard marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions test/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ test_broadcast(x::AbstractSpinOrPolarization) = x
end
end

@testset "number of spins or pols" begin
@testset "single" begin
@testset "$spin_or_pol" for spin_or_pol in (SpinUp(), SpinDown(), PolX(), PolY())
@test number_of_spin_pol(spin_or_pol) == 1
end
end
@testset "multiple" begin
@testset "$spin_or_pol" for spin_or_pol in (AllSpin(), AllPol())
@test number_of_spin_pol(spin_or_pol) == 2
end
end
end

@testset "fermion likes" begin
@testset "fermion" begin
struct TestFermion <: Fermion end
Expand Down
Loading