Algorithm Search⌘K

Algorithmcore

Source iteration

Also called scattering source iteration.

Solves the transport equation by repeated sweeps with the scattering source lagged, which converges slowly when the scattering ratio is near one.

Time
O(I N M) worst
Space
O(N M) extra
Where
I = the number of iterations; M = the number of cells; N = the number of directions
Properties
deterministicnot exactiterativenot randomized

Source iteration solves the discrete transport equation by fixed-point iteration on the scattering source. It takes the scalar flux of the last iterate, builds the scattering source from it, and solves the streaming and collision part for every direction exactly by a transport sweep. This needs no matrix, and each iteration costs one sweep. Iterate ll is the flux of the particles that have collided fewer than ll times. So the error falls by about the scattering ratio cc per iteration, and the method is very slow in thick media with cc near 1. Diffusion synthetic acceleration and Krylov methods such as GMRES are the standard ways to make it fast.

In plain words

Particles fly, hit atoms, and either disappear or bounce off in a new direction. If you knew where the bounced particles come from, the rest would be easy: you walk each direction through the mesh once, from the side where the particles enter.

So you guess the bounced particles, walk all directions, and use the result as the next guess. The first walk counts the particles that have not bounced yet. The second walk adds the particles that bounced once, the third those that bounced twice, and so on.

This works well when most particles escape or are absorbed after a few bounces. When almost every collision is a bounce and the material is thick, particles bounce hundreds of times, and you need hundreds of walks.

The problem

The model is the one-speed slab problem of the discrete ordinates page. The slab 0≤x≤L0 \le x \le L has MM cells with the total and scattering cross sections Σt,j\Sigma_{t,j} and Σs,j\Sigma_{s,j} in cm−1\mathrm{cm}^{-1} and an isotropic source qjq_j. The directions μn\mu_n and the weights wnw_n are the NN-point Gauss-Legendre rule, the weights sum to 2, and the equations are

μ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,

with diamond difference in space. Each face is vacuum, has given incoming values, or reflects. The scattering ratio is c=max⁡jΣs,j/Σt,jc = \max_j \Sigma_{s,j}/\Sigma_{t,j}.

Write ϕ=Tϕ+b\phi = T\phi + b for these equations. Here bb is the flux that one sweep gives from the source q/2q/2 and the incoming data, and TT is the map that sweeps the source Σsv/2\Sigma_s v/2 with zero data. The problem is to find the fixed point ϕ\phi.

The algorithm

  1. SOURCE-ITERATION(N, Σt, Σs, q, Δx, boundary conditions, tol, φ0)
  2. 1φ_j ← φ0_j (or 0) for every cell j
  3. 2repeat
  4. 3S_j ← (Σs_j φ_j + q_j) / 2 for every cell j ▷ the scattering source of the last iterate
  5. 4φ_new ← SWEEP(S): for each direction solve the cells in the direction of flight, then φ_new_j ← Σ_n w_n ψ_nj
  6. 5d ← max_j |φ_new_j − φ_j|; φ ← φ_new
  7. 6until d ≤ tol · max_j |φ_j|

Line L4 is the transport sweep with the diamond difference cell solve of the discrete ordinates page. With a reflecting face, the implementation sweeps the directions that leave through that face first, so the reflected value is current and not lagged. With two reflecting faces, it finds the incoming value of each pair of mirror directions from one scalar equation (Lemma 1 of the proof). Line L6 is a test on the change; Theorem 6 of the proof shows what it says about the error.

Example

An infinite medium by hand. Take Σ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, both faces reflecting and ϕ(0)=0\phi^{(0)} = 0. The sweep of a constant source SS gives ψ=S/Σt\psi = S/\Sigma_t in every direction, so line L4 gives ϕnew=2S=0.5ϕ+1\phi_{\mathrm{new}} = 2S = 0.5\phi + 1.

ll ϕ(l)\phi^{(l)} change dd
1 1 1
2 1.5 0.5
3 1.75 0.25
4 1.875 0.125
5 1.9375 0.0625

The exact value is q/(Σt−Σs)=2q/(\Sigma_t - \Sigma_s) = 2. Each iteration adds one more term of 1+c+c2+⋯1 + c + c^2 + \cdots, the particles after one more collision, and the error halves.

The cost of cc near 1. In the same infinite medium with tol=10−8\mathrm{tol} = 10^{-8}:

cc iterations relative error at the stop error / last change
0.5 27 7.45×10−97.45 \times 10^{-9} 1
0.9 154 8.98×10−88.98 \times 10^{-8} 9
0.99 1376 9.86×10−79.86 \times 10^{-7} 99
0.999 11509 9.98×10−69.98 \times 10^{-6} 999

The number of iterations grows like 1/(1−c)1/(1 - c), and the error left at the stop is c/(1−c)c/(1 - c) times the last change, as Theorem 6 of the proof states.

Fourier modes. On a reflecting slab of 40 cells of width 0.5 cm0.5\ \mathrm{cm} with Σt=1\Sigma_t = 1, c=0.9c = 0.9 and S8S_8, the cosine modes cos⁡(πk(j+1/2)/40)\cos(\pi k (j + 1/2)/40) are eigenvectors of one iteration (Theorem 5 of the proof). The eigenvalue depends on λ=4tan⁡(πk/80)\lambda = 4\tan(\pi k/80):

