-
Notifications
You must be signed in to change notification settings - Fork 3
Refactoring of differential cross section functionality #38
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
Merged
Merged
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
148f33c
fixed typos in function signatures and docstrings
a8e7d7d
updated differential cross section and tests
b70e755
formatting
5ae7618
rearranged probabilities in separate file; added unit tests for proba…
49347f8
formatting
27de535
started adding unittests for safe evaluation
6169896
cleanup
31d861c
rearranged and finalized tests for cross sections and probabilities
be17cb5
cleanup Project.toml
a844685
formatting
5e28aa1
fixed typo
ac7d449
end of day
a82a899
added missing doc-strings and renames probability -> differentia_prob…
c05e59d
formatting
1cde157
added interface total cross section and probability, adjusted tests a…
4d4ab9f
formatting
924784a
added docstrings to total probability and cross section; updated QEDb…
6f13343
formatting
c18a394
fixed typos
00ad5be
added comments to diff CS and prob
1a52ad2
extended the tests for cross section and probabilities
4dfb3d3
rewrite of the test implementation
cd67864
remove dependence on DocStringExtensions
270b5b9
refined totCS docstring
9e83493
Apply suggestions from code review
szabo137 cacae8c
renamed in_ps to in_phase_space
aa3df61
fixed docstring in rand momenta test implementation, fixed bug in all…
b6bcd69
added missing tests, fixed some typos
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
tjungni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.