Skip to content

Commit d046727

Browse files
gradient handling signature changes
1 parent 872682e commit d046727

File tree

17 files changed

+289
-225
lines changed

17 files changed

+289
-225
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
Pkg.add("BenchmarkTools")
2020
Pkg.add("Test")
2121
Pkg.add(url="https://github.com/JuliaStellarDynamics/OrbitalElements.jl.git")
22-
Pkg.add(url="https://github.com/JuliaStellarDynamics/DistributionFunctions.jl.git")
22+
Pkg.add(url="https://github.com/JuliaStellarDynamics/DistributionFunctions.jl.git")'
2323
ls
2424
julia --project=df -e '
2525
using Pkg

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributionFunctions"
22
uuid = "c869f47d-2815-40f9-b874-25ebe83f43af"
3-
version = "0.0.6dev"
3+
version = "0.0.7dev"
44

55
[deps]
66
OrbitalElements = "a3b07092-bde3-4843-b84f-c597d614ec7b"

src/Analytic/Isochrone/isochrone.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# Isochrone distribution functions (analytic)
33
#####################################
44
abstract type IsochroneDistributionFunction <: DistributionFunction end
5-
struct IsotropicIsochrone <: IsochroneDistributionFunction
6-
potential::IsochronePotential # Potential model
5+
struct IsotropicIsochrone{modelT<:IsochronePotential} <: IsochroneDistributionFunction
6+
potential::modelT # Potential model
77
end
8-
struct OsipkovMerrittIsochrone <: IsochroneDistributionFunction
8+
struct OsipkovMerrittIsochrone{modelT<:IsochronePotential} <: IsochroneDistributionFunction
99
ra::Float64 # Anisotropy radius
10-
potential::IsochronePotential # Potential model
10+
potential::modelT # Potential model
1111
end
1212