kk λ\lambda eigenvalue, diamond difference carctan⁡(λ)/λc\arctan(\lambda)/\lambda, continuous
0 0 0.9 0.9
1 0.157160 0.892698 0.892698
3 0.473431 0.840567 0.840567
10 1.656854 0.558181 0.558282
39 101.81 0.00107183 0.013799

The modes that oscillate fast from cell to cell die in a few iterations. The flat and slowly varying modes keep almost all of their size, and they set the rate. These are the modes that diffusion describes well, which is why a diffusion correction removes them.

A finite slab. With vacuum faces the flat mode leaks out, so a thin slab converges faster. With c=0.99c = 0.99, S8S_8 and cells of 0.250.25 mean free paths, the measured ratio of successive changes is 0.604550.60455 for L=1L = 1, 0.965920.96592 for L=10L = 10 and 0.989970.98997 for L=100L = 100 mean free paths. With q=1q = 1 and tol=10−8\mathrm{tol} = 10^{-8} this means 36, 437 and 1356 iterations.

Correctness

The proofs are in the proof file. From ϕ(0)=0\phi^{(0)} = 0, iterate ll is the partial sum b+Tb+⋯+Tl−1bb + Tb + \cdots + T^{l-1}b of the Neumann series, the flux of the particles with fewer than ll collisions. With vacuum, given or reflecting faces, TT is a contraction by the factor cc in the norm ∥v∥t2=∑jΣt,jvj2Δxj\|v\|_t^2 = \sum_j \Sigma_{t,j}v_j^2\Delta x_j, so for c<1c < 1 the discrete equations have one solution and the iteration converges to it from every start. In a homogeneous medium with both faces reflecting, the flat mode has the eigenvalue exactly cc, so the bound is sharp, and the cosine modes have the eigenvalues (c/2)∑nwn/(1+λ2μn2)(c/2)\sum_n w_n/(1 + \lambda^2\mu_n^2). If the error falls by ρ<1\rho < 1 per iteration, the error after the stop is at most ρ/(1−ρ)\rho/(1 - \rho) times the last change.

Proof: Source iteration sums the collision series, contracts by the scattering ratio in a weighted norm with vacuum, given or reflecting faces, has the Fourier factors of the page, and the change bounds the errorfull

We assume exact arithmetic. The slab, the cross sections and the lines L1 to L6 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, and c=max⁡jΣs,j/Σt,jc = \max_j \Sigma_{s,j}/\Sigma_{t,j}. The directions μn\mu_n and the weights wnw_n are the NN-point Gauss-Legendre rule with NN even. The rule is symmetric, the weights are positive, and they sum to 2. So the directions form N/2N/2 pairs ±μ\pm\mu with the same weight, and the weights of the pairs sum to 1.

For one direction and one cell, ψa\psi_a, ψb\psi_b and ψc\psi_c are the incoming face value, the outgoing face value and the cell value. The diamond difference equations are

∣μ∣ ψb−ψaΔxj+Σt,j ψc=Sj,ψc=ψa+ψb2.(1)|\mu|\,\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 discrete ordinates proof shows that one cell has exactly one solution, ψb=rjψa+2Sj/(Σt,j+2∣μ∣/Δxj)\psi_b = r_j\psi_a + 2S_j/(\Sigma_{t,j} + 2|\mu|/\Delta x_j) with rj=(2−τj)/(2+τj)r_j = (2 - \tau_j)/(2 + \tau_j) and τj=Σt,jΔxj/∣μ∣\tau_j = \Sigma_{t,j}\Delta x_j/|\mu|, and that a sweep in the direction of flight solves a whole direction for a given incoming value.

The sweep with reflection

Lemma 1 (one pair of directions). Fix the sources SjS_j and a pair ±μ\pm\mu with μ>0\mu > 0. For each choice of the faces (vacuum or data at a face, or reflection at one face or at both faces), the equations (1) of the two directions in all cells, with the face conditions, have exactly one solution, and line L4 computes it.

Proof. The outgoing value of a sweep is affine in its incoming value, with the slope R=∏jrjR = \prod_j r_j. Since τj>0\tau_j > 0, ∣rj∣<1|r_j| < 1 for every cell, so ∣R∣<1|R| < 1.

With data or vacuum at both faces, each direction is a separate sweep from its incoming face. With reflection at x=Lx = L only, the direction +μ+\mu has its incoming value at x=0x = 0 given, its sweep gives ψ+(L)\psi_{+}(L), and reflection sets ψ−(L)=ψ+(L)\psi_{-}(L) = \psi_{+}(L), after which the sweep of −μ-\mu is fixed. Reflection at x=0x = 0 only is the mirror case.

With reflection at both faces, let a=ψ+(0)a = \psi_+(0). The sweep of +μ+\mu gives ψ+(L)=Ra+s1\psi_+(L) = Ra + s_1, where s1s_1 is its outgoing value from a zero incoming value. Reflection at x=Lx = L makes this the incoming value of −μ-\mu. That sweep gives ψ−(0)=R(Ra+s1)+t2\psi_-(0) = R(Ra + s_1) + t_2, where t2t_2 is its outgoing value from a zero incoming value, because the two directions have the same ∣μ∣|\mu| and so the same RR. Reflection at x=0x = 0 requires ψ−(0)=a\psi_-(0) = a. So a(1−R2)=Rs1+t2a(1 - R^2) = Rs_1 + t_2. Since ∣R∣<1|R| < 1, this has exactly one solution. Every solution of the equations satisfies this equation, so the solution is unique. □\square

