Skip to content

Commit

Permalink
Use new AbstractPSP and AbstractPS interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonReinhard committed Jun 21, 2024
1 parent 8cb6ecd commit 552995c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 68 deletions.
51 changes: 8 additions & 43 deletions src/phase_spaces/access.jl
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
import QEDbase:
is_particle,
is_anti_particle,
is_fermion,
is_boson,
is_incoming,
is_outgoing,
mass,
charge

# particle interface
@inline is_incoming(particle::ParticleStateful) = is_incoming(particle.dir)
@inline is_outgoing(particle::ParticleStateful) = is_outgoing(particle.dir)
@inline QEDbase.is_fermion(particle::ParticleStateful) =
QEDbase.is_fermion(particle.species)
@inline QEDbase.is_boson(particle::ParticleStateful) = QEDbase.is_boson(particle.species)
@inline QEDbase.is_particle(particle::ParticleStateful) =
QEDbase.is_particle(particle.species)
@inline QEDbase.is_anti_particle(particle::ParticleStateful) =
QEDbase.is_anti_particle(particle.species)
@inline QEDbase.mass(particle::ParticleStateful) = QEDbase.mass(particle.species)
@inline QEDbase.charge(particle::ParticleStateful) = QEDbase.charge(particle.species)

# accessors
particle_direction(part::ParticleStateful) = part.dir
particle_species(part::ParticleStateful) = part.species
momentum(part::ParticleStateful) = part.mom

"""
momenta(psp::PhaseSpacePoint, ::ParticleDirection)
Return a `Tuple` of all the particles' momenta for the given `ParticleDirection`.
"""
momenta(psp::PhaseSpacePoint, ::QEDbase.Incoming) = momentum.(psp.in_particles)
momenta(psp::PhaseSpacePoint, ::QEDbase.Outgoing) = momentum.(psp.out_particles)
# accessor interface particle stateful
QEDbase.particle_direction(part::ParticleStateful) = part.dir
QEDbase.particle_species(part::ParticleStateful) = part.species
QEDbase.momentum(part::ParticleStateful) = part.mom

