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

Add pretty printing for particle directions, species, and spin/pol #61

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 16 additions & 0 deletions src/particles/particle_direction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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, ::MIME"text/plain", ::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

Expand All @@ -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, ::MIME"text/plain", ::Outgoing) = print(io, "outgoing")
48 changes: 48 additions & 0 deletions src/particles/particle_spin_pol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, ::MIME"text/plain", ::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, ::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.

```jldoctest
julia> using QEDbase

julia> AllSpin()
all spins
```
"""
struct AllSpin <: AbstractIndefiniteSpin end
Base.show(io::IO, ::MIME"text/plain", ::AllSpin) = print(io, "all spins")

"""
$(TYPEDSIGNATURES)
Expand Down Expand Up @@ -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`:
Expand All @@ -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, ::MIME"text/plain", ::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.
Expand All @@ -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, ::MIME"text/plain", ::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.
Expand All @@ -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, ::MIME"text/plain", ::PolY) = print(io, "y-polarized")
24 changes: 24 additions & 0 deletions src/particles/particle_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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, ::MIME"text/plain", ::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

Expand All @@ -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, ::MIME"text/plain", ::Positron) = print(io, "positron")

"""
Abstract base types for particle species that act like bosons in the sense of particle statistics.
Expand Down Expand Up @@ -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

Expand All @@ -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, ::MIME"text/plain", ::Photon) = print(io, "photon")
Loading