/
e2phot.jl
45 lines (37 loc) · 1.12 KB
/
e2phot.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
###############################################################################
#
# Convert energy to photons
#
###############################################################################
_FAC(FT) = FT(1e-9) / (H_PLANCK(FT) * LIGHT_SPEED(FT) * AVOGADRO(FT))
"""
e2phot(λ::Array{FT}, E::Array{FT}) where {FT<:AbstractFloat}
Calculates the number of moles of photons, given
- `λ` An array of wave length in `[nm]`, converted to `[m]` by _FAC
- `E` Joules of energy
"""
function e2phot(
λ::Array{FT},
E::Array{FT}
) where {FT<:AbstractFloat}
return (E .* λ) .* _FAC(FT)
end
"""
e2phot!(
λ::Array{FT,1},
E::Array{FT,1},
cache::Array{FT,1}
) where {FT<:AbstractFloat}
Calculates the number of moles of photons, given
- `λ` An array of wave length in `[nm]`, converted to `[m]` by _FAC
- `E` Joules of energy
- `cache` Cache to avoid memory allocations
"""
function e2phot!(
λ::Array{FT,1},
E::Array{FT,1},
cache::Array{FT,1}
) where {FT<:AbstractFloat}
cache .= (E .* λ) .* _FAC(FT);
return nothing
end