Skip to content

Commit

Permalink
Remove import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonReinhard committed Jun 27, 2024
1 parent e100971 commit 9339e4d
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 123 deletions.
1 change: 1 addition & 0 deletions src/algebraic_objects/dirac_tensors/multiplication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
#######

# Base.*(...) = ... is not possible directly so we have to import here
import Base: *

"""
Expand Down
59 changes: 27 additions & 32 deletions src/algebraic_objects/four_momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@
#
#######

import QEDbase:
getT,
getX,
getY,
getZ,
setT!,
setX!,
setY!,
setZ!,
IsLorentzVectorLike,
IsMutableLorentzVectorLike
import StaticArrays: similar_type

"""
$(TYPEDEF)
Expand Down Expand Up @@ -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}

#######
#
Expand Down Expand Up @@ -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}
41 changes: 21 additions & 20 deletions src/algebraic_objects/lorentz_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#
#######

import QEDbase: getT, getX, getY, getZ, setT!, setX!, setY!, setZ!
import StaticArrays: similar_type

#######
#
# Concrete LorentzVector types
Expand Down Expand Up @@ -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)
Expand All @@ -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}
42 changes: 20 additions & 22 deletions src/particles/particle_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# implement the abstact particle interface accordingly.
###############

import QEDbase: is_particle, is_anti_particle, is_boson, is_fermion, mass, charge

"""
AbstractParticleSpinor
Expand All @@ -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.
Expand All @@ -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`.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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")

"""
Expand All @@ -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")

"""
Expand All @@ -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).
Expand All @@ -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).
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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")
8 changes: 3 additions & 5 deletions src/particles/propagators.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import QEDbase: propagator

function _scalar_propagator(K::AbstractFourMomentum, mass::Real)
return one(mass) / (K * K - mass^2)
end
Expand All @@ -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
4 changes: 1 addition & 3 deletions src/particles/spinors.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Base.getindex

const SPINOR_VALIDITY_CHECK = Ref(true)

macro valid_spinor_input(ex)
Expand Down Expand Up @@ -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
Loading

0 comments on commit 9339e4d

Please sign in to comment.