diff --git a/src/QEDprocesses.jl b/src/QEDprocesses.jl index b595481..5963892 100644 --- a/src/QEDprocesses.jl +++ b/src/QEDprocesses.jl @@ -1,9 +1,5 @@ module QEDprocesses -export AbstractParticle -export is_fermion, is_boson, is_particle, is_anti_particle -export mass, charge - # Abstract model interface export AbstractModelDefinition, fundamental_interaction_type @@ -17,19 +13,11 @@ export differential_cross_section, total_cross_section export AbstractComputationSetup, InvalidInputError, compute export AbstractProcessSetup, scattering_process, physical_model -# particle types -export AbstractParticleType -export FermionLike, Fermion, AntiFermion, MajoranaFermion -export BosonLike, Boson, AntiBoson, MajoranaBoson -export Electron, Positron, Photon - using DocStringExtensions using QEDbase include("utils.jl") -include("interfaces/particle_interface.jl") include("interfaces/model_interface.jl") include("interfaces/process_interface.jl") include("interfaces/setup_interface.jl") -include("particle_types.jl") end diff --git a/src/interfaces/particle_interface.jl b/src/interfaces/particle_interface.jl deleted file mode 100644 index 1f95ef7..0000000 --- a/src/interfaces/particle_interface.jl +++ /dev/null @@ -1,80 +0,0 @@ -############### -# The paricle interface -# -# In this file, we define the interface for working with particles in a general -# sense. -############### - - -""" -Abstract base type for every type which might be considered a *particle* in the context of `QED.jl`. For every (concrete) subtype of `AbstractParticle`, there are two kinds of interface functions implemented: static functions and property functions. -The static functions provide information on what kind of particle it is (defaults are written in square brackets) - -```julia - is_fermion(::AbstractParticle)::Bool [= false] - is_boson(::AbstractParticle)::Bool [= false] - is_particle(::AbstractParticle)::Bool [= true] - is_anti_particle(::AbstractParticle)::Bool [= false] -``` -If the output of those functions differ from the defaults for a subtype of `AbstractParticle`, these functions need to be overwritten. -The second type of functions define a hard interface for `AbstractParticle`: - -```julia - mass(::AbstractParticle)::Real - charge(::AbstractParticle)::Real -``` -These functions must be implemented in order to have the subtype of `AbstractParticle` work with the functionalities of `QEDprocesses.jl`. -""" -abstract type AbstractParticle end - -""" - $(TYPEDSIGNATURES) - -Interface function for particles. Return `true` if the passed subtype of `AbstractParticle` can be considered a *fermion* in the sense of particle statistics, and `false` otherwise. -The default implementation of `is_fermion` for every subtype of `AbstractParticle` will always return `false`. -""" -is_fermion(::AbstractParticle) = false - -""" - $(TYPEDSIGNATURES) - -Interface function for particles. Return `true` if the passed subtype of `AbstractParticle` can be considered a *boson* in the sense of particle statistics, and `false` otherwise. -The default implementation of `is_boson` for every subtype of `AbstractParticle` will always return `false`. -""" -is_boson(::AbstractParticle) = false - -""" - $(TYPEDSIGNATURES) - -Interface function for particles. Return `true` if the passed subtype of `AbstractParticle` can be considered a *particle* as distinct from anti-particles, and `false` otherwise. -The default implementation of `is_particle` for every subtype of `AbstractParticle` will always return `true`. -""" -is_particle(::AbstractParticle) = true - -""" - $(TYPEDSIGNATURES) - -Interface function for particles. Return true if the passed subtype of `AbstractParticle` can be considered an *anti particle* as distinct from their particle counterpart, and `false` otherwise. -The default implementation of `is_anti_particle` for every subtype of `AbstractParticle` will always return `false`. -""" -is_anti_particle(::AbstractParticle) = false - -""" - - mass(particle::AbstractParticle)::Real - -Interface function for particles. Return the rest mass of a particle (in units of the electron mass). - -This needs to be implemented for each concrete subtype of `AbstractParticle`. -""" -function mass end - -""" - - charge(::AbstractParticle)::Real - -Interface function for particles. Return the electric charge of a particle (in units of the elementary electric charge). - -This needs to be implemented for each concrete subtype of `AbstractParticle`. -""" -function charge end diff --git a/src/interfaces/setup_interface.jl b/src/interfaces/setup_interface.jl index 19e8122..035f3b9 100644 --- a/src/interfaces/setup_interface.jl +++ b/src/interfaces/setup_interface.jl @@ -98,7 +98,7 @@ Interface function, which asserts that the given `input` is valid, and throws an ```Julia _assert_valid_input(stp::YourCustomSetup,input) ``` - which should throw an exception, which is a subtype of [`AbstractInvalidInputError`](@ref). One may also use the concrete implementation [`InvalidInputError`](@ref) if the input is invalid instead of writing a custom exception type. + which should throw an exception, which is a subtype of [`AbstractInvalidInputException`](@ref). One may also use the concrete implementation [`InvalidInputError`](@ref) if the input is invalid instead of writing a custom exception type. """ @inline function _assert_valid_input(stp::AbstractComputationSetup, input) diff --git a/src/particle_types.jl b/src/particle_types.jl deleted file mode 100644 index 10580ef..0000000 --- a/src/particle_types.jl +++ /dev/null @@ -1,192 +0,0 @@ -############### -# The particle types -# -# In this file, we define the types of particles used in `QEDprocesses.jl` and -# implement the abstact particle interface accordingly. -############### - -""" - AbstractParticleType <: AbstractParticle - -This is the abstract base type for every species of particles. All functionalities defined on subtypes of `AbstractParticleType` should be static, i.e. known at compile time. -For adding runtime information, e.g. four-momenta or particle states, to a particle, consider implementing a concrete subtype of `AbstractParticle` instead, which may have a type parameter `P<:AbstractParticleType`. See the concrete type `Particle{P,ST,MT}` - -Concrete built-in subtypes of `AbstractParticleType` are - -```julia - Electron - Positron - Photon -``` - -""" -abstract type AbstractParticleType <: AbstractParticle end - -""" -Abstract base types for particle species that act like fermions in the sense of particle statistics. - -!!! note "particle interface" - Every concrete subtype of `FermionLike` has `is_fermion(::FermionLike) = true`. -""" -abstract type FermionLike <: AbstractParticleType end - -Base.@pure is_fermion(::FermionLike) = true - -""" -Abstract base type for fermions as distinct from anti-fermions. - -!!! note "particle interface" - All subtypes of `Fermion` have - ```julia - is_fermion(::Fermion) = true - is_particle(::Fermion) = true - is_anti_particle(::Fermion) = false - ``` - -""" -abstract type Fermion <: FermionLike end - -is_particle(::Fermion) = true - -is_anti_particle(::Fermion) = false - -""" -Abstract base type for anti-fermions as distinct from its particle counterpart `Fermion`. - -!!! note "particle interface" - All subtypes of `AntiFermion` have - ```julia - is_fermion(::AntiFermion) = true - is_particle(::AntiFermion) = false - is_anti_particle(::AntiFermion) = true - ``` - -""" -abstract type AntiFermion <: FermionLike end - -is_particle(::AntiFermion) = false - -is_anti_particle(::AntiFermion) = true - -""" -Abstract base type for majorana-fermions, i.e. fermions which are their own anti-particles. - -!!! note "particle interface" - All subtypes of `MajoranaFermion` have - ```julia - is_fermion(::MajoranaFermion) = true - is_particle(::MajoranaFermion) = true - is_anti_particle(::MajoranaFermion) = true - ``` - -""" -abstract type MajoranaFermion <: FermionLike end - -is_particle(::MajoranaFermion) = true - -is_anti_particle(::MajoranaFermion) = true - -""" -Concrete type for *electrons* as a particle species. Mostly used for dispatch. - -!!! note "particle interface" - Besides being a subtype of `Fermion`, objects of type `Electron` have - - ```julia - mass(::Electron) = 1.0 - charge(::Electron) = -1.0 - ``` -""" -struct Electron <: Fermion end -mass(::Electron) = 1.0 -charge(::Electron) = -1.0 - -""" -Concrete type for *positrons* as a particle species. Mostly used for dispatch. - -!!! note "particle interface" - Besides being a subtype of `AntiFermion`, objects of type `Positron` have - - ```julia - mass(::Positron) = 1.0 - charge(::Positron) = 1.0 - ``` - -""" -struct Positron <: AntiFermion end -mass(::Positron) = 1.0 -charge(::Positron) = 1.0 - -""" -Abstract base types for particle species that act like bosons in the sense of particle statistics. - -!!! note "particle interface" - Every concrete subtype of `BosonLike` has `is_boson(::BosonLike) = true`. -""" -abstract type BosonLike <: AbstractParticleType end - -is_boson(::BosonLike) = true - -""" -Abstract base type for bosons as distinct from its anti-particle counterpart `AntiBoson`. - -!!! note "particle interface" - All subtypes of `Boson` have - ```julia - is_boson(::Boson) = true - is_particle(::Boson) = true - is_anti_particle(::Boson) = false - ``` - -""" -abstract type Boson <: BosonLike end -is_particle(::Boson) = true -is_anti_particle(::Boson) = false - -""" -Abstract base type for anti-bosons as distinct from its particle counterpart `Bosons`. - -!!! note "particle interface" - All subtypes of `AntiBoson` have - ```julia - is_boson(::AntiBoson) = true - is_particle(::AntiBoson) = false - is_anti_particle(::AntiBoson) = true - ``` - -""" -abstract type AntiBoson <: BosonLike end -is_particle(::AntiBoson) = false -is_anti_particle(::AntiBoson) = true - -""" -Abstract base type for majorana-bosons, i.e. bosons which are their own anti-particles. - -!!! note "particle interface" - All subtypes of `MajoranaBoson` have - ```julia - is_boson(::MajoranaBoson) = true - is_particle(::MajoranaBoson) = true - is_anti_particle(::MajoranaBoson) = true - ``` - -""" -abstract type MajoranaBoson <: BosonLike end -is_particle(::MajoranaBoson) = true -is_anti_particle(::MajoranaBoson) = true - -""" -Concrete type for the *photons* as a particle species. Mostly used for dispatch. - -!!! note "particle interface" - Besides being a subtype of `MajoranaBoson`, `Photon` has - - ```julia - mass(::Photon) = 0.0 - charge(::Photon) = 0.0 - ``` - -""" -struct Photon <: MajoranaBoson end -mass(::Photon) = 0.0 -charge(::Photon) = 0.0 diff --git a/test/interfaces/particle_interface.jl b/test/interfaces/particle_interface.jl deleted file mode 100644 index d803b18..0000000 --- a/test/interfaces/particle_interface.jl +++ /dev/null @@ -1,30 +0,0 @@ - -using Random -using QEDprocesses - -RNG = MersenneTwister(137137137) - -RND_MASS = rand(RNG) -RND_CHARGE = rand(RNG) - -struct TestParticle <: AbstractParticle end -QEDprocesses.mass(::TestParticle) = RND_MASS -QEDprocesses.charge(::TestParticle) = RND_CHARGE - -@testset "default interface" begin - @test !is_fermion(TestParticle()) - @test !is_boson(TestParticle()) - @test is_particle(TestParticle()) - @test !is_anti_particle(TestParticle()) -end - -@testset "hard interface" begin - @test mass(TestParticle()) == RND_MASS - @test charge(TestParticle()) == RND_CHARGE -end - -struct TestParticle_FAIL <: AbstractParticle end -@testset "interface fail" begin - @test_throws MethodError charge(TestParticle_FAIL()) - @test_throws MethodError mass(TestParticle_FAIL()) -end diff --git a/test/particle_types.jl b/test/particle_types.jl deleted file mode 100644 index cf59607..0000000 --- a/test/particle_types.jl +++ /dev/null @@ -1,75 +0,0 @@ -using QEDprocesses - -@testset "fermion likes" begin - @testset "fermion" begin - struct TestFermion <: Fermion end - @test is_fermion(TestFermion()) - @test is_particle(TestFermion()) - @test !is_anti_particle(TestFermion()) - end - - @testset "antifermion" begin - struct TestAntiFermion <: AntiFermion end - @test is_fermion(TestAntiFermion()) - @test !is_particle(TestAntiFermion()) - @test is_anti_particle(TestAntiFermion()) - end - - @testset "majorana fermion" begin - struct TestMajoranaFermion <: MajoranaFermion end - @test is_fermion(TestMajoranaFermion()) - @test is_particle(TestMajoranaFermion()) - @test is_anti_particle(TestMajoranaFermion()) - end - - @testset "electron" begin - @test is_fermion(Electron()) - @test is_particle(Electron()) - @test !is_anti_particle(Electron()) - @test mass(Electron()) == 1.0 - @test charge(Electron()) == -1.0 - end - - @testset "positron" begin - @test is_fermion(Positron()) - @test !is_particle(Positron()) - @test is_anti_particle(Positron()) - @test mass(Positron()) == 1.0 - @test charge(Positron()) == 1.0 - end -end - -@testset "boson likes" begin - @testset "boson" begin - struct TestBoson <: Boson end - @test !is_fermion(TestBoson()) - @test is_boson(TestBoson()) - @test is_particle(TestBoson()) - @test !is_anti_particle(TestBoson()) - end - - @testset "antiboson" begin - struct TestAntiBoson <: AntiBoson end - @test !is_fermion(TestAntiBoson()) - @test is_boson(TestAntiBoson()) - @test !is_particle(TestAntiBoson()) - @test is_anti_particle(TestAntiBoson()) - end - - @testset "majorana boson" begin - struct TestMajoranaBoson <: MajoranaBoson end - @test !is_fermion(TestMajoranaBoson()) - @test is_boson(TestMajoranaBoson()) - @test is_particle(TestMajoranaBoson()) - @test is_anti_particle(TestMajoranaBoson()) - end - - @testset "photon" begin - @test !is_fermion(Photon()) - @test is_boson(Photon()) - @test is_particle(Photon()) - @test is_anti_particle(Photon()) - @test charge(Photon()) == 0.0 - @test mass(Photon()) == 0.0 - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 4771120..90bf7b3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,9 +4,6 @@ using SafeTestsets begin # Interfaces - @time @safetestset "particle interface" begin - include("interfaces/particle_interface.jl") - end @time @safetestset "model interface" begin include("interfaces/model_interface.jl") end @@ -18,7 +15,4 @@ begin end # modules - @time @safetestset "particles types" begin - include("particle_types.jl") - end end