Algorithm Search⌘K

Algorithmcore

Discrete ordinates method

Also called SN method.

Solves the transport equation along a finite set of directions with quadrature weights, sweeping each direction through the mesh.

Time
O(I N M) worst
Space
O(N M) extra
Where
I = the number of source iterations; M = the number of cells; N = the number of directions
Properties
deterministicnot exactiterativenot randomized
Origin
G. C. Wick, S. Chandrasekhar, B. G. Carlson, 1943

The discrete ordinates method, or SNS_N method, solves the linear Boltzmann transport equation on a finite set of NN directions. It replaces the integral of the angular flux over all directions by a quadrature with weights, so the equation becomes NN transport equations, one per direction, coupled only through the scattering source. Each of these is solved by a sweep through the mesh in the direction of flight, and the coupling is handled by source iteration. The spherical harmonics method expands the angular flux in moments instead of sampling it at points, the method of characteristics sweeps along long tracks instead of through cells, and Monte Carlo transport follows random particle histories.

In plain words

Particles fly in every direction, so the unknown depends on position and on direction. The method keeps only a few directions, for example eight, chosen so that a sum over them with fixed weights gives the total over all directions very accurately.

For one direction the problem is easy. Particles that fly to the right only depend on what is to their left, so you start at the left edge and walk through the cells one by one to the right. In each cell you compute how many particles come out from how many go in and how many are made inside.

The particles that scatter change direction, so the directions are linked. You guess the scattered particles, walk all directions, add them up with the weights to get a better guess, and repeat until nothing changes.

The problem

The model is one-speed transport in a slab 0≤x≤L0 \le x \le L with isotropic scattering. The direction is the cosine μ∈[−1,1]\mu \in [-1, 1] of the angle with the xx axis, the angular flux is ψ(x,μ)\psi(x, \mu) and the scalar flux is ϕ(x)=∫−11ψ(x,μ) dμ\phi(x) = \int_{-1}^{1} \psi(x, \mu)\, d\mu. With the total and scattering cross sections Σt(x)\Sigma_t(x) and Σs(x)\Sigma_s(x) in cm−1\mathrm{cm}^{-1} and an isotropic source q(x)q(x) per unit length, the equation is

μ∂ψ∂x+Σt ψ=Σs ϕ+q2,\mu \frac{\partial \psi}{\partial x} + \Sigma_t\, \psi = \frac{\Sigma_s\, \phi + q}{2},

with the incoming flux ψ(0,μ)\psi(0, \mu) given for μ>0\mu > 0 and ψ(L,μ)\psi(L, \mu) given for μ<0\mu < 0. A vacuum face has zero incoming flux, and a reflecting face sends the outgoing flux back in the mirror direction. This page uses ϕ=∫−11ψ dμ\phi = \int_{-1}^1 \psi\, d\mu, so the emission per unit μ\mu is (Σsϕ+q)/2(\Sigma_s\phi + q)/2 and the weights sum to 2. Books that keep the azimuthal factor 2π2\pi have weights that sum to 1 or to 4π4\pi, with the source divided to match. The scattering ratio is c=Σs/Σtc = \Sigma_s/\Sigma_t.

The SNS_N equations replace the integral by the NN-point Gauss-Legendre rule with nodes μn\mu_n and weights wnw_n, NN even:

μndψndx+Σt ψn=Σs ϕ+q2,ϕ=∑n=1Nwnψn.\mu_n \frac{d\psi_n}{dx} + \Sigma_t\, \psi_n = \frac{\Sigma_s\, \phi + q}{2}, \qquad \phi = \sum_{n=1}^{N} w_n \psi_n .

The rule is exact for polynomials in μ\mu of degree up to 2N−12N - 1, it is symmetric about μ=0\mu = 0, and it has no node at μ=0\mu = 0. In space, the slab has MM cells Cj=[xj−1/2,xj+1/2]C_j = [x_{j-1/2}, x_{j+1/2}] of widths Δxj\Delta x_j with constant data, and the scheme is diamond difference: the cell balance with the cell value equal to the mean of the two face values.

The algorithm

  1. DISCRETE-ORDINATES(N, Σt, Σs, q, Δx, boundary conditions, tol)
  2. 1μ_1..μ_N, w_1..w_N ← the N-point Gauss-Legendre rule
  3. 2φ_j ← 0 for every cell j
  4. 3repeat
  5. 4S_j ← (Σs_j φ_j + q_j) / 2 for every cell j ▷ lagged scattering source
  6. 5for each direction n with μ_n > 0 do
  7. 6ψ_in ← the incoming value at x = 0 (0, the data, or the mirror outgoing value)
  8. 7for j ← 1 to M do a ← 2|μ_n| / Δx_j; ψ_nj ← (S_j + a ψ_in) / (Σt_j + a); ψ_in ← 2 ψ_nj − ψ_in
  9. 8for each direction n with μ_n < 0: the same from x = L, for j ← M down to 1
  10. 9φ_j ← Σ_n w_n ψ_nj for every cell j
  11. 10until the largest change of φ is at most tol times the largest φ

Line L7 is the diamond difference cell solve: the cell balance ∣μn∣(ψout−ψin)/Δxj+Σt,jψnj=Sj|\mu_n|(\psi_{\mathrm{out}} - \psi_{\mathrm{in}})/\Delta x_j + \Sigma_{t,j}\psi_{nj} = S_j with ψnj=(ψin+ψout)/2\psi_{nj} = (\psi_{\mathrm{in}} + \psi_{\mathrm{out}})/2, solved for the cell value, and then the outgoing value ψout=2ψnj−ψin\psi_{\mathrm{out}} = 2\psi_{nj} - \psi_{\mathrm{in}} becomes the incoming value of the next cell. Lines L5 to L8 are the transport sweep of each direction, and lines L3 to L10 are the source iteration. At a reflecting face, line L6 uses the outgoing value of the mirror direction from the last iteration, which the symmetric rule provides.

