Skip to content

Commit

Permalink
Implement invhankelh1 defined by passing through and tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
jondea committed Apr 11, 2021
1 parent dd8c557 commit 30e0b3d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/InverseHankelFunction.jl
Expand Up @@ -3,7 +3,11 @@ module InverseHankelFunction
import SpecialFunctions: hankelh1, gamma
import LambertW: lambertw

export invhankelh1, PassingThrough
export invhankelh1,
PassingThrough,
isfinite,
iszero,
isnan

export hankelh1n,
HankelH1N
Expand Down Expand Up @@ -34,4 +38,6 @@ include("hankel_asymptotics.jl")

include("invhankel.jl")

include("passingthrough.jl")

end # module
32 changes: 13 additions & 19 deletions src/passingthrough.jl
Expand Up @@ -3,9 +3,14 @@ struct PassingThrough{T}
point::T
end

import Base.isfinite
isfinite(p::PassingThrough) = isfinite(p.point)

import Base.iszero
iszero(p::PassingThrough) = iszero(p.point)

import Base.isnan
isnan(p::PassingThrough) = isnan(p.point)

"""
invhankelh1(ν, h, p::PassingThrough)
Expand All @@ -15,29 +20,18 @@ Find z such that H^{(1)}_\\nu(z) = h and the solution branch passes through p, t
function invhankelh1::Integer, h::Number, p::PassingThrough)

# Handle some special cases
if isinf(p)
throw(DomainError(p.point, "Multiple branches of invhankelh1 pass through $(p.point), find another value that this branch passes through"))
if isnan(p)
throw(DomainError(p.point, "invhankelh1 never passes through $(p.point) because it is not a number"))
end
if iszero(p)
throw(DomainError(p.point, "Multiple branches of invhankelh1 pass through $(p.point), find another value that this branch passes through"))
if !isfinite(p)
throw(DomainError(p.point, "Multiple branches of invhankelh1 pass through non finite ($(p.point)) find another value that this branch passes through"))
end
if isnan(p)
throw(DomainError(p.point, "invhankelh1 never passes through $(p.point)"))
if iszero(p)
throw(DomainError(p.point, "Multiple branches of invhankelh1 pass through zero ($(p.point)) find another value that this branch passes through"))
end

# Starting point for our continuation
z = p.point

SMALL_ARGUMENT_THRESHOLD = 0.5
LARGE_ARGUMENT_THRESHOLD = 2
if abs(z)/sqrt(abs(ν)+1) < SMALL_ARGUMENT_THRESHOLD

elseif abs(z)/sqrt(abs(ν)+1) > LARGE_ARGUMENT_THRESHOLD

end



return 1.0
z₀ = p.point

return invhankelh1n(ν, z₀, h/hankelh1(ν,z₀))
end
42 changes: 41 additions & 1 deletion test/runtests.jl
Expand Up @@ -107,7 +107,7 @@ include("utils.jl")

end

@testset "Normalised Hankel function" begin
@testset "Normalised Hankel function " begin
ν = 1
z₀ = 2.0 - 0.3im
z = 2.0 + 0.1im
Expand Down Expand Up @@ -239,6 +239,46 @@ end

end

@testset "Passing through " begin
for ν in [0, 1, 4]
for p in PassingThrough.([1.0, 2.0, 4.0, 1.0+0.5im, 2.0-0.2im])
h(z) = hankelh1(ν, z)
h⁻¹(z) = invhankelh1(ν, z, p)

# Check that invhankelh1 does indeed pass through this point
@test h⁻¹(h(p.point)) p.point

for hz in [0.9, 0.34, 0.01, 1.4, 1.0-0.5im]
h⁻¹hz = h⁻¹(hz)
@test h(h⁻¹hz) hz
end
end
end

@testset "Domain errors" begin
ν = 4
h = 3.4 + 0.1im

# NaNs
@test_throws DomainError invhankelh1(ν, h, PassingThrough(NaN - 1.0*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(NaN - Inf*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(NaN - NaN*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(10 - NaN*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(NaN))

# Any kind of infinity
@test_throws DomainError invhankelh1(ν, h, PassingThrough(Inf + 0im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(1.0 + Inf*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(Inf + -Inf*im))

# Zeros
@test_throws DomainError invhankelh1(ν, h, PassingThrough( 0.0 + 0.0*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough( 0.0 - 0.0*im))
@test_throws DomainError invhankelh1(ν, h, PassingThrough(-0.0 - 0.0*im))
end

end

@testset "Derivatives of Hankel functions " begin

for ν in [0, 1, 4, 10]
Expand Down

0 comments on commit 30e0b3d

Please sign in to comment.