Skip to content

Commit 3dcca4c

Browse files
committed
Move out more Fourier code
1 parent 8819a16 commit 3dcca4c

File tree

10 files changed

+28
-292
lines changed

10 files changed

+28
-292
lines changed

src/Domains/Domains.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,31 @@ include("IntervalCurve.jl")
77

88
isless(d1::IntervalOrSegment{T1},d2::Ray{false,T2}) where {T1<:Real,T2<:Real} = d1 d2.center
99
isless(d2::Ray{true,T2},d1::IntervalOrSegment{T1}) where {T1<:Real,T2<:Real} = d2.center d1
10+
11+
12+
## set minus
13+
function Base.setdiff(d::Union{AbstractInterval,Segment,Ray,Line}, ptsin::UnionDomain{AS}) where {AS <: AbstractVector{P}} where {P <: Point}
14+
pts=Number.(elements(ptsin))
15+
isempty(pts) && return d
16+
tol=sqrt(eps(arclength(d)))
17+
da=leftendpoint(d)
18+
isapprox(da,pts[1];atol=tol) && popfirst!(pts)
19+
isempty(pts) && return d
20+
db=rightendpoint(d)
21+
isapprox(db,pts[end];atol=tol) && pop!(pts)
22+
23+
sort!(pts)
24+
leftendpoint(d) > rightendpoint(d) && reverse!(pts)
25+
filter!(p->p d,pts)
26+
27+
isempty(pts) && return d
28+
length(pts) == 1 && return d \ pts[1]
29+
30+
ret = Array{Domain}(undef, length(pts)+1)
31+
ret[1] = Domain(leftendpoint(d) .. pts[1])
32+
for k = 2:length(pts)
33+
ret[k] = Domain(pts[k-1]..pts[k])
34+
end
35+
ret[end] = Domain(pts[end] .. rightendpoint(d))
36+
UnionDomain(ret)
37+
end

test/FullPDETest.jl

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -250,36 +250,6 @@ import ApproxFun: resizedata!, CachedOperator, RaggedMatrix, testbandedblockband
250250
end
251251
end
252252

253-
@testset "Periodic Poisson" begin
254-
d=PeriodicSegment()^2
255-
S=Space(d)
256-
257-
f=Fun((x,y)->exp(-10(sin(x/2)^2+sin(y/2)^2)),d)
258-
A=Laplacian(d)+0.1I
259-
testbandedblockbandedoperator(A)
260-
@time u=A\f
261-
@test u(.1,.2) u(.2,.1)
262-
@test (lap(u)+.1u-f)|>coefficients|>norm < 1000000eps()
263-
end
264-
265-
266-
@testset "periodic x interval" begin
267-
=PeriodicSegment(-2.,2.);dt=Interval(0,1.)
268-
d=×dt
269-
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])
270-
u0=Fun->exp(-20θ^2),dθ)
271-
272-
ε = 0.1
273-
@time u=\([Ildirichlet(dt);Dt-ε*^2-Dθ],[u0;0.];tolerance=1E-4)
274-
@test (u(0.1,0.2),0.3103472600253807;atol=1E-2)
275-
276-
A=Dt+
277-
testbandedblockbandedoperator(A)
278-
279-
@time u=\([Ildirichlet(dt);Dt+Dθ],[u0;0.0];tolerance=1E-6)
280-
@test (u(0.2,0.1),u0(0.1);atol=1E-6)
281-
end
282-
283253
@testset "Small diffusion" begin
284254
dx=ChebyshevInterval();dt=Interval(0,0.2)
285255
d=dx×dt
@@ -301,25 +271,6 @@ import ApproxFun: resizedata!, CachedOperator, RaggedMatrix, testbandedblockband
301271
@test u(.1,.2) 0.46810331039791464
302272
end
303273