Example

A two-cell slab by hand. Take S2S_2, two cells of width 1 cm, Σt=1 cm−1\Sigma_t = 1\ \mathrm{cm}^{-1}, Σs=0.5 cm−1\Sigma_s = 0.5\ \mathrm{cm}^{-1}, q=1q = 1 and vacuum faces. Line L1 gives μ=±1/3=±0.577350\mu = \pm 1/\sqrt{3} = \pm 0.577350 and w=1,1w = 1, 1, so a=2/3=1.154701a = 2/\sqrt{3} = 1.154701.

  • Iteration 1, line L4: ϕ=0\phi = 0, so S1=S2=0.5S_1 = S_2 = 0.5.
  • Line L7 for μ>0\mu > 0: cell 1 gets ψ=0.5/2.154701=0.232051\psi = 0.5/2.154701 = 0.232051 and passes 2⋅0.232051=0.4641022 \cdot 0.232051 = 0.464102 to cell 2, which gets ψ=(0.5+1.154701⋅0.464102)/2.154701=0.480762\psi = (0.5 + 1.154701 \cdot 0.464102)/2.154701 = 0.480762 and sends 0.4974230.497423 out at x=2x = 2.
  • Line L8: by symmetry, μ<0\mu < 0 gives 0.4807620.480762 in cell 1 and 0.2320510.232051 in cell 2.
  • Line L9: ϕ1=ϕ2=0.232051+0.480762=0.712813\phi_1 = \phi_2 = 0.232051 + 0.480762 = 0.712813.

The two directions of each cell together give ϕ=KS\phi = K S with K=(2+4a)/(1+a)2=1.425626K = (2 + 4a)/(1 + a)^2 = 1.425626, and S=ϕ/4+1/2S = \phi/4 + 1/2. So each iteration maps ϕ\phi to Kϕ/4+K/2K\phi/4 + K/2, and the error falls by the factor K/4=0.356406K/4 = 0.356406 per iteration. The iterates are 0.7128130.712813, 0.9668640.966864, 1.0574101.057410, and the fixed point is (K/2)/(1−K/4)=1.107551(K/2)/(1 - K/4) = 1.107551. At the fixed point the absorption is (Σt−Σs)ϕ⋅2=1.107551(\Sigma_t - \Sigma_s)\phi \cdot 2 = 1.107551 and each face leaks 0.4462240.446224, so absorption plus leakage is 2.0000002.000000, the total source.

A pure absorber, refined in angle. A slab of 2 mean free paths (Σt=1\Sigma_t = 1, Σs=0\Sigma_s = 0, L=2L = 2) has the incoming flux ψ=1\psi = 1 for all μ>0\mu > 0 at x=0x = 0. The exact transmitted fraction of the incoming current is 2E3(2)=0.06026682E_3(2) = 0.0602668, where E3E_3 is the exponential integral. With 200 cells:

NN transmission error
2 0.031298 2.90×10−22.90 \times 10^{-2}
4 0.057516 2.75×10−32.75 \times 10^{-3}
8 0.059652 6.14×10−46.14 \times 10^{-4}
16 0.060081 1.85×10−41.85 \times 10^{-4}

The error comes from the angular quadrature. The integrand μe−2/μ\mu e^{-2/\mu} is very flat near μ=0\mu = 0, and few nodes fall there. A beam along μ=1\mu = 1 through the same slab gives e−2=0.135335e^{-2} = 0.135335, which line L7 reproduces to 2×10−62 \times 10^{-6} with 400 cells.

Second order in space. A slab of 10 mean free paths with c=0.9c = 0.9, q=1q = 1 and S8S_8 leaks 1.29902111.2990211, 1.29880421.2988042, 1.29874971.2987497 and 1.29873601.2987360 through each face with 20, 40, 80 and 160 cells. The observed orders from three successive meshes are 1.9941.994 and 1.9981.998, which is the second order of diamond difference.

An infinite medium. With reflecting faces on both sides, Σt=1\Sigma_t = 1, Σs=0.5\Sigma_s = 0.5 and q=1q = 1, the solution is ϕ=q/(Σt−Σs)=2\phi = q/(\Sigma_t - \Sigma_s) = 2 in every cell, to 10−1110^{-11}.

Correctness

The proofs are in the proof file. Line L7 solves the diamond difference equations of one cell exactly, and lines L5 to L8 solve those of a whole direction, because each cell needs only the cell upstream. At a fixed point of the iteration, the total absorption plus the net leakage equals the total source exactly, because the weights sum to 2 and the face fluxes telescope. With vacuum or given incoming faces and c=max⁡jΣs,j/Σt,j<1c = \max_j \Sigma_{s,j}/\Sigma_{t,j} < 1, the discrete equations have exactly one solution, and the iteration reaches it with the error reduced at least by the factor cc per iteration in a weighted L2L^2 norm. This holds for diamond difference although it can give negative values. In a pure absorber the diamond difference transmission along one direction has an error of at most (ΣtL/∣μ∣)3/(12M2)(\Sigma_t L/|\mu|)^3/(12M^2). The second order with scattering in the example is a measurement.

Proof: The diamond difference sweep solves each direction, the converged S_N solution balances, the discrete solution is unique, and the spatial error is second orderfull

