From 5d648941429c0b27ad31489705316997fc6a8101 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Wed, 8 May 2024 19:56:23 +0200 Subject: [PATCH 1/2] Add pretty printing for particle directions, species, and spin/pol --- docs/Project.toml | 1 + src/particles/particle_direction.jl | 16 ++++++++++ src/particles/particle_spin_pol.jl | 48 +++++++++++++++++++++++++++++ src/particles/particle_types.jl | 24 +++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index 6c8f953..b927490 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -3,3 +3,4 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244" DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8" +QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93" diff --git a/src/particles/particle_direction.jl b/src/particles/particle_direction.jl index 5a38c62..b213f51 100644 --- a/src/particles/particle_direction.jl +++ b/src/particles/particle_direction.jl @@ -8,6 +8,13 @@ abstract type ParticleDirection end Concrete implementation of a [`ParticleDirection`](@ref) to indicate that a particle is *incoming* in the context of a given process. Mostly used for dispatch. +```jldoctest +julia> using QEDbase + +julia> Incoming() +incoming +``` + !!! note "ParticleDirection Interface" Besides being a subtype of [`ParticleDirection`](@ref), `Incoming` has @@ -19,12 +26,20 @@ Concrete implementation of a [`ParticleDirection`](@ref) to indicate that a part struct Incoming <: ParticleDirection end is_incoming(::Incoming) = true is_outgoing(::Incoming) = false +Base.show(io::IO, ::Incoming) = print(io, "incoming") """ Outgoing <: ParticleDirection Concrete implementation of a [`ParticleDirection`](@ref) to indicate that a particle is *outgoing* in the context of a given process. Mostly used for dispatch. +```jldoctest +julia> using QEDbase + +julia> Outgoing() +outgoing +``` + !!! note "ParticleDirection Interface" Besides being a subtype of [`ParticleDirection`](@ref), `Outgoing` has @@ -36,3 +51,4 @@ Concrete implementation of a [`ParticleDirection`](@ref) to indicate that a part struct Outgoing <: ParticleDirection end is_incoming(::Outgoing) = false is_outgoing(::Outgoing) = true +Base.show(io::IO, ::Outgoing) = print(io, "outgoing") diff --git a/src/particles/particle_spin_pol.jl b/src/particles/particle_spin_pol.jl index c60a6c5..f2826ba 100644 --- a/src/particles/particle_spin_pol.jl +++ b/src/particles/particle_spin_pol.jl @@ -24,18 +24,42 @@ abstract type AbstractIndefiniteSpin <: AbstractSpin end """ Concrete type indicating that a [`FermionLike`](@ref) has spin-up. + +```jldoctest +julia> using QEDbase + +julia> SpinUp() +spin up +``` """ struct SpinUp <: AbstractDefiniteSpin end +Base.show(io::IO, ::SpinUp) = print(io, "spin up") """ Concrete type indicating that a [`FermionLike`](@ref) has spin-down. + +```jldoctest +julia> using QEDbase + +julia> SpinDown() +spin down +``` """ struct SpinDown <: AbstractDefiniteSpin end +Base.show(io::IO, ::SpinDown) = print(io, "spin down") """ Concrete type indicating that a [`FermionLike`](@ref) has an indefinite spin and the differential cross section calculation should average or sum over all spins, depending on the direction ([`Incoming`](@ref) or [`Outgoing`](@ref)) of the particle in question. + +```jldoctest +julia> using QEDbase + +julia> AllSpin() +all spins +``` """ struct AllSpin <: AbstractIndefiniteSpin end +Base.show(io::IO, ::AllSpin) = print(io, "all spins") """ $(TYPEDSIGNATURES) @@ -73,6 +97,13 @@ abstract type AbstractIndefinitePolarization <: AbstractPolarization end """ Concrete type indicating that a [`BosonLike`](@ref) has an indefinite polarization and the differential cross section calculation should average or sum over all polarizations, depending on the direction ([`Incoming`](@ref) or [`Outgoing`](@ref)) of the particle in question. +```jldoctest +julia> using QEDbase + +julia> AllPol() +all polarizations +``` + !!! info "Alias" There is a built-in alias for `AllPolarization`: @@ -86,10 +117,18 @@ Concrete type indicating that a [`BosonLike`](@ref) has an indefinite polarizati """ struct AllPolarization <: AbstractIndefinitePolarization end const AllPol = AllPolarization +Base.show(io::IO, ::AllPol) = print(io, "all polarizations") """ Concrete type which indicates, that a [`BosonLike`](@ref) has polarization in ``x``-direction. +```jldoctest +julia> using QEDbase + +julia> PolX() +x-polarized +``` + !!! note "Coordinate axes" The notion of axes, e.g. ``x``- and ``y``-direction is just to distinguish two orthogonal polarization directions. @@ -107,10 +146,18 @@ Concrete type which indicates, that a [`BosonLike`](@ref) has polarization in `` """ struct PolarizationX <: AbstractDefinitePolarization end const PolX = PolarizationX +Base.show(io::IO, ::PolX) = print(io, "x-polarized") """ Concrete type which indicates, that a [`BosonLike`](@ref) has polarization in ``y``-direction. +```jldoctest +julia> using QEDbase + +julia> PolY() +y-polarized +``` + !!! note "Coordinate axes" The notion of axes, e.g. ``x``- and ``y``-direction is just to distinguish two orthogonal polarization directions. @@ -128,3 +175,4 @@ Concrete type which indicates, that a [`BosonLike`](@ref) has polarization in `` """ struct PolarizationY <: AbstractDefinitePolarization end const PolY = PolarizationY +Base.show(io::IO, ::PolY) = print(io, "y-polarized") diff --git a/src/particles/particle_types.jl b/src/particles/particle_types.jl index 9a9e6dc..16282e1 100644 --- a/src/particles/particle_types.jl +++ b/src/particles/particle_types.jl @@ -82,6 +82,13 @@ is_anti_particle(::MajoranaFermion) = true """ Concrete type for *electrons* as a particle species. Mostly used for dispatch. +```jldoctest +julia> using QEDbase + +julia> Electron() +electron +``` + !!! note "particle interface" Besides being a subtype of [`Fermion`](@ref), objects of type `Electron` have @@ -93,10 +100,18 @@ Concrete type for *electrons* as a particle species. Mostly used for dispatch. struct Electron <: Fermion end mass(::Electron) = 1.0 charge(::Electron) = -1.0 +Base.show(io::IO, ::Electron) = print(io, "electron") """ Concrete type for *positrons* as a particle species. Mostly used for dispatch. +```jldoctest +julia> using QEDbase + +julia> Positron() +positron +``` + !!! note "particle interface" Besides being a subtype of [`AntiFermion`](@ref), objects of type `Positron` have @@ -109,6 +124,7 @@ Concrete type for *positrons* as a particle species. Mostly used for dispatch. struct Positron <: AntiFermion end mass(::Positron) = 1.0 charge(::Positron) = 1.0 +Base.show(io::IO, ::Positron) = print(io, "positron") """ Abstract base types for particle species that act like bosons in the sense of particle statistics. @@ -171,6 +187,13 @@ is_anti_particle(::MajoranaBoson) = true """ Concrete type for the *photons* as a particle species. Mostly used for dispatch. +```jldoctest +julia> using QEDbase + +julia> Photon() +photon +``` + !!! note "particle interface" Besides being a subtype of `MajoranaBoson`, `Photon` has @@ -183,3 +206,4 @@ Concrete type for the *photons* as a particle species. Mostly used for dispatch. struct Photon <: MajoranaBoson end mass(::Photon) = 0.0 charge(::Photon) = 0.0 +Base.show(io::IO, ::Photon) = print(io, "photon") From 2b3905aad4a984cf4cc2cd2f0cd4058ca2615ec9 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Wed, 8 May 2024 20:18:05 +0200 Subject: [PATCH 2/2] Only overload 3 argument show --- src/particles/particle_direction.jl | 4 ++-- src/particles/particle_spin_pol.jl | 12 ++++++------ src/particles/particle_types.jl | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/particles/particle_direction.jl b/src/particles/particle_direction.jl index b213f51..9c25b16 100644 --- a/src/particles/particle_direction.jl +++ b/src/particles/particle_direction.jl @@ -26,7 +26,7 @@ incoming struct Incoming <: ParticleDirection end is_incoming(::Incoming) = true is_outgoing(::Incoming) = false -Base.show(io::IO, ::Incoming) = print(io, "incoming") +Base.show(io::IO, ::MIME"text/plain", ::Incoming) = print(io, "incoming") """ Outgoing <: ParticleDirection @@ -51,4 +51,4 @@ outgoing struct Outgoing <: ParticleDirection end is_incoming(::Outgoing) = false is_outgoing(::Outgoing) = true -Base.show(io::IO, ::Outgoing) = print(io, "outgoing") +Base.show(io::IO, ::MIME"text/plain", ::Outgoing) = print(io, "outgoing") diff --git a/src/particles/particle_spin_pol.jl b/src/particles/particle_spin_pol.jl index f2826ba..c291c22 100644 --- a/src/particles/particle_spin_pol.jl +++ b/src/particles/particle_spin_pol.jl @@ -33,7 +33,7 @@ spin up ``` """ struct SpinUp <: AbstractDefiniteSpin end -Base.show(io::IO, ::SpinUp) = print(io, "spin up") +Base.show(io::IO, ::MIME"text/plain", ::SpinUp) = print(io, "spin up") """ Concrete type indicating that a [`FermionLike`](@ref) has spin-down. @@ -46,7 +46,7 @@ spin down ``` """ struct SpinDown <: AbstractDefiniteSpin end -Base.show(io::IO, ::SpinDown) = print(io, "spin down") +Base.show(io::IO, ::MIME"text/plain", ::SpinDown) = print(io, "spin down") """ Concrete type indicating that a [`FermionLike`](@ref) has an indefinite spin and the differential cross section calculation should average or sum over all spins, depending on the direction ([`Incoming`](@ref) or [`Outgoing`](@ref)) of the particle in question. @@ -59,7 +59,7 @@ all spins ``` """ struct AllSpin <: AbstractIndefiniteSpin end -Base.show(io::IO, ::AllSpin) = print(io, "all spins") +Base.show(io::IO, ::MIME"text/plain", ::AllSpin) = print(io, "all spins") """ $(TYPEDSIGNATURES) @@ -117,7 +117,7 @@ all polarizations """ struct AllPolarization <: AbstractIndefinitePolarization end const AllPol = AllPolarization -Base.show(io::IO, ::AllPol) = print(io, "all polarizations") +Base.show(io::IO, ::MIME"text/plain", ::AllPol) = print(io, "all polarizations") """ Concrete type which indicates, that a [`BosonLike`](@ref) has polarization in ``x``-direction. @@ -146,7 +146,7 @@ x-polarized """ struct PolarizationX <: AbstractDefinitePolarization end const PolX = PolarizationX -Base.show(io::IO, ::PolX) = print(io, "x-polarized") +Base.show(io::IO, ::MIME"text/plain", ::PolX) = print(io, "x-polarized") """ Concrete type which indicates, that a [`BosonLike`](@ref) has polarization in ``y``-direction. @@ -175,4 +175,4 @@ y-polarized """ struct PolarizationY <: AbstractDefinitePolarization end const PolY = PolarizationY -Base.show(io::IO, ::PolY) = print(io, "y-polarized") +Base.show(io::IO, ::MIME"text/plain", ::PolY) = print(io, "y-polarized") diff --git a/src/particles/particle_types.jl b/src/particles/particle_types.jl index 16282e1..860c9aa 100644 --- a/src/particles/particle_types.jl +++ b/src/particles/particle_types.jl @@ -100,7 +100,7 @@ electron struct Electron <: Fermion end mass(::Electron) = 1.0 charge(::Electron) = -1.0 -Base.show(io::IO, ::Electron) = print(io, "electron") +Base.show(io::IO, ::MIME"text/plain", ::Electron) = print(io, "electron") """ Concrete type for *positrons* as a particle species. Mostly used for dispatch. @@ -124,7 +124,7 @@ positron struct Positron <: AntiFermion end mass(::Positron) = 1.0 charge(::Positron) = 1.0 -Base.show(io::IO, ::Positron) = print(io, "positron") +Base.show(io::IO, ::MIME"text/plain", ::Positron) = print(io, "positron") """ Abstract base types for particle species that act like bosons in the sense of particle statistics. @@ -206,4 +206,4 @@ photon struct Photon <: MajoranaBoson end mass(::Photon) = 0.0 charge(::Photon) = 0.0 -Base.show(io::IO, ::Photon) = print(io, "photon") +Base.show(io::IO, ::MIME"text/plain", ::Photon) = print(io, "photon")