So one iteration of lines L3 and L4 is the affine map ϕ↦Tϕ+b\phi \mapsto T\phi + b. Here bb is the result of line L4 with the source q/2q/2 and the given incoming data. TT is the linear map that sweeps the source Σsv/2\Sigma_s v/2 with zero data (vacuum where a face has data) and the same reflection.

The collision series

Theorem 2 (Neumann series). From ϕ(0)=0\phi^{(0)} = 0, the iterate after ll passes of lines L3 to L4 is

ϕ(l)=∑k=0l−1Tkb.\phi^{(l)} = \sum_{k=0}^{l-1} T^k b .

Proof. By induction on ll. For l=1l = 1, ϕ(1)=T⋅0+b=b\phi^{(1)} = T \cdot 0 + b = b. If the formula holds for ll, then ϕ(l+1)=Tϕ(l)+b=∑k=1lTkb+b\phi^{(l+1)} = T\phi^{(l)} + b = \sum_{k=1}^{l} T^k b + b. □\square

Here bb is the flux of the particles that have not collided yet, and TT turns the flux of the particles after kk collisions into the flux after k+1k + 1 collisions. So iterate ll is the flux of the particles with fewer than ll collisions. The series converges when the spectral radius of TT is less than 1 (Neumann series). The next theorem shows this for c<1c < 1.

Contraction

Write ⟨u,v⟩t=∑jΣt,j ujvj Δxj\langle u, v\rangle_t = \sum_j \Sigma_{t,j}\, u_j v_j\, \Delta x_j and ∥v∥t2=⟨v,v⟩t\|v\|_t^2 = \langle v, v\rangle_t.

Theorem 3 (contraction by cc). For every choice of the faces in Lemma 1 and every vector vv, ∥Tv∥t≤c ∥v∥t\|Tv\|_t \le c\,\|v\|_t. If c<1c < 1, the discrete equations have exactly one solution ϕ\phi, and every start gives ∥ϕ(l)−ϕ∥t≤c l ∥ϕ(0)−ϕ∥t\|\phi^{(l)} - \phi\|_t \le c^{\,l}\,\|\phi^{(0)} - \phi\|_t.

Proof. Fix vv and one pair ±μ\pm\mu, and solve Lemma 1 with Sj=Σs,jvj/2S_j = \Sigma_{s,j}v_j/2 and zero data. Multiply the balance in (1) by ψcΔxj\psi_c\Delta x_j. With the diamond relation, ∣μ∣(ψb−ψa)ψc=∣μ∣(ψb2−ψa2)/2|\mu|(\psi_b - \psi_a)\psi_c = |\mu|(\psi_b^2 - \psi_a^2)/2. Sum over the cells and over the two directions. The face terms telescope:

∣μ∣2(ψ+(L)2−ψ+(0)2+ψ−(0)2−ψ−(L)2)+∥x∥t2+∥y∥t2=⟨s,x+y⟩t,\frac{|\mu|}{2}\Big(\psi_+(L)^2 - \psi_+(0)^2 + \psi_-(0)^2 - \psi_-(L)^2\Big) + \|x\|_t^2 + \|y\|_t^2 = \langle s, x + y\rangle_t,

where xx and yy are the cell values of +μ+\mu and −μ-\mu and sj=Sj/Σt,js_j = S_j/\Sigma_{t,j}. At a reflecting face the two terms of that face cancel, since the incoming value equals the outgoing one. At a face with zero data the incoming term is 0 and the outgoing term is not negative. So the face part is not negative and

∥x∥t2+∥y∥t2≤⟨s,x+y⟩t≤∥s∥t ∥x+y∥t.\|x\|_t^2 + \|y\|_t^2 \le \langle s, x + y\rangle_t \le \|s\|_t\, \|x + y\|_t .

For all vectors, ∥x+y∥t2≤2(∥x∥t2+∥y∥t2)\|x + y\|_t^2 \le 2(\|x\|_t^2 + \|y\|_t^2). So ∥x+y∥t2≤2∥s∥t∥x+y∥t\|x + y\|_t^2 \le 2\|s\|_t\|x + y\|_t, that is ∥x+y∥t≤2∥s∥t\|x + y\|_t \le 2\|s\|_t. Since sj=(Σs,j/Σt,j) vj/2s_j = (\Sigma_{s,j}/\Sigma_{t,j})\,v_j/2 and Σs,j/Σt,j≤c\Sigma_{s,j}/\Sigma_{t,j} \le c, ∥s∥t≤(c/2)∥v∥t\|s\|_t \le (c/2)\|v\|_t. So ∥x+y∥t≤c∥v∥t\|x + y\|_t \le c\|v\|_t.

Line L4 forms Tv=∑pairsw (x+y)Tv = \sum_{\text{pairs}} w\,(x + y). The weights of the pairs are positive and sum to 1, so the triangle inequality gives ∥Tv∥t≤c∥v∥t\|Tv\|_t \le c\|v\|_t. For c<1c < 1, the contraction mapping theorem (fixed-point iteration) gives one fixed point, and the error of iterate ll is TlT^l applied to the first error. □\square

The proof does not use the sign of the cell values, so it holds for diamond difference with thick cells. With reflection at both faces it also holds when the slab is a homogeneous infinite medium, and the next theorem shows that the bound is then attained.

The rate

