Skip to content

Commit

Permalink
add dispersion and scattering model functions; rename TwoComponentSca…
Browse files Browse the repository at this point in the history
…tteringModel to TwoComponentScatteringFunction
  • Loading branch information
Christian Haack committed Jan 24, 2025
1 parent 55fecb6 commit ec1958f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
34 changes: 30 additions & 4 deletions src/CherenkovMediumBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ abstract type MediumProperties end

_not_implemented(type) = error("Not implemented for type $(typeof(type))")

"""
get_dispersion_model(medium::MediumProperties)
Return the dispersion model for a given medium.
"""
get_dispersion_model(medium::MediumProperties) = _not_implemented(medium)


"""
get_scattering_model(medium::MediumProperties)
Return the scattering model for a given medium.
"""
get_scattering_model(medium::MediumProperties) = _not_implemented(medium)

"""
pressure(medium::MediumProperties)
Expand Down Expand Up @@ -47,15 +60,22 @@ radiation_length(medium::MediumProperties) = _not_implemented(medium)
Return a scattering angle sampled from the scattering function of the medium.
"""
sample_scattering_function(medium::MediumProperties) = _not_implemented(medium)
function sample_scattering_function(medium::MediumProperties)
model = scattering_model(medium)


end

"""
scattering_length(medium::MediumProperties, wavelength)
Return scattering length at `wavelength` in units m.
`wavelength` is expected to be in units nm. Returned length is in units m.
"""
scattering_length(medium::MediumProperties, wavelength) = _not_implemented(medium)
function scattering_length(medium::MediumProperties, wavelength)
model = get_scattering_model(medium)
return scattering_length(model, wavelength)
end

"""
absorption_length(medium::MediumProperties, wavelength)
Expand All @@ -71,15 +91,21 @@ absorption_length(medium::MediumProperties, wavelength) = _not_implemented(mediu
Return the phase refractive index at `wavelength`.
`wavelength` is expected to be in units nm.
"""
phase_refractive_index(medium::MediumProperties, wavelength) = _not_implemented(medium)
function phase_refractive_index(medium::MediumProperties, wavelength)
model =get_dispersion_model(medium)
return phase_refractive_index(model, wavelength)
end

"""
dispersion(medium::MediumProperties, wavelength)
Return the dispersion dn/dλ at `wavelength` in units 1/nm.
`wavelength` is expected to be in units nm.
"""
dispersion(medium::MediumProperties, wavelength) = _not_implemented(medium)
function dispersion(medium::MediumProperties, wavelength)
model = get_dispersion_model(medium)
return dispersion(model, wavelength)
end

"""
cherenkov_angle(medium, wavelength)
Expand Down
18 changes: 12 additions & 6 deletions src/scattering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export HenyeyGreenStein
export PolynomialScatteringFunction
export EinsteinSmoluchowsky
export SimplifiedLiu
export TwoComponentScatteringModel
export TwoComponentScatteringFunction
export MixedHGES
export MixedHGSL

Expand Down Expand Up @@ -136,22 +136,22 @@ function EinsteinSmoluchowsky(b::T) where {T}
end

"""
TwoComponentScatteringModel{F1<:AbstractScatteringFunction, F2<:AbstractScatteringFunction}
TwoComponentScatteringFunction{F1<:AbstractScatteringFunction, F2<:AbstractScatteringFunction}
Struct for two-component scattering model.
"""
struct TwoComponentScatteringModel{F1<:AbstractScatteringFunction, F2<:AbstractScatteringFunction} <: AbstractScatteringFunction
struct TwoComponentScatteringFunction{F1<:AbstractScatteringFunction, F2<:AbstractScatteringFunction} <: AbstractScatteringFunction
f1::F1
f2::F2
fraction::Real
end


MixedHGES(g, b, fraction) = TwoComponentScatteringModel(HenyeyGreenStein(g), EinsteinSmoluchowsky(b), fraction)
MixedHGSL(g, fraction) = TwoComponentScatteringModel(HenyeyGreenStein(g), SimplifiedLiu(g), fraction)
MixedHGES(g, b, fraction) = TwoComponentScatteringFunction(HenyeyGreenStein(g), EinsteinSmoluchowsky(b), fraction)
MixedHGSL(g, fraction) = TwoComponentScatteringFunction(HenyeyGreenStein(g), SimplifiedLiu(g), fraction)


function Base.rand(rng::AbstractRNG, s::TwoComponentScatteringModel)
function Base.rand(rng::AbstractRNG, s::TwoComponentScatteringFunction)
choice = Base.rand(rng, Float64)
if choice < s.fraction
return Base.rand(rng, s.f1)
Expand Down Expand Up @@ -189,6 +189,12 @@ end

abstract type AbstractScatteringModel end
scattering_length(model::AbstractScatteringModel, wavelength::Real) = _not_implemented(model)
get_scattering_function(model::AbstractScatteringModel) = _not_implemented(model)

function sample_scattering_function(model::AbstractScatteringModel)
func = get_scattering_function(model)
return rand(func)
end

"""
KopelevichScatteringModel{F<:AbstractScatteringFunction, T}
Expand Down

0 comments on commit ec1958f

Please sign in to comment.