diff --git a/Project.toml b/Project.toml index b49002d..1c94728 100644 --- a/Project.toml +++ b/Project.toml @@ -6,4 +6,5 @@ version = "0.1.0" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93" +QEDcore = "35dc0263-cb5f-4c33-a114-1d7f54ab753e" QEDprocesses = "46de9c38-1bb3-4547-a1ec-da24d767fdad" diff --git a/src/FeynmanDiagramGenerator.jl b/src/FeynmanDiagramGenerator.jl index 7596639..42affeb 100644 --- a/src/FeynmanDiagramGenerator.jl +++ b/src/FeynmanDiagramGenerator.jl @@ -1,6 +1,7 @@ module FeynmanDiagramGenerator using QEDbase +using QEDcore using QEDprocesses include("QEDprocesses_patch.jl") diff --git a/src/QEDprocesses_patch.jl b/src/QEDprocesses_patch.jl index ba08085..7163f47 100644 --- a/src/QEDprocesses_patch.jl +++ b/src/QEDprocesses_patch.jl @@ -1,7 +1,7 @@ # patch QEDprocesses # see issue https://github.com/QEDjl-project/QEDprocesses.jl/issues/77 @inline function QEDprocesses.number_particles( - proc_def::AbstractProcessDefinition, dir::DIR, ::PT -) where {DIR<:ParticleDirection,PT<:AbstractParticleType} + proc_def::QEDbase.AbstractProcessDefinition, dir::DIR, ::PT +) where {DIR<:QEDbase.ParticleDirection,PT<:QEDbase.AbstractParticleType} return count(x -> x isa PT, particles(proc_def, dir)) end diff --git a/src/diagrams/diagrams.jl b/src/diagrams/diagrams.jl index 2fc6ee7..211a6fc 100644 --- a/src/diagrams/diagrams.jl +++ b/src/diagrams/diagrams.jl @@ -69,9 +69,50 @@ struct FeynmanDiagram{N,E,U,T,M,FM} <: AbstractTreeLevelFeynmanDiagram where {N, end end -function virtual_particles(diagram::FeynmanDiagram{N,E,U,T,M,FM}) where {N,E,U,T,M,FM} +# representation of a virtual particle and the return type of the virtual_particles function +struct VirtualParticle{PROC<:QEDbase.AbstractProcessDefinition,PT<:QEDbase.AbstractParticleType,I,O} + proc::PROC + species::PT + in_particle_contributions::NTuple{I,Bool} + out_particle_contributions::NTuple{O,Bool} +end - return NTuple{N,Tuple{QEDbase.AbstractParticleType,BitArray,BitArray}}() +import Base: + + +# "addition" of the bool tuples +# realistically, there should never be "colliding" 1s. if there are there is probably an error and this should be asserted +function +(a::Tuple{NTuple{I,Bool},NTuple{O,Bool}}, b::Tuple{NTuple{I,Bool},NTuple{O,Bool}}) where {I,O} + return (ntuple(i -> a[1][i] || b[1][i], I), ntuple(i -> a[2][i] || b[2][i], O)) +end + +function virtual_particles(proc::QEDbase.AbstractProcessDefinition, diagram::FeynmanDiagram{N,E,U,T,M,FM}) where {N,E,U,T,M,FM} + I = number_incoming_particles(proc) + O = number_outgoing_particles(proc) + + # map of all known particles' momentum composition + known_particles = Dict{Int64,Tuple{NTuple{I,Bool},NTuple{O,Bool}}}() + + + # 1: insert all the external ones (won't be returned), they all have exactly one 1 in their composition + # TODO + + + # 2: Loop: + # while there are incomplete fermion lines: + # take a fermion line where there is max=1 particle ∉ known_particles + # walk the fermion line, assign each virtual particle the momentum composition of the previous (or initial fermion if start) "+" the connected particle + # when/if the unknown particle is encountered, start walking from the other side + # when they meet at the unknown particle, assign the unknown particle Photon and left side - right side momentum contribution + # TODO + + # 3: minimalize the contributions, i.e., if the number of contributing particles > half of all particles, invert both vectors + # if it's exactly half of all particles, think of some consistent way to break the symmetry, e.g. swap if the first particle is not contributing + # TODO + + # 4: convert the known_particles Dict to an NTuple and remove the external particles (those with only 1 contributing momentum) + # TODO + + return NTuple{?,VirtualParticle}() end function vertices(diagram::FeynmanDiagram{N,E,U,T,M,FM}) where {N,E,U,T,M,FM} diff --git a/src/diagrams/interface.jl b/src/diagrams/interface.jl index 6e4f5fa..83f2b2a 100644 --- a/src/diagrams/interface.jl +++ b/src/diagrams/interface.jl @@ -30,10 +30,10 @@ function process end Interface function that must be implemented for an instance of [`AbstractTreeLevelFeynmanDiagram`](@ref). Return an `NTuple` with N elements, where N is the number of virtual particles in this diagram. For tree-level Feynman diagrams, \$N = k - 3\$, where \$k\$ is the number of external particles. -The elements of the `NTuple` are themselves `Tuple`s, containing for each virtual particle its `QEDbase.AbstractParticleType` and a `BitArray` (`Vector{Boolean}`), indicating -with a `1` that an incoming external particle's momentum contributes to the virtual particle's momentum, and a `0` otherwise. The second BitArray does the same for the outgoing external +The elements of the `NTuple` are themselves `Tuple`s, containing for each virtual particle its `QEDbase.AbstractParticleType` and an `NTuple{, Bool}` indicating +with a `1` that an incoming external particle's momentum contributes to the virtual particle's momentum, and a `0` otherwise. The second `NTuple{, Bool}` does the same for the outgoing external particles, which contribute their momentum negatively. -From this definition follows that a particles' `BitArray`s are equivalent to the inverse `BitArray`s, i.e., `BitArray`s where every bit is negated. +From this definition follows that a particles' `Boolean NTuple`ss are equivalent to their inverse, i.e., `BitArray`s where every bit is negated. Example: Consider the Compton scattering process \$e^- + \\gamma \\to e^- + \\gamma\$ with the diagram where the incoming electron interacts with the incoming photon first. For this diagram there is exactly one virtual particle, which is an electron. This electron's momentum can be represented as the sum of the two incoming particles' momenta, or diff --git a/src/generic_process_def.jl b/src/generic_process_def.jl index 38bb99d..71628da 100644 --- a/src/generic_process_def.jl +++ b/src/generic_process_def.jl @@ -1,10 +1,8 @@ -using QEDprocesses - _assert_particle_type_tuple(::Tuple{}) = nothing _assert_particle_type_tuple(t::Tuple{AbstractParticleType,Vararg}) = _assert_particle_type_tuple(t[2:end]) _assert_particle_type_tuple(t::Any) = throw(InvalidInputError("invalid input, provide a tuple of AbstractParticleTypes to construct a GenericQEDProcess")) -struct GenericQEDProcess{INT,OUTT} <: AbstractProcessDefinition where {INT<:Tuple,OUTT<:Tuple} +struct GenericQEDProcess{INT,OUTT} <: QEDbase.AbstractProcessDefinition where {INT<:Tuple,OUTT<:Tuple} incoming_particles::INT outgoing_particles::OUTT @@ -12,8 +10,6 @@ struct GenericQEDProcess{INT,OUTT} <: AbstractProcessDefinition where {INT<:Tupl _assert_particle_type_tuple(in_particles) _assert_particle_type_tuple(out_particles) - #feynman_diagrams((), ()) - return new{INT,OUTT}(in_particles, out_particles) end