Skip to content

Commit 9626407

Browse files
committed
Redefine zernikez
1 parent 01fae2f commit 9626407

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using QuasiArrays: AbstractVector
44
using ClassicalOrthogonalPolynomials, FastTransforms, BlockBandedMatrices, BlockArrays, DomainSets,
55
QuasiArrays, StaticArrays, ContinuumArrays, InfiniteArrays, InfiniteLinearAlgebra,
66
LazyArrays, SpecialFunctions, LinearAlgebra, BandedMatrices, LazyBandedMatrices, ArrayLayouts,
7-
HarmonicOrthogonalPolynomials, RecurrenceRelationships
7+
HarmonicOrthogonalPolynomials, RecurrenceRelationships, FillArrays
88

99
import Base: axes, in, ==, +, -, /, *, ^, \, copy, copyto!, OneTo, getindex, size, oneto, all, resize!, BroadcastStyle, similar, fill!, setindex!, convert, show, summary, diff
1010
import Base.Broadcast: Broadcasted, broadcasted, DefaultArrayStyle
@@ -14,6 +14,7 @@ import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle, domain
1414
import ContinuumArrays: @simplify, Weight, weight, grid, plotgrid, TransformFactorization, ExpansionLayout, plotvalues, unweighted, plan_transform, checkpoints, transform_ldiv, AbstractBasisLayout, basis_axes, Inclusion, grammatrix, weaklaplacian, layout_broadcasted, laplacian, abslaplacian, laplacian_axis, abslaplacian_axis, diff_layout, operatororder, broadcastbasis
1515

1616
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize
17+
import FillArrays: SquareEye
1718
import BlockArrays: block, blockindex, BlockSlice, viewblock, blockcolsupport, AbstractBlockStyle, BlockStyle
1819
import BlockBandedMatrices: _BandedBlockBandedMatrix, AbstractBandedBlockBandedMatrix, _BandedMatrix, blockbandwidths, subblockbandwidths
1920
import LinearAlgebra: factorize

src/disk.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ summary(io::IO, P::Zernike) = print(io, "Zernike($(P.a), $(P.b))")
6868

6969
orthogonalityweight(Z::Zernike) = ZernikeWeight(Z.a, Z.b)
7070

71-
zerniker(ℓ, m, a, b, r::T) where T = sqrt(convert(T,2)^(m+a+b+2-iszero(m))/π) * r^m * normalizedjacobip((ℓ-m) ÷ 2, b, m+a, 2r^2-1)
71+
zerniker(ℓ, m, a, b, r::T) where T = sqrt(convert(T,2)^(m+a+b+2-iszero(m))/π) * r^m * normalizedjacobip(, b, m+a, 2r^2-1)
7272
zerniker(ℓ, m, b, r) = zerniker(ℓ, m, zero(b), b, r)
7373
zerniker(ℓ, m, r) = zerniker(ℓ, m, zero(r), r)
7474

@@ -86,14 +86,15 @@ function getindex(Z::Zernike{T}, rθ::RadialCoordinate, B::BlockIndex{1}) where
8686
= Int(block(B))-1
8787
k = blockindex(B)
8888
m = iseven(ℓ) ? k-isodd(k) : k-iseven(k)
89-
zernikez(, (isodd(k+ℓ) ? 1 : -1) * m, Z.a, Z.b, rθ)
89+
zernikez((ℓ-m) ÷ 2, (isodd(k+ℓ) ? 1 : -1) * m, Z.a, Z.b, rθ)
9090
end
9191

9292

9393
getindex(Z::Zernike, xy::StaticVector{2}, B::BlockIndex{1}) = Z[RadialCoordinate(xy), B]
9494
getindex(Z::Zernike, xy::StaticVector{2}, B::Block{1}) = [Z[xy, B[j]] for j=1:Int(B)]
9595
getindex(Z::Zernike, xy::StaticVector{2}, JR::BlockOneTo) = mortar([Z[xy,Block(J)] for J = 1:Int(JR[end])])
9696

97+
basis_axes(::Inclusion{<:Any,<:UnitDisk}, v) = Zernike()
9798

9899
###
99100
# Jacobi matrices
@@ -192,6 +193,11 @@ end
192193
# Transforms
193194
###
194195

196+
function grammatrix(Z::Zernike{T}) where T
197+
@assert Z.a == Z.b == 0
198+
SquareEye{T}((axes(Z,2),))
199+
end
200+
195201
function grid(S::Zernike{T}, B::Block{1}) where T
196202
N = Int(B) ÷ 2 + 1 # matrix rows
197203
M = 4N-3 # matrix columns

test/test_diskvector.jl

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using MultivariateOrthogonalPolynomials, Test, ForwardDiff
1+
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, Test, ForwardDiff, StaticArrays
22
using ForwardDiff: gradient
33

44

55
k = 0; m = 0; n = 2
66

