Skip to content

Commit cb0fb24

Browse files
authored
work on grid for Zernike (#135)
* work on grid for Zernike * tests pass
1 parent 308f7dd commit cb0fb24

File tree

6 files changed

+32
-42
lines changed

6 files changed

+32
-42
lines changed

Project.toml

Lines changed: 4 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.4"
3+
version = "0.4.1"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -28,12 +28,12 @@ ArrayLayouts = "0.8.6"
2828
BandedMatrices = "0.17"
2929
BlockArrays = "0.16.14"
3030
BlockBandedMatrices = "0.11.5"
31-
ClassicalOrthogonalPolynomials = "0.6.9"
32-
ContinuumArrays = "0.11"
31+
ClassicalOrthogonalPolynomials = "0.7"
32+
ContinuumArrays = "0.12"
3333
DomainSets = "0.5, 0.6"
3434
FastTransforms = "0.14"
3535
FillArrays = "0.13"
36-
HarmonicOrthogonalPolynomials = "0.3"
36+
HarmonicOrthogonalPolynomials = "0.4"
3737
InfiniteArrays = "0.12"
3838
InfiniteLinearAlgebra = "0.6.6"
3939
LazyArrays = "0.22.10"

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import InfiniteArrays: InfiniteCardinal, OneToInf
2424
import ClassicalOrthogonalPolynomials: jacobimatrix, Weighted, orthogonalityweight, HalfWeighted, WeightedBasis, pad, recurrencecoefficients, clenshaw
2525
import HarmonicOrthogonalPolynomials: BivariateOrthogonalPolynomial, MultivariateOrthogonalPolynomial, Plan,
2626
PartialDerivative, AngularMomentum, BlockOneTo, BlockRange1, interlace,
27-
MultivariateOPLayout
27+
MultivariateOPLayout, MAX_PLOT_BLOCKS
2828

2929
export MultivariateOrthogonalPolynomial, BivariateOrthogonalPolynomial,
3030
UnitTriangle, UnitDisk,

src/disk.jl

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,9 @@ end
191191
# Transforms
192192
###
193193

194-
const FiniteZernike{T} = SubQuasiArray{T,2,Zernike{T},<:Tuple{<:Inclusion,<:BlockSlice{BlockRange1{OneTo{Int}}}}}
195-
196-
function grid(S::FiniteZernike{T}) where T
197-
N = blocksize(S,2) ÷ 2 + 1 # polynomial degree
198-
M = 4N-3
194+
function grid(S::Zernike{T}, B::Block{1}) where T
195+
N = Int(B) ÷ 2 + 1 # matrix rows
196+
M = 4N-3 # matrix columns
199197

200198
r = sinpi.((N .-(0:N-1) .- one(T)/2) ./ (2N))
201199

@@ -206,26 +204,21 @@ end
206204

207205
_angle(rθ::RadialCoordinate) =.θ
208206

209-
function plotgrid(S::FiniteZernike{T}) where T
210-
N = blocksize(S,2) ÷ 2 + 1 # polynomial degree
211-
g = grid(parent(S)[:,Block.(OneTo(2N))]) # double sampling
207+
function plotgrid(S::Zernike{T}, B::Block{1}) where T
208+
N = Int(B) ÷ 2 + 1 # polynomial degree
209+
g = grid(S, Block(min(2N, MAX_PLOT_BLOCKS))) # double sampling
212210
θ = [map(_angle,g[1,:]); 0]
213-
[permutedims(RadialCoordinate.(1,θ)); g g[:,1]; permutedims(RadialCoordinate.(0,θ))]
214-
end
215-
216-
function plotgrid(S::SubQuasiArray{<:Any,2,<:Zernike})
217-
kr,jr = parentindices(S)
218-
Z = parent(S)
219-
plotgrid(Z[kr,Block.(OneTo(Int(findblock(axes(Z,2),maximum(jr)))))])
211+
[permutedims(RadialCoordinate.(1,θ));
212+
g g[:,1];
213+
permutedims(RadialCoordinate.(0,θ))]
220214
end
221215

222-
223216
function plotvalues(u::ApplyQuasiVector{T,typeof(*),<:Tuple{Zernike, AbstractVector}}, x) where T
224217
Z,c = u.args
225-
CS = blockcolsupport(c)
226-
N = Int(last(CS)) ÷ 2 + 1 # polynomial degree
227-
F = ZernikeITransform{T}(2N, Z.a, Z.b)
228-
C = F * c[Block.(OneTo(2N))] # transform to grid
218+
B = findblock(axes(Z,2), last(colsupport(c)))
219+
N = Int(B) ÷ 2 + 1 # polynomial degree
220+
F = ZernikeITransform{T}(min(2N, MAX_PLOT_BLOCKS), Z.a, Z.b)
221+
C = F * c[Block.(OneTo(min(2N, MAX_PLOT_BLOCKS)))] # transform to grid
229222
[permutedims(u[x[1,:]]); # evaluate on edge of disk
230223
C C[:,1];
231224
fill(u[x[end,1]], 1, size(x,2))] # evaluate at origin and repeat
@@ -262,8 +255,11 @@ end
262255
*(P::ZernikeTransform{T}, f::Matrix{T}) where T = ModalTrav(P.disk2cxf \ (P.analysis * f))
263256
*(P::ZernikeITransform, f::AbstractVector) = P.synthesis * (P.disk2cxf * ModalTrav(f).matrix)
264257

265-
factorize(S::FiniteZernike{T}) where T = TransformFactorization(grid(S), ZernikeTransform{T}(blocksize(S,2), parent(S).a, parent(S).b))
258+
plan_grid_transform(Z::Zernike{T}, B::Tuple{Block{1}}, dims=1:1) where T = grid(Z,B[1]), ZernikeTransform{T}(Int(B[1]), Z.a, Z.b)
266259

260+
##
261+
# Laplacian
262+
###
267263

268264
@simplify function *::Laplacian, WZ::Weighted{<:Any,<:Zernike})
269265
@assert WZ.P.a == 0 && WZ.P.b == 1

