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

Remove PhasespaceDefinition in favor of PhaseSpaceLayout #94

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/phase_spaces/access.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end

QEDbase.process(psp::PhaseSpacePoint) = psp.proc
QEDbase.model(psp::PhaseSpacePoint) = psp.model
QEDbase.phase_space_definition(psp::PhaseSpacePoint) = psp.ps_def
QEDbase.phase_space_layout(psp::PhaseSpacePoint) = psp.psl

QEDbase.particles(psp::PhaseSpacePoint, ::Incoming) = psp.in_particles
QEDbase.particles(psp::PhaseSpacePoint, ::Outgoing) = psp.out_particles
58 changes: 29 additions & 29 deletions src/phase_spaces/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,44 @@ end
# PSP constructors from particle statefuls
"""
InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
psl::AbstractPhaseSpaceLayout,
in_ps::Tuple{ParticleStateful},
)

Construct a [`PhaseSpacePoint`](@ref) with only input particles from [`ParticleStateful`](@ref)s. The result will be `<: InPhaseSpacePoint` but **not** `<: OutPhaseSpacePoint`.
"""
function InPhaseSpacePoint(
proc::PROC, model::MODEL, ps_def::PSDEF, in_ps::IN_PARTICLES
proc::PROC, model::MODEL, psl::PSL, in_ps::IN_PARTICLES
) where {
PROC<:AbstractProcessDefinition,
MODEL<:AbstractModelDefinition,
PSDEF<:AbstractPhasespaceDefinition,
PSL<:AbstractPhaseSpaceLayout,
IN_PARTICLES<:Tuple{Vararg{ParticleStateful}},
}
return PhaseSpacePoint(proc, model, ps_def, in_ps, ())
return PhaseSpacePoint(proc, model, psl, in_ps, ())
end

"""
OutPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
psl::AbstractPhaseSpaceLayout,
out_ps::Tuple{ParticleStateful},
)

Construct a [`PhaseSpacePoint`](@ref) with only output particles from [`ParticleStateful`](@ref)s. The result will be `<: OutPhaseSpacePoint` but **not** `<: InPhaseSpacePoint`.
"""
function OutPhaseSpacePoint(
proc::PROC, model::MODEL, ps_def::PSDEF, out_ps::OUT_PARTICLES
proc::PROC, model::MODEL, psl::PSL, out_ps::OUT_PARTICLES
) where {
PROC<:AbstractProcessDefinition,
MODEL<:AbstractModelDefinition,
PSDEF<:AbstractPhasespaceDefinition,
PSL<:AbstractPhaseSpaceLayout,
OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}},
}
return PhaseSpacePoint(proc, model, ps_def, (), out_ps)
return PhaseSpacePoint(proc, model, psl, (), out_ps)
end

# PSP constructors from momenta
Expand All @@ -65,7 +65,7 @@ end
PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_momenta::NTuple{N,AbstractFourMomentum},
out_momenta::NTuple{M,AbstractFourMomentum},
)
Expand All @@ -75,21 +75,21 @@ Construct the phase space point from given momenta of incoming and outgoing part
function PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_momenta::NTuple{N,ELEMENT},
out_momenta::NTuple{M,ELEMENT},
) where {N,M,ELEMENT<:AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_momenta, Incoming())
out_particles = _build_particle_statefuls(proc, out_momenta, Outgoing())

return PhaseSpacePoint(proc, model, ps_def, in_particles, out_particles)
return PhaseSpacePoint(proc, model, psl, in_particles, out_particles)
end

"""
InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_momenta::NTuple{N,AbstractFourMomentum},
)

Expand All @@ -98,19 +98,19 @@ Construct a [`PhaseSpacePoint`](@ref) with only input particles from given momen
function InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_momenta::NTuple{N,ELEMENT},
) where {N,ELEMENT<:AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_momenta, Incoming())

return PhaseSpacePoint(proc, model, ps_def, in_particles, ())
return PhaseSpacePoint(proc, model, psl, in_particles, ())
end

"""
OutPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
out_momenta::NTuple{N,AbstractFourMomentum},
)

Expand All @@ -119,12 +119,12 @@ Construct a [`PhaseSpacePoint`](@ref) with only output particles from given mome
function OutPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
out_momenta::NTuple{N,ELEMENT},
) where {N,ELEMENT<:AbstractFourMomentum}
out_particles = _build_particle_statefuls(proc, out_momenta, Outgoing())

return PhaseSpacePoint(proc, model, ps_def, (), out_particles)
return PhaseSpacePoint(proc, model, psl, (), out_particles)
end