7-
Z_x = 𝐱 -> gradient(𝐱 -> zernikez(n,m,𝐱), 𝐱)[1]
8-
Z_y = 𝐱 -> gradient(𝐱 -> zernikez(n,m,𝐱), 𝐱)[2]
7+
Z_x = (n,m) -> (𝐱 -> gradient(𝐱 -> zernikez(n,m,𝐱), 𝐱)[1])
8+
Z_y = (n,m) -> (𝐱 -> gradient(𝐱 -> zernikez(n,m,𝐱), 𝐱)[2])
99

1010

1111
𝐱 = SVector(0.1,0.2)
@@ -21,5 +21,49 @@ r^m * cos(m*θ) * jacobip(n,k, m,z) / sqrt(W(n,k,m) / 2^(2+k+m))
2121

2222
sqrt(π) * zernikez(n,m,𝐱)
2323

24-
@time expand(Zernike(), Z_x)
24+
@time expand(Zernike(), Z_x(3,2))
2525

26+
# vector OPs
27+
o = expand(Zernike(), _ -> 1)
28+
29+
v = [[o,0*o], [0*o,o]]
30+
ip = (v,w) -> dot(v[1],w[1]) + dot(v[2],w[2])
31+
ip(v[1],v[2])
32+
33+
expand(Zernike(), Z_x(3,2))
34+
35+
36+
W_x = (n,m) -> (𝐱 -> gradient(𝐱 -> (1-norm(𝐱)^2)*zernikez(n,m,1,𝐱), 𝐱)[1])
37+
W_y = (n,m) -> (𝐱 -> gradient(𝐱 -> (1-norm(𝐱)^2)*zernikez(n,m,1,𝐱), 𝐱)[2])
38+
39+
∇W = (n,m) -> [expand(Zernike(), W_x(n,m)),expand(Zernike(), W_y(n,m))]
40+
41+
ip(∇W(2,3), [expand(Zernike(), splat((x,y) -> 1+x+y+x^2+x*y+y^2+x^3+x^2*y+x*y^2+y^3)),expand(Zernike(), splat((x,y) -> 1+x+y+x^2+x*y+y^2+x^3+x^2*y+x*y^2+y^3))])
42+
43+
ip(,[expand(Zernike(), W_x(3,2)),expand(Zernike(), W_y(3,2))])
44+
45+
w = [expand(Zernike(), splat((x,y)->1-y^2)) expand(Zernike(), splat((x,y)->x*y)); expand(Zernike(), splat((x,y)->x*y)) expand(Zernike(), splat((x,y)->1-x^2))]
46+
47+
wiW1 = (n,m) -> expand(Zernike()[:,Block.(1:20)], splat((x,y) -> [1-x^2,-x*y]' * gradient(𝐱 -> (1-norm(𝐱)^2)*zernikez(n,m,1,𝐱), SVector(x,y))/(1-x^2-y^2)))
48+
wiW2 = (n,m) -> expand(Zernike()[:,Block.(1:20)], splat((x,y) -> [-x*y,1-y^2]' * gradient(𝐱 -> (1-norm(𝐱)^2)*zernikez(n,m,1,𝐱), SVector(x,y))/(1-x^2-y^2)))
49+
50+
[wiW1(3,4),wiW2(3,4)], [expand(Zernike(), splat((x,y) -> 1+x+y+x^2+x*y+y^2+x^3+x^2*y+x*y^2+y^3)),expand(Zernike(), splat((x,y) -> 1+x+y+x^2+x*y+y^2+x^3+x^2*y+x*y^2+y^3))]
51+
52+
v = [wiW1(3,4),wiW2(3,4)]
53+
[ip(v, ∇W(n,m)) for n=0:5, m=0:5]
54+
dot(∇W(0,6)[1], ∇W(4,6)[1])
55+
dot(∇W(0,6)[2], ∇W(4,6)[2])
56+
57+
58+
∇W(0,6)[1][SVector(0.1,0.2)]
59+
gradient(𝐱 -> (1-norm(𝐱)^2)*zernikez(0,6,1,𝐱), SVector(0.1,0.2))
60+
ip(∇W(8,4), ∇W(9,4))
61+
[ip(∇W(8,4), ∇W(n,m)) for n=0:10, m=0:6]
62+
v = [wiW1(3,4),wiW2(3,4)]
63+
[ip(v, ∇W(n,m)) for n=0:10, m=0:6]
64+
65+
zernikez(4,6,1,0.1*SVector(cos(0.2),sin(0.2)))
66+
v[1][SVector(0.1,0.2)]
67+
68+
(1-x^2) *P^(1,1) * (1-x^2) *P^(1,1)
69+
(𝐱 -> (1-norm(𝐱)^2)*zernikez(3,4,1,𝐱))(0.1*SVector(cos(0.2),sin(0.2)))

0 commit comments

Comments
 (0)