Skip to content

Commit 9750e75

Browse files
committed
Work on 3DCone
1 parent c9882d0 commit 9750e75

File tree

3 files changed

+108
-29
lines changed

3 files changed

+108
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
Manifest.toml
3+
.DS_Store

src/Cone/Cone.jl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,41 @@ function evaluate(cfs::AbstractVector, S::DuffyConic, txy::Vec{3})
6464
Fun(rectspace(S), cfs)(t,θ)
6565
end
6666

67-
68-
function _coefficients(triangleplan, v::AbstractVector{T}, ::DuffyConic, ::LegendreConic) where T
69-
F = totensor(rectspace(DuffyConic()), v)
70-
F = pad(F, :, 2size(F,1)-1)
67+
function duffy2legendreconic!(triangleplan, F::AbstractMatrix)
7168
Fc = F[:,1:2:end]
7269
c_execute_tri_lo2hi(triangleplan, Fc)
7370
F[:,1:2:end] .= Fc
7471
# ignore first column
7572
Fc[:,2:end] .= F[:,2:2:end]
7673
c_execute_tri_lo2hi(triangleplan, Fc)
7774
F[:,2:2:end] .= Fc[:,2:end]
78-
fromtensor(LegendreConic(), F)
75+
F
7976
end
8077

81-
function _coefficients(triangleplan, v::AbstractVector{T}, ::LegendreConic, ::DuffyConic) where T
82-
F = totensor(LegendreConic(), v)
83-
F = pad(F, :, 2size(F,1)-1)
78+
function legendre2duffyconic!(triangleplan, F::AbstractMatrix)
8479
Fc = F[:,1:2:end]
8580
c_execute_tri_hi2lo(triangleplan, Fc)
8681
F[:,1:2:end] .= Fc
8782
# ignore first column
8883
Fc[:,2:end] .= F[:,2:2:end]
8984
c_execute_tri_hi2lo(triangleplan, Fc)
9085
F[:,2:2:end] .= Fc[:,2:end]
91-
fromtensor(DuffyConic(), F)
86+
F
87+
end
88+
89+
90+
function _coefficients(triangleplan, v::AbstractVector{T}, ::DuffyConic, ::LegendreConic) where T
91+
F = totensor(rectspace(DuffyConic()), v)
92+
F = pad(F, :, 2size(F,1)-1)
93+
duffy2legendreconic!(triangleplan, F)
94+
fromtensor(LegendreConic(), F)
95+
end
96+
97+
function _coefficients(triangleplan, v::AbstractVector{T}, ::LegendreConic, ::DuffyConic) where T
98+
F = totensor(LegendreConic(), v)
99+
F = pad(F, :, 2size(F,1)-1)
100+
legendre2duffyconic!(triangleplan, F)
101+
fromtensor(rectspace(DuffyConic()), F)
92102
end
93103

94104
function coefficients(cfs::AbstractVector{T}, CD::DuffyConic, ZD::LegendreConic) where T

test/test_cone.jl

Lines changed: 88 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,103 @@ import MultivariateOrthogonalPolynomials: rectspace, totensor, duffy2legendrecon
2727
@test g(t,x,y) f((t,x,y))
2828
end
2929

30-
@testset "Legendre<>DuffyConic" begin
31-
for k = 0:10
32-
a = [zeros(k); 1.0; zeros(5)]
33-
F = totensor(rectspace(DuffyConic()), a)
34-
F = pad(F, :, 2size(F,1)-1)
35-
T = eltype(a)
36-
P = c_plan_rottriangle(size(F,1), zero(T), zero(T), zero(T))
37-
@test legendre2duffyconic!(P, duffy2legendreconic!(P, copy(F))) F
38-
39-
b = coefficients(a, LegendreConic(), DuffyConic())
40-
@test a coefficients(b, DuffyConic(), LegendreConic())[1:length(a)]
30+
@testset "Legendre<>DuffyConic" begin
31+
for k = 0:10
32+
a = [zeros(k); 1.0; zeros(5)]
33+
F = totensor(rectspace(DuffyConic()), a)
34+
F = pad(F, :, 2size(F,1)-1)
35+
T = eltype(a)
36+
P = c_plan_rottriangle(size(F,1), zero(T), zero(T), zero(T))
37+
@test legendre2duffyconic!(P, duffy2legendreconic!(P, copy(F))) F
38+
39+
b = coefficients(a, LegendreConic(), DuffyConic())
40+
@test a coefficients(b, DuffyConic(), LegendreConic())[1:length(a)]
41+
end
42+
end
43+
44+
@testset "LegendreConicPlan" begin
45+
for (m,ℓ) in ((0,0), (0,1), (0,2), (1,1), (1,2), (2,2))
46+
f = (txy) -> ((t,x,y) = txy; θ = atan(y,x); Fun(NormalizedJacobi(0,2m+1,Segment(1,0)),[zeros(ℓ);1])(t) * 2^m * t^m * cos(m*θ))
47+
g = Fun(f, LegendreConic())
48+
t,x,y = sqrt(0.1^2+0.2^2),0.1,0.2
49+
@test g(t,x,y) f((t,x,y))
50+
end
51+
end
52+
53+
@testset "LegendreConic" begin
54+
f = Fun((t,x,y) -> 1, LegendreConic(), 10)
55+
@test f.coefficients [1; zeros(ncoefficients(f)-1)]
56+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 1
57+
58+
f = Fun((t,x,y) -> t, LegendreConic(), 10)
59+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) sqrt(0.1^2+0.2^2)
60+
f = Fun((t,x,y) -> 1+t+x+y, LegendreConic(), 10)
61+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 1+sqrt(0.1^2+0.2^2)+0.1+0.2
62+
63+
64+
@time Fun((t,x,y) -> 1+t+x+y, LegendreConic(), 1000)
4165
end
4266
end
4367

