Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of differential cross section functionality #38

Merged
merged 29 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
44b6bf2
started refactoring of differential cross sections
Nov 14, 2023
148f33c
fixed typos in function signatures and docstrings
Nov 16, 2023
a8e7d7d
updated differential cross section and tests
Nov 21, 2023
b70e755
formatting
Nov 21, 2023
5ae7618
rearranged probabilities in separate file; added unit tests for proba…
Nov 21, 2023
49347f8
formatting
Nov 21, 2023
27de535
started adding unittests for safe evaluation
Nov 23, 2023
6169896
cleanup
Nov 23, 2023
31d861c
rearranged and finalized tests for cross sections and probabilities
Nov 23, 2023
be17cb5
cleanup Project.toml
Nov 23, 2023
a844685
formatting
Nov 23, 2023
5e28aa1
fixed typo
Nov 30, 2023
ac7d449
end of day
Nov 30, 2023
a82a899
added missing doc-strings and renames probability -> differentia_prob…
Jan 28, 2024
c05e59d
formatting
Jan 31, 2024
1cde157
added interface total cross section and probability, adjusted tests a…
Feb 1, 2024
4d4ab9f
formatting
Feb 1, 2024
924784a
added docstrings to total probability and cross section; updated QEDb…
Feb 1, 2024
6f13343
formatting
Feb 14, 2024
c18a394
fixed typos
Feb 22, 2024
00ad5be
added comments to diff CS and prob
Feb 22, 2024
1a52ad2
extended the tests for cross section and probabilities
Feb 26, 2024
4dfb3d3
rewrite of the test implementation
Mar 1, 2024
cd67864
remove dependence on DocStringExtensions
Mar 1, 2024
270b5b9
refined totCS docstring
Mar 1, 2024
9e83493
Apply suggestions from code review
szabo137 Mar 1, 2024
cacae8c
renamed in_ps to in_phase_space
Mar 1, 2024
aa3df61
fixed docstring in rand momenta test implementation, fixed bug in all…
Mar 6, 2024
b6bcd69
added missing tests, fixed some typos
Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ authors = ["Uwe Hernandez Acosta <[email protected]>", "Simeon Ehrig", "Klaus
version = "0.1.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93"

[compat]
DocStringExtensions = "0.9"
QEDbase = "0.1"
julia = "1.6"
18 changes: 16 additions & 2 deletions src/QEDprocesses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ export AbstractModelDefinition, fundamental_interaction_type
export AbstractProcessDefinition, incoming_particles, outgoing_particles
export in_phasespace_dimension, out_phasespace_dimension
export number_incoming_particles, number_outgoing_particles
export differential_cross_section, total_cross_section

# 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
Expand All @@ -16,12 +23,19 @@ export AbstractProcessSetup, scattering_process, physical_model
# propagator
export propagator

using DocStringExtensions
# phase space
export AbstractCoordinateSystem, SphericalCoordinateSystem
export AbstractFrameOfReference, CenterOfMomentumFrame, ElectronRestFrame
export AbstractPhasespaceDefinition, PhasespaceDefinition

using QEDbase

include("utils.jl")
include("interfaces/model_interface.jl")
include("interfaces/process_interface.jl")
include("interfaces/setup_interface.jl")
include("propagators.jl")
include("phase_spaces.jl")
include("probabilities.jl")
include("cross_sections.jl")
end
304 changes: 304 additions & 0 deletions src/cross_sections.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
########################
# differential cross sections and probabilities.
#
# This file contains default implementations for differential and total cross
# sections based on the scattering process interface
########################

############
#
# differential cross sections
#
############

# differential cross sections without energy momentum conservation check
# single in phase space point/ single out phase space point
function _unsafe_differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVector{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVector{T},
) where {T<:QEDbase.AbstractFourMomentum}
I = 1 / (4 * _incident_flux(proc, model, in_phase_space))

return I * _unsafe_differential_probability(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
out_phase_space,
)
end

# differential cross sections without energy momentum conservation check
# single in phase space point/ several out phase space points
function _unsafe_differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVector{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractMatrix{T},
) where {T<:QEDbase.AbstractFourMomentum}
res = Vector{eltype(T)}(undef, size(out_phase_space, 2))
for i in 1:size(out_phase_space, 2)
res[i] = _unsafe_differential_cross_section(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
view(out_phase_space, :, i),
)
end
return res
end

# differential cross sections without energy momentum conservation check
# several in phase space points/ one or several out phase space points
function _unsafe_differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractMatrix{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}
res = Matrix{eltype(T)}(undef, size(in_phase_space, 2), size(out_phase_space, 2))
for i in 1:size(in_phase_space, 2)
res[i, :] .= _unsafe_differential_cross_section(
proc,
model,
in_phase_space_def,
view(in_phase_space, :, i),
out_phase_space_def,
out_phase_space,
)
end
return res
end

"""

function unsafe_differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVecOrMat{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}

Return the differential cross section without checking if the given phase space(s) are physical.
"""
function unsafe_differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVecOrMat{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}
size(in_phase_space, 1) == number_incoming_particles(proc) || throw(
DimensionMismatch(
"The number of incoming particles <$(number_incoming_particles(proc))> is inconsistent with input size <$(size(in_phase_space,1))>",
),
)

size(out_phase_space, 1) == number_outgoing_particles(proc) || throw(
DimensionMismatch(
"The number of outgoing particles <$(number_outgoing_particles(proc))> is inconsistent with input size <$(size(out_phase_space,1))>",
),
)

return _unsafe_differential_cross_section(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
out_phase_space,
)
end

# differential cross sections with energy momentum conservation check
# single in phase space point/ single out phase space point
function _differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVector{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVector{T},
) where {T<:QEDbase.AbstractFourMomentum}
if !_is_in_phasespace(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
out_phase_space,
)
return zero(eltype(T))
end

return _unsafe_differential_cross_section(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
out_phase_space,
)
end

# differential cross sections with energy momentum conservation check
# single in phase space point/ several out phase space points
function _differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVector{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractMatrix{T},
) where {T<:QEDbase.AbstractFourMomentum}
res = Vector{eltype(T)}(undef, size(out_phase_space, 2))
for i in 1:size(out_phase_space, 2)
res[i] = _differential_cross_section(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
view(out_phase_space, :, i),
)
end
return res
end

# differential cross sections with energy momentum conservation check
# several in phase space points/ one or several out phase space points
function _differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractMatrix{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}
res = Matrix{eltype(T)}(undef, size(in_phase_space, 2), size(out_phase_space, 2))
for i in 1:size(in_phase_space, 2)
res[i, :] .= _differential_cross_section(
proc,
model,
in_phase_space_def,
view(in_phase_space, :, i),
out_phase_space_def,
out_phase_space,
)
end
return res
end

"""
differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVecOrMat{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}

If the given phase spaces are physical, return differential cross section. Zero otherwise

"""
function differential_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVecOrMat{T},
out_phase_space_def::AbstractPhasespaceDefinition,
out_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}
size(in_phase_space, 1) == number_incoming_particles(proc) || throw(
DimensionMismatch(
"The number of incoming particles <$(number_incoming_particles(proc))> is inconsistent with input size <$(size(in_phase_space,1))>",
),
)

