Skip to content

Commit 7a51b0c

Browse files
committed
Triangle tests pass again
1 parent 972a606 commit 7a51b0c

File tree

1 file changed

+26
-154
lines changed

1 file changed

+26
-154
lines changed

test/TriangleTest.jl

Lines changed: 26 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -49,164 +49,37 @@ let P = (n,k,a,b,c,x,y) -> x == 1.0 ? ((1-x))^k*jacobip(n-k,2k+b+c+1,a,1.0)*jaco
4949
end
5050

5151
@testset "JacobiTriangle constructors" begin
52-
@time f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,-0.5,-0.5)); # 0.08s
53-
@test f(0.1,0.2) cos(100*0.1*0.2)
54-
P = plan_evaluate(f)
55-
@test values(f) P.(points(f))
56-
57-
@time f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,-0.5,-0.5),40_000); # 0.2
58-
@test f(0.1,0.2) cos(500*0.1*0.2)
59-
60-
@time f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,0.5,-0.5)); # 0.08s
61-
@time f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,0.5,-0.5),40_000); # 0.2
62-
@test f(0.1,0.2) cos(500*0.1*0.2)
63-
64-
f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,0.5,0.5)); # 1.15s
65-
f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,0.5,0.5),40_000); # 0.2
66-
@test f(0.1,0.2) cos(500*0.1*0.2)
67-
68-
f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,-0.5,0.5)); # 1.15s
69-
f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,-0.5,0.5),40_000); # 0.2
70-
@test f(0.1,0.2) cos(500*0.1*0.2)
71-
72-
d = Triangle(Vec(0,0),Vec(3,4),Vec(1,6))
73-
@time f = Fun((x,y)->cos(x*y),JacobiTriangle(0.0,-0.5,-0.5,d)); # 0.08s
74-
@test f(2,4) cos(2*4)
75-
@time f = Fun((x,y)->cos(x*y),JacobiTriangle(0.0,-0.5,0.5,d)); # 0.08s
76-
@test f(2,4) cos(2*4)
77-
end
78-
79-
@time f = Fun((x,y)->1,JacobiTriangle(0.0,0.5,-0.5),10); # 0.2
80-
p = points(JacobiTriangle(0.0,0.5,-0.5),10)
81-
S = space(f)
82-
P = plan_transform(S, f)
83-
v = (_ -> 1.0).(p)
84-
85-
= P.duffyplan*v
86-
F = MultivariateOrthogonalPolynomials.tridevec_trans(v̂)
87-
@which P.tri2cheb \ F
88-
P = MultivariateOrthogonalPolynomials.c_plan_tri2cheb(4, 0.0, 0.5, -0.5)
89-
F = zeros(4,4); F[1]=1;
90-
MultivariateOrthogonalPolynomials.c_cheb2tri(P, F)
91-
92-
P = MultivariateOrthogonalPolynomials.c_plan_tri2cheb(4, 0.0, -0.5, -0.5)
93-
F = zeros(4,4); F[1]=1;
94-
MultivariateOrthogonalPolynomials.c_cheb2tri(P, F)
95-
96-
F
97-
98-
n = floor(Integer,sqrt(2length(v)) + 1/2)
99-
= P.tri2cheb \ F
100-
trivec(tridenormalize!(F̌,P.a,P.b,P.c))
101-
102-
@time P(0.1,0.2)
103-
104-
105-
@time f = Fun((x,y) -> begin
106-
# ret = 0.0
107-
# for n = 18:18, k=8:8
108-
# ret += P(n,k,0.,-0.5,-0.5,x,y)
109-
# end
110-
# ret
111-
P(18,8,0.,-0.5,-0.5,x,y)
112-
end,
113-
JacobiTriangle(0.0,-0.5,-0.5),600); # 0.08s
114-
sum(f.coefficients)
115-
116-
n = 600
117-
S = JacobiTriangle(0.0,-0.5,-0.5)
118-
ff = (xy) -> P(18,8,0.,-0.5,-0.5,xy...)
119-
p = points(S,n)
120-
v = ff.(p)
121-
PP = plan_transform(S,v)
122-
= PP.duffyplan*v
123-
F = tridevec_trans(v̂)
124-
= FastTransforms.cheb2tri(F,0.,-0.5,-0.5)
125-
F̌₂ = PP.tri2cheb \ F
126-
norm(F̌ - F̌₂)
127-
size(F)
128-
= copy(F)
129-
c_cheb2tri(c_plan_tri2cheb(size(F,1),0.0,-0.5,-0.5),F̃)
130-
|> chopm
131-
132-
@which PP.tri2cheb \ F
133-
trivec(tridenormalize!(F̌,P.a,P.b,P.c))
52+
@time f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,-0.5,-0.5)); # 0.08s
53+
@test f(0.1,0.2) cos(100*0.1*0.2)
54+
P = plan_evaluate(f)
55+
@test values(f) P.(points(f))
13456