Theorem 4 (the flat mode). Let all cells have the same Σt\Sigma_t and Σs\Sigma_s, and let both faces reflect. Then the constant vector v=1v = 1 satisfies Tv=c vTv = c\,v. So the bound of Theorem 3 is attained, and for qq constant the iterates from 0 are ϕ(l)=(q/Σt)(1−cl)/(1−c)\phi^{(l)} = (q/\Sigma_t)(1 - c^l)/(1 - c).

Proof. The source is S=Σs/2S = \Sigma_s/2 in every cell. The values ψa=ψb=ψc=S/Σt\psi_a = \psi_b = \psi_c = S/\Sigma_t in every cell and every direction satisfy (1), and they satisfy both reflection conditions. By Lemma 1 they are the solution, so Tv=∑nwnS/Σt=2⋅Σs/(2Σt)=cTv = \sum_n w_n S/\Sigma_t = 2 \cdot \Sigma_s/(2\Sigma_t) = c. In the same way b=q/Σtb = q/\Sigma_t for a constant qq. Theorem 2 then gives ϕ(l)=(q/Σt)(1+c+⋯+cl−1)\phi^{(l)} = (q/\Sigma_t)(1 + c + \cdots + c^{l-1}). □\square

Theorem 5 (Fourier modes of diamond difference). Let the slab have MM equal cells of width hh with the same Σt\Sigma_t and Σs\Sigma_s, and let both faces reflect. For k=0,1,…,M−1k = 0, 1, \ldots, M - 1, let θ=πk/M\theta = \pi k/M and ej=cos⁡(θ(j+1/2))e_j = \cos(\theta(j + 1/2)) for the cells j=0,…,M−1j = 0, \ldots, M - 1. Then Te=ω(θ) eTe = \omega(\theta)\, e with

ω(θ)=c2∑n=1Nwn1+λ2μn2,λ=2tan⁡(θ/2)Σth.\omega(\theta) = \frac{c}{2}\sum_{n=1}^{N} \frac{w_n}{1 + \lambda^2\mu_n^2}, \qquad \lambda = \frac{2\tan(\theta/2)}{\Sigma_t h}.

Proof. Number the faces by integers, so that cell jj lies between faces jj and j+1j + 1. Take the complex source Sj=(Σs/2) eiθ(j+1/2)S_j = (\Sigma_s/2)\,e^{i\theta(j + 1/2)} on all integers jj, and try the face values BμeiθjB_\mu e^{i\theta j} and the cell values Aμeiθ(j+1/2)A_\mu e^{i\theta(j + 1/2)} for the direction μ\mu. The diamond relation gives Aμ=Bμcos⁡(θ/2)A_\mu = B_\mu\cos(\theta/2). The balance, divided by eiθ(j+1/2)e^{i\theta(j + 1/2)}, gives μBμ 2isin⁡(θ/2)/h+ΣtAμ=Σs/2\mu B_\mu\, 2i\sin(\theta/2)/h + \Sigma_t A_\mu = \Sigma_s/2. The two equations give

Aμ=Σs/2Σt+2iμtan⁡(θ/2)/h=c/21+iλμ.A_\mu = \frac{\Sigma_s/2}{\Sigma_t + 2i\mu\tan(\theta/2)/h} = \frac{c/2}{1 + i\lambda\mu}.

Since 0≤θ<π0 \le \theta < \pi, cos⁡(θ/2)>0\cos(\theta/2) > 0, so these values are well defined. The equations (1) are real, so the real parts solve them with the source (Σs/2)ej(\Sigma_s/2)e_j.

We now check the faces. Since A−μA_{-\mu} is the complex conjugate of AμA_\mu, so is B−μB_{-\mu} of BμB_\mu. At face 0, the real parts of BμB_\mu and B−μB_{-\mu} are equal, which is reflection. At face MM the values are the real parts of B±μeiπk=(−1)kB±μB_{\pm\mu}e^{i\pi k} = (-1)^k B_{\pm\mu}, which are again equal. So the real parts, restricted to the slab, satisfy (1) and both reflection conditions. By Lemma 1 they are the solution of line L4. The pair gives Aμ+A−μ=c/(1+λ2μ2)A_\mu + A_{-\mu} = c/(1 + \lambda^2\mu^2), which is real. So

(Te)j=∑pairsw c1+λ2μ2 ej=ω(θ) ej.□(Te)_j = \sum_{\text{pairs}} w\,\frac{c}{1 + \lambda^2\mu^2}\, e_j = \omega(\theta)\, e_j. \qquad\square

The MM vectors ee are orthogonal, so they are all the eigenvectors of TT in this case. Since ω\omega decreases in λ\lambda and λ=0\lambda = 0 only for k=0k = 0, the spectral radius is ω(0)=c\omega(0) = c. When Σth→0\Sigma_t h \to 0 with λ\lambda fixed, the factor is the same formula, which is the factor of the SNS_N equations exact in space. If also N→∞N \to \infty, the sum tends to the integral (c/2)∫−11dμ/(1+λ2μ2)=carctan⁡(λ)/λ(c/2)\int_{-1}^{1} d\mu/(1 + \lambda^2\mu^2) = c\arctan(\lambda)/\lambda, the factor of the continuous problem.

Stopping

Theorem 6 (the change bounds the error). Suppose ∥ϕ(l)−ϕ∥≤ρ ∥ϕ(l−1)−ϕ∥\|\phi^{(l)} - \phi\| \le \rho\,\|\phi^{(l-1)} - \phi\| in some norm, with ρ<1\rho < 1. Then

