1
1
module PiecewiseOrthogonalPolynomials
2
- using ClassicalOrthogonalPolynomials, LinearAlgebra, BlockArrays, BlockBandedMatrices, ContinuumArrays, QuasiArrays, LazyArrays, LazyBandedMatrices, FillArrays
2
+ using ClassicalOrthogonalPolynomials, LinearAlgebra, BlockArrays, BlockBandedMatrices, BandedMatrices, ContinuumArrays, QuasiArrays, LazyArrays, LazyBandedMatrices, FillArrays, MatrixFactorizations, ArrayLayouts
3
3
4
+ import ArrayLayouts: sublayout, sub_materialize, symmetriclayout, transposelayout, SymmetricLayout, HermitianLayout, TriangularLayout, layout_getindex, materialize!, MatLdivVec, AbstractStridedLayout, triangulardata
5
+ import BandedMatrices: _BandedMatrix
4
6
import BlockArrays: BlockSlice, block, blockindex, blockvec
5
- import BlockBandedMatrices: _BandedBlockBandedMatrix
6
- import ClassicalOrthogonalPolynomials: grid, massmatrix, ldiv, pad, adaptivetransform_ldiv
7
- import ContinuumArrays: @simplify , factorize, TransformFactorization, AbstractBasisLayout, MemoryLayout, layout_broadcasted, ExpansionLayout, basis, plan_grid_transform
7
+ import BlockBandedMatrices: _BandedBlockBandedMatrix, AbstractBandedBlockBandedMatrix, subblockbandwidths, blockbandwidths, AbstractBandedBlockBandedLayout, layout_replace_in_print_matrix
8
+ import ClassicalOrthogonalPolynomials: grid, ldiv, pad, adaptivetransform_ldiv, grammatrix
9
+ import ContinuumArrays: @simplify , factorize, TransformFactorization, AbstractBasisLayout, MemoryLayout, layout_broadcasted, ExpansionLayout, basis, plan_grid_transform, grammatrix
8
10
import LazyArrays: paddeddata
9
- import LazyBandedMatrices: BlockBroadcastMatrix, BlockVec
10
- import Base: axes, getindex, == , \ , OneTo
11
+ import LazyBandedMatrices: BlockBroadcastMatrix, BlockVec, BandedLazyLayouts, AbstractLazyBandedBlockBandedLayout, UpperOrLowerTriangular
12
+ import Base: axes, getindex, + , - , * , / , == , \ , OneTo, oneto, replace_in_print_matrix, copy, diff, getproperty, adjoint, transpose, tail
13
+ import LinearAlgebra: BlasInt
14
+ import MatrixFactorizations: reversecholcopy
11
15
12
- export PiecewisePolynomial, ContinuousPolynomial, Derivative, Block
16
+ export PiecewisePolynomial, ContinuousPolynomial, Derivative, Block, weaklaplacian, grammatrix
13
17
14
18
abstract type AbstractPiecewisePolynomial{order,T,P<: AbstractVector } <: Basis{T} end
15
19
@@ -204,35 +208,83 @@ function \(P::ContinuousPolynomial{0}, C::ContinuousPolynomial{1})
204
208
_BandedBlockBandedMatrix (dat, axes (P, 2 ), (1 , 1 ), (0 , 1 ))
205
209
end
206
210
211
+ function \ (P:: ContinuousPolynomial{0, <:Any, <:AbstractRange} , C:: ContinuousPolynomial{1, <:Any, <:AbstractRange} )
212
+ T = promote_type (eltype (P), eltype (C))
213
+ @assert P. points == C. points
214
+ v = (convert (T, 2 ): 2 : ∞) ./ (3 : 2 : ∞)
215
+ N = length (P. points)
216
+ L = ArrowheadMatrix (_BandedMatrix (Ones {T} (2 , N)/ 2 , oneto (N- 1 ), 0 , 1 ),
217
+ (_BandedMatrix (Fill (v[1 ], 1 , N- 1 ), oneto (N- 1 ), 0 , 0 ),),
218
+ (_BandedMatrix (Vcat (Ones {T} (1 , N)/ 2 , - Ones {T} (1 , N)/ 2 ), oneto (N- 1 ), 0 , 1 ),),
219
+ Fill (_BandedMatrix (Hcat (v, Zeros {T} (∞), - v)' , axes (v,1 ), 1 , 1 ), N- 1 ))
220
+ end
221
+
222
+
223
+
207
224
# #####
208
225
# Gram matrix
209
226
# #####
210
227
211
- @simplify function * (Ac:: QuasiAdjoint{<:Any,<:ContinuousPolynomial{0}} , B:: ContinuousPolynomial{0} )
212
- A = Ac'
213
- T = promote_type (eltype (A), eltype (B))
228
+ function grammatrix (A:: ContinuousPolynomial{0,T} ) where T
229
+ r = A. points
230
+ N = length (r) - 1
231
+ hs = diff (r)
232
+ M = grammatrix (Legendre {T} ())
233
+ ArrowheadMatrix {T} (Diagonal (Fill (hs[1 ], N)), (), (), [Diagonal (M. diag[2 : end ] * h/ 2 ) for h in hs])
234
+ end
235
+
236
+ function grammatrix (A:: ContinuousPolynomial{0,T, <:AbstractRange} ) where T
214
237
r = A. points
215
- @assert r == B. points
216
238
N = length (r)
217
- M = massmatrix (Legendre {T} ())
239
+ M = grammatrix (Legendre {T} ())
218
240
Diagonal (mortar (Fill .((step (r) / 2 ) .* M. diag, N - 1 )))
219
241
end
220
242
243
+ function grammatrix (C:: ContinuousPolynomial{1, T, <:AbstractRange} ) where T
244
+ r = C. points
245
+
246
+ N = length (r) - 1
247
+ h = step (r) # 2/N
248
+ a = ((convert (T,4 ): 4 : ∞) .* (convert (T,- 2 ): 2 : ∞)) ./ ((1 : 2 : ∞) .* (3 : 2 : ∞) .* (- 1 : 2 : ∞))
249
+ b = (((convert (T,2 ): 2 : ∞) ./ (3 : 2 : ∞)). ^ 2 .* (convert (T,2 ) ./ (1 : 2 : ∞) .+ convert (T,2 ) ./ (5 : 2 : ∞)))
250
+
251
+ a11 = LazyBandedMatrices. Bidiagonal (Vcat (h/ 3 , Fill (2 h/ 3 , N- 1 ), h/ 3 ), Fill (h/ 6 , N), :U )
252
+ a21 = _BandedMatrix (Fill (h/ 3 , 2 , N), N+ 1 , 1 , 0 )
253
+ a31 = _BandedMatrix (Vcat (Fill (- 2 h/ 15 , 1 , N), Fill (2 h/ 15 , 1 , N)), N+ 1 , 1 , 0 )
254
+
255
+ Symmetric (ArrowheadMatrix (a11, (a21, a31), (),
256
+ Fill (_BandedMatrix (Vcat ((- h* a/ 2 )' ,
257
+ Zeros (1 ,∞),
258
+ (h* b/ 2 )' ), ∞, 0 , 2 ), N)))
259
+ end
260
+
261
+
262
+ function grammatrix (C:: ContinuousPolynomial )
263
+ P = ContinuousPolynomial {0} (C)
264
+ L = P \ C
265
+ L' * grammatrix (P) * L
266
+ end
221
267
222
268
@simplify function * (Ac:: QuasiAdjoint{<:Any,<:ContinuousPolynomial} , B:: ContinuousPolynomial )
223
269
A = Ac'
270
+ A == B && return grammatrix (A)
224
271
P = ContinuousPolynomial {0} (A)
225
- Q = ContinuousPolynomial {0} (B)
226
- (P \ A)' * (P' Q) * (Q \ B)
272
+ (P \ A)' * grammatrix (P) * (P \ B)
273
+ end
274
+
275
+ @simplify function * (Ac:: QuasiAdjoint{<:Any,<:ContinuousPolynomial{0}} , B:: ContinuousPolynomial{0} )
276
+ A = Ac'
277
+ @assert A == B
278
+ grammatrix (A)
227
279
end
228
280
281
+
282
+
229
283
# ####
230
284
# Derivative
231
285
# ####
232
286
233
- @simplify function * (D:: Derivative , C:: ContinuousPolynomial{1} )
234
- T = promote_type (eltype (D), eltype (C))
235
-
287
+ function diff (C:: ContinuousPolynomial{1,T} ; dims= 1 ) where T
236
288
# Legendre() \ (D*Weighted(Jacobi(1,1)))
237
289
r = C. points
238
290
N = length (r)
242
294
H = BlockBroadcastArray (hcat, z, v)
243
295
M = BlockVcat (Hcat (Ones {T} (N) .* [zero (T); s] , - Ones {T} (N) .* [s; zero (T)] ), H)
244
296
P = ContinuousPolynomial {0} (C)
245
- P * _BandedBlockBandedMatrix (M' , (axes (P, 2 ), axes (C, 2 )), (0 , 0 ), (0 , 1 ))
297
+ ApplyQuasiMatrix (* , P, _BandedBlockBandedMatrix (M' , (axes (P, 2 ), axes (C, 2 )), (0 , 0 ), (0 , 1 )))
298
+ end
299
+
300
+ function weaklaplacian (C:: ContinuousPolynomial{1,T,<:AbstractRange} ) where T
301
+ r = C. points
302
+ N = length (r)
303
+ s = step (r)
304
+ si = inv (s)
305
+ t1 = Vcat (- si, Fill (- 2 si, N- 2 ), - si)
306
+ t2 = Fill (si, N- 1 )
307
+ Symmetric (ArrowheadMatrix (LazyBandedMatrices. Bidiagonal (t1, t2, :U ), (), (),
308
+ Fill (Diagonal (convert (T, - 16 ) .* (1 : ∞) .^ 2 ./ (s .* ((2 : 2 : ∞) .+ 1 ))), N- 1 )))
246
309
end
247
310
248
311
@@ -268,5 +331,7 @@ function layout_broadcasted(::Tuple{ExpansionLayout{PiecewisePolynomialLayout{0}
268
331
(a .* P) * (P \ C)
269
332
end
270
333
334
+ include (" arrowhead.jl" )
335
+
271
336
272
337
end # module
0 commit comments