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

Add number_particles overloads #90

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion src/QEDbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ include("particles/direction.jl")
include("particles/spin_pol.jl")

include("interfaces/phase_space.jl")
include("interfaces/process.jl")
include("interfaces/particle_stateful.jl")
include("interfaces/process.jl")
include("interfaces/phase_space_point.jl")

include("cross_section/diff_probability.jl")
Expand Down
26 changes: 24 additions & 2 deletions src/interfaces/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,37 @@ Convenience function dispatching to [`incoming_particles`](@ref) or [`outgoing_p
outgoing_particles(proc_def)

"""
number_particles(proc_def::AbstractProcessDefinition, ::ParticleDirection)
number_particles(proc_def::AbstractProcessDefinition, dir::ParticleDirection)

Convenience function dispatching to [`number_incoming_particles`](@ref) or [`number_outgoing_particles`](@ref) depending on the given direction.
Convenience function dispatching to [`number_incoming_particles`](@ref) or [`number_outgoing_particles`](@ref) depending on the given direction, returning the number of incoming or outgoing particles, respectively.
"""
@inline number_particles(proc_def::AbstractProcessDefinition, ::Incoming) =
number_incoming_particles(proc_def)
@inline number_particles(proc_def::AbstractProcessDefinition, ::Outgoing) =
number_outgoing_particles(proc_def)

"""
number_particles(proc_def::AbstractProcessDefinition, dir::ParticleDirection, species::AbstractParticleType)

Return the number of particles of the given direction and species in the given process definition.
"""
@inline function number_particles(
proc_def::AbstractProcessDefinition, dir::DIR, species::PT
) where {DIR<:ParticleDirection,PT<:AbstractParticleType}
return count(x -> x isa PT, particles(proc_def, dir))
end

"""
number_particles(proc_def::AbstractProcessDefinition, particle::AbstractParticleStateful)

Return the number of particles of the given particle's direction and species in the given process definition.
"""
@inline function number_particles(
proc_def::AbstractProcessDefinition, ps::AbstractParticleStateful
)
return number_particles(proc_def, particle_direction(ps), particle_species(ps))
end

#####
# Generation of four-momenta from coordinates
#
Expand Down
Loading