Skip to content

Commit ce1c192

Browse files
authored
Support KronPolynomial '* quasi vector (#232)
* Support KronPolynomial '* quasi vector * Update test_rect.jl * Update test_rect.jl
1 parent 98c698e commit ce1c192

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎examples/mixedpfem.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A = [M₁ Z₁ D₁';
3939
Z₁ M₂ D₂';
4040
D₁ D₂ Z₂]
4141

42-
f = expand(P², splat((x,y) -> 2*(-1+x^2)*cos((1+x)sin(1-y))+2*(-1+y^2)cos((1+x)sin(1-y))-(-1+x)*(1+x)^3*(-1+y^2)*cos(1-y)^2*cos((1+x)*sin(1-y))-(-1+x^2)*(-1+y^2)*cos((1+x)*sin(1-y))sin(1-y)^2+4*(-1+x)*(1+x)^2*y*cos(1-y)sin((1+x)sin(1-y))-4x*(-1+y^2)*sin(1-y)sin((1+x)sin(1-y))+(-1+x)*(1+x)^2*(-1+y^2)*sin(1-y)*sin((1+x)sin(1-y))))
42+
f = [2*(-1+x^2)*cos((1+x)sin(1-y))+2*(-1+y^2)cos((1+x)sin(1-y))-(-1+x)*(1+x)^3*(-1+y^2)*cos(1-y)^2*cos((1+x)*sin(1-y))-(-1+x^2)*(-1+y^2)*cos((1+x)*sin(1-y))sin(1-y)^2+4*(-1+x)*(1+x)^2*y*cos(1-y)sin((1+x)sin(1-y))-4x*(-1+y^2)*sin(1-y)sin((1+x)sin(1-y))+(-1+x)*(1+x)^2*(-1+y^2)*sin(1-y)*sin((1+x)sin(1-y)) for (x,y) in axes(P²,1)]
4343

4444
𝐳 = Zeros(axes(M₁,1))
4545
𝐜 = A \ [𝐳; 𝐳; (P²'f)[Block.(1:N-1)]]

‎src/MultivariateOrthogonalPolynomials.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import DomainSets: boundary, EuclideanDomain
1313
import QuasiArrays: LazyQuasiMatrix, LazyQuasiArrayStyle, domain, vec_layout, reshape_layout, pointchoice
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, KronExpansionLayout, ApplyPlan
1515

16-
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize
16+
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize, mul
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, LazyMatrix, ApplyMatrix, ApplyLayout
20+
import LazyArrays: arguments, paddeddata, LazyArrayStyle, LazyLayout, PaddedLayout, applylayout, LazyMatrix, ApplyMatrix, ApplyLayout, simplifiable
2121
import LazyBandedMatrices: LazyBandedBlockBandedLayout, AbstractBandedBlockBandedLayout, AbstractLazyBandedBlockBandedLayout, _krontrav_axes, DiagTravLayout, diagtrav, invdiagtrav, ApplyBandedBlockBandedLayout, krontrav
2222
import InfiniteArrays: InfiniteCardinal, OneToInf
2323

‎src/rect.jl‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ struct KronPolynomial{d, T, PP} <: MultivariateOrthogonalPolynomial{d, T}
22
args::PP
33
end
44

5-
KronPolynomial{d,T}(a::Vararg{Any,d}) where {d,T} = KronPolynomial{d,T,typeof(a)}(a)
6-
KronPolynomial{d}(a::Vararg{Any,d}) where d = KronPolynomial{d,mapreduce(eltype, promote_type, a)}(a...)
7-
KronPolynomial(a::Vararg{Any,d}) where d = KronPolynomial{d}(a...)
5+
KronPolynomial{d,T}(a::NTuple{d,Any}) where {d,T} = KronPolynomial{d,T,typeof(a)}(a)
6+
KronPolynomial{d}(a::NTuple{d,Any}) where d = KronPolynomial{d,mapreduce(eltype, promote_type, a)}(a)
7+
KronPolynomial(a::NTuple{d,Any}) where d = KronPolynomial{d}(a)
8+
KronPolynomial{d,T}(a::Vararg{Any,d}) where {d,T} = KronPolynomial{d,T}(a)
9+
KronPolynomial{d}(a::Vararg{Any,d}) where d = KronPolynomial{d}(a)
10+
KronPolynomial(a::Vararg{Any,d}) where d = KronPolynomial{d}(a)
811
KronPolynomial{d,T}(a::AbstractVector) where {d,T} = KronPolynomial{d,T,typeof(a)}(a)
912
KronPolynomial{d}(a::AbstractVector) where d = KronPolynomial{d,eltype(eltype(a))}(a)
1013
KronPolynomial(a::AbstractVector) = KronPolynomial{length(a)}(a)
@@ -81,6 +84,16 @@ end
8184
KronTrav(PB'QB, PA'QA)
8285
end
8386

87+
simplifiable(::typeof(*), ::QuasiAdjoint{T,<:KronPolynomial{d}}, ::AbstractQuasiVector) where {d,T} = Val(true)
88+
simplifiable(::typeof(*), ::QuasiAdjoint{T,<:AbstractQuasiVector}, ::KronPolynomial{d}) where {d,T} = Val(true)
89+
function mul(Ac::QuasiAdjoint{T,<:KronPolynomial{d}}, B::AbstractQuasiVector) where {d,T}
90+
P = KronPolynomial{d, T}(map(_ -> Legendre{eltype(Ac)}(), parent(Ac).args))
91+
(Ac * P) * (P \ B)
92+
end
93+
94+
mul(B::QuasiAdjoint{T,<:AbstractQuasiVector}, A::KronPolynomial{d}) where {d,T} = (A'B')'
95+
96+
8497
grammatrix(P::KronPolynomial) = KronTrav(reverse(grammatrix.(P.args))...)
8598

8699

‎test/test_rect.jl‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,23 @@ Random.seed!(3242)
333333
@test (M*c)[Block.(1:N)] ≈ M[Block.(1:N),Block.(1:N)] * c[Block.(1:N)] ≈ sparse(M[Block.(1:N),Block.(1:N)]) * c[Block.(1:N)]
334334
@test c'M*c ≈ f'f
335335
end
336+
337+
@testset "tuple constructors" begin
338+
P = KronPolynomial(Legendre(), Chebyshev())
339+
@test KronPolynomial((Legendre(), Chebyshev())) == KronPolynomial{2}((Legendre(), Chebyshev())) == KronPolynomial{2,Float64}((Legendre(), Chebyshev())) == P
340+
@test KronPolynomial{2}(Legendre(), Chebyshev()) == KronPolynomial{2,Float64}(Legendre(), Chebyshev()) == P
341+
end
342+
343+
@testset "P'f for quasi-vector f" begin
344+
P = KronPolynomial(Jacobi(1,1), Legendre())
345+
f = splat((x,y) -> exp(x*cos(y))).(axes(P,1))
346+
@test MultivariateOrthogonalPolynomials.simplifiable(*, P', f) == Val(true)
347+
@test MultivariateOrthogonalPolynomials.simplifiable(*, f', P) == Val(true)
348+
c = P'f
349+
@test c[1] ≈ sum(2sinh(cos(y))/cos(y) for y in ChebyshevInterval())
350+
for k in (2, 3, 5)
351+
@test c[k] ≈ sum(exp(x*cos(y))*P[SVector(x,y),k] for (x,y) in ChebyshevInterval()^2) atol=1E-12
352+
end
353+
@test (f'P)[1:6] ≈ c[1:6]
354+
end
336355
end

0 commit comments

Comments
 (0)