Maybe the functions can dispatch on both the particle type and the trap type? Is that expressive enough?
If you use something like:
mutable struct System{P, Tup}
ps::Vector{P}
forces::Tup
end
You can allow the user to provide a tuple with many forces, which will allow specialized methods, because the tuple is annotated in every element.
2 Likes
Thanks, this does everything I need and reduces the performance difference down to ~20ns.