135-
sum(1:18)
57+
@time f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,-0.5,-0.5),40_000); # 0.2
58+
@test f(0.1,0.2) cos(500*0.1*0.2)
13659

60+
@time f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,0.5,-0.5)); # 0.08s
61+
@time f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,0.5,-0.5),40_000); # 0.2
62+
@test f(0.1,0.2) cos(500*0.1*0.2)
13763

138-
using SO
139-
tridevec(f.coefficients) |> chopm
64+
f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,0.5,0.5)); # 1.15s
65+
f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,0.5,0.5),40_000); # 0.2
66+
@test f(0.1,0.2) cos(500*0.1*0.2)
14067

68+
f = Fun((x,y)->cos(100x*y),JacobiTriangle(0.0,-0.5,0.5)); # 1.15s
69+
f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,-0.5,0.5),40_000); # 0.2
70+
@test f(0.1,0.2) cos(500*0.1*0.2)
14171

142-
sum(1:16)
143-
144-
@test f(0.1,0.2) cos(0.1*0.2)
145-
146-
p = points(space(f), 150)
147-
148-
ff = (xy) -> cos(xy[1]*xy[2])
149-
ff.(p)
150-
151-
152-
153-
154-
@time f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,-0.5,-0.5),40_000); # 0.2
155-
@time f = Fun((x,y)->cos(500x*y),JacobiTriangle(0.0,-0.5,-0.5)); # 0.2
156-
157-
plot(f)
158-
ncoefficients(f)
159-
160-
P = (n,k,a,b,c,x,y) -> x == 1.0 ? ((1-x))^k*jacobip(n-k,2k+b+c+1,a,1.0)*jacobip(k,c,b,-1.0) :
161-
((1-x))^k*jacobip(n-k,2k+b+c+1,a,2x-1)*jacobip(k,c,b,2y/(1-x)-1)
162-
163-
f = Fun((x,y) -> P(5,1,0.,0.,0.,x,y), JacobiTriangle(0.,-0.5,-0.5) )
164-
F = tridevec(f.coefficients)
165-
F[:,2] = jjt(F[:,2], 2.0, 0.0, 3.0, 0.0) # correct
166-
jjt(F[2,:], -0.5, -0.5, 0.0, 0.0)
167-
F
168-
jjt(F[:,1], 0.0, 0.0, 1.0, 0.0) # correct
169-
170-
171-
172-
173-
174-
jjt(jjt(F[:,1], 0.0, -0.5, 0.0, 0.0),0.0,0.0,1.0,0.0)
175-
176-
jac2jac(Fun(Fun(Legendre(),[0,0,1.0]),Jacobi(0.0,0.5)).coefficients,
177-
0.0, 0.0, 0.5, 0.0)
178-
179-
jac2jac(Fun(x -> Fun(Jacobi(0.0,0.5),[0,0,1.0])(x),Legendre()).coefficients,
180-
0.0, 0.0, 0.5, 0.0)
181-
182-
jjt(Fun(x -> jacobip(2,0.5,0.0,x),Legendre()).coefficients,
183-
0.0, 0.0, 0.5, 0.0)
184-
185-
using SO
186-
Fun(Fun(Jacobi(-0.5,0.0), [0,0,0,0,1.0]), Jacobi(0.0,0.0))
187-
188-
189-
Fun(Fun(Jacobi(0.0,-0.5), [0,0,0,0,1.0]), Jacobi(0.0,0.0))
190-
191-
192-
v = f.coefficients
193-
N = floor(Integer,sqrt(2length(v)) + 1/2)
194-
ret = zeros(Float64, N, N)
195-
j = 1
196-
for n=1:N,k=1:n
197-
j > length(v) && return
198-
ret[n-k+1,k] = v[j]
199-
j += 1
200-
end
201-
ret
202-
203-
204-
v
72+
d = Triangle(Vec(0,0),Vec(3,4),Vec(1,6))
73+
@time f = Fun((x,y)->cos(x*y),JacobiTriangle(0.0,-0.5,-0.5,d)); # 0.08s
74+
@test f(2,4) cos(2*4)
75+
@time f = Fun((x,y)->cos(x*y),JacobiTriangle(0.0,-0.5,0.5,d)); # 0.08s
76+
@test f(2,4) cos(2*4)
77+
end
20578

