Skip to content

Commit 0df1c6d

Browse files
committed
copy over from OrthogonalPolynomialsQuasi.jl
1 parent 4424138 commit 0df1c6d

34 files changed

+4936
-0
lines changed

.github/workflows/CompatHelper.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CompatHelper
2+
3+
on:
4+
schedule:
5+
- cron: '00 * * * *'
6+
7+
jobs:
8+
build:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
julia-version: [1.2.0]
13+
julia-arch: [x86]
14+
os: [ubuntu-latest]
15+
steps:
16+
- uses: julia-actions/setup-julia@latest
17+
with:
18+
version: ${{ matrix.julia-version }}
19+
- name: Install dependencies
20+
run: julia -e 'using Pkg; Pkg.add(Pkg.PackageSpec(name = "CompatHelper", url = "https://github.com/bcbi/CompatHelper.jl.git"))'
21+
- name: CompatHelper.main
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
JULIA_DEBUG: CompatHelper
25+
run: julia -e 'using CompatHelper; CompatHelper.main()'

.github/workflows/TagBot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: TagBot
2+
on:
3+
issue_comment: # THIS BIT IS NEW
4+
types:
5+
- created
6+
workflow_dispatch:
7+
jobs:
8+
TagBot:
9+
# THIS 'if' LINE IS NEW
10+
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
11+
# NOTHING BELOW HAS CHANGED
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: JuliaRegistries/TagBot@v1
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
ssh: ${{ secrets.DOCUMENTER_KEY }}

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
version:
13+
- '1.5'
14+
- 'nightly'
15+
os:
16+
- ubuntu-latest
17+
- macOS-latest
18+
- windows-latest
19+
arch:
20+
- x64
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: julia-actions/setup-julia@v1
24+
with:
25+
version: ${{ matrix.version }}
26+
arch: ${{ matrix.arch }}
27+
- uses: actions/cache@v1
28+
env:
29+
cache-name: cache-artifacts
30+
with:
31+
path: ~/.julia/artifacts
32+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
33+
restore-keys: |
34+
${{ runner.os }}-test-${{ env.cache-name }}-
35+
${{ runner.os }}-test-
36+
${{ runner.os }}-
37+
- uses: julia-actions/julia-buildpkg@v1
38+
- uses: julia-actions/julia-runtest@v1
39+
- uses: julia-actions/julia-processcoverage@v1
40+
- uses: codecov/codecov-action@v1
41+
with:
42+
file: lcov.info

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ docs/site/
2222
# committed for packages, but should be committed for applications that require a static
2323
# environment.
2424
Manifest.toml
25+
.DS_Store

