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_quantityFunction
kernel_quantity( k::AbstractSPHKernel, h_inv::Real, 
                 xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
                 Aⱼ::Vector{<:Real},
                 mⱼ::Real,             ρⱼ::Real )

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)$

source
kernel_quantity( k::AbstractSPHKernel, h_inv::Real, 
                 xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
                 Aⱼ::Vector{<:Real},
                 mⱼ::Real,             ρⱼ::Real )

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)$

source

or its more compact form

SPHKernels.𝒜Function
𝒜( k::AbstractSPHKernel, h_inv::Real, 
    xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
    Aⱼ::Vector{<:Real},
    mⱼ::Real,             ρⱼ::Real )

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)$

source
𝒜( k::AbstractSPHKernel, 
    r::Real,  h_inv::Real, 
    Aⱼ::Union{Real, Vector{<:Real}},
    mⱼ::Real, ρⱼ::Real )

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)$

source

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_gradientFunction
kernel_gradient( 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 xⱼ.

$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$

source
kernel_gradient( k::AbstractSPHKernel, r::Real, h_inv::Real, 
                 Δx::Vector{<:Real})

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}$

source
kernel_gradient( 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 xⱼ.

$∇W(x_{ij}, h_i) = \frac{dW}{dx}\vert_{x_j} \frac{Δx_{ij}}{||x_{ij}||} \frac{1}{h_i}$

source

or its more compact form

SPHKernels.∇𝒲Function
∇𝒲( 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 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}$

source
∇𝒲( 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}$

source

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_gradientFunction
quantity_gradient( k::AbstractSPHKernel, h_inv::Real, 
                   xᵢ::Union{Real, Vector{<:Real}},   
                   xⱼ::Union{Real, Vector{<:Real}},
                   Aⱼ::Union{Real, Vector{<:Real}},
                   mⱼ::Real,             ρⱼ::Real )

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 m_j \frac{\vec{A}_j}{\rho_j} ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$

source
quantity_gradient( k::AbstractSPHKernel, 
                   r::Real,  h_inv::Real, 
                   Δx::Union{Real, Vector{<:Real}},
                   Aⱼ::Union{Real, Vector{<:Real}},
                   mⱼ::Real, ρⱼ::Real )

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 m_j \frac{\vec{A}_j}{\rho_j} ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$

source

or its compact form

SPHKernels.∇𝒜Function
∇𝒜( k::AbstractSPHKernel, h_inv::Real, 
    xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
    Aⱼ::Vector{<:Real},   
    mⱼ::Real=1,           ρⱼ::Real=1 )

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 m_j \frac{\vec{A}_j}{\rho_j} ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$

source
∇𝒜( k::AbstractSPHKernel, 
     r::Real,  h_inv::Real, 
     Δx::Union{Real, Vector{<:Real}},
     Aⱼ::Union{Real, Vector{<:Real}},
     mⱼ::Real, ρⱼ::Real )

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 m_j \frac{\vec{A}_j}{\rho_j} ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$

source
∇𝒜( k::AbstractSPHKernel, 
     r::Real,  h_inv::Real, 
     Δx::Union{Real, Vector{<:Real}},
     Aⱼ::Union{Real, Vector{<:Real}},
     mⱼ::Real, ρⱼ::Real )

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 m_j \frac{\vec{A}_j}{\rho_j} ∇W(||\vec{x}_i - \vec{x}_j||, h_i)$

source

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_divFunction
kernel_div( k::AbstractSPHKernel,       h_inv::Real, 
            xᵢ::Vector{<:Real}, xⱼ::Vector{<:Real},
            Aᵢ::Vector{<:Real}, Aⱼ::Vector{<:Real} )

Compute the kernel divergence ∇⋅𝒲 between particle i and neighbour j for some SPH quantity A.

source

or its more compact form

SPHKernels.∇̇dot𝒲Function
∇̇dot𝒲( k::AbstractSPHKernel, h_inv::Real, 
        xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
        Aᵢ::Vector{<:Real},   Aⱼ::Vector{<:Real})

Compute the kernel divergence ∇⋅𝒲 between particle i and neighbour j for some SPH quantity A. Compact notation of kernel_div.

source

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_divergenceFunction
quantity_divergence( k::AbstractSPHKernel, h_inv::Real, 
                      xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
                      Aᵢ::Vector{<:Real},   Aⱼ::Vector{<:Real},
                      mⱼ::Real,             ρⱼ::Real )

Compute the contribution of particle j to the divergence of the SPH quantity A for particle i.

$∇\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)$

source

or its compact form

SPHKernels.∇dot𝒜Function
∇dotA( k::AbstractSPHKernel, h_inv::Real, 
       xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
       Aᵢ::Vector{<:Real},   Aⱼ::Vector{<:Real},
       mⱼ::Real,             ρⱼ::Real )

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 m_j \frac{\vec{A}_j}{\rho_j} \cdot ∇W(\vec{x}_i - \vec{x}_j, h_i)$

source

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_curlFunction
kernel_curl( k::AbstractSPHKernel,       h_inv::Real, 
             xᵢ::Vector{<:Real}, xⱼ::Vector{<:Real},
             Aᵢ::Vector{<:Real}, Aⱼ::Vector{<:Real} )

Compute the kernel curl ∇x𝒲 between particle i and neighbour j for some SPH quantity A.

source

or its more compact form

SPHKernels.∇x𝒲Function
∇x𝒲( k::AbstractSPHKernel, h_inv::Real, 
      xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
      Aⱼ::Vector{<:Real})

Compute the kernel curl ∇x𝒲 between particle i and neighbour j for some SPH quantity A.

source

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_curlFunction
quantity_curl( k::AbstractSPHKernel, h_inv::Real, 
      xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
      Aⱼ::Vector{<:Real},
      mⱼ::Real,             ρⱼ::Real )

Compute the contribution of particle j to the curl of the SPH quantity A for particle i.

$∇×\vec{A}_i(x) ≈ - \sum_j m_j \frac{\vec{A}_j}{\rho_j} \times ∇W(\vec{x}_i - \vec{x}_j, h_i)$

source

or its compact form

SPHKernels.∇x𝒜Function
∇x𝒜( k::AbstractSPHKernel, h_inv::Real, 
      xᵢ::Vector{<:Real},   xⱼ::Vector{<:Real},
      Aᵢ::Vector{<:Real},   Aⱼ::Vector{<:Real},
      mⱼ::Real,             ρⱼ::Real )

Compute the contribution of particle j to the curl of the SPH quantity A for particle i.

$∇×\vec{A}_i(x) ≈ - \sum_j m_j \frac{}{\rho_j} \times ∇W(\vec{x}_i - \vec{x}_j, h_i)$

source