We assume exact arithmetic. The slab, the cross sections and the lines L1 to L10 are those of the page. Every cell has Σt,j>0\Sigma_{t,j} > 0, 0≤Σs,j≤Σt,j0 \le \Sigma_{s,j} \le \Sigma_{t,j} and Δxj>0\Delta x_j > 0. The directions μn\mu_n and the weights wnw_n are the NN-point Gauss-Legendre rule with NN even, so every μn≠0\mu_n \ne 0, the weights are positive and sum to 2, and the rule is symmetric: if μn\mu_n is a node, then −μn-\mu_n is a node with the same weight (Gauss-Legendre quadrature).

For one direction nn and one cell jj, write ψa\psi_a for the incoming face value, ψb\psi_b for the outgoing face value and ψc\psi_c for the cell value. With τ=Σt,jΔxj/∣μn∣\tau = \Sigma_{t,j}\Delta x_j/|\mu_n| (the optical thickness of the cell along the direction) and the cell source SjS_j, the diamond difference equations of the cell are

∣μn∣ ψb−ψaΔxj+Σt,j ψc=Sj,ψc=ψa+ψb2.(1)|\mu_n|\,\frac{\psi_b - \psi_a}{\Delta x_j} + \Sigma_{t,j}\,\psi_c = S_j, \qquad \psi_c = \frac{\psi_a + \psi_b}{2}. \tag{1}

The first equation is the balance of the cell, and the second is the diamond relation.

Lemma 1 (one cell). For every ψa\psi_a and SjS_j, the equations (1) have exactly one solution, and it is the one of line L7:

ψc=Sj+(2∣μn∣/Δxj) ψaΣt,j+2∣μn∣/Δxj,ψb=2ψc−ψa.\psi_c = \frac{S_j + (2|\mu_n|/\Delta x_j)\,\psi_a}{\Sigma_{t,j} + 2|\mu_n|/\Delta x_j}, \qquad \psi_b = 2\psi_c - \psi_a.

Proof. The diamond relation gives ψb=2ψc−ψa\psi_b = 2\psi_c - \psi_a. Put this into the balance: ∣μn∣(2ψc−2ψa)/Δxj+Σt,jψc=Sj|\mu_n|(2\psi_c - 2\psi_a)/\Delta x_j + \Sigma_{t,j}\psi_c = S_j, that is (Σt,j+2∣μn∣/Δxj) ψc=Sj+(2∣μn∣/Δxj) ψa(\Sigma_{t,j} + 2|\mu_n|/\Delta x_j)\,\psi_c = S_j + (2|\mu_n|/\Delta x_j)\,\psi_a. The factor on the left is positive, so ψc\psi_c is unique and equals the formula. Then ψb\psi_b is fixed by the diamond relation. Both equations hold by construction. □\square

Lemma 2 (one sweep). Fix the sources SjS_j and the incoming value at the face where direction nn enters. Lines L5 to L8 compute the unique solution of the equations (1) of direction nn in all cells, with the outgoing value of each cell equal to the incoming value of the next cell downstream.

Proof. Take μn>0\mu_n > 0; the case μn<0\mu_n < 0 is the mirror image, with the cells in the order M,…,1M, \ldots, 1. We use induction on the cell index. Cell 1 has the incoming value of the boundary, so by Lemma 1 its equations have one solution, and line L7 computes it. If cells 1,…,j−11, \ldots, j - 1 are solved, the incoming value of cell jj is the outgoing value of cell j−1j - 1, which is now known, and Lemma 1 again gives the one solution. The equations of cell jj contain no unknown of a cell downstream, so the order of line L7 solves them all. □\square

So one iteration of lines L4 to L9 is ϕ↦Tϕ+b\phi \mapsto T\phi + b: it sweeps all directions with the source (Σsϕ+q)/2(\Sigma_s \phi + q)/2 of the last iterate and integrates with the weights. The map is affine in ϕ\phi, and its linear part TT is the sweep of the source Σsϕ/2\Sigma_s\phi/2 with zero incoming values.

Theorem 3 (balance at the fixed point). Let ϕ\phi be a fixed point of the iteration, ϕ=Tϕ+b\phi = T\phi + b, with incoming face values given (vacuum or data). Let JinJ^{\mathrm{in}} be the incoming partial current ∑μn>0wnμnψn(0)+∑μn<0wn∣μn∣ψn(L)\sum_{\mu_n > 0} w_n \mu_n \psi_n(0) + \sum_{\mu_n < 0} w_n |\mu_n| \psi_n(L) and JoutJ^{\mathrm{out}} the outgoing one, with the outgoing face values. Then

∑j=1M(Σt,j−Σs,j) ϕj Δxj+Jout=∑j=1Mqj Δxj+Jin.\sum_{j=1}^{M} (\Sigma_{t,j} - \Sigma_{s,j})\,\phi_j\,\Delta x_j + J^{\mathrm{out}} = \sum_{j=1}^{M} q_j\,\Delta x_j + J^{\mathrm{in}}.

