Skip to content

Commit fb2482b

Browse files
authored
Grammatrix fore Triangles, Makie experiments (#160)
* Update Makie code * Update MultivariateOrthogonalPolynomialsMakieExt.jl * tricontourf * Add Triangle * plotvalues no grid * Update Project.toml * Add grammatrix and Conjugate matrix * Update Project.toml * Update Project.toml * B -> Q in Conjugate * Update test_triangle.jl * Update Project.toml * Update Project.toml * Increase coverage * increase coverage * Update test_triangle.jl
1 parent 260b154 commit fb2482b

File tree

5 files changed

+464
-27
lines changed

5 files changed

+464
-27
lines changed

Project.toml

Lines changed: 8 additions & 8 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.5.1"
3+
version = "0.6"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -27,18 +27,18 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2727
ArrayLayouts = "1.0.9"
2828
BandedMatrices = "0.17.30"
2929
BlockArrays = "0.16.14"
30-
BlockBandedMatrices = "0.12"
31-
ClassicalOrthogonalPolynomials = "0.10, 0.11"
32-
ContinuumArrays = "0.13, 0.14"
30+
BlockBandedMatrices = "0.12.5"
31+
ClassicalOrthogonalPolynomials = "0.11"
32+
ContinuumArrays = "0.15"
3333
DomainSets = "0.6"
3434
FastTransforms = "0.15"
3535
FillArrays = "1.0"
36-
HarmonicOrthogonalPolynomials = "0.4"
36+
HarmonicOrthogonalPolynomials = "0.5"
3737
InfiniteArrays = "0.12, 0.13"
38-
InfiniteLinearAlgebra = "0.6.6"
38+
InfiniteLinearAlgebra = "0.7"
3939
LazyArrays = "1.0"
40-
LazyBandedMatrices = "0.8.4"
41-
QuasiArrays = "0.10, 0.11"
40+
LazyBandedMatrices = "0.9"
41+
QuasiArrays = "0.11"
4242
SpecialFunctions = "1, 2"
4343
StaticArrays = "1"
4444
julia = "1.9"

examples/makieplotting.jl

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
# module MultivariateOrthogonalPolynomialsMakieExt
2+
3+
using GLMakie
4+
using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays
5+
import Makie: mesh, mesh!
6+
using ContinuumArrays: plotgridvalues
7+
8+
export contourf, contourf
9+
10+
contourf(f::Fun; kwds...) = _mesh(meshdata(f)...; shading=false, kwds...)
11+
contourf!(s, f::Fun; kwds...) = _mesh!(s, meshdata(f)...; shading=false, kwds...)
12+
13+
14+
function _mesh(p, T, v; resolution=(400,400), kwds...)
15+
T_mat = Array{Int}(undef, length(T), 3)
16+
for k = 1:length(T)
17+
T_mat[k,:] .= T[k]
18+
end
19+
s = Scene(resolution=resolution)
20+
mesh!(s, [first.(p) last.(p)], T_mat; color=v, kwds...)
21+
end
22+
23+
24+
function _surface(p, T, v; resolution=(400,400), kwds...)
25+
T_mat = Array{Int}(undef, length(T), 3)
26+
for k = 1:length(T)
27+
T_mat[k,:] .= T[k]
28+
end
29+
# s = Scene(resolution=resolution)
30+
mesh(first.(p), last.(p), vec(v), T_mat; kwds...)
31+
end
32+
33+
34+
35+
function _mesh!(s, p, T, v; kwds...)
36+
T_mat = Array{Int}(undef, length(T), 3)
37+
for k = 1:length(T)
38+
T_mat[k,:] .= T[k]
39+
end
40+
mesh!(s, [first.(p) last.(p)], T_mat; color=v, kwds...)
41+
end
42+
43+
function meshdata(f::Fun{<:PiecewiseSpace})
44+
pTv = MultivariateTriangle.meshdata.(components(f))
45+
p = vcat(first.(pTv)...)
46+
T = pTv[1][2]
47+
cs = length(pTv[1][1])
48+
for k = 2:length(pTv)
49+
append!(T, (t -> (cs.+t)).(pTv[k][2]))
50+
cs += length(pTv[k][1])
51+
end
52+
53+
v = vcat(last.(pTv)...)
54+
55+
p, T, v
56+
end
57+
58+
function meshdata(f::Fun{<:TensorSpace{<:Tuple{<:Chebyshev,<:Chebyshev}}})
59+
p = points(f)
60+
v = values(f)
61+
n = length(p)
62+
T = Vector{NTuple{3,Int}}()
63+
d_x,d_y = factors(domain(f))
64+
a_x,b_x = endpoints(d_x)
65+
a_y,b_y = endpoints(d_y)
66+
if iseven(_padua_length(n))
67+
l = floor(Int, (1+sqrt(1+8n))/4)
68+
69+
push!(p, Vec(b_x,b_y))
70+
push!(p, Vec(a_x,b_y))
71+
72+
push!(v, f(b_x,b_y))
73+
push!(v, f(a_x,b_y))
74+
75+
for p = 0:l-2
76+
for k = (2p*l)+1:(2p*l)+l-1
77+
push!(T, (k+1, k, l+k+1))
78+
end
79+
for k = (2p*l)+1:(2p*l)+l-1
80+
push!(T, (k, l+k, l+k+1))
81+
end
82+
for k = (2p*l)+l+1:(2p*l)+2l-1
83+
push!(T, (k+1, k, l+k))
84+
end
85+
for k = (2p*l)+l+2:(2p*l)+2l
86+
push!(T, (k, k+l-1, l+k))
87+
end
88+
end
89+
for p=0:l-3
90+
push!(T, ((2p+1)*l+1, (2p+2)*l+1, (2p+3)*l+1))
91+
end
92+
for p =0:l-2
93+
push!(T, ((2p+1)*l, (2p+2)*l, (2p+3)*l))
94+
end
95+
push!(T, (1, n+1, l+1))
96+
push!(T, (n-2l+1, n+2, n-l+1))
97+
else
98+
l = floor(Int, (3+sqrt(1+8n))/4)
99+
100+
push!(p, Vec(a_x,b_y))
101+
push!(p, Vec(a_x,a_y))
102+
103+
push!(v, f(a_x,b_y))
104+
push!(v, f(a_x,a_y))
105+
106+
for p = 0:l-2
107+
for k = p*(2l-1)+1:p*(2l-1)+l-1
108+
push!(T, (k+1, k, l+k))
109+
end
110+
for k = p*(2l-1)+1:p*(2l-1)+l-2
111+
push!(T, (k+1, l+k, l+k+1))
112+
end
113+
end
114+
for p = 0:l-3
115+
for k = p*(2l-1)+l+1:p*(2l-1)+2l-2
116+
push!(T, (k+1, k, l+k))
117+
end
118+
for k = p*(2l-1)+l+1:p*(2l-1)+2l-1
119+
push!(T, (k, k+l-1, l+k))
120+
end
121+
end
122+
123+
for p=0:l-3
124+
push!(T, (p*(2l-1) + 1, p*(2l-1) + l+1, p*(2l-1) + 2l))
125+
end
126+
127+
for p=0:l-3
128+
push!(T, (p*(2l-1) + l, p*(2l-1) + 2l-1, p*(2l-1) + 3l-1))
129+
end
130+
131+
push!(T, (n-2l+2, n+1, n-l+2))
132+
push!(T, (n-l+1, n+2, n))
133+
end
134+
135+
p, T, v
136+
end
137+
138+
139+
140+
meshdata(f) =
141+
triangle_meshdata(points(f), values(f), (domain(f).a, domain(f).b, domain(f).c),
142+
f.((domain(f).a, domain(f).b, domain(f).c)))
143+
144+
function triangle_meshdata(p, v, (a, b, c), (fa, fb, fc))
145+
n = length(p)
146+
T = Vector{NTuple{3,Int}}()
147+
148+
149+
if iseven(_padua_length(n))
150+
l = floor(Int, (1+sqrt(1+8n))/4)
151+
152+
push!(p, b)
153+
push!(p, c)
154+
155+
push!(v, fb)
156+
push!(v, fc)
157+
158+
for p = 0:l-2
159+
for k = (2p*l)+1:(2p*l)+l-1
160+
push!(T, (k+1, k, l+k+1))
161+
end
162+
for k = (2p*l)+1:(2p*l)+l-1
163+
push!(T, (k, l+k, l+k+1))
164+
end
165+
for k = (2p*l)+l+1:(2p*l)+2l-1
166+
push!(T, (k+1, k, l+k))
167+
end
168+
for k = (2p*l)+l+2:(2p*l)+2l
169+
push!(T, (k, k+l-1, l+k))
170+
end
171+
end
172+
for p=0:l-3
173+
push!(T, ((2p+1)*l+1, (2p+2)*l+1, (2p+3)*l+1))
174+
end
175+
for p =0:l-2
176+
push!(T, ((2p+1)*l, (2p+2)*l, (2p+3)*l))
177+
end
178+
push!(T, (1, n+1, l+1))
179+
push!(T, (n-2l+1, n+2, n-l+1))
180+
else
181+
l = floor(Int, (3+sqrt(1+8n))/4)
182+
183+
push!(p, Vec(c))
184+
push!(p, Vec(a))
185+
186+
push!(v, fc)
187+
push!(v, fa)
188+
189+
for p = 0:l-2
190+
for k = p*(2l-1)+1:p*(2l-1)+l-1
191+
push!(T, (k+1, k, l+k))
192+
end
193+
for k = p*(2l-1)+1:p*(2l-1)+l-2
194+
push!(T, (k+1, l+k, l+k+1))
195+
end
196+
end
197+
for p = 0:l-3
198+
for k = p*(2l-1)+l+1:p*(2l-1)+2l-2
199+
push!(T, (k+1, k, l+k))
200+
end
201+
for k = p*(2l-1)+l+1:p*(2l-1)+2l-1
202+
push!(T, (k, k+l-1, l+k))
203+
end
204+
end
205+
206+
for p=0:l-3
207+
push!(T, (p*(2l-1) + 1, p*(2l-1) + l+1, p*(2l-1) + 2l))
208+
end
209+
210+
for p=0:l-3
211+
push!(T, (p*(2l-1) + l, p*(2l-1) + 2l-1, p*(2l-1) + 3l-1))
212+
end
213+
214+
push!(T, (n-2l+2, n+1, n-l+2))
215+
push!(T, (n-l+1, n+2, n))
216+
end
217+
218+
p, T, v
219+
end
220+
221+
222+
P = JacobiTriangle()
223+
f = expand(P, splat((x,y) -> cos(x*exp(y))))
224+
(a,b,c) = (SVector(0.,0.), SVector(0.,1.), SVector(1.,0.))
225+
xy,F = plotgridvalues(f)
226+
x,y = first.(xy),last.(xy)
227+
228+
229+
230+
triangle_meshdata(plotgridvalues(f)..., (a,b,c), getindex.(Ref(f), (a,b,c)))
231+
232+
233+
tricontourf(vec(x), vec(y), vec(F); levels=100)
234+
235+
using Makie, MultivariateOrthogonalPolynomials
236+
using ContinuumArrays: ApplyQuasiVector, plotgridvalues
237+
# Makie.plottype(a::ApplyQuasiVector{<:Any, typeof(*), <:Tuple{JacobiTriangle,AbstractVector}}) = Tricontourf
238+
239+
240+
function Makie.tricontourf(f::ApplyQuasiVector{<:Any, typeof(*)}; kwds...)
241+
xy,F = plotgridvalues(f)
242+
x,y = first.(xy),last.(xy)
243+
tricontourf(vec(x), vec(y), vec(F); kwds...)
244+
end
245+
246+
function Makie.tricontourf!(f::ApplyQuasiVector{<:Any, typeof(*)}; kwds...)
247+
xy,F = plotgridvalues(f)
248+
x,y = first.(xy),last.(xy)
249+
tricontourf!(vec(x), vec(y), vec(F); kwds...)
250+
end
251+
252+
253+
# f = expand(Weighted(JacobiTriangle(1,1,1))[:,20])
254+
# tricontourf(f; levels=100)
255+
import Base: oneto
256+
KR = Block.(oneto(40))
257+
P = JacobiTriangle()
258+
f = P[:,KR] * (P \ Weighted(JacobiTriangle(1,1,1)))[KR,10]
259+
260+
p = Figure(resolution = (3200, 2400))
261+
ax = Axis(p[1, 1])
262+
tricontourf!(f; levels=100)
263+
save("bubble10.png", p)
264+
265+
266+
using ContinuumArrays: AffineMap, affine
267+
using MultivariateOrthogonalPolynomials
268+
using MultivariateOrthogonalPolynomials: Triangle
269+
using StaticArrays
270+
271+
a = affine(Triangle(), Triangle(SVector(1,0), SVector(0,1), SVector(1,1)))
272+
a[SVector(0.1,0.2)]
273+
274+
P = JacobiTriangle()
275+
Q = P[affine(Triangle(SVector(1,0), SVector(0,1), SVector(1,1)), axes(P,1)), :]
276+
277+
f = Q * [[randn(20); zeros(100)]; zeros(∞)]
278+
279+
tricontourf(f; nlevels=300)
280+
281+
282+
# end # modul

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ using ClassicalOrthogonalPolynomials, FastTransforms, BlockBandedMatrices, Block
66
LazyArrays, SpecialFunctions, LinearAlgebra, BandedMatrices, LazyBandedMatrices, ArrayLayouts,
77
HarmonicOrthogonalPolynomials
88

9-
import Base: axes, in, ==, *, ^, \, copy, copyto!, OneTo, getindex, size, oneto, all, resize!, BroadcastStyle, similar, fill!, setindex!, convert, show, summary
9+
import Base: axes, in, ==, +, -, /, *, ^, \, copy, copyto!, OneTo, getindex, size, oneto, all, resize!, BroadcastStyle, similar, fill!, setindex!, convert, show, summary
1010
import Base.Broadcast: Broadcasted, broadcasted, DefaultArrayStyle
11-
import DomainSets: boundary
11+
import DomainSets: boundary, EuclideanDomain
1212

1313
import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle, domain
14-
import ContinuumArrays: @simplify, Weight, weight, grid, plotgrid, TransformFactorization, ExpansionLayout, plotvalues, unweighted, plan_grid_transform, checkpoints, transform_ldiv, AbstractBasisLayout, basis_axes
14+
import ContinuumArrays: @simplify, Weight, weight, grid, plotgrid, TransformFactorization, ExpansionLayout, plotvalues, unweighted, plan_grid_transform, checkpoints, transform_ldiv, AbstractBasisLayout, basis_axes, Inclusion, grammatrix
1515

1616
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize
1717
import BlockArrays: block, blockindex, BlockSlice, viewblock, blockcolsupport, AbstractBlockStyle, BlockStyle
1818
import BlockBandedMatrices: _BandedBlockBandedMatrix, AbstractBandedBlockBandedMatrix, _BandedMatrix, blockbandwidths, subblockbandwidths
1919
import LinearAlgebra: factorize
20-
import LazyArrays: arguments, paddeddata, LazyArrayStyle, LazyLayout, PaddedLayout, applylayout
21-
import LazyBandedMatrices: LazyBandedBlockBandedLayout, AbstractBandedBlockBandedLayout, AbstractLazyBandedBlockBandedLayout, _krontrav_axes, DiagTravLayout
20+
import LazyArrays: arguments, paddeddata, LazyArrayStyle, LazyLayout, PaddedLayout, applylayout, LazyMatrix, ApplyMatrix
21+
import LazyBandedMatrices: LazyBandedBlockBandedLayout, AbstractBandedBlockBandedLayout, AbstractLazyBandedBlockBandedLayout, _krontrav_axes, DiagTravLayout, invdiagtrav, ApplyBandedBlockBandedLayout
2222
import InfiniteArrays: InfiniteCardinal, OneToInf
2323

2424
import ClassicalOrthogonalPolynomials: jacobimatrix, Weighted, orthogonalityweight, HalfWeighted, WeightedBasis, pad, recurrencecoefficients, clenshaw
@@ -32,7 +32,8 @@ export MultivariateOrthogonalPolynomial, BivariateOrthogonalPolynomial,
3232
DunklXuDisk, DunklXuDiskWeight, WeightedDunklXuDisk,
3333
Zernike, ZernikeWeight, zerniker, zernikez,
3434
PartialDerivative, Laplacian, AbsLaplacianPower, AngularMomentum,
35-
RadialCoordinate, Weighted, Block, jacobimatrix, KronPolynomial, RectPolynomial
35+
RadialCoordinate, Weighted, Block, jacobimatrix, KronPolynomial, RectPolynomial,
36+
grammatrix, oneto
3637

3738
include("ModalInterlace.jl")
3839
include("rect.jl")

0 commit comments

Comments
 (0)