Skip to content

Commit

Permalink
add viscosity kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Apr 30, 2024
1 parent fb40c20 commit 98b40ad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ end

@inline W(k::KernelPoly6,r2) = k.coeff * (k.- r2)^3
@inline ∇W(k::KernelPoly6,rij,r = norm(rij)) = k.coeff_grad * (k.- r^2)^2 * rij



function KernelViscosity(N,h::T) where T
coeff = (N-1)*N*(N+2)*(N+3) / (6*h^N * surface_hypersphere(N))
coeff_grad = 1.0
KernelViscosity{N,T}(h,coeff,coeff_grad)
end

@inline function W(k::KernelViscosity,r2)
r = sqrt(r2)
rh = r/k.h

return k.coeff * (-0.5 * rh^3 + rh^2 + 0.5/rh - 1)
end

@inline function ∇W(k::KernelViscosity,rij,r = norm(rij))
rh = r/k.h

return k.coeff * (-1.5 * rh^2 + 2*rh - 0.5/(rh^2)) / k.h * rij/r
end


@inline function ∇²W(k::KernelViscosity,r2)
r = sqrt(r2)
rh = r/k.h
#TODO
return 0
end
7 changes: 7 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ struct KernelPoly6{N,T} <: Kernel{N} where T <: Number
coeff_grad::T
end


struct KernelViscosity{N,T} <: Kernel{N} where T <: Number
h::T
coeff::T
coeff_grad::T
end

struct Particle{N,T}
x::SVector{N,T} # position
v::SVector{N,T} # velocity
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Test
using LinearAlgebra
import SmoothedParticleHydrodynamics: forces!, update!, surface_hypersphere, KernelSpiky,KernelPoly6, Kernel, W, ∇W, Particle
import SmoothedParticleHydrodynamics: forces!, update!, surface_hypersphere, KernelSpiky,KernelPoly6, Kernel, W, ∇W, Particle, KernelViscosity


function numerical_integration(k::Kernel{N},dr) where N
integral = 0.
for r = 0:dr:k.h
for r = dr/2:dr:k.h
r2 = r^2
integral = integral + W(k,r2)*surface_hypersphere(N)*r^(N-1)*dr
end
Expand All @@ -31,7 +31,7 @@ end

rij = [2.,3.,4.]

for kernel in (KernelSpiky,KernelPoly6)
for kernel in (KernelSpiky,KernelPoly6,KernelViscosity)
for N = 2:4
local k
k = kernel(N,h)
Expand Down

0 comments on commit 98b40ad

Please sign in to comment.