1313
"""

src/Analytic/Isochrone/isotropic.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ end
1010

1111

1212

13-
"""isochroneisotropicDF(E[,bc,M,G])
13+
"""Distribution(E[,bc,M,G])
1414
the isotropic DF
1515
"""
16-
function F(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
16+
function Distribution(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
1717
E,L = EL
1818

1919
scaleEnergy = - df.potential.G * df.potential.M / df.potential.bc
@@ -29,10 +29,10 @@ function F(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
2929
end
3030

3131

32-
"""isochroneisotropicdDFdE(E[,bc,M,G])
32+
"""DFDE(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
3333
the isotropic DF derivative w.r.t. E
3434
"""
35-
function dFdE(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
35+
function DFDE(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
3636

3737
E,L = EL
3838

@@ -50,14 +50,12 @@ function dFdE(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
5050
end
5151

5252

53-
function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance::Resonance, df::IsotropicIsochrone)
54-
Ω1,Ω2 = ΩΩ
55-
ndotΩ = resonance.number[1]*Ω1 + resonance.number[2]*Ω2
56-
57-
dFdEval = dFdE(EL,df)
53+
"""DFDL(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)
54+
the isotropic DF derivative w.r.t. L: always zero!
55+
"""
56+
function DFDL(EL::Tuple{Float64,Float64}, df::IsotropicIsochrone)::Float64
5857

59-
# Value of n.dF/dJ
60-
result = ndotΩ*dFdEval
58+
return 0.0
6159

62-
return result
6360
end
61+

src/Analytic/Isochrone/osipkovmerritt.jl

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ end
5151
Saha distribution function
5252
ra is the anisotropy radius
5353
"""
54-
function F(EL::Tuple{Float64,Float64}, df::OsipkovMerrittIsochrone)
54+
function Distribution(EL::Tuple{Float64,Float64}, df::OsipkovMerrittIsochrone)::Float64
5555

5656
Q = osipkovmerritt_Q(EL, df)
5757
scaleDF = dfscale(df)
@@ -93,15 +93,27 @@ function osipkovmerritt_dFdQ(EL::Tuple{Float64,Float64}, df::OsipkovMerrittIsoch
9393

9494
end
9595

96+
function DFDE(EL::Tuple{Float64,Float64}, df::OsipkovMerrittIsochrone)::Float64
9697

98+
Q = osipkovmerritt_Q(EL,df)
9799

98-
function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance::Resonance, df::OsipkovMerrittIsochrone)
100+
# If Q is outside of the [0,1]--range, we set the function to 0.0
101+
# ATTEN TION, this is a lazy implementation -- it would have been much better to restrict the integration domain
102+
if (!(0.0 <= Q <= 1.0)) # If Q is outside of the [0,1]-range, we set the function to 0
103+
return 0.0 # Outside of the physically allowed orbital domain
104+
end
99105

106+
# Value of dF/dQ
107+
dFdQ = osipkovmerritt_dFdQ(EL,df)
108+
109+
# Value of dQ/dE
110+
dQdE = osipkovmerritt_dQdE(EL,df)
111+
112+
return dFdQ * dQdE
113+
end
114+
115+
function DFDL(EL::Tuple{Float64,Float64}, df::OsipkovMerrittIsochrone)::Float64
100116

101-
Ω1,Ω2 = ΩΩ
102-
n1,n2 = resonance.number[1],resonance.number[2]
103-
ndotΩ = n1*Ω1 + n2*Ω2
104-
105117
Q = osipkovmerritt_Q(EL,df)
106118

107119
# If Q is outside of the [0,1]--range, we set the function to 0.0
@@ -113,12 +125,8 @@ function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance
113125
# Value of dF/dQ
114126
dFdQ = osipkovmerritt_dFdQ(EL,df)
115127

116-
# Values of dQ/dE, dQ/dL
117-
dQdE, dQdL = osipkovmerritt_dQdE(EL,df), osipkovmerritt_dQdL(EL,df)
118-
119-
# Value of n.dF/dJ
120-
result = dFdQ*(dQdE*ndotΩ + n2*dQdL)
121-
122-
return result
128+
# Value dQ/dL
129+
dQdL = osipkovmerritt_dQdL(EL,df)
123130

131+
return dFdQ * dQdL
124132
end

src/Analytic/Plummer/isotropic.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313
"""
1414
The distribution function for the isotropic Plummer model
1515
"""
16-
function F(EL::Tuple{Float64,Float64}, df::IsotropicPlummer)
16+
function Distribution(EL::Tuple{Float64,Float64}, df::IsotropicPlummer)
1717
E,L = EL
1818

1919
scaleEnergy = - df.potential.G * df.potential.M / df.potential.bc
@@ -31,7 +31,9 @@ the derivative of the isotropic distribution function
3131
F[EN_] = (24 Sqrt[2])/(7 Pi^3) * EN^(7/2)
3232
D[F[EN], {EN}]
3333
"""
34-
function dFdE(E::Float64,df::IsotropicPlummer)
34+
function DFDE(EL::Tuple{Float64,Float64},df::IsotropicPlummer)
35+
36+
E,L = EL
3537

3638
scaleEnergy = - df.potential.G * df.potential.M / df.potential.bc
3739
scaleDF = dfscale(df)
@@ -42,19 +44,9 @@ function dFdE(E::Float64,df::IsotropicPlummer)
4244

4345
end
4446

47+
function DFDL(EL::Tuple{Float64,Float64},df::IsotropicPlummer)::Float64
4548

46-
"""
47-
calculate n.dF/dE, for the isotropic plummer case.
48-
"""
49-
function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance::Resonance, df::IsotropicPlummer)
50-
E,L = EL
51-
Ω1,Ω2 = ΩΩ
52-
ndotΩ = resonance.number[1]*Ω1 + resonance.number[2]*Ω2
53-
54-
dFdE = dFdE(E,df)
49+
return 0.0
5550

56-
# Value of n.dF/dJ
57-
result = ndotΩ*dFdE
51+
end
5852

59-
return result
60-
end

src/Analytic/Plummer/osipkovmerrit.jl

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
"""
4949
the anisotropic distribution function from PlummerPlus
5050
"""
51-
function F(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)
51+
function Distribution(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)
5252

5353
Q = osipkovmerritt_Q(EL, df)
5454
scaleDF = dfscale(df)
@@ -62,34 +62,26 @@ function F(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)
6262

6363
end
6464

65+
function DFDE(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)::Float64
6566

66-
"""
67-
the derivative of the anisotropic distribution function
68-
"""
69-
function osipkovmerritt_dFdQ(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)
67+
Q = osipkovmerritt_Q(EL, df)
7068

71-
Q = osipkovmerritt_Q(EL, df)
72-
scaleDF = dfscale(df)
69+
# If Q is outside of the [0,1]--range, we set the function to 0.0
70+
# ATTENTION, this is a lazy implementation -- it would have been much better to restrict the integration domain
71+
if (!(0.0 <= Q <= 1.0)) # If Q is outside of the [0,1]-range, we set the function to 0
72+
return 0.0 # Outside of the physically allowed orbital domain
73+
end
7374

74-
# dimensionless anisotropy radius: ALREADY SQUARED
75-
gamma = (df.potential.bc/df.ra)^2
75+
# Value of dF/dQ
76+
dFdQ = osipkovmerritt_dFdQ(EL,df)
7677

77-
prefactor = (df.potential.M/scaleDF) * ((3*sqrt(2))/(4*(pi^3)))
78-
return prefactor * sqrt(Q) * ( (gamma)*(3 - 16(Q^2)) + 16(Q^2))
78+
# Value of dQ/dE, dQ/dL
79+
dQdE = osipkovmerritt_dQdE(EL,df)
7980

81+
return dFdQ*dQdE
8082
end
8183

82-
83-
"""
84-
calculate n.dF/dJ, for the osipkov-merritt plummer case.
85-
86-
@IMPROVE, make a distribution function fix. perhaps only integrate in regions where the DF is positive?
87-
"""
88-
function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance::Resonance, df::OsipkovMerrittPlummer)
89-
90-
Ω1,Ω2 = ΩΩ
91-
n1,n2 = resonance.number[1],resonance.number[2]
92-
ndotΩ = n1*Ω1 + n2*Ω2
84+
function DFDL(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)::Float64
9385

9486
Q = osipkovmerritt_Q(EL, df)
9587

@@ -102,12 +94,26 @@ function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance
10294
# Value of dF/dQ
10395
dFdQ = osipkovmerritt_dFdQ(EL,df)
10496

105-
# Values of dQ/dE, dQ/dL
106-
dQdE, dQdL = osipkovmerritt_dQdE(EL,df), osipkovmerritt_dQdL(EL,df)
97+
# Value of dQ/dL
98+
dQdL = osipkovmerritt_dQdL(EL,df)
99+
100+
return dFdQ*dQdL
101+
end
107102

108-
# Value of n.dF/dJ
109-
result = dFdQ*(dQdE*ndotΩ + n2*dQdL)
110103

111-
return result
104+
"""
105+
the derivative of the anisotropic distribution function
106+
"""
107+
function osipkovmerritt_dFdQ(EL::Tuple{Float64,Float64}, df::OsipkovMerrittPlummer)
108+
109+
Q = osipkovmerritt_Q(EL, df)
110+
scaleDF = dfscale(df)
111+
112+
# dimensionless anisotropy radius: ALREADY SQUARED
113+
gamma = (df.potential.bc/df.ra)^2
114+
115+
prefactor = (df.potential.M/scaleDF) * ((3*sqrt(2))/(4*(pi^3)))
116+
return prefactor * sqrt(Q) * ( (gamma)*(3 - 16(Q^2)) + 16(Q^2))
112117

113118
end
119+

src/Analytic/RazorThinDiscs/mestel.jl

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,32 @@ MestelDisc([potential])
55
66
Mestel disc distribution function.
77
"""
8-
function MestelDisc(;potential::MestelPotential=MestelPotential(),q::IntorFloat=11.44,ξDF::Float64=1.0,G::Float64=1.0)
9-
return MestelDisc(potential,q,ξDF,G)
8+
function MestelDisc(;potential::MestelPotential=MestelPotential(),q::IntorFloat=11.44,G::Float64=1.0)
9+
return MestelDisc(potential,q,G)
1010
end
1111

1212
"""
13-
MestelDF(EL::Tuple{Float64,Float64},df::MestelDisc)
13+
MestelDistribution(EL::Tuple{Float64,Float64},df::MestelDisc)
1414
Mestel distribution function.
1515
"""
16-
function F(EL::Tuple{Float64,Float64},df::MestelDisc)::Float64
16+
function Distribution(EL::Tuple{Float64,Float64},df::MestelDisc)::Float64
1717

18-
return MestelDF(EL,df)
18+
return MestelDistribution(EL,df)
1919
end
2020

2121
"""
2222
dFdE(EL::Tuple{Float64,Float64},df::MestelDisc)
2323
Mestel DF derivative w.r.t. E.
2424
"""
25-
function dFdE(EL::Tuple{Float64,Float64},df::MestelDisc)::Float64
25+
function DFDE(EL::Tuple{Float64,Float64},df::MestelDisc)::Float64
2626
return MesteldFdE(EL,df)
2727
end
2828

2929
"""
3030
dFdL(E, L[, C, q, sigma])
3131
Mestel DF derivative w.r.t. E.
3232
"""
33-
function dFdL(EL::Tuple{Float64,Float64},df::MestelDisc)::Float64
33+
function DFDL(EL::Tuple{Float64,Float64},df::MestelDisc)::Float64
3434
return MesteldFdL(EL,df)
3535
end
3636

37-
38-
"""
39-
ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance::Resonance, df::MestelDisc)
40-
Zang star DF derivative w.r.t. the actions J.
41-
"""
42-
function ndFdJ(EL::Tuple{Float64,Float64},ΩΩ::Tuple{Float64,Float64},resonance::Resonance, df::MestelDisc)::Float64
43-
44-
E,L = EL
45-
Ω1,Ω2 = ΩΩ
46-
n1,n2 = resonance.number
47-
ndotΩ = n1*Ω1 + n2*Ω2
48-
49-
if L <= 0.
50-
println("WARNING: L <= 0.")
51-
return 0.
52-
end
53-
54-
dDFdE = dFdE(EL,df)
55-
dDFdL = dFdL(EL,df)
56-
57-
return df.ξDF * (ndotΩ*dDFdE + n2*dDFdL)
58-
end

src/Analytic/RazorThinDiscs/miyamoto.jl

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using HypergeometricFunctions
1010
1111
Miyamoto distribution function for Kuzmin-Toomre disc.
1212
"""
13-
function miyamoto_distribution(E::Float64, L::Float64; mM::Int64=1)
13+
function Distribution(E::Float64, L::Float64; mM::Int64=1)
1414
return (
1515
(2mM + 3)
1616
* (-E)^(2mM + 2)
@@ -24,7 +24,7 @@ end
2424
2525
Miyamoto distribution derivative w.r.t. energy.
2626
"""
27-
function miyamoto_dFdE(E::Float64, L::Float64; mM::Int64=1)
27+
function DFDE(E::Float64, L::Float64; mM::Int64=1)
2828
return (
2929
E^(2mM)
3030
* (1 + mM)
@@ -42,7 +42,7 @@ end
4242
4343
Miyamoto distribution derivative w.r.t. angular momentum.
4444
"""
45-
function miyamoto_dFdL(E::Float64, L::Float64; mM::Int64=1)
45+
function DFDL(E::Float64, L::Float64; mM::Int64=1)
4646

4747
return -(
4848
2
@@ -56,22 +56,3 @@ function miyamoto_dFdL(E::Float64, L::Float64; mM::Int64=1)
5656
)
5757
end
5858

59-
"""
60-
miyamoto_ndFdJ(n1, n2, E, L, ndotOmega[, mM])
61-
62-
Miyamoto distribution derivatives w.r.t. the actions.
63-
"""
64-
function miyamoto_ndFdJ(
65-
n1::Int64,
66-
n2::Int64,
67-
E::Float64,
68-
L::Float64,
69-
ndotOmega::Float64;
70-
mM::Int64=1
71-
)
72-
73-
dFdE = miyamoto_dFdE(E, L; mM=mM)
74-
dFdL = miyamoto_dFdL(E, L; mM=mM)
75-
76-
return ndotOmega*dFdE + n2*dFdL
77-
end

0 commit comments

Comments
 (0)