From 37d6125afba125f7ef55022b9a81385f2811ddf6 Mon Sep 17 00:00:00 2001 From: AntonReinhard Date: Fri, 5 Jul 2024 14:13:15 +0200 Subject: [PATCH] Add convenience constructors for particle statefuls --- src/phase_spaces/create.jl | 19 ++++++++++++++++++- test/phase_spaces.jl | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/phase_spaces/create.jl b/src/phase_spaces/create.jl index 4364e5a..bb1d4d4 100644 --- a/src/phase_spaces/create.jl +++ b/src/phase_spaces/create.jl @@ -1,5 +1,22 @@ -# PSP constructors from particle statefuls +""" + ParticleStateful{DIR, SPECIES}(mom::AbstractFourMomentum) + ParticleStateful{DIR, SPECIES, EL}(mom::EL) + +Construct a [`ParticleStateful`](@ref) from the given momentum on a fully or partially specified type. +""" +@inline function ParticleStateful{DIR,SPECIES}( + mom::AbstractFourMomentum +) where {DIR<:ParticleDirection,SPECIES<:AbstractParticleType} + return ParticleStateful(DIR(), SPECIES(), mom) +end + +@inline function ParticleStateful{DIR,SPECIES,EL}( + mom::EL +) where {DIR<:ParticleDirection,SPECIES<:AbstractParticleType,EL<:AbstractFourMomentum} + return ParticleStateful(DIR(), SPECIES(), mom) +end +# PSP constructors from particle statefuls """ InPhaseSpacePoint( proc::AbstractProcessDefinition, diff --git a/test/phase_spaces.jl b/test/phase_spaces.jl index 6ef7a06..e26a389 100644 --- a/test/phase_spaces.jl +++ b/test/phase_spaces.jl @@ -23,6 +23,9 @@ end mom = rand(RNG, SFourMomentum) particle_stateful = ParticleStateful(dir, species, mom) + @test particle_stateful == ParticleStateful{typeof(dir),typeof(species)}(mom) + @test particle_stateful == + ParticleStateful{typeof(dir),typeof(species),typeof(mom)}(mom) # particle interface @test is_fermion(particle_stateful) == is_fermion(species)