Discrete ordinates Jacobian, node response matrices, adding and doubling, and node approximations for polarized 1D radiative transfer
DefinitionArxiv1705_08274_BasicObjects of Sections I-II and Appendix B of Ganapol (2017), arXiv:1705.08274.
- Discrete ordinates model (eqs. (1a)-(3g)). A homogeneous node is described by quadrature directions , weights , an albedo and a scattering matrix factor with . A half-range Stokes vector has components, indexed by a direction and a Stokes component ( or ). The matrices are , , and , whose block of size is .
- Jacobian (eq. (5c)). For the discrete ordinates equations are with
- Node propagator and response (eqs. (6a)-(11b), (43)). Over a node of width , . For a propagator the response matrix is . It maps the incoming intensities to the outgoing intensities . For a scheme the response matrix is . A response matrix is symmetric if its diagonal blocks are equal () and its off-diagonal blocks are equal ().
- Adding (eqs. (28b)-(28d)). For a composite with response and an added node with response , the paper sets , , and . Applied to two full response matrices, adding uses the and blocks of each. The adding sequence of identical nodes starts from the empty slab (, so ). The doubling sequence combines two copies of the previous response: , . An adding step is admissible when is invertible.
- Boundary reflection (eq. (32b)). is the array all of whose blocks equal the reflection matrix .
- Node approximations (Section II.A). The Padé polynomials are and , with . The RK5 matrix , with , is one Fehlberg fifth-order step for , with the coefficients of Table 1.
Formalization Note Vectors of length are indexed by pairs (direction, Stokes component), and block matrices by the disjoint union of two copies of that index set, upper block . The matrix exponential is Mathlib's NormedSpace.exp. The Padé coefficient uses ; the paper prints , which is for . Matrix inverses that the paper takes for granted are written as hypotheses in the statements that use them.
import Mathlib
/-!
B. D. Ganapol, *A 1D Radiative Transfer Benchmark with Polarization via Doubling and Adding*,
arXiv:1705.08274v1 (2017): the discrete ordinates Jacobian of Sections I.A-I.B (eqs. (1a)-(5c)),
the single node response matrix of Section I.C (eqs. (6a)-(11b)), the adding recurrence and
doubling of Sections I.D-I.E (eqs. (25a)-(37b)), and the node propagators of Section II.A
(diamond difference, Padé, RK5; eqs. (40)-(54), Table 1) and Appendix B (eq. (B1)).
Throughout, a vector of `2N` components (eqs. (3a,b)) is indexed by `Dir N = Fin N × Fin 2`
(direction `m`, Stokes component `I` or `Q`), and a matrix of order `4N` acting on the stacked
vector `Y = [I⁺; I⁻]` (eq. (5a)) is a block matrix indexed by `Dir N ⊕ Dir N`, upper block `I⁺`.
-/
open Matrix
noncomputable section
namespace Arxiv1705_08274
/-- Eqs. (3a,b): index set of an unrolled half-range Stokes vector, direction `m ∈ {1,…,N}` and
Stokes component `i ∈ {I, Q}` (a vector of length `2N`). -/
abbrev Dir (N : ℕ) : Type := Fin N × Fin 2
/-- Sections I.A-I.B, eqs. (1a)-(3g): the data of the discrete ordinates model of a homogeneous
node: positive quadrature directions `μ_m`, quadrature weights `w_m` (written `ω_m` in eq. (3e)),
single scatter albedo `ω`, and the `2 × 2` scattering matrix factor `Q(μ)` of eq. (1a). -/
structure DOModel (N : ℕ) where
/-- Quadrature directions `μ_m > 0`, eq. (2a). -/
mu : Fin N → ℝ
/-- Quadrature weights, eq. (2b). -/
wt : Fin N → ℝ
/-- Single scatter albedo `ω`, eq. (1a). -/
albedo : ℝ
/-- Scattering matrix factor `Q(μ)`, eq. (1a). -/
scat : ℝ → Matrix (Fin 2) (Fin 2) ℝ
/-- Sections I.A-I.B and II.B: the standing assumptions on the model: directions
`0 < μ_m ≤ 1`, weights `w_m ≥ 0` (Section II.B adds the beam direction with weight `ε` and
Section II.D adds edit directions with weight `0`), albedo `0 ≤ ω ≤ 1`, and the scattering
symmetry `Q(-μ) = Q(μ)` of eq. (1b). -/
def DOModel.Admissible {N : ℕ} (S : DOModel N) : Prop :=
(∀ m, 0 < S.mu m ∧ S.mu m ≤ 1) ∧ (∀ m, 0 ≤ S.wt m) ∧ 0 ≤ S.albedo ∧ S.albedo ≤ 1 ∧
∀ x, S.scat (-x) = S.scat x
/-- Eq. (3f): `M = diag{μ_m I₂}`. -/
def DOModel.muMat {N : ℕ} (S : DOModel N) : Matrix (Dir N) (Dir N) ℝ :=
diagonal fun p => S.mu p.1
/-- Eq. (3e): `W = diag{w_m I₂}`. -/
def DOModel.wMat {N : ℕ} (S : DOModel N) : Matrix (Dir N) (Dir N) ℝ :=
diagonal fun p => S.wt p.1
/-- Eq. (3g): the matrix of `2 × 2` blocks `P = (ω/2) {Q(μ_m) Qᵀ(μ_m')}`. -/
def DOModel.scatMat {N : ℕ} (S : DOModel N) : Matrix (Dir N) (Dir N) ℝ :=
fun p q => S.albedo / 2 * (S.scat (S.mu p.1) * (S.scat (S.mu q.1))ᵀ) p.2 q.2
/-- Eqs. (5c), (18a), (A1): the block `α = η₁₁⁽¹⁾ = M⁻¹(I - PW)`. -/
def DOModel.alpha {N : ℕ} (S : DOModel N) : Matrix (Dir N) (Dir N) ℝ :=
S.muMat⁻¹ * (1 - S.scatMat * S.wMat)
/-- Eqs. (5c), (18a), (A1): the block `β = η₁₂⁽¹⁾ = M⁻¹PW`. -/
def DOModel.beta {N : ℕ} (S : DOModel N) : Matrix (Dir N) (Dir N) ℝ :=
S.muMat⁻¹ * (S.scatMat * S.wMat)
/-- Eq. (5c): the constant Jacobian `A = [[M⁻¹(I - PW), -M⁻¹PW], [M⁻¹PW, -M⁻¹(I - PW)]]` of
`dY/dτ + AY = 0` (eq. (5b)) for the stacked vector `Y = [I⁺; I⁻]`. -/
def DOModel.jacobian {N : ℕ} (S : DOModel N) : Matrix (Dir N ⊕ Dir N) (Dir N ⊕ Dir N) ℝ :=
fromBlocks S.alpha (-S.beta) S.beta (-S.alpha)
/-- Eq. (32b): the `N × N` array `𝒟` all of whose `2 × 2` blocks equal the reflection matrix
`D` of eq. (1e). -/
def reflArray {N : ℕ} (D : Matrix (Fin 2) (Fin 2) ℝ) : Matrix (Dir N) (Dir N) ℝ :=
fun p q => D p.2 q.2
section Blocks
variable {n : Type*} [Fintype n] [DecidableEq n]
/-- Eqs. (6a), (7), (17): the exact node propagator `e^{-Ah}` over a homogeneous node of width
`h` (the matrix exponential). -/
def nodeExp (A : Matrix (n ⊕ n) (n ⊕ n) ℝ) (h : ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
NormedSpace.exp (-(h • A))
/-- Eq. (11b): the response matrix of a node with propagator `E = [[E₁₁, E₁₂], [E₂₁, E₂₂]]`
(`Y_{j+1} = E Y_j`): `R = [[E₁₂, -I], [E₂₂, 0]]⁻¹ [[0, -E₁₁], [I, -E₂₁]]`, mapping
`[I⁻_{j+1}; I⁺_j]` to `[I⁻_j; I⁺_{j+1}]` (eq. (11a)). -/
def respOfProp (E : Matrix (n ⊕ n) (n ⊕ n) ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
(fromBlocks E.toBlocks₁₂ (-1) E.toBlocks₂₂ 0)⁻¹ *
fromBlocks 0 (-E.toBlocks₁₁) 1 (-E.toBlocks₂₁)
/-- Eqs. (43), (B1): the response matrix of a node propagated by `Y_{j+1} = P*⁻¹ P Y_j`:
`R = [[-P₁₂, P*₁₁], [-P₂₂, P*₂₁]]⁻¹ [[-P*₁₂, P₁₁], [-P*₂₂, P₂₁]]`. -/
def respOfPair (Ps P : Matrix (n ⊕ n) (n ⊕ n) ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
(fromBlocks (-P.toBlocks₁₂) Ps.toBlocks₁₁ (-P.toBlocks₂₂) Ps.toBlocks₂₁)⁻¹ *
fromBlocks (-Ps.toBlocks₁₂) P.toBlocks₁₁ (-Ps.toBlocks₂₂) P.toBlocks₂₁
/-- Eqs. (13)-(14): a response matrix is symmetric (in the paper's sense) when its diagonal
blocks agree (`T_n`) and its off-diagonal blocks agree (`R_f`). -/
def IsSymmetricResponse (R : Matrix (n ⊕ n) (n ⊕ n) ℝ) : Prop :=
R.toBlocks₁₁ = R.toBlocks₂₂ ∧ R.toBlocks₁₂ = R.toBlocks₂₁
/-- Eq. (28c): `w_{m,l} = [[I, -Q_{l-1,2}], [-R_f, I]]`. -/
def wMinus (Q2 Rf : Matrix n n ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
fromBlocks 1 (-Q2) (-Rf) 1
/-- Eq. (28c): `w_{p,l} = [[0, Q_{l-1,1}], [T_n, 0]]`. -/
def wPlus (Q1 Tn : Matrix n n ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
fromBlocks 0 Q1 Tn 0
/-- Eq. (28b): `U_l = w_{m,l}⁻¹ w_{p,l}`, for a composite with symmetric response
`[[Q₁, Q₂], [Q₂, Q₁]]` (eq. (25b)) and an added node with response `[[T_n, R_f], [R_f, T_n]]`. -/
def addU (Q1 Q2 Tn Rf : Matrix n n ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
(wMinus Q2 Rf)⁻¹ * wPlus Q1 Tn
/-- Eq. (28d): the combined response `Q_l = [[0, Q_{l-1,1}], [T_n, 0]] U_l + [[0, Q_{l-1,2}],
[R_f, 0]]`. -/
def addQ (Q1 Q2 Tn Rf : Matrix n n ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
wPlus Q1 Tn * addU Q1 Q2 Tn Rf + fromBlocks 0 Q2 Rf 0
/-- Section I.D, eqs. (25b), (28b) and the paragraph after (29b): the matrix `U_l` for adding
a composite (or node) with response `R` to a composite with response `Q`, both taken in the
symmetric form, i.e. `Q_{l-1,1} = Q₁₁`, `Q_{l-1,2} = Q₁₂`, `T_n = R₁₁`, `R_f = R₁₂`. -/
def addRespU (Q R : Matrix (n ⊕ n) (n ⊕ n) ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
addU Q.toBlocks₁₁ Q.toBlocks₁₂ R.toBlocks₁₁ R.toBlocks₁₂
/-- Section I.D, eqs. (25b), (28d) and the paragraph after (29b): the combined response of a
composite with response `Q` followed by a composite (or node) with response `R`, both taken in
the symmetric form. -/
def addResp (Q R : Matrix (n ⊕ n) (n ⊕ n) ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
addQ Q.toBlocks₁₁ Q.toBlocks₁₂ R.toBlocks₁₁ R.toBlocks₁₂
/-- Eq. (28b) (implicit "suitable invertibility"): the matrix `w_{m,l}` of the adding step of
`R` to `Q` is invertible. -/
def CanAdd (Q R : Matrix (n ⊕ n) (n ⊕ n) ℝ) : Prop :=
IsUnit (wMinus Q.toBlocks₁₂ R.toBlocks₁₂).det
/-- Section I.E.2, eq. (35): the cumulative response `Q_l` of `l` identical nodes of response
`R`, added one at a time with eqs. (28). `Q_0 = I` is the response of an empty slab, so
`Q_1 = R`. -/
def addSeq (R : Matrix (n ⊕ n) (n ⊕ n) ℝ) : ℕ → Matrix (n ⊕ n) (n ⊕ n) ℝ
| 0 => 1
| l + 1 => addResp (addSeq R l) R
/-- Section I.E.1: the response after `k` doublings of a node of response `R`
(`Q_0 = R`, `Q_{k+1}` combines two copies of `Q_k` with eqs. (28)), i.e. of `2^k` nodes. -/
def dblSeq (R : Matrix (n ⊕ n) (n ⊕ n) ℝ) : ℕ → Matrix (n ⊕ n) (n ⊕ n) ℝ
| 0 => R
| k + 1 => addResp (dblSeq R k) (dblSeq R k)
/-- Eqs. (46b,c): the coefficient `(2q - j)! q! / ((2q)! j! (q - j)!)` of the `(q,q)` Padé
approximant of the exponential (Moler and Van Loan, Ref. 13; the paper prints `(q - j)` for
`(q - j)!`). -/
def padeCoeff (q j : ℕ) : ℝ :=
((2 * q - j).factorial * q.factorial : ℝ) /
((2 * q).factorial * j.factorial * (q - j).factorial)
/-- Eq. (46b): `N_q(h) = I + ∑_{j=1}^q (-1)^j c_{q,j} A^j h^j`. -/
def padeNum (A : Matrix (n ⊕ n) (n ⊕ n) ℝ) (h : ℝ) (q : ℕ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
1 + ∑ j ∈ Finset.Icc 1 q, ((-1) ^ j * padeCoeff q j * h ^ j) • A ^ j
/-- Eq. (46c): `D_q(h) = I + ∑_{j=1}^q c_{q,j} A^j h^j`. -/
def padeDen (A : Matrix (n ⊕ n) (n ⊕ n) ℝ) (h : ℝ) (q : ℕ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
1 + ∑ j ∈ Finset.Icc 1 q, (padeCoeff q j * h ^ j) • A ^ j
/-- Eqs. (51c,d), (52a,b), Table 1: one step of Fehlberg's fifth-order Runge-Kutta method of
size `h` for `dξ/dτ = (A/2) ξ`, written as the matrix `P*(h) = I + ∑ b_i g_i(h)` with
`g_i(h) = (h/2) A [I + ∑_{n<i} a_{in} g_n(h)]`. -/
def rk5Pstar (A : Matrix (n ⊕ n) (n ⊕ n) ℝ) (h : ℝ) : Matrix (n ⊕ n) (n ⊕ n) ℝ :=
let K := (h / 2) • A
let g1 := K
let g2 := K * (1 + (1 / 4 : ℝ) • g1)
let g3 := K * (1 + (3 / 32 : ℝ) • g1 + (9 / 32 : ℝ) • g2)
let g4 := K * (1 + (1932 / 2197 : ℝ) • g1 + (-7200 / 2197 : ℝ) • g2 + (7296 / 2197 : ℝ) • g3)
let g5 := K * (1 + (439 / 216 : ℝ) • g1 + (-8 : ℝ) • g2 + (3680 / 513 : ℝ) • g3 +
(-845 / 4104 : ℝ) • g4)
let g6 := K * (1 + (-8 / 27 : ℝ) • g1 + (2 : ℝ) • g2 + (-3544 / 2565 : ℝ) • g3 +
(1859 / 4104 : ℝ) • g4 + (-11 / 40 : ℝ) • g5)
1 + (16 / 135 : ℝ) • g1 + (0 : ℝ) • g2 + (6656 / 12825 : ℝ) • g3 + (28561 / 56430 : ℝ) • g4 +
(-9 / 50 : ℝ) • g5 + (2 / 55 : ℝ) • g6
end Blocks
end Arxiv1705_08274
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Index set . For a natural number , is the set of pairs with and , so it has elements. When it is empty. Throughout, "" means two disjoint copies of : a first ("upper") copy and a second ("lower") copy, elements in all.
Model data . A model with directions consists of four components, with no constraints imposed by the structure itself:
- a real number for each (directions);
- a real number for each such (weights);
- a real number (albedo);
- a function assigning a real matrix, indexed by , to every real number.
Admissibility. A model is called admissible when all of the following hold:
- for every ;
- for every ;
- ;
- for every real .
Nothing further is required. The directions need not be distinct, the weights need not sum to any particular value (they may all be ), and is allowed. When the first two conditions are vacuous.
Direction matrix . For a model , is the real diagonal matrix indexed by whose diagonal entry at is . Each thus appears twice, once for and once for , and all off-diagonal entries are .
Weight matrix . For a model , is the real diagonal matrix indexed by whose diagonal entry at is , with all off-diagonal entries .
Scattering matrix . For a model , is the real matrix indexed by with entries
That is, its block for the pair of directions is . No admissibility is assumed.
Block . For a model ,
where is the identity matrix on . Here is the true inverse when is invertible, that is, when every . By convention it is the zero matrix otherwise, in which case . No admissibility is assumed.
Block . For a model ,
is the true inverse when every and the zero matrix otherwise, in which case . No admissibility is assumed.
Jacobian . For a model , is the real matrix indexed by given in block form (upper copy first) by
with and as above. When some , the convention makes . No admissibility is assumed.
Reflection array . Given and a real matrix indexed by , is the matrix indexed by with
for all . Every block of equals , whether or not .
Conventions for the remaining declarations. In what follows, is an arbitrary finite index type with decidable equality, possibly empty. All matrices are real and indexed by , two copies of with the first copy "upper". For such a matrix :
- denote its four blocks: rows from the first or second copy, columns from the first or second copy.
- denotes an identity matrix and a zero matrix.
- denotes the true inverse when is invertible (determinant nonzero) and the zero matrix otherwise.
Node exponential. For a matrix indexed by and any real (negative and zero included),
the matrix exponential, given by the convergent power series .
Response from a propagator. For a matrix indexed by , with blocks ,
If the first block matrix is singular, its "inverse" is the zero matrix and . No hypothesis on is imposed.
Response from a pair. For two matrices and indexed by ,
If the first block matrix is singular, its "inverse" is the zero matrix and . No hypothesis on or is imposed.
Symmetric response. A matrix indexed by is called a symmetric response when
Both conditions are required. Ordinary transpose-symmetry is not involved.
Matrix . For matrices and ,
Matrix . For matrices and ,
Adding matrix . For matrices ,
If is singular, .
Added response . For matrices ,
with as above. If is singular, and the result is just .
Adding matrix for two responses. For matrices and indexed by ,
Only the upper blocks enter; are ignored entirely. Neither nor is required to be a symmetric response. The inverse is zero if the matrix is singular.
Added response of two responses. For matrices and indexed by ,
Only the blocks are used; the lower blocks of and are ignored, and no symmetry of or is assumed. If the middle matrix is singular, its "inverse" is and the result is .
Addability. For matrices and indexed by , " can be added to " means
that is, this matrix is invertible. Only and matter. If is empty, the determinant is and the condition holds.
Adding sequence. For a matrix indexed by , the sequence is defined by
using the added response above, with its zero-inverse convention whenever a step's matrix is singular. Unwinding the first step, the matrix is always invertible, and
This equals exactly when and . No hypothesis on is imposed, and only and ever enter the sequence.
Doubling sequence. For a matrix indexed by , the sequence is defined by
using the added response above, with the zero-inverse convention at singular steps. For the result depends only on and , and no hypothesis on is imposed.
Padé coefficient. For natural numbers and , is the real number
where the subtractions and are truncated at : they equal whenever the true difference would be negative. Consequently, for the formula is still defined but uses , and if . The denominator is always positive.
Padé numerator. For a matrix indexed by , a real and a natural number ,
with as above. For the sum is empty and . No combination is defined here.
Padé denominator. For a matrix indexed by , a real and a natural number ,
with as above. For , .
Runge–Kutta propagator . For a matrix indexed by and any real , set and define
The result is
All products are matrix products with on the left. Nothing relates to or to any accuracy property within these definitions.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.