Skip to content

Commit

Permalink
Export Basis constructors; improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-petersen committed Jun 12, 2024
1 parent 44d818c commit a802d8c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/AstroBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ export getUln,getDln,tabUl!,tabDl!

# bring in the Clutton-Brock (1973) spherical basis
include("CB73.jl")
export CB73Basis

# bring in the Hernquist & Ostriker (1992) disc basis
include("Hernquist.jl")
export HernquistBasis

# @IMPROVE, add Bessel basis

# @IMPROVE, add readers for EXP empirical bases

# bring in the Clutton-Brock (1972) disc basis
include("CB72.jl")
export CB72Basis

# bring in the Kalnajs (1976) disc basis
include("Kalnajs76.jl")
export K76Basis


end # module
8 changes: 4 additions & 4 deletions src/Hernquist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ end



"""ClnHernquist(α,n,rho)
"""_ClnHernquist(α,n,rho)
Definition of the Gegenbauer polynomials
These coefficients are computed through an upward recurrence
@IMPROVE compute all the basis elements (n)_{1<=n<=nmax} at once
"""
function ClnHernquist::Float64,n::Int64,xi::Float64)
function _ClnHernquist::Float64,n::Int64,xi::Float64)

v0 = 1.0 # Initial value for n=0
if (n == 0)
Expand Down Expand Up @@ -173,7 +173,7 @@ function UlnpHernquist(l::Int64,np::Int64,r::Float64,tabPrefHernquist_Ulnp::Matr
x = r/rb # Dimensionless radius
rho = rhoHernquist(x) # Value of the rescaled parameter rho
valR = ((x/(1.0+x^(2)))^(l))/(sqrt(1.0+x^(2))) # Value of the multipole factor
valC = ClnHernquist(l+1.0,np,rho) # Value of the Gegenbauer polynomials
valC = _ClnHernquist(l+1.0,np,rho) # Value of the Gegenbauer polynomials
res = pref*valR*valC # Value of the radial function
return res
end
Expand All @@ -193,7 +193,7 @@ function DlnpHernquist(l::Int64,np::Int64,r::Float64,tabPrefHernquist_Dlnp::Matr
x = r/rb # Dimensionless radius
rho = rhoHernquist(x) # Value of the rescaled parameter rho
valR = ((x/(1.0+x^(2)))^(l))/((1.0+x^(2))^(5/2)) # Value of the multipole factor
valC = ClnHernquist(l+1.0,np,rho) # Value of the Gegenbauer polynomials
valC = _ClnHernquist(l+1.0,np,rho) # Value of the Gegenbauer polynomials
res = pref*valR*valC
return res
end
Expand Down
6 changes: 4 additions & 2 deletions test/test_razorthin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ ltest, nradial = 2, 5

@testset "razorthinbases" begin
@testset "CB72" begin
basis = AstroBasis.CB72Basis(lmax=ltest,nradial=nradial,G=G, rb=rb)
basis = CB72Basis(lmax=ltest,nradial=nradial,G=G, rb=rb)
@test dimension(basis) == 2
@test getparameters(basis)["name"] == "CB72"
@test getDln(basis,ltest,1,rb) == 0.0
@test getDln(basis,ltest,nradial-1,rb) 0.33126698841066865 atol=1e-6
@test getUln(basis,ltest,nradial-1,rb) -0.3202172114362374 atol=1e-6
tabUl!(basis,0,rb)
Expand All @@ -16,9 +17,10 @@ ltest, nradial = 2, 5
@test basis.tabDl[2] == 0
end
@testset "Kalnajs76" begin
basis = AstroBasis.K76Basis(lmax=ltest,nradial=nradial,G=G, rb=rb)
basis = K76Basis(lmax=ltest,nradial=nradial,G=G, rb=rb)
@test dimension(basis) == 2
@test getparameters(basis)["name"] == "K76"
@test getDln(basis,ltest,1,rb) == 0.0
@test getDln(basis,ltest,nradial-1,rb) == 0.0
@test getUln(basis,ltest,nradial-1,rb) -0.3167679231608087 atol=1e-6
tabUl!(basis,0,rb)
Expand Down
13 changes: 8 additions & 5 deletions test/test_spherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ ltest, nradial = 2, 5

@testset "sphericalbases" begin
@testset "CB73" begin
# build bases with unique cases
basis = AstroBasis.CB73Basis(lmax=ltest,nradial=1,G=G, rb=rb)
basis = AstroBasis.CB73Basis(lmax=ltest,nradial=2,G=G, rb=rb)
# test Gegenbauer polynomial (non)recursions
@test AstroBasis._ClnCB73(1.0,0,1.0) == 1.0
@test AstroBasis._ClnCB73(1.0,1,1.0) == 2.0
# build a standard basis
basis = AstroBasis.CB73Basis(lmax=ltest,nradial=nradial,G=G, rb=rb)
basis = CB73Basis(lmax=ltest,nradial=nradial,G=G, rb=rb)
@test dimension(basis) == 3
@test getparameters(basis)["name"] == "CB73"
# backward compatibility check
Expand All @@ -25,7 +25,10 @@ ltest, nradial = 2, 5
AstroBasis.WriteParameters("tmp.h5",basis,"w")
end
@testset "Hernquist" begin
basis = AstroBasis.HernquistBasis(lmax=ltest,nradial=nradial,G=G, rb=rb)
# test Gegenbauer polynomial (non)recursions
@test AstroBasis._ClnHernquist(1.0,0,1.0) == 1.0
@test AstroBasis._ClnHernquist(1.0,1,1.0) == 2.0
basis = HernquistBasis(lmax=ltest,nradial=nradial,G=G, rb=rb)
@test dimension(basis) == 3
@test getparameters(basis)["name"] == "Hernquist"
@test getDln(basis,ltest,nradial-1,rb) 1.552003244163087 atol=1e-6
Expand Down

0 comments on commit a802d8c

Please sign in to comment.