From f143534716b7e650228d438090dc9dfeceb63b93 Mon Sep 17 00:00:00 2001 From: AntonReinhard Date: Fri, 21 Jun 2024 12:45:17 +0200 Subject: [PATCH 1/6] Delete interfaces that move to base and functionality that moves to core --- Project.toml | 3 +- src/QEDprocesses.jl | 43 +-- src/interfaces/model_interface.jl | 27 -- src/interfaces/process_interface.jl | 205 -------------- src/interfaces/setup_interface.jl | 195 ------------- src/models/models.jl | 2 + src/momentum_generation.jl | 54 ---- src/phase_spaces/access.jl | 59 ---- src/phase_spaces/create.jl | 158 ----------- src/phase_spaces/print.jl | 58 ---- src/phase_spaces/types.jl | 177 ------------ src/phase_spaces/utility.jl | 143 ---------- .../one_photon_compton/one_photon_compton.jl | 11 - .../perturbative/cross_section.jl | 3 + .../perturbative/kinematics.jl | 2 + .../perturbative/total_probability.jl | 1 + src/propagators.jl | 29 +- test/interfaces/model_interface.jl | 19 -- test/interfaces/process_interface.jl | 131 --------- test/interfaces/setup_interface.jl | 190 ------------- test/runtests.jl | 13 - .../test_implementation/TestImplementation.jl | 40 --- test/test_implementation/groundtruths.jl | 265 ------------------ test/test_implementation/random_momenta.jl | 83 ------ test/test_implementation/test_model.jl | 5 - test/test_implementation/test_process.jl | 131 --------- test/test_implementation/utils.jl | 44 --- 27 files changed, 16 insertions(+), 2075 deletions(-) delete mode 100644 src/interfaces/model_interface.jl delete mode 100644 src/interfaces/process_interface.jl delete mode 100644 src/interfaces/setup_interface.jl delete mode 100644 src/momentum_generation.jl delete mode 100644 src/phase_spaces/access.jl delete mode 100644 src/phase_spaces/create.jl delete mode 100644 src/phase_spaces/print.jl delete mode 100644 src/phase_spaces/types.jl delete mode 100644 src/phase_spaces/utility.jl delete mode 100644 src/processes/one_photon_compton/one_photon_compton.jl delete mode 100644 test/interfaces/model_interface.jl delete mode 100644 test/interfaces/process_interface.jl delete mode 100644 test/interfaces/setup_interface.jl delete mode 100644 test/test_implementation/TestImplementation.jl delete mode 100644 test/test_implementation/groundtruths.jl delete mode 100644 test/test_implementation/random_momenta.jl delete mode 100644 test/test_implementation/test_model.jl delete mode 100644 test/test_implementation/test_process.jl delete mode 100644 test/test_implementation/utils.jl diff --git a/Project.toml b/Project.toml index 15df20c..a6aaba1 100644 --- a/Project.toml +++ b/Project.toml @@ -23,8 +23,7 @@ julia = "1.6" [extras] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" -Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Random", "SafeTestsets", "Suppressor", "Test"] +test = ["Random", "SafeTestsets", "Test"] diff --git a/src/QEDprocesses.jl b/src/QEDprocesses.jl index 8f197f4..2f6c362 100644 --- a/src/QEDprocesses.jl +++ b/src/QEDprocesses.jl @@ -8,40 +8,9 @@ module QEDprocesses export ALPHA, ALPHA_SQUARE, ELEMENTARY_CHARGE, ELEMENTARY_CHARGE_SQUARE, ELECTRONMASS, ONE_OVER_FOURPI -# Abstract model interface -export AbstractModelDefinition, fundamental_interaction_type - -# Abstract process interface -export AbstractProcessDefinition, incoming_particles, outgoing_particles -export number_incoming_particles, number_outgoing_particles -export particles, number_particles - -# probabilities -export differential_probability, unsafe_differential_probability -export total_probability - -# probabilities -export differential_probability, unsafe_differential_probability -export total_probability - -# differential cross section -export differential_cross_section, unsafe_differential_cross_section -export total_cross_section - -# Abstract setup interface -export AbstractComputationSetup, InvalidInputError, compute -export AbstractProcessSetup, scattering_process, physical_model - # propagator export propagator -# phase space -export AbstractCoordinateSystem, SphericalCoordinateSystem -export AbstractFrameOfReference, CenterOfMomentumFrame, ElectronRestFrame -export AbstractPhasespaceDefinition, PhasespaceDefinition -export ParticleStateful, PhaseSpacePoint, InPhaseSpacePoint, OutPhaseSpacePoint -export spin, polarization, particle_direction, particle_species, momentum, momenta, getindex - # specific compute models export PerturbativeQED @@ -56,17 +25,12 @@ using QuadGK include("constants.jl") include("utils.jl") -include("interfaces/model_interface.jl") -include("interfaces/process_interface.jl") -include("interfaces/setup_interface.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("momentum_generation.jl") include("propagators.jl") include("cross_section/diff_probability.jl") @@ -75,7 +39,12 @@ include("cross_section/total_probability.jl") include("cross_section/total_cross_section.jl") include("models/models.jl") -include("processes/one_photon_compton/one_photon_compton.jl") + +# one photon compton +include("processes/one_photon_compton/process.jl") +include("processes/one_photon_compton/perturbative/kinematics.jl") +include("processes/one_photon_compton/perturbative/cross_section.jl") +include("processes/one_photon_compton/perturbative/total_probability.jl") include("patch_QEDbase.jl") end diff --git a/src/interfaces/model_interface.jl b/src/interfaces/model_interface.jl deleted file mode 100644 index e99a558..0000000 --- a/src/interfaces/model_interface.jl +++ /dev/null @@ -1,27 +0,0 @@ -############### -# The model interface -# -# In this file, we define the interface of working with compute models in -# general. -############### -# root type for models -""" -Abstract base type for all compute model definitions in the context of scattering processes. Every subtype of `AbstractModelDefinition` is associated with a fundamental interaction. -Therefore, one needs to implement the following soft interface function - -```Julia -fundamental_interaction_type(::AbstractModelDefinition) -``` -""" -abstract type AbstractModelDefinition end - -# broadcast every model as a scalar -Broadcast.broadcastable(model::AbstractModelDefinition) = Ref(model) - -""" - - fundamental_interaction_type(models_def::AbstractModelDefinition) - -Return the fundamental interaction associated with the passed model definition. -""" -function fundamental_interaction_type end diff --git a/src/interfaces/process_interface.jl b/src/interfaces/process_interface.jl deleted file mode 100644 index 0decb37..0000000 --- a/src/interfaces/process_interface.jl +++ /dev/null @@ -1,205 +0,0 @@ -############### -# The process interface -# -# In this file, we define the interface for working with scattering processes in -# general. -############### - -""" -Abstract base type for definitions of scattering processes. It is the root type for the -process interface, which assumes that every subtype of `AbstractProcessDefinition` -implements at least - -```Julia -incoming_particles(proc_def::AbstractProcessDefinition) -outgoing_particles(proc_def::AbstractProcessDefinition) -``` - -which return a tuple of the incoming and outgoing particles, respectively. - -Furthermore, to calculate scattering probabilities and differential cross sections, the following -interface functions need to be implemented for every combination of `CustomProcess<:AbstractProcessDefinition`, -`CustomModel<:AbstractModelDefinition`, and `CustomPhasespaceDefinition<:AbstractPhasespaceDefinition`. - -```Julia - _incident_flux(psp::InPhaseSpacePoint{CustomProcess,CustomModel}) - - _matrix_element(psp::PhaseSpacePoint{CustomProcess,CustomModel}) - - _averaging_norm(proc::CustomProcess) - - _is_in_phasespace(psp::PhaseSpacePoint{CustomProcess,CustomModel}) - - _phase_space_factor(psp::PhaseSpacePoint{CustomProcess,CustomModel,CustomPhasespaceDefinition}) -``` - -Optional is the implementation of - -```Julia - - _total_probability(psp::PhaseSpacePoint{CustomProcess,CustomModel,CustomPhasespaceDefinition}) - -``` -to enable the calculation of total probabilities and cross sections. - -""" -abstract type AbstractProcessDefinition end - -# broadcast every model as a scalar -Broadcast.broadcastable(proc::AbstractProcessDefinition) = Ref(proc) - -""" - - incoming_particles(proc_def::AbstractProcessDefinition) - -Interface function for scattering processes. Return a tuple of the incoming particles for the given process definition. -This function needs to be given to implement the scattering process interface. -""" -function incoming_particles end - -""" - - outgoing_particles(proc_def::AbstractProcessDefinition) - -Interface function for scattering processes. Return the tuple of outgoing particles for the given process definition. -This function needs to be given to implement the scattering process interface. -""" -function outgoing_particles end - -""" - _incident_flux(in_psp::InPhaseSpacePoint{PROC,MODEL}) where { - PROC <: AbstractProcessDefinition, - MODEL <: AbstractModelDefinition, - } - -Interface function which returns the incident flux of the given scattering process for a given [`InPhaseSpacePoint`](@ref). - -""" -function _incident_flux end - -""" - _matrix_element(PhaseSpacePoint{PROC,MODEL}) where { - PROC <: AbstractProcessDefinition, - MODEL <: AbstractModelDefinition, - } - -Interface function which returns a tuple of scattering matrix elements for each spin and polarization combination of `proc`. -""" -function _matrix_element end - -""" - _averaging_norm(proc::AbstractProcessDefinition) - -Interface function, which returns a normalization for the averaging of the squared matrix elements over spins and polarizations. -""" -function _averaging_norm end - -""" - - _is_in_phasespace(PhaseSpacePoint{PROC,MODEL}) where { - PROC <: AbstractProcessDefinition, - MODEL <: AbstractModelDefinition, - } - -Interface function which returns `true` if the combination of the given incoming and outgoing phase space -is physical, i.e. all momenta are on-shell and some sort of energy-momentum conservation holds. -""" -function _is_in_phasespace end - -""" - _phase_space_factor(PhaseSpacePoint{PROC,MODEL,PSDEF}) where { - PROC <: AbstractProcessDefinition, - MODEL <: AbstractModelDefinition - PSDEF <: AbstractPhasespaceDefinition, - } - -Interface function, which returns the pre-differential factor of the invariant phase space intergral measure. - -!!! note "Convention" - - It is assumed, that this function returns the value of - - ```math - \\mathrm{d}\\Pi_n:= \\prod_{i=1}^N \\frac{\\mathrm{d}^3p_i}{(2\\pi)^3 2 p_i^0} H(P_t, p_1, \\dots, p_N), - ``` -where ``H(\\dots)`` is a characteristic function (or distribution) which constrains the phase space, e.g. ``\\delta^{(4)}(P_t - \\sum_i p_i)``. -""" -function _phase_space_factor end - -####################### -# -# utility functions -# -####################### - -""" - number_incoming_particles(proc_def::AbstractProcessDefinition) - -Return the number of incoming particles of a given process. -""" -@inline function number_incoming_particles(proc_def::AbstractProcessDefinition) - return length(incoming_particles(proc_def)) -end - -""" - number_outgoing_particles(proc_def::AbstractProcessDefinition) - -Return the number of outgoing particles of a given process. -""" -@inline function number_outgoing_particles(proc_def::AbstractProcessDefinition) - return length(outgoing_particles(proc_def)) -end - -""" - particles(proc_def::AbstractProcessDefinition, ::ParticleDirection) - -Convenience function dispatching to [`incoming_particles`](@ref) or [`outgoing_particles`](@ref) depending on the given direction. -""" -@inline particles(proc_def::AbstractProcessDefinition, ::QEDbase.Incoming) = - incoming_particles(proc_def) -@inline particles(proc_def::AbstractProcessDefinition, ::QEDbase.Outgoing) = - outgoing_particles(proc_def) - -""" - number_particles(proc_def::AbstractProcessDefinition, ::ParticleDirection) - -Convenience function dispatching to [`number_incoming_particles`](@ref) or [`number_outgoing_particles`](@ref) depending on the given direction. -""" -@inline number_particles(proc_def::AbstractProcessDefinition, ::QEDbase.Incoming) = - number_incoming_particles(proc_def) -@inline number_particles(proc_def::AbstractProcessDefinition, ::QEDbase.Outgoing) = - number_outgoing_particles(proc_def) - -""" - in_phase_space_dimension( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ) -TBW -""" -function in_phase_space_dimension end - -""" - out_phase_space_dimension( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ) -TBW -""" -function out_phase_space_dimension end - -""" - _total_probability(in_psp::InPhaseSpacePoint{PROC,MODEL}) where { - PROC <: AbstractProcessDefinition, - MODEL <: AbstractModelDefinition, - } - -Interface function for the combination of a scattering process and a physical model. Return the total of a -given process and model for a passed [`InPhaseSpacePoint`](@ref). - -!!! note "total cross section" - - Given an implementation of this method and [`_incident_flux`](@ref), the respective function for the total cross section [`total_cross_section`](@ref) is also available. - -""" -function _total_probability end diff --git a/src/interfaces/setup_interface.jl b/src/interfaces/setup_interface.jl deleted file mode 100644 index ac406f4..0000000 --- a/src/interfaces/setup_interface.jl +++ /dev/null @@ -1,195 +0,0 @@ -############### -# The process setup -# -# In this file, we define the interface for general computation and process setups. -############### - -""" -Abstract base type for computation setups. A *setup* means -a collection of setup data needed to evaluate a dedicated quantity of given -running data. Therefore, each setup is associated with a single quantity, which one may compute using the setup data and the running data. -Despite that, the decomposition into setup and running data is -arbitrary, and this can be used for cases where a subset of the variables a -quantity depends on is kept constant. - -!!! note "Computation setup interface" - - The computation performed using a computation setup is separated into three steps: - - 1. input validation - 2. actual computation - 3. post processing - - where every step has its own interface function (see [`compute`](@ref) for details). - - ## Input validation - - Every subtype of `AbstractComputationSetup` should implement the interface function - - ```Julia - _assert_valid_input(stp::AbstractComputationSetup, input) - ``` - - which should throw and an exception subtyped from [`AbstractInvalidInputException`](@ref) if the `input` is not valid for the computation of the associated quantity (see [`_assert_valid_input`](@ref) for more details). - The default implementation does nothing, i.e. every input is valid by default. Provide a custom implementation if a different behavior is required. - - ## Actual computation - - Every subtype of `AbstractComputationSetup` must at least implement the required interface function - - ```Julia - _compute(stp::AbstractComputationSetup, input) - ``` - - which computes the value of the associated quantity for a given `input` (see [`_compute`](@ref) for more details). - - - ## Post processing - - Every subtype of `AbstractComputationSetup` should implement the interface function - - ```Julia - _post_processing(stp::AbstractComputationSetup, input, result) - ``` - - which performs task after the actual computation, e.g. conversions or normalizations (see [`_post_processing`](@ref) for more details). - -""" -abstract type AbstractComputationSetup end - -# convenience function to check if an object is a computation setup -_is_computation_setup(::AbstractComputationSetup) = true - -""" -Abstract base type for exceptions indicating invalid input. See [`InvalidInputError`](@ref) for a simple concrete implementation. -Concrete implementations should at least implement - -```Julia - -Base.showerror(io::IO, err::CustomInvalidError) where {CustomInvalidError<:AbstractInvalidInputException} - -``` -""" -abstract type AbstractInvalidInputException <: Exception end - -""" - - InvalidInputError(msg::String) - -Exception which is thrown if a given input is invalid, e.g. passed to [`_assert_valid_input`](@ref). -""" -struct InvalidInputError <: AbstractInvalidInputException - msg::String -end -function Base.showerror(io::IO, err::InvalidInputError) - return println(io, "InvalidInputError: $(err.msg)") -end - -""" - - _assert_valid_input(stp::AbstractComputationSetup, input::Any) - -Interface function, which asserts that the given `input` is valid, and throws an [`InvalidInputError`](@ref) if not. - -!!! note "default implementation" - - By default, every input is assumed to be valid. Therefore, this function does nothing. - To customize this behavior, add your own implementation of - - ```Julia - _assert_valid_input(stp::YourCustomSetup,input) - ``` - 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) - return nothing -end - -""" - - function _post_processing(stp::AbstractComputationSetup, input::Any, result::Any) - -Interface function, which is called in [`compute`](@ref) after [`_compute`](@ref) has been called. This function is dedicated to -finalize the result of a computation. - -!!! note "default implementation" - - Since in the case of no post processing the result of [`_compute`](@ref) is unchanged, this function returns `result` by default. - -""" -@inline function _post_processing(stp::AbstractComputationSetup, input, result) - return result -end - -""" - - _compute(stp::AbstractComputationSetup, input::Any) - -Interface function that returns the value of the associated quantity evaluated on `input`, which can be anything the associated quantity is defined to be feasible for. - -!!! note "unsafe implementation" - - This function must be implemented for any subtype of [`AbstractComputationSetup`](@ref). It should not do any input validation or post processing (see [`_assert_valid_input`](@ref) and [`_post_processing`](@ref)), as those two are performed while calling - the safe version of this function [`compute`](@ref). - -""" -function _compute end - -""" - - compute(stp::AbstractComputationSetup, input::Any) - -Return the value of the quantity associated with `stp` for a given `input`. -In addition to the actual call of the associated unsafe version [`_compute`](@ref), -input validation ([`_assert_valid_input`]) and post processing -(using [`_post_processing`](@ref)) are wrapped around the calculation (see [`AbstractComputationSetup`](@ref) for details). -""" -function compute(stp::AbstractComputationSetup, input) - _assert_valid_input(stp, input) - raw_result = _compute(stp, input) - return _post_processing(stp, input, raw_result) -end - -""" -Abstract base type for setups related to combining scattering processes and physical models. -Every subtype of `AbstractProcessSetup` must implement at least the following -interface functions: - -```Julia -scattering_process(::AbstractProcessSetup) -physical_model(::AbstractProcessSetup) -``` - -Derived from these interface functions, the following delegations are provided: - -```Julia -number_incoming_particles(::AbstractProcessSetup) -number_outgoing_particles(::AbstractProcessSetup) -``` - -""" -abstract type AbstractProcessSetup <: AbstractComputationSetup end - -""" - - scattering_process(stp::AbstractProcessSetup) - -Interface function that returns the scattering process associated with `stp`, -i.e. an object which is a subtype of [`AbstractProcessDefinition`](@ref). -""" -function scattering_process end - -""" - - physical_model(stp::AbstractProcessSetup) - -Interface function that returns the physical model associated with `stp`, i.e. -an object which is a subtype of [`AbstractModelDefinition`](@ref). -""" -function physical_model end - -@inline number_incoming_particles(stp::AbstractProcessSetup) = - number_incoming_particles(scattering_process(stp)) -@inline number_outgoing_particles(stp::AbstractProcessSetup) = - number_outgoing_particles(scattering_process(stp)) diff --git a/src/models/models.jl b/src/models/models.jl index f08ce00..1ed8e75 100644 --- a/src/models/models.jl +++ b/src/models/models.jl @@ -1,2 +1,4 @@ +import QEDbase: + in_phase_space_dimension, out_phase_space_dimension, fundamental_interaction_type include("perturbative_qed.jl") diff --git a/src/momentum_generation.jl b/src/momentum_generation.jl deleted file mode 100644 index 7e7d278..0000000 --- a/src/momentum_generation.jl +++ /dev/null @@ -1,54 +0,0 @@ -##### -# Generation of four-momenta from coordinates -# -# This file contains the interface and functionality to compute momenta from -# given coordinates. -##### - -""" - _generate_incoming_momenta - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - phase_space_def::AbstractPhasespaceDefinition, - in_phase_space::NTuple{N,T}, - ) where {N,T<:Real} - -Interface function to generate the four-momenta of the incoming particles from coordinates for a given phase-space definition. -""" -function _generate_incoming_momenta end - -""" - _generate_outgoing_momenta - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - phase_space_def::AbstractPhasespaceDefinition, - out_phase_space::NTuple{N,T}, - ) where {N,T<:Real} - -Interface function to generate the four-momenta of the outgoing particles from coordinates for a given phase-space definition. -""" -function _generate_outgoing_momenta end - -""" - _generate_momenta( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - phase_space_def::AbstractPhasespaceDefinition, - in_phase_space::NTuple{N,T}, - out_phase_space::NTuple{M,T}, -) where {N,M,T<:Real} - -Return four-momenta for incoming and outgoing particles for given coordinate based phase-space points. -""" -function _generate_momenta( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - phase_space_def::AbstractPhasespaceDefinition, - in_phase_space::NTuple{N,T}, - out_phase_space::NTuple{M,T}, -) where {N,M,T<:Real} - in_momenta = _generate_incoming_momenta(proc, model, phase_space_def, in_phase_space) - out_momenta = _generate_outgoing_momenta(proc, model, phase_space_def, out_phase_space) - - return in_momenta, out_momenta -end diff --git a/src/phase_spaces/access.jl b/src/phase_spaces/access.jl deleted file mode 100644 index 3082096..0000000 --- a/src/phase_spaces/access.jl +++ /dev/null @@ -1,59 +0,0 @@ -import QEDbase: - is_particle, - is_anti_particle, - is_fermion, - is_boson, - is_incoming, - is_outgoing, - mass, - charge - -# particle interface -@inline is_incoming(particle::ParticleStateful) = is_incoming(particle.dir) -@inline is_outgoing(particle::ParticleStateful) = is_outgoing(particle.dir) -@inline is_fermion(particle::ParticleStateful) = is_fermion(particle.species) -@inline is_boson(particle::ParticleStateful) = is_boson(particle.species) -@inline is_particle(particle::ParticleStateful) = is_particle(particle.species) -@inline is_anti_particle(particle::ParticleStateful) = is_anti_particle(particle.species) -@inline mass(particle::ParticleStateful) = mass(particle.species) -@inline charge(particle::ParticleStateful) = charge(particle.species) - -# accessors -particle_direction(part::ParticleStateful) = part.dir -particle_species(part::ParticleStateful) = part.species -momentum(part::ParticleStateful) = part.mom - -""" - momenta(psp::PhaseSpacePoint, ::ParticleDirection) - -Return a `Tuple` of all the particles' momenta for the given `ParticleDirection`. -""" -momenta(psp::PhaseSpacePoint, ::QEDbase.Incoming) = momentum.(psp.in_particles) -momenta(psp::PhaseSpacePoint, ::QEDbase.Outgoing) = momentum.(psp.out_particles) - -""" - Base.getindex(psp::PhaseSpacePoint, dir::Incoming, n::Int) - -Overload for the array indexing operator `[]`. Returns the nth incoming particle in this phase space point. -""" -function Base.getindex(psp::PhaseSpacePoint, ::QEDbase.Incoming, n::Int) - return psp.in_particles[n] -end - -""" - Base.getindex(psp::PhaseSpacePoint, dir::Outgoing, n::Int) - -Overload for the array indexing operator `[]`. Returns the nth outgoing particle in this phase space point. -""" -function Base.getindex(psp::PhaseSpacePoint, ::QEDbase.Outgoing, n::Int) - return psp.out_particles[n] -end - -""" - momentum(psp::PhaseSpacePoint, dir::ParticleDirection, n::Int) - -Returns the momentum of the `n`th particle in the given [`PhaseSpacePoint`](@ref) which has direction `dir`. If `n` is outside the valid range for this phase space point, a `BoundsError` is thrown. -""" -function momentum(psp::PhaseSpacePoint, dir::QEDbase.ParticleDirection, n::Int) - return psp[dir, n].mom -end diff --git a/src/phase_spaces/create.jl b/src/phase_spaces/create.jl deleted file mode 100644 index 99d03ef..0000000 --- a/src/phase_spaces/create.jl +++ /dev/null @@ -1,158 +0,0 @@ -# PSP constructors from particle statefuls - -""" - InPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_ps::Tuple{ParticleStateful}, - ) - - Construct a [`PhaseSpacePoint`](@ref) with only input particles from [`ParticleStateful`](@ref)s. The result will be `<: InPhaseSpacePoint` but **not** `<: OutPhaseSpacePoint`. -""" -function InPhaseSpacePoint( - proc::PROC, model::MODEL, ps_def::PSDEF, in_ps::IN_PARTICLES -) where { - PROC<:AbstractProcessDefinition, - MODEL<:AbstractModelDefinition, - PSDEF<:AbstractPhasespaceDefinition, - IN_PARTICLES<:Tuple{Vararg{ParticleStateful}}, -} - return PhaseSpacePoint(proc, model, ps_def, in_ps, ()) -end - -""" - OutPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - out_ps::Tuple{ParticleStateful}, - ) - -Construct a [`PhaseSpacePoint`](@ref) with only output particles from [`ParticleStateful`](@ref)s. The result will be `<: OutPhaseSpacePoint` but **not** `<: InPhaseSpacePoint`. -""" -function OutPhaseSpacePoint( - proc::PROC, model::MODEL, ps_def::PSDEF, out_ps::OUT_PARTICLES -) where { - PROC<:AbstractProcessDefinition, - MODEL<:AbstractModelDefinition, - PSDEF<:AbstractPhasespaceDefinition, - OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}}, -} - return PhaseSpacePoint(proc, model, ps_def, (), out_ps) -end - -# PSP constructors from momenta - -""" - PhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_momenta::NTuple{N,QEDbase.AbstractFourMomentum}, - out_momenta::NTuple{M,QEDbase.AbstractFourMomentum}, - ) - -Construct the phase space point from given momenta of incoming and outgoing particles regarding a given process. -""" -function PhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_momenta::NTuple{N,ELEMENT}, - out_momenta::NTuple{M,ELEMENT}, -) where {N,M,ELEMENT<:QEDbase.AbstractFourMomentum} - in_particles = _build_particle_statefuls(proc, in_momenta, QEDbase.Incoming()) - out_particles = _build_particle_statefuls(proc, out_momenta, QEDbase.Outgoing()) - - return PhaseSpacePoint(proc, model, ps_def, in_particles, out_particles) -end - -""" - InPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_momenta::NTuple{N,QEDbase.AbstractFourMomentum}, - ) - -Construct a [`PhaseSpacePoint`](@ref) with only input particles from given momenta. The result will be `<: InPhaseSpacePoint` but **not** `<: OutPhaseSpacePoint`. -""" -function InPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_momenta::NTuple{N,ELEMENT}, -) where {N,ELEMENT<:QEDbase.AbstractFourMomentum} - in_particles = _build_particle_statefuls(proc, in_momenta, QEDbase.Incoming()) - - return PhaseSpacePoint(proc, model, ps_def, in_particles, ()) -end - -""" - OutPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - out_momenta::NTuple{N,QEDbase.AbstractFourMomentum}, - ) - -Construct a [`PhaseSpacePoint`](@ref) with only output particles from given momenta. The result will be `<: OutPhaseSpacePoint` but **not** `<: InPhaseSpacePoint`. -""" -function OutPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - out_momenta::NTuple{N,ELEMENT}, -) where {N,ELEMENT<:QEDbase.AbstractFourMomentum} - out_particles = _build_particle_statefuls(proc, out_momenta, QEDbase.Outgoing()) - - return PhaseSpacePoint(proc, model, ps_def, (), out_particles) -end - -# PSP constructors from coordinates - -""" - PhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_coords::NTuple{N,Real}, - out_coords::NTuple{M,Real}, - ) - -Construct a [`PhaseSpacePoint`](@ref) from given coordinates by using the [`_generate_momenta`](@ref) interface. -""" -function PhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_coords::NTuple{N,Real}, - out_coords::NTuple{M,Real}, -) where {N,M} - in_ps, out_ps = _generate_momenta(proc, model, ps_def, in_coords, out_coords) - return PhaseSpacePoint(proc, model, ps_def, in_ps, out_ps) -end - -""" - InPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_coords::NTuple{N,Real}, - ) - -Construct a [`PhaseSpacePoint`](@ref) from given coordinates by using the [`_generate_momenta`](@ref) interface. The result will be `<: InPhaseSpacePoint` but **not** `<: OutPhaseSpacePoint`. - -!!! note - A similar function for [`OutPhaseSpacePoint`](@ref) does not exist from coordinates, only a full [`PhaseSpacePoint`](@ref). -""" -function InPhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_coords::NTuple{N,Real}, -) where {N} - in_ps = _generate_incoming_momenta(proc, model, ps_def, in_coords) - return InPhaseSpacePoint(proc, model, ps_def, in_ps) -end diff --git a/src/phase_spaces/print.jl b/src/phase_spaces/print.jl deleted file mode 100644 index e362218..0000000 --- a/src/phase_spaces/print.jl +++ /dev/null @@ -1,58 +0,0 @@ -function Base.show(io::IO, ::SphericalCoordinateSystem) - print(io, "spherical coordinates") - return nothing -end - -function Base.show(io::IO, ::CenterOfMomentumFrame) - print(io, "center-of-momentum frame") - return nothing -end - -function Base.show(io::IO, ::ElectronRestFrame) - print(io, "electron rest frame") - return nothing -end - -function Base.show(io::IO, m::MIME"text/plain", ps_def::PhasespaceDefinition) - println(io, "PhasespaceDefinition") - println(io, " coordinate system: $(ps_def.coord_sys)") - println(io, " frame: $(ps_def.frame)") - return nothing -end - -function Base.show(io::IO, ps_def::PhasespaceDefinition) - print(io, "$(ps_def.coord_sys) in $(ps_def.frame)") - return nothing -end - -function Base.show(io::IO, particle::ParticleStateful) - print(io, "$(particle.dir) $(particle.species): $(particle.mom)") - return nothing -end - -function Base.show(io::IO, m::MIME"text/plain", particle::ParticleStateful) - println(io, "ParticleStateful: $(particle.dir) $(particle.species)") - println(io, " momentum: $(particle.mom)") - return nothing -end - -function Base.show(io::IO, psp::PhaseSpacePoint) - print(io, "PhaseSpacePoint of $(psp.proc)") - return nothing -end - -function Base.show(io::IO, ::MIME"text/plain", psp::PhaseSpacePoint) - println(io, "PhaseSpacePoint:") - println(io, " process: $(psp.proc)") - println(io, " model: $(psp.model)") - println(io, " phasespace definition: $(psp.ps_def)") - println(io, " incoming particles:") - for p in psp.in_particles - println(io, " -> $(p)") - end - println(io, " outgoing particles:") - for p in psp.out_particles - println(io, " -> $(p)") - end - return nothing -end diff --git a/src/phase_spaces/types.jl b/src/phase_spaces/types.jl deleted file mode 100644 index 8e8f6a8..0000000 --- a/src/phase_spaces/types.jl +++ /dev/null @@ -1,177 +0,0 @@ -abstract type AbstractCoordinateSystem end -struct SphericalCoordinateSystem <: AbstractCoordinateSystem end - -abstract type AbstractFrameOfReference end -struct CenterOfMomentumFrame <: AbstractFrameOfReference end -struct ElectronRestFrame <: AbstractFrameOfReference end - -abstract type AbstractPhasespaceDefinition end - -""" - PhasespaceDefinition(coord_sys::AbstractCoordinateSystem, frame::AbstractFrameOfReference) - -Convenient type to dispatch on coordiante systems and frames of reference. -""" -struct PhasespaceDefinition{CS<:AbstractCoordinateSystem,F<:AbstractFrameOfReference} <: - AbstractPhasespaceDefinition - coord_sys::CS - frame::F -end - -Broadcast.broadcastable(ps_def::AbstractPhasespaceDefinition) = Ref(ps_def) - -# abstract type for generic phase spaces -# -# Currently, elements can be either four-momenta, or real numbers, -# i.e. coordinates. -AbstractPhasespaceElement = Union{QEDbase.AbstractFourMomentum,Real} - -""" - ParticleStateful <: AbstractParticle - -Representation of a particle with a state. It has four fields: -- `dir::ParticleDirection`: The direction of the particle, `QEDbase.Incoming()` or `QEDbase.Outgoing()`. -- `species::AbstractParticleType`: The species of the particle, `QEDbase.Electron()`, `QEDbase.Positron()` etc. -- `mom::QEDbase.AbstractFourMomentum`: The momentum of the particle. - -Overloads for `QEDbase.is_fermion`, `QEDbase.is_boson`, `QEDbase.is_particle`, `QEDbase.is_anti_particle`, `QEDbase.is_incoming`, `QEDbase.is_outgoing`, `QEDbase.mass`, and `QEDbase.charge` are provided, delegating the call to the correct field and thus implementing the `QEDbase.AbstractParticle` interface. - -```jldoctest -julia> import QEDbase; using QEDcore; using QEDprocesses - -julia> ParticleStateful(QEDbase.Incoming(), Electron(), SFourMomentum(1, 0, 0, 0)) -ParticleStateful: incoming electron - momentum: [1.0, 0.0, 0.0, 0.0] - -julia> ParticleStateful(QEDbase.Outgoing(), Photon(), SFourMomentum(1, 0, 0, 0)) -ParticleStateful: outgoing photon - momentum: [1.0, 0.0, 0.0, 0.0] -``` -""" -struct ParticleStateful{ - DIR<:QEDbase.ParticleDirection, - SPECIES<:QEDbase.AbstractParticleType, - ELEMENT<:QEDbase.AbstractFourMomentum, -} <: QEDbase.AbstractParticle - dir::DIR - species::SPECIES - mom::ELEMENT - - function ParticleStateful( - dir::DIR, species::SPECIES, mom::ELEMENT - ) where { - DIR<:QEDbase.ParticleDirection, - SPECIES<:QEDbase.AbstractParticleType, - ELEMENT<:QEDbase.AbstractFourMomentum, - } - return new{DIR,SPECIES,ELEMENT}(dir, species, mom) - end -end - -""" - PhaseSpacePoint - -Representation of a point in the phase space of a process. Contains the process ([`AbstractProcessDefinition`](@ref)), the model ([`AbstractModelDefinition`](@ref)), the phase space definition ([`AbstractPhasespaceDefinition`]), and stateful incoming and outgoing particles ([`ParticleStateful`](@ref)). - -The legality of the combination of the given process and the incoming and outgoing particles is checked on construction. If the numbers of particles mismatch, the types of particles mismatch (note that order is important), or incoming particles have an `Outgoing` direction, an error is thrown. - -```jldoctest -julia> using QEDprocesses; import QEDbase; using QEDcore - -julia> PhaseSpacePoint( - Compton(), - PerturbativeQED(), - PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()), - ( - ParticleStateful(QEDbase.Incoming(), Electron(), SFourMomentum(1, 0, 0, 0)), - ParticleStateful(QEDbase.Incoming(), Photon(), SFourMomentum(1, 0, 0, 0)) - ), - ( - ParticleStateful(QEDbase.Outgoing(), Electron(), SFourMomentum(1, 0, 0, 0)), - ParticleStateful(QEDbase.Outgoing(), Photon(), SFourMomentum(1, 0, 0, 0)) - ) - ) -PhaseSpacePoint: - process: one-photon Compton scattering - model: perturbative QED - phasespace definition: spherical coordinates in electron rest frame - incoming particles: - -> incoming electron: [1.0, 0.0, 0.0, 0.0] - -> incoming photon: [1.0, 0.0, 0.0, 0.0] - outgoing particles: - -> outgoing electron: [1.0, 0.0, 0.0, 0.0] - -> outgoing photon: [1.0, 0.0, 0.0, 0.0] -``` - -!!! note - `PhaseSpacePoint`s can be constructed with only one of their in- or out-channel set. For this, see the special constructors [`InPhaseSpacePoint`](@ref) and [`OutPhaseSpacePoint`](@ref). - The [`InPhaseSpacePoint`](@ref) and [`OutPhaseSpacePoint`](@ref) type definitions can be used to dispatch on such `PhaseSpacePoint`s. Note that a full `PhaseSpacePoint` containing both its in- and out-channel matches both, .i.e. `psp isa InPhaseSpacePoint` and `psp isa OutPhaseSpacePoint` both evaluate to true if psp contains both channels. - A completely empty `PhaseSpacePoint` is not allowed. -""" -struct PhaseSpacePoint{ - PROC<:AbstractProcessDefinition, - MODEL<:AbstractModelDefinition, - PSDEF<:AbstractPhasespaceDefinition, - IN_PARTICLES<:Tuple{Vararg{ParticleStateful}}, - OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}}, - ELEMENT<:QEDbase.AbstractFourMomentum, -} - proc::PROC - model::MODEL - ps_def::PSDEF - - in_particles::IN_PARTICLES - out_particles::OUT_PARTICLES - - """ - PhaseSpacePoint( - proc::AbstractProcessDefinition, - model::AbstractModelDefinition, - ps_def::AbstractPhasespaceDefinition, - in_ps::Tuple{ParticleStateful}, - out_ps::Tuple{ParticleStateful}, - ) - - Construct a [`PhaseSpacePoint`](@ref) from a process, model, phasespace definition and a tuple of [`ParticleStateful`](@ref)s. - """ - function PhaseSpacePoint( - proc::PROC, model::MODEL, ps_def::PSDEF, in_p::IN_PARTICLES, out_p::OUT_PARTICLES - ) where { - PROC<:AbstractProcessDefinition, - MODEL<:AbstractModelDefinition, - PSDEF<:AbstractPhasespaceDefinition, - IN_PARTICLES<:Tuple{Vararg{ParticleStateful}}, - OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}}, - } - # this entire check is compiled away every time, so there's no need to disable it for performance ever - ELEMENT = _check_psp( - incoming_particles(proc), outgoing_particles(proc), in_p, out_p - ) - - return new{PROC,MODEL,PSDEF,IN_PARTICLES,OUT_PARTICLES,ELEMENT}( - proc, model, ps_def, in_p, out_p - ) - end -end - -""" - InPhaseSpacePoint - -A partial type specialization on [`PhaseSpacePoint`](@ref) which can be used for dispatch in functions requiring only the in channel of the phase space to exist, for example implementations of [`_incident_flux`](@ref). No restrictions are imposed on the out-channel, which may or may not exist. - -See also: [`OutPhaseSpacePoint`](@ref) -""" -InPhaseSpacePoint{P,M,D,IN,OUT,E} = PhaseSpacePoint{ - P,M,D,IN,OUT,E -} where {IN<:Tuple{ParticleStateful,Vararg},OUT<:Tuple{Vararg}} - -""" - OutPhaseSpacePoint - -A partial type specialization on [`PhaseSpacePoint`](@ref) which can be used for dispatch in functions requiring only the out channel of the phase space to exist. No restrictions are imposed on the in-channel, which may or may not exist. - -See also: [`InPhaseSpacePoint`](@ref) -""" -OutPhaseSpacePoint{P,M,D,IN,OUT,E} = PhaseSpacePoint{ - P,M,D,IN,OUT,E -} where {IN<:Tuple{Vararg},OUT<:Tuple{ParticleStateful,Vararg}} diff --git a/src/phase_spaces/utility.jl b/src/phase_spaces/utility.jl deleted file mode 100644 index 21cb214..0000000 --- a/src/phase_spaces/utility.jl +++ /dev/null @@ -1,143 +0,0 @@ -# recursion termination: base case -@inline _assemble_tuple_type(::Tuple{}, ::QEDbase.ParticleDirection, ::Type) = () - -# function assembling the correct type information for the tuple of ParticleStatefuls in a phasespace point constructed from momenta -@inline function _assemble_tuple_type( - particle_types::Tuple{SPECIES_T,Vararg{QEDbase.AbstractParticleType}}, - dir::DIR_T, - ELTYPE::Type, -) where {SPECIES_T<:QEDbase.AbstractParticleType,DIR_T<:QEDbase.ParticleDirection} - return ( - ParticleStateful{DIR_T,SPECIES_T,ELTYPE}, - _assemble_tuple_type(particle_types[2:end], dir, ELTYPE)..., - ) -end - -# recursion termination: success -@inline _recursive_type_check(::Tuple{}, ::Tuple{}, ::QEDbase.ParticleDirection) = nothing - -# recursion termination: overload for unequal number of particles -@inline function _recursive_type_check( - ::Tuple{Vararg{ParticleStateful,N}}, - ::Tuple{Vararg{QEDbase.AbstractParticleType,M}}, - dir::QEDbase.ParticleDirection, -) where {N,M} - throw(InvalidInputError("expected $(M) $(dir) particles for the process but got $(N)")) - return nothing -end - -# recursion termination: overload for invalid types -@inline function _recursive_type_check( - ::Tuple{ParticleStateful{DIR_IN_T,SPECIES_IN_T},Vararg{ParticleStateful,N}}, - ::Tuple{SPECIES_T,Vararg{QEDbase.AbstractParticleType,N}}, - dir::DIR_T, -) where { - N, - DIR_IN_T<:QEDbase.ParticleDirection, - DIR_T<:QEDbase.ParticleDirection, - SPECIES_IN_T<:QEDbase.AbstractParticleType, - SPECIES_T<:QEDbase.AbstractParticleType, -} - throw( - InvalidInputError( - "expected $(dir) $(SPECIES_T()) but got $(DIR_IN_T()) $(SPECIES_IN_T())" - ), - ) - return nothing -end - -@inline function _recursive_type_check( - t::Tuple{ParticleStateful{DIR_T,SPECIES_T},Vararg{ParticleStateful,N}}, - p::Tuple{SPECIES_T,Vararg{QEDbase.AbstractParticleType,N}}, - dir::DIR_T, -) where {N,DIR_T<:QEDbase.ParticleDirection,SPECIES_T<:QEDbase.AbstractParticleType} - return _recursive_type_check(t[2:end], p[2:end], dir) -end - -@inline function _check_psp( - in_proc::P_IN_Ts, out_proc::P_OUT_Ts, in_p::IN_Ts, out_p::OUT_Ts -) where { - P_IN_Ts<:Tuple{Vararg{QEDbase.AbstractParticleType}}, - P_OUT_Ts<:Tuple{Vararg{QEDbase.AbstractParticleType}}, - IN_Ts<:Tuple{Vararg{ParticleStateful}}, - OUT_Ts<:Tuple{}, -} - # specific overload for InPhaseSpacePoint - _recursive_type_check(in_p, in_proc, QEDbase.Incoming()) - - return typeof(in_p[1].mom) -end - -@inline function _check_psp( - in_proc::P_IN_Ts, out_proc::P_OUT_Ts, in_p::IN_Ts, out_p::OUT_Ts -) where { - P_IN_Ts<:Tuple{Vararg{QEDbase.AbstractParticleType}}, - P_OUT_Ts<:Tuple{Vararg{QEDbase.AbstractParticleType}}, - IN_Ts<:Tuple{}, - OUT_Ts<:Tuple{Vararg{ParticleStateful}}, -} - # specific overload for OutPhaseSpacePoint - _recursive_type_check(out_p, out_proc, QEDbase.Outgoing()) - - return typeof(out_p[1].mom) -end - -@inline function _check_psp( - in_proc::P_IN_Ts, out_proc::P_OUT_Ts, in_p::IN_Ts, out_p::OUT_Ts -) where { - P_IN_Ts<:Tuple{Vararg{QEDbase.AbstractParticleType}}, - P_OUT_Ts<:Tuple{Vararg{QEDbase.AbstractParticleType}}, - IN_Ts<:Tuple{Vararg{ParticleStateful}}, - OUT_Ts<:Tuple{Vararg{ParticleStateful}}, -} - # in_proc/out_proc contain only species types - # in_p/out_p contain full ParticleStateful types - - _recursive_type_check(in_p, in_proc, QEDbase.Incoming()) - _recursive_type_check(out_p, out_proc, QEDbase.Outgoing()) - - return typeof(out_p[1].mom) -end - -""" - _momentum_type(psp::PhaseSpacePoint) - _momentum_type(type::Type{PhaseSpacePoint}) - -Returns the element type of the [`PhaseSpacePoint`](@ref) object or type, e.g. `SFourMomentum`. - -```jldoctest -julia> using QEDprocesses; using QEDcore - -julia> psp = PhaseSpacePoint(Compton(), PerturbativeQED(), PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()), Tuple(rand(SFourMomentum) for _ in 1:2), Tuple(rand(SFourMomentum) for _ in 1:2)); - -julia> QEDprocesses._momentum_type(psp) -SFourMomentum - -julia> QEDprocesses._momentum_type(typeof(psp)) -SFourMomentum -``` -""" -@inline function _momentum_type( - ::Type{T} -) where {P,M,D,I,O,E,T<:PhaseSpacePoint{P,M,D,I,O,E}} - return E -end - -@inline _momentum_type(::T) where {T<:PhaseSpacePoint} = _momentum_type(T) - -# convenience function building a type stable tuple of ParticleStatefuls from the given process, momenta, and direction -function _build_particle_statefuls( - proc::AbstractProcessDefinition, moms::NTuple{N,ELEMENT}, dir::QEDbase.ParticleDirection -) where {N,ELEMENT<:QEDbase.AbstractFourMomentum} - N == number_particles(proc, dir) || throw( - InvalidInputError( - "expected $(number_particles(proc, dir)) $(dir) particles for the process but got $(N)", - ), - ) - res = Tuple{_assemble_tuple_type(particles(proc, dir), dir, ELEMENT)...}( - ParticleStateful(dir, particle, mom) for - (particle, mom) in zip(particles(proc, dir), moms) - ) - - return res -end diff --git a/src/processes/one_photon_compton/one_photon_compton.jl b/src/processes/one_photon_compton/one_photon_compton.jl deleted file mode 100644 index 922fc8d..0000000 --- a/src/processes/one_photon_compton/one_photon_compton.jl +++ /dev/null @@ -1,11 +0,0 @@ -################# -# The one-photon Compton process -# -# This file contains the implementation of the abstract process setup for -# Compton -################## - -include("process.jl") -include("perturbative/kinematics.jl") -include("perturbative/cross_section.jl") -include("perturbative/total_probability.jl") diff --git a/src/processes/one_photon_compton/perturbative/cross_section.jl b/src/processes/one_photon_compton/perturbative/cross_section.jl index c2d85df..80931d3 100644 --- a/src/processes/one_photon_compton/perturbative/cross_section.jl +++ b/src/processes/one_photon_compton/perturbative/cross_section.jl @@ -3,6 +3,9 @@ # Implementation of the cross section interface ##### +import QEDbase: + _incident_flux, _matrix_element, _averaging_norm, _is_in_phasespace, _phase_space_factor + function _incident_flux(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) return momentum(in_psp, QEDbase.Incoming(), 1) * momentum(in_psp, QEDbase.Incoming(), 2) end diff --git a/src/processes/one_photon_compton/perturbative/kinematics.jl b/src/processes/one_photon_compton/perturbative/kinematics.jl index a299726..c7cfdb9 100644 --- a/src/processes/one_photon_compton/perturbative/kinematics.jl +++ b/src/processes/one_photon_compton/perturbative/kinematics.jl @@ -1,3 +1,5 @@ +import QEDbase: _generate_incoming_momenta, _generate_outgoing_momenta, _generate_momenta + @inline function _pert_omega_prime(omega, cth; mass=1.0) return omega / (1 + omega / mass * (1 - cth)) end diff --git a/src/processes/one_photon_compton/perturbative/total_probability.jl b/src/processes/one_photon_compton/perturbative/total_probability.jl index 072856c..6655b4c 100644 --- a/src/processes/one_photon_compton/perturbative/total_probability.jl +++ b/src/processes/one_photon_compton/perturbative/total_probability.jl @@ -1,3 +1,4 @@ +import QEDbase: _total_probability function _total_probability(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) omega = QEDbase.getE(momentum(in_psp[QEDbase.Incoming(), 2])) diff --git a/src/propagators.jl b/src/propagators.jl index 6d54527..77cd66e 100644 --- a/src/propagators.jl +++ b/src/propagators.jl @@ -1,37 +1,10 @@ - ############### # Propagators # # This file contains implementations for the fermion and boson propagators. #### -""" - - propagator(particle::AbstractParticleType, mom::QEDbase.AbstractFourMomentum, [mass::Real]) - -Return the propagator of a particle for a given four-momentum. If `mass` is passed, the respective propagator for massive particles is used, if not, it is assumed the particle passed in is massless. - -!!! note "Convention" - - There are two types of implementations for propagators given in `QEDProcesses`: - For a `BosonLike` particle with four-momentum ``k`` and mass ``m``, the propagator is given as - - ```math - D(k) = \\frac{1}{k^2 - m^2}. - ``` - - For a `FermionLike` particle with four-momentum ``p`` and mass ``m``, the propagator is given as - - ```math - S(p) = \\frac{\\gamma^\\mu p_\\mu + mass}{p^2 - m^2}. - ``` - -!!! warning - - This function does not throw when the given particle is off-shell. If an off-shell particle is passed, the function `propagator` returns `Inf`. - -""" -function propagator end +import QEDbase: propagator function _scalar_propagator(K::QEDbase.AbstractFourMomentum, mass::Real) return one(mass) / (K * K - mass^2) diff --git a/test/interfaces/model_interface.jl b/test/interfaces/model_interface.jl deleted file mode 100644 index fbd7ee0..0000000 --- a/test/interfaces/model_interface.jl +++ /dev/null @@ -1,19 +0,0 @@ -using QEDprocesses - -include("../test_implementation/TestImplementation.jl") - -@testset "hard interface" begin - TESTMODEL = TestImplementation.TestModel() - @test fundamental_interaction_type(TESTMODEL) == :test_interaction -end - -@testset "interface fail" begin - TESTMODEL_FAIL = TestImplementation.TestModel_FAIL() - @test_throws MethodError fundamental_interaction_type(TESTMODEL_FAIL) -end - -@testset "broadcast" begin - test_func(model) = model - TESTMODEL = TestImplementation.TestModel() - @test test_func.(TESTMODEL) == TESTMODEL -end diff --git a/test/interfaces/process_interface.jl b/test/interfaces/process_interface.jl deleted file mode 100644 index ffe55d1..0000000 --- a/test/interfaces/process_interface.jl +++ /dev/null @@ -1,131 +0,0 @@ -using Random -using QEDbase: QEDbase -using QEDcore -using QEDprocesses - -RNG = MersenneTwister(137137) -ATOL = 0.0 -RTOL = sqrt(eps()) - -include("../test_implementation/TestImplementation.jl") - -@testset "($N_INCOMING,$N_OUTGOING)" for (N_INCOMING, N_OUTGOING) in Iterators.product( - (1, rand(RNG, 2:8)), (1, rand(RNG, 2:8)) -) - INCOMING_PARTICLES = Tuple(rand(RNG, TestImplementation.PARTICLE_SET, N_INCOMING)) - OUTGOING_PARTICLES = Tuple(rand(RNG, TestImplementation.PARTICLE_SET, N_OUTGOING)) - - TESTPROC = TestImplementation.TestProcess(INCOMING_PARTICLES, OUTGOING_PARTICLES) - TESTMODEL = TestImplementation.TestModel() - TESTPSDEF = TestImplementation.TestPhasespaceDef() - IN_PS = TestImplementation._rand_momenta(RNG, N_INCOMING) - OUT_PS = TestImplementation._rand_momenta(RNG, N_OUTGOING) - PSP = PhaseSpacePoint(TESTPROC, TESTMODEL, TESTPSDEF, IN_PS, OUT_PS) - - @testset "failed interface" begin - TESTPROC_FAIL_ALL = TestImplementation.TestProcess_FAIL_ALL( - INCOMING_PARTICLES, OUTGOING_PARTICLES - ) - TESTPROC_FAIL_DIFFCS = TestImplementation.TestProcess_FAIL_DIFFCS( - INCOMING_PARTICLES, OUTGOING_PARTICLES - ) - TESTMODEL_FAIL = TestImplementation.TestModel_FAIL() - TESTPSDEF_FAIL = TestImplementation.TestPhasespaceDef_FAIL() - - @testset "failed process interface" begin - @test_throws MethodError incoming_particles(TESTPROC_FAIL_ALL) - @test_throws MethodError outgoing_particles(TESTPROC_FAIL_ALL) - end - - @testset "$PROC $MODEL" for (PROC, MODEL) in Iterators.product( - (TESTPROC, TESTPROC_FAIL_DIFFCS), (TESTMODEL, TESTMODEL_FAIL) - ) - if TestImplementation._any_fail(PROC, MODEL) - psp = PhaseSpacePoint(PROC, MODEL, TESTPSDEF, IN_PS, OUT_PS) - @test_throws MethodError QEDprocesses._incident_flux(psp) - @test_throws MethodError QEDprocesses._averaging_norm(psp) - @test_throws MethodError QEDprocesses._matrix_element(psp) - end - - for PS_DEF in (TESTPSDEF, TESTPSDEF_FAIL) - if TestImplementation._any_fail(PROC, MODEL, PS_DEF) - psp = PhaseSpacePoint(PROC, MODEL, PS_DEF, IN_PS, OUT_PS) - @test_throws MethodError QEDprocesses._phase_space_factor(psp) - end - end - end - end - - @testset "broadcast" begin - test_func(proc::AbstractProcessDefinition) = proc - @test test_func.(TESTPROC) == TESTPROC - - test_func(model::AbstractModelDefinition) = model - @test test_func.(TESTMODEL) == TESTMODEL - end - - @testset "incoming/outgoing particles" begin - @test incoming_particles(TESTPROC) == INCOMING_PARTICLES - @test outgoing_particles(TESTPROC) == OUTGOING_PARTICLES - @test number_incoming_particles(TESTPROC) == N_INCOMING - @test number_outgoing_particles(TESTPROC) == N_OUTGOING - end - - @testset "incident flux" begin - test_incident_flux = QEDprocesses._incident_flux( - InPhaseSpacePoint(TESTPROC, TESTMODEL, TESTPSDEF, IN_PS) - ) - groundtruth = TestImplementation._groundtruth_incident_flux(IN_PS) - @test isapprox(test_incident_flux, groundtruth, atol=ATOL, rtol=RTOL) - - test_incident_flux = QEDprocesses._incident_flux( - PhaseSpacePoint(TESTPROC, TESTMODEL, TESTPSDEF, IN_PS, OUT_PS) - ) - @test isapprox(test_incident_flux, groundtruth, atol=ATOL, rtol=RTOL) - - @test_throws MethodError QEDprocesses._incident_flux( - OutPhaseSpacePoint(TESTPROC, TESTMODEL, TESTPSDEF, OUT_PS) - ) - end - - @testset "averaging norm" begin - test_avg_norm = QEDprocesses._averaging_norm(TESTPROC) - groundtruth = TestImplementation._groundtruth_averaging_norm(TESTPROC) - @test isapprox(test_avg_norm, groundtruth, atol=ATOL, rtol=RTOL) - end - - @testset "matrix element" begin - test_matrix_element = QEDprocesses._matrix_element(PSP) - groundtruth = TestImplementation._groundtruth_matrix_element(IN_PS, OUT_PS) - @test length(test_matrix_element) == length(groundtruth) - for i in eachindex(test_matrix_element) - @test isapprox(test_matrix_element[i], groundtruth[i], atol=ATOL, rtol=RTOL) - end - end - - @testset "is in phasespace" begin - @test QEDprocesses._is_in_phasespace(PSP) - - IN_PS_unphysical = (zero(SFourMomentum), IN_PS[2:end]...) - OUT_PS_unphysical = (OUT_PS[1:(end - 1)]..., ones(SFourMomentum)) - PSP_unphysical_in_ps = PhaseSpacePoint( - TESTPROC, TESTMODEL, TESTPSDEF, IN_PS_unphysical, OUT_PS - ) - PSP_unphysical_out_ps = PhaseSpacePoint( - TESTPROC, TESTMODEL, TESTPSDEF, IN_PS, OUT_PS_unphysical - ) - PSP_unphysical = PhaseSpacePoint( - TESTPROC, TESTMODEL, TESTPSDEF, IN_PS_unphysical, OUT_PS_unphysical - ) - - @test !QEDprocesses._is_in_phasespace(PSP_unphysical_in_ps) - @test !QEDprocesses._is_in_phasespace(PSP_unphysical_out_ps) - @test !QEDprocesses._is_in_phasespace(PSP_unphysical) - end - - @testset "phase space factor" begin - test_phase_space_factor = QEDprocesses._phase_space_factor(PSP) - groundtruth = TestImplementation._groundtruth_phase_space_factor(IN_PS, OUT_PS) - @test isapprox(test_phase_space_factor, groundtruth, atol=ATOL, rtol=RTOL) - end -end diff --git a/test/interfaces/setup_interface.jl b/test/interfaces/setup_interface.jl deleted file mode 100644 index bdb8097..0000000 --- a/test/interfaces/setup_interface.jl +++ /dev/null @@ -1,190 +0,0 @@ - -using Random -using Suppressor -using QEDbase -using QEDprocesses - -RNG = MersenneTwister(137137) -ATOL = 0.0 -RTOL = sqrt(eps()) - -_groundtruth_compute(x) = x -_groundtruth_input_validation(x) = (x > 0) -struct TestException <: QEDprocesses.AbstractInvalidInputException end -function _groundtruth_valid_input_assert(x) - _groundtruth_input_validation(x) || throw(TestException()) - return nothing -end -_transform_to_invalid(x) = -abs(x) -_groundtruth_post_processing(x, y) = x + y - -# setups for which the interface is implemented -abstract type AbstractTestSetup <: AbstractComputationSetup end -QEDprocesses._compute(stp::AbstractTestSetup, x) = _groundtruth_compute(x) - -# setup with default implementations -struct TestSetupDefault <: AbstractTestSetup end - -# setup with custom _assert_valid_input -struct TestSetupCustomAssertValidInput <: AbstractTestSetup end -function QEDprocesses._assert_valid_input(stp::TestSetupCustomAssertValidInput, x) - return _groundtruth_valid_input_assert(x) -end - -# setup with custom post processing -struct TestSetupCustomPostProcessing <: AbstractTestSetup end -function QEDprocesses._post_processing(::TestSetupCustomPostProcessing, x, y) - return _groundtruth_post_processing(x, y) -end - -# setup with custom input validation and post processing -struct TestSetupCustom <: AbstractTestSetup end -function QEDprocesses._assert_valid_input(stp::TestSetupCustom, x) - return _groundtruth_valid_input_assert(x) -end -QEDprocesses._post_processing(::TestSetupCustom, x, y) = _groundtruth_post_processing(x, y) - -# setup which fail on computation with default implementations -struct TestSetupFAIL <: AbstractComputationSetup end - -# setup which fail on computation with custom input validation, where the -# invalid input will be caught before the computation. -struct TestSetupCustomValidationFAIL <: AbstractComputationSetup end -function QEDprocesses._assert_valid_input(stp::TestSetupCustomValidationFAIL, x) - return _groundtruth_valid_input_assert(x) -end - -# setup which fail on computation with custom post processing -struct TestSetupCustomPostProcessingFAIL <: AbstractComputationSetup end -function QEDprocesses._post_processing(::TestSetupCustomPostProcessingFAIL, x, y) - return _groundtruth_post_processing(x, y) -end -@testset "general computation setup interface" begin - @testset "interface fail" begin - rnd_input = rand(RNG) - - @test_throws MethodError QEDprocesses._compute(TestSetupFAIL(), rnd_input) - @test_throws MethodError compute(TestSetupFAIL(), rnd_input) - - @test_throws MethodError QEDprocesses._compute( - TestSetupCustomValidationFAIL(), rnd_input - ) - @test_throws MethodError compute(TestSetupCustomValidationFAIL(), rnd_input) - # invalid input should be caught without throwing a MethodError - @test_throws TestException compute( - TestSetupCustomValidationFAIL(), _transform_to_invalid(rnd_input) - ) - - @test_throws MethodError QEDprocesses._compute( - TestSetupCustomPostProcessingFAIL(), rnd_input - ) - @test_throws MethodError compute(TestSetupCustomPostProcessingFAIL(), rnd_input) - end - - @testset "default interface" begin - stp = TestSetupDefault() - - rnd_input = rand(RNG) - rnd_output = rand(RNG) - @test QEDprocesses._post_processing(stp, rnd_input, rnd_output) == rnd_output - @test isapprox( - QEDprocesses._compute(stp, rnd_input), - _groundtruth_compute(rnd_input), - atol=ATOL, - rtol=RTOL, - ) - @test isapprox( - compute(stp, rnd_input), _groundtruth_compute(rnd_input), atol=ATOL, rtol=RTOL - ) - end - - @testset "custom input validation" begin - stp = TestSetupCustomAssertValidInput() - rnd_input = rand(RNG) - @test QEDprocesses._assert_valid_input(stp, rnd_input) == nothing - @test_throws TestException QEDprocesses._assert_valid_input( - stp, _transform_to_invalid(rnd_input) - ) - @test_throws TestException compute(stp, _transform_to_invalid(rnd_input)) - end - - @testset "custom post processing" begin - stp = TestSetupCustomPostProcessing() - rnd_input = rand(RNG) - rnd_output = rand(RNG) - @test isapprox( - QEDprocesses._post_processing(stp, rnd_input, rnd_output), - _groundtruth_post_processing(rnd_input, rnd_output), - ) - @test isapprox( - compute(stp, rnd_input), - _groundtruth_post_processing(rnd_input, _groundtruth_compute(rnd_input)), - ) - end - - @testset "custom input validation and post processing" begin - stp = TestSetupCustom() - rnd_input = rand(RNG) - rnd_output = rand(RNG) - - @test_throws TestException() compute(stp, _transform_to_invalid(rnd_input)) - @test isapprox( - QEDprocesses._post_processing(stp, rnd_input, rnd_output), - _groundtruth_post_processing(rnd_input, rnd_output), - ) - @test isapprox( - compute(stp, rnd_input), - _groundtruth_post_processing(rnd_input, _groundtruth_compute(rnd_input)), - ) - end -end -# process setup - -struct TestParticle1 <: AbstractParticle end -struct TestParticle2 <: AbstractParticle end -struct TestParticle3 <: AbstractParticle end -struct TestParticle4 <: AbstractParticle end - -PARTICLE_SET = [TestParticle1(), TestParticle2(), TestParticle3(), TestParticle4()] - -struct TestProcess <: AbstractProcessDefinition end -struct TestModel <: AbstractModelDefinition end - -struct TestProcessSetup <: AbstractProcessSetup end -QEDprocesses.scattering_process(::TestProcessSetup) = TestProcess() -QEDprocesses.physical_model(::TestProcessSetup) = TestModel() - -struct TestProcessSetupFAIL <: AbstractProcessSetup end - -@testset "process setup interface" begin - @testset "interface fail" begin - rnd_input = rand(RNG) - @test_throws MethodError scattering_process(TestProcessSetupFAIL()) - @test_throws MethodError physical_model(TestProcessSetupFAIL()) - @test_throws MethodError QEDprocesses._compute(TestProcessSetupFAIL(), rnd_input) - end - - @testset "hard interface" begin - stp = TestProcessSetup() - - @test QEDprocesses._is_computation_setup(stp) - @test scattering_process(stp) == TestProcess() - @test physical_model(stp) == TestModel() - end - - @testset "($N_INCOMING,$N_OUTGOING)" for (N_INCOMING, N_OUTGOING) in Iterators.product( - (1, rand(RNG, 2:8)), (1, rand(RNG, 2:8)) - ) - INCOMING_PARTICLES = rand(RNG, PARTICLE_SET, N_INCOMING) - OUTGOING_PARTICLES = rand(RNG, PARTICLE_SET, N_OUTGOING) - - @suppress QEDprocesses.incoming_particles(::TestProcess) = INCOMING_PARTICLES - @suppress QEDprocesses.outgoing_particles(::TestProcess) = OUTGOING_PARTICLES - - @testset "delegated functions" begin - stp = TestProcessSetup() - @test number_incoming_particles(stp) == N_INCOMING - @test number_outgoing_particles(stp) == N_OUTGOING - end - end -end diff --git a/test/runtests.jl b/test/runtests.jl index cc6570b..7fc4a98 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,19 +3,6 @@ using Test using SafeTestsets begin - # # Interfaces - @time @safetestset "model interface" begin - include("interfaces/model_interface.jl") - end - @time @safetestset "process interface" begin - include("interfaces/process_interface.jl") - end - - # TODO: remove after restructuring - #@time @safetestset "computation setup interface" begin - # include("interfaces/setup_interface.jl") - #end - # modules @time @safetestset "propagators" begin include("propagators.jl") diff --git a/test/test_implementation/TestImplementation.jl b/test/test_implementation/TestImplementation.jl deleted file mode 100644 index a46dc89..0000000 --- a/test/test_implementation/TestImplementation.jl +++ /dev/null @@ -1,40 +0,0 @@ -""" -This module provides a full implementation of the model and process interface. Its purpose is only for testing and it does not reflect any -real-world physics. - -The module exports: - -``` -TestParticle1 # set of test particles without properties -TestParticle2 -TestParticle3 -TestParticle4 -TestModel # dummy compute model -TestModel_FAIL # failing compute model -TestProcess # dummy scattering process -TestProcess_FAIL # failing scattering process -TestPhasespaceDef # dummy phase space definition -TestPhasespaceDef_FAIL # failing phase space definition -``` -The respective groundtruth implementations for the interface functions are stored in `groundtruths.jl` -""" -module TestImplementation - -export TestParticle1, TestParticle2, TestParticle3, TestParticle4, PARTICLE_SET -export TestModel, TestModel_FAIL -export TestProcess, TestProcess_FAIL -export TestPhasespaceDef, TestPhasespaceDef_FAIL - -using Random -using QEDbase: QEDbase -using QEDcore -using QEDprocesses -using StaticArrays - -include("groundtruths.jl") -include("test_model.jl") -include("test_process.jl") -include("random_momenta.jl") -include("utils.jl") - -end diff --git a/test/test_implementation/groundtruths.jl b/test/test_implementation/groundtruths.jl deleted file mode 100644 index b9d0883..0000000 --- a/test/test_implementation/groundtruths.jl +++ /dev/null @@ -1,265 +0,0 @@ -import QEDbase.AbstractFourMomentum - -""" - _groundtruth_incident_flux(in_ps) - -Test implementation of the incident flux. Return the Minkowski square of the sum of the incoming momenta: - -```math -\\begin{align} -I = \\left(\\sum p_i\\right)^2, -\\end{align} -``` -where \$p_i\\in\\mathrm{ps_in}\$. -""" -function _groundtruth_incident_flux(in_ps) - s = sum(in_ps) - return s * s -end - -""" - _groundtruth_matrix_element(in_ps, out_ps) - -Test implementation for a matrix elements. Returns a list of three complex numbers without any physical meaning. -""" -function _groundtruth_matrix_element(in_ps, out_ps) - s_in = sum(in_ps) - s_out = sum(out_ps) - res = s_in * s_in + 1im * (s_out * s_out) - return (res, 2 * res, 3 * res) -end - -""" - _groundtruth_averaging_norm(proc) - -Test implementation of the averaging norm. Returns the inverse of the sum of all external particles of the passed process. -""" -function _groundtruth_averaging_norm(proc) - return 1.0 / (number_incoming_particles(proc) + number_outgoing_particles(proc)) -end - -""" - _groundtruth_is_in_phasespace(in_ps, out_ps) - -Test implementation of the phase space check. Return `false` if either the momentum of the first incoming particle is exactly `zero(SFourMomentum)`, or if the momentum of the last outgoing momentum is exactly `ones(SFourMomentum)`. Otherwise, return true. -""" -function _groundtruth_is_in_phasespace(in_ps, out_ps) - if in_ps[1] == SFourMomentum(zeros(4)) - return false - end - if out_ps[end] == ones(SFourMomentum) - return false - end - return true -end - -""" - _groundtruth_phase_space_factor(in_ps, out_ps) - -Test implementation of the phase space factor. Return the inverse of the product of the energies of all external particles. -""" -function _groundtruth_phase_space_factor(in_ps, out_ps) - en_in = QEDbase.getE.(in_ps) - en_out = QEDbase.getE.(out_ps) - return 1 / (prod(en_in) * prod(en_out)) -end - -function _groundtruth_generate_momenta(ps_coords) - moms = _furl_moms(ps_coords) - return moms -end -""" - _groundtruth_unsafe_probability(proc, in_ps, out_ps) - -Test implementation of the unsafe differential probability. Uses the test implementations of `_groundtruth_matrix_element`,`_groundtruth_averaging_norm` and `_groundtruth_phase_space_factor`. -""" -function _groundtruth_unsafe_probability(proc, in_ps, out_ps) - mat_el = _groundtruth_matrix_element(in_ps, out_ps) - mat_el_sq = abs2.(mat_el) - normalization = _groundtruth_averaging_norm(proc) - ps_fac = _groundtruth_phase_space_factor(in_ps, out_ps) - return sum(mat_el_sq) * ps_fac * normalization -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractVector, out_ps::AbstractMatrix -) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_unsafe_probability(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractMatrix, out_ps::AbstractVector -) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_unsafe_probability(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix -) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_unsafe_probability( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_safe_probability(proc, in_ps, out_ps) - -Test implementation of the safe differential probability. Uses the test implementations of `_groundtruth_is_in_phasespace` and `_groundtruth_unsafe_probability`. -""" -function _groundtruth_safe_probability(proc, in_ps, out_ps) - if !_groundtruth_is_in_phasespace(in_ps, out_ps) - return zero(Float64) - end - return _groundtruth_unsafe_probability(proc, in_ps, out_ps) -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_safe_probability(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_safe_probability(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_safe_probability( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) - -Test implementation of the unsafe differential cross section. Uses the test implementations of `_groundtruth_incident_flux` and `_groundtruth_unsafe_probability`. -""" -function _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) - init_flux = _groundtruth_incident_flux(in_ps) - return _groundtruth_unsafe_probability(proc, in_ps, out_ps) / (4 * init_flux) -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_unsafe_diffCS(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_unsafe_diffCS(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_unsafe_diffCS( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_safe_diffCS(proc, in_ps, out_ps) - -Test implementation of the safe differential cross section. Uses the test implementations of `_groundtruth_is_in_phasespace` and `_groundtruth_unsafe_diffCS`. -""" -function _groundtruth_safe_diffCS(proc, in_ps, out_ps) - if !_groundtruth_is_in_phasespace(in_ps, out_ps) - return zero(Float64) - end - return _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_safe_diffCS(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_safe_diffCS(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_safe_diffCS( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_total_probability(in_ps::AbstractVector) - -Test implementation of the total cross section. Return the Minkowski square of the sum the momenta of all incoming particles. -""" -function _groundtruth_total_probability( - in_ps::NTuple{N,T} -) where {N,T<:AbstractFourMomentum} - Ptot = sum(in_ps) - return Ptot * Ptot -end - -function _groundtruth_total_probability( - in_pss::Vector{NTuple{N,T}} -) where {N,T<:AbstractFourMomentum} - return _groundtruth_total_probability.(in_pss) -end - -function _groundtruth_total_cross_section( - in_ps::NTuple{N,T} -) where {N,T<:AbstractFourMomentum} - init_flux = _groundtruth_incident_flux(in_ps) - return _groundtruth_total_probability(in_ps) / (4 * init_flux) -end - -function _groundtruth_total_cross_section( - in_pss::Vector{NTuple{N,T}} -) where {N,T<:AbstractFourMomentum} - return _groundtruth_total_cross_section.(in_psps) -end diff --git a/test/test_implementation/random_momenta.jl b/test/test_implementation/random_momenta.jl deleted file mode 100644 index b631551..0000000 --- a/test/test_implementation/random_momenta.jl +++ /dev/null @@ -1,83 +0,0 @@ - -""" -Return a tuple of random four momenta, i.e. a random phase space point. -""" -function _rand_momenta(rng::AbstractRNG, n) - return NTuple{n,SFourMomentum}(SFourMomentum(rand(rng, 4)) for _ in 1:n) -end - -""" -Return a vector of tuples of random four momenta, i.e. a collection of phase space points. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_momenta(rng::AbstractRNG, n1, n2) - moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) - for i in 1:n2 - moms[i] = _rand_momenta(rng, n1) - end - return moms -end - -""" -Return a random phase space point that is failing the incoming phase space constraint, -i.e. the first entry of the phase space is the null momentum. -""" -function _rand_in_momenta_failing(rng::AbstractRNG, n) - return (zero(SFourMomentum), _rand_momenta(rng, n - 1)...) -end - -""" -Return a random phase space point that is failing the outgoing phase space constraint, -i.e. the last entry of the phase space is the unit momentum. -""" -function _rand_out_momenta_failing(rng::AbstractRNG, n) - return (_rand_momenta(rng, n - 1)..., ones(SFourMomentum)) -end - -""" -Return a collection of incoming phase space points, where the first point is failing the phase space constraint, -i.e. the first entry of the vector is invalid but the others pass. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_in_momenta_failing_mix(rng::AbstractRNG, n1, n2) - moms = _rand_momenta(rng, n1, n2) - moms[1] = _rand_in_momenta_failing(rng, n1) - return moms -end - -""" -Return a collection of incoming phase space points, where all points are failing the phase space constraint, -i.e. their first entries are null momenta. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_in_momenta_failing_all(rng::AbstractRNG, n1, n2) - moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) - for i in 1:n2 - moms[i] = _rand_in_momenta_failing(rng, n1) - end - return moms -end - -""" -Return a vector of outgoing phase space points, where the first point is failing the phase space constraint, -i.e. the last entry of the vector is invalid but the others pass. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_out_momenta_failing_mix(rng::AbstractRNG, n1, n2) - moms = _rand_momenta(rng, n1, n2) - moms[end] = _rand_out_momenta_failing(rng, n1) - return moms -end - -""" -Return a vector of outgoing phase space points, where all points are failing the phase space constraint, -i.e. their last entries are unit momenta. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_out_momenta_failing_all(rng::AbstractRNG, n1, n2) - moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) - for i in 1:n2 - moms[i] = _rand_out_momenta_failing(rng, n1) - end - return moms -end diff --git a/test/test_implementation/test_model.jl b/test/test_implementation/test_model.jl deleted file mode 100644 index 4aa469b..0000000 --- a/test/test_implementation/test_model.jl +++ /dev/null @@ -1,5 +0,0 @@ - -struct TestModel <: AbstractModelDefinition end -QEDprocesses.fundamental_interaction_type(::TestModel) = :test_interaction - -struct TestModel_FAIL <: AbstractModelDefinition end diff --git a/test/test_implementation/test_process.jl b/test/test_implementation/test_process.jl deleted file mode 100644 index a15cbb2..0000000 --- a/test/test_implementation/test_process.jl +++ /dev/null @@ -1,131 +0,0 @@ -# dummy particles -struct TestParticleFermion <: FermionLike end -struct TestParticleBoson <: BosonLike end - -const PARTICLE_SET = [TestParticleFermion(), TestParticleBoson()] - -""" - TestProcess(rng,incoming_particles,outgoing_particles) - -""" -struct TestProcess{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = rand(rng, PARTICLE_SET, N_in) - out_particles = rand(rng, PARTICLE_SET, N_out) - return TestProcess(in_particles, out_particles) -end - -QEDprocesses.incoming_particles(proc::TestProcess) = proc.incoming_particles -QEDprocesses.outgoing_particles(proc::TestProcess) = proc.outgoing_particles - -struct TestProcess_FAIL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess_FAIL(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) - out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) - return TestProcess_FAIL(in_particles, out_particles) -end - -function QEDprocesses.in_phase_space_dimension(proc::TestProcess, ::TestModel) - return number_incoming_particles(proc) * 4 -end -function QEDprocesses.out_phase_space_dimension(proc::TestProcess, ::TestModel) - return number_outgoing_particles(proc) * 4 -end - -""" -Test process with no implemented interface. Should fail every usage except construction. -""" -struct TestProcess_FAIL_ALL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess_FAIL_ALL(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) - out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) - return TestProcess_FAIL_ALL(in_particles, out_particles) -end - -""" -Test process with no implemented interface except the incoming and outgoing particles. -Should fail every usage except construction of itself and the respective phase space point for given four-momenta. -""" -struct TestProcess_FAIL_DIFFCS{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess_FAIL_DIFFCS(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) - out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) - return TestProcess_FAIL_DIFFCS(in_particles, out_particles) -end - -QEDprocesses.incoming_particles(proc::TestProcess_FAIL_DIFFCS) = proc.incoming_particles -QEDprocesses.outgoing_particles(proc::TestProcess_FAIL_DIFFCS) = proc.outgoing_particles - -# dummy phase space definition + failing phase space definition -struct TestPhasespaceDef <: AbstractPhasespaceDefinition end -struct TestPhasespaceDef_FAIL <: AbstractPhasespaceDefinition end - -# dummy implementation of the process interface - -function QEDprocesses._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel}) - return _groundtruth_incident_flux(momenta(in_psp, QEDbase.Incoming())) -end - -function QEDprocesses._averaging_norm(proc::TestProcess) - return _groundtruth_averaging_norm(proc) -end - -function QEDprocesses._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel}) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) - return _groundtruth_matrix_element(in_ps, out_ps) -end - -function QEDprocesses._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel}) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) - return _groundtruth_is_in_phasespace(in_ps, out_ps) -end - -function QEDprocesses._phase_space_factor( - psp::PhaseSpacePoint{<:TestProcess,TestModel,TestPhasespaceDef} -) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) - return _groundtruth_phase_space_factor(in_ps, out_ps) -end - -function QEDprocesses._generate_incoming_momenta( - proc::TestProcess, - model::TestModel, - phase_space_def::TestPhasespaceDef, - in_phase_space::NTuple{N,T}, -) where {N,T<:Real} - return _groundtruth_generate_momenta(in_phase_space) -end - -function QEDprocesses._generate_outgoing_momenta( - proc::TestProcess, - model::TestModel, - phase_space_def::TestPhasespaceDef, - out_phase_space::NTuple{N,T}, -) where {N,T<:Real} - return _groundtruth_generate_momenta(out_phase_space) -end - -function QEDprocesses._total_probability( - in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef} -) - return _groundtruth_total_probability(momenta(in_psp, QEDbase.Incoming())) -end diff --git a/test/test_implementation/utils.jl b/test/test_implementation/utils.jl deleted file mode 100644 index 3a141d9..0000000 --- a/test/test_implementation/utils.jl +++ /dev/null @@ -1,44 +0,0 @@ - -# Check if any failed type is in the input -_any_fail(x...) = true -_any_fail(::TestProcess, ::TestModel) = false -_any_fail(::TestProcess, ::TestModel, ::TestPhasespaceDef) = false - -# unrolls all elements of a list of four-momenta into vector of coordinates -function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:QEDbase.AbstractFourMomentum} - return collect(Iterators.flatten(ps_moms)) -end - -function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:QEDbase.AbstractFourMomentum} - res = Matrix{eltype(T)}(undef, size(ps_moms, 1) * 4, size(ps_moms, 2)) - for i in 1:size(ps_moms, 2) - res[:, i] .= _unroll_moms(view(ps_moms, :, i)) - end - return res -end - -flat_components(moms::AbstractVecOrMat) = _unroll_moms(moms) -flat_components(moms::Tuple) = Tuple(_unroll_moms([moms...])) - -# collect components of four-momenta from a vector of coordinates -function __furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} - return SFourMomentum.(eachcol(reshape(ps_coords, 4, :))) -end - -function _furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} - @assert length(ps_coords) % 4 == 0 - return __furl_moms(ps_coords) -end - -function _furl_moms(ps_coords::AbstractMatrix{T}) where {T<:Real} - @assert size(ps_coords, 1) % 4 == 0 - res = Matrix{SFourMomentum}(undef, Int(size(ps_coords, 1)//4), size(ps_coords, 2)) - for i in 1:size(ps_coords, 2) - res[:, i] .= __furl_moms(view(ps_coords, :, i)) - end - return res -end - -function _furl_moms(moms::NTuple{N,Float64}) where {N} - return Tuple(_furl_moms(Vector{Float64}([moms...]))) -end From 087a1b64b9fdf321c2962db91fd50c4dc61f46bd Mon Sep 17 00:00:00 2001 From: AntonReinhard Date: Fri, 21 Jun 2024 12:46:29 +0200 Subject: [PATCH 2/6] Remove propagator and phase space --- src/QEDprocesses.jl | 8 -- src/patch_QEDbase.jl | 25 ----- src/propagators.jl | 35 ------ test/phase_spaces.jl | 262 ------------------------------------------- test/propagators.jl | 27 ----- test/runtests.jl | 7 -- 6 files changed, 364 deletions(-) delete mode 100644 src/propagators.jl delete mode 100644 test/phase_spaces.jl delete mode 100644 test/propagators.jl 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 From 6963a7808796d288226f61bf605aed78f40ccf98 Mon Sep 17 00:00:00 2001 From: Rubydragon Date: Tue, 25 Jun 2024 22:13:26 +0200 Subject: [PATCH 3/6] Add test implementation again --- .../test_implementation/TestImplementation.jl | 40 +++ test/test_implementation/groundtruths.jl | 265 ++++++++++++++++++ test/test_implementation/random_momenta.jl | 83 ++++++ test/test_implementation/test_model.jl | 5 + test/test_implementation/test_process.jl | 131 +++++++++ test/test_implementation/utils.jl | 44 +++ 6 files changed, 568 insertions(+) create mode 100644 test/test_implementation/TestImplementation.jl create mode 100644 test/test_implementation/groundtruths.jl create mode 100644 test/test_implementation/random_momenta.jl create mode 100644 test/test_implementation/test_model.jl create mode 100644 test/test_implementation/test_process.jl create mode 100644 test/test_implementation/utils.jl diff --git a/test/test_implementation/TestImplementation.jl b/test/test_implementation/TestImplementation.jl new file mode 100644 index 0000000..a46dc89 --- /dev/null +++ b/test/test_implementation/TestImplementation.jl @@ -0,0 +1,40 @@ +""" +This module provides a full implementation of the model and process interface. Its purpose is only for testing and it does not reflect any +real-world physics. + +The module exports: + +``` +TestParticle1 # set of test particles without properties +TestParticle2 +TestParticle3 +TestParticle4 +TestModel # dummy compute model +TestModel_FAIL # failing compute model +TestProcess # dummy scattering process +TestProcess_FAIL # failing scattering process +TestPhasespaceDef # dummy phase space definition +TestPhasespaceDef_FAIL # failing phase space definition +``` +The respective groundtruth implementations for the interface functions are stored in `groundtruths.jl` +""" +module TestImplementation + +export TestParticle1, TestParticle2, TestParticle3, TestParticle4, PARTICLE_SET +export TestModel, TestModel_FAIL +export TestProcess, TestProcess_FAIL +export TestPhasespaceDef, TestPhasespaceDef_FAIL + +using Random +using QEDbase: QEDbase +using QEDcore +using QEDprocesses +using StaticArrays + +include("groundtruths.jl") +include("test_model.jl") +include("test_process.jl") +include("random_momenta.jl") +include("utils.jl") + +end diff --git a/test/test_implementation/groundtruths.jl b/test/test_implementation/groundtruths.jl new file mode 100644 index 0000000..b9d0883 --- /dev/null +++ b/test/test_implementation/groundtruths.jl @@ -0,0 +1,265 @@ +import QEDbase.AbstractFourMomentum + +""" + _groundtruth_incident_flux(in_ps) + +Test implementation of the incident flux. Return the Minkowski square of the sum of the incoming momenta: + +```math +\\begin{align} +I = \\left(\\sum p_i\\right)^2, +\\end{align} +``` +where \$p_i\\in\\mathrm{ps_in}\$. +""" +function _groundtruth_incident_flux(in_ps) + s = sum(in_ps) + return s * s +end + +""" + _groundtruth_matrix_element(in_ps, out_ps) + +Test implementation for a matrix elements. Returns a list of three complex numbers without any physical meaning. +""" +function _groundtruth_matrix_element(in_ps, out_ps) + s_in = sum(in_ps) + s_out = sum(out_ps) + res = s_in * s_in + 1im * (s_out * s_out) + return (res, 2 * res, 3 * res) +end + +""" + _groundtruth_averaging_norm(proc) + +Test implementation of the averaging norm. Returns the inverse of the sum of all external particles of the passed process. +""" +function _groundtruth_averaging_norm(proc) + return 1.0 / (number_incoming_particles(proc) + number_outgoing_particles(proc)) +end + +""" + _groundtruth_is_in_phasespace(in_ps, out_ps) + +Test implementation of the phase space check. Return `false` if either the momentum of the first incoming particle is exactly `zero(SFourMomentum)`, or if the momentum of the last outgoing momentum is exactly `ones(SFourMomentum)`. Otherwise, return true. +""" +function _groundtruth_is_in_phasespace(in_ps, out_ps) + if in_ps[1] == SFourMomentum(zeros(4)) + return false + end + if out_ps[end] == ones(SFourMomentum) + return false + end + return true +end + +""" + _groundtruth_phase_space_factor(in_ps, out_ps) + +Test implementation of the phase space factor. Return the inverse of the product of the energies of all external particles. +""" +function _groundtruth_phase_space_factor(in_ps, out_ps) + en_in = QEDbase.getE.(in_ps) + en_out = QEDbase.getE.(out_ps) + return 1 / (prod(en_in) * prod(en_out)) +end + +function _groundtruth_generate_momenta(ps_coords) + moms = _furl_moms(ps_coords) + return moms +end +""" + _groundtruth_unsafe_probability(proc, in_ps, out_ps) + +Test implementation of the unsafe differential probability. Uses the test implementations of `_groundtruth_matrix_element`,`_groundtruth_averaging_norm` and `_groundtruth_phase_space_factor`. +""" +function _groundtruth_unsafe_probability(proc, in_ps, out_ps) + mat_el = _groundtruth_matrix_element(in_ps, out_ps) + mat_el_sq = abs2.(mat_el) + normalization = _groundtruth_averaging_norm(proc) + ps_fac = _groundtruth_phase_space_factor(in_ps, out_ps) + return sum(mat_el_sq) * ps_fac * normalization +end + +function _groundtruth_unsafe_probability( + proc, in_ps::AbstractVector, out_ps::AbstractMatrix +) + res = Vector{Float64}(undef, size(out_ps, 2)) + for i in 1:size(out_ps, 2) + res[i] = _groundtruth_unsafe_probability(proc, in_ps, view(out_ps, :, i)) + end + return res +end + +function _groundtruth_unsafe_probability( + proc, in_ps::AbstractMatrix, out_ps::AbstractVector +) + res = Vector{Float64}(undef, size(in_ps, 2)) + for i in 1:size(in_ps, 2) + res[i] = _groundtruth_unsafe_probability(proc, view(in_ps, :, i), out_ps) + end + return res +end + +function _groundtruth_unsafe_probability( + proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix +) + res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) + for i in 1:size(in_ps, 2) + for j in 1:size(out_ps, 2) + res[i, j] = _groundtruth_unsafe_probability( + proc, view(in_ps, :, i), view(out_ps, :, j) + ) + end + end + return res +end + +""" + _groundtruth_safe_probability(proc, in_ps, out_ps) + +Test implementation of the safe differential probability. Uses the test implementations of `_groundtruth_is_in_phasespace` and `_groundtruth_unsafe_probability`. +""" +function _groundtruth_safe_probability(proc, in_ps, out_ps) + if !_groundtruth_is_in_phasespace(in_ps, out_ps) + return zero(Float64) + end + return _groundtruth_unsafe_probability(proc, in_ps, out_ps) +end + +function _groundtruth_safe_probability(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) + res = Vector{Float64}(undef, size(out_ps, 2)) + for i in 1:size(out_ps, 2) + res[i] = _groundtruth_safe_probability(proc, in_ps, view(out_ps, :, i)) + end + return res +end + +function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) + res = Vector{Float64}(undef, size(in_ps, 2)) + for i in 1:size(in_ps, 2) + res[i] = _groundtruth_safe_probability(proc, view(in_ps, :, i), out_ps) + end + return res +end + +function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) + res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) + for i in 1:size(in_ps, 2) + for j in 1:size(out_ps, 2) + res[i, j] = _groundtruth_safe_probability( + proc, view(in_ps, :, i), view(out_ps, :, j) + ) + end + end + return res +end + +""" + _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) + +Test implementation of the unsafe differential cross section. Uses the test implementations of `_groundtruth_incident_flux` and `_groundtruth_unsafe_probability`. +""" +function _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) + init_flux = _groundtruth_incident_flux(in_ps) + return _groundtruth_unsafe_probability(proc, in_ps, out_ps) / (4 * init_flux) +end + +function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) + res = Vector{Float64}(undef, size(out_ps, 2)) + for i in 1:size(out_ps, 2) + res[i] = _groundtruth_unsafe_diffCS(proc, in_ps, view(out_ps, :, i)) + end + return res +end + +function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) + res = Vector{Float64}(undef, size(in_ps, 2)) + for i in 1:size(in_ps, 2) + res[i] = _groundtruth_unsafe_diffCS(proc, view(in_ps, :, i), out_ps) + end + return res +end + +function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) + res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) + for i in 1:size(in_ps, 2) + for j in 1:size(out_ps, 2) + res[i, j] = _groundtruth_unsafe_diffCS( + proc, view(in_ps, :, i), view(out_ps, :, j) + ) + end + end + return res +end + +""" + _groundtruth_safe_diffCS(proc, in_ps, out_ps) + +Test implementation of the safe differential cross section. Uses the test implementations of `_groundtruth_is_in_phasespace` and `_groundtruth_unsafe_diffCS`. +""" +function _groundtruth_safe_diffCS(proc, in_ps, out_ps) + if !_groundtruth_is_in_phasespace(in_ps, out_ps) + return zero(Float64) + end + return _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) +end + +function _groundtruth_safe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) + res = Vector{Float64}(undef, size(out_ps, 2)) + for i in 1:size(out_ps, 2) + res[i] = _groundtruth_safe_diffCS(proc, in_ps, view(out_ps, :, i)) + end + return res +end + +function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) + res = Vector{Float64}(undef, size(in_ps, 2)) + for i in 1:size(in_ps, 2) + res[i] = _groundtruth_safe_diffCS(proc, view(in_ps, :, i), out_ps) + end + return res +end + +function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) + res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) + for i in 1:size(in_ps, 2) + for j in 1:size(out_ps, 2) + res[i, j] = _groundtruth_safe_diffCS( + proc, view(in_ps, :, i), view(out_ps, :, j) + ) + end + end + return res +end + +""" + _groundtruth_total_probability(in_ps::AbstractVector) + +Test implementation of the total cross section. Return the Minkowski square of the sum the momenta of all incoming particles. +""" +function _groundtruth_total_probability( + in_ps::NTuple{N,T} +) where {N,T<:AbstractFourMomentum} + Ptot = sum(in_ps) + return Ptot * Ptot +end + +function _groundtruth_total_probability( + in_pss::Vector{NTuple{N,T}} +) where {N,T<:AbstractFourMomentum} + return _groundtruth_total_probability.(in_pss) +end + +function _groundtruth_total_cross_section( + in_ps::NTuple{N,T} +) where {N,T<:AbstractFourMomentum} + init_flux = _groundtruth_incident_flux(in_ps) + return _groundtruth_total_probability(in_ps) / (4 * init_flux) +end + +function _groundtruth_total_cross_section( + in_pss::Vector{NTuple{N,T}} +) where {N,T<:AbstractFourMomentum} + return _groundtruth_total_cross_section.(in_psps) +end diff --git a/test/test_implementation/random_momenta.jl b/test/test_implementation/random_momenta.jl new file mode 100644 index 0000000..b631551 --- /dev/null +++ b/test/test_implementation/random_momenta.jl @@ -0,0 +1,83 @@ + +""" +Return a tuple of random four momenta, i.e. a random phase space point. +""" +function _rand_momenta(rng::AbstractRNG, n) + return NTuple{n,SFourMomentum}(SFourMomentum(rand(rng, 4)) for _ in 1:n) +end + +""" +Return a vector of tuples of random four momenta, i.e. a collection of phase space points. +n1 is the size of the phase space point, n2 is the number of points. +""" +function _rand_momenta(rng::AbstractRNG, n1, n2) + moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) + for i in 1:n2 + moms[i] = _rand_momenta(rng, n1) + end + return moms +end + +""" +Return a random phase space point that is failing the incoming phase space constraint, +i.e. the first entry of the phase space is the null momentum. +""" +function _rand_in_momenta_failing(rng::AbstractRNG, n) + return (zero(SFourMomentum), _rand_momenta(rng, n - 1)...) +end + +""" +Return a random phase space point that is failing the outgoing phase space constraint, +i.e. the last entry of the phase space is the unit momentum. +""" +function _rand_out_momenta_failing(rng::AbstractRNG, n) + return (_rand_momenta(rng, n - 1)..., ones(SFourMomentum)) +end + +""" +Return a collection of incoming phase space points, where the first point is failing the phase space constraint, +i.e. the first entry of the vector is invalid but the others pass. +n1 is the size of the phase space point, n2 is the number of points. +""" +function _rand_in_momenta_failing_mix(rng::AbstractRNG, n1, n2) + moms = _rand_momenta(rng, n1, n2) + moms[1] = _rand_in_momenta_failing(rng, n1) + return moms +end + +""" +Return a collection of incoming phase space points, where all points are failing the phase space constraint, +i.e. their first entries are null momenta. +n1 is the size of the phase space point, n2 is the number of points. +""" +function _rand_in_momenta_failing_all(rng::AbstractRNG, n1, n2) + moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) + for i in 1:n2 + moms[i] = _rand_in_momenta_failing(rng, n1) + end + return moms +end + +""" +Return a vector of outgoing phase space points, where the first point is failing the phase space constraint, +i.e. the last entry of the vector is invalid but the others pass. +n1 is the size of the phase space point, n2 is the number of points. +""" +function _rand_out_momenta_failing_mix(rng::AbstractRNG, n1, n2) + moms = _rand_momenta(rng, n1, n2) + moms[end] = _rand_out_momenta_failing(rng, n1) + return moms +end + +""" +Return a vector of outgoing phase space points, where all points are failing the phase space constraint, +i.e. their last entries are unit momenta. +n1 is the size of the phase space point, n2 is the number of points. +""" +function _rand_out_momenta_failing_all(rng::AbstractRNG, n1, n2) + moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) + for i in 1:n2 + moms[i] = _rand_out_momenta_failing(rng, n1) + end + return moms +end diff --git a/test/test_implementation/test_model.jl b/test/test_implementation/test_model.jl new file mode 100644 index 0000000..4aa469b --- /dev/null +++ b/test/test_implementation/test_model.jl @@ -0,0 +1,5 @@ + +struct TestModel <: AbstractModelDefinition end +QEDprocesses.fundamental_interaction_type(::TestModel) = :test_interaction + +struct TestModel_FAIL <: AbstractModelDefinition end diff --git a/test/test_implementation/test_process.jl b/test/test_implementation/test_process.jl new file mode 100644 index 0000000..a15cbb2 --- /dev/null +++ b/test/test_implementation/test_process.jl @@ -0,0 +1,131 @@ +# dummy particles +struct TestParticleFermion <: FermionLike end +struct TestParticleBoson <: BosonLike end + +const PARTICLE_SET = [TestParticleFermion(), TestParticleBoson()] + +""" + TestProcess(rng,incoming_particles,outgoing_particles) + +""" +struct TestProcess{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition + incoming_particles::IP + outgoing_particles::OP +end + +function TestProcess(rng::AbstractRNG, N_in::Int, N_out::Int) + in_particles = rand(rng, PARTICLE_SET, N_in) + out_particles = rand(rng, PARTICLE_SET, N_out) + return TestProcess(in_particles, out_particles) +end + +QEDprocesses.incoming_particles(proc::TestProcess) = proc.incoming_particles +QEDprocesses.outgoing_particles(proc::TestProcess) = proc.outgoing_particles + +struct TestProcess_FAIL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition + incoming_particles::IP + outgoing_particles::OP +end + +function TestProcess_FAIL(rng::AbstractRNG, N_in::Int, N_out::Int) + in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) + out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) + return TestProcess_FAIL(in_particles, out_particles) +end + +function QEDprocesses.in_phase_space_dimension(proc::TestProcess, ::TestModel) + return number_incoming_particles(proc) * 4 +end +function QEDprocesses.out_phase_space_dimension(proc::TestProcess, ::TestModel) + return number_outgoing_particles(proc) * 4 +end + +""" +Test process with no implemented interface. Should fail every usage except construction. +""" +struct TestProcess_FAIL_ALL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition + incoming_particles::IP + outgoing_particles::OP +end + +function TestProcess_FAIL_ALL(rng::AbstractRNG, N_in::Int, N_out::Int) + in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) + out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) + return TestProcess_FAIL_ALL(in_particles, out_particles) +end + +""" +Test process with no implemented interface except the incoming and outgoing particles. +Should fail every usage except construction of itself and the respective phase space point for given four-momenta. +""" +struct TestProcess_FAIL_DIFFCS{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition + incoming_particles::IP + outgoing_particles::OP +end + +function TestProcess_FAIL_DIFFCS(rng::AbstractRNG, N_in::Int, N_out::Int) + in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) + out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) + return TestProcess_FAIL_DIFFCS(in_particles, out_particles) +end + +QEDprocesses.incoming_particles(proc::TestProcess_FAIL_DIFFCS) = proc.incoming_particles +QEDprocesses.outgoing_particles(proc::TestProcess_FAIL_DIFFCS) = proc.outgoing_particles + +# dummy phase space definition + failing phase space definition +struct TestPhasespaceDef <: AbstractPhasespaceDefinition end +struct TestPhasespaceDef_FAIL <: AbstractPhasespaceDefinition end + +# dummy implementation of the process interface + +function QEDprocesses._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel}) + return _groundtruth_incident_flux(momenta(in_psp, QEDbase.Incoming())) +end + +function QEDprocesses._averaging_norm(proc::TestProcess) + return _groundtruth_averaging_norm(proc) +end + +function QEDprocesses._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel}) + in_ps = momenta(psp, QEDbase.Incoming()) + out_ps = momenta(psp, QEDbase.Outgoing()) + return _groundtruth_matrix_element(in_ps, out_ps) +end + +function QEDprocesses._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel}) + in_ps = momenta(psp, QEDbase.Incoming()) + out_ps = momenta(psp, QEDbase.Outgoing()) + return _groundtruth_is_in_phasespace(in_ps, out_ps) +end + +function QEDprocesses._phase_space_factor( + psp::PhaseSpacePoint{<:TestProcess,TestModel,TestPhasespaceDef} +) + in_ps = momenta(psp, QEDbase.Incoming()) + out_ps = momenta(psp, QEDbase.Outgoing()) + return _groundtruth_phase_space_factor(in_ps, out_ps) +end + +function QEDprocesses._generate_incoming_momenta( + proc::TestProcess, + model::TestModel, + phase_space_def::TestPhasespaceDef, + in_phase_space::NTuple{N,T}, +) where {N,T<:Real} + return _groundtruth_generate_momenta(in_phase_space) +end + +function QEDprocesses._generate_outgoing_momenta( + proc::TestProcess, + model::TestModel, + phase_space_def::TestPhasespaceDef, + out_phase_space::NTuple{N,T}, +) where {N,T<:Real} + return _groundtruth_generate_momenta(out_phase_space) +end + +function QEDprocesses._total_probability( + in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef} +) + return _groundtruth_total_probability(momenta(in_psp, QEDbase.Incoming())) +end diff --git a/test/test_implementation/utils.jl b/test/test_implementation/utils.jl new file mode 100644 index 0000000..3a141d9 --- /dev/null +++ b/test/test_implementation/utils.jl @@ -0,0 +1,44 @@ + +# Check if any failed type is in the input +_any_fail(x...) = true +_any_fail(::TestProcess, ::TestModel) = false +_any_fail(::TestProcess, ::TestModel, ::TestPhasespaceDef) = false + +# unrolls all elements of a list of four-momenta into vector of coordinates +function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:QEDbase.AbstractFourMomentum} + return collect(Iterators.flatten(ps_moms)) +end + +function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:QEDbase.AbstractFourMomentum} + res = Matrix{eltype(T)}(undef, size(ps_moms, 1) * 4, size(ps_moms, 2)) + for i in 1:size(ps_moms, 2) + res[:, i] .= _unroll_moms(view(ps_moms, :, i)) + end + return res +end + +flat_components(moms::AbstractVecOrMat) = _unroll_moms(moms) +flat_components(moms::Tuple) = Tuple(_unroll_moms([moms...])) + +# collect components of four-momenta from a vector of coordinates +function __furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} + return SFourMomentum.(eachcol(reshape(ps_coords, 4, :))) +end + +function _furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} + @assert length(ps_coords) % 4 == 0 + return __furl_moms(ps_coords) +end + +function _furl_moms(ps_coords::AbstractMatrix{T}) where {T<:Real} + @assert size(ps_coords, 1) % 4 == 0 + res = Matrix{SFourMomentum}(undef, Int(size(ps_coords, 1)//4), size(ps_coords, 2)) + for i in 1:size(ps_coords, 2) + res[:, i] .= __furl_moms(view(ps_coords, :, i)) + end + return res +end + +function _furl_moms(moms::NTuple{N,Float64}) where {N} + return Tuple(_furl_moms(Vector{Float64}([moms...]))) +end From 4dffa19891e781a1b17ab1c9d52ca5ac3f1d0670 Mon Sep 17 00:00:00 2001 From: Rubydragon Date: Tue, 25 Jun 2024 22:36:38 +0200 Subject: [PATCH 4/6] Remove QEDbase. replacements --- add_QEDcore_dev.jl | 1 - src/QEDprocesses.jl | 14 +++-- src/cross_section/diff_probability.jl | 2 +- .../perturbative/cross_section.jl | 58 ++++++++----------- .../perturbative/total_probability.jl | 2 +- src/processes/one_photon_compton/process.jl | 28 +++++---- src/utils.jl | 4 +- test/cross_sections.jl | 1 + .../one_photon_compton/perturbative.jl | 14 ++--- test/processes/one_photon_compton/process.jl | 52 +++++++---------- .../test_implementation/TestImplementation.jl | 2 +- test/test_implementation/groundtruths.jl | 6 +- test/test_implementation/test_process.jl | 16 ++--- test/test_implementation/utils.jl | 4 +- 14 files changed, 92 insertions(+), 112 deletions(-) diff --git a/add_QEDcore_dev.jl b/add_QEDcore_dev.jl index b0b3443..c8da8a5 100644 --- a/add_QEDcore_dev.jl +++ b/add_QEDcore_dev.jl @@ -3,4 +3,3 @@ using Pkg: Pkg Pkg.add(; url="https://github.com/QEDjl-project/QEDcore.jl", rev="dev") -#Pkg.add(; url="https://github.com/QEDjl-project/QEDbase.jl.git", rev="process_interfaces") diff --git a/src/QEDprocesses.jl b/src/QEDprocesses.jl index 5b78ed9..f722eeb 100644 --- a/src/QEDprocesses.jl +++ b/src/QEDprocesses.jl @@ -1,7 +1,3 @@ - -# TODO: remove after refac -__precompile__(false) - module QEDprocesses # constants @@ -17,7 +13,15 @@ export PerturbativeQED # specific scattering processes export Compton, omega_prime -using QEDbase: QEDbase +# probabilities +export differential_probability, unsafe_differential_probability +export total_probability + +# differential cross sections +export differential_cross_section, unsafe_differential_cross_section +export total_cross_section + +using QEDbase using QEDcore using StaticArrays using QuadGK diff --git a/src/cross_section/diff_probability.jl b/src/cross_section/diff_probability.jl index 0810e97..9d74dc5 100644 --- a/src/cross_section/diff_probability.jl +++ b/src/cross_section/diff_probability.jl @@ -35,7 +35,7 @@ If the given phase spaces are physical, return differential probability evaluate """ function differential_probability(phase_space_point::PhaseSpacePoint) if !_is_in_phasespace(phase_space_point) - return zero(eltype(momentum(phase_space_point, QEDbase.Incoming(), 1))) + return zero(eltype(momentum(phase_space_point, Incoming(), 1))) end return unsafe_differential_probability(phase_space_point) diff --git a/src/processes/one_photon_compton/perturbative/cross_section.jl b/src/processes/one_photon_compton/perturbative/cross_section.jl index 80931d3..e3fed5b 100644 --- a/src/processes/one_photon_compton/perturbative/cross_section.jl +++ b/src/processes/one_photon_compton/perturbative/cross_section.jl @@ -7,12 +7,12 @@ import QEDbase: _incident_flux, _matrix_element, _averaging_norm, _is_in_phasespace, _phase_space_factor function _incident_flux(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) - return momentum(in_psp, QEDbase.Incoming(), 1) * momentum(in_psp, QEDbase.Incoming(), 2) + return momentum(in_psp, Incoming(), 1) * momentum(in_psp, Incoming(), 2) end function _matrix_element(psp::PhaseSpacePoint{<:Compton,PerturbativeQED}) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) + in_ps = momenta(psp, Incoming()) + out_ps = momenta(psp, Outgoing()) return _pert_compton_matrix_element(psp.proc, in_ps, out_ps) end @@ -30,28 +30,24 @@ end @inline function _all_onshell(psp::PhaseSpacePoint{<:Compton}) return @inbounds isapprox( - QEDbase.getMass2(momentum(psp, QEDbase.Incoming(), 1)), - QEDbase.mass(incoming_particles(psp.proc)[1])^2, + getMass2(momentum(psp, Incoming(), 1)), mass(incoming_particles(psp.proc)[1])^2 ) && isapprox( - QEDbase.getMass2(momentum(psp, QEDbase.Incoming(), 2)), - QEDbase.mass(incoming_particles(psp.proc)[2])^2, + getMass2(momentum(psp, Incoming(), 2)), mass(incoming_particles(psp.proc)[2])^2 ) && isapprox( - QEDbase.getMass2(momentum(psp, QEDbase.Outgoing(), 1)), - QEDbase.mass(outgoing_particles(psp.proc)[1])^2, + getMass2(momentum(psp, Outgoing(), 1)), mass(outgoing_particles(psp.proc)[1])^2 ) && isapprox( - QEDbase.getMass2(momentum(psp, QEDbase.Outgoing(), 2)), - QEDbase.mass(outgoing_particles(psp.proc)[2])^2, + getMass2(momentum(psp, Outgoing(), 2)), mass(outgoing_particles(psp.proc)[2])^2 ) end @inline function _is_in_phasespace(psp::PhaseSpacePoint{<:Compton,<:PerturbativeQED}) @inbounds if ( !isapprox( - momentum(psp, QEDbase.Incoming(), 1) + momentum(psp, QEDbase.Incoming(), 2), - momentum(psp, QEDbase.Outgoing(), 1) + momentum(psp, QEDbase.Outgoing(), 2), + momentum(psp, Incoming(), 1) + momentum(psp, Incoming(), 2), + momentum(psp, Outgoing(), 1) + momentum(psp, Outgoing(), 2), ) ) return false @@ -60,8 +56,8 @@ end end @inline function _phase_space_factor(psp::PhaseSpacePoint{<:Compton,PerturbativeQED}) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) + in_ps = momenta(psp, Incoming()) + out_ps = momenta(psp, Outgoing()) return _pert_compton_ps_fac(psp.ps_def, in_ps[2], out_ps[2]) end @@ -71,24 +67,18 @@ end @inline function _pert_compton_matrix_element( proc::Compton, in_ps::NTuple{N,T}, out_ps::NTuple{M,T} -) where {N,M,T<:QEDbase.AbstractFourMomentum} +) where {N,M,T<:AbstractFourMomentum} in_electron_mom = in_ps[1] in_photon_mom = in_ps[2] out_electron_mom = out_ps[1] out_photon_mom = out_ps[2] - in_electron_state = base_state( - Electron(), QEDbase.Incoming(), in_electron_mom, proc.in_spin - ) - in_photon_state = base_state(Photon(), QEDbase.Incoming(), in_photon_mom, proc.in_pol) + in_electron_state = base_state(Electron(), Incoming(), in_electron_mom, proc.in_spin) + in_photon_state = base_state(Photon(), Incoming(), in_photon_mom, proc.in_pol) - out_electron_state = base_state( - Electron(), QEDbase.Outgoing(), out_electron_mom, proc.out_spin - ) + out_electron_state = base_state(Electron(), Outgoing(), out_electron_mom, proc.out_spin) - out_photon_state = base_state( - Photon(), QEDbase.Outgoing(), out_photon_mom, proc.out_pol - ) + out_photon_state = base_state(Photon(), Outgoing(), out_photon_mom, proc.out_pol) return _pert_compton_matrix_element( in_electron_mom, in_electron_state, @@ -110,12 +100,12 @@ function _pert_compton_matrix_element( out_electron_state, out_photon_mom::T, out_photon_state, -) where {T<:QEDbase.AbstractFourMomentum} +) where {T<:AbstractFourMomentum} base_states_comb = Iterators.product( - QEDbase._as_svec(in_electron_state), - QEDbase._as_svec(in_photon_state), - QEDbase._as_svec(out_electron_state), - QEDbase._as_svec(out_photon_state), + _as_svec(in_electron_state), + _as_svec(in_photon_state), + _as_svec(out_electron_state), + _as_svec(out_photon_state), ) matrix_elements = Vector{ComplexF64}() @@ -148,7 +138,7 @@ function _pert_compton_matrix_element_single( out_electron_state::AdjointBiSpinor, out_photon_mom::T, out_photon_state::SLorentzVector, -) where {T<:QEDbase.AbstractFourMomentum} +) where {T<:AbstractFourMomentum} in_ph_slashed = slashed(in_photon_state) out_ph_slashed = slashed(out_photon_state) @@ -178,7 +168,7 @@ function _pert_compton_ps_fac( in_ps_def::PhasespaceDefinition{inCS,ElectronRestFrame}, in_photon_mom, out_photon_mom ) where {inCS} # TODO - omega = QEDbase.getE(in_photon_mom) - omega_prime = QEDbase.getE(out_photon_mom) + omega = getE(in_photon_mom) + omega_prime = getE(out_photon_mom) return omega_prime^2 / (16 * pi^2 * omega * mass(Electron())) end diff --git a/src/processes/one_photon_compton/perturbative/total_probability.jl b/src/processes/one_photon_compton/perturbative/total_probability.jl index 6655b4c..72bae48 100644 --- a/src/processes/one_photon_compton/perturbative/total_probability.jl +++ b/src/processes/one_photon_compton/perturbative/total_probability.jl @@ -1,7 +1,7 @@ import QEDbase: _total_probability function _total_probability(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) - omega = QEDbase.getE(momentum(in_psp[QEDbase.Incoming(), 2])) + omega = getE(momentum(in_psp[Incoming(), 2])) function func(x) return unsafe_differential_probability( diff --git a/src/processes/one_photon_compton/process.jl b/src/processes/one_photon_compton/process.jl index 537b09d..6caa813 100644 --- a/src/processes/one_photon_compton/process.jl +++ b/src/processes/one_photon_compton/process.jl @@ -8,10 +8,10 @@ """ struct Compton{InElectronSpin,InPhotonPol,OutElectronSpin,OutPhotonPol} <: AbstractProcessDefinition where { - InElectronSpin<:QEDbase.AbstractSpin, - InPhotonPol<:QEDbase.AbstractPolarization, - OutElectronSpin<:QEDbase.AbstractSpin, - OutPhotonPol<:QEDbase.AbstractPolarization, + InElectronSpin<:AbstractSpin, + InPhotonPol<:AbstractPolarization, + OutElectronSpin<:AbstractSpin, + OutPhotonPol<:AbstractPolarization, } in_spin::InElectronSpin in_pol::InPhotonPol @@ -21,16 +21,14 @@ struct Compton{InElectronSpin,InPhotonPol,OutElectronSpin,OutPhotonPol} <: end function Compton() - return Compton(QEDbase.AllSpin(), QEDbase.AllPol(), QEDbase.AllSpin(), QEDbase.AllPol()) + return Compton(AllSpin(), AllPol(), AllSpin(), AllPol()) end -function Compton(in_pol::QEDbase.AbstractPolarization) - return Compton(QEDbase.AllSpin(), in_pol, QEDbase.AllSpin(), QEDbase.AllPol()) +function Compton(in_pol::AbstractPolarization) + return Compton(AllSpin(), in_pol, AllSpin(), AllPol()) end -function Compton( - in_pol::QEDbase.AbstractPolarization, out_pol::QEDbase.AbstractPolarization -) - return Compton(QEDbase.AllSpin(), in_pol, QEDbase.AllSpin(), out_pol) +function Compton(in_pol::AbstractPolarization, out_pol::AbstractPolarization) + return Compton(AllSpin(), in_pol, AllSpin(), out_pol) end _polarizations(proc::Compton) = (proc.in_pol, proc.out_pol) @@ -46,19 +44,19 @@ function QEDprocesses.outgoing_particles(::Compton) return (Electron(), Photon()) end -function _spin_or_pol(process::Compton, ::Electron, ::QEDbase.Incoming) +function _spin_or_pol(process::Compton, ::Electron, ::Incoming) return process.in_spin end -function _spin_or_pol(process::Compton, ::Electron, ::QEDbase.Outgoing) +function _spin_or_pol(process::Compton, ::Electron, ::Outgoing) return process.out_spin end -function _spin_or_pol(process::Compton, ::Photon, ::QEDbase.Incoming) +function _spin_or_pol(process::Compton, ::Photon, ::Incoming) return process.in_pol end -function _spin_or_pol(process::Compton, ::Photon, ::QEDbase.Outgoing) +function _spin_or_pol(process::Compton, ::Photon, ::Outgoing) return process.out_pol end diff --git a/src/utils.jl b/src/utils.jl index ee06356..97eb6a2 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -6,7 +6,7 @@ """ - _base_component_type(array_of_lv::AbstractArray{LV}) where {LV<:QEDbase.AbstractLorentzVector} + _base_component_type(array_of_lv::AbstractArray{LV}) where {LV<:AbstractLorentzVector} Return the type of the components of given Lorentz vectors, which are by themself elements of an `AbstractArray`. @@ -20,6 +20,6 @@ julia> QEDprocesses._base_component_type(v) Float64 ``` """ -function _base_component_type(::AbstractArray{LV}) where {LV<:QEDbase.AbstractLorentzVector} +function _base_component_type(::AbstractArray{LV}) where {LV<:AbstractLorentzVector} return eltype(LV) end diff --git a/test/cross_sections.jl b/test/cross_sections.jl index 8861f78..bf5d116 100644 --- a/test/cross_sections.jl +++ b/test/cross_sections.jl @@ -1,5 +1,6 @@ using Random using QEDbase +using QEDcore using QEDprocesses RNG = MersenneTwister(137137) diff --git a/test/processes/one_photon_compton/perturbative.jl b/test/processes/one_photon_compton/perturbative.jl index d59d8e1..bf6dfc3 100644 --- a/test/processes/one_photon_compton/perturbative.jl +++ b/test/processes/one_photon_compton/perturbative.jl @@ -38,10 +38,10 @@ end IN_PS, OUT_PS = QEDprocesses._generate_momenta( PROC, MODEL, PS_DEF, IN_COORDS, OUT_COORDS ) - in_mom_square = QEDbase.getMass2.(IN_PS) - out_mom_square = QEDbase.getMass2.(OUT_PS) - in_masses = QEDbase.mass.(incoming_particles(PROC)) .^ 2 - out_masses = QEDbase.mass.(outgoing_particles(PROC)) .^ 2 + in_mom_square = getMass2.(IN_PS) + out_mom_square = getMass2.(OUT_PS) + in_masses = mass.(incoming_particles(PROC)) .^ 2 + out_masses = mass.(outgoing_particles(PROC)) .^ 2 # we need a larger ATOL than eps() here because the error is accumulated over several additions @test all(isapprox.(in_mom_square, in_masses, atol=4 * ATOL, rtol=RTOL)) @@ -76,7 +76,7 @@ end end @testset "x-pol and spin summed" begin - PROC = Compton(QEDbase.PolX()) + PROC = Compton(PolX()) @testset "$cos_theta $phi" for (cos_theta, phi) in Iterators.product(COS_THETAS, PHIS) @@ -98,7 +98,7 @@ end end @testset "y-pol and spin summed" begin - PROC = Compton(QEDbase.PolY()) + PROC = Compton(PolY()) @testset "$cos_theta $phi" for (cos_theta, phi) in Iterators.product(COS_THETAS, PHIS) @@ -155,7 +155,7 @@ end out_moms = momenta( PhaseSpacePoint(PROC, MODEL, PS_DEF, IN_COORDS, OUT_COORDS), - QEDbase.Outgoing(), + Outgoing(), ) @test_throws MethodError QEDprocesses.total_cross_section( OutPhaseSpacePoint(PROC, MODEL, PS_DEF, out_moms) diff --git a/test/processes/one_photon_compton/process.jl b/test/processes/one_photon_compton/process.jl index 1e13c87..4e7e669 100644 --- a/test/processes/one_photon_compton/process.jl +++ b/test/processes/one_photon_compton/process.jl @@ -3,8 +3,8 @@ using Random using QEDbase: QEDbase using QEDcore -POLS = [QEDbase.PolX(), QEDbase.PolY(), QEDbase.AllPol()] -SPINS = [QEDbase.SpinUp(), QEDbase.SpinDown(), QEDbase.AllSpin()] +POLS = [PolX(), PolY(), AllPol()] +SPINS = [SpinUp(), SpinDown(), AllSpin()] POL_AND_SPIN_COMBINATIONS = Iterators.product(SPINS, POLS, SPINS, POLS) POL_COMBINATIONS = Iterators.product(POLS, POLS) BUF = IOBuffer() @@ -12,59 +12,50 @@ BUF = IOBuffer() @testset "constructor" begin @testset "default" begin proc = Compton() - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == - QEDbase.AllPol() - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) == - QEDbase.AllSpin() - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) == - QEDbase.AllPol() - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) == - QEDbase.AllSpin() + @test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == AllPol() + @test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == AllSpin() + @test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == AllPol() + @test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == AllSpin() print(BUF, proc) @test String(take!(BUF)) == "one-photon Compton scattering" show(BUF, MIME"text/plain"(), proc) @test String(take!(BUF)) == - "one-photon Compton scattering\n incoming: electron ($(QEDbase.AllSpin())), photon ($(QEDbase.AllPol()))\n outgoing: electron ($(QEDbase.AllSpin())), photon ($(QEDbase.AllPol()))\n" + "one-photon Compton scattering\n incoming: electron ($(AllSpin())), photon ($(AllPol()))\n outgoing: electron ($(AllSpin())), photon ($(AllPol()))\n" end @testset "in_pol" begin @testset "$pol" for pol in POLS proc = Compton(pol) - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) == - QEDbase.AllSpin() - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == pol - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) == - QEDbase.AllSpin() - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) == - QEDbase.AllPol() + @test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == AllSpin() + @test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == pol + @test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == AllSpin() + @test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == AllPol() print(BUF, proc) @test String(take!(BUF)) == "one-photon Compton scattering" show(BUF, MIME"text/plain"(), proc) @test String(take!(BUF)) == - "one-photon Compton scattering\n incoming: electron ($(QEDbase.AllSpin())), photon ($(pol))\n outgoing: electron ($(QEDbase.AllSpin())), photon ($(QEDbase.AllPol()))\n" + "one-photon Compton scattering\n incoming: electron ($(AllSpin())), photon ($(pol))\n outgoing: electron ($(AllSpin())), photon ($(AllPol()))\n" end end @testset "in_pol+out_pol" begin @testset "$in_pol, $out_pol" for (in_pol, out_pol) in POL_COMBINATIONS proc = Compton(in_pol, out_pol) - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) == - QEDbase.AllSpin() - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == in_pol - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) == - QEDbase.AllSpin() - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) == out_pol + @test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == AllSpin() + @test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == in_pol + @test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == AllSpin() + @test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == out_pol print(BUF, proc) @test String(take!(BUF)) == "one-photon Compton scattering" show(BUF, MIME"text/plain"(), proc) @test String(take!(BUF)) == - "one-photon Compton scattering\n incoming: electron ($(QEDbase.AllSpin())), photon ($(in_pol))\n outgoing: electron ($(QEDbase.AllSpin())), photon ($(out_pol))\n" + "one-photon Compton scattering\n incoming: electron ($(AllSpin())), photon ($(in_pol))\n outgoing: electron ($(AllSpin())), photon ($(out_pol))\n" end end @testset "all spins+pols" begin @@ -72,11 +63,10 @@ BUF = IOBuffer() in_spin, in_pol, out_spin, out_pol ) in POL_AND_SPIN_COMBINATIONS proc = Compton(in_spin, in_pol, out_spin, out_pol) - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) == in_spin - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == in_pol - @test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) == - out_spin - @test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) == out_pol + @test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == in_spin + @test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == in_pol + @test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == out_spin + @test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == out_pol print(BUF, proc) @test String(take!(BUF)) == "one-photon Compton scattering" diff --git a/test/test_implementation/TestImplementation.jl b/test/test_implementation/TestImplementation.jl index a46dc89..714fda2 100644 --- a/test/test_implementation/TestImplementation.jl +++ b/test/test_implementation/TestImplementation.jl @@ -26,7 +26,7 @@ export TestProcess, TestProcess_FAIL export TestPhasespaceDef, TestPhasespaceDef_FAIL using Random -using QEDbase: QEDbase +using QEDbase using QEDcore using QEDprocesses using StaticArrays diff --git a/test/test_implementation/groundtruths.jl b/test/test_implementation/groundtruths.jl index b9d0883..fce9891 100644 --- a/test/test_implementation/groundtruths.jl +++ b/test/test_implementation/groundtruths.jl @@ -1,5 +1,3 @@ -import QEDbase.AbstractFourMomentum - """ _groundtruth_incident_flux(in_ps) @@ -59,8 +57,8 @@ end Test implementation of the phase space factor. Return the inverse of the product of the energies of all external particles. """ function _groundtruth_phase_space_factor(in_ps, out_ps) - en_in = QEDbase.getE.(in_ps) - en_out = QEDbase.getE.(out_ps) + en_in = getE.(in_ps) + en_out = getE.(out_ps) return 1 / (prod(en_in) * prod(en_out)) end diff --git a/test/test_implementation/test_process.jl b/test/test_implementation/test_process.jl index a15cbb2..9c7fd5d 100644 --- a/test/test_implementation/test_process.jl +++ b/test/test_implementation/test_process.jl @@ -79,7 +79,7 @@ struct TestPhasespaceDef_FAIL <: AbstractPhasespaceDefinition end # dummy implementation of the process interface function QEDprocesses._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel}) - return _groundtruth_incident_flux(momenta(in_psp, QEDbase.Incoming())) + return _groundtruth_incident_flux(momenta(in_psp, Incoming())) end function QEDprocesses._averaging_norm(proc::TestProcess) @@ -87,22 +87,22 @@ function QEDprocesses._averaging_norm(proc::TestProcess) end function QEDprocesses._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel}) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) + in_ps = momenta(psp, Incoming()) + out_ps = momenta(psp, Outgoing()) return _groundtruth_matrix_element(in_ps, out_ps) end function QEDprocesses._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel}) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) + in_ps = momenta(psp, Incoming()) + out_ps = momenta(psp, Outgoing()) return _groundtruth_is_in_phasespace(in_ps, out_ps) end function QEDprocesses._phase_space_factor( psp::PhaseSpacePoint{<:TestProcess,TestModel,TestPhasespaceDef} ) - in_ps = momenta(psp, QEDbase.Incoming()) - out_ps = momenta(psp, QEDbase.Outgoing()) + in_ps = momenta(psp, Incoming()) + out_ps = momenta(psp, Outgoing()) return _groundtruth_phase_space_factor(in_ps, out_ps) end @@ -127,5 +127,5 @@ end function QEDprocesses._total_probability( in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef} ) - return _groundtruth_total_probability(momenta(in_psp, QEDbase.Incoming())) + return _groundtruth_total_probability(momenta(in_psp, Incoming())) end diff --git a/test/test_implementation/utils.jl b/test/test_implementation/utils.jl index 3a141d9..8804b29 100644 --- a/test/test_implementation/utils.jl +++ b/test/test_implementation/utils.jl @@ -5,11 +5,11 @@ _any_fail(::TestProcess, ::TestModel) = false _any_fail(::TestProcess, ::TestModel, ::TestPhasespaceDef) = false # unrolls all elements of a list of four-momenta into vector of coordinates -function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:QEDbase.AbstractFourMomentum} +function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:AbstractFourMomentum} return collect(Iterators.flatten(ps_moms)) end -function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:QEDbase.AbstractFourMomentum} +function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:AbstractFourMomentum} res = Matrix{eltype(T)}(undef, size(ps_moms, 1) * 4, size(ps_moms, 2)) for i in 1:size(ps_moms, 2) res[:, i] .= _unroll_moms(view(ps_moms, :, i)) From 6ead68ad018cee28398013e76d8ef97177473032 Mon Sep 17 00:00:00 2001 From: Rubydragon Date: Wed, 26 Jun 2024 00:24:36 +0200 Subject: [PATCH 5/6] Fix namespace issues --- src/cross_section/diff_cross_section.jl | 6 ++-- src/cross_section/diff_probability.jl | 8 ++--- src/cross_section/total_cross_section.jl | 4 +-- src/cross_section/total_probability.jl | 2 +- src/models/models.jl | 3 -- src/models/perturbative_qed.jl | 10 ++++-- .../perturbative/cross_section.jl | 31 ++++++++++--------- .../perturbative/kinematics.jl | 8 ++--- .../perturbative/total_probability.jl | 4 +-- test/cross_sections.jl | 12 +++---- .../one_photon_compton/perturbative.jl | 10 +++--- test/processes/one_photon_compton/process.jl | 2 +- test/test_implementation/test_model.jl | 2 +- test/test_implementation/test_process.jl | 28 ++++++++--------- 14 files changed, 64 insertions(+), 66 deletions(-) diff --git a/src/cross_section/diff_cross_section.jl b/src/cross_section/diff_cross_section.jl index 0a32b1c..6f35603 100644 --- a/src/cross_section/diff_cross_section.jl +++ b/src/cross_section/diff_cross_section.jl @@ -11,7 +11,7 @@ Return the differential cross section evaluated on a phase space point without checking if the given phase space is physical. """ function unsafe_differential_cross_section(phase_space_point::PhaseSpacePoint) - I = 1 / (4 * _incident_flux(phase_space_point)) + I = 1 / (4 * QEDbase._incident_flux(phase_space_point)) return I * unsafe_differential_probability(phase_space_point) end @@ -22,8 +22,8 @@ end If the given phase spaces are physical, return differential cross section evaluated on a phase space point. Zero otherwise. """ function differential_cross_section(phase_space_point::PhaseSpacePoint) - if !_is_in_phasespace(phase_space_point) - return zero(eltype(_momentum_type(phase_space_point))) + if !QEDbase._is_in_phasespace(phase_space_point) + return zero(eltype(QEDcore._momentum_type(phase_space_point))) end return unsafe_differential_cross_section(phase_space_point) diff --git a/src/cross_section/diff_probability.jl b/src/cross_section/diff_probability.jl index 9d74dc5..e6d4eec 100644 --- a/src/cross_section/diff_probability.jl +++ b/src/cross_section/diff_probability.jl @@ -9,7 +9,7 @@ # convenience function # can be overloaded if an analytical version is known function _matrix_element_square(psp::PhaseSpacePoint) - mat_el = _matrix_element(psp) + mat_el = QEDbase._matrix_element(psp) return abs2.(mat_el) end @@ -21,9 +21,9 @@ Return differential probability evaluated on a phase space point without checkin function unsafe_differential_probability(psp::PhaseSpacePoint) matrix_elements_sq = _matrix_element_square(psp) - normalization = _averaging_norm(psp.proc) + normalization = QEDbase._averaging_norm(psp.proc) - ps_fac = _phase_space_factor(psp) + ps_fac = QEDbase._phase_space_factor(psp) return normalization * sum(matrix_elements_sq) * ps_fac end @@ -34,7 +34,7 @@ end If the given phase spaces are physical, return differential probability evaluated on a phase space point. Zero otherwise. """ function differential_probability(phase_space_point::PhaseSpacePoint) - if !_is_in_phasespace(phase_space_point) + if !QEDbase._is_in_phasespace(phase_space_point) return zero(eltype(momentum(phase_space_point, Incoming(), 1))) end diff --git a/src/cross_section/total_cross_section.jl b/src/cross_section/total_cross_section.jl index f4a5ffa..7d838b0 100644 --- a/src/cross_section/total_cross_section.jl +++ b/src/cross_section/total_cross_section.jl @@ -9,6 +9,6 @@ Return the total cross section for a given [`InPhaseSpacePoint`](@ref). """ function total_cross_section(in_psp::InPhaseSpacePoint) - I = 1 / (4 * _incident_flux(in_psp)) - return I * _total_probability(in_psp) + I = 1 / (4 * QEDbase._incident_flux(in_psp)) + return I * QEDbase._total_probability(in_psp) end diff --git a/src/cross_section/total_probability.jl b/src/cross_section/total_probability.jl index 446900f..96cf9ba 100644 --- a/src/cross_section/total_probability.jl +++ b/src/cross_section/total_probability.jl @@ -8,5 +8,5 @@ Return the total probability of a given [`InPhaseSpacePoint`](@ref). """ function total_probability(in_psp::InPhaseSpacePoint) - return _total_probability(in_psp) + return QEDbase._total_probability(in_psp) end diff --git a/src/models/models.jl b/src/models/models.jl index 1ed8e75..4d74b9d 100644 --- a/src/models/models.jl +++ b/src/models/models.jl @@ -1,4 +1 @@ -import QEDbase: - in_phase_space_dimension, out_phase_space_dimension, fundamental_interaction_type - include("perturbative_qed.jl") diff --git a/src/models/perturbative_qed.jl b/src/models/perturbative_qed.jl index 39d47ac..8592b33 100644 --- a/src/models/perturbative_qed.jl +++ b/src/models/perturbative_qed.jl @@ -1,7 +1,7 @@ struct PerturbativeQED <: AbstractModelDefinition end -fundamental_interaction_type(::PerturbativeQED) = :electromagnetic +QEDbase.fundamental_interaction_type(::PerturbativeQED) = :electromagnetic """ in_phase_space_dimension(proc::AbstractProcessDefinition, ::PerturbativeQED) @@ -12,11 +12,15 @@ Return the number of degrees of freedom to determine the incoming phase space fo The current implementation only supports the case where two of the incoming particles collide head-on. """ -function in_phase_space_dimension(proc::AbstractProcessDefinition, ::PerturbativeQED) +function QEDbase.in_phase_space_dimension( + proc::AbstractProcessDefinition, ::PerturbativeQED +) return 3 * number_incoming_particles(proc) - 4 - 1 end -function out_phase_space_dimension(proc::AbstractProcessDefinition, ::PerturbativeQED) +function QEDbase.out_phase_space_dimension( + proc::AbstractProcessDefinition, ::PerturbativeQED +) return 3 * number_outgoing_particles(proc) - 4 end diff --git a/src/processes/one_photon_compton/perturbative/cross_section.jl b/src/processes/one_photon_compton/perturbative/cross_section.jl index e3fed5b..e86322f 100644 --- a/src/processes/one_photon_compton/perturbative/cross_section.jl +++ b/src/processes/one_photon_compton/perturbative/cross_section.jl @@ -3,14 +3,11 @@ # Implementation of the cross section interface ##### -import QEDbase: - _incident_flux, _matrix_element, _averaging_norm, _is_in_phasespace, _phase_space_factor - -function _incident_flux(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) +function QEDbase._incident_flux(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) return momentum(in_psp, Incoming(), 1) * momentum(in_psp, Incoming(), 2) end -function _matrix_element(psp::PhaseSpacePoint{<:Compton,PerturbativeQED}) +function QEDbase._matrix_element(psp::PhaseSpacePoint{<:Compton,PerturbativeQED}) in_ps = momenta(psp, Incoming()) out_ps = momenta(psp, Outgoing()) return _pert_compton_matrix_element(psp.proc, in_ps, out_ps) @@ -23,8 +20,8 @@ end We average over the initial spins and pols, and sum over final. """ -function _averaging_norm(proc::Compton) - normalizations = number_of_spin_pol.(_in_spin_and_pol(proc)) +function QEDbase._averaging_norm(proc::Compton) + normalizations = multiplicity.(_in_spin_and_pol(proc)) return inv(prod(normalizations)) end @@ -43,7 +40,9 @@ end ) end -@inline function _is_in_phasespace(psp::PhaseSpacePoint{<:Compton,<:PerturbativeQED}) +@inline function QEDbase._is_in_phasespace( + psp::PhaseSpacePoint{<:Compton,<:PerturbativeQED} +) @inbounds if ( !isapprox( momentum(psp, Incoming(), 1) + momentum(psp, Incoming(), 2), @@ -55,7 +54,9 @@ end return _all_onshell(psp) end -@inline function _phase_space_factor(psp::PhaseSpacePoint{<:Compton,PerturbativeQED}) +@inline function QEDbase._phase_space_factor( + psp::PhaseSpacePoint{<:Compton,PerturbativeQED} +) in_ps = momenta(psp, Incoming()) out_ps = momenta(psp, Outgoing()) return _pert_compton_ps_fac(psp.ps_def, in_ps[2], out_ps[2]) @@ -102,10 +103,10 @@ function _pert_compton_matrix_element( out_photon_state, ) where {T<:AbstractFourMomentum} base_states_comb = Iterators.product( - _as_svec(in_electron_state), - _as_svec(in_photon_state), - _as_svec(out_electron_state), - _as_svec(out_photon_state), + QEDbase._as_svec(in_electron_state), + QEDbase._as_svec(in_photon_state), + QEDbase._as_svec(out_electron_state), + QEDbase._as_svec(out_photon_state), ) matrix_elements = Vector{ComplexF64}() @@ -142,8 +143,8 @@ function _pert_compton_matrix_element_single( in_ph_slashed = slashed(in_photon_state) out_ph_slashed = slashed(out_photon_state) - prop1 = _fermion_propagator(in_photon_mom + in_electron_mom, mass(Electron())) - prop2 = _fermion_propagator(in_electron_mom - out_photon_mom, mass(Electron())) + prop1 = QEDcore._fermion_propagator(in_photon_mom + in_electron_mom, mass(Electron())) + prop2 = QEDcore._fermion_propagator(in_electron_mom - out_photon_mom, mass(Electron())) # TODO: fermion propagator is not yet in QEDbase diagram_1 = diff --git a/src/processes/one_photon_compton/perturbative/kinematics.jl b/src/processes/one_photon_compton/perturbative/kinematics.jl index c7cfdb9..b28ac1e 100644 --- a/src/processes/one_photon_compton/perturbative/kinematics.jl +++ b/src/processes/one_photon_compton/perturbative/kinematics.jl @@ -1,5 +1,3 @@ -import QEDbase: _generate_incoming_momenta, _generate_outgoing_momenta, _generate_momenta - @inline function _pert_omega_prime(omega, cth; mass=1.0) return omega / (1 + omega / mass * (1 - cth)) end @@ -11,10 +9,10 @@ function generate_momenta( in_ps::NTuple{N,T}, out_ps::NTuple{M,T}, ) where {N,M,T<:Real} - return _generate_momenta(proc, model, in_ps_def, in_ps, out_ps) + return QEDbase._generate_momenta(proc, model, in_ps_def, in_ps, out_ps) end -function _generate_incoming_momenta( +function QEDbase._generate_incoming_momenta( proc::Compton, model::PerturbativeQED, in_ps_def::PhasespaceDefinition{SphericalCoordinateSystem,ElectronRestFrame}, @@ -28,7 +26,7 @@ function _generate_incoming_momenta( return P, K end -function _generate_momenta( +function QEDbase._generate_momenta( proc::Compton, model::PerturbativeQED, in_ps_def::PhasespaceDefinition{SphericalCoordinateSystem,ElectronRestFrame}, diff --git a/src/processes/one_photon_compton/perturbative/total_probability.jl b/src/processes/one_photon_compton/perturbative/total_probability.jl index 72bae48..e3cca7e 100644 --- a/src/processes/one_photon_compton/perturbative/total_probability.jl +++ b/src/processes/one_photon_compton/perturbative/total_probability.jl @@ -1,6 +1,4 @@ -import QEDbase: _total_probability - -function _total_probability(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) +function QEDbase._total_probability(in_psp::InPhaseSpacePoint{<:Compton,<:PerturbativeQED}) omega = getE(momentum(in_psp[Incoming(), 2])) function func(x) diff --git a/test/cross_sections.jl b/test/cross_sections.jl index bf5d116..8e56523 100644 --- a/test/cross_sections.jl +++ b/test/cross_sections.jl @@ -40,7 +40,7 @@ TESTPSDEF = TestImplementation.TestPhasespaceDef() TESTPROC, TESTMODEL, TESTPSDEF, p_in_phys, p_out_phys ) - diffCS_on_psp = unsafe_differential_cross_section(PS_POINT) + diffCS_on_psp = QEDprocesses.unsafe_differential_cross_section(PS_POINT) groundtruth = TestImplementation._groundtruth_unsafe_diffCS( TESTPROC, p_in_phys, p_out_phys ) @@ -52,7 +52,7 @@ TESTPSDEF = TestImplementation.TestPhasespaceDef() for (P_IN, P_OUT) in p_combs PS_POINT = PhaseSpacePoint(TESTPROC, TESTMODEL, TESTPSDEF, P_IN, P_OUT) - diffCS_on_psp = differential_cross_section(PS_POINT) + diffCS_on_psp = QEDprocesses.differential_cross_section(PS_POINT) groundtruth = TestImplementation._groundtruth_safe_diffCS( TESTPROC, P_IN, P_OUT ) @@ -85,7 +85,7 @@ TESTPSDEF = TestImplementation.TestPhasespaceDef() PS_POINT = PhaseSpacePoint( TESTPROC, TESTMODEL, TESTPSDEF, p_in_phys, p_out_phys ) - prop_on_psp = unsafe_differential_probability(PS_POINT) + prop_on_psp = QEDprocesses.unsafe_differential_probability(PS_POINT) groundtruth = TestImplementation._groundtruth_unsafe_probability( TESTPROC, p_in_phys, p_out_phys ) @@ -95,7 +95,7 @@ TESTPSDEF = TestImplementation.TestPhasespaceDef() @testset "safe compute" begin for (P_IN, P_OUT) in p_combs PS_POINT = PhaseSpacePoint(TESTPROC, TESTMODEL, TESTPSDEF, P_IN, P_OUT) - prop_on_psp = differential_probability(PS_POINT) + prop_on_psp = QEDprocesses.differential_probability(PS_POINT) groundtruth = TestImplementation._groundtruth_safe_probability( TESTPROC, P_IN, P_OUT ) @@ -114,8 +114,8 @@ TESTPSDEF = TestImplementation.TestPhasespaceDef() ) groundtruth = TestImplementation._groundtruth_total_probability(p_in_phys) - totCS_on_moms = total_probability(IN_PS_POINT) - totCS_on_coords = total_probability(IN_PS_POINT_COORDS) + totCS_on_moms = QEDprocesses.total_probability(IN_PS_POINT) + totCS_on_coords = QEDprocesses.total_probability(IN_PS_POINT_COORDS) @test isapprox(totCS_on_moms, groundtruth, atol=ATOL, rtol=RTOL) @test isapprox(totCS_on_coords, groundtruth, atol=ATOL, rtol=RTOL) diff --git a/test/processes/one_photon_compton/perturbative.jl b/test/processes/one_photon_compton/perturbative.jl index bf6dfc3..c7abf1f 100644 --- a/test/processes/one_photon_compton/perturbative.jl +++ b/test/processes/one_photon_compton/perturbative.jl @@ -1,5 +1,5 @@ -using QEDbase: QEDbase +using QEDbase using QEDcore using QEDprocesses using Random @@ -35,7 +35,7 @@ end Iterators.product(OMEGAS, COS_THETAS, PHIS) IN_COORDS = (om,) OUT_COORDS = (cth, phi) - IN_PS, OUT_PS = QEDprocesses._generate_momenta( + IN_PS, OUT_PS = QEDbase._generate_momenta( PROC, MODEL, PS_DEF, IN_COORDS, OUT_COORDS ) in_mom_square = getMass2.(IN_PS) @@ -60,7 +60,7 @@ end Iterators.product(COS_THETAS, PHIS) IN_COORDS = (omega,) OUT_COORDS = (cos_theta, phi) - IN_PS, OUT_PS = QEDprocesses._generate_momenta( + IN_PS, OUT_PS = QEDbase._generate_momenta( PROC, MODEL, PS_DEF, IN_COORDS, OUT_COORDS ) @@ -82,7 +82,7 @@ end Iterators.product(COS_THETAS, PHIS) IN_COORDS = (omega,) OUT_COORDS = (cos_theta, phi) - IN_PS, OUT_PS = QEDprocesses._generate_momenta( + IN_PS, OUT_PS = QEDbase._generate_momenta( PROC, MODEL, PS_DEF, IN_COORDS, OUT_COORDS ) @@ -104,7 +104,7 @@ end Iterators.product(COS_THETAS, PHIS) IN_COORDS = (omega,) OUT_COORDS = (cos_theta, phi) - IN_PS, OUT_PS = QEDprocesses._generate_momenta( + IN_PS, OUT_PS = QEDbase._generate_momenta( PROC, MODEL, PS_DEF, IN_COORDS, OUT_COORDS ) diff --git a/test/processes/one_photon_compton/process.jl b/test/processes/one_photon_compton/process.jl index 4e7e669..0ddc431 100644 --- a/test/processes/one_photon_compton/process.jl +++ b/test/processes/one_photon_compton/process.jl @@ -1,6 +1,6 @@ using QEDprocesses using Random -using QEDbase: QEDbase +using QEDbase using QEDcore POLS = [PolX(), PolY(), AllPol()] diff --git a/test/test_implementation/test_model.jl b/test/test_implementation/test_model.jl index 4aa469b..12b961f 100644 --- a/test/test_implementation/test_model.jl +++ b/test/test_implementation/test_model.jl @@ -1,5 +1,5 @@ struct TestModel <: AbstractModelDefinition end -QEDprocesses.fundamental_interaction_type(::TestModel) = :test_interaction +QEDbase.fundamental_interaction_type(::TestModel) = :test_interaction struct TestModel_FAIL <: AbstractModelDefinition end diff --git a/test/test_implementation/test_process.jl b/test/test_implementation/test_process.jl index 9c7fd5d..5a81146 100644 --- a/test/test_implementation/test_process.jl +++ b/test/test_implementation/test_process.jl @@ -19,8 +19,8 @@ function TestProcess(rng::AbstractRNG, N_in::Int, N_out::Int) return TestProcess(in_particles, out_particles) end -QEDprocesses.incoming_particles(proc::TestProcess) = proc.incoming_particles -QEDprocesses.outgoing_particles(proc::TestProcess) = proc.outgoing_particles +QEDbase.incoming_particles(proc::TestProcess) = proc.incoming_particles +QEDbase.outgoing_particles(proc::TestProcess) = proc.outgoing_particles struct TestProcess_FAIL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition incoming_particles::IP @@ -33,10 +33,10 @@ function TestProcess_FAIL(rng::AbstractRNG, N_in::Int, N_out::Int) return TestProcess_FAIL(in_particles, out_particles) end -function QEDprocesses.in_phase_space_dimension(proc::TestProcess, ::TestModel) +function QEDbase.in_phase_space_dimension(proc::TestProcess, ::TestModel) return number_incoming_particles(proc) * 4 end -function QEDprocesses.out_phase_space_dimension(proc::TestProcess, ::TestModel) +function QEDbase.out_phase_space_dimension(proc::TestProcess, ::TestModel) return number_outgoing_particles(proc) * 4 end @@ -69,8 +69,8 @@ function TestProcess_FAIL_DIFFCS(rng::AbstractRNG, N_in::Int, N_out::Int) return TestProcess_FAIL_DIFFCS(in_particles, out_particles) end -QEDprocesses.incoming_particles(proc::TestProcess_FAIL_DIFFCS) = proc.incoming_particles -QEDprocesses.outgoing_particles(proc::TestProcess_FAIL_DIFFCS) = proc.outgoing_particles +QEDbase.incoming_particles(proc::TestProcess_FAIL_DIFFCS) = proc.incoming_particles +QEDbase.outgoing_particles(proc::TestProcess_FAIL_DIFFCS) = proc.outgoing_particles # dummy phase space definition + failing phase space definition struct TestPhasespaceDef <: AbstractPhasespaceDefinition end @@ -78,27 +78,27 @@ struct TestPhasespaceDef_FAIL <: AbstractPhasespaceDefinition end # dummy implementation of the process interface -function QEDprocesses._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel}) +function QEDbase._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel}) return _groundtruth_incident_flux(momenta(in_psp, Incoming())) end -function QEDprocesses._averaging_norm(proc::TestProcess) +function QEDbase._averaging_norm(proc::TestProcess) return _groundtruth_averaging_norm(proc) end -function QEDprocesses._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel}) +function QEDbase._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel}) in_ps = momenta(psp, Incoming()) out_ps = momenta(psp, Outgoing()) return _groundtruth_matrix_element(in_ps, out_ps) end -function QEDprocesses._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel}) +function QEDbase._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel}) in_ps = momenta(psp, Incoming()) out_ps = momenta(psp, Outgoing()) return _groundtruth_is_in_phasespace(in_ps, out_ps) end -function QEDprocesses._phase_space_factor( +function QEDbase._phase_space_factor( psp::PhaseSpacePoint{<:TestProcess,TestModel,TestPhasespaceDef} ) in_ps = momenta(psp, Incoming()) @@ -106,7 +106,7 @@ function QEDprocesses._phase_space_factor( return _groundtruth_phase_space_factor(in_ps, out_ps) end -function QEDprocesses._generate_incoming_momenta( +function QEDbase._generate_incoming_momenta( proc::TestProcess, model::TestModel, phase_space_def::TestPhasespaceDef, @@ -115,7 +115,7 @@ function QEDprocesses._generate_incoming_momenta( return _groundtruth_generate_momenta(in_phase_space) end -function QEDprocesses._generate_outgoing_momenta( +function QEDbase._generate_outgoing_momenta( proc::TestProcess, model::TestModel, phase_space_def::TestPhasespaceDef, @@ -124,7 +124,7 @@ function QEDprocesses._generate_outgoing_momenta( return _groundtruth_generate_momenta(out_phase_space) end -function QEDprocesses._total_probability( +function QEDbase._total_probability( in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef} ) return _groundtruth_total_probability(momenta(in_psp, Incoming())) From bbbfdea69cb333f03a0643d9e8df151856e9f7d7 Mon Sep 17 00:00:00 2001 From: Rubydragon Date: Thu, 27 Jun 2024 14:46:13 +0200 Subject: [PATCH 6/6] Fix docs building --- docs/make.jl | 11 ++++++++++- src/cross_section/total_cross_section.jl | 2 +- src/cross_section/total_probability.jl | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 9e957e5..35a4832 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,14 @@ -using QEDprocesses +using Pkg + +# targeting the correct source code +# this asumes the make.jl script is located in QEDprocesses.jl/docs +project_path = Base.Filesystem.joinpath(Base.Filesystem.dirname(Base.source_path()), "..") +Pkg.develop(; path=project_path) +# temporarily necessary because processes used to have a compat that is gone after the `develop` above +Pkg.update() + using Documenter +using QEDprocesses DocMeta.setdocmeta!(QEDprocesses, :DocTestSetup, :(using QEDprocesses); recursive=true) diff --git a/src/cross_section/total_cross_section.jl b/src/cross_section/total_cross_section.jl index 7d838b0..b8059f4 100644 --- a/src/cross_section/total_cross_section.jl +++ b/src/cross_section/total_cross_section.jl @@ -6,7 +6,7 @@ """ total_cross_section(in_psp::InPhaseSpacePoint) -Return the total cross section for a given [`InPhaseSpacePoint`](@ref). +Return the total cross section for a given `QEDcore.InPhaseSpacePoint`. """ function total_cross_section(in_psp::InPhaseSpacePoint) I = 1 / (4 * QEDbase._incident_flux(in_psp)) diff --git a/src/cross_section/total_probability.jl b/src/cross_section/total_probability.jl index 96cf9ba..5140d6f 100644 --- a/src/cross_section/total_probability.jl +++ b/src/cross_section/total_probability.jl @@ -5,7 +5,7 @@ """ total_probability(in_psp::InPhaseSpacePoint) -Return the total probability of a given [`InPhaseSpacePoint`](@ref). +Return the total probability of a given `QEDcore.InPhaseSpacePoint`. """ function total_probability(in_psp::InPhaseSpacePoint) return QEDbase._total_probability(in_psp)