304-
@testset "Laplace in a strip" begin
305-
d=PeriodicSegment() × ChebyshevInterval()
306-
g=Fun((x,y)->real(cos(x+im*y)),(d)) # boundary data
307-
308-
309-
@test g(0.1,1.0) real(cos(0.1+im))
310-
@test g(0.1,-1.0) real(cos(0.1-im))
311-
v=[g;0]
312-
@test v(0.1,-1) [real(cos(0.1-im));0]
313-
314-
A=[Dirichlet(d);Laplacian(d)]
315-
a = space(v)
316-
b = rangespace(A)
317-
318-
@test Fun(component(v[1],1), component(b[1],1))(0.1,-1.0) v(0.1,-1.0)[1]
319-
@test Fun(component(v[1],2), component(b[1],2))(0.1,-1.0) v(0.1,-1.0)[1]
320-
@test ApproxFun.default_Fun(v[1] , b[1])(0.1,1.0) v(0.1,1.0)[1]
321-
end
322-
323274
@testset "concatenate InterlaceOperator" begin
324275
a=Fun(x -> 0 x 0.5 ? 0.5 : 1, Domain(-1..1) \ [0,0.5])
325276
@test a(0.1) == 0.5

test/IntegralEquationsTest.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,6 @@ using ApproxFunOrthogonalPolynomials, ApproxFunBase, IntervalSets, Random, Linea
133133
testbandedbelowoperator(L)
134134
end
135135

136-
@testset "Piecewise space definite integral" begin
137-
Γ=Segment(-im,1.0-im) Curve(Fun(x->exp(0.8im)*(x+x^2-1+im*(x-4x^3+x^4)/6))) Circle(2.0,0.2)
138-
z=Fun(Γ)
139-
140-
S=PiecewiseSpace(map(d->isa(d,Circle) ? Fourier(d) : JacobiWeight(0.5,0.5,Ultraspherical(1,d)),components(Γ)))
141-
142-
143-
B=DefiniteLineIntegral(S)
144-
145-
Random.seed!(0)
146-
f=Fun(S,rand(20))
147-
@test B*f linesum(component(f,1)) + linesum(component(f,2)) + linesum(component(f,3))
148-
end
149-
150-
151136
@testset "union domain" begin
152137
dom = ApproxFun.UnionDomain(0..1, 2..3)
153138
= DefiniteLineIntegral(union(JacobiWeight.(-0.5,-0.5,ChebyshevDirichlet{1,1}.(components(dom)))...))

test/MultivariateTest.jl

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,6 @@ using ApproxFun, LinearAlgebra, SpecialFunctions, Test
222222
testbandedblockbandedoperator(L)
223223
end
224224

225-
@testset "Bug in Multiplication" begin
226-
dom = Interval(0.001, 1) × PeriodicSegment(-pi, pi)
227-
228-
@test blocklengths(Space(dom)) == 2:2:
229-
230-
r,r2 = Fun((r,t) -> [r;r^2], dom)
231-
232-
@test r(0.1,0.2) 0.1
233-
@test r2(0.1,0.2) 0.1^2
234-
235-
sp = Space(dom)
236-
Dr = Derivative(sp, [1,0])
237-
@test ApproxFun.blockbandwidths(Dr) == (-1,1)
238-
@test ApproxFun.subblockbandwidths(Dr) == (1,3)
239-
240-
= Derivative(sp, [0,1])
241-
Mr = Multiplication(Fun( (r, θ) -> r, sp ), sp)
242-
rDr = Mr * Dr
243-
244-
testbandedblockbandedoperator(rDr)
245-
end
246-
247225
@testset "Cheby * Interval" begin
248226
d = ChebyshevInterval()^2
249227
x,y = Fun((d))
@@ -257,12 +235,6 @@ using ApproxFun, LinearAlgebra, SpecialFunctions, Test
257235
@test exp(x+im*y)(1.0,0.1) exp(1.0+0.1im)
258236
end
259237

