Skip to content

Commit e8486d2

Browse files
authored
Support plotting on disks (#74)
* Support plotting on disks * disk plotting works * Update Project.toml * add tests * ZernikeITransform tests
1 parent d1f1c63 commit e8486d2

File tree

6 files changed

+118
-22
lines changed

6 files changed

+118
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
version:
13-
- '1.5'
14-
- '^1.6.0-0'
13+
- '1'
1514
os:
1615
- ubuntu-latest
1716
- macOS-latest

Project.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MultivariateOrthogonalPolynomials"
22
uuid = "4f6956fd-4f93-5457-9149-7bfc4b2ce06d"
3-
version = "0.0.9"
3+
version = "0.1.0"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -18,18 +18,19 @@ InfiniteLinearAlgebra = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
1818
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
1919
LazyBandedMatrices = "d7e5e226-e90b-4449-9968-0f923699bf6f"
2020
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
21+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
2122
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
2223
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2324
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2425
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2526

2627
[compat]
27-
ArrayLayouts = "0.6"
28+
ArrayLayouts = "0.6, 0.7"
2829
BandedMatrices = "0.16"
2930
BlockArrays = "0.14.1, 0.15"
3031
BlockBandedMatrices = "0.10.1"
3132
ClassicalOrthogonalPolynomials = "0.3.2"
32-
ContinuumArrays = "0.6.3, 0.7"
33+
ContinuumArrays = "0.7.3"
3334
DomainSets = "0.4"
3435
FastTransforms = "0.11, 0.12"
3536
FillArrays = "0.11"
@@ -41,4 +42,11 @@ LazyBandedMatrices = "0.5"
4142
QuasiArrays = "0.4, 0.5"
4243
SpecialFunctions = "0.10, 1"
4344
StaticArrays = "0.12, 1"
44-
julia = "1.5"
45+
julia = "1.6"
46+
47+
[extras]
48+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
49+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
50+
51+
[targets]
52+
test = ["RecipesBase", "Test"]

examples/diskhelmholtz.jl

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,70 @@
11
using MultivariateOrthogonalPolynomials, FastTransforms, BlockBandedMatrices, Plots
2+
plotly()
3+
import MultivariateOrthogonalPolynomials: ZernikeITransform, grid, plotgrid
4+
5+
6+
Z = Zernike()[:,Block.(Base.OneTo(10))]
7+
g = grid(Z)
8+
θ = getproperty.(g[1,:],)
9+
[permutedims(RadialCoordinate.(1,θ)); g; permutedims(RadialCoordinate.(0,θ))]
10+
import Mul
11+
12+
plotgrid(Z)
13+
14+
15+
Z = Zernike()
16+
xy = axes(Z,1)
17+
x,y = first.(xy),last.(xy)
18+
u = Z * (Z \ @.(cos(10x*y)))
19+
surface(u)
20+
21+
@.(cos(10x*y))
22+
23+
plot(u)
24+
25+
g = plotgrid(Z[:,Block.(Base.OneTo(10))])
26+
surface(first.(g), last.(g), u[g])
27+
plot(u)
28+
29+
30+
G = grid(Z)
31+
32+
contourf(first.(G), last.(G), ones(size(G)...))
33+
34+
35+
scatter(vec(first.(G)), vec(last.(G)))
36+
G[1,1].θ
237

338
WZ = Weighted(Zernike(1))
439
xy = axes(WZ,1)
540
x,y = first.(xy),last.(xy)
6-
u = Zernike(1) \ @. exp(x*cos(y))
41+
f = Zernike(1) \ @. exp(x*cos(y))
742

843
N = 50
944
KR = Block.(Base.OneTo(N))
10-
Δ = BandedBlockBandedMatrix((Zernike(1) \ (Laplacian(xy) * WZ))[KR,KR],(0,0),(0,0))
45+
Δ = (Zernike(1) \ (Laplacian(xy) * WZ))[KR,KR]
1146
C = (Zernike(1) \ WZ)[KR,KR]
1247
k = 5
1348
L = Δ - k^2 * C
1449

15-
v = (L \ u[KR])
50+
v = f[KR]
51+
@time u = (L \ v);
52+
53+
g = MultivariateOrthogonalPolynomials.grid(Zernike(1)[:,KR])
54+
U = ZernikeITransform{Float64}(N, 0, 1) * u
55+
56+
plot(first.(g), last.(g), U)
57+
58+
59+
60+
F = factorize(Zernike(1)[:,KR]).plan
61+
F \ u
62+
u
63+
64+
65+
F*u
66+
1667

17-
F = factorize(Zernike(1)[:,KR])
1868
F.plan \ v
1969
F |> typeof |> fieldnames
2070

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ using ClassicalOrthogonalPolynomials, FastTransforms, BlockBandedMatrices, Block
44
LazyArrays, SpecialFunctions, LinearAlgebra, BandedMatrices, LazyBandedMatrices, ArrayLayouts,
55
HarmonicOrthogonalPolynomials
66

7-
import Base: axes, in, ==, *, ^, \, copy, OneTo, getindex, size
7+
import Base: axes, in, ==, *, ^, \, copy, OneTo, getindex, size, oneto
88
import DomainSets: boundary
99

1010
import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle
11-
import ContinuumArrays: @simplify, Weight, grid, TransformFactorization, Expansion
11+
import ContinuumArrays: @simplify, Weight, grid, plotgrid, TransformFactorization, Expansion
1212

1313
import ArrayLayouts: MemoryLayout
1414
import BlockArrays: block, blockindex, BlockSlice, viewblock
@@ -26,13 +26,6 @@ export UnitTriangle, UnitDisk, JacobiTriangle, TriangleWeight, WeightedTriangle,
2626
MultivariateOrthogonalPolynomial, BivariateOrthogonalPolynomial, Zernike, RadialCoordinate,
2727
zerniker, zernikez, Weighted, Block, ZernikeWeight
2828

29-
if VERSION < v"1.6-"
30-
oneto(n) = Base.OneTo(n)
31-
else
32-
import Base: oneto
33-
end
34-
35-
3629

3730
include("disk.jl")
3831
include("triangle.jl")

src/disk.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,45 @@ function grid(S::FiniteZernike{T}) where T
178178
RadialCoordinate.(r, π*θ')
179179
end
180180

181+
_angle(rθ::RadialCoordinate) =.θ
182+
183+
function plotgrid(S::FiniteZernike{T}) where T
184+
N = blocksize(S,2) ÷ 2 + 1 # polynomial degree
185+
g = grid(parent(S)[:,Block.(OneTo(2N))]) # double sampling
186+
θ = [map(_angle,g[1,:]); 0]
187+
[permutedims(RadialCoordinate.(1,θ)); g g[:,1]; permutedims(RadialCoordinate.(0,θ))]
188+
end
189+
190+
function plotgrid(S::SubQuasiArray{<:Any,2,<:Zernike})
191+
kr,jr = parentindices(S)
192+
Z = parent(S)
193+
plotgrid(Z[kr,Block.(OneTo(Int(findblock(axes(Z,2),maximum(jr)))))])
194+
end
195+
181196
struct ZernikeTransform{T} <: Plan{T}
182197
N::Int
183198
disk2cxf::FastTransforms.FTPlan{T,2,FastTransforms.DISK}
184199
analysis::FastTransforms.FTPlan{T,2,FastTransforms.DISKANALYSIS}
185200
end
186201

202+
struct ZernikeITransform{T} <: Plan{T}
203+
N::Int
204+
disk2cxf::FastTransforms.FTPlan{T,2,FastTransforms.DISK}
205+
synthesis::FastTransforms.FTPlan{T,2,FastTransforms.DISKSYNTHESIS}
206+
end
207+
187208
function ZernikeTransform{T}(N::Int, a::Number, b::Number) where T<:Real
188209
= N ÷ 2 + 1
189210
ZernikeTransform{T}(N, plan_disk2cxf(T, Ñ, a, b), plan_disk_analysis(T, Ñ, 4-3))
190211
end
212+
function ZernikeITransform{T}(N::Int, a::Number, b::Number) where T<:Real
213+
= N ÷ 2 + 1
214+
ZernikeITransform{T}(N, plan_disk2cxf(T, Ñ, a, b), plan_disk_synthesis(T, Ñ, 4-3))
215+
end
216+
217+
*(P::ZernikeTransform{T}, f::AbstractArray) where T = P * convert(Matrix{T}, f)
191218
*(P::ZernikeTransform{T}, f::Matrix{T}) where T = DiskTrav(P.disk2cxf \ (P.analysis * f))[Block.(1:P.N)]
192-
\(P::ZernikeTransform, f::AbstractVector) = P.analysis \ (P.disk2cxf * DiskTrav(f).matrix)
219+
*(P::ZernikeITransform, f::AbstractVector) = P.synthesis * (P.disk2cxf * DiskTrav(f).matrix)
193220

194221
factorize(S::FiniteZernike{T}) where T = TransformFactorization(grid(S), ZernikeTransform{T}(blocksize(S,2), parent(S).a, parent(S).b))
195222

test/test_disk.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, BlockArrays, BandedMatrices, FastTransforms, LinearAlgebra, Test
2-
import MultivariateOrthogonalPolynomials: DiskTrav, grid
1+
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, BlockArrays, BandedMatrices, FastTransforms, LinearAlgebra, RecipesBase, Test
2+
import MultivariateOrthogonalPolynomials: DiskTrav, grid, ZernikeTransform, ZernikeITransform
33
import ClassicalOrthogonalPolynomials: HalfWeighted
44

55

66
@testset "Disk" begin
7+
@testset "Transform" begin
8+
N = 5
9+
T = ZernikeTransform{Float64}(N, 0, 0)
10+
Ti = ZernikeITransform{Float64}(N, 0, 0)
11+
12+
v = PseudoBlockArray(randn(sum(1:N)),1:N)
13+
@test T * (Ti * v) v
14+
15+
16+
@test_throws MethodError T * randn(15)
17+
end
718
@testset "Basics" begin
819
@test ZernikeWeight(1)[SVector(0.1,0.2)] (1 - 0.1^2 - 0.2^2)
920
@test ZernikeWeight(1) == ZernikeWeight(1)
@@ -225,4 +236,12 @@ import ClassicalOrthogonalPolynomials: HalfWeighted
225236
L2 = Zernike(1) \ Weighted(Zernike(1))
226237
@test w*Zernike(1)[xy,Block.(1:5)]' Zernike(1)[xy,Block.(1:7)]'*L2[Block.(1:7),Block.(1:5)]
227238
end
239+
240+
@testset "plotting" begin
241+
Z = Zernike()
242+
u = Z * [1; 2; zeros(∞)];
243+
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), u)
244+
g = MultivariateOrthogonalPolynomials.plotgrid(Z[:,1:3])
245+
@test rep[1].args == (first.(g),last.(g),u[g])
246+
end
228247
end

0 commit comments

Comments
 (0)