-
Notifications
You must be signed in to change notification settings - Fork 0
/
MieTransitionMatrix.jl
96 lines (80 loc) · 3.54 KB
/
MieTransitionMatrix.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@doc raw"""
According to Eq. (5.42) -- Eq. (5.44) in Mishchenko et al. (2002), the T-Matrix for a Mie particle can be written as:
```math
\begin{array}{l}
T_{m n m^{\prime} n^{\prime}}^{12}(P) \equiv 0, \quad T_{m n m^{\prime} n^{\prime}}^{21}(P) \equiv 0, \\
T_{m n m^{\prime} n^{\prime}}^{11}(P)=-\delta_{m m^{\prime}} \delta_{n n^{\prime}} b_n, \\
T_{m n m^{\prime} n^{\prime}}^{22}(P)=-\delta_{m m^{\prime}} \delta_{n n^{\prime}} a_n .
\end{array}
```
```
MieTransitionMatrix{CT, N}(x::Real, m::Number)
```
Generate the T-Matrix from the Mie coefficients of a homogeneous sphere.
```
MieTransitionMatrix{CT, N}(x_core::Real, x_mantle::Real, m_core::Number, m_mantle::Number)
```
Generate the T-Matrix from the Mie coefficients of a coated sphere.
This struct provides the T-Matrix API for a Mie particle.
"""
struct MieTransitionMatrix{CT, N, V <: AbstractVector{CT}} <:
AbstractTransitionMatrix{CT, N}
a::V
b::V
end
function MieTransitionMatrix{CT, N}(x::Real, m::Number) where {CT, N}
T = real(CT)
a, b = bhmie(T, x, m; nₘₐₓ = N)
MieTransitionMatrix{CT, N, Vector{CT}}(a, b)
end
function MieTransitionMatrix{CT, N}(x_core::Real, x_mantle::Real, m_core::Number,
m_mantle::Number) where {CT, N}
T = real(CT)
a, b = bhcoat(T, x_core, x_mantle, m_core, m_mantle; nₘₐₓ = N)
MieTransitionMatrix{CT, N, Vector{CT}}(a, b)
end
Base.@propagate_inbounds function Base.getindex(mie::MieTransitionMatrix{CT, N, V},
m::Integer, n::Integer, m′::Integer,
n′::Integer, p::Integer,
p′::Integer) where {CT, N, V}
if m != m′ || n != n′ || p != p′ || abs(m) > n
zero(CT)
else
p == 1 ? -mie.b[n] : -mie.a[n]
end
end
"""
```
rotate(mie::MieTransitionMatrix, ::Rotation{3})
```
The T-Matrix of a Mie scatterer is invariant under rotation. Therefore, the original T-Matrix will be returned.
"""
rotate(mie::MieTransitionMatrix, ::Rotation{3}) = mie
"""
```
orientation_average(mie::MieTransitionMatrix, _pₒ; _kwargs...)
```
The T-Matrix of a Mie scatterer is invariant under rotation. Therefore, the original T-Matrix will be returned.
"""
orientation_average(mie::MieTransitionMatrix, _pₒ; _kwargs...) = mie
@testitem "MieTransitionMatrix" begin
using TransitionMatrices: MieTransitionMatrix, RotZYZ, TransitionMatrix, rotate
@testset "of a homogeneous sphere remains the same under rotations" begin
𝐓 = MieTransitionMatrix{ComplexF64, 5}(1.0, 1.311)
@test all(isapprox.(𝐓,
rotate(TransitionMatrix{ComplexF64, 5, typeof(𝐓)}(𝐓),
RotZYZ(0.2, 0.3, 0.4)); atol = eps(Float64)))
@test all(isapprox.(𝐓,
rotate(TransitionMatrix{ComplexF64, 5, typeof(𝐓)}(𝐓),
RotZYZ(0.8, 0.0, -1.0)); atol = eps(Float64)))
end
@testset "of a coated sphere remains the same under rotations" begin
𝐓 = MieTransitionMatrix{ComplexF64, 5}(0.4, 0.8, 1.0, 1.311)
@test all(isapprox.(𝐓,
rotate(TransitionMatrix{ComplexF64, 5, typeof(𝐓)}(𝐓),
RotZYZ(0.2, 0.3, 0.4)); atol = eps(Float64)))
@test all(isapprox.(𝐓,
rotate(TransitionMatrix{ComplexF64, 5, typeof(𝐓)}(𝐓),
RotZYZ(0.8, 0.0, -1.0)); atol = eps(Float64)))
end
end