Algorithm Search⌘K

Algorithmadvanced

Method of characteristics for neutron transport

Also called MOC transport.

Solves the transport equation along long tracks that cross the geometry, the standard method for detailed reactor lattice calculations.

Time
O(I T P) worst
Space
O(T + R) extra
Where
I = the number of iterations; P = the number of polar angles; R = the number of flat source regions; T = the number of track segments
Properties
deterministicnot exactiterativenot randomized

The method of characteristics (MOC) solves the transport equation by following particles along many parallel straight lines, called tracks, that cross the whole geometry. The geometry is cut into flat source regions, in which the emission of particles is taken as constant. Along each piece of a track inside one region, the transport equation is an ordinary differential equation with a constant source, and its solution is one exponential. The method adds up the change of the angular flux along all the pieces in a region to get the scalar flux there, and it repeats this as a source iteration until the scattering source settles. Because the tracks need no mesh that fits the cells, MOC handles the circles and rings of fuel pins exactly, and it is the standard method for detailed two-dimensional reactor lattice calculations.

In plain words

Draw many thin parallel lines across a map of the reactor, for a set of directions. Each line crosses a row of regions. Walk along a line from the edge where nothing comes in. In each region, some of the particles you carry get absorbed or turned aside, and the region adds new particles of its own. A simple formula gives what leaves the region from what entered it.

Every time you walk through a region, note how much the count changed. Add these notes for all lines and all directions, and you know how many particles are in each region on average.

The new particles in a region depend on how many particles hit it and bounce. So you walk all the lines again with the new counts, and you repeat until the counts stop changing.

The problem

The domain is a rectangle [0,W]×[0,H][0, W] \times [0, H], infinite in zz, cut into regions ii of the area AiA_i with the total cross section Σt,i>0\Sigma_{t,i} > 0, the scattering cross section Σs,i≥0\Sigma_{s,i} \ge 0 and the isotropic source qiq_i, all in units of cm−1\mathrm{cm}^{-1} and particles per cm3\mathrm{cm}^3 per second. The faces are vacuum. The unknown is the scalar flux ϕ=∫ψ dΩ\phi = \int\psi\,d\Omega over the unit sphere, and the emission per steradian is Qi=(Σs,iϕi+qi)/(4π)Q_i = (\Sigma_{s,i}\phi_i + q_i)/(4\pi). The one-speed equation is

Ω⋅∇ψ+Σtψ=Q.\Omega\cdot\nabla\psi + \Sigma_t\psi = Q .

A direction has an azimuthal angle α\alpha in the plane and a polar angle θ\theta to the zz axis. The implementation takes nan_a azimuthal angles αa=π(a+1/2)/na\alpha_a = \pi(a + 1/2)/n_a in (0,π)(0, \pi), each track walked in both senses, with the weight π/na\pi/n_a, and npn_p Gauss polar cosines μp\mu_p in (0,1)(0, 1) with weights wpw_p that sum to 2, so the weights of all directions sum to 4π4\pi. For each angle the tracks are straight lines at the spacing δα\delta_\alpha, and each track is cut into segments (i,ℓ)(i, \ell), one for each region that it crosses, with the in-plane length ℓ\ell. The goal is the region fluxes ϕi\phi_i of the flat source MOC equations.

The algorithm

  1. MOC(regions, Σt, Σs, q, n_a, n_p, spacing, tol)
  2. 1for each angle α: lay tracks at the spacing δ_α and cut each into segments (i, ℓ)
  3. 2φ_i ← 0 for every region i
  4. 3repeat
  5. 4for each region i: Q_i/Σt_i ← (Σs_i φ_i + q_i) / (4π Σt_i); tally_i ← 0; leak ← 0
  6. 5for each track, each polar angle p and each of the two senses: ψ ← 0 (vacuum inflow)
  7. 6for each segment (i, ℓ) in the order of flight: Δψ ← (ψ - Q_i/Σt_i)(1 - exp(-Σt_i ℓ / sin θ_p)); tally_i ← tally_i + w Δψ; ψ ← ψ - Δψ
  8. 7leak ← leak + w ψ
  9. 8φ_i ← 4π Q_i/Σt_i + tally_i / (Σt_i A_i) for every region i
  10. 9until the largest change of φ is at most tol times the largest φ

The weight of a track in line L6 is w=(π/na) wp δαsin⁡θpw = (\pi/n_a)\,w_p\,\delta_\alpha\sin\theta_p. Line L1 runs once: the tracks and segments depend only on the geometry and the angles, and real codes store them. Line L6 is the exact solution of the equation along a straight path with a constant source: with the optical length τ=Σtℓ/sin⁡θ\tau = \Sigma_t\ell/\sin\theta of the 3D path, the leaving value is ψout=ψine−τ+(Q/Σt)(1−e−τ)\psi_{\mathrm{out}} = \psi_{\mathrm{in}}e^{-\tau} + (Q/\Sigma_t)(1 - e^{-\tau}), and Δψ=ψin−ψout\Delta\psi = \psi_{\mathrm{in}} - \psi_{\mathrm{out}}. Line L8 turns the tally into the region flux: the particles lost from the tracks in a region are the particles that the region absorbs or scatters, less those it emits. Line L7 counts the particles that leave the domain. Lines L5 to L7 are a transport sweep along the tracks instead of over cells, and there is no ordering problem, since every track is a line from one face to another.

