Skip to content

Commit 9b416d8

Browse files
authored
Overhaul of finite-differences (#41)
* Implemented hashing of bases * Finite-differences stencils now generated when needed In-progress support for non-uniform implicit finite-differences Coulomb fix at r=0 no longer part of type, but instantiated via special CoulombDerivative operator * Also compare indices when comparing restricted bases * Print spacing variation for non-uniform finite-differences * Disambiguate various finite-differences in hash * Implemented R'D'QuasiDiagonal*D*R for StaggeredFiniteDifferences * Derivative errors computed in R and not in Hilbert space * Also test on Julia 1.6 * Fixed finite-differences test errors due to API breakage * Update compat entries * v0.3.0 * Fixed docs plots * Ensure implicit finite-differences work in restricted bases * Type alias * Update CI.yml; 1.6 released, don't test on Windows due to memory issue (?) * Updated CI to skip Windows/1.5 only and avoid Doctest error -> fail
1 parent f184728 commit 9b416d8

File tree

16 files changed

+734
-295
lines changed

16 files changed

+734
-295
lines changed

.github/workflows/CI.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ jobs:
1111
matrix:
1212
version:
1313
- '1.5'
14-
# - '1.6'
14+
- '1.6'
1515
- 'nightly'
1616
os:
1717
- ubuntu-latest
1818
- macOS-latest
1919
- windows-latest
2020
arch:
2121
- x64
22+
exclude:
23+
- os: windows-latest
24+
version: '1.5'
2225
steps:
2326
- uses: actions/checkout@v2
2427
- uses: julia-actions/setup-julia@v1
@@ -74,7 +77,10 @@ jobs:
7477
using Pkg
7578
Pkg.develop(PackageSpec(path=pwd()))
7679
Pkg.instantiate()'
77-
- run: |
80+
- name: Run Doctests
81+
# See https://github.com/actions/toolkit/issues/399
82+
continue-on-error: true
83+
run: |
7884
julia --project=docs -e '
7985
using Documenter: DocMeta, doctest
8086
using CompactBases

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CompactBases"
22
uuid = "2c0377a8-7469-4ebd-be0f-82e501f20078"
33
authors = ["Stefanos Carlström <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.3.0"
55

66
[deps]
77
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
@@ -21,14 +21,14 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2121
[compat]
2222
BandedMatrices = "0.16"
2323
BlockBandedMatrices = "0.10"
24-
ContinuumArrays = "0.6.4"
24+
ContinuumArrays = "0.6.4,0.7"
2525
FastGaussQuadrature = "0.4"
2626
FillArrays = "0.11"
2727
Formatting = "0.4"
2828
IntervalSets = "0.5.1"
2929
LazyArrays = "0.20,0.21"
3030
OffsetArrays = "1.1"
31-
QuasiArrays = "0.4.9"
31+
QuasiArrays = "0.4.9,0.5"
3232
RecipesBase = "1.0"
3333
julia = "1.5"
3434

docs/plots.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function densities()
135135
rr = 10.0 .^ range(-2, stop=log10(rmax), length=3000)
136136

137137
for R in [FiniteDifferences(N, ρ),
138-
StaggeredFiniteDifferences(ρmin, ρmax, α, rmax, 0.0),
138+
StaggeredFiniteDifferences(ρmin, ρmax, α, rmax),
139139
FEDVR(range(0, stop=rmax, length=Nn), k),
140140
BSpline(LinearKnotSet(k, 0, rmax, Nn))]
141141
r = axes(R,1)
@@ -203,12 +203,12 @@ function diagonal_operators()
203203

204204
ρ = 0.1/Z
205205
N = ceil(Int, rmax/ρ)
206-
ufd = StaggeredFiniteDifferences(N, ρ, Z)
206+
ufd = StaggeredFiniteDifferences(N, ρ)
207207

208208
ρmin=0.1/Z
209209
ρmax=0.6
210210
α=0.002
211-
nufd = StaggeredFiniteDifferences(ρmin, ρmax, α, rmax, Z)
211+
nufd = StaggeredFiniteDifferences(ρmin, ρmax, α, rmax)
212212

213213
fedvr = FEDVR(range(0, stop=rmax, length=20),
214214
vcat(10,fill(7,18)))[:,2:end-1]

src/CompactBases.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ContinuumArrays: Basis, ℵ₁, Derivative, Inclusion, @simplify, simplif
1010
using QuasiArrays
1111
import QuasiArrays: AbstractQuasiMatrix, QuasiAdjoint, MulQuasiArray,
1212
PInvQuasiMatrix, InvQuasiMatrix, QuasiDiagonal,
13-
BroadcastQuasiArray, SubQuasiArray
13+
BroadcastQuasiArray, SubQuasiArray, LazyQuasiMatrix
1414

1515
using IntervalSets
1616

@@ -43,6 +43,8 @@ include("skewtridiag.jl")
4343

4444
include("materialize_dsl.jl")
4545

46+
include("coulomb_derivative.jl")
47+
4648
include("fornberg.jl")
4749
include("finite_differences.jl")
4850
include("fd_operators.jl")

src/bsplines.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ BSpline(t::AbstractKnotSet; k′=3) = BSpline(t, num_quadrature_points(order(t),
123123
axes(B::BSpline) = (Inclusion(first(B.t)..last(B.t)), Base.OneTo(numfunctions(B.t)))
124124
size(B::BSpline) = (ℵ₁, numfunctions(B.t))
125125
==(A::BSpline,B::BSpline) = A.t == B.t
126+
Base.hash(B::BSpline, h::UInt) = hash(B.t, h)
126127

127128
distribution(B::BSpline) = distribution(B.t)
128129

src/coulomb_derivative.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
CoulombDerivative(D, Z, ℓ)
3+
4+
Helper operator wrapping the `Derivative` operator in the case of a
5+
Coulomb potential of charge `Z` and centrifugal potential
6+
``ℓ(ℓ+1)/2r²``. Its main use is to correctly apply boundary conditions
7+
at ``r=0``, when materializing derivatives.
8+
"""
9+
struct CoulombDerivative{T,Der<:Derivative{T},U<:Number} <: LazyQuasiMatrix{T}
10+
D::Der
11+
Z::U
12+
::Int
13+
end
14+
15+
axes(D::CoulombDerivative) = axes(D.D)
16+
==(a::CoulombDerivative, b::CoulombDerivative) = a.D == b.D && a.Z == b.Z && a.== b.
17+
copy(D::CoulombDerivative) = CoulombDerivative(copy(D.D), D.Z, D.ℓ)
18+
19+
Base.show(io::IO, D::CoulombDerivative) =
20+
write(io, "CoulombDerivative($(D.D), Z = $(D.Z), ℓ = $(D.ℓ))")
21+
22+
export CoulombDerivative

0 commit comments

Comments
 (0)