Skip to content

Commit

Permalink
Add caching for assoc_legendre_func_table (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhro authored Apr 16, 2024
1 parent cca7ac2 commit 67f7154
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ version = "0.0.1-DEV"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LegendrePolynomials = "3db4a2ba-fc88-11e8-3e01-49c72059a882"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
ThreadSafeDicts = "4239201d-c60e-5e0a-9702-85d713665ba7"

[compat]
julia = "1.6"
Expand Down
5 changes: 4 additions & 1 deletion src/MagneticFieldSHTCExpander.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using LinearAlgebra: LowerTriangular, norm
using LegendrePolynomials: Plm
using ForwardDiff: derivative as derivativefd

using Memoization: @memoize
using ThreadSafeDicts: ThreadSafeDict

const R_0 = 1 # sun's radius in solar radius
const R_SS = 2.5 # source surface in solar radius (PFSS)

Expand Down Expand Up @@ -152,7 +155,7 @@ end
Plm′(x, l, m; kwargs...) = derivativefd(x -> Plm(x, l, m; kwargs...), x)
Plm′′(x, l, m; kwargs...) = derivativefd(x -> Plm′(x, l, m; kwargs...), x)

function assoc_legendre_func_table(x, lmax::Integer)
@memoize ThreadSafeDict function assoc_legendre_func_table(x, lmax::Integer)
# declare the three matrices
# the assoc legendre polynomials are only defined as m ≤ l, so enforce that
# in a lower triangular matrix.
Expand Down

0 comments on commit 67f7154

Please sign in to comment.