The implementation lays out the tracks on a rectangle grid of nx×nyn_x \times n_y regions and computes the cut points of each track with the grid lines. For real lattices, a ray tracer cuts the tracks at circles and planes in the same way.

Example

One segment by hand. Take ψin=0\psi_{\mathrm{in}} = 0, Q/Σt=1Q/\Sigma_t = 1 and τ=1.25\tau = 1.25. Line L6 gives Δψ=(0−1)(1−e−1.25)=−0.7134952\Delta\psi = (0 - 1)(1 - e^{-1.25}) = -0.7134952, so ψout=0.7134952\psi_{\mathrm{out}} = 0.7134952, and the mean over the segment is 1+(0−0.7134952)/1.25=0.42920381 + (0 - 0.7134952)/1.25 = 0.4292038.

A tall strip against the exact slab flux. A pure absorber with Σt=1\Sigma_t = 1 and q=1q = 1 fills W=2W = 2, H=20H = 20, cut into nx=10n_x = 10 by ny=5n_y = 5 regions. In the middle row the strip acts as a slab of 2 mean free paths, whose exact flux is ϕ(x)=q2Σt(2−E2(Σtx)−E2(Σt(W−x)))\phi(x) = \tfrac{q}{2\Sigma_t}\left(2 - E_2(\Sigma_tx) - E_2(\Sigma_t(W - x))\right) with the exponential integral E2E_2 (Theorem 6 of the proof). The top and bottom faces change this by less than 3.4×10−43.4 \times 10^{-4}. The exact averages of the five left cells of the middle row (the right five are the mirror image) are 0.6084070.608407, 0.7353780.735378, 0.7989860.798986, 0.8335350.833535 and 0.8490270.849027. With no scattering, the second iteration already stops. The largest error of the middle row is:

nan_a npn_p spacing (cm) largest error segments
4 2 0.1 2.818×10−22.818 \times 10^{-2} 5520
8 3 0.05 1.188×10−21.188 \times 10^{-2} 21556
16 3 0.05 5.681×10−35.681 \times 10^{-3} 42904
16 5 0.02 3.718×10−33.718 \times 10^{-3} 107168
32 5 0.02 1.838×10−31.838 \times 10^{-3} 214148

At (32,5,0.02)(32, 5, 0.02) the five values are 0.6065700.606570, 0.7349350.734935, 0.7989850.798985, 0.8336910.833691 and 0.8492040.849204. Doubling the azimuthal angles about halves the error here, which is a measurement for this problem; the error is largest in the cells at the faces, where the flux changes fastest with the direction.

Track areas. The tracks of each angle cover the area of each region only approximately, since a region gets a whole number of tracks. On a 4×44 \times 4 cm square with 8×88 \times 8 regions, the track area of a region for one angle differs from its true area by at most 3.829×10−33.829 \times 10^{-3} of the area with na=8n_a = 8 and the spacing 0.05, and by at most 4.487×10−34.487 \times 10^{-3} with na=4n_a = 4 and the spacing 0.1. The total track area, averaged over the angles, is 16.000916.0009 and 16.006216.0062 against the true 1616. Line L8 uses the true area in the flat source part of the flux (Lemma 3 of the proof), so these errors do not break the balance.

Balance and symmetry. On the same square with a heterogeneous, symmetric map of Σt\Sigma_t, Σs\Sigma_s and qq, the iteration stops after 40 iterations, and absorption plus leakage equals the total source to 1.3×10−121.3 \times 10^{-12} of the source. The flux is symmetric under the mirror in xx to 1.6×10−151.6 \times 10^{-15}. For a uniform medium with the scattering ratio c=0.7c = 0.7, it takes 50 iterations, with the flux 2.3535 in a center region and 1.0032 in a corner region.

Scattering ratio and iterations. On a square of side 8 cm with 8×88 \times 8 regions, (na,np,spacing)=(4,2,0.2)(n_a, n_p, \text{spacing}) = (4, 2, 0.2) and the tolerance 10−610^{-6}, the number of iterations is 19 for c=0.5c = 0.5, 66 for c=0.9c = 0.9 and 125 for c=0.99c = 0.99. The growth is that of source iteration; leakage from the 8 mean free path square keeps the count at c=0.99c = 0.99 much below that of an infinite medium.

Correctness

The proofs are in the proof file. Line L6 is the exact solution along a straight segment with a flat source (Lemma 1), and the cut points of a track with the grid lines give segments that each lie in one region (Lemma 2). Line L8 equals the quadrature average of the angular flux over the region, with the track area replaced by the true area in the flat source part (Lemma 3). The sum of the tallies over all regions telescopes along every track, so absorption plus leakage equals the source in every iteration, exactly up to the change of the scattering source, for any spacing and any quadrature (Theorem 4). The iteration contracts in the maximum norm with the factor at most c(1+2ε)c(1 + 2\varepsilon), where ε\varepsilon is the largest excess of a track area over the true area (Theorem 5), so it converges to a unique fixed point when this factor is below 1. For a strip that is long in yy, the flux in the middle tends to the exact slab flux with E2E_2 (Theorem 6), which is the reference of the example.

Proof: MOC solves each segment exactly for a flat source, conserves particles in every iteration, contracts by about the scattering ratio, and reduces to the exact slab flux for a long stripfull

