diff --git a/src/algebraic_objects/dirac_tensors/multiplication.jl b/src/algebraic_objects/dirac_tensors/multiplication.jl index 21c8e84..e7117ca 100644 --- a/src/algebraic_objects/dirac_tensors/multiplication.jl +++ b/src/algebraic_objects/dirac_tensors/multiplication.jl @@ -4,6 +4,7 @@ # ####### +# Base.*(...) = ... is not possible directly so we have to import here import Base: * """ diff --git a/src/algebraic_objects/four_momentum.jl b/src/algebraic_objects/four_momentum.jl index ad86be5..0ed0460 100644 --- a/src/algebraic_objects/four_momentum.jl +++ b/src/algebraic_objects/four_momentum.jl @@ -4,19 +4,6 @@ # ####### -import QEDbase: - getT, - getX, - getY, - getZ, - setT!, - setX!, - setY!, - setZ!, - IsLorentzVectorLike, - IsMutableLorentzVectorLike -import StaticArrays: similar_type - """ $(TYPEDEF) @@ -50,21 +37,25 @@ function SFourMomentum(t::T, x::T, y::T, z::T) where {T<:Union{Integer,Rational, return SFourMomentum(float(t), x, y, z) end -function similar_type(::Type{A}, ::Type{T}, ::Size{S}) where {A<:SFourMomentum,T<:Real,S} +function StaticArrays.similar_type( + ::Type{A}, ::Type{T}, ::Size{S} +) where {A<:SFourMomentum,T<:Real,S} return SFourMomentum end -function similar_type(::Type{A}, ::Type{T}, ::Size{S}) where {A<:SFourMomentum,T,S} +function StaticArrays.similar_type( + ::Type{A}, ::Type{T}, ::Size{S} +) where {A<:SFourMomentum,T,S} return SLorentzVector{T} end -@inline getT(p::SFourMomentum) = p.E -@inline getX(p::SFourMomentum) = p.px -@inline getY(p::SFourMomentum) = p.py -@inline getZ(p::SFourMomentum) = p.pz +@inline QEDbase.getT(p::SFourMomentum) = p.E +@inline QEDbase.getX(p::SFourMomentum) = p.px +@inline QEDbase.getY(p::SFourMomentum) = p.py +@inline QEDbase.getZ(p::SFourMomentum) = p.pz # TODO: this breaks incremental compilation because it's trying to eval permanent changes in a different module #register_LorentzVectorLike(SFourMomentum) -@traitimpl IsLorentzVectorLike{SFourMomentum} +@traitimpl QEDbase.IsLorentzVectorLike{SFourMomentum} ####### # @@ -104,35 +95,39 @@ function MFourMomentum(t::T, x::T, y::T, z::T) where {T<:Union{Integer,Rational, return MFourMomentum(float(t), x, y, z) end -function similar_type(::Type{A}, ::Type{T}, ::Size{S}) where {A<:MFourMomentum,T<:Real,S} +function StaticArrays.similar_type( + ::Type{A}, ::Type{T}, ::Size{S} +) where {A<:MFourMomentum,T<:Real,S} return MFourMomentum end -function similar_type(::Type{A}, ::Type{T}, ::Size{S}) where {A<:MFourMomentum,T,S} +function StaticArrays.similar_type( + ::Type{A}, ::Type{T}, ::Size{S} +) where {A<:MFourMomentum,T,S} return MLorentzVector{T} end -@inline getT(p::MFourMomentum) = p.E -@inline getX(p::MFourMomentum) = p.px -@inline getY(p::MFourMomentum) = p.py -@inline getZ(p::MFourMomentum) = p.pz +@inline QEDbase.getT(p::MFourMomentum) = p.E +@inline QEDbase.getX(p::MFourMomentum) = p.px +@inline QEDbase.getY(p::MFourMomentum) = p.py +@inline QEDbase.getZ(p::MFourMomentum) = p.pz -function setT!(lv::MFourMomentum, value::Float64) +function QEDbase.setT!(lv::MFourMomentum, value::Float64) return lv.E = value end -function setX!(lv::MFourMomentum, value::Float64) +function QEDbase.setX!(lv::MFourMomentum, value::Float64) return lv.px = value end -function setY!(lv::MFourMomentum, value::Float64) +function QEDbase.setY!(lv::MFourMomentum, value::Float64) return lv.py = value end -function setZ!(lv::MFourMomentum, value::Float64) +function QEDbase.setZ!(lv::MFourMomentum, value::Float64) return lv.pz = value end # TODO: this breaks incremental compilation because it's trying to eval permanent changes in a different module # register_LorentzVectorLike(MFourMomentum) -@traitimpl IsLorentzVectorLike{MFourMomentum} -@traitimpl IsMutableLorentzVectorLike{MFourMomentum} +@traitimpl QEDbase.IsLorentzVectorLike{MFourMomentum} +@traitimpl QEDbase.IsMutableLorentzVectorLike{MFourMomentum} diff --git a/src/algebraic_objects/lorentz_vector.jl b/src/algebraic_objects/lorentz_vector.jl index 3658cf5..3241a27 100644 --- a/src/algebraic_objects/lorentz_vector.jl +++ b/src/algebraic_objects/lorentz_vector.jl @@ -4,9 +4,6 @@ # ####### -import QEDbase: getT, getX, getY, getZ, setT!, setX!, setY!, setZ! -import StaticArrays: similar_type - ####### # # Concrete LorentzVector types @@ -35,18 +32,20 @@ struct SLorentzVector{T} <: AbstractLorentzVector{T} end SLorentzVector(t, x, y, z) = SLorentzVector(promote(t, x, y, z)...) -function similar_type(::Type{A}, ::Type{T}, ::Size{S}) where {A<:SLorentzVector,T,S} +function StaticArrays.similar_type( + ::Type{A}, ::Type{T}, ::Size{S} +) where {A<:SLorentzVector,T,S} return SLorentzVector{T} end -@inline getT(lv::SLorentzVector) = lv.t -@inline getX(lv::SLorentzVector) = lv.x -@inline getY(lv::SLorentzVector) = lv.y -@inline getZ(lv::SLorentzVector) = lv.z +@inline QEDbase.getT(lv::SLorentzVector) = lv.t +@inline QEDbase.getX(lv::SLorentzVector) = lv.x +@inline QEDbase.getY(lv::SLorentzVector) = lv.y +@inline QEDbase.getZ(lv::SLorentzVector) = lv.z # TODO: this breaks incremental compilation because it's trying to eval permanent changes in a different module #register_LorentzVectorLike(SLorentzVector) -@traitimpl IsLorentzVectorLike{SLorentzVector} +@traitimpl QEDbase.IsLorentzVectorLike{SLorentzVector} """ $(TYPEDEF) @@ -71,32 +70,34 @@ mutable struct MLorentzVector{T} <: AbstractLorentzVector{T} end MLorentzVector(t, x, y, z) = MLorentzVector(promote(t, x, y, z)...) -function similar_type(::Type{A}, ::Type{T}, ::Size{S}) where {A<:MLorentzVector,T,S} +function StaticArrays.similar_type( + ::Type{A}, ::Type{T}, ::Size{S} +) where {A<:MLorentzVector,T,S} return MLorentzVector{T} end -@inline getT(lv::MLorentzVector) = lv.t -@inline getX(lv::MLorentzVector) = lv.x -@inline getY(lv::MLorentzVector) = lv.y -@inline getZ(lv::MLorentzVector) = lv.z +@inline QEDbase.getT(lv::MLorentzVector) = lv.t +@inline QEDbase.getX(lv::MLorentzVector) = lv.x +@inline QEDbase.getY(lv::MLorentzVector) = lv.y +@inline QEDbase.getZ(lv::MLorentzVector) = lv.z -function setT!(lv::MLorentzVector, value::T) where {T} +function QEDbase.setT!(lv::MLorentzVector, value::T) where {T} return lv.t = value end -function setX!(lv::MLorentzVector, value::T) where {T} +function QEDbase.setX!(lv::MLorentzVector, value::T) where {T} return lv.x = value end -function setY!(lv::MLorentzVector, value::T) where {T} +function QEDbase.setY!(lv::MLorentzVector, value::T) where {T} return lv.y = value end -function setZ!(lv::MLorentzVector, value::T) where {T} +function QEDbase.setZ!(lv::MLorentzVector, value::T) where {T} return lv.z = value end # TODO: this breaks incremental compilation because it's trying to eval permanent changes in a different module #register_LorentzVectorLike(MLorentzVector) -@traitimpl IsLorentzVectorLike{MLorentzVector} -@traitimpl IsMutableLorentzVectorLike{MLorentzVector} +@traitimpl QEDbase.IsLorentzVectorLike{MLorentzVector} +@traitimpl QEDbase.IsMutableLorentzVectorLike{MLorentzVector} diff --git a/src/particles/particle_types.jl b/src/particles/particle_types.jl index 8bdeb78..97917df 100644 --- a/src/particles/particle_types.jl +++ b/src/particles/particle_types.jl @@ -5,8 +5,6 @@ # implement the abstact particle interface accordingly. ############### -import QEDbase: is_particle, is_anti_particle, is_boson, is_fermion, mass, charge - """ AbstractParticleSpinor @@ -22,7 +20,7 @@ Abstract base types for particle species that act like fermions in the sense of """ abstract type FermionLike <: AbstractParticleType end -is_fermion(::FermionLike) = true +QEDbase.is_fermion(::FermionLike) = true """ Abstract base type for fermions as distinct from [`AntiFermion`](@ref)s. @@ -38,9 +36,9 @@ Abstract base type for fermions as distinct from [`AntiFermion`](@ref)s. """ abstract type Fermion <: FermionLike end -is_particle(::Fermion) = true +QEDbase.is_particle(::Fermion) = true -is_anti_particle(::Fermion) = false +QEDbase.is_anti_particle(::Fermion) = false """ Abstract base type for anti-fermions as distinct from its particle counterpart `Fermion`. @@ -55,9 +53,9 @@ Abstract base type for anti-fermions as distinct from its particle counterpart ` """ abstract type AntiFermion <: FermionLike end -is_particle(::AntiFermion) = false +QEDbase.is_particle(::AntiFermion) = false -is_anti_particle(::AntiFermion) = true +QEDbase.is_anti_particle(::AntiFermion) = true """ Abstract base type for majorana-fermions, i.e. fermions which are their own anti-particles. @@ -73,9 +71,9 @@ Abstract base type for majorana-fermions, i.e. fermions which are their own anti """ abstract type MajoranaFermion <: FermionLike end -is_particle(::MajoranaFermion) = true +QEDbase.is_particle(::MajoranaFermion) = true -is_anti_particle(::MajoranaFermion) = true +QEDbase.is_anti_particle(::MajoranaFermion) = true """ Concrete type for *electrons* as a particle species. Mostly used for dispatch. @@ -96,8 +94,8 @@ electron ``` """ struct Electron <: Fermion end -mass(::Electron) = 1.0 -charge(::Electron) = -1.0 +QEDbase.mass(::Electron) = 1.0 +QEDbase.charge(::Electron) = -1.0 Base.show(io::IO, ::Electron) = print(io, "electron") """ @@ -119,8 +117,8 @@ positron ``` """ struct Positron <: AntiFermion end -mass(::Positron) = 1.0 -charge(::Positron) = 1.0 +QEDbase.mass(::Positron) = 1.0 +QEDbase.charge(::Positron) = 1.0 Base.show(io::IO, ::Positron) = print(io, "positron") """ @@ -131,7 +129,7 @@ Abstract base types for particle species that act like bosons in the sense of pa """ abstract type BosonLike <: AbstractParticleType end -is_boson(::BosonLike) = true +QEDbase.is_boson(::BosonLike) = true """ Abstract base type for bosons as distinct from its anti-particle counterpart [`AntiBoson`](@ref). @@ -145,8 +143,8 @@ Abstract base type for bosons as distinct from its anti-particle counterpart [`A ``` """ abstract type Boson <: BosonLike end -is_particle(::Boson) = true -is_anti_particle(::Boson) = false +QEDbase.is_particle(::Boson) = true +QEDbase.is_anti_particle(::Boson) = false """ Abstract base type for anti-bosons as distinct from its particle counterpart [`Boson`](@ref). @@ -160,8 +158,8 @@ Abstract base type for anti-bosons as distinct from its particle counterpart [`B ``` """ abstract type AntiBoson <: BosonLike end -is_particle(::AntiBoson) = false -is_anti_particle(::AntiBoson) = true +QEDbase.is_particle(::AntiBoson) = false +QEDbase.is_anti_particle(::AntiBoson) = true """ Abstract base type for majorana-bosons, i.e. bosons which are their own anti-particles. @@ -175,8 +173,8 @@ Abstract base type for majorana-bosons, i.e. bosons which are their own anti-par ``` """ abstract type MajoranaBoson <: BosonLike end -is_particle(::MajoranaBoson) = true -is_anti_particle(::MajoranaBoson) = true +QEDbase.is_particle(::MajoranaBoson) = true +QEDbase.is_anti_particle(::MajoranaBoson) = true """ Concrete type for the *photons* as a particle species. Mostly used for dispatch. @@ -197,6 +195,6 @@ photon ``` """ struct Photon <: MajoranaBoson end -mass(::Photon) = 0.0 -charge(::Photon) = 0.0 +QEDbase.mass(::Photon) = 0.0 +QEDbase.charge(::Photon) = 0.0 Base.show(io::IO, ::Photon) = print(io, "photon") diff --git a/src/particles/propagators.jl b/src/particles/propagators.jl index 8e58a99..702c2d1 100644 --- a/src/particles/propagators.jl +++ b/src/particles/propagators.jl @@ -1,5 +1,3 @@ -import QEDbase: propagator - function _scalar_propagator(K::AbstractFourMomentum, mass::Real) return one(mass) / (K * K - mass^2) end @@ -16,14 +14,14 @@ function _fermion_propagator(P::AbstractFourMomentum) return (slashed(P)) * _scalar_propagator(P) end -function propagator(particle_type::BosonLike, K::AbstractFourMomentum) +function QEDbase.propagator(particle_type::BosonLike, K::AbstractFourMomentum) return _scalar_propagator(K, mass(particle_type)) end -function propagator(particle_type::Photon, K::AbstractFourMomentum) +function QEDbase.propagator(particle_type::Photon, K::AbstractFourMomentum) return _scalar_propagator(K) end -function propagator(particle_type::FermionLike, P::AbstractFourMomentum) +function QEDbase.propagator(particle_type::FermionLike, P::AbstractFourMomentum) return _fermion_propagator(P, mass(particle_type)) end diff --git a/src/particles/spinors.jl b/src/particles/spinors.jl index 0764b22..ab9ddbb 100644 --- a/src/particles/spinors.jl +++ b/src/particles/spinors.jl @@ -1,5 +1,3 @@ -import Base.getindex - const SPINOR_VALIDITY_CHECK = Ref(true) macro valid_spinor_input(ex) @@ -118,6 +116,6 @@ end const SpinorVbar = IncomingAntiFermionSpinor -function getindex(SP::T, idx) where {T<:AbstractParticleSpinor} +function Base.getindex(SP::T, idx) where {T<:AbstractParticleSpinor} return idx in (1, 2) ? SP(idx) : throw(BoundsError()) end diff --git a/src/particles/states.jl b/src/particles/states.jl index d656e67..c59a6c2 100644 --- a/src/particles/states.jl +++ b/src/particles/states.jl @@ -1,5 +1,3 @@ -import QEDbase: base_state - function _booster_fermion(mom::AbstractFourMomentum, mass::Real) return (slashed(mom) + mass * one(DiracMatrix)) / (sqrt(abs(getT(mom)) + mass)) end @@ -8,26 +6,28 @@ function _booster_antifermion(mom::AbstractFourMomentum, mass::Real) return (mass * one(DiracMatrix) - slashed(mom)) / (sqrt(abs(getT(mom)) + mass)) end -function base_state( +function QEDbase.base_state( particle::Fermion, ::Incoming, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin ) booster = _booster_fermion(mom, mass(particle)) return BiSpinor(booster[:, QEDbase._spin_index(spin)]) end -function base_state(particle::Fermion, ::Incoming, mom::AbstractFourMomentum, spin::AllSpin) +function QEDbase.base_state( + particle::Fermion, ::Incoming, mom::AbstractFourMomentum, spin::AllSpin +) booster = _booster_fermion(mom, mass(particle)) return SVector(BiSpinor(booster[:, 1]), BiSpinor(booster[:, 2])) end -function base_state( +function QEDbase.base_state( particle::AntiFermion, ::Incoming, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin ) booster = _booster_antifermion(mom, mass(particle)) return AdjointBiSpinor(BiSpinor(booster[:, QEDbase._spin_index(spin) + 2])) * GAMMA[1] end -function base_state( +function QEDbase.base_state( particle::AntiFermion, ::Incoming, mom::AbstractFourMomentum, spin::AllSpin ) booster = _booster_antifermion(mom, mass(particle)) @@ -37,14 +37,16 @@ function base_state( ) end -function base_state( +function QEDbase.base_state( particle::Fermion, ::Outgoing, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin ) booster = _booster_fermion(mom, mass(particle)) return AdjointBiSpinor(BiSpinor(booster[:, QEDbase._spin_index(spin)])) * GAMMA[1] end -function base_state(particle::Fermion, ::Outgoing, mom::AbstractFourMomentum, spin::AllSpin) +function QEDbase.base_state( + particle::Fermion, ::Outgoing, mom::AbstractFourMomentum, spin::AllSpin +) booster = _booster_fermion(mom, mass(particle)) return SVector( AdjointBiSpinor(BiSpinor(booster[:, 1])) * GAMMA[1], @@ -52,14 +54,14 @@ function base_state(particle::Fermion, ::Outgoing, mom::AbstractFourMomentum, sp ) end -function base_state( +function QEDbase.base_state( particle::AntiFermion, ::Outgoing, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin ) booster = _booster_antifermion(mom, mass(particle)) return BiSpinor(booster[:, QEDbase._spin_index(spin) + 2]) end -function base_state( +function QEDbase.base_state( particle::AntiFermion, ::Outgoing, mom::AbstractFourMomentum, spin::AllSpin ) booster = _booster_antifermion(mom, mass(particle)) @@ -91,13 +93,13 @@ function _photon_state(pol::PolarizationY, mom::AbstractFourMomentum) return SLorentzVector{Float64}(0.0, -sin_phi, cos_phi, 0.0) end -@inline function base_state( +@inline function QEDbase.base_state( particle::Photon, ::ParticleDirection, mom::AbstractFourMomentum, pol::AllPolarization ) return _photon_state(pol, mom) end -@inline function base_state( +@inline function QEDbase.base_state( particle::Photon, ::ParticleDirection, mom::AbstractFourMomentum, diff --git a/src/phase_spaces/access.jl b/src/phase_spaces/access.jl index 3b7769a..eb87974 100644 --- a/src/phase_spaces/access.jl +++ b/src/phase_spaces/access.jl @@ -1,16 +1,7 @@ -import QEDbase: - particle_direction, - particle_species, - momentum, - process, - model, - phase_space_definition, - particles - # accessor interface particle stateful -particle_direction(part::ParticleStateful) = part.dir -particle_species(part::ParticleStateful) = part.species -momentum(part::ParticleStateful) = part.mom +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 """ @@ -31,9 +22,9 @@ function Base.getindex(psp::PhaseSpacePoint, ::Outgoing, n::Int) return psp.out_particles[n] end -process(psp::PhaseSpacePoint) = psp.proc -model(psp::PhaseSpacePoint) = psp.model -phase_space_definition(psp::PhaseSpacePoint) = psp.ps_def +QEDbase.process(psp::PhaseSpacePoint) = psp.proc +QEDbase.model(psp::PhaseSpacePoint) = psp.model +QEDbase.phase_space_definition(psp::PhaseSpacePoint) = psp.ps_def -particles(psp::PhaseSpacePoint, ::Incoming) = psp.in_particles -particles(psp::PhaseSpacePoint, ::Outgoing) = psp.out_particles +QEDbase.particles(psp::PhaseSpacePoint, ::Incoming) = psp.in_particles +QEDbase.particles(psp::PhaseSpacePoint, ::Outgoing) = psp.out_particles diff --git a/src/phase_spaces/types.jl b/src/phase_spaces/types.jl index 3e74275..5c50c80 100644 --- a/src/phase_spaces/types.jl +++ b/src/phase_spaces/types.jl @@ -41,7 +41,7 @@ Representation of a particle with a state. It has four fields: Overloads for `is_fermion`, `is_boson`, `is_particle`, `is_anti_particle`, `is_incoming`, `is_outgoing`, `mass`, and `charge` are provided, delegating the call to the correct field and thus implementing the `AbstractParticle` interface. TODO: Turn this back into a `jldoctest` once refactoring is done. -```Julia +```jldoctest julia> using QEDcore; using QEDbase julia> ParticleStateful(Incoming(), Electron(), SFourMomentum(1, 0, 0, 0)) @@ -77,7 +77,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 `Outgoing` direction, an error is thrown. TODO: Turn this back into a `jldoctest` once refactoring is done. -```Julia +```jldoctest julia> using QEDcore; using QEDbase; using QEDprocesses julia> PhaseSpacePoint( diff --git a/src/phase_spaces/utility.jl b/src/phase_spaces/utility.jl index 5e90fd5..a808cff 100644 --- a/src/phase_spaces/utility.jl +++ b/src/phase_spaces/utility.jl @@ -104,7 +104,7 @@ end Returns the element type of the [`PhaseSpacePoint`](@ref) object or type, e.g. `SFourMomentum`. TODO: Turn this back into a `jldoctest` once refactoring is done. -```Julia +```jldoctest 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)); diff --git a/test/particles/types.jl b/test/particles/types.jl index 220dd55..6832d6a 100644 --- a/test/particles/types.jl +++ b/test/particles/types.jl @@ -3,15 +3,6 @@ using QEDcore using StaticArrays using Random -# TODO this can be deleted when QEDbase is released again -# fix ambiguity of the types while both core and base export these -import QEDcore: - AntiFermion, MajoranaFermion, Electron, Positron, Boson, AntiBoson, MajoranaBoson - -# TODO this can be deleted when QEDbase is released again -# fix for the broadcast tests -Base.broadcastable(part::QEDbase.AbstractParticleType) = Ref(part) - # test function to test scalar broadcasting test_broadcast(x::AbstractParticle) = x test_broadcast(x::ParticleDirection) = x