Proof. Multiply the balance in (1) for direction nn and cell jj by wnΔxjw_n \Delta x_j and sum over nn. The source is the same for all directions, and ∑nwn=2\sum_n w_n = 2, so the right side is 2SjΔxj=(Σs,jϕj+qj)Δxj2 S_j \Delta x_j = (\Sigma_{s,j}\phi_j + q_j)\Delta x_j. The collision term gives Σt,jΔxj∑nwnψn,j=Σt,jϕjΔxj\Sigma_{t,j}\Delta x_j \sum_n w_n \psi_{n,j} = \Sigma_{t,j}\phi_j\Delta x_j by line L9, because at the fixed point the ϕ\phi of line L9 is the ϕ\phi of line L4. The streaming term is ∑nwn∣μn∣(ψn,out−ψn,in)\sum_n w_n |\mu_n|(\psi_{n,\mathrm{out}} - \psi_{n,\mathrm{in}}) for cell jj. Now sum over jj. For a direction with μn>0\mu_n > 0, the outgoing value of cell jj is the incoming value of cell j+1j + 1 (Lemma 2), so the sum over jj telescopes to ∣μn∣(ψn(L)−ψn(0))|\mu_n|(\psi_n(L) - \psi_n(0)). For μn<0\mu_n < 0 it telescopes to ∣μn∣(ψn(0)−ψn(L))|\mu_n|(\psi_n(0) - \psi_n(L)). The sum of these over nn with the weights is Jout−JinJ^{\mathrm{out}} - J^{\mathrm{in}}. Move Σsϕ\Sigma_s\phi to the left. □\square

At a reflecting face, the incoming current equals the outgoing one at the fixed point, because the rule is symmetric and the mirror direction has the same weight and the same ∣μ∣|\mu|, so the two terms of that face cancel. The page checks the balance with the leakages that the implementation returns.

Theorem 4 (existence, uniqueness and convergence). Let c=max⁡jΣs,j/Σt,j<1c = \max_j \Sigma_{s,j}/\Sigma_{t,j} < 1, and let the incoming face values be given (vacuum or data, not reflecting). Then the discrete SNS_N equations have exactly one solution, and the iteration of lines L3 to L10 converges to it from every start, with

∥ϕ(l)−ϕ∥t≤c l ∥ϕ(0)−ϕ∥t,∥v∥t2=∑jΣt,j vj2 Δxj.\|\phi^{(l)} - \phi\|_t \le c^{\,l}\, \|\phi^{(0)} - \phi\|_t, \qquad \|v\|_t^2 = \sum_{j} \Sigma_{t,j}\, v_j^2\, \Delta x_j .

Proof. It is enough to show ∥Tv∥t≤c∥v∥t\|Tv\|_t \le c\|v\|_t for every vector vv. Then TT is a contraction in this norm, the map ϕ↦Tϕ+b\phi \mapsto T\phi + b has exactly one fixed point by the contraction mapping theorem (fixed-point iteration), and the error of iterate ll is TlT^l applied to the first error.

Fix vv and one direction nn, and let ψ\psi be its sweep with the source Sj=Σs,jvj/2S_j = \Sigma_{s,j} v_j/2 and zero incoming value. Multiply the balance in (1) by ψc Δxj\psi_c\,\Delta x_j. With the diamond relation, ∣μn∣(ψb−ψa)ψc=∣μn∣(ψb2−ψa2)/2|\mu_n|(\psi_b - \psi_a)\psi_c = |\mu_n|(\psi_b^2 - \psi_a^2)/2. The sum over the cells telescopes as in Theorem 3:

∣μn∣2 ψout2+∑jΣt,j ψc,j2 Δxj=∑jSj ψc,j Δxj,\frac{|\mu_n|}{2}\,\psi_{\mathrm{out}}^2 + \sum_j \Sigma_{t,j}\,\psi_{c,j}^2\,\Delta x_j = \sum_j S_j\,\psi_{c,j}\,\Delta x_j,

where ψout\psi_{\mathrm{out}} is the value that leaves the slab and the incoming value is 0. The first term is not negative. Write the right side as ∑j(Sj/Σt,j) ψc,j Σt,jΔxj\sum_j (S_j/\Sigma_{t,j})\,\psi_{c,j}\,\Sigma_{t,j}\Delta x_j and use the Cauchy-Schwarz inequality in the weighted inner product:

∥ψc∥t2≤∥S/Σt∥t ∥ψc∥t,so∥ψc∥t≤∥S/Σt∥t≤c2 ∥v∥t,\|\psi_c\|_t^2 \le \|S/\Sigma_t\|_t\, \|\psi_c\|_t, \quad\text{so}\quad \|\psi_c\|_t \le \|S/\Sigma_t\|_t \le \frac{c}{2}\,\|v\|_t,

because Sj/Σt,j=(Σs,j/Σt,j) vj/2S_j/\Sigma_{t,j} = (\Sigma_{s,j}/\Sigma_{t,j})\, v_j/2 and Σs,j/Σt,j≤c\Sigma_{s,j}/\Sigma_{t,j} \le c. Line L9 forms Tv=∑nwnψc(n)Tv = \sum_n w_n \psi_{c}^{(n)}, so by the triangle inequality ∥Tv∥t≤∑nwn(c/2)∥v∥t=c ∥v∥t\|Tv\|_t \le \sum_n w_n (c/2)\|v\|_t = c\,\|v\|_t, since the weights are positive and sum to 2. □\square

The proof does not need the cell values to be positive, so it holds for diamond difference, which can give negative values (Theorem 6). The source iteration page shows that the factor cc is sharp in thick media and gives the Fourier analysis of the rate.

Theorem 5 (second order in space along a direction). Take a pure absorber with Σt\Sigma_t constant, no source, MM equal cells on [0,L][0, L], a direction μ≠0\mu \ne 0 and the incoming value 1. Let τ=ΣtL/(∣μ∣M)\tau = \Sigma_t L/(|\mu| M) be the optical thickness of one cell along the direction. The exact transmitted value is e−ΣtL/∣μ∣e^{-\Sigma_t L/|\mu|}, and the diamond difference value ψout\psi_{\mathrm{out}} satisfies

∣ψout−e−ΣtL/∣μ∣∣≤(ΣtL/∣μ∣)312 M2,|\psi_{\mathrm{out}} - e^{-\Sigma_t L/|\mu|}| \le \frac{(\Sigma_t L/|\mu|)^3}{12\, M^2},