We assume exact arithmetic. The rectangle, the cells, the tracks and the lines L1 to L9 are those of the page. Every cell ii has the area AiA_i, Σt,i>0\Sigma_{t,i} > 0 and 0≤Σs,i≤c Σt,i0 \le \Sigma_{s,i} \le c\,\Sigma_{t,i}, and all faces are vacuum. A direction is a track direction α\alpha with the azimuthal weight wα=π/naw_\alpha = \pi/n_a and a polar cosine μp\mu_p with the weight wpw_p, where the wpw_p sum to 2 and sin⁡θp=1−μp2\sin\theta_p = \sqrt{1 - \mu_p^2}. The weights of all directions sum to 2na⋅(π/na)⋅2=4π2n_a \cdot (\pi/n_a) \cdot 2 = 4\pi. A track of the angle α\alpha carries the spacing δα\delta_\alpha, and it is cut into segments, one for each cell that it crosses, of the in-plane lengths ℓ\ell.

One segment

Lemma 1 (the segment solve is exact). Let a segment of in-plane length ℓ\ell lie in cell ii, with the emission density QiQ_i per steradian. Along the direction with the polar angle θ\theta, the transport equation is sin⁡θ dψ/ds+Σtψ=Q\sin\theta\,d\psi/ds + \Sigma_t\psi = Q in the in-plane distance ss. Its solution from the entering value ψin\psi_{\mathrm{in}} is

ψ(s)=QΣt+(ψin−QΣt)e−Σts/sin⁡θ,\psi(s) = \frac{Q}{\Sigma_t} + \left(\psi_{\mathrm{in}} - \frac{Q}{\Sigma_t}\right)e^{-\Sigma_ts/\sin\theta},

so line L6 gives the exact leaving value ψout=ψ(ℓ)\psi_{\mathrm{out}} = \psi(\ell), and the mean of ψ\psi over the segment is ψˉ=Q/Σt+(ψin−ψout)/τ\bar\psi = Q/\Sigma_t + (\psi_{\mathrm{in}} - \psi_{\mathrm{out}})/\tau with τ=Σtℓ/sin⁡θ\tau = \Sigma_t\ell/\sin\theta.

Proof. A 3D path that makes the angle θ\theta with the zz axis covers the in-plane distance ss over the path length s/sin⁡θs/\sin\theta, so the streaming term Ω⋅∇ψ\Omega\cdot\nabla\psi is sin⁡θ dψ/ds\sin\theta\,d\psi/ds. The formula solves this linear equation with the initial value ψin\psi_{\mathrm{in}}. Integrating it over [0,ℓ][0, \ell] gives ℓ ψˉ=ℓQ/Σt+(ψin−Q/Σt)(1−e−τ)ℓ/τ\ell\,\bar\psi = \ell Q/\Sigma_t + (\psi_{\mathrm{in}} - Q/\Sigma_t)(1 - e^{-\tau})\ell/\tau, and (ψin−Q/Σt)(1−e−τ)=ψin−ψout(\psi_{\mathrm{in}} - Q/\Sigma_t)(1 - e^{-\tau}) = \psi_{\mathrm{in}} - \psi_{\mathrm{out}}. □\square

In line L6, Δψ=(ψ−Q/Σt)(1−e−τ)\Delta\psi = (\psi - Q/\Sigma_t)(1 - e^{-\tau}) is ψin−ψout\psi_{\mathrm{in}} - \psi_{\mathrm{out}}, and ψ←ψ−Δψ\psi \leftarrow \psi - \Delta\psi is ψout\psi_{\mathrm{out}}. Since 0<1−e−τ<10 < 1 - e^{-\tau} < 1, ψout\psi_{\mathrm{out}} lies between ψin\psi_{\mathrm{in}} and Q/ΣtQ/\Sigma_t.

Lemma 2 (the segments are correct). The cut points of a track are its entry and exit points and all its crossings with the inner grid lines. So each open interval between two cut points lies in one cell, the cell of its midpoint, and the segments of a track partition its chord.

Proof. A line meets each grid line at most once (or lies on it, which a track with sin⁡α>0\sin\alpha > 0 and offset at a midpoint does only with measure zero, and then the cut test treats it as not crossing). Between two consecutive cut points the track crosses no grid line, so it stays in one cell. □\square

The cell flux and the balance

Let Φi\Phi_i be the sum over the directions and the segments in cell ii of wαwpδαℓ ψˉw_\alpha w_p\delta_\alpha\ell\,\bar\psi, which is the quadrature for ∫Ai∫ψ dΩ dA\int_{A_i}\int\psi\,d\Omega\,dA: the tracks of each direction sample the cell with the spacing δα\delta_\alpha, and each segment contributes the area δαℓ\delta_\alpha\ell. Let ai=14πAi∑wαwpδαℓa_i = \frac{1}{4\pi A_i}\sum w_\alpha w_p\delta_\alpha\ell be the ratio of the track area of cell ii to its true area, averaged over the directions.

Lemma 3 (line L8). Line L8 is

ϕi=ΦiAi+(1−ai) 4πQiΣt,i.\phi_i = \frac{\Phi_i}{A_i} + (1 - a_i)\,\frac{4\pi Q_i}{\Sigma_{t,i}}.

