SPH Functions
We provide some basic functions to compute the gradient, divergence and curl of the kernel with a particle quantity if required.
Please note that these functions are not terribly flexible and/or performance optimized, as we believe that this should be done in a seperate SPHLoop.jl
package. These functions are more meant as a starting point for a more efficient implementation or code that is not used in performance-relevant applications.
Notation
The derivative of a quantity in gradient, divergence and curl can be reduced to the derivative of the kernel combined with the remaining mathematical operation (see e.g. Price (2012)).
To provide some helper functions we split this into two functions:
One to calculate only the kernel derivative and use as a gradient for divergence and curl with the particle quantity.
The other to directly calculate the contribution of particle j
to the gradient, divergence and curl of the SPH quantity for particle i
.
Quantities
You can compute the contribution of particle j
to the SPH quantity A
for particle i
via (see e.g. Price 2012):
$\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} W(\vec{x}_i - \vec{x}_j, h_i)$
To do this you can loop over the function
SPHKernels.kernel_quantity
— Functionkernel_quantity(k::AbstractSPHKernel, r::T1, h_inv::T1,
Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the SPH quantity A
for particle i
. Based on Euclidean distance r
between the particles. Useful if many quantities need to be computed for the same particle pair.
$\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} W(\vec{x}_i - \vec{x}_j, h_i)$
kernel_quantity(k::AbstractSPHKernel, h_inv::T1,
xᵢ::T2, xⱼ::T2, Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the SPH quantity A
for particle i
. Based on positions xᵢ
and xⱼ
.
$\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} W(\vec{x}_i - \vec{x}_j, h_i)$
or its more compact form
SPHKernels.𝒜
— Function𝒜(k::AbstractSPHKernel, h_inv::T1,
xᵢ::Union{T1, T2}, xⱼ::Union{T1, T2},
Aⱼ::Union{T1, T2}, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the SPH quantity A
for particle i
. Based on positions xᵢ
and xⱼ
.
$\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} W(\vec{x}_i - \vec{x}_j, h_i)$
𝒜(k::AbstractSPHKernel, r::T1, h_inv::T1, Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the SPH quantity A
for particle i
. Based on Euclidean distance r
between the particles. Useful if many quantities need to be computed for the same particle pair.
$\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} W(r, h_i)$
Gradient
The gradient of a quantity in SPH can be reduced to the gradient of the kernel (see e.g. Price 2012):
$∇\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$
We provide two functionalities
Kernel
You can compute the gradient of the kernel at position x_j
$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$
by using
SPHKernels.kernel_gradient
— Functionkernel_gradient( k::AbstractSPHKernel, h_inv::Real, xᵢ::T, xⱼ::T ) where T
Computes the gradient of the kernel k
at the position of the neighbour xⱼ
.
$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$
kernel_gradient( k::AbstractSPHKernel, r::T1, h_inv::T1, Δx::T2) where {T1,T2}
Computes the gradient of the kernel k
at the distance r
along the distance vector Δx
of the neighbour j
.
$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$
or its more compact form
SPHKernels.∇𝒲
— Function∇𝒲( k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2 ) where {T1<:Real,T2}
Computes the gradient of the kernel k
at the position of the neighbour xⱼ
. Compact notation of kernel_gradient
.
$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$
∇𝒲( k::AbstractSPHKernel, h_inv::Real, xᵢ::Union{Real, Vector{<:Real}}, xⱼ::Union{Real, Vector{<:Real}} )
Computes the gradient of the kernel k
at the position of the neighbour j
. Based on Euclidean distance r
and distance vector Δx
between the particles. Useful if many quantities need to be computed for the same particle pair. Compact notation of kernel_gradient
.
$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$
where xᵢ
and xⱼ
are the positions of particles i
and j
in 1D-3D space.
Quantity
To compute the gradient of a SPH quantity for particle i
$∇\vec{A}_i(x) ≈ - \sum_j m_j \frac{\vec{A}_j}{\rho_j} ∇W(\vec{x}_i - \vec{x}_j, h_i)$
you can loop over
SPHKernels.quantity_gradient
— Functionquantity_gradient(k::AbstractSPHKernel, h_inv::T1,
xᵢ::T2, xⱼ::T2, Aⱼ::T2,
mⱼ::T1, ρⱼ::T1 ) where {T1<:Real, T2}
Compute the contribution of particle j
to the gradient of the SPH quantity A
for particle i
. Based on positions xᵢ
and xⱼ
.
$∇\vec{A}_i(x) ≈ \sum_j \frac{m_j}{\rho_j} \vec{A}_j \: ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$
quantity_gradient(k::AbstractSPHKernel,
r::T1, h_inv::T1,
Δx::T2, Aⱼ::T2,
mⱼ::T1, ρⱼ::T1) where {T1<:Real,T2}
Compute the contribution of particle j
to the gradient of the SPH quantity A
for particle i
. Based on Euclidean distance r
and distance vector Δx
between the particles. Useful if many quantities need to be computed for the same particle pair.
$∇\vec{A}_i(x) ≈ \sum_j \frac{m_j}{\rho_j} \vec{A}_j \: ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$
or its compact form
SPHKernels.∇𝒜
— Function∇𝒜( k::AbstractSPHKernel, h_inv, xᵢ, xⱼ, Aⱼ, mⱼ, ρⱼ)
Compute the contribution of particle j
to the gradient of the SPH quantity A
for particle i
. Compact notation of quantity_gradient
.
$∇\vec{A}_i(x) ≈ \sum_j \frac{m_j}{\rho_j} \vec{A}_j \: ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$
Divergence
The divergence of a quantity in SPH can be calculated as (see e.g. Price 2012):
$∇\cdot\vec{A}_i(x) ≈ \sum_j m_j \frac{\vec{A}_j}{\rho_j} \cdot ∇W(\vec{x}_i - \vec{x}_j, h_i)$
We provide two functionalities
Kernel
You can compute the divergence of the kernel at position x_j
by using
SPHKernels.kernel_div
— Functionkernel_div( k::AbstractSPHKernel, h_inv::T1,
xᵢ::T2, xⱼ::T2, Aⱼ::T2) where {T1,T2}
Compute the kernel divergence ∇⋅𝒲
between particle i
and neighbour j
for some SPH quantity A
.
or its more compact form
SPHKernels.∇dot𝒲
— Function∇dot𝒲( k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2) where {T1,T2}
Compute the kernel divergence ∇⋅𝒲
between particle i
and neighbour j
for some SPH quantity A
. Compact notation of kernel_div
.
where xᵢ
and xⱼ
are the positions of particles i
and j
in 1D-3D space.
Quantity
To compute the gradient of a SPH quantity for particle i
you can loop over
SPHKernels.quantity_divergence
— Functionquantity_divergence(k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the divergence of the SPH quantity A
for particle i
.
$∇\cdot\vec{A}_i(x) ≈ \sum_j \frac{m_j}{\rho_j} \vec{A}_j \cdot ∇W(\vec{x}_i - \vec{x}_j, h_i)$
or its compact form
SPHKernels.∇dot𝒜
— Function∇dot𝒜(k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the divergence of the SPH quantity A
for particle i
. Compact notation of quantity_divergence
.
$∇\cdot\vec{A}_i(x) ≈ \sum_j \frac{m_j}{\rho_j} \vec{A}_j \cdot ∇W(\vec{x}_i - \vec{x}_j, h_i)$
Curl
The curl of a quantity in SPH can be calculated as (see e.g. Price 2012):
$∇×\vec{A}_i(x) ≈ - \sum_j m_j \frac{\vec{A}_j}{\rho_j} \times ∇W(\vec{x}_i - \vec{x}_j, h_i)$
We provide two functionalities
Kernel
You can compute the divergence of the kernel at position x_j
by using
SPHKernels.kernel_curl
— Functionkernel_curl(k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2) where {T1,T2}
Compute the kernel curl ∇x𝒲
between particle i
and neighbour j
for some SPH quantity A
.
or its more compact form
SPHKernels.∇x𝒲
— Function∇x𝒲(k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2) where {T1,T2}
Compute the kernel curl ∇x𝒲
between particle i
and neighbour j
for some SPH quantity A
.
where xᵢ
and xⱼ
are the positions of particles i
and j
in 1D-3D space.
Quantity
To compute the gradient of a SPH quantity for particle i
you can loop over
SPHKernels.quantity_curl
— Functionquantity_curl(k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the curl of the SPH quantity A
for particle i
.
$∇×\vec{A}_i(x) ≈ - \sum_j \frac{m_j}{\rho_j} \vec{A}_j \times ∇W(\vec{x}_i - \vec{x}_j, h_i)$
or its compact form
SPHKernels.∇x𝒜
— Function∇x𝒜(k::AbstractSPHKernel, h_inv::T1, xᵢ::T2, xⱼ::T2, Aⱼ::T2, mⱼ::T1, ρⱼ::T1 ) where {T1,T2}
Compute the contribution of particle j
to the curl of the SPH quantity A
for particle i
.
$∇×\vec{A}_i(x) ≈ - \sum_j \frac{m_j}{\rho_j} \vec{A}_j \times ∇W(\vec{x}_i - \vec{x}_j, h_i)$