Skip to content

Commit 686b26d

Browse files
author
Christian Haack
committed
refactor scattering functions for improved type handling and clarity in documentation
1 parent 5d06336 commit 686b26d

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

src/CherenkovMediumBase.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ radiation_length(medium::MediumProperties) = _not_implemented(medium)
6565
"""
6666
sample_scattering_function(medium::MediumProperties)
6767
68-
Return a scattering angle sampled from the scattering function of the medium.
68+
Return a cos(scattering angle) sampled from the scattering function of the medium.
6969
"""
7070
function sample_scattering_function(medium::MediumProperties)
7171
model = get_scattering_model(medium)
@@ -101,7 +101,7 @@ Return the phase refractive index at `wavelength`.
101101
`wavelength` is expected to be in units nm.
102102
"""
103103
function phase_refractive_index(medium::MediumProperties, wavelength)
104-
model =get_dispersion_model(medium)
104+
model = get_dispersion_model(medium)
105105
return phase_refractive_index(model, wavelength)
106106
end
107107

src/dispersion.jl

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Helper function to get the parameters for the Quan & Fry formula as function of
2525
salinity, temperature and pressure.
2626
"""
2727
function calc_quan_fry_params(
28-
salinity::Real,
29-
temperature::Real,
30-
pressure::Real)
28+
salinity::T,
29+
temperature::T,
30+
pressure::T) where {T <: Real}
3131

3232
n0 = 1.31405
3333
n1 = 1.45e-5
@@ -54,11 +54,12 @@ function calc_quan_fry_params(
5454
a3 = -n9
5555
a4 = n10
5656

57-
return a01, a2, a3, a4
57+
return T(a01), T(a2), T(a3), T(a4)
5858
end
5959

60+
6061
"""
61-
refractive_index_fry(wavelength, salinity, temperature, pressure)
62+
_refractive_index_fry(wavelength, quan_fry_params)
6263
6364
The phase refractive index of sea water according to a model
6465
from Quan & Fry.
@@ -76,14 +77,6 @@ downloaded Jan 2011 from: http://www.physics.ox.ac.uk/Users/schuster/thesis0098m
7677
7778
Adapted from clsim (https://github.com/claudiok/clsim)
7879
"""
79-
function _refractive_index_fry(
80-
wavelength::T;
81-
salinity::Real,
82-
temperature::Real,
83-
pressure::Real) where {T<:Real}
84-
refractive_index_fry(wavelength, T.(calc_quan_fry_params(salinity, temperature, pressure)))
85-
end
86-
8780
function _refractive_index_fry(
8881
wavelength::Real,
8982
quan_fry_params::Tuple{U,U,U,U}
@@ -94,26 +87,10 @@ function _refractive_index_fry(
9487
end
9588

9689
"""
97-
dispersion_fry(
98-
wavelength::T;
99-
salinity::Real,
100-
temperature::Real,
101-
pressure::Real) where {T <: Real}
90+
dispersion_fry(wavelength, a2, a3, a4)
10291
103-
Calculate the dispersion (dn/dλ) for the Quan & Fry model.
104-
Wavelength is given in nm, salinity in permille, temperature in °C and pressure in atm
92+
Calculate the dispersion for the Quan & Fry dispersion model.
10593
"""
106-
function dispersion_fry(
107-
wavelength::T;
108-
salinity::Real,
109-
temperature::Real,
110-
pressure::Real) where {T<:Real}
111-
112-
quan_fry_params = T.(calc_quan_fry_params(salinity, temperature, pressure))
113-
114-
dispersion_fry(wavelength, quan_fry_params[2], quan_fry_params[3], quan_fry_params[4])
115-
end
116-
11794
function dispersion_fry(wavelength::T, a2, a3, a4) where {T<:Number}
11895
x = one(T) / wavelength
11996

src/scattering.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ using Distributions
22
using Random: AbstractRNG
33
using Polynomials: fit, Polynomial, ImmutablePolynomial
44

5+
# Scattering functions
56
export AbstractScatteringFunction
6-
export AbstractScatteringModel
77
export HenyeyGreenStein
88
export PolynomialScatteringFunction
99
export EinsteinSmoluchowsky
@@ -12,6 +12,8 @@ export TwoComponentScatteringFunction
1212
export MixedHGES
1313
export MixedHGSL
1414

15+
# Scattering models
16+
export AbstractScatteringModel
1517
export KopelevichScatteringModel
1618
export WavelengthIndependentScatteringModel
1719

@@ -69,7 +71,7 @@ Implementation from: https://user-web.icecube.wisc.edu/~dima/work/WISC/ppc/spice
6971
function sl_scattering_func(rng::AbstractRNG, g::T) where {T <: Real}
7072
eta = Base.rand(rng, T)
7173
beta = (1-g) / (1+g)
72-
costheta::T = 2 * eta^beta - 1
74+
costheta::T = T(2) * eta^beta - T(1)
7375
return clamp(costheta, T(-1), T(1))
7476
end
7577

@@ -138,7 +140,7 @@ end
138140
"""
139141
TwoComponentScatteringFunction{F1<:AbstractScatteringFunction, F2<:AbstractScatteringFunction}
140142
141-
Struct for two-component scattering model.
143+
Struct for two-component mixture scattering model.
142144
"""
143145
struct TwoComponentScatteringFunction{F1<:AbstractScatteringFunction, F2<:AbstractScatteringFunction,T} <: AbstractScatteringFunction
144146
f1::F1

0 commit comments

Comments
 (0)