∥ϕ(l)−ϕ∥≤ρ1−ρ ∥ϕ(l)−ϕ(l−1)∥.\|\phi^{(l)} - \phi\| \le \frac{\rho}{1 - \rho}\,\|\phi^{(l)} - \phi^{(l-1)}\|.

In the homogeneous infinite medium of Theorem 4 with ρ=c\rho = c, equality holds in every norm.

Proof. Write el=ϕ(l)−ϕe_l = \phi^{(l)} - \phi. Then el−1=el−(ϕ(l)−ϕ(l−1))e_{l-1} = e_l - (\phi^{(l)} - \phi^{(l-1)}), so ∥el∥≤ρ∥el−1∥≤ρ∥el∥+ρ∥ϕ(l)−ϕ(l−1)∥\|e_l\| \le \rho\|e_{l-1}\| \le \rho\|e_l\| + \rho\|\phi^{(l)} - \phi^{(l-1)}\|. Move ρ∥el∥\rho\|e_l\| to the left and divide by 1−ρ1 - \rho. In the case of Theorem 4 from ϕ(0)=0\phi^{(0)} = 0, el=−(q/Σt)cl/(1−c)e_l = -(q/\Sigma_t)c^l/(1 - c) and ϕ(l)−ϕ(l−1)=(q/Σt)cl−1\phi^{(l)} - \phi^{(l-1)} = (q/\Sigma_t)c^{l-1} in every cell, so the ratio of the two is exactly c/(1−c)c/(1 - c). □\square

So with c=0.99c = 0.99, a stopping test on the change at a tolerance tol leaves an error of up to 9999 tol in the infinite medium.

Complexity

In the real RAM model, one iteration is one sweep, O(NM)O(NM) operations; reflection at both faces adds two sweeps per pair of directions, which is the same order. So II iterations cost O(INM)O(INM). The infinite medium is the worst case of Theorem 3. There the relative change after ll iterations is cl−1(1−c)/(1−cl)c^{l-1}(1 - c)/(1 - c^l), so the test of line L6 stops after about 1+ln⁡(tol/(1−c))/ln⁡c1 + \ln(\mathrm{tol}/(1 - c))/\ln c iterations (a theorem for that case; it matches the table). For c=0.99c = 0.99 this is about 100 times ln⁡(10−2/tol)\ln(10^{-2}/\mathrm{tol}). The memory is O(M)O(M) for ϕ\phi and the source if each direction is added into ϕ\phi as soon as it is swept; the implementation keeps the O(NM)O(NM) angular fluxes only to return them.

Properties

  • Linear convergence. The error falls by at most cc per iteration in the weighted norm, with any faces (Theorem 3). The bound does not depend on the mesh or on NN.
  • Sharp in thick media. In an infinite medium the rate is exactly cc. In a finite slab the rate is lower, because the flat mode leaks, and it tends to cc as the slab gets thicker.
  • Smoothing. Modes that vary fast in space decay fast, with the factor carctan⁡(λ)/λc\arctan(\lambda)/\lambda in the continuous problem. Only the smooth modes are slow.
  • A physical meaning. Each iteration adds one generation of scattered particles, so the iterates from zero increase toward the solution when the exact transport operator is used and the data are not negative. Diamond difference can give negative values, so this monotone growth is not guaranteed for it.
  • Matrix free. The only operation is a sweep, which inverts the streaming and collision operator in O(NM)O(NM) operations.

Variants and improvements

  • Diffusion synthetic acceleration. After each sweep, solve a diffusion equation for the error and add the correction. By the Fourier analysis of the continuous problem in an infinite medium, this reduces the factor to at most about 0.2247c0.2247c, if the diffusion equation is discretized consistently with the transport scheme (diffusion synthetic acceleration).
  • Krylov methods. The fixed point ϕ=Tϕ+b\phi = T\phi + b is the linear system (I−T)ϕ=b(I - T)\phi = b. GMRES solves it with one sweep per matrix-vector product. As a rule of thumb from the review of Adams and Larsen (2002), it converges much faster than plain iteration for cc near 1, and more so with a diffusion preconditioner.
  • Inner and outer iterations. With energy groups (multigroup approximation), source iteration is the inner iteration of each group, and an outer Gauss-Seidel iteration over the groups handles the scattering between groups. For a reactor, the k-eigenvalue problem adds an outer power iteration on the fission source.
  • Other sweeps. The same iteration works with any spatial scheme for line L4 (step, linear discontinuous, characteristics) and in two and three dimensions; the contraction factor cc of the continuous problem stays the same.

When to use it

Use plain source iteration when particles collide only a few times before they are absorbed or escape: cc well below 1, or a slab that is thin in mean free paths. Shielding problems with strong absorption are of this type. In thick scattering media, such as a reactor core with water or radiative transfer in optically thick matter, use it only inside an accelerated or Krylov method. It is also the reference iteration against which accelerations are measured.

Pitfalls

  • False convergence (line L6). A small change does not mean a small error. With c=0.99c = 0.99 the error can be 99 times the last change. Divide the tolerance by c/(1−c)c/(1 - c), or estimate the rate from the ratio of successive changes and use Theorem 6.
  • Slow convergence that looks like stagnation. For c=0.999c = 0.999 the change falls by 0.1 percent per iteration. A run with a cap on the number of iterations can stop far from the solution without a warning.
  • Lagged reflection. If the reflected value is taken from the last iteration, as in the discrete ordinates page, reflection adds its own slow mode. Sweeping the leaving directions first (one reflecting face) or solving for the incoming value (two faces) avoids this.
  • The weight convention (line L3). The factor 1/21/2 belongs to weights that sum to 2. With weights that sum to 1 or to 4π4\pi the source must be divided to match, or the effective cc is wrong.
  • Negative values. Diamond difference with thick cells gives negative angular fluxes. The iteration still converges (Theorem 3), but a negative flux fixup makes the sweep nonlinear, and the convergence proof no longer applies.

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.