260-
261-
@testset "Taylor()^2, checks bug in type of plan_transform" begin
262-
f = Fun((x,y)->exp((x-0.1)*cos(y-0.2)),Taylor()^2)
263-
@test f(0.2,0.3) exp(0.1*cos(0.1))
264-
end
265-
266238
@testset "DefiniteIntegral" begin
267239
f = Fun((x,y) -> exp(-x*cos(y)))
268240
@test Number(DefiniteIntegral()*f) sum(f)
@@ -299,10 +271,6 @@ using ApproxFun, LinearAlgebra, SpecialFunctions, Test
299271
g = Fun(1, Segment(Vec(0,-1) , Vec(π,-1)))
300272
@test g(0.1,-1) 1
301273
@test g(0.1,1) 0
302-
303-
g = Fun(1, PeriodicSegment(Vec(0,-1) , Vec(π,-1)))
304-
@test g(0.1,-1) 1
305-
@test g(0.1,1) 0
306274
end
307275

308276

test/ODETest.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ using ApproxFunOrthogonalPolynomials, ApproxFunBase, SpecialFunctions, LazyArray
3838
@test (u(0.),airyai(0.);atol=10ncoefficients(u)*eps())
3939

4040
B=Neumann(d);
41-
@which B.op[1,2]
4241
A=[B;D2-X];
4342
b=[[airyaiprime(leftendpoint(d)),airyaiprime(rightendpoint(d))],0.];
4443

test/PDETest.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,6 @@ using ApproxFun, LinearAlgebra, Test
8080
@test u(0.1,0.2) 1.0
8181
end
8282

83-
@testset "Periodic x Interval" begin
84-
d=PeriodicSegment() × ChebyshevInterval()
85-
86-
u_ex=Fun((x,y)->real(cos(x+im*y)),d)
87-
@test u_ex(1.0,0.1) real(cos(1.0+im*0.1)) atol=10eps()
88-
89-
B=Dirichlet(Space(d))
90-
91-
@test B.order == 0 # tests stupid bug
92-
g=Fun((x,y)->real(cos(x+im*y)),rangespace(B)) # boundary data
93-
94-
@test norm((B*u_ex-g).coefficients) < 100eps()
95-
96-
testbandedblockbandedoperator(Laplacian(d))
97-
98-
@time u=[B;Laplacian(d)]\[g;0.]
99-
100-
@test u(.1,.2) real(cos(.1+.2im))
101-
end
102-
10383
@testset "Schrodinger" begin
10484
dx=0..1; dt=0.0..0.001
10585
C=Conversion(Chebyshev(dx)*Ultraspherical(1,dt),Ultraspherical(2,dx)*Ultraspherical(1,dt))

test/SingularitiesTest.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,6 @@ using ApproxFun, IntervalSets, SpecialFunctions, LinearAlgebra, Random, Test
117117
@test f'(0.1) -2*0.1exp(-0.1^2)
118118
@test (Derivative()*f)(0.1) -2*0.1exp(-0.1^2)
119119
end
120-
121-
@testset "PeriodicLine" begin
122-
d=PeriodicLine()
123-
D=Derivative(d)
124-
125-
f = Fun(x->sech(x-0.1),d,200)
126-
@test f(1.) sech(1-0.1)
127-
128-
f=Fun(x->sech(x-0.1),d)
129-
@test f(1.) sech(1-0.1)
130-
131-
@test ((D*f)(.2),-0.0991717226583897;atol=100000eps())
132-
@test ((D^2*f)(.2),-0.9752522555114987;atol=1000000eps())
133-
end
134120
end
135121

136122
@testset "LogWeight" begin

test/SpacesTest.jl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,6 @@ using ApproxFun, SpecialFunctions, LinearAlgebra, Test
161161
@test f(0.1) (C*f)(0.1)
162162
end
163163

