From a1581182ca91bc2cd7128259be6a57c637ebaf2a Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Tue, 2 Jul 2024 10:50:30 +0200 Subject: [PATCH] WIP --- Project.toml | 2 +- src/MetagraphOptimization.jl | 32 ++--- src/models/physics_models/interface.jl | 7 +- src/models/physics_models/qed/particle.jl | 145 ++++++---------------- src/models/print.jl | 10 -- 5 files changed, 62 insertions(+), 134 deletions(-) diff --git a/Project.toml b/Project.toml index 63f9d2e..ae82e04 100644 --- a/Project.toml +++ b/Project.toml @@ -14,12 +14,12 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" NumaAllocators = "21436f30-1b4a-4f08-87af-e26101bb5379" QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93" +QEDcore = "35dc0263-cb5f-4c33-a114-1d7f54ab753e" QEDprocesses = "46de9c38-1bb3-4547-a1ec-da24d767fdad" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" -oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b" [extras] CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2" diff --git a/src/MetagraphOptimization.jl b/src/MetagraphOptimization.jl index 608b515..429b7d4 100644 --- a/src/MetagraphOptimization.jl +++ b/src/MetagraphOptimization.jl @@ -173,22 +173,24 @@ include("optimization/split.jl") include("models/interface.jl") include("models/print.jl") -include("models/abc/types.jl") -include("models/abc/particle.jl") -include("models/abc/compute.jl") -include("models/abc/create.jl") -include("models/abc/properties.jl") -include("models/abc/parse.jl") -include("models/abc/print.jl") +include("models/physics_models/interface.jl") -include("models/qed/types.jl") -include("models/qed/particle.jl") -include("models/qed/diagrams.jl") -include("models/qed/compute.jl") -include("models/qed/create.jl") -include("models/qed/properties.jl") -include("models/qed/parse.jl") -include("models/qed/print.jl") +include("models/physics_models/abc/types.jl") +include("models/physics_models/abc/particle.jl") +include("models/physics_models/abc/compute.jl") +include("models/physics_models/abc/create.jl") +include("models/physics_models/abc/properties.jl") +include("models/physics_models/abc/parse.jl") +include("models/physics_models/abc/print.jl") + +include("models/physics_models/qed/types.jl") +include("models/physics_models/qed/particle.jl") +include("models/physics_models/qed/diagrams.jl") +include("models/physics_models/qed/compute.jl") +include("models/physics_models/qed/create.jl") +include("models/physics_models/qed/properties.jl") +include("models/physics_models/qed/parse.jl") +include("models/physics_models/qed/print.jl") include("devices/measure.jl") include("devices/detect.jl") diff --git a/src/models/physics_models/interface.jl b/src/models/physics_models/interface.jl index 32478cf..17b90fd 100644 --- a/src/models/physics_models/interface.jl +++ b/src/models/physics_models/interface.jl @@ -1,4 +1,3 @@ -import QEDbase.mass import QEDbase.AbstractParticle """ @@ -9,13 +8,13 @@ Base type for a model, e.g. ABC-Model or QED. This is used to dispatch many func abstract type AbstractPhysicsModel <: AbstractModel end """ - ParticleValue{ParticleType <: AbstractParticle} + ParticleValue{ParticleType <: AbstractParticleStateful} -A struct describing a particle during a calculation of a Feynman Diagram, together with the value that's being calculated. `AbstractParticle` is the type from the QEDbase package. +A struct describing a particle during a calculation of a Feynman Diagram, together with the value that's being calculated. `AbstractParticleStateful` is the type from the QEDbase package. `sizeof(ParticleValue())` = 48 Byte """ -struct ParticleValue{ParticleType <: AbstractParticle, ValueType} +struct ParticleValue{ParticleType <: AbstractParticleStateful, ValueType} p::ParticleType v::ValueType end diff --git a/src/models/physics_models/qed/particle.jl b/src/models/physics_models/qed/particle.jl index d51fedd..130dc2e 100644 --- a/src/models/physics_models/qed/particle.jl +++ b/src/models/physics_models/qed/particle.jl @@ -1,8 +1,6 @@ using QEDprocesses using StaticArrays -import QEDbase.mass -# TODO check const e = sqrt(4π / 137) """ @@ -12,17 +10,6 @@ Singleton definition for identification of the QED-Model. """ struct QEDModel <: AbstractPhysicsModel end -""" - QEDParticle - -Base type for all particles in the [`QEDModel`](@ref). - -Its template parameter specifies the particle's direction. - -The concrete types contain singletons of the types that they are, like `Photon` and `Electron` from QEDbase, and their state descriptions. -""" -abstract type QEDParticle{Direction <: ParticleDirection} <: AbstractParticle end - """ QEDProcessDescription <: AbstractProcessDescription @@ -35,7 +22,7 @@ struct QEDProcessDescription <: AbstractProcessDescription outParticles::Dict{Type{<:QEDParticle{Outgoing}}, Int} end -QEDParticleValue{ParticleType <: QEDParticle} = Union{ +QEDParticleValue{ParticleType <: ParticleStateful} = Union{ ParticleValue{ParticleType, BiSpinor}, ParticleValue{ParticleType, AdjointBiSpinor}, ParticleValue{ParticleType, DiracMatrix}, @@ -43,92 +30,48 @@ QEDParticleValue{ParticleType <: QEDParticle} = Union{ ParticleValue{ParticleType, ComplexF64}, } -""" - PhotonStateful <: QEDParticle - -A photon of the [`QEDModel`](@ref) with its state. -""" -struct PhotonStateful{Direction <: ParticleDirection, Pol <: AbstractDefinitePolarization} <: QEDParticle{Direction} - momentum::SFourMomentum -end - -PhotonStateful{Direction}(mom::SFourMomentum) where {Direction <: ParticleDirection} = - PhotonStateful{Direction, PolX}(mom) - -PhotonStateful{Dir, Pol}(ph::PhotonStateful) where {Dir, Pol} = PhotonStateful{Dir, Pol}(ph.momentum) - -""" - FermionStateful <: QEDParticle - -A fermion of the [`QEDModel`](@ref) with its state. -""" -struct FermionStateful{Direction <: ParticleDirection, Spin <: AbstractDefiniteSpin} <: QEDParticle{Direction} - momentum::SFourMomentum - # TODO: mass for electron/muon/tauon representation? -end - -FermionStateful{Direction}(mom::SFourMomentum) where {Direction <: ParticleDirection} = - FermionStateful{Direction, SpinUp}(mom) - -FermionStateful{Dir, Spin}(f::FermionStateful) where {Dir, Spin} = FermionStateful{Dir, Spin}(f.momentum) - -""" - AntiFermionStateful <: QEDParticle - -An anti-fermion of the [`QEDModel`](@ref) with its state. -""" -struct AntiFermionStateful{Direction <: ParticleDirection, Spin <: AbstractDefiniteSpin} <: QEDParticle{Direction} - momentum::SFourMomentum - # TODO: mass for electron/muon/tauon representation? -end - -AntiFermionStateful{Direction}(mom::SFourMomentum) where {Direction <: ParticleDirection} = - AntiFermionStateful{Direction, SpinUp}(mom) - -AntiFermionStateful{Dir, Spin}(f::AntiFermionStateful) where {Dir, Spin} = AntiFermionStateful{Dir, Spin}(f.momentum) - """ interaction_result(t1::Type{T1}, t2::Type{T2}) where {T1 <: QEDParticle, T2 <: QEDParticle} For two given particle types that can interact, return the third. """ -function interaction_result(t1::Type{T1}, t2::Type{T2}) where {T1 <: QEDParticle, T2 <: QEDParticle} +function interaction_result(t1::Type{T1}, t2::Type{T2}) where {T1 <: ParticleStateful, T2 <: ParticleStateful} @assert false "Invalid interaction between particles of types $t1 and $t2" end +interaction_result(::Type{ParticleStateful{Incoming, Electron}}, ::Type{ParticleStateful{Outgoing, Electron}}) = + ParticleStateful{Incoming, Photon} +interaction_result(::Type{ParticleStateful{Incoming, Electron}}, ::Type{ParticleStateful{Incoming, Positron}}) = + ParticleStateful{Incoming, Photon} interaction_result( - ::Type{FermionStateful{Incoming, Spin1}}, - ::Type{FermionStateful{Outgoing, Spin2}}, -) where {Spin1, Spin2} = PhotonStateful{Incoming, PolX} -interaction_result( - ::Type{FermionStateful{Incoming, Spin1}}, - ::Type{AntiFermionStateful{Incoming, Spin2}}, -) where {Spin1, Spin2} = PhotonStateful{Incoming, PolX} -interaction_result(::Type{FermionStateful{Incoming, Spin1}}, ::Type{<:PhotonStateful}) where {Spin1} = - FermionStateful{Outgoing, SpinUp} + ::Type{ParticleStateful{Incoming, Electron}}, + ::Type{ParticleStateful{<:ParticleDirection, Photon}}, +) = ParticleStateful{Outgoing, Electron} +interaction_result(::Type{ParticleStateful{Outgoing, Electron}}, ::Type{ParticleStateful{Incoming, Electron}}) = + ParticleStateful{Incoming, Photon} +interaction_result(::Type{ParticleStateful{Outgoing, Electron}}, ::Type{ParticleStateful{Outgoing, Positron}}) = + ParticleStateful{Incoming, Photon} interaction_result( - ::Type{FermionStateful{Outgoing, Spin1}}, - ::Type{FermionStateful{Incoming, Spin2}}, -) where {Spin1, Spin2} = PhotonStateful{Incoming, PolX} -interaction_result( - ::Type{FermionStateful{Outgoing, Spin1}}, - ::Type{AntiFermionStateful{Outgoing, Spin2}}, -) where {Spin1, Spin2} = PhotonStateful{Incoming, PolX} -interaction_result(::Type{FermionStateful{Outgoing, Spin1}}, ::Type{<:PhotonStateful}) where {Spin1} = - FermionStateful{Incoming, SpinUp} + ::Type{ParticleStateful{Outgoing, Electron}}, + ::Type{ParticleStateful{<:ParticleDirection, Photon}}, +) = ParticleStateful{Incoming, Electron} # antifermion mirror -interaction_result(::Type{AntiFermionStateful{Incoming, Spin}}, t2::Type{<:QEDParticle}) where {Spin} = - interaction_result(FermionStateful{Outgoing, Spin}, t2) -interaction_result(::Type{AntiFermionStateful{Outgoing, Spin}}, t2::Type{<:QEDParticle}) where {Spin} = - interaction_result(FermionStateful{Incoming, Spin}, t2) +interaction_result(::Type{ParticleStateful{Incoming, Positron}}, t2::Type{<:ParticleStateful}) = + interaction_result(ParticleStateful{Outgoing, Electron}, t2) +interaction_result(::Type{ParticleStateful{Outgoing, Positron}}, t2::Type{<:ParticleStateful}) = + interaction_result(ParticleStateful{Incoming, Electron}, t2) # photon commutativity -interaction_result(t1::Type{<:PhotonStateful}, t2::Type{<:QEDParticle}) = interaction_result(t2, t1) +interaction_result(t1::Type{<:ParticleStateful{<:ParticleDirection, Photon}}, t2::Type{<:ParticleStateful}) = + interaction_result(t2, t1) # but prevent stack overflow -function interaction_result(t1::Type{<:PhotonStateful}, t2::Type{<:PhotonStateful}) +function interaction_result( + t1::Type{ParticleStateful{<:ParticleDirection, Photon}}, + t2::Type{ParticleStateful{<:ParticleDirection, Photon}}, +) @assert false "Invalid interaction between particles of types $t1 and $t2" end @@ -137,18 +80,12 @@ end Return the type of the inverted direction. E.g. """ -propagation_result(::Type{FermionStateful{Incoming, Spin}}) where {Spin <: AbstractDefiniteSpin} = - FermionStateful{Outgoing, Spin} -propagation_result(::Type{FermionStateful{Outgoing, Spin}}) where {Spin <: AbstractDefiniteSpin} = - FermionStateful{Incoming, Spin} -propagation_result(::Type{AntiFermionStateful{Incoming, Spin}}) where {Spin <: AbstractDefiniteSpin} = - AntiFermionStateful{Outgoing, Spin} -propagation_result(::Type{AntiFermionStateful{Outgoing, Spin}}) where {Spin <: AbstractDefiniteSpin} = - AntiFermionStateful{Incoming, Spin} -propagation_result(::Type{PhotonStateful{Incoming, Pol}}) where {Pol <: AbstractDefinitePolarization} = - PhotonStateful{Outgoing, Pol} -propagation_result(::Type{PhotonStateful{Outgoing, Pol}}) where {Pol <: AbstractDefinitePolarization} = - PhotonStateful{Incoming, Pol} +propagation_result(::Type{ParticleStateful{Incoming, Electron}}) = ParticleStateful{Outgoing, Electron} +propagation_result(::Type{ParticleStateful{Outgoing, Electron}}) = ParticleStateful{Incoming, Electron} +propagation_result(::Type{ParticleStateful{Incoming, Positron}}) = ParticleStateful{Outgoing, Positron} +propagation_result(::Type{ParticleStateful{Outgoing, Positron}}) = ParticleStateful{Incoming, Positron} +propagation_result(::Type{ParticleStateful{Incoming, Photon}}) = ParticleStateful{Outgoing, Photon} +propagation_result(::Type{ParticleStateful{Outgoing, Photon}}) = ParticleStateful{Incoming, Photon} """ types(::QEDModel) @@ -157,12 +94,12 @@ Return a Vector of the possible types of particle in the [`QEDModel`](@ref). """ function types(::QEDModel) return [ - PhotonStateful{Incoming, PolX}, - PhotonStateful{Outgoing, PolX}, - FermionStateful{Incoming, SpinUp}, - FermionStateful{Outgoing, SpinUp}, - AntiFermionStateful{Incoming, SpinUp}, - AntiFermionStateful{Outgoing, SpinUp}, + ParticleStateful{Incoming, Photon}, + ParticleStateful{Outgoing, Photon}, + ParticleStateful{Incoming, Electron}, + ParticleStateful{Outgoing, Electron}, + ParticleStateful{Incoming, Positron}, + ParticleStateful{Outgoing, Positron}, ] end @@ -235,9 +172,9 @@ end @inline isoutgoing(::Type{<:QEDParticle{Incoming}}) = false @inline isoutgoing(::Type{<:QEDParticle{Outgoing}}) = true -@inline mass(::Type{<:FermionStateful}) = 1.0 -@inline mass(::Type{<:AntiFermionStateful}) = 1.0 -@inline mass(::Type{<:PhotonStateful}) = 0.0 +@inline QEDbase.mass(::Type{<:FermionStateful}) = 1.0 +@inline QEDbase.mass(::Type{<:AntiFermionStateful}) = 1.0 +@inline QEDbase.mass(::Type{<:PhotonStateful}) = 0.0 @inline invert_momentum(p::FermionStateful{Dir, Spin}) where {Dir, Spin} = FermionStateful{Dir, Spin}(-p.momentum, p.spin) diff --git a/src/models/print.jl b/src/models/print.jl index 00b8489..e69de29 100644 --- a/src/models/print.jl +++ b/src/models/print.jl @@ -1,10 +0,0 @@ - -""" - show(io::IO, particleValue::ParticleValue) - -Pretty print a [`ParticleValue`](@ref), no newlines. -""" -function show(io::IO, particleValue::ParticleValue) - print(io, "($(particleValue.p), value: $(particleValue.v))") - return nothing -end