From 552995c9fa29aac5c1f13029d1960c677dfd8c32 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Fri, 21 Jun 2024 12:03:52 +0200 Subject: [PATCH] Use new AbstractPSP and AbstractPS interfaces --- src/phase_spaces/access.jl | 51 ++++-------------------- src/phase_spaces/types.jl | 24 +++++++++-- test/phase_spaces.jl | 26 ++++++------ test/test_implementation/test_process.jl | 16 ++++---- 4 files changed, 49 insertions(+), 68 deletions(-) diff --git a/src/phase_spaces/access.jl b/src/phase_spaces/access.jl index a8540aa..7a936cf 100644 --- a/src/phase_spaces/access.jl +++ b/src/phase_spaces/access.jl @@ -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) @@ -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 diff --git a/src/phase_spaces/types.jl b/src/phase_spaces/types.jl index 610b80e..43d2178 100644 --- a/src/phase_spaces/types.jl +++ b/src/phase_spaces/types.jl @@ -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 @@ -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 @@ -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(), @@ -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 diff --git a/test/phase_spaces.jl b/test/phase_spaces.jl index 3716386..7116a4b 100644 --- a/test/phase_spaces.jl +++ b/test/phase_spaces.jl @@ -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) @@ -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 @@ -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] diff --git a/test/test_implementation/test_process.jl b/test/test_implementation/test_process.jl index 0c03dcc..0de4ae3 100644 --- a/test/test_implementation/test_process.jl +++ b/test/test_implementation/test_process.jl @@ -79,7 +79,7 @@ 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) @@ -87,22 +87,22 @@ function QEDbase._averaging_norm(proc::TestProcess) 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 @@ -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