source_iteration.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/source-iteration/. The authors are listed in prov/ZGYN85.jsonl.
"""Source iteration for the one-speed S_N equations in a slab.

The slab has M cells of widths dx[j] with the total cross section sigma_t[j],
the scattering cross section sigma_s[j] (both in cm^-1) and an isotropic
source q[j]. Scattering is isotropic. The scalar flux is phi = integral of
psi over mu in [-1, 1], so the emission per unit mu is (sigma_s phi + q) / 2
and the Gauss-Legendre weights sum to 2. Space is discretized by diamond
differences.

Source iteration: phi_(l+1) = sweep of the source (sigma_s phi_l + q) / 2,
integrated with the weights. Each sweep inverts the streaming and collision
operator exactly, direction by direction.

Faces: "vacuum", "reflect", or a list of incoming angular fluxes (one per
entering direction, in the order of the rule). Reflection is exact inside
each sweep, not lagged: with one reflecting face the directions that leave
through it are swept first; with two reflecting faces the incoming value of
each pair of mirror directions is found from the scalar equation
a = R2 (R1 a + s1) + t2, which uses that a diamond difference sweep is affine
in its incoming value.
"""

import math


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


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))
        for _ in range(100):
            p, dp = legendre(n, x)
            step = p / dp
            x -= step
            if abs(step) < 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 dd_sweep(mu: float, psi_in: float, sigma_t, src, dx):
    """Diamond difference sweep of one direction. Returns (cell values, outgoing value)."""
    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:
        a = 2.0 * abs(mu) / dx[j]
        cells[j] = (src[j] + a * psi) / (sigma_t[j] + a)
        psi = 2.0 * cells[j] - psi
    return cells, psi


def transmission_factor(mu: float, sigma_t, dx):
    """R = product of (2 - tau_j) / (2 + tau_j): the outgoing value per unit incoming value without a source."""
    r = 1.0
    for st, h in zip(sigma_t, dx):
        tau = st * h / abs(mu)
        r *= (2.0 - tau) / (2.0 + tau)
    return r


def sweep_all(mus, ws, sigma_t, src, dx, left="vacuum", right="vacuum"):
    """Sweep every direction with the cell source src. Returns (phi, leak_left, leak_right).

    leak_left and leak_right are the partial currents that leave at x = 0 and at x = L."""
    n, m = len(mus), len(dx)
    phi = [0.0] * m
    leak_left = leak_right = 0.0
    pos = [k for k in range(n) if mus[k] > 0]
    for idx, k in enumerate(pos):
        kb = n - 1 - k  # the mirror direction, mus[kb] = -mus[k]
        mu, w = mus[k], ws[k]
        if left == "reflect" and right == "reflect":
            _, s1 = dd_sweep(mu, 0.0, sigma_t, src, dx)
            _, t2 = dd_sweep(-mu, 0.0, sigma_t, src, dx)
            r = transmission_factor(mu, sigma_t, dx)
            a = (r * s1 + t2) / (1.0 - r * r)
            fwd, out_r = dd_sweep(mu, a, sigma_t, src, dx)
            bwd, out_l = dd_sweep(-mu, out_r, sigma_t, src, dx)
        elif left == "reflect":
            b = 0.0 if right == "vacuum" else right[len(pos) - 1 - idx]
            bwd, out_l = dd_sweep(-mu, b, sigma_t, src, dx)
            fwd, out_r = dd_sweep(mu, out_l, sigma_t, src, dx)
        elif right == "reflect":
            a = 0.0 if left == "vacuum" else left[idx]
            fwd, out_r = dd_sweep(mu, a, sigma_t, src, dx)
            bwd, out_l = dd_sweep(-mu, out_r, sigma_t, src, dx)
        else:
            a = 0.0 if left == "vacuum" else left[idx]
            b = 0.0 if right == "vacuum" else right[len(pos) - 1 - idx]
            fwd, out_r = dd_sweep(mu, a, sigma_t, src, dx)
            bwd, out_l = dd_sweep(-mu, b, sigma_t, src, dx)
        for j in range(m):
            phi[j] += w * (fwd[j] + bwd[j])
        if right != "reflect":
            leak_right += w * mu * out_r
        if left != "reflect":
            leak_left += w * mu * out_l
    return phi, leak_left, leak_right


def source_iteration(n, sigma_t, sigma_s, q, dx, left="vacuum", right="vacuum",
                     tol=1e-10, max_iter=100000, phi0=None):
    """Iterate phi <- sweep((sigma_s phi + q) / 2) until the largest change is at most tol times the largest phi.

    Returns a dict with phi, the leakages, the number of iterations and the
    list of the largest changes (one per iteration)."""
    mus, ws = gauss_legendre(n)
    m = len(dx)
    phi = list(phi0) if phi0 is not None else [0.0] * m  # @line L1
    changes = []
    leak_left = leak_right = 0.0
    it = 0
    for it in range(1, max_iter + 1):  # @line L2
        src = [(sigma_s[j] * phi[j] + q[j]) / 2.0 for j in range(m)]  # @line L3
        new, leak_left, leak_right = sweep_all(mus, ws, sigma_t, src, dx, left, right)  # @line L4
        change = max(abs(new[j] - phi[j]) for j in range(m))  # @line L5
        phi = new
        changes.append(change)
        if change <= tol * (max(abs(v) for v in phi) or 1.0):  # @line L6
            break
    return {"phi": phi, "leak_left": leak_left, "leak_right": leak_right,
            "iterations": it, "changes": changes}