164-
@testset "Piecewise + Constant" begin
165-
Γ=Circle() Circle(0.0,0.4)
166-
o=ones(Γ)
167-
@test o(1.) 1.0
168-
@test o(0.4) 1.0
169-
170-
@time G=Fun(z->in(z,component(Γ,2)) ? [1 0; -1/z 1] : [z 0; 0 1/z],Γ)
171-
@test (G-I)(exp(0.1im)) (G(exp(0.1im))-I)
172-
end
173-
174164
@testset "Previoius segfault" begin
175165
x=Fun(identity,-1..1)
176166
@time f=x+sin(2x)*sqrt(1-x^2)
@@ -223,19 +213,7 @@ using ApproxFun, SpecialFunctions, LinearAlgebra, Test
223213
@test exp(z)(0.1exp(0.2im)) exp(0.1exp(0.2im))
224214
end
225215

226-
@testset "Extending function" begin
227-
Γ = Segment(-im,1.0-im) Curve(Fun(x->exp(0.8im)*(x+x^2-1+im*(x-4x^3+x^4)/6))) Circle(2.0,0.2)
228-
229-
@test isempty(component(Γ,1)\component(Γ,1))
230-
@test Γ \ component(Γ,1) == component(Γ,2) component(Γ,3)
231-
232-
@test norm(Fun(ones(component(Γ,1)),Γ) - Fun(x->x component(Γ,1) ? 1.0 : 0.0,Γ)) == 0
233-
end
234-
235216
@testset "Line" begin
236-
f=Fun(z->2exp(z^2),PeriodicLine(0./2))
237-
@test f(1.1im) 2exp(-1.1^2)
238-
239217
f=Fun(z->2exp(z^2),Line(0./2))
240218
@test f(1.1im) 2exp(-1.1^2)
241219
end

test/VectorTest.jl

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -75,55 +75,6 @@ using ApproxFunOrthogonalPolynomials, ApproxFunBase, LazyArrays, FillArrays, Lin
7575
@test (m+I)(0.1) m(0.1)+I
7676
end
7777

78-
@testset "CosSpace Vector" begin
79-
a = [1 2; 3 4]
80-
f = Fun->[1,cos(θ)],CosSpace())
81-
@test (a*f)(0.1) [1+2cos(0.1); 3+4cos(0.1)]
82-
@test (a*f)(0.1) a*f(0.1)
83-
@test Fun(a)*f a*f
84-
@test Fun(a*Array(f)) a*f
85-
end
86-
87-
@testset "CosSpace Matrix" begin
88-
a = [1 2; 3 4]
89-
m = Fun->[1 cos(θ); cos(2θ) cos(cos(θ))],CosSpace())
90-
@test (a*m)(0.1) a*m(0.1)
91-
@test (m*a)(0.1) m(0.1)*a
92-
@test Fun(a)*m a*m
93-
@test Fun(a*Array(m)) a*m
94-
95-
@test (a+m)(0.1) a+m(0.1)
96-
@test (m+a)(0.1) m(0.1)+a
97-
98-
@test (m+I)(0.1) m(0.1)+I
99-
end
100-
101-
@testset "SinSpace Vector" begin
102-
a = [1 2; 3 4]
103-
f = Fun->[sin(θ),sin(2θ)],SinSpace())
104-
@test (a*f)(0.1) a*f(0.1)
105-
@test Fun(a)*f a*f
106-
@test Fun(a*Array(f)) a*f
107-
108-
@test all(sp -> sp isa SinSpace, space(a*f).spaces)
109-
end
110-
111-
@testset "CosSpace Matrix" begin
112-
a = [1 2; 3 4]
113-
m = Fun->[sin(3θ) sin(θ); sin(2θ) sin(sin(θ))],SinSpace())
114-
@test (a*m)(0.1) a*m(0.1)
115-
@test (m*a)(0.1) m(0.1)*a
116-
@test Fun(a)*m a*m
117-
@test Fun(a*Array(m)) a*m
118-
119-
@test all(sp -> sp isa SinSpace, space(a*m).spaces)
120-
121-
@test (a+m)(0.1) a+m(0.1)
122-
@test (m+a)(0.1) m(0.1)+a
123-
124-
@test (m+I)(0.1) m(0.1)+I
125-
end
126-
12778
@testset "Matrix{Fun}*Matrix{Fun}" begin
12879
# note that 2x2 and 3x3 mult are special cases
12980
x=Fun()
@@ -220,71 +171,7 @@ end
220171
@test norm((([1 2;3 4]*f)-Fun(t->[t^2+2sin(t),3t^2+4sin(t)])).coefficients)<100eps()
221172
end
222173

