Small changes

This commit is contained in:
AntonReinhard 2024-07-09 18:33:37 +02:00
parent e8bc26b0c0
commit f6084065e5
3 changed files with 26 additions and 13 deletions

View File

@ -1,21 +1,29 @@
# patch QEDprocesses # patch QEDprocesses
# see issue https://github.com/QEDjl-project/QEDprocesses.jl/issues/77 # see issue https://github.com/QEDjl-project/QEDprocesses.jl/issues/77
@inline function QEDprocesses.number_particles(
proc_def::QEDbase.AbstractProcessDefinition, dir::DIR, ::PT
) where {DIR<:QEDbase.ParticleDirection,PT<:QEDbase.AbstractParticleType} function _number_particles_helper(
return count(x -> x isa PT, particles(proc_def, dir)) particles::Tuple{}, species::SPECIES, n::Val{N}
) where {SPECIES,N}
return N
end end
function _number_particles_helper(
particles::Tuple{SPECIES,Vararg}, species::SPECIES2, n::Val{N}
) where {SPECIES,SPECIES2,N}
return _number_particles_helper(particles[2:end], species, Val(N))
end
""" function _number_particles_helper(
number_particles(proc_def::AbstractProcessDefinition, dir::ParticleDirection, species::AbstractParticleType) particles::Tuple{SPECIES,Vararg}, species::SPECIES, n::Val{N}
) where {SPECIES,N}
return _number_particles_helper(particles[2:end], species, Val(N + 1))
end
Return the number of particles of the given direction and species in the given process definition. @inline function QEDprocesses.number_particles(
"""
@inline function QEDbase.number_particles(
proc_def::AbstractProcessDefinition, dir::DIR, species::PT proc_def::AbstractProcessDefinition, dir::DIR, species::PT
) where {DIR<:ParticleDirection,PT<:AbstractParticleType} ) where {DIR<:ParticleDirection,PT<:AbstractParticleType}
return count(x -> x isa PT, particles(proc_def, dir)) return _number_particles_helper(particles(proc_def, dir), species, Val(0))
end end
""" """

View File

@ -105,6 +105,9 @@ function normalize(virtual_particle::VirtualParticle{P,S,IN_T,OUT_T}) where {P,S
end end
function _momentum_contribution(proc::AbstractProcessDefinition, dir::ParticleDirection, species::AbstractParticleType, index::Int) function _momentum_contribution(proc::AbstractProcessDefinition, dir::ParticleDirection, species::AbstractParticleType, index::Int)
I = number_incoming_particles(proc)
O = number_outgoing_particles(proc)
# get index of n-th "dir species" particle in proc # get index of n-th "dir species" particle in proc
particles_seen = 0 particles_seen = 0
c = 0 c = 0
@ -114,9 +117,11 @@ function _momentum_contribution(proc::AbstractProcessDefinition, dir::ParticleDi
particles_seen += 1 particles_seen += 1
end end
if particles_seen == index if particles_seen == index
return (ntuple(x -> is_incoming(dir) && x == c, number_incoming_particles(proc)), ntuple(x -> is_outgoing(dir) && x == c, number_outgoing_particles(proc))) return (((is_incoming(dir) && x == c for x in 1:I)...,), ((is_outgoing(dir) && x == c for x in 1:O)...,))
end end
end end
@assert false "tried to get momentum contribution of $dir $species $index but it does not exist in $proc"
end end
function _momentum_contribution(proc::AbstractProcessDefinition, diagram::FeynmanDiagram{N,E,U,T,M,FM}, n::Int) where {N,E,U,T,M,FM} function _momentum_contribution(proc::AbstractProcessDefinition, diagram::FeynmanDiagram{N,E,U,T,M,FM}, n::Int) where {N,E,U,T,M,FM}

View File

@ -25,8 +25,8 @@ struct GenericQEDProcess{INT,OUTT} <: QEDbase.AbstractProcessDefinition where {I
end end
end end
QEDprocesses.incoming_particles(proc::GenericQEDProcess) = proc.incoming_particles QEDprocesses.incoming_particles(proc::GenericQEDProcess{INT,OUTT}) where {INT,OUTT} = proc.incoming_particles
QEDprocesses.outgoing_particles(proc::GenericQEDProcess) = proc.outgoing_particles QEDprocesses.outgoing_particles(proc::GenericQEDProcess{INT,OUTT}) where {INT,OUTT} = proc.outgoing_particles
function isphysical(proc::GenericQEDProcess) function isphysical(proc::GenericQEDProcess)
return (number_particles(proc, Incoming(), Electron()) + number_particles(proc, Outgoing(), Positron()) == return (number_particles(proc, Incoming(), Electron()) + number_particles(proc, Outgoing(), Positron()) ==