@@ -14,6 +14,9 @@ axes(B::ContinuousPolynomial{0}) = axes(PiecewisePolynomial(B))
1414axes (B:: ContinuousPolynomial{1} ) =
1515 (Inclusion (first (B. points) .. last (B. points)), blockedrange (Vcat (length (B. points), Fill (length (B. points) - 1 , ∞))))
1616
17+ show (io:: IO , Q:: ContinuousPolynomial{λ} ) where λ = summary (io, Q)
18+ summary (io:: IO , Q:: ContinuousPolynomial{λ} ) where λ = print (io, " ContinuousPolynomial{$λ }($(Q. points) )" )
19+
1720== (P:: PiecewisePolynomial , C:: ContinuousPolynomial{0} ) = P == PiecewisePolynomial (C)
1821== (C:: ContinuousPolynomial{0} , P:: PiecewisePolynomial ) = PiecewisePolynomial (C) == P
1922== (:: PiecewisePolynomial , :: ContinuousPolynomial{1} ) = false
@@ -25,6 +28,8 @@ axes(B::ContinuousPolynomial{1}) =
2528
2629getindex (P:: ContinuousPolynomial{0,T} , x:: Number , Kk:: BlockIndex{1} ) where {T} = PiecewisePolynomial (P)[x, Kk]
2730
31+ bubblebasis (:: Type{T} ) where T = Ultraspherical {T} (- one (real (T))/ 2 )
32+
2833function getindex (P:: ContinuousPolynomial{1,T} , x:: Number , Kk:: BlockIndex{1} ) where {T}
2934 K, k = block (Kk), blockindex (Kk)
3035 if K == Block (1 )
@@ -33,7 +38,7 @@ function getindex(P::ContinuousPolynomial{1,T}, x::Number, Kk::BlockIndex{1}) wh
3338 b = searchsortedlast (P. points, x)
3439 if b == k
3540 α, β = convert (T, P. points[b]), convert (T, P. points[b+ 1 ])
36- Weighted ( Jacobi {T} ( 1 , 1 )) [affine (α.. β, ChebyshevInterval {real(T)} ())[x], Int (K)- 1 ]
41+ bubblebasis (T) [affine (α.. β, ChebyshevInterval {real(T)} ())[x], Int (K)+ 1 ]
3742 else
3843 zero (T)
3944 end
6671
6772function plan_transform (C:: ContinuousPolynomial{1,T} , Ns:: NTuple{N,Block{1}} , dims= ntuple (identity,Val (N))) where {N,T}
6873 P = Legendre {T} ()
69- W = Weighted ( Jacobi {T} ( 1 , 1 ) )
74+ W = bubblebasis (T )
7075 # TODO : this is unnecessarily not triangular which makes it much slower than necessary and prevents in-place.
7176 # However, the speed of the Legendre transform will far exceed this so its not high priority.
7277 # Probably using Ultraspherical(-1/2) would be better.
73- R̃ = [[T[1 1 ; - 1 1 ]/ 2 ; Zeros {T} (∞,2 )] (P \ W)]
78+ R̃ = [[T[1 1 ; - 1 1 ]/ 2 ; Zeros {T} (∞,2 )] (P \ W)[:, 3 : end ] ]
7479 ContinuousPolynomialTransform (plan_transform (ContinuousPolynomial {0} (C), Ns .+ 1 , dims). F,
7580 InvPlan (map (N -> R̃[1 : Int (N),1 : Int (N)], Ns .+ 1 ), _doubledims (dims... )),
7681 dims)
@@ -167,11 +172,11 @@ function adaptivetransform_ldiv(Q::ContinuousPolynomial{1,V}, f::AbstractQuasiVe
167172 c̃ = paddeddata (c)
168173 N = max (2 ,div (length (c̃), M, RoundUp)) # degree
169174 P = Legendre {T} ()
170- W = Weighted ( Jacobi {T} ( 1 , 1 ) )
175+ W = bubblebasis (T )
171176
172177 # Restrict hat function to each element, add in bubble functions and compute connection
173178 # matrix to Legendre. [1 1; -1 1]/2 are the Legendre coefficients of the hat functions.
174- R̃ = [[T[1 1 ; - 1 1 ]/ 2 ; Zeros {T} (∞,2 )] (P \ W)]
179+ R̃ = [[T[1 1 ; - 1 1 ]/ 2 ; Zeros {T} (∞,2 )] (P \ W)[:, 3 : end ] ]
175180
176181 # convert from Legendre to piecewise restricted hat + Bubble
177182 dat = R̃[1 : N,1 : N] \ reshape (pad (c̃, M* N), M, N)'
@@ -200,7 +205,7 @@ grid(P::ContinuousPolynomial{1}, M::Block{1}) = grid(ContinuousPolynomial{0}(P),
200205function \ (P:: ContinuousPolynomial{0} , C:: ContinuousPolynomial{1} )
201206 T = promote_type (eltype (P), eltype (C))
202207 @assert P. points == C. points
203- v = ( convert (T, 2 ) : 2 : ∞ ) ./ (3 : 2 : ∞)
208+ v = one (T ) ./ (3 : 2 : ∞)
204209 N = length (P. points)
205210 ArrowheadMatrix (_BandedMatrix (Ones {T} (2 , N)/ 2 , oneto (N- 1 ), 0 , 1 ),
206211 (_BandedMatrix (Fill (v[1 ], 1 , N- 1 ), oneto (N- 1 ), 0 , 0 ),),
@@ -234,15 +239,15 @@ function grammatrix(C::ContinuousPolynomial{1, T, <:AbstractRange}) where T
234239
235240 N = length (r) - 1
236241 h = step (r) # 2/N
237- a = (( convert (T, 4 ) : 4 : ∞) .* ( convert (T, - 2 ) : 2 : ∞)) ./ (( 1 : 2 : ∞) .* ( 3 : 2 : ∞) .* ( - 1 : 2 : ∞))
238- b = ((( convert (T, 2 ) : 2 : ∞) ./ ( 3 : 2 : ∞)) . ^ 2 .* ( convert (T, 2 ) ./ ( 1 : 2 : ∞) .+ convert (T, 2 ) ./ ( 5 : 2 : ∞)))
242+ a = [ - 2 / (( 2 k + 1 ) * ( 2 k + 3 ) * ( 2 k + 5 )) for k = - 1 : ∞]
243+ b = [ 4 / (( 2 k + 1 ) * ( 2 k + 3 ) * ( 2 k + 5 )) for k = 0 : ∞]
239244
240245 a11 = LazyBandedMatrices. Bidiagonal (Vcat (h/ 3 , Fill (2 h/ 3 , N- 1 ), h/ 3 ), Fill (h/ 6 , N), :U )
241- a21 = _BandedMatrix (Fill (h/ 3 , 2 , N), N+ 1 , 1 , 0 )
242- a31 = _BandedMatrix (Vcat (Fill (- 2 h / 15 , 1 , N), Fill (2 h / 15 , 1 , N)), N+ 1 , 1 , 0 )
246+ a21 = _BandedMatrix (Fill (h/ 6 , 2 , N), N+ 1 , 1 , 0 )
247+ a31 = _BandedMatrix (Vcat (Fill (- h / 30 , 1 , N), Fill (h / 30 , 1 , N)), N+ 1 , 1 , 0 )
243248
244249 Symmetric (ArrowheadMatrix (a11, (a21, a31), (),
245- Fill (_BandedMatrix (Vcat ((- h* a/ 2 )' ,
250+ Fill (_BandedMatrix (Vcat ((h* a/ 2 )' ,
246251 Zeros {T} (1 ,∞),
247252 (h* b/ 2 )' ), ∞, 0 , 2 ), N)))
248253end
@@ -278,12 +283,17 @@ function diff(C::ContinuousPolynomial{1,T}; dims=1) where T
278283 r = C. points
279284 N = length (r)
280285 s = one (T) ./ (r[2 : end ]- r[1 : end - 1 ])
281- v = mortar (Fill (T (2 ) * s, ∞)) .* mortar (Fill .((- convert (T, 2 ): - 2 : - ∞), N - 1 ))
282- z = Zeros {T} (axes (v))
283- H = BlockBroadcastArray (hcat, z, v)
284- M = BlockVcat (Hcat (Ones {T} (N) .* [zero (T); s] , - Ones {T} (N) .* [s; zero (T)] ), H)
285- P = ContinuousPolynomial {0} (C)
286- ApplyQuasiMatrix (* , P, _BandedBlockBandedMatrix (M' , axes (P, 2 ), (0 , 0 ), (0 , 1 )))
286+ ContinuousPolynomial {0} (r) * ArrowheadMatrix (_BandedMatrix (Vcat ([0 ; s]' , [- s; 0 ]' ), length (s), 0 , 1 ), (), (),
287+ (- 2 s) .* Ref (Eye {T} (∞)))
288+ end
289+
290+ function diff (C:: ContinuousPolynomial{1,T,<:AbstractRange} ; dims= 1 ) where T
291+ # Legendre() \ (D*Weighted(Jacobi(1,1)))
292+ r = C. points
293+ N = length (r)
294+ s = 1 ./ step (r)
295+ ContinuousPolynomial {0} (r) * ArrowheadMatrix (_BandedMatrix (Vcat (Fill (s, 1 , N), Fill (- s, 1 , N)), N- 1 , 0 , 1 ), (), (),
296+ Fill (- 2 s* Eye {T} (∞), N- 1 ))
287297end
288298
289299function weaklaplacian (C:: ContinuousPolynomial{1,T,<:AbstractRange} ) where T
@@ -294,7 +304,7 @@ function weaklaplacian(C::ContinuousPolynomial{1,T,<:AbstractRange}) where T
294304 t1 = Vcat (- si, Fill (- 2 si, N- 2 ), - si)
295305 t2 = Fill (si, N- 1 )
296306 Symmetric (ArrowheadMatrix (LazyBandedMatrices. Bidiagonal (t1, t2, :U ), (), (),
297- Fill (Diagonal (convert (T, - 16 ) .* ( 1 : ∞) .^ 2 . / (s .* (( 2 : 2 : ∞) .+ 1 ))), N- 1 )))
307+ Fill (Diagonal (convert (T,- 4 ) ./ (s* ( convert (T, 3 ) : 2 : ∞))), N- 1 )))
298308end
299309
300310
0 commit comments