diff --git a/src/models/physics_models/abc/compute.jl b/src/models/physics_models/abc/compute.jl index 9641e8a..ad1edf2 100644 --- a/src/models/physics_models/abc/compute.jl +++ b/src/models/physics_models/abc/compute.jl @@ -1,6 +1,17 @@ using AccurateArithmetic using StaticArrays +function input_expr(instance::ABCProcessDescription, name::String, psp_symbol::Symbol) + (type, index) = type_index_from_name(ABCModel(), name) + + return Meta.parse( + "ABCParticleValue( + $type(momentum($psp_symbol, $(construction_string(particle_direction(type))), $(construction_string(particle_species(type))), Val($index))), + 0.0im, + )", + ) +end + """ compute(::ComputeTaskABC_P, data::ABCParticleValue) @@ -8,7 +19,7 @@ Return the particle and value as is. 0 FLOP. """ -function compute(::ComputeTaskABC_P, data::ABCParticleValue{P})::ABCParticleValue{P} where {P <: ABCParticle} +function compute(::ComputeTaskABC_P, data::ABCParticleValue{P})::ABCParticleValue{P} where {P} return data end @@ -19,7 +30,7 @@ Compute an outer edge. Return the particle value with the same particle and the 1 FLOP. """ -function compute(::ComputeTaskABC_U, data::ABCParticleValue{P})::ABCParticleValue{P} where {P <: ABCParticle} +function compute(::ComputeTaskABC_U, data::ABCParticleValue{P})::ABCParticleValue{P} where {P} return ABCParticleValue{P}(data.p, data.v * ABC_outer_edge(data.p)) end @@ -34,7 +45,7 @@ function compute( ::ComputeTaskABC_V, data1::ABCParticleValue{P1}, data2::ABCParticleValue{P2}, -)::ABCParticleValue where {P1 <: ABCParticle, P2 <: ABCParticle} +)::ABCParticleValue where {P1, P2} p3 = ABC_conserve_momentum(data1.p, data2.p) dataOut = ABCParticleValue{typeof(p3)}(p3, data1.v * ABC_vertex() * data2.v) return dataOut @@ -49,11 +60,7 @@ For valid inputs, both input particles should have the same momenta at this poin 12 FLOP. """ -function compute( - ::ComputeTaskABC_S2, - data1::ParticleValue{P}, - data2::ParticleValue{P}, -)::Float64 where {P <: ABCParticle} +function compute(::ComputeTaskABC_S2, data1::ParticleValue{P}, data2::ParticleValue{P})::Float64 where {P} #= @assert isapprox(abs(data1.p.momentum.E), abs(data2.p.momentum.E), rtol = 0.001, atol = sqrt(eps())) "E: $(data1.p.momentum.E) vs. $(data2.p.momentum.E)" @assert isapprox(data1.p.momentum.px, -data2.p.momentum.px, rtol = 0.001, atol = sqrt(eps())) "px: $(data1.p.momentum.px) vs. $(data2.p.momentum.px)" diff --git a/src/models/physics_models/abc/particle.jl b/src/models/physics_models/abc/particle.jl index d91bc0b..196fdff 100644 --- a/src/models/physics_models/abc/particle.jl +++ b/src/models/physics_models/abc/particle.jl @@ -14,34 +14,28 @@ struct ABCModel <: AbstractPhysicsModel end Base type for all particles in the [`ABCModel`](@ref). """ -abstract type ABCParticle <: AbstractParticle end +abstract type ABCParticle <: AbstractParticleType end """ ParticleA <: ABCParticle An 'A' particle in the ABC Model. """ -struct ParticleA <: ABCParticle - momentum::SFourMomentum -end +struct ParticleA <: ABCParticle end """ ParticleB <: ABCParticle A 'B' particle in the ABC Model. """ -struct ParticleB <: ABCParticle - momentum::SFourMomentum -end +struct ParticleB <: ABCParticle end """ ParticleC <: ABCParticle A 'C' particle in the ABC Model. """ -struct ParticleC <: ABCParticle - momentum::SFourMomentum -end +struct ParticleC <: ABCParticle end """ ABCProcessDescription <: AbstractProcessDescription @@ -72,7 +66,7 @@ struct ABCProcessInput{N1, N2, N3, N4, N5, N6} <: AbstractProcessInput outC::SVector{N6, ParticleC} end -ABCParticleValue{ParticleType <: ABCParticle} = ParticleValue{ParticleType, ComplexF64} +ABCParticleValue{ParticleType} = ParticleValue{ParticleType, ComplexF64} """ mass(t::Type{T}) where {T <: ABCParticle} @@ -109,39 +103,46 @@ end Return a Vector of the possible types of particle in the [`ABCModel`](@ref). """ function types(::ABCModel) - return [ParticleA, ParticleB, ParticleC] + return [ + ParticleStateful{Incoming, ParticleA, SFourMomentum}, + ParticleStateful{Incoming, ParticleB, SFourMomentum}, + ParticleStateful{Incoming, ParticleC, SFourMomentum}, + ParticleStateful{Outgoing, ParticleA, SFourMomentum}, + ParticleStateful{Outgoing, ParticleB, SFourMomentum}, + ParticleStateful{Outgoing, ParticleC, SFourMomentum}, + ] end """ - square(p::ABCParticle) + square(p::AbstractParticleStateful{Dir, ABCParticle}) Return the square of the particle's momentum as a `Float` value. Takes 7 effective FLOP. """ -function square(p::ABCParticle) - return getMass2(p.momentum) +function square(p::AbstractParticleStateful{D, ABCParticle}) where {D} + return getMass2(momentum(p)) end """ - ABC_inner_edge(p::ABCParticle) + ABC_inner_edge(p::AbstractParticleStateful{Dir, ABCParticle}) Return the factor of the inner edge with the given (virtual) particle. Takes 10 effective FLOP. (3 here + 7 in square(p)) """ -function ABC_inner_edge(p::ABCParticle) - return 1.0 / (square(p) - mass(p)^2) +function ABC_inner_edge(p::AbstractParticleStateful{D, ABCParticle}) where {D} + return 1.0 / (square(p) - mass(particle(p))^2) end """ - ABC_outer_edge(p::ABCParticle) + ABC_outer_edge(p::AbstractParticleStateful{Dir, ABCParticle}) Return the factor of the outer edge with the given (real) particle. Takes 0 effective FLOP. """ -function ABC_outer_edge(p::ABCParticle) +function ABC_outer_edge(::AbstractParticleStateful{D, ABCParticle}) where {D} return 1.0 end @@ -179,17 +180,26 @@ model(::ABCProcessDescription) = ABCModel() model(::ABCProcessInput) = ABCModel() function type_index_from_name(::ABCModel, name::String) - if startswith(name, "A") - return (ParticleA, parse(Int, name[2:end])) - elseif startswith(name, "B") - return (ParticleB, parse(Int, name[2:end])) - elseif startswith(name, "C") - return (ParticleC, parse(Int, name[2:end])) + if startswith(name, "Ai") + return (ParticleStateful{Incoming, ParticleA, SFourMomentum}, parse(Int, name[3:end])) + elseif startswith(name, "Ao") + return (ParticleStateful{Outgoing, ParticleA, SFourMomentum}, parse(Int, name[3:end])) + elseif startswith(name, "Bi") + return (ParticleStateful{Incoming, ParticleB, SFourMomentum}, parse(Int, name[3:end])) + elseif startswith(name, "Bo") + return (ParticleStateful{Outgoing, ParticleB, SFourMomentum}, parse(Int, name[3:end])) + elseif startswith(name, "Ci") + return (ParticleStateful{Incoming, ParticleC, SFourMomentum}, parse(Int, name[3:end])) + elseif startswith(name, "Co") + return (ParticleStateful{Outgoing, ParticleC, SFourMomentum}, parse(Int, name[3:end])) else throw("Invalid name for a particle in the ABC model") end end +function String(::Type{PS}) where {DIR, P <: ABCParticle, PS <: AbstractParticleStateful{DIR, P}} + return String(P) +end function String(::Type{ParticleA}) return "A" end diff --git a/test/runtests.jl b/test/runtests.jl index fa37b10..c338e9d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using SafeTestsets - +#= @safetestset "Utility Unit Tests " begin include("unit_tests_utility.jl") end @@ -30,6 +30,7 @@ end @safetestset "Graph Unit Tests " begin include("unit_tests_graph.jl") end +=# @safetestset "Execution Unit Tests " begin include("unit_tests_execution.jl") end diff --git a/test/unit_tests_execution.jl b/test/unit_tests_execution.jl index 4e74641..a2e121c 100644 --- a/test/unit_tests_execution.jl +++ b/test/unit_tests_execution.jl @@ -63,8 +63,14 @@ machine = Machine( ) process_2_2 = ABCProcessDescription( - Dict{Type, Int64}(ParticleA => 1, ParticleB => 1), - Dict{Type, Int64}(ParticleA => 1, ParticleB => 1), + Dict{Type, Int64}( + ParticleStateful{Incoming, ParticleA, SFourMomentum} => 1, + ParticleStateful{Incoming, ParticleB, SFourMomentum} => 1, + ), + Dict{Type, Int64}( + ParticleStateful{Outgoing, ParticleA, SFourMomentum} => 1, + ParticleStateful{Outgoing, ParticleB, SFourMomentum} => 1, + ), ) particles_2_2 = ABCProcessInput( @@ -106,8 +112,14 @@ end end process_2_4 = ABCProcessDescription( - Dict{Type, Int64}(ParticleA => 1, ParticleB => 1), - Dict{Type, Int64}(ParticleA => 1, ParticleB => 3), + Dict{Type, Int64}( + ParticleStateful{Incoming, ParticleA, SFourMomentum} => 1, + ParticleStateful{Incoming, ParticleB, SFourMomentum} => 1, + ), + Dict{Type, Int64}( + ParticleStateful{Outgoing, ParticleA, SFourMomentum} => 1, + ParticleStateful{Outgoing, ParticleB, SFourMomentum} => 3, + ), ) particles_2_4 = gen_process_input(process_2_4) graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->ABBB.txt"), ABCModel())