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
- Model
- Real RAM
- Properties
- deterministicnot exactiterativenot randomized
- Evidence
- Proof sketchCode in 1 languages
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 , infinite in , cut into regions of the area with the total cross section , the scattering cross section and the isotropic source , all in units of and particles per per second. The faces are vacuum. The unknown is the scalar flux over the unit sphere, and the emission per steradian is . The one-speed equation is
A direction has an azimuthal angle in the plane and a polar angle to the axis. The implementation takes azimuthal angles in , each track walked in both senses, with the weight , and Gauss polar cosines in with weights that sum to 2, so the weights of all directions sum to . For each angle the tracks are straight lines at the spacing , and each track is cut into segments , one for each region that it crosses, with the in-plane length . The goal is the region fluxes of the flat source MOC equations.
The algorithm
MOC(regions, Σt, Σs, q, n_a, n_p, spacing, tol)- 1
for each angle α: lay tracks at the spacing δ_α and cut each into segments (i, ℓ) - 2
φ_i ← 0 for every region i - 3
repeat - 4
for each region i: Q_i/Σt_i ← (Σs_i φ_i + q_i) / (4π Σt_i); tally_i ← 0; leak ← 0 - 5
for each track, each polar angle p and each of the two senses: ψ ← 0 (vacuum inflow) - 6
for each segment (i, ℓ) in the order of flight: Δψ ← (ψ - Q_i/Σt_i)(1 - exp(-Σt_i ℓ / sin θ_p)); tally_i ← tally_i + w Δψ; ψ ← ψ - Δψ - 7
leak ← leak + w ψ - 8
φ_i ← 4π Q_i/Σt_i + tally_i / (Σt_i A_i) for every region i - 9
until the largest change of φ is at most tol times the largest φ
The weight of a track in line L6 is . 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 of the 3D path, the leaving value is , and . 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 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 , and . Line L6 gives , so , and the mean over the segment is .
A tall strip against the exact slab flux. A pure absorber with and fills , , cut into by regions. In the middle row the strip acts as a slab of 2 mean free paths, whose exact flux is with the exponential integral (Theorem 6 of the proof). The top and bottom faces change this by less than . The exact averages of the five left cells of the middle row (the right five are the mirror image) are , , , and . With no scattering, the second iteration already stops. The largest error of the middle row is:
| spacing (cm) | largest error | segments | ||
|---|---|---|---|---|
| 4 | 2 | 0.1 | 5520 | |
| 8 | 3 | 0.05 | 21556 | |
| 16 | 3 | 0.05 | 42904 | |
| 16 | 5 | 0.02 | 107168 | |
| 32 | 5 | 0.02 | 214148 |
At the five values are , , , and . 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 cm square with regions, the track area of a region for one angle differs from its true area by at most of the area with and the spacing 0.05, and by at most with and the spacing 0.1. The total track area, averaged over the angles, is and against the true . 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 , and , the iteration stops after 40 iterations, and absorption plus leakage equals the total source to of the source. The flux is symmetric under the mirror in to . For a uniform medium with the scattering ratio , 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 regions, and the tolerance , the number of iterations is 19 for , 66 for and 125 for . The growth is that of source iteration; leakage from the 8 mean free path square keeps the count at 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 , where 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 , the flux in the middle tends to the exact slab flux with (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 has the area , and , and all faces are vacuum. A direction is a track direction with the azimuthal weight and a polar cosine with the weight , where the sum to 2 and . The weights of all directions sum to . A track of the angle carries the spacing , and it is cut into segments, one for each cell that it crosses, of the in-plane lengths .
One segment
Lemma 1 (the segment solve is exact). Let a segment of in-plane length lie in cell , with the emission density per steradian. Along the direction with the polar angle , the transport equation is in the in-plane distance . Its solution from the entering value is
so line L6 gives the exact leaving value , and the mean of over the segment is with .
Proof. A 3D path that makes the angle with the axis covers the in-plane distance over the path length , so the streaming term is . The formula solves this linear equation with the initial value . Integrating it over gives , and .
In line L6, is , and is . Since , lies between and .
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 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.
The cell flux and the balance
Let be the sum over the directions and the segments in cell of , which is the quadrature for : the tracks of each direction sample the cell with the spacing , and each segment contributes the area . Let be the ratio of the track area of cell to its true area, averaged over the directions.
Lemma 3 (line L8). Line L8 is
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 , .
Proof. The tally of line L6 adds for each segment. By Lemma 1, . So the tally of cell is , and line L8 gives .
Theorem 4 (balance in every iteration). Let be the old iterate, , and the new iterate with the leakage of line L7. Then
At convergence () this is the exact balance , for any track spacing and any quadrature.
Proof. By line L8, is the tally of cell . The sum of the tallies over all cells is the sum over all tracks and directions of times the sum of 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 times the leaving value into , so the sum of the tallies is . Finally .
The weight of a leaving track is the quadrature of the outgoing current over the face: a track bundle of the width crosses a face of the length , where is the angle between the track and the normal, and .
Convergence of the source iteration
Theorem 5 (contraction). Let . Then the iteration of lines L3 to L8 is a contraction in the maximum norm with the factor at most . So for the iterates converge to the unique fixed point from every start.
Proof. The map is affine, and its linear part sends an error to the result of lines L4 to L8 with and . Let . Each track enters with 0, and by Lemma 1 each leaving value lies between the entering value and ; by induction along the track, on every segment, and so as a mean of . By Lemma 3,
since the weights in sum to . If the factor is 1, and otherwise it is . So . The Banach fixed-point theorem gives the rest.
With a pure absorber () 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 percent, so .
The long strip
Theorem 6 (the slab limit). Consider a purely absorbing slab , infinite in and , with a uniform source and vacuum faces. Its exact scalar flux is
Proof. With and no scattering, the flux along a direction with the cosine to the axis is the uncollided flux from the entering face: for , , and for the same with and , by Lemma 1 along the straight path. Then , and by the substitution .
The cell averages follow from and . 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 (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 for segments and polar angles, and iterations cost . Lines L4 and L8 cost per iteration, which is less. Line L1 costs on a grid, once. The memory is for the stored segments and 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 doubles , 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 is between its inflow and , 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 , 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 , not . 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 . For very short segments, 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.
# 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
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag J4S5CW Edit this page History Report an error Markdown