Project.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name = "ClassicalOrthogonalPolynomials"
2+
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
3+
authors = ["Sheehan Olver <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
8+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
9+
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
10+
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
11+
ContinuumArrays = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
12+
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
13+
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
14+
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
15+
FastTransforms = "057dd010-8810-581a-b7be-e3fc3b93f78c"
16+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
17+
InfiniteArrays = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
18+
InfiniteLinearAlgebra = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
19+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
20+
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
21+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
22+
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
23+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
24+
25+
[compat]
26+
ArrayLayouts = "0.5.1"
27+
BandedMatrices = "0.16"
28+
BlockArrays = "0.14"
29+
BlockBandedMatrices = "0.10"
30+
ContinuumArrays = "0.5"
31+
DomainSets = "0.4, 0.5"
32+
FFTW = "1.1"
33+
FastGaussQuadrature = "0.4.3"
34+
FastTransforms = "0.11"
35+
FillArrays = "0.11"
36+
InfiniteArrays = "0.9"
37+
InfiniteLinearAlgebra = "0.4.6"
38+
IntervalSets = "0.3.1, 0.4, 0.5"
39+
LazyArrays = "0.20"
40+
QuasiArrays = "0.4"
41+
SpecialFunctions = "0.10, 1"
42+
julia = "1.5"
43+
44+
[extras]
45+
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
46+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
47+
LazyBandedMatrices = "d7e5e226-e90b-4449-9968-0f923699bf6f"
48+
SemiseparableMatrices = "f8ebbe35-cbfb-4060-bf7f-b10e4670cf57"
49+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
50+
51+
[targets]
52+
test = ["Base64", "Test", "ForwardDiff", "SemiseparableMatrices", "LazyBandedMatrices"]

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,89 @@
11
# ClassicalOrthogonalPolynomials.jl
22
A Julia package for classical orthogonal polynomials and expansions
3+
4+
[![Build Status](https://github.com/JuliaApproximation/ClassicalOrthogonalPolynomials.jl/workflows/CI/badge.svg)](https://github.com/JuliaApproximation/FastGaussQuadrature.jl/actions)
5+
[![codecov](https://codecov.io/gh/JuliaApproximation/ClassicalOrthogonalPolynomials.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaApproximation/ClassicalOrthogonalPolynomials.jl)
6+
7+
8+
This package implements classical orthogonal polynomials as quasi-arrays where one one axes is continuous and the other axis is discrete (countably infinite), as implemented in [QuasiArrays.jl](https://github.com/JuliaApproximation/QuasiArrays.jl) and [ContinuumArrays.jl](https://github.com/JuliaApproximation/ContinuumArrays.jl).
9+
```julia
10+
julia> using ClassicalOrthogonalPolynomials, ContinuumArrays
11+
12+
julia> P = Legendre(); # Legendre polynomials
13+
14+
julia> size(P) # uncountable ∞ x countable ∞
15+
(ℵ₁, ∞)
16+
17+
julia> axes(P) # essentially (-1..1, 1:∞), Inclusion plays the same role as Slice
18+
(Inclusion(-1.0..1.0 (Chebyshev)), OneToInf())
19+
20+
julia> P[0.1,1:10] # [P_0(0.1), …, P_9(0.1)]
21+
10-element Array{Float64,1}:
22+
1.0
23+
0.1
24+
-0.485
25+
-0.14750000000000002
26+
0.3379375
27+
0.17882875
28+
-0.2488293125
29+
-0.19949294375000004
30+
0.180320721484375
31+
0.21138764183593753
32+
33+
julia> @time P[range(-1,1; length=10_000), 1:10_000]; # construct 10_000^2 Vandermonde matrix
34+
1.624796 seconds (10.02 k allocations: 1.491 GiB, 6.81% gc time)
35+
```
36+
This also works for associated Legendre polynomials as weighted Ultraspherical polynomials:
37+
```julia
38+
julia> associatedlegendre(m) = ((-1)^m*prod(1:2:(2m-1)))*(UltrasphericalWeight((m+1)/2).*Ultraspherical(m+1/2))
39+
associatedlegendre (generic function with 1 method)
40+
41+
julia> associatedlegendre(2)[0.1,1:10]
42+
10-element Array{Float64,1}:
43+
2.9699999999999998
44+
1.4849999999999999
45+
-6.9052500000000006
46+
-5.041575
47+
10.697754375
48+
10.8479361375
49+
-13.334647528125
50+
-18.735466024687497
51+
13.885467170308594
52+
28.220563705988674
53+
```
54+
55+
## p-Finite Element Method
56+
57+
The language of quasi-arrays gives a natural framework for constructing p-finite element methods. The convention
58+
is that adjoint-products are understood as inner products over the axes with uniform weight. Thus to solve Poisson's equation
59+
using its weak formulation with Dirichlet conditions we can expand in a weighted Jacobi basis:
60+
```julia
61+
julia> P¹¹ = Jacobi(1.0,1.0); # Quasi-matrix of Jacobi polynomials
62+
63+
julia> w = JacobiWeight(1.0,1.0); # quasi-vector correspoinding to (1-x^2)
64+
65+
julia> w[0.1] (1-0.1^2)
66+
true
67+
68+
julia> S = w .* P¹¹; # Quasi-matrix of weighted Jacobi polynomials
69+
70+
julia> D = Derivative(axes(S,1)); # quasi-matrix corresponding to derivative
71+
72+
julia> Δ = (D*S)'*(D*S) # weak laplacian corresponding to inner products of weighted Jacobi polynomials
73+
×∞ LazyArrays.ApplyArray{Float64,2,typeof(*),Tuple{Adjoint{Int64,BandedMatrices.BandedMatrix{Int64,Adjoint{Int64,InfiniteArrays.InfStepRange{Int64,Int64}},InfiniteArrays.OneToInf{Int64}}},LazyArrays.BroadcastArray{Float64,2,typeof(*),Tuple{LazyArrays.BroadcastArray{Float64,1,typeof(/),Tuple{Int64,InfiniteArrays.InfStepRange{Int64,Int64}}},BandedMatrices.BandedMatrix{Int64,Adjoint{Int64,InfiniteArrays.InfStepRange{Int64,Int64}},InfiniteArrays.OneToInf{Int64}}}}}} with indices OneToInf()×OneToInf():
74+
2.66667
75+
6.4
76+
10.2857
77+
14.2222
78+
18.1818
79+
22.1538
80+
26.1333
81+
30.1176
82+
83+
84+
85+
86+
87+
```
88+
89+

examples/beam.jl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using ClassicalOrthogonalPolynomials, ContinuumArrays, DifferentialEquations, Plots
2+
3+
###
4+
# Heat
5+
###
6+
7+
S = JacobiWeight(1.0,1.0) .* Jacobi(1.0,1.0)
8+
D = Derivative(axes(S,1))
9+
Δ = -((D*S)'*(D*S))
10+
M = S'S
11+
12+
function evolution(u, (M,A), t)
13+
M\(A*u)
14+
end
15+
n = 50
16+
u0 = [[1,2,3]; zeros(n-3)]
17+
prob = ODEProblem(evolution,u0,(0.0,3.0),(cholesky(Symmetric(M[1:n,1:n])),Δ[1:n,1:n]))
18+
@time u = solve(prob,TRBDF2()); u(1.0)
19+
20+
###
21+
# Heat natural
22+
###
23+
L = LinearSpline(range(-1,1;length=2))
24+
P = apply(hcat,L,S)
25+
ApplyArray(hcat,Legendre() \ (D*L), Legendre() \ (D*S))
26+
27+
(D*L)'*(D*L)
28+
29+
(D*S)'*(D*S)
30+
31+
((D*S)'*(D*L)).args[3]
32+
(D*L)'*(D*S)
33+
H = (D*L).args[1]
34+
P = Legendre()
35+
(P\H)' * P'P * (P \ (D*S))
36+
37+
38+
39+
###
40+
# Beam
41+
###
42+
43+
# [u, u_t]_t = [0 I; M] * [u, u_t]
44+
45+
S = JacobiWeight(2.0,2.0) .* Jacobi(2.0,2.0)
46+
D = Derivative(axes(S,1))
47+
Δ² = (D^2*S)'*(D^2*S)
48+
M = S'S
49+
function wave(uv, (M,A), t)
50+
n = size(M,1)
51+
u,v = uv[1:n],uv[n+1:end]
52+
[v; M\(A*u)]
53+
end
54+
n = 30
55+
u0 = [1; 2; 3; zeros(n-3)]
56+
prob = ODEProblem(wave,[u0; zeros(n)],(0.0,3.0),(cholesky(Symmetric(M[1:n,1:n])),-(Δ²)[1:n,1:n]))
57+
@time u = solve(prob,TRBDF2()); u(1.0)
58+
59+
g = range(-1,1;length=200)
60+
V = S[g,1:n]
61+
@gif for t in 0.0:0.01:3.0
62+
plot(g, V*u(t)[1:n]; ylims=(-5,5))
63+
end
64+
65+
66+
prob = ODEProblem(wave,[u0; zeros(n)],(0.0,3.0),(qr(M),-(Δ²)))

examples/collocation.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using ContinuumArrays, QuasiArrays, FillArrays, InfiniteArrays
2+
import QuasiArrays: Inclusion, QuasiDiagonal
3+
4+
using Plots; pyplot();
5+
6+
S = LinearSpline(range(0,1; length=10))
7+
xx = range(0,1; length=1000)
8+
9+
S = Jacobi(true,true)
10+
11+
12+
P = Legendre()
13+
X = QuasiDiagonal(Inclusion(-1..1))
14+
15+
@test X[-1:0.1:1,-1:0.1:1] == Diagonal(-1:0.1:1)
16+
17+
axes(X)
18+
J = pinv(P)*X*P
19+
20+
J - I
21+
Vcat(Hcat(1, Zeros(1,∞)), J)

examples/golubwelsch.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using ClassicalOrthogonalPolynomials, FastGaussQuadrature
2+
3+
P = Legendre()
4+
x = axes(P,1)
5+
x .* P
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using ContinuumArrays, FillArrays, InfiniteArrays, Plots
2+
3+
T = Chebyshev()
4+
C = Ultraspherical(2)
5+
D = Derivative(axes(T,1))
6+
A = (C\(D^2*T))+100(C\T)
7+
8+
n = 100
9+
c = [T[[-1,1],1:n]; A[1:n-2,1:n]] \ [1;2;zeros(n-2)]
10+
u = T*Vcat(c,Zeros(∞))
11+
12+
xx = range(-1,1;length=1000)
13+
plot(xx,u[xx])
14+

0 commit comments

Comments
 (0)