and ψout≤e−ΣtL/∣μ∣\psi_{\mathrm{out}} \le e^{-\Sigma_t L/|\mu|} when τ≤2\tau \le 2.

Proof. With S=0S = 0, Lemma 1 gives ψb=r(τ) ψa\psi_b = r(\tau)\,\psi_a with r(τ)=(2−τ)/(2+τ)r(\tau) = (2 - \tau)/(2 + \tau), so ψout=r(τ)M\psi_{\mathrm{out}} = r(\tau)^M. Let f(τ)=(2+τ)e−τ−(2−τ)f(\tau) = (2 + \tau)e^{-\tau} - (2 - \tau). Then f(0)=0f(0) = 0, f′(τ)=1−(1+τ)e−τf'(\tau) = 1 - (1 + \tau)e^{-\tau} with f′(0)=0f'(0) = 0, and f′′(τ)=τe−τf''(\tau) = \tau e^{-\tau}. By Taylor's formula with the integral remainder, f(τ)=∫0τ(τ−s) se−s dsf(\tau) = \int_0^\tau (\tau - s)\, s e^{-s}\, ds, so 0≤f(τ)≤∫0τ(τ−s) s ds=τ3/60 \le f(\tau) \le \int_0^\tau (\tau - s)\, s\, ds = \tau^3/6. Since e−τ−r(τ)=f(τ)/(2+τ)e^{-\tau} - r(\tau) = f(\tau)/(2 + \tau),

0≤e−τ−r(τ)≤τ36(2+τ)≤τ312.0 \le e^{-\tau} - r(\tau) \le \frac{\tau^3}{6(2 + \tau)} \le \frac{\tau^3}{12}.

Both e−τe^{-\tau} and r(τ)r(\tau) lie in [−1,1][-1, 1] for τ≥0\tau \ge 0. For numbers a,ba, b in [−1,1][-1, 1], aM−bM=(a−b)∑i=0M−1aibM−1−ia^M - b^M = (a - b)\sum_{i=0}^{M-1} a^i b^{M-1-i}, so ∣aM−bM∣≤M∣a−b∣|a^M - b^M| \le M|a - b|. With a=e−τa = e^{-\tau} and b=r(τ)b = r(\tau) this gives ∣e−Mτ−r(τ)M∣≤Mτ3/12=(ΣtL/∣μ∣)3/(12M2)|e^{-M\tau} - r(\tau)^M| \le M\tau^3/12 = (\Sigma_t L/|\mu|)^3/(12M^2). If τ≤2\tau \le 2, then 0≤r(τ)≤e−τ0 \le r(\tau) \le e^{-\tau}, so r(τ)M≤e−Mτr(\tau)^M \le e^{-M\tau}. □\square

For a smooth problem with scattering, the same local error of order τ3\tau^3 per cell gives a global error of order Δx2\Delta x^2; the page measures this order on a scattering slab and does not prove it in general.

Theorem 6 (negative values). In a pure absorber cell with Sj=0S_j = 0 and ψa>0\psi_a > 0, the outgoing value ψb\psi_b is negative if and only if τ>2\tau > 2, that is Σt,jΔxj>2∣μn∣\Sigma_{t,j}\Delta x_j > 2|\mu_n|.

Proof. By Lemma 1, ψb=r(τ)ψa\psi_b = r(\tau)\psi_a with r(τ)=(2−τ)/(2+τ)r(\tau) = (2 - \tau)/(2 + \tau), and r(τ)<0r(\tau) < 0 exactly when τ>2\tau > 2. □\square

The cell value ψc=ψa/(1+τ/2)\psi_c = \psi_a/(1 + \tau/2) stays positive. The negative face value enters the next cell, and there it can make the cell value negative too.

Complexity

In the real RAM model, line L7 costs a fixed number of operations, so one iteration costs O(NM)O(NM), and II iterations cost O(INM)O(INM). The number of iterations depends on the problem: it grows like log⁡(1/tol)/log⁡(1/c)\log(1/\mathrm{tol})/\log(1/c) in a thick medium, so it is large for cc near 1 (source iteration gives the analysis, and diffusion synthetic acceleration removes the growth). Storing all ψnj\psi_{nj} needs O(NM)O(NM) memory; if only ϕ\phi and the face values for reflection are kept, O(M+N)O(M + N) is enough. In three dimensions with MM cells and a quadrature of NN directions the cost of an iteration is again O(NM)O(NM), and for the level-symmetric SNS_N sets the number of directions is N(N+2)N(N + 2).

Properties

  • Deterministic. The result has no statistical noise; its errors come from the angular quadrature, the spatial mesh and the stopping test.
  • Conservative. The converged solution satisfies the particle balance of each cell and of the whole slab exactly (Theorem 3 of the proof).
  • Not positive. Diamond difference gives a negative outgoing value in a source-free cell when ΣtΔx>2∣μ∣\Sigma_t\Delta x > 2|\mu|. In the test, μ=0.1\mu = 0.1, Σt=1\Sigma_t = 1 and Δx=1\Delta x = 1 turn the incoming value 1 into −0.666667-0.666667.
  • Second order in space. For smooth solutions and thin cells; the order drops where the solution has kinks, for example near a boundary where the incoming flux jumps.
  • Exact in angle up to degree 2N−12N - 1. The Gauss rule integrates every polynomial in μ\mu up to this degree, so any angular flux that is such a polynomial has an exact scalar flux.