So it is the quadrature average of the angular flux, with the track area replaced by the true area in the flat-source part. If ai=1a_i = 1, ϕi=Φi/Ai\phi_i = \Phi_i/A_i.

Proof. The tally of line L6 adds wαwpδαsin⁡θp(ψin−ψout)w_\alpha w_p\delta_\alpha\sin\theta_p(\psi_{\mathrm{in}} - \psi_{\mathrm{out}}) for each segment. By Lemma 1, sin⁡θ(ψin−ψout)=sin⁡θ τ(ψˉ−Q/Σt)=Σtℓ(ψˉ−Q/Σt)\sin\theta(\psi_{\mathrm{in}} - \psi_{\mathrm{out}}) = \sin\theta\,\tau(\bar\psi - Q/\Sigma_t) = \Sigma_t\ell(\bar\psi - Q/\Sigma_t). So the tally of cell ii is Σt,iΦi−Qi⋅4πAiai\Sigma_{t,i}\Phi_i - Q_i\cdot 4\pi A_ia_i, and line L8 gives 4πQi/Σt,i+Φi/Ai−4πaiQi/Σt,i4\pi Q_i/\Sigma_{t,i} + \Phi_i/A_i - 4\pi a_iQ_i/\Sigma_{t,i}. □\square

Theorem 4 (balance in every iteration). Let ϕ\phi be the old iterate, Qi=(Σs,iϕi+qi)/(4π)Q_i = (\Sigma_{s,i}\phi_i + q_i)/(4\pi), and ϕ′\phi' the new iterate with the leakage Λ\Lambda of line L7. Then