# PSP constructors from coordinates
Expand All @@ -133,7 +133,7 @@ end
PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_coords::NTuple{N,Real},
out_coords::NTuple{M,Real},
)
Expand All @@ -143,19 +143,19 @@ Construct a [`PhaseSpacePoint`](@ref) from given coordinates by using the `_gene
function PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_coords::NTuple{N,Real},
out_coords::NTuple{M,Real},
) where {N,M}
in_ps, out_ps = QEDbase._generate_momenta(proc, model, ps_def, in_coords, out_coords)
return PhaseSpacePoint(proc, model, ps_def, in_ps, out_ps)
in_ps, out_ps = QEDbase._build_momenta(proc, model, psl, in_coords, out_coords)
return PhaseSpacePoint(proc, model, psl, in_ps, out_ps)
end

"""
InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractPhaseSpaceLayout,
in_coords::NTuple{N,Real},
)

Expand All @@ -167,9 +167,9 @@ Construct a [`PhaseSpacePoint`](@ref) from given coordinates by using the `_gene
function InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
psl::AbstractInPhaseSpaceLayout,
in_coords::NTuple{N,Real},
) where {N}
in_ps = QEDbase._generate_incoming_momenta(proc, model, ps_def, in_coords)
return InPhaseSpacePoint(proc, model, ps_def, in_ps)
in_ps = QEDbase._build_momenta(proc, model, psl, in_coords)
return InPhaseSpacePoint(proc, model, psl, in_ps)
end
27 changes: 0 additions & 27 deletions src/phase_spaces/print.jl
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
function Base.show(io::IO, ::SphericalCoordinateSystem)
print(io, "spherical coordinates")
return nothing
end

function Base.show(io::IO, ::CenterOfMomentumFrame)
print(io, "center-of-momentum frame")
return nothing
end

function Base.show(io::IO, ::ElectronRestFrame)
print(io, "electron rest frame")
return nothing
end

function Base.show(io::IO, m::MIME"text/plain", ps_def::PhasespaceDefinition)
println(io, "PhasespaceDefinition")
println(io, " coordinate system: $(ps_def.coord_sys)")
println(io, " frame: $(ps_def.frame)")
return nothing
end

function Base.show(io::IO, ps_def::PhasespaceDefinition)
print(io, "$(ps_def.coord_sys) in $(ps_def.frame)")
return nothing
end

function Base.show(io::IO, particle::ParticleStateful)
print(io, "$(particle.dir) $(particle.species): $(particle.mom)")
return nothing
Expand Down
60 changes: 14 additions & 46 deletions src/phase_spaces/types.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
"""
SphericalCoordinateSystem <: AbstractCoordinateSystem

TBW
"""
struct SphericalCoordinateSystem <: AbstractCoordinateSystem end

"""
CenterOfMomentumFrame <: AbstractFrameOfReference

TBW
"""
struct CenterOfMomentumFrame <: AbstractFrameOfReference end

"""
ElectronRestFrame <: AbstractFrameOfReference

TBW
"""
struct ElectronRestFrame <: AbstractFrameOfReference end

"""
PhasespaceDefinition(coord_sys::AbstractCoordinateSystem, frame::AbstractFrameOfReference)

Convenient type to dispatch on coordiante systems and frames of reference. Combines a `AbstractCoordinateSystem` with a `AbstractFrameOfReference`.
"""
struct PhasespaceDefinition{CS<:AbstractCoordinateSystem,F<:AbstractFrameOfReference} <:
AbstractPhasespaceDefinition
coord_sys::CS
frame::F
end

"""
ParticleStateful <: AbstractParticle

Expand Down Expand Up @@ -71,17 +39,17 @@ end
"""
PhaseSpacePoint

Representation of a point in the phase space of a process. Contains the process (`AbstractProcessDefinition`), the model (`AbstractModelDefinition`), the phase space definition (`AbstractPhasespaceDefinition`), and stateful incoming and outgoing particles ([`ParticleStateful`](@ref)).
Representation of a point in the phase space of a process. Contains the process (`AbstractProcessDefinition`), the model (`AbstractModelDefinition`), the phase space layout (`AbstractPhaseSpaceLayout`), and stateful incoming and outgoing particles ([`ParticleStateful`](@ref)).

szabo137 marked this conversation as resolved.
Show resolved Hide resolved
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 `Outgoing` direction, an error is thrown.

```jldoctest
```juila
julia> using QEDcore; using QEDprocesses
szabo137 marked this conversation as resolved.
Show resolved Hide resolved