20679

20780
@testset "old constructors" begin
20881
f = Fun((x,y)->exp(x*cos(y)),JacobiTriangle(1,1,1))
209-
@test Fun(f,ProductTriangle(1,1,1))(0.1,0.2) exp(0.1*cos(0.2))
82+
@test f(0.1,0.2) exp(0.1*cos(0.2))
21083
f=Fun((x,y)->exp(x*cos(y)),JacobiTriangle(0,0,0))
21184
@test f(0.1,0.2) exp(0.1*cos(0.2))
21285
d = Triangle(Vec(0,0),Vec(3,4),Vec(1,6))
@@ -256,7 +129,6 @@ end
256129
f = Fun((x,y)->exp(x*cos(y)),JacobiTriangle(1,1,1))
257130
Jx = MultivariateOrthogonalPolynomials.Lowering{1}(space(f))
258131
testbandedblockbandedoperator(Jx)
259-
@test Fun(Jx*f,ProductTriangle(0,1,1))(0.1,0.2) 0.1exp(0.1*cos(0.2))
260132

261133
Jy = MultivariateOrthogonalPolynomials.Lowering{2}(space(f))
262134
testbandedblockbandedoperator(Jy)
@@ -269,12 +141,12 @@ end
269141
@test ApproxFun.colstop(Jy,4) == 8
270142

271143

272-
@test Fun(Jy*f,ProductTriangle(1,0,1))(0.1,0.2) 0.2exp(0.1*cos(0.2))
144+
@test (Jy*f)(0.1,0.2) 0.2exp(0.1*cos(0.2))
273145
@test norm((Jy*f-Fun((x,y)->y*exp(x*cos(y)),JacobiTriangle(1,0,1))).coefficients) < 1E-11
274146

275147
Jz = MultivariateOrthogonalPolynomials.Lowering{3}(space(f))
276148
testbandedblockbandedoperator(Jz)
277-
@test Fun(Jz*f,ProductTriangle(1,1,0))(0.1,0.2) (1-0.1-0.2)exp(0.1*cos(0.2))
149+
@test (Jz*f)(0.1,0.2) (1-0.1-0.2)exp(0.1*cos(0.2))
278150

279151
@test f(0.1,0.2) exp(0.1*cos(0.2))
280152

@@ -494,7 +366,7 @@ end
494366

495367
f=Fun(S,rand(3))
496368
h=0.01
497-
QR=qrfact(I-h*Δ)
369+
QR=qr(I-h*Δ)
498370
@time u=\(QR,f;tolerance=1E-7)
499371
@time g=Fun(f,rangespace(QR))
500372
@time \(QR,g;tolerance=1E-7)
@@ -530,7 +402,7 @@ end
530402
h=0.01
531403
Δ = Laplacian(S)
532404
@test maxspace(rangespace(Δ), S) == JacobiTriangle(1,1,1,d)
533-
QR=qrfact(I-h*Δ)
405+
QR=qr(I-h*Δ)
534406
@time u=\(QR,f;tolerance=1E-7)
535407
@time g=Fun(f,rangespace(QR))
536408
@time \(QR,g;tolerance=1E-7)

0 commit comments

Comments
 (0)