diff --git a/src/QEDprocesses.jl b/src/QEDprocesses.jl index 2f6c362..5b78ed9 100644 --- a/src/QEDprocesses.jl +++ b/src/QEDprocesses.jl @@ -25,14 +25,6 @@ using QuadGK include("constants.jl") include("utils.jl") -include("phase_spaces/types.jl") -include("phase_spaces/access.jl") -include("phase_spaces/create.jl") -include("phase_spaces/print.jl") -include("phase_spaces/utility.jl") - -include("propagators.jl") - include("cross_section/diff_probability.jl") include("cross_section/diff_cross_section.jl") include("cross_section/total_probability.jl") diff --git a/src/patch_QEDbase.jl b/src/patch_QEDbase.jl index c241543..3da67e1 100644 --- a/src/patch_QEDbase.jl +++ b/src/patch_QEDbase.jl @@ -3,28 +3,3 @@ # remove if this went into `QEDbase.jl` # ############# - -# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/61 -Base.show(io::IO, ::Electron) = print(io, "electron") -Base.show(io::IO, ::Positron) = print(io, "positron") -Base.show(io::IO, ::Photon) = print(io, "photon") -Base.show(io::IO, ::QEDbase.Incoming) = print(io, "incoming") -Base.show(io::IO, ::QEDbase.Outgoing) = print(io, "outgoing") -Base.show(io::IO, ::QEDbase.PolX) = print(io, "x-polarized") -Base.show(io::IO, ::QEDbase.PolY) = print(io, "y-polarized") -Base.show(io::IO, ::QEDbase.AllPol) = print(io, "all polarizations") -Base.show(io::IO, ::QEDbase.SpinUp) = print(io, "spin up") -Base.show(io::IO, ::QEDbase.SpinDown) = print(io, "spin down") -Base.show(io::IO, ::QEDbase.AllSpin) = print(io, "all spins") - -# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/62 -Broadcast.broadcastable(dir::QEDbase.Incoming) = Ref(dir) -Broadcast.broadcastable(dir::QEDbase.Outgoing) = Ref(dir) -Broadcast.broadcastable(part::QEDbase.AbstractParticleType) = Ref(part) -Broadcast.broadcastable(spin_or_pol::QEDbase.AbstractSpinOrPolarization) = Ref(spin_or_pol) - -# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/63 -number_of_spin_pol(::QEDbase.AbstractDefinitePolarization) = 1 -number_of_spin_pol(::QEDbase.AbstractDefiniteSpin) = 1 -number_of_spin_pol(::QEDbase.AbstractIndefinitePolarization) = 2 -number_of_spin_pol(::QEDbase.AbstractIndefiniteSpin) = 2 diff --git a/src/propagators.jl b/src/propagators.jl deleted file mode 100644 index 77cd66e..0000000 --- a/src/propagators.jl +++ /dev/null @@ -1,35 +0,0 @@ -############### -# Propagators -# -# This file contains implementations for the fermion and boson propagators. -#### - -import QEDbase: propagator - -function _scalar_propagator(K::QEDbase.AbstractFourMomentum, mass::Real) - return one(mass) / (K * K - mass^2) -end - -function _scalar_propagator(K::QEDbase.AbstractFourMomentum) - return one(QEDbase.getT(K)) / (K * K) -end - -function _fermion_propagator(P::QEDbase.AbstractFourMomentum, mass::Real) - return (slashed(P) + mass * one(DiracMatrix)) * _scalar_propagator(P, mass) -end - -function _fermion_propagator(P::QEDbase.AbstractFourMomentum) - return (slashed(P)) * _scalar_propagator(P) -end - -function propagator(particle_type::BosonLike, K::QEDbase.AbstractFourMomentum) - return _scalar_propagator(K, mass(particle_type)) -end - -function propagator(particle_type::Photon, K::QEDbase.AbstractFourMomentum) - return _scalar_propagator(K) -end - -function propagator(particle_type::FermionLike, P::QEDbase.AbstractFourMomentum) - return _fermion_propagator(P, mass(particle_type)) -end diff --git a/test/phase_spaces.jl b/test/phase_spaces.jl deleted file mode 100644 index a039c43..0000000 --- a/test/phase_spaces.jl +++ /dev/null @@ -1,262 +0,0 @@ -using Random -using StaticArrays -using QEDbase: QEDbase -using QEDcore -using QEDprocesses - -# can be removed when QEDbase exports them -import QEDbase.is_incoming, QEDbase.is_outgoing - -include("test_implementation/TestImplementation.jl") -TESTMODEL = TestImplementation.TestModel() -TESTPSDEF = TestImplementation.TestPhasespaceDef() - -RNG = Random.MersenneTwister(727) -BUF = IOBuffer() - -@testset "broadcast" begin - test_func(ps_def) = ps_def - @test test_func.(TESTPSDEF) == TESTPSDEF -end - -@testset "Stateful Particle" begin - DIRECTIONS = [QEDbase.Incoming(), QEDbase.Outgoing()] - SPECIES = [Electron(), Positron()] #=, Muon(), AntiMuon(), Tauon(), AntiTauon()=# - - for (species, dir) in Iterators.product(SPECIES, DIRECTIONS) - mom = rand(RNG, SFourMomentum) - - particle_stateful = ParticleStateful(dir, species, mom) - - # particle interface - @test QEDbase.is_fermion(particle_stateful) == QEDbase.is_fermion(species) - @test QEDbase.is_boson(particle_stateful) == QEDbase.is_boson(species) - @test QEDbase.is_particle(particle_stateful) == QEDbase.is_particle(species) - @test QEDbase.is_anti_particle(particle_stateful) == - QEDbase.is_anti_particle(species) - @test QEDbase.is_incoming(particle_stateful) == QEDbase.is_incoming(dir) - @test QEDbase.is_outgoing(particle_stateful) == QEDbase.is_outgoing(dir) - @test QEDbase.mass(particle_stateful) == QEDbase.mass(species) - @test QEDbase.charge(particle_stateful) == QEDbase.charge(species) - - # accessors - @test particle_stateful.dir == dir - @test particle_direction(particle_stateful) == particle_stateful.dir - @test particle_stateful.species == species - @test particle_species(particle_stateful) == particle_stateful.species - @test particle_stateful.mom == mom - @test momentum(particle_stateful) == mom - - # printing - print(BUF, particle_stateful) - @test String(take!(BUF)) == "$(dir) $(species): $(mom)" - - show(BUF, MIME"text/plain"(), particle_stateful) - @test String(take!(BUF)) == - "ParticleStateful: $(dir) $(species)\n momentum: $(mom)\n" - end -end - -@testset "Phasespace Point" begin - in_el_mom = rand(RNG, SFourMomentum) - in_ph_mom = rand(RNG, SFourMomentum) - out_el_mom = rand(RNG, SFourMomentum) - out_ph_mom = rand(RNG, SFourMomentum) - - in_el = ParticleStateful(QEDbase.Incoming(), Electron(), in_el_mom) - in_ph = ParticleStateful(QEDbase.Incoming(), Photon(), in_ph_mom) - out_el = ParticleStateful(QEDbase.Outgoing(), Electron(), out_el_mom) - out_ph = ParticleStateful(QEDbase.Outgoing(), Photon(), out_ph_mom) - - in_particles_valid = (in_el, in_ph) - in_particles_invalid = (in_el, out_ph) - - out_particles_valid = (out_el, out_ph) - out_particles_invalid = (out_el, in_ph) - - model = TESTMODEL - process = TestImplementation.TestProcess((Electron(), Photon()), (Electron(), Photon())) - phasespace_def = TESTPSDEF - - psp = PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, out_particles_valid - ) - - take!(BUF) - print(BUF, psp) - @test String(take!(BUF)) == "PhaseSpacePoint of $(process)" - - show(BUF, MIME"text/plain"(), psp) - @test match( - r"PhaseSpacePoint:\n process: (.*)TestProcess(.*)\n model: (.*)TestModel(.*)\n phasespace definition: (.*)TestPhasespaceDef(.*)\n incoming particles:\n -> incoming electron: (.*)\n -> incoming photon: (.*)\n outgoing particles:\n -> outgoing electron: (.*)\n -> outgoing photon: (.*)\n", - String(take!(BUF)), - ) isa RegexMatch - - @testset "Accessor" begin - @test momentum(psp, QEDbase.Incoming(), 1) == in_el.mom - @test momentum(psp, QEDbase.Incoming(), 2) == in_ph.mom - @test momentum(psp, QEDbase.Outgoing(), 1) == out_el.mom - @test momentum(psp, QEDbase.Outgoing(), 2) == out_ph.mom - - @test psp[QEDbase.Incoming(), 1] == in_el - @test psp[QEDbase.Incoming(), 2] == in_ph - @test psp[QEDbase.Outgoing(), 1] == out_el - @test psp[QEDbase.Outgoing(), 2] == out_ph - end - - @testset "Error handling" begin - if (VERSION >= v"1.8") - # julia versions before 1.8 did not have support for regex matching in @test_throws - @test_throws r"expected incoming photon but got outgoing photon" PhaseSpacePoint( - process, model, phasespace_def, in_particles_invalid, out_particles_valid - ) - - @test_throws r"expected outgoing photon but got incoming photon" PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, out_particles_invalid - ) - - @test_throws r"expected incoming electron but got incoming photon" PhaseSpacePoint( - process, model, phasespace_def, (in_ph, in_el), out_particles_valid - ) - - @test_throws r"expected outgoing electron but got outgoing photon" PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, (out_ph, out_el) - ) - - @test_throws r"expected 2 outgoing particles for the process but got 1" PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, (out_el,) - ) - - @test_throws r"expected 2 incoming particles for the process but got 1" PhaseSpacePoint( - process, model, phasespace_def, (out_el,), out_particles_valid - ) - - @test_throws r"expected 2 outgoing particles for the process but got 3" PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, (out_el, out_el, out_ph) - ) - - @test_throws r"expected 2 incoming particles for the process but got 3" PhaseSpacePoint( - process, model, phasespace_def, (in_el, in_el, in_ph), out_particles_valid - ) - end - - @test_throws BoundsError momentum(psp, QEDbase.Incoming(), -1) - @test_throws BoundsError momentum(psp, QEDbase.Outgoing(), -1) - @test_throws BoundsError momentum(psp, QEDbase.Incoming(), 4) - @test_throws BoundsError momentum(psp, QEDbase.Outgoing(), 4) - - @test_throws BoundsError psp[QEDbase.Incoming(), -1] - @test_throws BoundsError psp[QEDbase.Outgoing(), -1] - @test_throws BoundsError psp[QEDbase.Incoming(), 4] - @test_throws BoundsError psp[QEDbase.Outgoing(), 4] - - @test_throws InvalidInputError PhaseSpacePoint( - process, model, phasespace_def, in_particles_invalid, out_particles_valid - ) - - @test_throws InvalidInputError PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, out_particles_invalid - ) - - @test_throws InvalidInputError PhaseSpacePoint( - process, model, phasespace_def, (in_ph, in_el), out_particles_valid - ) - - @test_throws InvalidInputError PhaseSpacePoint( - process, model, phasespace_def, in_particles_valid, (out_ph, out_el) - ) - end - - @testset "Generation from momenta" begin - test_psp = PhaseSpacePoint( - process, model, phasespace_def, (in_el_mom, in_ph_mom), (out_el_mom, out_ph_mom) - ) - - @test test_psp.proc == process - @test test_psp.model == model - @test test_psp.ps_def == phasespace_def - - @test test_psp[QEDbase.Incoming(), 1] == in_el - @test test_psp[QEDbase.Incoming(), 2] == in_ph - @test test_psp[QEDbase.Outgoing(), 1] == out_el - @test test_psp[QEDbase.Outgoing(), 2] == out_ph - end - - @testset "Error handling from momenta" for (i, o) in - Iterators.product([1, 3, 4, 5], [1, 3, 4, 5]) - @test_throws InvalidInputError PhaseSpacePoint( - process, - model, - phasespace_def, - TestImplementation._rand_momenta(RNG, i), - TestImplementation._rand_momenta(RNG, o), - ) - end - - @testset "Directional PhaseSpacePoint" begin - @test psp isa PhaseSpacePoint - @test psp isa InPhaseSpacePoint - @test psp isa OutPhaseSpacePoint - - in_psp = InPhaseSpacePoint(process, model, phasespace_def, in_particles_valid) - out_psp = OutPhaseSpacePoint(process, model, phasespace_def, out_particles_valid) - in_psp_from_moms = InPhaseSpacePoint( - process, model, phasespace_def, (in_el_mom, in_ph_mom) - ) - out_psp_from_moms = OutPhaseSpacePoint( - process, model, phasespace_def, (out_el_mom, out_ph_mom) - ) - - @test in_psp isa InPhaseSpacePoint - @test !(in_psp isa OutPhaseSpacePoint) - @test in_psp_from_moms isa InPhaseSpacePoint - @test !(in_psp_from_moms isa OutPhaseSpacePoint) - - @test out_psp isa OutPhaseSpacePoint - @test !(out_psp isa InPhaseSpacePoint) - @test out_psp_from_moms isa OutPhaseSpacePoint - @test !(out_psp_from_moms isa InPhaseSpacePoint) - - @test_throws InvalidInputError InPhaseSpacePoint( - process, model, phasespace_def, in_particles_invalid - ) - @test_throws InvalidInputError OutPhaseSpacePoint( - process, model, phasespace_def, out_particles_invalid - ) - - @testset "Error handling from momenta" for i in [1, 3, 4, 5] - @test_throws InvalidInputError InPhaseSpacePoint( - process, model, phasespace_def, TestImplementation._rand_momenta(RNG, i) - ) - @test_throws InvalidInputError OutPhaseSpacePoint( - process, model, phasespace_def, TestImplementation._rand_momenta(RNG, i) - ) - end - end -end - -@testset "Coordinate System" begin - @testset "Pretty printing" begin - print(BUF, SphericalCoordinateSystem()) - @test String(take!(BUF)) == "spherical coordinates" - end -end -@testset "Reference Frame" begin - @testset "Pretty printing" begin - print(BUF, ElectronRestFrame()) - @test String(take!(BUF)) == "electron rest frame" - print(BUF, CenterOfMomentumFrame()) - @test String(take!(BUF)) == "center-of-momentum frame" - end -end - -@testset "Phasespace Definition" for (coord_sys, frame) in Iterators.product( - [SphericalCoordinateSystem()], [ElectronRestFrame(), CenterOfMomentumFrame()] -) - ps_def = PhasespaceDefinition(coord_sys, frame) - - @testset "Pretty printing" begin - print(BUF, ps_def) - @test String(take!(BUF)) == "$coord_sys in $frame" - end -end diff --git a/test/propagators.jl b/test/propagators.jl deleted file mode 100644 index 9dc2f4d..0000000 --- a/test/propagators.jl +++ /dev/null @@ -1,27 +0,0 @@ -using Random -using QEDbase: QEDbase -using QEDcore -using QEDprocesses - -RNG = MersenneTwister(137137) -ATOL = 0.0 -RTOL = sqrt(eps()) - -function _rand_momentum(rng::AbstractRNG) - return SFourMomentum(rand(rng, 4)) -end - -groundtruth_propagator(::Photon, mom) = one(eltype(mom)) / (mom * mom) -function groundtruth_propagator(particle::FermionLike, mom) - return (slashed(mom) + QEDbase.mass(particle) * one(DiracMatrix)) / - (mom * mom - QEDbase.mass(particle)^2) -end - -@testset "propagators" begin - @testset "$P" for P in (Electron(), Positron(), Photon()) - mom = _rand_momentum(RNG) - groundtruth = groundtruth_propagator(P, mom) - test_prop = propagator(P, mom) - @test isapprox(test_prop, groundtruth, atol=ATOL, rtol=RTOL) - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 7fc4a98..e5d7a1e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,17 +4,10 @@ using SafeTestsets begin # modules - @time @safetestset "propagators" begin - include("propagators.jl") - end @time @safetestset "cross section & probability" begin include("cross_sections.jl") end - @time @safetestset "phase spaces" begin - include("phase_spaces.jl") - end - # scattering processes include("processes/run_process_test.jl") end