Skip to content

Commit

Permalink
Document interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoStra committed Aug 12, 2021
1 parent 7fe63e0 commit 99b9f91
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/interactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ where ``\rho`` is the piecewise-constant density associated to the particles `ys
It `t` is omitted, then `W′(x)` is assumed independent of time.
See also [`integrated_interaction`](@ref).
See also [`integrated_interaction`](@ref), [`compute_interaction`](@ref).
"""
function sampled_interaction end

Expand All @@ -31,15 +31,6 @@ function sampled_interaction(t::Real, x::Real; Wprime, particles::AbstractVector
-sum(Wprime(t, x - p) for p in particles) / (length(particles) - 1)
end

# function total_interaction__(Wprime, ys::AbstractVector{<:Real}, x::Real)
# T = promote_type(eltype(ys), typeof(x))
# w::T = 0
# for y in ys
# w += Wprime(y - x)
# end
# w / (length(ys) - 1)
# end


@doc raw"""
integrated_interaction([t,] x, W, ys[, dens_diff])
Expand All @@ -54,7 +45,7 @@ It `t` is omitted, then `W(x)` is assumed independent of time.
To ensure the correctness of the computation, `dens_diff` must coincide with `diff(pwc_density(ys))`.
It can be pre-computed and passed explicitly to allow reuse (as an optimization).
See also [`sampled_interaction`](@ref).
See also [`sampled_interaction`](@ref), [`compute_interaction`](@ref).
"""
function integrated_interaction end

Expand All @@ -67,14 +58,44 @@ function integrated_interaction(t::Real, x::Real, W, ys::AbstractVector{<:Real},
end


"""
SampledInteraction(W′)
Represents the sampled interaction induced by the function `W′`.
The interaction can be evaluated with [`compute_interaction`](@ref).
See also [`IntegratedInteraction`](@ref).
"""
struct SampledInteraction{TWprime}
Wprime::TWprime
end

"""
IntegratedInteraction(W)
Represents the integrated interaction induced by the function `W`.
The interaction can be evaluated with [`compute_interaction`](@ref).
See also [`SampledInteraction`](@ref).
"""
struct IntegratedInteraction{TW}
W::TW
end

"""
compute_interaction(t, x, interaction, ys[, dens_diff])
Evaluates the interaction generated by the particles `ys` at `(t, x)`.
`interaction` can be a `SampledInteraction`, an `IntegratedInteraction`, or any other
form of interaction that provides this interface.
See also [`SampledInteraction`](@ref), [`IntegratedInteraction`](@ref),
[`sampled_interaction`](@ref), [`integrated_interaction`](@ref).
"""
function compute_interaction end

function compute_interaction(t::Real, x::Real, int::SampledInteraction, ys::AbstractVector{<:Real}, dens_diff::AbstractVector{<:Real}=Float16[])
sampled_interaction(t, x, int.Wprime, ys)
Expand Down

0 comments on commit 99b9f91

Please sign in to comment.