Skip to content

Commit a737b55

Browse files
Add derivatives for WeightedTriangle (#179)
* Add derivatives for WeightedTriangle * fix bug, update CI * FastTransforms v0.16 --------- Co-authored-by: Sheehan Olver <[email protected]>
1 parent 089ad3c commit a737b55

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ jobs:
1111
matrix:
1212
version:
1313
- '1.9'
14+
- '1'
1415
os:
1516
- ubuntu-latest
1617
- macOS-latest
1718
- windows-latest
1819
arch:
1920
- x64
2021
steps:
21-
- uses: actions/checkout@v2
22-
- uses: julia-actions/setup-julia@v1
22+
- uses: actions/checkout@v4
23+
- uses: julia-actions/setup-julia@v2
2324
with:
2425
version: ${{ matrix.version }}
2526
arch: ${{ matrix.arch }}
26-
- uses: actions/cache@v1
27+
- uses: actions/cache@v4
2728
env:
2829
cache-name: cache-artifacts
2930
with:
@@ -36,6 +37,7 @@ jobs:
3637
- uses: julia-actions/julia-buildpkg@v1
3738
- uses: julia-actions/julia-runtest@v1
3839
- uses: julia-actions/julia-processcoverage@v1
39-
- uses: codecov/codecov-action@v1
40+
- uses: codecov/codecov-action@v4
4041
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}
4143
file: lcov.info

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BlockBandedMatrices = "0.12.5"
3131
ClassicalOrthogonalPolynomials = "0.12"
3232
ContinuumArrays = "0.17"
3333
DomainSets = "0.6, 0.7"
34-
FastTransforms = "0.15.11"
34+
FastTransforms = "0.15.11, 0.16"
3535
FillArrays = "1.0"
3636
HarmonicOrthogonalPolynomials = "0.5"
3737
InfiniteArrays = "0.13"

src/rect.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function plan_transform(P::KronPolynomial{d}, B::Tuple{Block{1}}, dims=1:1) wher
138138
end
139139

140140
applylayout(::Type{typeof(*)}, ::Lay, ::DiagTravLayout) where Lay <: AbstractBasisLayout = ExpansionLayout{Lay}()
141-
ContinuumArrays._mul_plotgrid(::Tuple{Any,DiagTravLayout{<:PaddedLayout}}, (P,c)) = plotgrid(P, maximum(blockcolsupport(c)))
141+
ContinuumArrays._mul_plotgrid(::Tuple{Any,DiagTravLayout{<:PaddedLayout}}, (P,c)::NTuple{2,Any}) = plotgrid(P, maximum(blockcolsupport(c)))
142142

143143
pad(C::DiagTrav, ::BlockedUnitRange{RangeCumsum{Int,OneToInf{Int}}}) = DiagTrav(pad(C.array, ∞, ∞))
144144

src/triangle.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ end
165165
JacobiTriangle(a,b+1,c+1) * _BandedBlockBandedMatrix((k .+ convert(T, b+c))', axes(k,1), (-1,1), (-1,1))
166166
end
167167

168+
# TODO: The derivatives below only hold for a, b, c > 0.
169+
@simplify function *(Dx::PartialDerivative{1}, P::WeightedTriangle)
170+
a, b, c = P.P.a, P.P.b, P.P.c
171+
n = mortar(Fill.(oneto(∞),oneto(∞)))
172+
k = mortar(Base.OneTo.(oneto(∞)))
173+
scale = -(2k .+ (b + c - 1))
174+
coeff1 = (k .+ (c - 1)) .* (n .- k .+ 1) ./ scale
175+
coeff2 = k .* (n .- k .+ a) ./ scale
176+
dat = BlockBroadcastArray(hcat, coeff1, coeff2)
177+
WeightedTriangle(a-1, b, c-1) * _BandedBlockBandedMatrix(dat', axes(k, 1), (1, -1), (1, 0))
178+
end
179+
180+
@simplify function *(Dy::PartialDerivative{2}, P::WeightedTriangle)
181+
a, b, c = P.P.a, P.P.b, P.P.c
182+
k = mortar(Base.OneTo.(oneto(∞)))
183+
T = promote_type(eltype(Dy), eltype(P)) # avoid bug in convert
184+
WeightedTriangle(a, b-1, c-1) * _BandedBlockBandedMatrix(-one(T) * k', axes(k, 1), (1, -1), (1, -1))
185+
end
168186

169187
# @simplify function *(Δ::Laplacian, P)
170188
# _lap_mul(P, eltype(axes(P,1)))

test/test_triangle.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,35 @@ import MultivariateOrthogonalPolynomials: tri_forwardrecurrence, grid, TriangleR
501501

502502
@test affine(d, axes(P,1))[affine(axes(P,1), d)[𝐱]] 𝐱
503503
end
504+
505+
@testset "Weighted derivatives" begin
506+
for a in (0.001, 0.1, 0.2, 1.0)
507+
for b in (0.001, 0.1, 0.2, 1.0)
508+
for c in (0.001, 0.1, 0.2, 1.0)
509+
f = let a = a, b = b, c = c
510+
((x, y),) -> x^a * y^b * (1 - x - y)^c * (x^2 + 3y^2 + x * y)
511+
end
512+
dfx = let a = a, b = b, c = c
513+
((x, y),) -> x^a * y^b * (1 - x - y)^c * (2x + y - c * (x^2 + 3y^2 + x * y) / (1 - x - y) + a * (x + y + 3 * y^2 / x))
514+
end
515+
dfy = let a = a, b = b, c = c
516+
((x, y),) -> x^a * y^b * (1 - x - y)^c * (x + 6y + b * (x + x^2 / y + 3y) - c * (x^2 + 3y^2 + x * y) / (1 - x - y))
517+
end
518+
P = Weighted(JacobiTriangle(a, b, c))
519+
Pf = expand(P, f)
520+
𝐱 = axes(P, 1)
521+
∂ˣ = PartialDerivative{1}(𝐱)
522+
∂ʸ = PartialDerivative{2}(𝐱)
523+
Pfx = ∂ˣ * Pf
524+
Pfy = ∂ʸ * Pf
525+
for _ in 1:100
526+
u, v = minmax(rand(2)...)
527+
x, y = v - u, 1 - v # random point in the triangle
528+
@test Pfx[SVector(x, y)] dfx((x, y))
529+
@test Pfy[SVector(x, y)] dfy((x, y))
530+
end
531+
end
532+
end
533+
end
534+
end
504535
end

0 commit comments

Comments
 (0)