Skip to content

Commit 63dc386

Browse files
authored
Use transform for plotting (#127)
* Use transform for plotting * Separate weighted and regular Zernike plot * Update test_disk.jl * test weighted zernike plot
1 parent cf0d0ba commit 63dc386

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

examples/diskhelmholtz.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using MultivariateOrthogonalPolynomials, FastTransforms, BlockBandedMatrices, Plots, LinearAlgebra, StaticArrays
2-
plotly()
2+
pyplot()
33

44

55
####
@@ -25,7 +25,7 @@ L = Δ + k^2 * S # discretisation of Helmholtz
2525
f = @.(cos(x * exp(y)))
2626

2727
u = W * (L \ (Z \ f))
28-
surface(u)
28+
contourf(u)
2929

3030

3131
# One can also fix the discretisation size
@@ -36,16 +36,14 @@ Wₙ = W[:,Block.(1:N)]
3636
Lₙ = L[Block.(1:N),Block.(1:N)]
3737

3838
u = Wₙ * (Lₙ \ (Zₙ \ f))
39-
surface(u)
39+
contourf(u)
4040

4141

4242
# We can also do eigenvalues of the Laplacian
43-
43+
N = 20
4444
Δₙ = Δ[Block.(1:N),Block.(1:N)]
4545
Sₙ = S[Block.(1:N),Block.(1:N)]
4646

47-
BandedMatrix(Δₙ)
48-
4947
λ,Q = eigen(Symmetric(Matrix(Δₙ)), Symmetric(Matrix(Sₙ)))
5048

51-
surface(Wₙ * Q[:,end])
49+
contourf(Wₙ * Q[:,end-10])

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import Base: axes, in, ==, *, ^, \, copy, OneTo, getindex, size, oneto, all, res
1010
import DomainSets: boundary
1111

1212
import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle
13-
import ContinuumArrays: @simplify, Weight, grid, plotgrid, TransformFactorization, ExpansionLayout
13+
import ContinuumArrays: @simplify, Weight, weight, grid, plotgrid, TransformFactorization, ExpansionLayout, plotvalues, unweighted
1414

1515
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize
16-
import BlockArrays: block, blockindex, BlockSlice, viewblock
16+
import BlockArrays: block, blockindex, BlockSlice, viewblock, blockcolsupport
1717
import BlockBandedMatrices: _BandedBlockBandedMatrix, AbstractBandedBlockBandedMatrix, _BandedMatrix, blockbandwidths, subblockbandwidths
1818
import LinearAlgebra: factorize
1919
import LazyArrays: arguments, paddeddata, LazyArrayStyle, LazyLayout

src/disk.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ function plotgrid(S::SubQuasiArray{<:Any,2,<:Zernike})
286286
plotgrid(Z[kr,Block.(OneTo(Int(findblock(axes(Z,2),maximum(jr)))))])
287287
end
288288

289+
290+
function plotvalues(u::ApplyQuasiVector{T,typeof(*),<:Tuple{Zernike, AbstractVector}}, x) where T
291+
Z,c = u.args
292+
CS = blockcolsupport(c)
293+
N = Int(last(CS)) ÷ 2 + 1 # polynomial degree
294+
F = ZernikeITransform{T}(2N, Z.a, Z.b)
295+
C = F * c[Block.(OneTo(2N))] # transform to grid
296+
[permutedims(u[x[1,:]]); # evaluate on edge of disk
297+
C C[:,1];
298+
fill(u[x[end,1]], 1, size(x,2))] # evaluate at origin and repeat
299+
end
300+
301+
function plotvalues(u::ApplyQuasiVector{T,typeof(*),<:Tuple{Weighted{<:Any,<:Zernike}, AbstractVector}}, x) where T
302+
U = plotvalues(unweighted(u), x)
303+
w = weight(u.args[1])
304+
w[x] .* U
305+
end
306+
289307
struct ZernikeTransform{T} <: Plan{T}
290308
N::Int
291309
disk2cxf::FastTransforms.FTPlan{T,2,FastTransforms.DISK}

test/test_disk.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,13 @@ import ForwardDiff: hessian
311311
u = Z * [1; 2; zeros(∞)];
312312
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), u)
313313
g = MultivariateOrthogonalPolynomials.plotgrid(Z[:,1:3])
314-
@test rep[1].args == (first.(g),last.(g),u[g])
314+
@test all(rep[1].args .≈ (first.(g),last.(g),u[g]))
315+
316+
W = Weighted(Zernike(1))
317+
u = W * [1; 2; zeros(∞)];
318+
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), u)
319+
g = MultivariateOrthogonalPolynomials.plotgrid(W[:,1:3])
320+
@test all(rep[1].args .≈ (first.(g),last.(g),u[g]))
315321
end
316322
end
317323

0 commit comments

Comments
 (0)