223-
@testset "Two circles" begin
224-
Γ = Circle() Circle(0.5)
225-
226-
f = Fun(z -> in(z,component(Γ,2)) ? 1 : z,Γ)
227-
@test f(exp(0.1im)) exp(0.1im)
228-
@test f(0.5exp(0.1im)) 1
229-
230-
G = Fun(z -> in(z,component(Γ,2)) ? [1 -z^(-1); 0 1] :
231-
[z 0; 0 z^(-1)], Γ);
232-
233-
@test G(exp(0.1im)) [exp(0.1im) 0 ; 0 exp(-0.1im)]
234-
@test G(0.5exp(0.1im)) [1 -2exp(-0.1im) ; 0 1]
235-
236-
G1=Fun(Array(G)[:,1])
237-
238-
@test G1(exp(0.1im)) [exp(0.1im),0.]
239-
@test G1(0.5exp(0.1im)) [1,0.]
240-
241-
M = Multiplication(G, space(G1))
242-
testblockbandedoperator(M)
243-
244-
for z in (0.5exp(0.1im),exp(0.2im))
245-
@test G[1,1](z) G[1](z)
246-
@test (M.op.ops[1,1]*G1[1])(z) M.f[1,1](z)*G1[1](z)
247-
@test (M.op.ops[2,1]*G1[1])(z) M.f[2,1](z)*G1[1](z)
248-
@test (M.op.ops[1,2]*G1[2])(z) M.f[1,2](z)*G1[2](z)
249-
@test (M.op.ops[2,2]*G1[2])(z) M.f[2,2](z)*G1[2](z)
250-
end
251-
252-
u = M*G1
253-
@test norm(u(exp(.1im))-[exp(.2im),0])<100eps()
254-
@test norm(u(.5exp(.1im))-[1,0])<100eps()
255-
end
256-
257-
@testset "Circle" begin
258-
G = Fun(z->[-1 -3; -3 -1]/z +
259-
[ 2 2; 1 -3] +
260-
[ 2 -1; 1 2]*z, Circle())
261-
262-
@test G[1,1](exp(0.1im)) == G(exp(0.1im))[1,1]
263-
264-
= Array((G-I)[:,1])
265-
F = (G-I)[:,1]
266-
267-
@test Fun(F) F
268-
269-
@test F(exp(0.1im)) [-exp(-0.1im)+1+2exp(0.1im);-3exp(-0.1im)+1+1exp(0.1im)]
270-
@test Fun(F̃,space(F))(exp(0.1im)) [-exp(-0.1im)+1+2exp(0.1im);-3exp(-0.1im)+1+1exp(0.1im)]
271-
272-
@test coefficients(F̃,space(F)) == F.coefficients
273-
@test Fun(F̃,space(F)) == F
274-
275-
@test F == Fun(vec(F),space(F))
276-
277-
@test inv(G(exp(0.1im))) inv(G)(exp(0.1im))
278-
279-
@test Fun(Matrix(I,2,2),space(G))(exp(0.1im)) Matrix(I,2,2)
280-
@test Fun(I,space(G))(exp(0.1im)) Matrix(I,2,2)
281-
end
282-
283174
@testset "Conversion" begin
284-
f=Fun(t->[cos(t) 0;sin(t) 1],-π..π)
285-
g=Fun(f,Space(PeriodicSegment(-π,π)))
286-
@test g(.1) f(.1)
287-
288175
a = ArraySpace(JacobiWeight(1/2,1/2, Chebyshev()), 2)
289176
b = ArraySpace(JacobiWeight(1/2,1/2, Ultraspherical(1)), 2)
290177
C = Conversion(a, b)

0 commit comments

Comments
 (0)