ConservationLawsParticles.AbstractModel
— Typeabstract type AbstractModel{N}
Abstract type representing a particle model.
ConservationLawsParticles.DiffusiveIntegratedModel
— TypeDiffusiveIntegratedModel((V₁, ...), ((W₁₁, ...), ...), (mob₁, ...), (D₁, ...))
Represents a particles system with:
- external velocities
Vᵢ
, - integrated interactions
Wᵢⱼ
(this is the effect of the speciesj
on the speciesi
), - mobilities
mobᵢ
, - diffusions
Dᵢ
.
See also DiffusiveSampledModel
.
Examples
julia> using ConservationLawsParticles.Examples, RecursiveArrayTools
julia> model = DiffusiveIntegratedModel(
(V, V),
((W_attr, W_rep),
(W_rep, W_attr)),
(mobρ, mobσ),
(Diffusion(1), nothing));
julia> x = ArrayPartition(gaussian_particles(2, 4), collect(range(-3, 4, length=5)))
([-2.000000000000003, -0.30305473018369145, 0.30305473018369145, 2.000000000000003], [-3.0, -1.25, 0.5, 2.25, 4.0])
julia> velocities_diff(x, model, 0.)
([6.032353228461558, -0.7551163082821832, 0.6338610075015758, -6.3250083138486275], [23.261098611816987, 0.9023583690557855, 0.7055593913708742, -8.774526834146023, -55.23308442021724])
ConservationLawsParticles.DiffusiveSampledModel
— TypeDiffusiveSampledModel((V₁, ...), ((W′₁₁, ...), ...), (mob₁, ...), (D₁, ...))
Represents a particles system with:
- external velocities
Vᵢ
, - sampled interactions
W′ᵢⱼ
(this is the effect of the speciesj
on the speciesi
), - mobilities
mobᵢ
, - diffusions
Dᵢ
.
See also DiffusiveIntegratedModel
.
Examples
julia> using ConservationLawsParticles.Examples, RecursiveArrayTools
julia> model = DiffusiveSampledModel(
(V, V),
((Wprime_attr, Wprime_rep),
(Wprime_rep, Wprime_attr)),
(mobρ, mobσ),
(Diffusion(1), nothing));
julia> x = ArrayPartition(gaussian_particles(2, 4), collect(range(-3, 4, length=5)))
([-2.000000000000003, -0.30305473018369145, 0.30305473018369145, 2.000000000000003], [-3.0, -1.25, 0.5, 2.25, 4.0])
julia> velocities_diff(x, model, 0.)
([5.701842050142524, -0.8139064918316994, 0.3386810988127882, -6.637012508114956], [22.405129478914613, 1.1249366684885518, 1.5188519354999799, -7.87111869358889, -54.536397957423915])
ConservationLawsParticles.HyperbolicModel
— TypeHyperbolicModel((V₁, ...), ((I₁₁, ...), ...), (mob₁, ...))
Represents a particles system with:
- external velocities
Vᵢ
, - integrated interactions
Iᵢⱼ
(this is the effect of the speciesj
on the speciesi
), - mobilities
mobᵢ
.
See also ParabolicModel
.
Examples
julia> using ConservationLawsParticles.Examples, RecursiveArrayTools
julia> model = HyperbolicModel(
(V, V),
((SampledInteraction(Wprime_attr), IntegratedInteraction(W_rep)),
(IntegratedInteraction(W_rep), SampledInteraction(Wprime_attr))),
(mobρ, mobσ));
julia> x = ArrayPartition(gaussian_particles(2, 4), collect(range(-3, 4, length=5)))
([-2.000000000000003, -0.30305473018369145, 0.30305473018369145, 2.000000000000003], [-3.0, -1.25, 0.5, 2.25, 4.0])
julia> abstract_velocities(x, model, 0.)
([6.267901451064502, 0.2629261335925302, -0.3841814343731375, -6.560556536451573], [22.921033907881895, 0.8199108735979148, 0.7055593913708742, -8.681409489341364, -54.89301971628215])
ConservationLawsParticles.IntegratedInteraction
— TypeIntegratedInteraction(W)
Represents the integrated interaction induced by the function W
.
The interaction can be evaluated with compute_interaction
.
See also SampledInteraction
.
ConservationLawsParticles.IntegratedModel
— TypeIntegratedModel((V₁, ...), ((W₁₁, ...), ...), (mob₁, ...))
Represents a particles system with:
- external velocities
Vᵢ
, - integrated interactions
Wᵢⱼ
(this is the effect of the speciesj
on the speciesi
), - mobilities
mobᵢ
.
See also SampledModel
.
Examples
julia> using ConservationLawsParticles.Examples, RecursiveArrayTools
julia> model = IntegratedModel(
(V, V),
((W_attr, W_rep),
(W_rep, W_attr)),
(mobρ, mobσ));
julia> x = ArrayPartition(gaussian_particles(2, 4), collect(range(-3, 4, length=5)))
([-2.000000000000003, -0.30305473018369145, 0.30305473018369145, 2.000000000000003], [-3.0, -1.25, 0.5, 2.25, 4.0])
julia> velocities(x, model, 0.)
([6.621647425385332, 0.30545649966452776, -0.42671180044513507, -6.914302510772401], [23.261098611816987, 0.9023583690557855, 0.7055593913708742, -8.774526834146023, -55.23308442021724])
ConservationLawsParticles.ParabolicModel
— TypeParabolicModel((V₁, ...), ((I₁₁, ...), ...), (mob₁, ...), (D₁, ...))
Represents a particles system with:
- external velocities
Vᵢ
, - interactions
Iᵢⱼ
(this is the effect of the speciesj
on the speciesi
), - mobilities
mobᵢ
, - diffusions
Dᵢ
.
See also HyperbolicModel
.
Examples
julia> using ConservationLawsParticles.Examples, RecursiveArrayTools
julia> model = ParabolicModel(
(V, V),
((SampledInteraction(Wprime_attr), IntegratedInteraction(W_rep)),
(IntegratedInteraction(W_rep), SampledInteraction(Wprime_attr))),
(mobρ, mobσ),
(Diffusion(1), nothing));
julia> x = ArrayPartition(gaussian_particles(2, 4), collect(range(-3, 4, length=5)))
([-2.000000000000003, -0.30305473018369145, 0.30305473018369145, 2.000000000000003], [-3.0, -1.25, 0.5, 2.25, 4.0])
julia> abstract_velocities(x, model, 0.)
([5.678607254140728, -0.7976466743541808, 0.6763913735735734, -5.971262339527799], [22.921033907881895, 0.8199108735979148, 0.7055593913708742, -8.681409489341364, -54.89301971628215])
ConservationLawsParticles.SampledInteraction
— TypeSampledInteraction(W′)
Represents the sampled interaction induced by the function W′
.
The interaction can be evaluated with compute_interaction
.
See also IntegratedInteraction
.
ConservationLawsParticles.SampledModel
— TypeSampledModel((V₁, ...), ((W′₁₁, ...), ...), (mob₁, ...))
Represents a particles system with:
- external velocities
Vᵢ
, - sampled interactions
W′ᵢⱼ
(this is the effect of the speciesj
on the speciesi
), - mobilities
mobᵢ
.
See also IntegratedModel
.
Examples
julia> using ConservationLawsParticles.Examples, RecursiveArrayTools
julia> model = SampledModel(
(V, V),
((Wprime_attr, Wprime_rep),
(Wprime_rep, Wprime_attr)),
(mobρ, mobσ));
julia> x = ArrayPartition(gaussian_particles(2, 4), collect(range(-3, 4, length=5)))
([-2.000000000000003, -0.30305473018369145, 0.30305473018369145, 2.000000000000003], [-3.0, -1.25, 0.5, 2.25, 4.0])
julia> velocities(x, model, 0.)
([6.291136247066298, 0.2466663161150116, -0.7218917091339228, -7.22630670503873], [22.405129478914613, 1.1249366684885518, 1.5188519354999799, -7.87111869358889, -54.536397957423915])
ConservationLawsParticles.compute_interaction
— Functioncompute_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
, IntegratedInteraction
, sampled_interaction
, integrated_interaction
.
ConservationLawsParticles.diffusion
— Methoddiffusion(mod::AbstractModel, i::Integer) -> Any
Returns the diffusion associated to the species i
.
ConservationLawsParticles.eachspecies
— Methodeachspecies(mod::AbstractModel) -> Any
Returns an iterator over the indices of the species of the model.
ConservationLawsParticles.external_velocity
— Methodexternal_velocity(mod::AbstractModel, i::Integer) -> Any
Returns the external velocity field associated to the species i
.
ConservationLawsParticles.gaussian_particles
— Methodgaussian_particles(width::Real, number::Integer)
Generates number
particles defining a Gaussian distribution with variance 1/2
truncated to the interval [-width, width]
.
ConservationLawsParticles.integrated_interaction
— Functionintegrated_interaction([t,] x, W, ys[, dens_diff])
Computes $-(W' * \rho)(t, x) = -(W * \rho')(t,x)$, where $\rho$ is the piecewise-constant density associated to the particles ys
.
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
, compute_interaction
.
ConservationLawsParticles.interaction
— Methodinteraction(
mod::AbstractModel,
i::Integer,
j::Integer
) -> Any
Returns the interaction exerted on the species i
by the species j
.
ConservationLawsParticles.make_velocities
— Methodmake_velocities((V₁, ...), ((W′₁₁, ...), ...), (mob₁, ...))
Creates a function velocities(dx, x, p, t)
that computes the velocity of the particles under the influence of the external velocities Vᵢ
, mutual interactions W′ᵢⱼ
and congestions given by mobᵢ
.
See also make_velocity
.
ConservationLawsParticles.make_velocity
— Methodmake_velocity(V::Function, Wprime::Function, mobility::Function)
Creates a function velocity(dx, x, p, t)
that computes the velocity of the particles under the influence of an external velocity V
, a mutual interaction Wprime
and the congestion given by mobility
.
See also make_velocities
.
ConservationLawsParticles.mobility
— Methodmobility(mod::AbstractModel, i::Integer) -> Any
Returns the mobility associated to the species i
.
ConservationLawsParticles.num_species
— Methodnum_species(mod::AbstractModel) -> Any
Returns the number of species of the model.
ConservationLawsParticles.pwc_densities
— Functionpwc_densities(xs::AbstractVector{<:Real}...)
pwc_densities(xs::Tuple{Vararg{AbstractVector{<:Real}}})
Given a list of n
families of particles of lengths l₁, …, lₙ
, returns an n
-tuple whose s
-th entry is an n×2×lₛ
array densₛ
.
This array contains the information about the densities of all the species around the particles of the s
-th species. This array is indexed as [o,side,i]
, where o∈{1, …, n}
is the index of the other species whose density we want to know, side
is either 1
if we want to know the left density or 2
for the right density, and i∈{1, …, lₛ}
is the index of the particle.
In other words, densₛ[o,side,i]
is the density of the o
-th species on the left (side=1
) or right (side=2
) of the i
-th particle of the s
-th species.
See also pwc_densities!
for an inplace version.
Examples
julia> pwc_densities([0,1,2], [0,2,3])
([0.0 0.5; 0.0 0.25;;; 0.5 0.5; 0.25 0.25;;; 0.5 0.0; 0.25 0.5], [0.0 0.5; 0.0 0.25;;; 0.5 0.0; 0.25 0.5;;; 0.0 0.0; 0.5 0.0])
ConservationLawsParticles.pwc_densities!
— Functionpwc_densities!(dens, xs::AbstractVector{<:Real}...)
pwc_densities!(dens, xs::Tuple{Vararg{AbstractVector{<:Real}}})
This is an inplace version of pwc_densities
that writes the result in dens
.
See the documentation of pwc_densities
for an explanation.
ConservationLawsParticles.pwc_density
— Methodpwc_density(x::AbstractVector, y::AbstractVector)
The returned x_dens
is indexed as x_dens[x_or_y, left_or_right, i]
.
ConservationLawsParticles.pwc_density
— Methodpwc_density(x::AbstractVector)
Returns the piecewise constant probability density from the quantile particle positions.
Let the quantile particles be at positions x₀, x₁, …, xₙ
(remember that in Julia they are actually x[1], x[2], ..., x[n], x[n+1]
). The returned array R
is such that R[1] = R[n+2] = 0
and R[i] = 1 / (N * (x[i] - x[i-1]))
for the intermediate indices (this formula holds also for the first and last entry if we assume x[0] = -∞
and x[n+2] = ∞
).
Examples
julia> pwc_density([0, 1, 3])
4-element Vector{Float64}:
0.0
0.5
0.25
0.0
ConservationLawsParticles.sampled_interaction
— Functionsampled_interaction([t,] x, W′, ys)
Computes $-(W' * \dot\rho)(t, x)$, which is the sampled approximation of $-(W' * \rho)(t, x)$, 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
, compute_interaction
.
ConservationLawsParticles.species
— Methodspecies(state, i::Integer) -> Any
Returns the particles associated to the species i
.
ConservationLawsParticles.@time_independent
— MacroAutomatically define a method which takes time as first argument and discards it.
Examples
The definition
@time_independent V(x) = -x^3
is equivalent to
V(x) = -x^3
V(t, x) = V(x)
This also works with more than one argument, for instance
@time_independent V(x₁, x₂) = x₁ * x₂
is equivalent to
V(x₁, x₂) = x₁ * x₂
V(t, x₁, x₂) = V(x₁, x₂)