Skip to content

Commit 27669c8

Browse files
committed
OP tests pass
1 parent 8cf7890 commit 27669c8

File tree

7 files changed

+80
-18
lines changed

7 files changed

+80
-18
lines changed

src/Domains/PiecewiseSegment.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export PiecewiseSegment
2+
13
struct PiecewiseSegment{T} <: Domain{T}
24
points::Vector{T}
35
PiecewiseSegment{T}(d::Vector{T}) where {T} = new{T}(d)

src/Operators/banded/ToeplitzOperator.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,6 @@ function Base.inv(T::ToeplitzOperator)
161161
ToeplitzOperator(ai[2:end],ai[1:1])
162162
end
163163

164-
function Fun(T::ToeplitzOperator)
165-
if length(T.nonnegative)==1
166-
Fun(Taylor(),[T.nonnegative;T.negative])
167-
elseif length(T.negative)==0
168-
Fun(Hardy{false}(),T.nonnegative)
169-
else
170-
Fun(Laurent(Circle()),interlace(T.nonnegative,T.negative))
171-
end
172-
end
173-
174-
175164

176165
####
177166
# Toeplitz/Hankel

src/Spaces/HeavisideSpace.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ convert(::Type{HeavisideSpace},d::AbstractVector) =
1818
HeavisideSpace(PiecewiseSegment(sort(d)))
1919

2020
spacescompatible(a::SplineSpace{λ},b::SplineSpace{λ}) where {λ} = domainscompatible(a,b)
21-
canonicalspace(sp::HeavisideSpace) = PiecewiseSpace(map(Chebyshev,components(domain(sp))))
2221

2322

24-
function evaluate(f::Fun{HeavisideSpace{T,R}},x::Real) where {T<:Real,R}
25-
p = domain(f).points
26-
c = f.coefficients
23+
function evaluate(c::AbstractVector{T}, s::HeavisideSpace{<:Real}, x::Real) where T
24+
p = domain(s).points
2725
for k=1:length(c)
2826
if p[k]  x  p[k+1]
2927
return c[k]
@@ -33,7 +31,7 @@ function evaluate(f::Fun{HeavisideSpace{T,R}},x::Real) where {T<:Real,R}
3331
end
3432

3533

36-
function evaluate(f::Fun{SplineSpace{1,T,R}},x::Real) where {T<:Real,R}
34+
function evaluate(c::AbstractVector{T}, s::SplineSpace{1,<:Real}, x::Real) where T
3735
p = domain(f).points
3836
c = f.coefficients
3937
for k=1:length(p)-1

src/Spaces/ProductSpaceOperators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
export continuity
22

33
## Space promotion for InterlaceOperator
44
# It's here because we need DirectSumSpace

src/specialfunctions.jl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,42 @@ function roots(f::Fun{P}) where P<:PiecewiseSpace
551551
rts
552552
end
553553