# accessor interface phase space point
"""
Base.getindex(psp::PhaseSpacePoint, dir::Incoming, n::Int)
Expand All @@ -52,11 +22,6 @@ function Base.getindex(psp::PhaseSpacePoint, ::QEDbase.Outgoing, n::Int)
return psp.out_particles[n]
end

"""
momentum(psp::PhaseSpacePoint, dir::ParticleDirection, n::Int)
Returns the momentum of the `n`th particle in the given [`PhaseSpacePoint`](@ref) which has direction `dir`. If `n` is outside the valid range for this phase space point, a `BoundsError` is thrown.
"""
function momentum(psp::PhaseSpacePoint, dir::QEDbase.ParticleDirection, n::Int)
return psp[dir, n].mom
end
QEDbase.process(psp::PhaseSpacePoint) = psp.proc
QEDbase.model(psp::PhaseSpacePoint) = psp.model
QEDbase.phase_space_definition(psp::PhaseSpacePoint) = psp.ps_def
24 changes: 20 additions & 4 deletions src/phase_spaces/types.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
"""
SphericalCoordinateSystem <: AbstractCoordinateSystem
TBW
"""
struct SphericalCoordinateSystem <: QEDbase.AbstractCoordinateSystem end

"""
CenterOfMomentumFrame <: AbstractFrameOfReference
TBW
"""
struct CenterOfMomentumFrame <: QEDbase.AbstractFrameOfReference end

"""
ElectronRestFrame <: AbstractFrameOfReference
TBW
"""
struct ElectronRestFrame <: QEDbase.AbstractFrameOfReference end

"""
PhasespaceDefinition(coord_sys::QEDbase.AbstractCoordinateSystem, frame::QEDbase.AbstractFrameOfReference)
Convenient type to dispatch on coordiante systems and frames of reference.
Convenient type to dispatch on coordiante systems and frames of reference. Combines a `QEDbase.AbstractCoordinateSystem` with a `QEDbase.AbstractFrameOfReference`.
"""
struct PhasespaceDefinition{
CS<:QEDbase.AbstractCoordinateSystem,F<:QEDbase.AbstractFrameOfReference
Expand Down Expand Up @@ -41,7 +57,7 @@ struct ParticleStateful{
DIR<:QEDbase.ParticleDirection,
SPECIES<:QEDbase.AbstractParticleType,
ELEMENT<:QEDbase.AbstractFourMomentum,
} <: QEDbase.AbstractParticle
} <: QEDbase.AbstractParticleStateful{DIR,SPECIES,ELEMENT}
dir::DIR
species::SPECIES
mom::ELEMENT
Expand All @@ -65,7 +81,7 @@ Representation of a point in the phase space of a process. Contains the process
The legality of the combination of the given process and the incoming and outgoing particles is checked on construction. If the numbers of particles mismatch, the types of particles mismatch (note that order is important), or incoming particles have an `QEDbase.Outgoing` direction, an error is thrown.
```jldoctest
julia> using QEDprocesses; import QEDbase
julia> using QEDprocesses; using QEDbase; using QEDcore
julia> PhaseSpacePoint(
Compton(),
Expand Down Expand Up @@ -104,7 +120,7 @@ struct PhaseSpacePoint{
IN_PARTICLES<:Tuple{Vararg{ParticleStateful}},
OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}},
ELEMENT<:QEDbase.AbstractFourMomentum,
}
} <: QEDbase.AbstractPhaseSpacePoint{PROC,MODEL,PSDEF,IN_PARTICLES,OUT_PARTICLES,ELEMENT}
proc::PROC
model::MODEL
ps_def::PSDEF
Expand Down
26 changes: 13 additions & 13 deletions test/phase_spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ end
@test QEDbase.is_particle(particle_stateful) == QEDbase.is_particle(species)
@test QEDbase.is_anti_particle(particle_stateful) ==
QEDbase.is_anti_particle(species)
@test is_incoming(particle_stateful) == is_incoming(dir)
@test is_outgoing(particle_stateful) == is_outgoing(dir)
@test QEDbase.is_incoming(particle_stateful) == QEDbase.is_incoming(dir)
@test QEDbase.is_outgoing(particle_stateful) == QEDbase.is_outgoing(dir)
@test QEDbase.mass(particle_stateful) == QEDbase.mass(species)
@test QEDbase.charge(particle_stateful) == QEDbase.charge(species)

# accessors
@test particle_stateful.dir == dir
@test particle_direction(particle_stateful) == particle_stateful.dir
@test QEDbase.particle_direction(particle_stateful) == particle_stateful.dir
@test particle_stateful.species == species
@test particle_species(particle_stateful) == particle_stateful.species
@test QEDbase.particle_species(particle_stateful) == particle_stateful.species
@test particle_stateful.mom == mom
@test momentum(particle_stateful) == mom
@test QEDbase.momentum(particle_stateful) == mom

# printing
print(BUF, particle_stateful)
Expand Down Expand Up @@ -92,10 +92,10 @@ end
) isa RegexMatch

@testset "Accessor" begin
@test momentum(psp, QEDbase.Incoming(), 1) == in_el.mom
@test momentum(psp, QEDbase.Incoming(), 2) == in_ph.mom
@test momentum(psp, QEDbase.Outgoing(), 1) == out_el.mom
@test momentum(psp, QEDbase.Outgoing(), 2) == out_ph.mom
@test QEDbase.momentum(psp, QEDbase.Incoming(), 1) == in_el.mom
@test QEDbase.momentum(psp, QEDbase.Incoming(), 2) == in_ph.mom
@test QEDbase.momentum(psp, QEDbase.Outgoing(), 1) == out_el.mom
@test QEDbase.momentum(psp, QEDbase.Outgoing(), 2) == out_ph.mom

@test psp[QEDbase.Incoming(), 1] == in_el
@test psp[QEDbase.Incoming(), 2] == in_ph
Expand Down Expand Up @@ -139,10 +139,10 @@ end
)
end

@test_throws BoundsError momentum(psp, QEDbase.Incoming(), -1)
@test_throws BoundsError momentum(psp, QEDbase.Outgoing(), -1)
@test_throws BoundsError momentum(psp, QEDbase.Incoming(), 4)
@test_throws BoundsError momentum(psp, QEDbase.Outgoing(), 4)
@test_throws BoundsError QEDbase.momentum(psp, QEDbase.Incoming(), -1)
@test_throws BoundsError QEDbase.momentum(psp, QEDbase.Outgoing(), -1)
@test_throws BoundsError QEDbase.momentum(psp, QEDbase.Incoming(), 4)
@test_throws BoundsError QEDbase.momentum(psp, QEDbase.Outgoing(), 4)

@test_throws BoundsError psp[QEDbase.Incoming(), -1]
@test_throws BoundsError psp[QEDbase.Outgoing(), -1]
Expand Down
16 changes: 8 additions & 8 deletions test/test_implementation/test_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,30 @@ struct TestPhasespaceDef_FAIL <: QEDbase.AbstractPhasespaceDefinition end
# dummy implementation of the process interface

function QEDbase._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel})
return _groundtruth_incident_flux(momenta(in_psp, QEDbase.Incoming()))
return _groundtruth_incident_flux(QEDbase.momenta(in_psp, QEDbase.Incoming()))
end

function QEDbase._averaging_norm(proc::TestProcess)
return _groundtruth_averaging_norm(proc)
end

function QEDbase._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel})
in_ps = momenta(psp, QEDbase.Incoming())
out_ps = momenta(psp, QEDbase.Outgoing())
in_ps = QEDbase.momenta(psp, QEDbase.Incoming())
out_ps = QEDbase.momenta(psp, QEDbase.Outgoing())
return _groundtruth_matrix_element(in_ps, out_ps)
end

function QEDbase._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel})
in_ps = momenta(psp, QEDbase.Incoming())
out_ps = momenta(psp, QEDbase.Outgoing())
in_ps = QEDbase.momenta(psp, QEDbase.Incoming())
out_ps = QEDbase.momenta(psp, QEDbase.Outgoing())
return _groundtruth_is_in_phasespace(in_ps, out_ps)
end

function QEDbase._phase_space_factor(
psp::PhaseSpacePoint{<:TestProcess,TestModel,TestPhasespaceDef}
)
in_ps = momenta(psp, QEDbase.Incoming())
out_ps = momenta(psp, QEDbase.Outgoing())
in_ps = QEDbase.momenta(psp, QEDbase.Incoming())
out_ps = QEDbase.momenta(psp, QEDbase.Outgoing())
return _groundtruth_phase_space_factor(in_ps, out_ps)
end

Expand All @@ -127,5 +127,5 @@ end
function QEDbase._total_probability(
in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef}
)
return _groundtruth_total_probability(momenta(in_psp, QEDbase.Incoming()))
return _groundtruth_total_probability(QEDbase.momenta(in_psp, QEDbase.Incoming()))
end

0 comments on commit 552995c

Please sign in to comment.