def fourier_continuous(lam: float, c: float) -> float:
    """Eigenvalue of source iteration for the error mode exp(i lam sigma_t x) in an infinite medium, exact angle and space."""
    if lam == 0.0:
        return c
    return c * math.atan(lam) / lam


def fourier_sn(lam: float, c: float, mus, ws) -> float:
    """The same with the S_N quadrature in angle and exact space: (c / 2) sum of w / (1 + lam^2 mu^2)."""
    return 0.5 * c * sum(w / (1.0 + (lam * mu) ** 2) for mu, w in zip(mus, ws))


def fourier_dd(theta: float, c: float, tau_cell: float, mus, ws) -> float:
    """The same with S_N and diamond differences on equal cells of optical thickness tau_cell, for the mode exp(i theta j)."""
    lam = 2.0 * math.tan(theta / 2.0) / tau_cell
    return fourier_sn(lam, c, mus, ws)


def error_bound(change: float, rho: float) -> float:
    """Bound on the remaining error when the error contracts by rho < 1 per iteration and the last change was change."""
    return rho / (1.0 - rho) * change
test_source_iteration.py 155 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/source-iteration/. The authors are listed in prov/ZGYN85.jsonl.
import math
import random
import unittest

from source_iteration import (dd_sweep, error_bound, fourier_continuous, fourier_dd, fourier_sn,
                              gauss_legendre, source_iteration, sweep_all)


def weighted_norm(v, sigma_t, dx):
    return math.sqrt(sum(s * x * x * h for x, s, h in zip(v, sigma_t, dx)))


class TestInfiniteMedium(unittest.TestCase):
    def test_iterates_are_the_neumann_series(self):
        # reflecting faces, sigma_t = 1, c = 0.5, q = 1: phi_l = 1 + c + ... + c^(l-1)
        for l in range(1, 6):
            r = source_iteration(2, [1.0, 1.0], [0.5, 0.5], [1.0, 1.0], [1.0, 1.0],
                                 "reflect", "reflect", tol=0.0, max_iter=l)
            exact = (1.0 - 0.5 ** l) / 0.5
            for p in r["phi"]:
                self.assertAlmostEqual(p, exact, places=13)

    def test_error_falls_by_exactly_c(self):
        for c in (0.5, 0.9, 0.99):
            r = source_iteration(8, [1.0] * 10, [c] * 10, [1.0] * 10, [0.5] * 10,
                                 "reflect", "reflect", tol=0.0, max_iter=20)
            ch = r["changes"]
            for i in range(len(ch) - 1):
                self.assertAlmostEqual(ch[i + 1] / ch[i], c, places=7)

    def test_error_is_c_over_one_minus_c_times_the_last_change(self):
        for c in (0.5, 0.9, 0.99):
            r = source_iteration(2, [1.0] * 2, [c] * 2, [1.0] * 2, [1.0] * 2, "reflect", "reflect", tol=1e-8)
            exact = 1.0 / (1.0 - c)
            err = exact - r["phi"][0]
            self.assertAlmostEqual(err / r["changes"][-1], c / (1.0 - c), delta=1e-5 * c / (1.0 - c))
            self.assertAlmostEqual(error_bound(r["changes"][-1], c), err, delta=1e-5 * err)

    def test_iteration_count(self):
        # the change test stops at the first l with c^(l-1) (1 - c) / (1 - c^l) <= tol
        for c, expected in ((0.5, 27), (0.9, 154), (0.99, 1376)):
            r = source_iteration(2, [1.0] * 2, [c] * 2, [1.0] * 2, [1.0] * 2, "reflect", "reflect", tol=1e-8)
            self.assertEqual(r["iterations"], expected)


class TestFourier(unittest.TestCase):
    def test_continuous_factor(self):
        self.assertEqual(fourier_continuous(0.0, 0.9), 0.9)
        self.assertAlmostEqual(fourier_continuous(1.0, 1.0), math.pi / 4.0, places=15)
        for lam in (0.1, 1.0, 3.0, 30.0):
            self.assertLess(fourier_continuous(lam, 1.0), 1.0)
        mus, ws = gauss_legendre(64)
        for lam in (0.5, 2.0, 5.0):
            self.assertAlmostEqual(fourier_sn(lam, 0.8, mus, ws), fourier_continuous(lam, 0.8), places=6)

    def test_reflecting_slab_cosine_modes_are_eigenvectors(self):
        m, h, c = 40, 0.5, 0.9
        mus, ws = gauss_legendre(8)
        for k in (0, 1, 3, 10, 39):
            theta = math.pi * k / m
            e = [math.cos(theta * (j + 0.5)) for j in range(m)]
            r = source_iteration(8, [1.0] * m, [c] * m, [0.0] * m, [h] * m, "reflect", "reflect",
                                 tol=0.0, max_iter=1, phi0=e)
            omega = fourier_dd(theta, c, h, mus, ws)
            for j in range(m):
                self.assertAlmostEqual(r["phi"][j], omega * e[j], places=12)
            self.assertLessEqual(omega, c + 1e-15)

    def test_thin_cells_approach_the_sn_factor(self):
        mus, ws = gauss_legendre(8)
        lam = 1.5
        for tau in (0.1, 0.01):
            theta = 2.0 * math.atan(lam * tau / 2.0)
            self.assertAlmostEqual(fourier_dd(theta, 1.0, tau, mus, ws), fourier_sn(lam, 1.0, mus, ws), places=12)