554-
roots(f::Fun{S,T}) where {S<:PointSpace,T} = space(f).points[values(f) .== 0]
554+
roots(f::Fun{S,T}) where {S<:PointSpace,T} = space(f).points[values(f) .== 0]
555+
556+
557+
558+
#
559+
# These formulæ, appearing in Eq. (2.5) of:
560+
#
561+
# A.-K. Kassam and L. N. Trefethen, Fourth-order time-stepping for stiff PDEs, SIAM J. Sci. Comput., 26:1214--1233, 2005,
562+
#
563+
# are derived to implement ETDRK4 in double precision without numerical instability from cancellation.
564+
#
565+
566+
expα_asy(x) = (exp(x)*(4-3x+x^2)-4-x)/x^3
567+
expβ_asy(x) = (exp(x)*(x-2)+x+2)/x^3
568+
expγ_asy(x) = (exp(x)*(4-x)-4-3x-x^2)/x^3
569+
570+
# TODO: General types
571+
572+
expα_taylor(x::Union{Float64,ComplexF64}) = @evalpoly(x,1/6,1/6,3/40,1/45,5/1008,1/1120,7/51840,1/56700,1/492800,1/4790016,11/566092800,1/605404800,13/100590336000,1/106748928000,1/1580833013760,1/25009272288000,17/7155594141696000,1/7508956815360000)
573+
expβ_taylor(x::Union{Float64,ComplexF64}) = @evalpoly(x,1/6,1/12,1/40,1/180,1/1008,1/6720,1/51840,1/453600,1/4435200,1/47900160,1/566092800,1/7264857600,1/100590336000,1/1494484992000,1/23712495206400,1/400148356608000,1/7155594141696000,1/135161222676480000)
574+
expγ_taylor(x::Union{Float64,ComplexF64}) = @evalpoly(x,1/6,0/1,-1/120,-1/360,-1/1680,-1/10080,-1/72576,-1/604800,-1/5702400,-1/59875200,-1/691891200,-1/8717829120,-1/118879488000,-1/1743565824000,-1/27360571392000,-1/457312407552000,-1/8109673360588800)
575+
576+
expα(x::Float64) = abs(x) < 17/16 ? expα_taylor(x) : expα_asy(x)
577+
expβ(x::Float64) = abs(x) < 19/16 ? expβ_taylor(x) : expβ_asy(x)
578+
expγ(x::Float64) = abs(x) < 15/16 ? expγ_taylor(x) : expγ_asy(x)
579+
580+
expα(x::ComplexF64) = abs2(x) < (17/16)^2 ? expα_taylor(x) : expα_asy(x)
581+
expβ(x::ComplexF64) = abs2(x) < (19/16)^2 ? expβ_taylor(x) : expβ_asy(x)
582+
expγ(x::ComplexF64) = abs2(x) < (15/16)^2 ? expγ_taylor(x) : expγ_asy(x)
583+
584+
expα(x) = expα_asy(x)
585+
expβ(x) = expβ_asy(x)
586+
expγ(x) = expγ_asy(x)
587+
588+
589+
for f in (:(exp),:(expm1),:expα,:expβ,:expγ)
590+
@eval $f(op::Operator) = OperatorFunction(op,$f)
591+
end
592+

test/ETDRK4Test.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using ApproxFunBase, Test
2+
import ApproxFunBase: expα, expβ, expγ
3+
4+
#
5+
# This tests the numerical stability of the formulæ appearing in Eq. (2.5) of:
6+
#
7+
# A.-K. Kassam and L. N. Trefethen, Fourth-order time-stepping for stiff PDEs, SIAM J. Sci. Comput., 26:1214--1233, 2005.
8+
#
9+
10+
@testset "ETDRK4" begin
11+
x = 10 .^ range(-15, stop=2, length=18)
12+
13+
@test norm(expα.(x)./expα.(big.(x)).-1,Inf) < eps()
14+
@test norm(expβ.(x)./expβ.(big.(x)).-1,Inf) < eps()
15+
@test norm(expγ.(x)./expγ.(big.(x)).-1,Inf) < eps()
16+
end

test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,22 @@ end
4747

4848
@time include("MatrixTest.jl")
4949
@time include("SpacesTest.jl")
50+
51+
52+
@testset "blockbandwidths for FiniteOperator of pointscompatibleace bug" begin
53+
S = ApproxFunBase.PointSpace([1.0,2.0])
54+
@test ApproxFunBase.blockbandwidths(FiniteOperator([1 2; 3 4],S,S)) == (0,0)
55+
end
56+
57+
@testset "DiracDelta sampling" begin
58+
δ = 0.3DiracDelta(0.1) + 3DiracDelta(2.3)
59+
Random.seed!(0)
60+
for _=1:10
61+
@test sample(δ) [0.1, 2.3]
62+
end
63+
Random.seed!(0)
64+
r = sample(δ, 10_000)
65+
@test count(i -> i == 0.1, r)/length(r) 0.3/(3.3) atol=0.01
66+
end
67+
68+
@time include("ETDRK4Test.jl")

0 commit comments

Comments
 (0)