4468

45-
@testset "LegendreConicPlan" begin
46-
for (m,ℓ) in ((0,0), (0,1), (0,2), (1,1), (1,2), (2,2))
69+
@testset "Cone" begin
70+
@testset "rectspace" begin
71+
rs = rectspace(DuffyCone())
72+
@test points(rs,10) isa Vector{SVector{3,Float64}}
73+
end
74+
75+
@testset "DuffyCone" begin
76+
f = Fun((t,x,y) -> 1, DuffyCone(), 10)
77+
@test f.coefficients [1; zeros(ncoefficients(f)-1)]
78+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 1
79+
80+
f = Fun((t,x,y) -> t, DuffyConic(), 10)
81+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) sqrt(0.1^2+0.2^2)
82+
83+
f = Fun((t,x,y) -> x, DuffyConic(), 10)
84+
85+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 0.1
86+
87+
f = Fun((t,x,y) -> exp(cos(t*x)*y), DuffyConic(), 1000)
88+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) exp(cos(sqrt(0.1^2+0.2^2)*0.1)*0.2)
89+
90+
f = Fun((t,x,y) -> exp(cos(t*x)*y), DuffyConic())
91+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) exp(cos(sqrt(0.1^2+0.2^2)*0.1)*0.2)
92+
93+
m,ℓ = (1,1)
4794
f = (txy) -> ((t,x,y) = txy; θ = atan(y,x); Fun(NormalizedJacobi(0,2m+1,Segment(1,0)),[zeros(ℓ);1])(t) * 2^m * t^m * cos(m*θ))
48-
g = Fun(f, LegendreConic())
95+
g = Fun(f, DuffyConic())
4996
t,x,y = sqrt(0.1^2+0.2^2),0.1,0.2
5097
@test g(t,x,y) f((t,x,y))
5198
end
52-
end
5399

100+
@testset "Legendre<>DuffyConic" begin
101+
for k = 0:10
102+
a = [zeros(k); 1.0; zeros(5)]
103+
F = totensor(rectspace(DuffyConic()), a)
104+
F = pad(F, :, 2size(F,1)-1)
105+
T = eltype(a)
106+
P = c_plan_rottriangle(size(F,1), zero(T), zero(T), zero(T))
107+
@test legendre2duffyconic!(P, duffy2legendreconic!(P, copy(F))) F
108+
109+
b = coefficients(a, LegendreConic(), DuffyConic())
110+
@test a coefficients(b, DuffyConic(), LegendreConic())[1:length(a)]
111+
end
112+
end
113+
114+
@testset "LegendreConicPlan" begin
115+
for (m,ℓ) in ((0,0), (0,1), (0,2), (1,1), (1,2), (2,2))
116+
f = (txy) -> ((t,x,y) = txy; θ = atan(y,x); Fun(NormalizedJacobi(0,2m+1,Segment(1,0)),[zeros(ℓ);1])(t) * 2^m * t^m * cos(m*θ))
117+
g = Fun(f, LegendreConic())
118+
t,x,y = sqrt(0.1^2+0.2^2),0.1,0.2
119+
@test g(t,x,y) f((t,x,y))
120+
end
121+
end
54122

55-
@testset "LegendreConic" begin
56-
f = Fun((t,x,y) -> 1, LegendreConic(), 10)
57-
@test f.coefficients [1; zeros(ncoefficients(f)-1)]
58-
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 1
123+
@testset "LegendreConic" begin
124+
f = Fun((t,x,y) -> 1, LegendreConic(), 10)
125+
@test f.coefficients [1; zeros(ncoefficients(f)-1)]
126+
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 1
59127

60128
f = Fun((t,x,y) -> t, LegendreConic(), 10)
61129
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) sqrt(0.1^2+0.2^2)
@@ -65,4 +133,4 @@ end
65133

66134
@time Fun((t,x,y) -> 1+t+x+y, LegendreConic(), 1000)
67135
end
68-
end
136+
end

0 commit comments

Comments
 (0)