julia> PhaseSpacePoint(
Compton(),
PerturbativeQED(),
PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()),
DefaultPhaseSpaceDefinition(),
(
ParticleStateful(Incoming(), Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(Incoming(), Photon(), SFourMomentum(1, 0, 0, 0))
Expand All @@ -94,7 +62,7 @@ julia> PhaseSpacePoint(
PhaseSpacePoint:
process: one-photon Compton scattering
model: perturbative QED
phasespace definition: spherical coordinates in electron rest frame
phasespace layout: default
incoming particles:
-> incoming electron: [1.0, 0.0, 0.0, 0.0]
-> incoming photon: [1.0, 0.0, 0.0, 0.0]
Expand All @@ -111,35 +79,35 @@ PhaseSpacePoint:
struct PhaseSpacePoint{
PROC<:AbstractProcessDefinition,
MODEL<:AbstractModelDefinition,
PSDEF<:AbstractPhasespaceDefinition,
PSL<:AbstractPhaseSpaceLayout,
IN_PARTICLES<:Tuple{Vararg{ParticleStateful}},
OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}},
ELEMENT<:AbstractFourMomentum,
} <: AbstractPhaseSpacePoint{PROC,MODEL,PSDEF,IN_PARTICLES,OUT_PARTICLES}
} <: AbstractPhaseSpacePoint{PROC,MODEL,PSL,IN_PARTICLES,OUT_PARTICLES}
proc::PROC
model::MODEL
ps_def::PSDEF
psl::PSL

in_particles::IN_PARTICLES
out_particles::OUT_PARTICLES

"""
PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
psl::AbstractPhaseSpaceLayout,
in_ps::Tuple{ParticleStateful},
out_ps::Tuple{ParticleStateful},
)

Construct a [`PhaseSpacePoint`](@ref) from a process, model, phasespace definition and a tuple of [`ParticleStateful`](@ref)s.
"""
function PhaseSpacePoint(
proc::PROC, model::MODEL, ps_def::PSDEF, in_p::IN_PARTICLES, out_p::OUT_PARTICLES
proc::PROC, model::MODEL, psl::PSL, in_p::IN_PARTICLES, out_p::OUT_PARTICLES
) where {
PROC<:AbstractProcessDefinition,
MODEL<:AbstractModelDefinition,
PSDEF<:AbstractPhasespaceDefinition,
PSL<:AbstractPhaseSpaceLayout,
IN_PARTICLES<:Tuple{Vararg{ParticleStateful}},
OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}},
}
Expand All @@ -148,8 +116,8 @@ struct PhaseSpacePoint{
incoming_particles(proc), outgoing_particles(proc), in_p, out_p
)

return new{PROC,MODEL,PSDEF,IN_PARTICLES,OUT_PARTICLES,ELEMENT}(
proc, model, ps_def, in_p, out_p
return new{PROC,MODEL,PSL,IN_PARTICLES,OUT_PARTICLES,ELEMENT}(
proc, model, psl, in_p, out_p
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/phase_spaces/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ end

Returns the element type of the [`PhaseSpacePoint`](@ref) object or type, e.g. `SFourMomentum`.

```jldoctest
```julia
julia> using QEDcore; using QEDprocesses

julia> psp = PhaseSpacePoint(Compton(), PerturbativeQED(), PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()), Tuple(rand(SFourMomentum) for _ in 1:2), Tuple(rand(SFourMomentum) for _ in 1:2));
julia> psp = PhaseSpacePoint(Compton(), PerturbativeQED(), DefaultPhaseSpaceLayout(), Tuple(rand(SFourMomentum) for _ in 1:2), Tuple(rand(SFourMomentum) for _ in 1:2));

julia> QEDcore._momentum_type(psp)
SFourMomentum
Expand Down
4 changes: 2 additions & 2 deletions test/coordinate_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ include("test_implementation/TestImplementation.jl")
TESTPROC = TestImplementation.TestProcess(INCOMING_PARTICLES, OUTGOING_PARTICLES)
TESTMODEL = TestImplementation.TestModel()

TESTINPSL = TestImplementation.TrivialInPSL()
TESTINPSL = TestImplementation.TestInPhaseSpaceLayout()
TESTINCOORDS = Tuple(rand(RNG, 4 * N_INCOMING))
groundtruth_in_moms = TestImplementation._groundtruth_in_moms(TESTINCOORDS)

TESTOUTPSL = TestImplementation.TrivialOutPSL(TESTINPSL)
TESTOUTPSL = TestImplementation.TestOutPhaseSpaceLayout(TESTINPSL)
TESTOUTCOORDS = Tuple(rand(RNG, 4 * N_OUTGOING - 4))
groundtruth_out_moms = TestImplementation._groundtruth_out_moms(
groundtruth_in_moms, TESTOUTCOORDS
Expand Down
Loading
Loading