size(out_phase_space, 1) == number_outgoing_particles(proc) || throw(
DimensionMismatch(
"The number of outgoing particles <$(number_outgoing_particles(proc))> is inconsistent with input size <$(size(out_phase_space,1))>",
),
)

return _differential_cross_section(
proc,
model,
in_phase_space_def,
in_phase_space,
out_phase_space_def,
out_phase_space,
)
end

############
# Total cross sections
############

# total cross section on single phase space point
function _total_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVector{T},
) where {T<:QEDbase.AbstractFourMomentum}
I = 1 / (4 * _incident_flux(proc, model, in_phase_space))

return I * _total_probability(proc, model, in_phase_space_def, in_phase_space)
end

# total cross section on several phase space points
function _total_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractMatrix{T},
) where {T<:QEDbase.AbstractFourMomentum}
res = Vector{eltype(T)}(undef, size(in_phase_space, 2))
for i in 1:size(in_phase_space, 2)
res[i] = _total_cross_section(
proc, model, in_phase_space_def, view(in_phase_space, :, i)
)
end
return res
end

"""
total_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}

Return the total cross section for a given combination of scattering process and compute model.
"""
function total_cross_section(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
in_phase_space_def::AbstractPhasespaceDefinition,
in_phase_space::AbstractVecOrMat{T},
) where {T<:QEDbase.AbstractFourMomentum}
size(in_phase_space, 1) == number_incoming_particles(proc) || throw(
DimensionMismatch(
"The number of incoming particles <$(number_incoming_particles(proc))> is inconsistent with input size <$(size(in_phase_space,1))>",
),
)

return _total_cross_section(proc, model, in_phase_space_def, in_phase_space)
end
Loading
Loading