∑i(Σt,iϕi′−Σs,iϕi−qi)Ai+Λ=0.\sum_i\left(\Sigma_{t,i}\phi'_i - \Sigma_{s,i}\phi_i - q_i\right)A_i + \Lambda = 0 .

At convergence (ϕ′=ϕ\phi' = \phi) this is the exact balance ∑iΣa,iϕiAi+Λ=∑iqiAi\sum_i\Sigma_{a,i}\phi_iA_i + \Lambda = \sum_iq_iA_i, for any track spacing and any quadrature.

Proof. By line L8, (Σt,iϕi′−4πQi)Ai(\Sigma_{t,i}\phi'_i - 4\pi Q_i)A_i is the tally of cell ii. The sum of the tallies over all cells is the sum over all tracks and directions of wαwpδαsin⁡θpw_\alpha w_p\delta_\alpha\sin\theta_p times the sum of ψin−ψout\psi_{\mathrm{in}} - \psi_{\mathrm{out}} over the segments of the track. This telescopes to the value entering the domain, 0 for vacuum, minus the value leaving it. Line L7 adds wαwpδαsin⁡θpw_\alpha w_p\delta_\alpha\sin\theta_p times the leaving value into Λ\Lambda, so the sum of the tallies is −Λ-\Lambda. Finally 4πQi=Σs,iϕi+qi4\pi Q_i = \Sigma_{s,i}\phi_i + q_i. □\square

The weight wαwpδαsin⁡θp ψw_\alpha w_p\delta_\alpha\sin\theta_p\,\psi of a leaving track is the quadrature of the outgoing current ∫Ω⋅n ψ dΩ\int\Omega\cdot n\,\psi\,d\Omega over the face: a track bundle of the width δα\delta_\alpha crosses a face of the length δα/∣cos⁡β∣\delta_\alpha/|\cos\beta|, where β\beta is the angle between the track and the normal, and Ω⋅n=sin⁡θcos⁡β\Omega\cdot n = \sin\theta\cos\beta.

Convergence of the source iteration

Theorem 5 (contraction). Let ε=max⁡imax⁡(0,ai−1)\varepsilon = \max_i\max(0, a_i - 1). Then the iteration of lines L3 to L8 is a contraction in the maximum norm with the factor at most c(1+2ε)c(1 + 2\varepsilon). So for c(1+2ε)<1c(1 + 2\varepsilon) < 1 the iterates converge to the unique fixed point from every start.

Proof. The map ϕ↦ϕ′\phi \mapsto \phi' is affine, and its linear part sends an error ee to the result e′e' of lines L4 to L8 with q=0q = 0 and Qi=Σs,iei/(4π)Q_i = \Sigma_{s,i}e_i/(4\pi). Let m=max⁡i∣Qi∣/Σt,i≤cmax⁡i∣ei∣/(4π)m = \max_i|Q_i|/\Sigma_{t,i} \le c\max_i|e_i|/(4\pi). Each track enters with 0, and by Lemma 1 each leaving value lies between the entering value and Q/ΣtQ/\Sigma_t; by induction along the track, ∣ψ∣≤m|\psi| \le m on every segment, and so ∣ψˉ∣≤m|\bar\psi| \le m as a mean of ψ\psi. By Lemma 3,

∣ei′∣≤∣Φi∣Ai+∣1−ai∣ 4πm≤(ai+∣1−ai∣)4πm,|e'_i| \le \frac{|\Phi_i|}{A_i} + |1 - a_i|\,4\pi m \le \left(a_i + |1 - a_i|\right)4\pi m,

since the weights in Φi/Ai\Phi_i/A_i sum to 4πai4\pi a_i. If ai≤1a_i \le 1 the factor is 1, and otherwise it is 2ai−1≤1+2ε2a_i - 1 \le 1 + 2\varepsilon. So max⁡i∣ei′∣≤c(1+2ε)max⁡i∣ei∣\max_i|e'_i| \le c(1 + 2\varepsilon)\max_i|e_i|. The Banach fixed-point theorem gives the rest. □\square

With a pure absorber (c=0c = 0) the second iteration repeats the first, so line L9 stops after 2 iterations, as the tests check. In the tests the track areas of single angles differ from the true areas by at most 0.40.4 percent, so ε≤0.004\varepsilon \le 0.004.

The long strip

Theorem 6 (the slab limit). Consider a purely absorbing slab 0≤x≤L0 \le x \le L, infinite in yy and zz, with a uniform source qq and vacuum faces. Its exact scalar flux is

ϕ(x)=q2Σt(2−E2(Σtx)−E2(Σt(L−x))),E2(a)=∫1∞e−att2 dt.\phi(x) = \frac{q}{2\Sigma_t}\left(2 - E_2(\Sigma_tx) - E_2(\Sigma_t(L - x))\right), \qquad E_2(a) = \int_1^\infty\frac{e^{-at}}{t^2}\,dt .

Proof. With Q=q/(4π)Q = q/(4\pi) and no scattering, the flux along a direction with the cosine μ\mu to the xx axis is the uncollided flux from the entering face: for μ>0\mu > 0, ψ=(Q/Σt)(1−e−Σtx/μ)\psi = (Q/\Sigma_t)(1 - e^{-\Sigma_tx/\mu}), and for μ<0\mu < 0 the same with L−xL - x and ∣μ∣|\mu|, by Lemma 1 along the straight path. Then ϕ=2π∫−11ψ dμ\phi = 2\pi\int_{-1}^1\psi\,d\mu, and ∫01e−a/μ dμ=E2(a)\int_0^1 e^{-a/\mu}\,d\mu = E_2(a) by the substitution t=1/μt = 1/\mu. □\square

The cell averages follow from ∫E2(Σtx) dx=−E3(Σtx)/Σt\int E_2(\Sigma_tx)\,dx = -E_3(\Sigma_tx)/\Sigma_t and E3(a)=(e−a−aE2(a))/2E_3(a) = (e^{-a} - aE_2(a))/2. For the rectangle of the tests, which is 20 mean free paths tall, every point of the middle row of cells is at least 8 mean free paths from the top and bottom faces, so the particles that these faces remove change the flux there by less than e−8q/Σt≈3.4×10−4e^{-8} q/\Sigma_t \approx 3.4 \times 10^{-4} (the uncollided flux along a path longer than 8 mean free paths). The remaining difference between MOC and Theorem 6 is the error of the angular quadrature and of the track spacing, which the page measures.

Complexity

In the real RAM model, line L6 does a constant number of operations, among them one exponential, for each segment, each polar angle and each sense, so one iteration costs O(TP)O(TP) for TT segments and PP polar angles, and II iterations cost O(ITP)O(ITP). Lines L4 and L8 cost O(R)O(R) per iteration, which is less. Line L1 costs O(T)O(T) on a grid, once. The memory is O(T)O(T) for the stored segments and O(R)O(R) for the fluxes, the sources and the tallies; the angular flux on a track is never stored.

The number of segments grows as the area over the spacing times the number of azimuthal angles, times the mean number of regions a unit length of track crosses. Halving the spacing or doubling nan_a doubles TT, as the table of the example shows. Codes replace the exponential of line L6 by a table or a rational approximation, since it dominates the cost of the segment.

Properties

  • Exact along each segment. For a flat source, line L6 has no truncation error. The errors come only from the flat source, the angular quadrature and the track spacing.
  • Conservative. Absorption plus leakage equals the source in every iteration, for any track layout (Theorem 4 of the proof).
  • Geometry free. The regions can have any shape. The tracks only need their intersections with the region boundaries, so the circles of fuel pins need no mesh.
  • Positive. With sources and inflows that are not negative, every ψ\psi is between its inflow and Q/ΣtQ/\Sigma_t, so no flux is ever negative, unlike diamond difference.
  • Iterative. It converges like source iteration, slowly when the scattering ratio is near 1 and the regions are optically thick.

Variants and improvements

  • Reflective and periodic boundaries. Lattice codes lay the tracks so that each track that leaves a face meets the start of another track at the same point, a cyclic layout. The leaving value then becomes the entering value of the next track, which replaces the zero of line L5 with the value of the last iteration.
  • Linear source. A source that is linear in each region, instead of flat, allows much larger regions for the same accuracy.
  • Acceleration. Coarse mesh finite difference (CMFD) and other low order diffusion corrections, related to diffusion synthetic acceleration, cut the number of iterations for optically thick problems with high scattering.
  • Polar quadratures. Codes use quadratures with few polar angles fitted to the integrals of the exponential, such as that of Tabuchi and Yamamoto, so that two or three polar angles are enough for lattice cells.
  • Three dimensions. Fully 3D MOC lays out tracks in 3D, at a much higher cost; 2D/1D methods couple a 2D MOC in each plane with a 1D solve in the axial direction.
  • Energy and eigenvalues. With the multigroup approximation the same sweep runs for each group, inside a power iteration for the k-eigenvalue problem.

When to use it

Use MOC for two-dimensional lattice and full core calculations where the geometry has curved boundaries and strong local changes, such as fuel pins, control rods and burnable absorbers, and where a mesh that fits the geometry would be hard to make. It suits problems with many regions and few angles per region. For simple rectangle geometries, a discrete ordinates sweep on a grid uses less memory. For optically thick, highly scattering problems, add an acceleration, as in plain source iteration.

Pitfalls

  • Too few azimuthal angles. The error falls slowly with nan_a, and streaming paths between regions, such as channels, can show ray effects. Check the result with a finer angular set.
  • Track spacing too wide (line L1). A region that only a few tracks cross gets a poor track area and a poor flux. The spacing must be small next to the smallest region.
  • Tracks on the grid lines. A track that runs along a region boundary has segments with an unclear region. Offset the tracks to the middle of each spacing interval, as the implementation does.
  • Exponent of the 3D path (line L6). The optical length is Σtℓ/sin⁡θ\Sigma_t\ell/\sin\theta, not Σtℓ\Sigma_t\ell. Forgetting the polar factor gives a 2D medium that is too thin.
  • Track area against true area (line L8). Dividing the tally by the track area instead of the true area breaks the exact balance of Theorem 4 of the proof. The tally form of line L8 with the true area keeps it.
  • Cancellation for small τ\tau. For very short segments, 1−e−τ1 - e^{-\tau} loses digits; use a series or the function expm1.

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.

method_of_characteristics_transport.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/method-of-characteristics-transport/. The authors are listed in prov/J4S5CW.jsonl.
"""The method of characteristics (MOC) for the one-speed transport equation in two dimensions.

The domain is the rectangle [0, width] x [0, height], infinite in z, cut into
nx by ny flat-source regions (cell k = ix + nx * iy). Each cell has
sigma_t > 0, sigma_s and an isotropic source q (particles per cm^3 per s).
The scalar flux is phi = integral of psi over the unit sphere, so the
emission density is Q = (sigma_s phi + q) / (4 pi). All faces are vacuum.

Directions: n_azim azimuthal angles alpha_a = pi (a + 1/2) / n_azim in
(0, pi), each track traced in both directions, times n_polar Gauss-Legendre
polar cosines in (0, 1), counted twice for the symmetry in z. The weights
of all directions sum to 4 pi.

Along a segment of in-plane length l in a cell, the 3D path length is
l / sin(theta) and the exact solution with a flat source is

    psi_out = psi_in exp(-tau) + (Q / sigma_t) (1 - exp(-tau)),  tau = sigma_t l / sin(theta).

The cell flux is phi = 4 pi Q / sigma_t + (sum over segments of w delta sin(theta) (psi_in - psi_out)) / (sigma_t A).
"""

import math


def segment(psi_in, q_over_sigma, tau):
    """Exact outgoing and segment-averaged angular flux for a flat source. Returns (psi_out, psi_avg)."""
    if tau < 1e-10:
        return psi_in - (psi_in - q_over_sigma) * tau, psi_in - (psi_in - q_over_sigma) * tau / 2.0
    decay = 1.0 - math.exp(-tau)
    out = psi_in - (psi_in - q_over_sigma) * decay
    return out, q_over_sigma + (psi_in - out) / tau


def lay_tracks(width, height, nx, ny, n_azim, spacing):
    """Cyclic-free track laydown for vacuum faces.

    Returns a list of tracks (a, delta, segments) where a is the azimuthal
    index, delta the actual track spacing for that angle, and segments a list
    of (cell, length) in the direction (cos alpha, sin alpha)."""
    hx, hy = width / nx, height / ny
    tracks = []
    for a in range(n_azim):
        alpha = math.pi * (a + 0.5) / n_azim
        ca, sa = math.cos(alpha), math.sin(alpha)
        proj = [-x * sa + y * ca for x in (0.0, width) for y in (0.0, height)]
        pmin, pmax = min(proj), max(proj)
        nt = max(1, math.ceil((pmax - pmin) / spacing))
        delta = (pmax - pmin) / nt
        for t in range(nt):
            p = pmin + (t + 0.5) * delta
            x0, y0 = -p * sa, p * ca
            lo, hi = (0.0 - y0) / sa, (height - y0) / sa
            if abs(ca) > 1e-15:
                s1, s2 = (0.0 - x0) / ca, (width - x0) / ca
                lo, hi = max(lo, min(s1, s2)), min(hi, max(s1, s2))
            if hi - lo <= 1e-14:
                continue
            cuts = [lo, hi]
            if abs(ca) > 1e-15:
                for i in range(1, nx):
                    s = (i * hx - x0) / ca
                    if lo < s < hi:
                        cuts.append(s)
            for j in range(1, ny):
                s = (j * hy - y0) / sa
                if lo < s < hi:
                    cuts.append(s)
            cuts.sort()
            segs = []
            for s0, s1 in zip(cuts, cuts[1:]):
                if s1 - s0 <= 1e-14:
                    continue
                sm = (s0 + s1) / 2.0
                ix = min(nx - 1, max(0, int((x0 + sm * ca) / hx)))
                iy = min(ny - 1, max(0, int((y0 + sm * sa) / hy)))
                segs.append((ix + nx * iy, s1 - s0))
            tracks.append((a, delta, segs))
    return tracks


def polar_quadrature(n_polar):
    """Gauss-Legendre cosines in (0, 1) and weights that sum to 2 (both hemispheres)."""
    mus, ws = [], []
    for i in range(n_polar):
        x = math.cos(math.pi * (i + 0.75) / (n_polar + 0.5))
        for _ in range(100):
            p0, p1 = 1.0, x
            for k in range(2, n_polar + 1):
                p0, p1 = p1, ((2 * k - 1) * x * p1 - (k - 1) * p0) / k
            dp = n_polar * (x * p1 - p0) / (x * x - 1.0)
            step = p1 / dp
            x -= step
            if abs(step) < 1e-16:
                break
        p0, p1 = 1.0, x
        for k in range(2, n_polar + 1):
            p0, p1 = p1, ((2 * k - 1) * x * p1 - (k - 1) * p0) / k
        dp = n_polar * (x * p1 - p0) / (x * x - 1.0)
        mus.append((x + 1.0) / 2.0)
        ws.append(2.0 / ((1.0 - x * x) * dp * dp))  # the weight on [-1, 1], twice the mapped weight on (0, 1)
    return mus, ws


def moc_solve(width, height, nx, ny, sigma_t, sigma_s, q, n_azim=8, n_polar=3, spacing=0.05,
              tol=1e-8, max_iter=1000, tracks=None):
    """Source iteration with MOC sweeps. Returns a dict with phi (per cell), leakage, iterations and tracks."""
    ncell = nx * ny
    area = (width / nx) * (height / ny)
    if tracks is None:
        tracks = lay_tracks(width, height, nx, ny, n_azim, spacing)  # @line L1
    mus, ws = polar_quadrature(n_polar)
    sines = [math.sqrt(1.0 - m * m) for m in mus]
    w_azim = math.pi / n_azim
    phi = [0.0] * ncell  # @line L2
    leak = 0.0
    it = 0
    for it in range(1, max_iter + 1):  # @line L3
        qs = [(sigma_s[k] * phi[k] + q[k]) / (4.0 * math.pi) / sigma_t[k] for k in range(ncell)]  # @line L4
        tally = [0.0] * ncell
        leak = 0.0
        for a, delta, segs in tracks:
            for sn, wp in zip(sines, ws):
                wgt = w_azim * wp * delta * sn
                for order in (segs, reversed(segs)):
                    psi = 0.0  # @line L5
                    for k, length in order:
                        dpsi = (psi - qs[k]) * (1.0 - math.exp(-sigma_t[k] * length / sn))  # @line L6
                        tally[k] += wgt * dpsi
                        psi -= dpsi
                    leak += wgt * psi  # @line L7
        new = [4.0 * math.pi * qs[k] + tally[k] / (sigma_t[k] * area) for k in range(ncell)]  # @line L8
        change = max(abs(a - b) for a, b in zip(new, phi))
        phi = new
        if change <= tol * max(abs(v) for v in phi):  # @line L9
            break
    return {"phi": phi, "leakage": leak, "iterations": it, "tracks": tracks}


def expint1(x):
    """E_1(x) for x > 0: series for x <= 1, continued fraction otherwise."""
    if x <= 1.0:
        term, k = 1.0, 1
        total = -0.5772156649015329 - math.log(x)
        while True:
            term *= -x / k
            add = -term / k
            total += add
            if abs(add) < 1e-17 * abs(total):
                break
            k += 1
        return total
    # Lentz continued fraction for E_1
    b = x + 1.0
    c = 1.0 / 1e-300
    d = 1.0 / b
    h = d
    for i in range(1, 300):
        an = -i * i
        b += 2.0
        d = 1.0 / (an * d + b)
        c = b + an / c
        de = c * d
        h *= de
        if abs(de - 1.0) < 1e-16:
            break
    return h * math.exp(-x)


def expint(n, x):
    """E_n(x) for n = 1, 2, 3 and x >= 0 by the recurrence E_(n+1)(x) = (exp(-x) - x E_n(x)) / n."""
    if x == 0.0:
        return math.inf if n == 1 else 1.0 / (n - 1)
    e = expint1(x)
    for k in range(1, n):
        e = (math.exp(-x) - x * e) / k
    return e


def slab_absorber_flux(sigma_t, q, length, a, b):
    """Average over [a, b] of the exact scalar flux (q / (2 sigma_t)) (2 - E2(sigma_t x) - E2(sigma_t (L - x)))
    of a purely absorbing slab with a uniform source and vacuum faces."""
    def int_e2(x0, x1):  # integral of E2(sigma_t x) dx over [x0, x1]
        return (expint(3, sigma_t * x0) - expint(3, sigma_t * x1)) / sigma_t
    total = 2.0 * (b - a) - int_e2(a, b) - int_e2(length - b, length - a)
    return q / (2.0 * sigma_t) * total / (b - a)
test_method_of_characteristics_transport.py 91 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/method-of-characteristics-transport/. The authors are listed in prov/J4S5CW.jsonl.
import math
import random
import unittest

from method_of_characteristics_transport import (expint, lay_tracks, moc_solve, polar_quadrature, segment,
                                                 slab_absorber_flux)


def strip_error(n_azim, n_polar, spacing):
    width, height, nx, ny = 2.0, 20.0, 10, 5
    n = nx * ny
    r = moc_solve(width, height, nx, ny, [1.0] * n, [0.0] * n, [1.0] * n, n_azim, n_polar, spacing, tol=1e-12)
    exact = [slab_absorber_flux(1.0, 1.0, width, i * width / nx, (i + 1) * width / nx) for i in range(nx)]
    return max(abs(r["phi"][i + 2 * nx] - exact[i]) for i in range(nx)), r["iterations"]


class TestPieces(unittest.TestCase):
    def test_segment_is_exact(self):
        for psi_in, qs, tau in ((0.0, 1.0, 1.25), (2.0, 0.5, 0.3), (1.0, 1.0, 7.0), (0.3, 0.0, 1e-12)):
            out, avg = segment(psi_in, qs, tau)
            self.assertAlmostEqual(out, qs + (psi_in - qs) * math.exp(-tau), places=12)
            k = 20000
            mean = sum(qs + (psi_in - qs) * math.exp(-tau * (i + 0.5) / k) for i in range(k)) / k
            self.assertAlmostEqual(avg, mean, places=8)
        out, avg = segment(0.0, 1.0, 1.25)
        self.assertAlmostEqual(out, 0.7134952, places=7)
        self.assertAlmostEqual(avg, 0.4292038, places=7)

    def test_exponential_integrals(self):
        self.assertAlmostEqual(expint(1, 1.0), 0.219383934395520, places=13)
        self.assertAlmostEqual(expint(2, 1.0), 0.148495506775922, places=13)
        self.assertAlmostEqual(expint(1, 0.1), 1.822923958419390, places=12)
        self.assertAlmostEqual(expint(3, 0.0), 0.5, places=15)

    def test_polar_weights(self):
        for n in (1, 2, 3, 5):
            mus, ws = polar_quadrature(n)
            self.assertAlmostEqual(sum(ws), 2.0, places=13)
            if n > 1:
                # exact for mu^2 on (0, 1), counted on both hemispheres
                self.assertAlmostEqual(sum(w * mu * mu for mu, w in zip(mus, ws)), 2.0 / 3.0, places=12)

    def test_tracks_cover_cells(self):
        tracks = lay_tracks(4.0, 4.0, 8, 8, 8, 0.05)
        for a in range(8):
            areas = [0.0] * 64
            for b, delta, segs in tracks:
                if b == a:
                    for k, length in segs:
                        areas[k] += delta * length
            self.assertLess(max(abs(x - 0.25) for x in areas) / 0.25, 5e-3)
            self.assertAlmostEqual(sum(areas), 16.0, delta=2e-3)


class TestSolve(unittest.TestCase):
    def test_tall_strip_matches_slab_formula(self):
        coarse, it = strip_error(8, 3, 0.05)
        self.assertEqual(it, 2)
        fine, _ = strip_error(32, 5, 0.02)
        self.assertLess(coarse, 1.5e-2)
        self.assertLess(fine, 2.5e-3)
        self.assertLess(fine, coarse / 4.0)

    def test_balance_heterogeneous(self):
        rng = random.Random(5)
        nx = ny = 8
        st = [rng.uniform(0.5, 3.0) for _ in range(nx * ny)]
        ss = [s * rng.uniform(0.0, 0.8) for s in st]
        q = [rng.uniform(0.0, 1.0) for _ in range(nx * ny)]
        r = moc_solve(4.0, 4.0, nx, ny, st, ss, q, 8, 3, 0.05, tol=1e-12)
        area = 0.25
        absorbed = sum((a - b) * f * area for a, b, f in zip(st, ss, r["phi"]))
        self.assertAlmostEqual(absorbed + r["leakage"], sum(v * area for v in q), delta=1e-9)
        self.assertTrue(all(v > 0.0 for v in r["phi"]))

    def test_symmetry(self):
        nx = ny = 8
        r = moc_solve(4.0, 4.0, nx, ny, [1.0] * 64, [0.7] * 64, [1.0] * 64, 8, 3, 0.05, tol=1e-12)
        p = r["phi"]
        for i in range(nx):
            for j in range(ny):
                self.assertAlmostEqual(p[i + nx * j], p[nx - 1 - i + nx * j], places=12)
                self.assertAlmostEqual(p[i + nx * j], p[i + nx * (ny - 1 - j)], places=12)
                self.assertAlmostEqual(p[i + nx * j], p[j + nx * i], places=12)
        self.assertGreater(p[3 + 8 * 3], p[0])


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

History

Askew (1972) described the solution of the transport equation along straight characteristic lines through regions of any shape with a flat source, for the complicated geometries of reactor lattices. The method was taken up by lattice codes in the following decades and became the standard for detailed two-dimensional lattice calculations, with polar quadratures fitted to the exponential, cyclic tracks for reflective boundaries and low order acceleration. Open source codes such as OpenMOC, described by Boyd and coauthors (2014), give the track laydown, the segment update and the source iteration in the form of this page.

References

  1. J. R. Askew, A characteristics formulation of the neutron transport equation in complicated geometries, report AEEW-M 1108, United Kingdom Atomic Energy Authority, Winfrith, 1972, the formulation of transport along straight characteristic lines through regions of any shape with a flat source
  2. William Boyd, Samuel Shaner, Lulu Li, Benoit Forget and Kord Smith, The OpenMOC method of characteristics neutral particle transport code, Annals of Nuclear Energy 68, 2014, 43-52, the description of the track laydown, the segment update with the exponential, the flat source region flux and the source iteration

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