class TestSlab(unittest.TestCase):
    def test_rate_approaches_c_in_a_thick_slab(self):
        rates = []
        for length in (1.0, 10.0, 100.0):
            m = int(length / 0.25)
            r = source_iteration(8, [1.0] * m, [0.99] * m, [0.0] * m, [0.25] * m, tol=0.0, max_iter=300,
                                 phi0=[1.0] * m)
            ch = r["changes"]
            rates.append(ch[-1] / ch[-2])
        self.assertLess(rates[0], 0.65)
        self.assertLess(rates[0], rates[1])
        self.assertLess(rates[1], rates[2])
        self.assertLess(rates[2], 0.99)
        self.assertGreater(rates[2], 0.985)

    def test_contraction_in_weighted_norm(self):
        rng = random.Random(7)
        m = 30
        st = [rng.uniform(0.5, 3.0) for _ in range(m)]
        ss = [s * rng.uniform(0.0, 0.95) for s in st]
        dx = [rng.uniform(0.05, 1.5) for _ in range(m)]
        c = max(b / a for a, b in zip(st, ss))
        exact = source_iteration(6, st, ss, [1.0] * m, dx, tol=1e-15)["phi"]
        for left, right in (("vacuum", "vacuum"), ("reflect", "vacuum"), ("vacuum", "reflect")):
            exact = source_iteration(6, st, ss, [1.0] * m, dx, left, right, tol=1e-15)["phi"]
            prev = None
            for l in range(1, 15):
                phi = source_iteration(6, st, ss, [1.0] * m, dx, left, right, tol=0.0, max_iter=l)["phi"]
                err = weighted_norm([a - b for a, b in zip(phi, exact)], st, dx)
                if prev is not None and prev > 1e-12:
                    self.assertLessEqual(err, c * prev * (1 + 1e-9))
                prev = err

    def test_balance(self):
        m, length = 40, 10.0
        r = source_iteration(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)
        r = source_iteration(8, [1.0] * m, [0.9] * m, [1.0] * m, [length / m] * m, "reflect", "vacuum", tol=1e-13)
        absorbed = sum(0.1 * p * length / m for p in r["phi"])
        self.assertEqual(r["leak_left"], 0.0)
        self.assertAlmostEqual(absorbed + r["leak_right"], length, places=9)

    def test_pure_absorber_needs_one_sweep(self):
        m = 50
        r = source_iteration(4, [1.0] * m, [0.0] * m, [0.0] * m, [2.0 / m] * m, left=[1.0, 1.0], tol=1e-14)
        self.assertEqual(r["iterations"], 2)
        self.assertEqual(r["changes"][-1], 0.0)

    def test_reflection_matches_a_doubled_slab(self):
        # a slab with a reflecting right face equals the left half of a symmetric slab twice as wide
        m = 20
        st = [1.0 + 0.1 * j for j in range(m)]
        ss = [0.7 * s for s in st]
        q = [1.0 + 0.05 * j for j in range(m)]
        dx = [0.2] * m
        half = source_iteration(4, st, ss, q, dx, "vacuum", "reflect", tol=1e-14)["phi"]
        full = source_iteration(4, st + st[::-1], ss + ss[::-1], q + q[::-1], dx + dx, tol=1e-14)["phi"]
        for j in range(m):
            self.assertAlmostEqual(half[j], full[j], places=10)

    def test_incoming_data_order_on_the_right(self):
        mus, ws = gauss_legendre(4)
        m = 10
        st, dx = [1.0] * m, [0.1] * m
        src = [0.0] * m
        # incoming at x = L for the directions mu < 0 in the order of the rule: mus[0], mus[1]
        phi, leak_l, _ = sweep_all(mus, ws, st, src, dx, "vacuum", [2.0, 5.0])
        expect = 0.0
        for k, v in ((0, 2.0), (1, 5.0)):
            _, out = dd_sweep(mus[k], v, st, src, dx)
            expect += ws[k] * abs(mus[k]) * out
        self.assertAlmostEqual(leak_l, expect, places=14)


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

History

Source iteration is the natural way to solve the discrete ordinates equations, and it was used from the first SNS_N codes of the 1950s on. Its slow convergence for cc near 1 led to the synthetic methods, in which a cheaper low-order problem corrects each transport iterate: Kopp proposed the idea in 1963, and Alcouffe (1977) showed how to make the diffusion correction stable with diamond difference. Lewis and Miller (1984) give the iteration and its infinite medium rate in textbook form. Adams and Larsen (2002) review its Fourier analysis together with the accelerations and the Krylov methods that replace it.

References

  1. E. E. Lewis and W. F. Miller, Jr., Computational Methods of Neutron Transport, Wiley, 1984, the sections on source iteration in slab geometry and its convergence in an infinite medium
  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 source iteration, its Fourier analysis and its stopping criteria

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
  • History with a source
  • at least three sources
  • a scene preset for the example