Documentation | Build Status | Licence | Citation |
---|---|---|---|
This package supplies a number of kernels frequently used in Smoothed-Particle Hydrodynamics (SPH), as well as functions to evaluate their values and derivatives in 2D and 3D.
The implementation closely follows the one in Gadget2, see Springel (2005) for details.
These kernels include the B-splines (Cubic
and Quintic
) suggested in Monaghan & Lattanzio (1985), the Wendland functions (WendlandC2
, WendlandC4
and WendlandC6
from Wendland (2009)) as suggested in Dehnen & Aly (2012) and WendlandC8
as suggested by Kummer et. al. (2019).
⚠️ The version numbering of this package is unfortunately not really reflective of the state. I made an error on the original setup of the repository, so I had to start out with version 1.0. View this more as v0.2, instead of v2.0!: Please sanity-check everything before you use it in production!
To evaluate a 3D kernel you need to use the function
kernel_value(k::AbstractSPHKernel, u::Real, h_inv::Real)
where AbstractSPHKernel
is the supertype for an implemented SPH kernel, u = \frac{x}{h}
is the distance to the kernel origin in measures of the smoothing length and h_inv
is the inverse of the smoothing length.
If you want your code to look a little more fancy you can also use the alternative functions 𝒲
:
𝒲( kernel::AbstractSPHKernel, u::Real, h_inv::Real) = kernel_value(kernel, u, h_inv)
As an example:
using SPHKernels
# Wendland C6 kernel with double precision in 3D
k = WendlandC6(Float64, 3)
# distance between the particle and the origin of the kernel
r = 0.5
h = 1.0
h_inv = 1.0 / h
u = r * h_inv
# kernel value at position r
val = 𝒲(k, u, h_inv)
Similar to Evaluating Kernels you can evluate a kernel derivative with
kernel_deriv(k::AbstractSPHKernel, u::Real, h_inv::Real)
or in the fancy way:
d𝒲(kernel::AbstractSPHKernel, u::Real, h_inv::Real) = kernel_deriv(kernel, u, h_inv)
You can correct for the kernel bias of the Wendland kernels as described in Dehnen & Aly (2012), Eq. 18 + 19 with the functions:
bias_correction(kernel::AbstractSPHKernel, density::Real, m::Real, h_inv::Real, n_neighbours::Integer)
or again in the fancy way
δρ(kernel::AbstractSPHKernel, density::Real, m::Real, h_inv::Real, n_neighbours::Integer) = bias_correction(kernel, density, m, h_inv, n_neighbours)
This will return a new value for the density:
using SPHKernels
density = 1.0
kernel = WendlandC6(3)
# correct density
density = bias_correction(kernel, density, 1.0, 0.5, 295)