src/rect.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ function checkpoints(P::RectPolynomial)
5959
SVector.(x, y')
6060
end
6161

62-
function plan_grid_transform(P::KronPolynomial{d,<:Any,<:Fill}, B, dims=1:ndims(B)) where d
62+
function plan_grid_transform(P::KronPolynomial{d,<:Any,<:Fill}, B::Tuple{Block{1}}, dims=1:1) where d
6363
@assert dims == 1
6464

6565
T = first(P.args)
66-
x, F = plan_grid_transform(T, Array{eltype(B)}(undef, Fill(blocksize(B,1),d)...))
66+
x, F = plan_grid_transform(T, Array{eltype(P)}(undef, Fill(Int(B[1]),d)...))
6767
@assert d == 2
6868
= Vector(x)
6969
SVector.(x̃, x̃'), ApplyPlan(DiagTrav, F)

src/triangle.jl

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -637,19 +637,13 @@ function tridenormalize!(F̌,a,b,c)
637637
638638
end
639639

640-
function _trigrid(N::Integer)
640+
function trigrid(N::Integer)
641641
M = N
642642
x = [sinpi((2N-2n-1)/(4N))^2 for n in 0:N-1]
643643
w = [sinpi((2M-2m-1)/(4M))^2 for m in 0:M-1]
644644
[SVector(x[n+1], x[N-n]*w[m+1]) for n in 0:N-1, m in 0:M-1]
645-
end
646-
trigrid(N::Block{1}) = _trigrid(Int(N))
647-
648-
649-
function grid(Pn::SubQuasiArray{T,2,<:JacobiTriangle,<:Tuple{Inclusion,BlockSlice{<:BlockRange{1}}}}) where T
650-
kr,jr = parentindices(Pn)
651-
trigrid(maximum(jr.block))
652-
end
645+
end
646+
grid(P::JacobiTriangle, B::Block{1}) = trigrid(Int(B))
653647

654648
struct TriPlan{T}
655649
tri2cheb::FastTransforms.FTPlan{T,2,FastTransforms.TRIANGLE}
@@ -666,8 +660,8 @@ TriPlan{T}(N::Block{1}, a, b, c) where T = TriPlan{T}(Matrix{T}(undef, Int(N), I
666660

667661
*(T::TriPlan, F::AbstractMatrix) = DiagTrav(tridenormalize!(T.tri2cheb\(T.grid2cheb*F),T.a,T.b,T.c))
668662

669-
function plan_grid_transform(P::JacobiTriangle, arr::AbstractVector, dims=1:ndims(arr))
670-
T = promote_type(eltype(P), eltype(arr))
671-
N = findblock(axes(P,2), length(arr))
672-
grid(P[:,Block.(OneTo(Int(N)))]), TriPlan{T}(N, P.a, P.b, P.c)
663+
function plan_grid_transform(P::JacobiTriangle, Bs::Tuple{Block{1}}, dims=1:1)
664+
T = eltype(P)
665+
N = Bs[1]
666+
grid(P, N), TriPlan{T}(N, P.a, P.b, P.c)
673667
end

test/test_disk.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ import ForwardDiff: hessian
309309
@testset "plotting" begin
310310
Z = Zernike()
311311
u = Z * [1; 2; zeros(∞)];
312-
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), u)
312+
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), u);
313313
g = MultivariateOrthogonalPolynomials.plotgrid(Z[:,1:3])
314314
@test all(rep[1].args .≈ (first.(g),last.(g),u[g]))
315315

0 commit comments

Comments
 (0)