LudwigBoess / SPHKernels.jl

Julia implementation of some common SPH kernels
MIT License
10 stars 0 forks source link

Seems StaticArrays and tuples not supported #31

Closed PharmCat closed 1 week ago

PharmCat commented 8 months ago

Hello!

I used concept-code:

   using SPHKernels, StaticArrays
    sphk     = WendlandC6(Float64, 3)
    r     = 0.5
    h     = 1.0
    h_inv = 1.0 / h
    u     = r * h_inv
    Δx    = SVector((0.1,0.1,0.1))
    ∇𝒲(sphk, r, h⁻¹, Δx)

Seems StaticArrays and tuples not supported.

ERROR: MethodError: no method matching ∇𝒲 (::WendlandC6{Float64}, ::Float64, ::Float64, ::SVector{3, Float64})
Closest candidates are:
  ∇𝒲(::AbstractSPHKernel, ::Real, ::Real,  ::Union{Real, Vector{<:Real}}) at .julia\packages\SPHKernels\SDriS\src\sph_functions\gradient.jl:87
  ∇𝒲(::AbstractSPHKernel, ::Real, ::Union{Real, Vector{<:Real}},  ::Union{Real, Vector{<:Real}}) at .julia\packages\SPHKernels\SDriS\src\sph_functions\gradient.jl:74
Stacktrace:

So maybe make method definition:

∇𝒲(::AbstractSPHKernel, ::Real, ::Real,  ::Union{Real, AbstrcatVector{<:Real}, Tuple{Real, Real}, Tuple{Real, Real, Real} })

So I see 3 functions:

function kernel_gradient( k::AbstractSPHKernel, h_inv::Real,  xᵢ::Vector{<:Real},  xⱼ::Vector{<:Real} ) # f1
function kernel_gradient( k::AbstractSPHKernel, r::Real, h_inv::Real,  Δx::Union{Real, Vector{<:Real}}) # f2
function kernel_gradient( k::AbstractSPHKernel, h_inv::Real,  xᵢ::Real,  xⱼ::Real ) # f3

Seems f2 will never run for kernel_gradient( k::AbstractSPHKernel, r::Real, h_inv::Real, Δx::Real) because it should call f3

Seems function f1 and function f2 have same code inside.

May be better to make:

function kernel_gradient( k::AbstractSPHKernel, h_inv,  xᵢ,  xⱼ ) # f1
function kernel_gradient( k::AbstractSPHKernel, h_inv,  r, Δx::Union{AbstractVector{<:Real}, NTuple{N, Real}}) where N # f2

then just

∇𝒲 = kernel_gradient
LudwigBoess commented 1 week ago

Hey, I'm really sorry I just saw these issues! Can you please check the branch rc2.3.0 if this solution works for you?