Variants and improvements

  • Other spatial schemes. The step scheme (the outgoing value equals the cell value) is positive and first order. The step characteristic scheme integrates the equation exactly in each cell for a flat source. Weighted diamond schemes and linear discontinuous finite elements trade accuracy against positivity; linear discontinuous elements stay accurate with thick cells in diffusive regions, where diamond difference can oscillate and go negative.
  • Multidimensional quadratures. In two and three dimensions, the directions form sets on the unit sphere. Level-symmetric sets have the same cosines on each axis, and product sets combine a Gauss rule in the polar cosine with equal azimuthal steps.
  • Energy and anisotropy. The multigroup approximation gives one SNS_N problem per energy group, coupled by group to group scattering. Anisotropic scattering adds Legendre moments of the flux to the source.
  • Faster iterations. Diffusion synthetic acceleration or a Krylov method such as GMRES with the sweep as the operator replaces plain source iteration in diffusive problems.
  • Eigenvalue problems. The k-eigenvalue problem is solved by power iteration on the fission source, with an SNS_N fixed source solve in each step.

When to use it

Use the SNS_N method for shielding, reactor core and radiation problems where the whole flux field is needed without statistical noise, the geometry fits a mesh, and the cross sections can be put into groups. In optically thick, highly scattering media, use it with an acceleration. When the geometry is very complex, use the method of characteristics or Monte Carlo; when the flux is nearly isotropic everywhere, the diffusion approximation is much cheaper.

Pitfalls

  • Negative fluxes (line L7). Thick cells give negative values, which can make a cross section feedback or a nonlinear coupling fail. A set-to-zero fixup puts the outgoing value to zero and computes the cell value again from the balance. This keeps the balance, but the scheme becomes nonlinear and only first order in those cells. Refine the mesh or use a positive scheme.
  • Ray effects. In two and three dimensions, a localized source in a weakly scattering medium is seen only along the few quadrature directions, so the flux far away has unphysical rays (Lathrop 1968). More directions reduce them slowly; a first collision source or a Monte Carlo estimate of the uncollided flux removes their main cause.
  • The weight convention. The source term must match the normalization of the weights. With weights that sum to 2 the source is (Σsϕ+q)/2(\Sigma_s\phi + q)/2; mixing this with a rule normalized to 1 or to 4π4\pi makes the scattering source wrong by a constant factor.
  • The stopping test (line L10). A small change between iterations does not mean a small error when cc is near 1: the error can be about c/(1−c)c/(1 - c) times the change.
  • Reflecting faces (line L6). The reflected value lags one iteration behind. This slows the iteration, and the quadrature must contain the mirror of each direction.
  • Isotropic incident flux. A flux that is constant in μ\mu on (0,1](0, 1] is not a polynomial on [−1,1][-1, 1], and the transmitted current has the slow angular convergence of the second example.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

discrete_ordinates_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/discrete-ordinates-method/. The authors are listed in prov/S57PHM.jsonl.
"""The discrete ordinates (S_N) method for one-speed transport in a slab.

The slab 0 <= x <= L is cut into M cells of widths dx[j], each with a total
cross section sigma_t[j], a scattering cross section sigma_s[j] (both in
cm^-1) and an isotropic source q[j] per unit length. Scattering is isotropic.
The convention is phi(x) = integral of psi(x, mu) over mu in [-1, 1], so the
emission density per unit mu is (sigma_s phi + q) / 2 and the weights of the
Gauss-Legendre rule sum to 2.

The angular variable is replaced by the N Gauss-Legendre directions mu_n
(N even). The space variable is discretized by diamond differences: in each
cell, psi_cell = (psi_in + psi_out) / 2. The coupled equations are solved by
source iteration: a transport sweep for each direction with the scattering
source of the last iterate.

Boundary conditions: "vacuum" (no incoming flux), "reflect" (the incoming
flux at a face is the outgoing flux in the mirror direction, from the last
iteration), or a list of incoming angular fluxes, one per direction that
enters the slab at that face (in the order of the rule).
"""

import math


def legendre(n: int, x: float):
    """P_n(x) and its derivative, by the three-term recurrence."""
    p0, p1 = 1.0, x
    if n == 0:
        return 1.0, 0.0
    for k in range(2, n + 1):
        p0, p1 = p1, ((2 * k - 1) * x * p1 - (k - 1) * p0) / k
    dp = n * (x * p1 - p0) / (x * x - 1.0)
    return p1, dp


def gauss_legendre(n: int):
    """Nodes (in increasing order) and weights of the n-point Gauss-Legendre rule on [-1, 1]."""
    nodes, weights = [0.0] * n, [0.0] * n
    for i in range((n + 1) // 2):
        x = math.cos(math.pi * (i + 0.75) / (n + 0.5))  # a start near the i-th largest root
        for _ in range(100):
            p, dp = legendre(n, x)
            dx = p / dp
            x -= dx
            if abs(dx) < 1e-16:
                break
        p, dp = legendre(n, x)
        w = 2.0 / ((1.0 - x * x) * dp * dp)
        nodes[n - 1 - i], weights[n - 1 - i] = x, w
        nodes[i], weights[i] = -x, w
    return nodes, weights


def sweep_cell(mu_abs: float, psi_in: float, sigma_t: float, src: float, dx: float):
    """Diamond difference in one cell. Returns (cell average, outgoing flux)."""
    a = 2.0 * mu_abs / dx
    psi_c = (src + a * psi_in) / (sigma_t + a)
    return psi_c, 2.0 * psi_c - psi_in


def sweep(mu: float, psi_in: float, sigma_t, src, dx):
    """Sweep one direction through all cells in the direction of flight.

    Returns (cell averages in cell order, outgoing flux at the far face)."""
    m = len(dx)
    cells = [0.0] * m
    order = range(m) if mu > 0 else range(m - 1, -1, -1)
    psi = psi_in
    for j in order:
        cells[j], psi = sweep_cell(abs(mu), psi, sigma_t[j], src[j], dx[j])
    return cells, psi


def discrete_ordinates(n, sigma_t, sigma_s, q, dx, left="vacuum", right="vacuum", tol=1e-10, max_iter=100000):
    """Solve the S_N equations with diamond differences by source iteration.

    Returns a dict with phi (cell-average scalar flux), psi (psi[n][j]),
    the outgoing angular fluxes at both faces, the partial currents that
    leave at both faces, and the number of iterations."""
    mus, ws = gauss_legendre(n)  # @line L1
    m = len(dx)
    pos = [k for k in range(n) if mus[k] > 0]
    neg = [k for k in range(n) if mus[k] < 0]
    mirror = {k: n - 1 - k for k in range(n)}
    out_left = {k: 0.0 for k in neg}  # psi leaving at x = 0
    out_right = {k: 0.0 for k in pos}  # psi leaving at x = L
    phi = [0.0] * m  # @line L2
    psi = [[0.0] * m for _ in range(n)]
    for it in range(1, max_iter + 1):  # @line L3
        src = [(sigma_s[j] * phi[j] + q[j]) / 2.0 for j in range(m)]  # @line L4
        new_left, new_right = {}, {}
        for idx, k in enumerate(pos):  # @line L5
            if left == "vacuum":  # @line L6
                psi_in = 0.0
            elif left == "reflect":
                psi_in = out_left[mirror[k]]
            else:
                psi_in = left[idx]
            psi[k], new_right[k] = sweep(mus[k], psi_in, sigma_t, src, dx)  # @line L7
        for idx, k in enumerate(neg):  # @line L8
            if right == "vacuum":
                psi_in = 0.0
            elif right == "reflect":
                psi_in = out_right[mirror[k]]
            else:
                psi_in = right[idx]
            psi[k], new_left[k] = sweep(mus[k], psi_in, sigma_t, src, dx)
        out_left, out_right = new_left, new_right
        new_phi = [sum(ws[k] * psi[k][j] for k in range(n)) for j in range(m)]  # @line L9
        change = max(abs(new_phi[j] - phi[j]) for j in range(m))
        scale = max(abs(v) for v in new_phi) or 1.0
        phi = new_phi
        if change <= tol * scale:  # @line L10
            break
    j_left = sum(ws[k] * abs(mus[k]) * out_left[k] for k in neg)
    j_right = sum(ws[k] * mus[k] * out_right[k] for k in pos)
    return {"phi": phi, "psi": psi, "mu": mus, "w": ws, "out_left": out_left, "out_right": out_right,
            "leak_left": j_left, "leak_right": j_right, "iterations": it}
test_discrete_ordinates_method.py 124 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/discrete-ordinates-method/. The authors are listed in prov/S57PHM.jsonl.
import math
import unittest

from discrete_ordinates_method import discrete_ordinates, gauss_legendre, sweep, sweep_cell


def e3(x, k=20000):
    """E_3(x) = integral over mu in (0, 1] of mu e^(-x/mu), by the midpoint rule."""
    s = 0.0
    for i in range(k):
        m = (i + 0.5) / k
        s += m * math.exp(-x / m)
    return s / k


class TestGaussLegendre(unittest.TestCase):
    def test_weights_sum_to_two_and_rule_is_symmetric(self):
        for n in (2, 4, 8, 16):
            x, w = gauss_legendre(n)
            self.assertAlmostEqual(sum(w), 2.0, places=13)
            for i in range(n):
                self.assertAlmostEqual(x[i], -x[n - 1 - i], places=14)
                self.assertAlmostEqual(w[i], w[n - 1 - i], places=14)

    def test_exact_to_degree_2n_minus_1(self):
        for n in (2, 4, 8):
            x, w = gauss_legendre(n)
            for d in range(0, 2 * n, 2):
                got = sum(wi * xi ** d for xi, wi in zip(x, w))
                self.assertAlmostEqual(got, 2.0 / (d + 1), places=12)

    def test_known_nodes(self):
        x, w = gauss_legendre(2)
        self.assertAlmostEqual(x[1], 1.0 / math.sqrt(3.0), places=14)
        x, w = gauss_legendre(4)
        self.assertAlmostEqual(x[3], 0.8611363115940526, places=13)
        self.assertAlmostEqual(w[3], 0.3478548451374538, places=13)


class TestHandTrace(unittest.TestCase):
    def test_first_sweep_and_first_iterate(self):
        cells, out = sweep(1.0 / math.sqrt(3.0), 0.0, [1.0, 1.0], [0.5, 0.5], [1.0, 1.0])
        self.assertAlmostEqual(cells[0], 0.2320508075688773, places=12)
        self.assertAlmostEqual(cells[1], 0.4807621135331595, places=12)
        self.assertAlmostEqual(out, 0.4974226119285644, places=12)
        r = discrete_ordinates(2, [1.0, 1.0], [0.5, 0.5], [1.0, 1.0], [1.0, 1.0], tol=0.0, max_iter=1)
        self.assertAlmostEqual(r["phi"][0], 0.7128129211020369, places=12)
        self.assertAlmostEqual(r["phi"][1], 0.7128129211020369, places=12)

    def test_balance(self):
        r = discrete_ordinates(2, [1.0, 1.0], [0.5, 0.5], [1.0, 1.0], [1.0, 1.0], tol=1e-14)
        absorbed = sum(0.5 * p * 1.0 for p in r["phi"])
        self.assertAlmostEqual(absorbed + r["leak_left"] + r["leak_right"], 2.0, places=11)
        self.assertAlmostEqual(r["leak_left"], r["leak_right"], places=12)


class TestPureAbsorber(unittest.TestCase):
    def test_single_direction_is_second_order(self):
        mu = 1.0 / math.sqrt(3.0)
        exact = math.exp(-2.0 / mu)
        errs = []
        for m in (8, 16, 32):
            _, out = sweep(mu, 1.0, [1.0] * m, [0.0] * m, [2.0 / m] * m)
            errs.append(abs(out - exact))
        for a, b in zip(errs, errs[1:]):
            self.assertAlmostEqual(math.log2(a / b), 2.0, delta=0.05)

    def test_normal_beam_transmission(self):
        # one direction with mu = 1 is not in the rule, so sweep it directly
        m = 400
        _, out = sweep(1.0, 1.0, [1.0] * m, [0.0] * m, [2.0 / m] * m)
        self.assertAlmostEqual(out, math.exp(-2.0), delta=2e-6)
        self.assertAlmostEqual(math.exp(-2.0), 0.135335, places=6)

    def test_isotropic_incidence_converges_in_angle(self):
        exact = 2.0 * e3(2.0)
        m = 200
        errs = []
        for n in (2, 4, 8, 16):
            x, w = gauss_legendre(n)
            r = discrete_ordinates(n, [1.0] * m, [0.0] * m, [0.0] * m, [2.0 / m] * m, left=[1.0] * (n // 2))
            jin = sum(w[k] * x[k] for k in range(n) if x[k] > 0)
            errs.append(abs(r["leak_right"] / jin - exact))
        for a, b in zip(errs, errs[1:]):
            self.assertLess(b, a)
        self.assertLess(errs[-1], 3e-4)


class TestScattering(unittest.TestCase):
    def test_infinite_medium(self):
        # reflecting faces: phi = q / sigma_a = 1 / 0.5 = 2
        r = discrete_ordinates(8, [1.0] * 10, [0.5] * 10, [1.0] * 10, [0.5] * 10,
                               left="reflect", right="reflect", tol=1e-13)
        for p in r["phi"]:
            self.assertAlmostEqual(p, 2.0, places=11)

    def test_balance_with_strong_scattering(self):
        m, length = 40, 10.0
        r = discrete_ordinates(8, [1.0] * m, [0.9] * m, [1.0] * m, [length / m] * m, tol=1e-13)
        absorbed = sum(0.1 * p * length / m for p in r["phi"])
        self.assertAlmostEqual(absorbed + r["leak_left"] + r["leak_right"], length, places=9)

    def test_leakage_is_second_order_in_space(self):
        length = 10.0
        leaks = []
        for m in (20, 40, 80):
            r = discrete_ordinates(8, [1.0] * m, [0.9] * m, [1.0] * m, [length / m] * m, tol=1e-13)
            leaks.append(r["leak_left"])
        p = math.log2((leaks[0] - leaks[1]) / (leaks[1] - leaks[2]))
        self.assertAlmostEqual(p, 2.0, delta=0.2)


class TestNegativeFlux(unittest.TestCase):
    def test_thick_cell_gives_negative_outgoing_flux(self):
        c, out = sweep_cell(0.1, 1.0, 1.0, 0.0, 1.0)
        self.assertAlmostEqual(c, 0.2 / 1.2, places=14)
        self.assertAlmostEqual(out, -0.8 / 1.2, places=14)
        self.assertLess(out, 0.0)


if __name__ == "__main__":
    unittest.main()

History

Wick (1943) replaced the angular integral of the transfer equation by a Gauss quadrature, and Chandrasekhar developed this method of discrete ordinates for radiative transfer in plane-parallel atmospheres; his book Radiative Transfer (1950) collects the work. At Los Alamos, Carlson made the SnS_n method for neutron transport in the 1950s, first with a piecewise linear angular flux and then with general quadrature sets, and it became the basis of the deterministic transport codes of the following decades. Lathrop (1968) explained the ray effects of multidimensional SNS_N solutions. Lewis and Miller (1984) give the slab and multidimensional methods in textbook form, and Adams and Larsen (2002) review the spatial schemes and the iterations.

References

  1. E. E. Lewis and W. F. Miller, Jr., Computational Methods of Neutron Transport, Wiley, 1984, the chapters on discrete ordinates in slab geometry (Gauss quadrature, diamond difference, negative fluxes, source iteration) and in multidimensional geometry (level-symmetric quadrature, ray effects)
  2. Marvin L. Adams and Edward W. Larsen, Fast iterative methods for discrete-ordinates particle transport calculations, Progress in Nuclear Energy 40(1), 2002, 3-159, the sections on the slab geometry S_N equations, the spatial discretizations and the source iteration
  3. K. D. Lathrop, Ray effects in discrete ordinates equations, Nuclear Science and Engineering 32, 1968, 357-369, the origin of ray effects in two-dimensional S_N solutions and their size
  4. S. Chandrasekhar, Radiative Transfer, Oxford University Press, 1950, Dover reprint 1960, the chapter on the method of discrete ordinates with Gauss points for the transfer equation in plane-parallel atmospheres
  5. G. C. Wick, Über ebene Diffusionsprobleme, Zeitschrift für Physik 121, 1943, 702-718, the replacement of the angular integral by a Gauss quadrature in plane problems
  6. B. G. Carlson, Solution of the transport equation by S_n approximations, Los Alamos Scientific Laboratory report LA-1891, 1955, the S_n method of Los Alamos

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example