Algorithmadvanced
Implicit Monte Carlo
Also called Fleck-Cummings method.
Solves thermal radiation transport coupled to a material energy equation by Monte Carlo, treating part of the absorption and reemission as effective scattering so large time steps stay stable.
- Time
- O(S N K) average
- Space
- O(N) extra
- Where
- K = the mean number of collisions per particle and step; N = the number of particles per time step; S = the number of time steps
- Model
- Real RAM
- Properties
- conservativerandomizednot exactiterativerandomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Joseph A. Fleck, Jr., J. D. Cummings, 1971
Implicit Monte Carlo (IMC) solves the equations of thermal radiation: the radiative transfer equation for the photon intensity, coupled to an energy equation for the material that absorbs and emits the photons. The coupling is stiff, because the emission grows like and the material can absorb and reemit energy many times in one time step. A Monte Carlo method that takes the emission from the temperature at the start of the step (explicit coupling) oscillates and can give negative temperatures for large steps. Fleck and Cummings linearized the emission in time, which gives a factor , the Fleck factor: in each step only the fraction of the absorptions is real, and the rest is replaced by effective scattering, absorption and immediate reemission in the same step. The particles are then followed as in analog Monte Carlo transport with a modified medium. The method is a semi-implicit time discretization in the spirit of the backward Euler method for a stiff problem, not an exact one. It is placed in particle transport, next to neutron Monte Carlo, because the transport part is the same random walk.
In plain words
Hot matter glows, and the light it gives off heats other matter, which glows in turn. Light moves very fast and the glow grows very quickly with temperature, so a simulation with long time steps can go wrong: cold matter takes in so much light in one step that it gets hotter than its source, and then it sends out too much in the next step.
Implicit Monte Carlo fixes this with a guess about the future. It estimates how much of the light that the matter takes in during the step will come out again before the step ends. That part is not stored as heat. Instead, the light simply bounces on, like a scattering. Only the rest heats the matter. The steps then stay calm, even when they are long.
The problem
In the grey case (one frequency group), the radiation intensity and the material temperature obey
where is the speed of light, the radiation constant, the absorption opacity in (which depends on ) and the heat capacity per unit volume. The radiation energy density is , and the equilibrium value is . Real problems add frequency dependence, physical scattering, material motion and boundaries. The model problem of this page is an infinite uniform zone, where space and direction drop out:
and is constant. Its solution tends to the equilibrium with , and the maximum principle holds: stays between the smallest and the largest of and the radiation temperature .
The algorithm
IMC-STEP(T, census, Δt) ▷ census: list of particle energies; data frozen at T- 1
β ← 4 a T³ / c_v, f ← 1 / (1 + β c σ Δt) ▷ the Fleck factor - 2
E_em ← f c σ a T⁴ Δt; emit particles with this total energy, birth times uniform in the step - 3
for each particle (w, t_left) of the census and of the emission do - 4
loop - 5
d ← -ln(ξ)/σ; if d ≥ c t_left then put w in the new census; break - 6
t_left ← t_left - d/c - 7
with probability f: E_abs ← E_abs + w; break ▷ real absorption - 8
otherwise effective scattering: a new isotropic direction, go on - 9
T ← T + (E_abs - E_em) / c_v ▷ material energy balance - 10
(one zone only) merge the census into equal-weight particles
Line L1 freezes the data at the start of the step. Line L2 emits the energy that the linearized material equation predicts. In a code with space, line L2 also samples the position and an isotropic direction, and line L5 compares the distance to collision with the distances to census and to the faces of the cell. Lines L7 and L8 split each collision into a real absorption with probability and an effective scattering with probability . Line L9 is exact energy bookkeeping: every unit of energy that left the material in line L2 and did not come back in line L7 is in the census or has left the system. Codes often replace line L7 with continuous absorption, a weight reduction along the path in the manner of implicit capture, which lowers the noise of the absorbed energy.
Where the Fleck factor comes from. Write for the equilibrium radiation energy density. The material equation gives with . A backward Euler step with frozen, , gives . Putting this into the emission term of the radiation equation gives
an emission , an absorption with opacity , and the remaining opacity as scattering. This is what lines L2, L7 and L8 implement.
Example
The Fleck factor by hand. With , and : , and . Half of the collisions in the step are real absorptions.
Explicit coupling against IMC. Start with and in the same units, so the equilibrium has , . Take . The table gives the expected temperature after each step (the mean of the Monte Carlo step, computed in closed form). The explicit method is the same algorithm with .
| step | explicit, | IMC |
|---|---|---|
| 1 | 0.0067 | 0.7881 |
| 2 | 0.9933 | 0.7236 |
| 3 | 0.0330 | 0.7246 |
| 4 | 0.9935 | 0.7245 |
| 5 | 0.0323 | 0.7245 |
The explicit method emits 5 units of energy in the first step from a material that holds 1, takes most of it back, and then swings between hot and cold. IMC goes to the equilibrium in two steps.
Accuracy in time. Start with and , so and the equilibrium is . With 2000 particles per step (random.Random(3)), against an accurate ODE solution:
| exact | IMC, | IMC, | |
|---|---|---|---|
| 1 | 0.6737 | 0.6698 | 0.7384 |
| 2 | 0.7561 | 0.7545 | 0.7574 |
| 4 | 0.7623 | 0.7675 | 0.7595 |
With the material heats too fast in the first step: the frozen data are a first-order approximation in time.
A violation of the maximum principle. With the same start and one step of : , , , and almost all radiation is absorbed. The expected temperature after the step is , and the run gives . The material is now hotter than the radiation that heated it, whose temperature was 1. The exact solution never exceeds 1. This is the effect that Larsen and Mercier analysed: the frozen at the cold start temperature greatly underestimates the emission during the step.
Correctness
Three claims are theorems. First, total energy is conserved exactly in every step: line L9 adds to the material the absorbed energy minus the emitted energy, and every particle energy is either absorbed, in the census or gone through a boundary. Second, the algorithm is an unbiased Monte Carlo solution of the time-discrete problem defined by the frozen Fleck factor: in one zone, the expected census energy after a step is , which the tests check. Third, the Fleck factor is the exact result of the backward Euler linearization above. The proofs are below.
What is not a theorem is the accuracy of the time-discrete problem. The linearization is first order in , and with large steps it can violate the maximum principle, as Larsen and Mercier proved and as the example shows. They also showed that the maximum principle holds when the time step is small enough. IMC is widely described as stable for large time steps; this is a property observed in practice and supported by analysis of the linearized problem, not a proof of unconditional stability for the nonlinear one.
Proof: Implicit Monte Carlo conserves energy and solves the time-discrete Fleck-Cummings problemfull
We assume exact arithmetic and exact independent uniform random numbers. We prove three things: the Fleck factor is the result of a backward Euler linearization, one step conserves energy exactly, and in one zone the expected census energy is the solution of the time-discrete equation. The accuracy of the time discretization is not a theorem of this page; Larsen and Mercier (1987), cited on the page, prove a maximum principle for small time steps and show that it can fail for large ones.
Lemma 1 (the Fleck factor). Let and , frozen at the start of the step. The backward Euler step of the linearized material equation gives with .
Proof. The material equation is . By the chain rule , which is with frozen at . The backward Euler step gives . Divide by and use .
Putting in place of in the emission term of the radiation equation gives . The second term equals the part of the absorption , so the two cancel as a scattering with opacity , and what remains is the emission and the absorption with opacity . The time-discrete problem of IMC is the transport problem over the step with these frozen coefficients.
Lemma 2 (each collision). At a collision, line L7 absorbs the particle with probability , and line L8 keeps it with probability . So the distance to the next real absorption, measured along the path, is exponential with rate , and the particle moves at speed between collisions.
Proof. Collisions happen at the rate along the path by line L5. Thinning a Poisson process of rate by independent coin flips with probability gives a Poisson process of rate . In one zone the direction plays no role.
Theorem 1 (energy conservation). Let be the material energy, the energy in the census and the energy that left through boundaries. After a step, equals its value before the step.
Proof. Every particle of the old census and of the emission ends the step in exactly one of three ways: absorbed in line L7, put in the new census in line L5, or (in a code with space) gone through a boundary. Line L8 does not change the weight. So the energy of the old census plus equals plus the new census energy plus the energy that left. Line L9 changes by . Adding the two equalities gives the claim. Line L10 replaces the census by particles with the same total weight.
Theorem 2 (the expected step in one zone). In an infinite uniform zone, with old census energy and emission at uniform birth times, the expected new census energy is
which is the exact solution at time of , . The expected new temperature follows from Theorem 1: in expectation.
Proof. By Lemma 2 a particle with time left in the step survives to census with probability , because it travels the distance . The old census particles have , which gives the first term. An emitted particle born at time , uniform in , has , also uniform. So the expected surviving emitted energy is
By linearity of expectation, the expected census energy is the sum. The ODE solution is checked by substitution.
Consequences. The radiation part of the step is solved exactly in expectation, and the only errors are the statistical noise and the frozen coefficients , and , which make the method first order in . For a large step, tends to , so the expected census energy tends to , a bounded combination, instead of the explicit emission , which grows without bound. This is why the explicit step with oscillates in the example and the IMC step does not. When is small (a cold material), is tiny and almost all of is absorbed, so the material can end hotter than the radiation: the maximum principle fails, as Larsen and Mercier showed.
Complexity
Each step costs for particles with collisions each in the step, plus for emission and census. In an optically thick zone with a large step, is small and is large, so a particle has about effective scatterings before it is absorbed or reaches census: grows like , which is the main cost of IMC in thick, hot regions. Remedies are random walk acceleration, which replaces many small scatterings by a jump from the diffusion solution, and hybrid methods that use diffusion in thick cells. The space is for the census.
Properties
- Conservative. The total energy of radiation and matter is conserved to rounding in each step.
- Stable in practice. The step can be much longer than the explicit limit of about , with no oscillation in the usual problems.
- Not monotone. The maximum principle can fail for large steps.
- First order in time. The frozen data and the linearization give an error of order .
- Monte Carlo noise. The temperature carries noise from the absorbed energy, and the noise feeds back into the next step through , and the emission.
Variants and improvements
- The time-centring parameter. Fleck and Cummings allow a parameter in in the linearization, with ; is the common choice.
- Frequency dependence. With multigroup or continuous frequency, the emission spectrum is the Planck function, and effective scattering changes the frequency as well as the direction.
- Random walk and diffusion acceleration. Replace many effective scatterings in a thick cell by one step of the diffusion solution, as in the diffusion approximation, or use implicit Monte Carlo diffusion in thick regions.
- Implicit Monte Carlo with better time discretization. Iterating the step with updated , or using a different linearization, reduces the violations of the maximum principle at extra cost.
- Symbolic IMC and other implicit methods. Other schemes, such as the symbolic implicit Monte Carlo of Brooks, treat the emission implicitly in a different way, with different trade-offs.
When to use it
Use IMC for time-dependent thermal radiation problems in which transport effects matter: inertial confinement fusion, astrophysics, high energy density experiments, radiation through optically thin and thick regions together. Where the medium is optically thick everywhere, a diffusion solver is much cheaper. Choose the time step with the maximum principle in mind: a step that the explicit limit forbids is fine, but a step over which the temperature changes by a large factor is not.
Pitfalls
- Overheating with large steps. A cold material next to a hot radiation field can end the step hotter than the field. Limit the relative change of per step.
- Noise in cold regions. With few particles in a cell, the absorbed energy is noisy, and the temperature can fluctuate strongly; continuous absorption lowers this noise.
- Teleportation error. In a code with space, emitting particles uniformly in a cell with a steep temperature gradient moves energy too far, and gives wrong wave speeds in thick media. Sample the emission position from a reconstructed profile.
- The census count. The number of census particles grows from step to step. Population control (combining in a cell, or Russian roulette) must conserve energy.
- Merging in space. Merging census particles of different positions or directions changes the solution. The merge of line L10 is valid only in one zone with no space or direction.
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/implicit-monte-carlo/. The authors are listed in prov/CX3297.jsonl.
"""Implicit Monte Carlo (Fleck and Cummings) for grey radiation in one zone.
The zone is infinite and uniform, so space and direction drop out. The
radiation energy density E_r and the material temperature T obey
dE_r/dt = c sigma (a T^4 - E_r),
c_v dT/dt = c sigma (E_r - a T^4),
and E_r + c_v T is constant. One IMC step of size dt freezes the
temperature-dependent data at the start of the step and uses the Fleck
factor
beta = 4 a T^3 / c_v, f = 1 / (1 + beta c sigma dt).
During the step the material emits f c sigma a T^4 per unit time. A
radiation particle collides at rate c sigma; at a collision it is
absorbed with probability f, and with probability 1 - f it goes on as if
scattered ("effective scattering"). Particles that reach the end of the
step go to census. The material energy changes by the absorbed energy
minus the emitted energy, so the total energy is conserved exactly.
Since this zone has no space or direction, the census can be merged into
equal-weight particles without loss; a code with space cannot do that.
"""
import math
def uniform_open(rng) -> float:
return 1.0 - rng.random()
def imc_step(temp, census, dt, n_emit, rng, a=1.0, c=1.0, sigma=1.0, cv=1.0, n_census=None):
"""One IMC step. census is a list of particle energies.
Returns (new temperature, new census list, info dict).
"""
beta = 4.0 * a * temp ** 3 / cv # @line L1
f = 1.0 / (1.0 + beta * c * sigma * dt)
e_emit = f * c * sigma * a * temp ** 4 * dt # @line L2
particles = [(w, dt) for w in census]
if n_emit > 0 and e_emit > 0.0:
w = e_emit / n_emit
particles += [(w, dt * (1.0 - rng.random())) for _ in range(n_emit)] # time left after birth
e_abs = 0.0
out = []
for w, t_left in particles: # @line L3
while True: # @line L4
d_coll = -math.log(uniform_open(rng)) / sigma
if d_coll >= c * t_left: # @line L5
out.append(w)
break
t_left -= d_coll / c # @line L6
if rng.random() < f: # @line L7
e_abs += w
break
continue # @line L8 (effective scattering: the particle goes on)
new_temp = temp + (e_abs - e_emit) / cv # @line L9
if n_census is not None and len(out) > n_census: # @line L10
total = sum(out)
out = [total / n_census] * n_census
info = {"f": f, "emitted": e_emit, "absorbed": e_abs, "launched_w2": sum(w * w for w, _ in particles)}
return new_temp, out, info
def expected_census(e_r, temp, dt, a=1.0, c=1.0, sigma=1.0, cv=1.0):
"""Exact mean radiation energy after one IMC step (the step's own linear model)."""
beta = 4.0 * a * temp ** 3 / cv
f = 1.0 / (1.0 + beta * c * sigma * dt)
x = f * c * sigma * dt
return e_r * math.exp(-x) + a * temp ** 4 * (1.0 - math.exp(-x))
def equilibrium_temperature(total, a=1.0, cv=1.0):
"""Solve a T^4 + c_v T = total by bisection."""
lo, hi = 0.0, max(total / cv, (total / a) ** 0.25)
for _ in range(200):
mid = 0.5 * (lo + hi)
if a * mid ** 4 + cv * mid < total:
lo = mid
else:
hi = mid
return 0.5 * (lo + hi)
test_implicit_monte_carlo.py 57 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/implicit-monte-carlo/. The authors are listed in prov/CX3297.jsonl.
import math
import random
import pytest
from implicit_monte_carlo import equilibrium_temperature, expected_census, imc_step
def test_fleck_factor_by_hand():
# T = 1, a = c = sigma = c_v = 1, dt = 0.25: beta = 4, f = 1 / (1 + 1) = 0.5.
_, _, info = imc_step(1.0, [], 0.25, 10, random.Random(0))
assert info["f"] == pytest.approx(0.5)
assert info["emitted"] == pytest.approx(0.5 * 0.25)
def test_energy_is_conserved_exactly():
rng = random.Random(1)
temp, census = 0.1, [1.0 / 500] * 500
total = temp + sum(census)
for _ in range(20):
temp, census, _ = imc_step(temp, census, 0.3, 500, rng, n_census=500)
assert temp + sum(census) == pytest.approx(total, rel=1e-12)
@pytest.mark.parametrize("temp,e_r,dt", [(0.1, 1.0, 0.5), (0.8, 0.2, 0.2), (1.0, 1.0, 2.0)])
def test_one_step_mean(temp, e_r, dt):
n = 6000
census = [e_r / n] * n
_, out, info = imc_step(temp, census, dt, n, random.Random(2))
exact = expected_census(e_r, temp, dt)
# Each particle reaches census or not, so the variance is at most sum(w^2) / 4.
bound = 4.0 * math.sqrt(info["launched_w2"] / 4.0)
assert abs(sum(out) - exact) < bound
def test_relaxes_to_equilibrium():
rng = random.Random(3)
temp, census = 0.1, [1.0 / 400] * 400
t_eq = equilibrium_temperature(1.0 + 0.1)
assert t_eq + t_eq ** 4 == pytest.approx(1.1)
for _ in range(60):
temp, census, _ = imc_step(temp, census, 0.2, 400, rng, n_census=400)
assert temp == pytest.approx(t_eq, abs=0.03)
assert sum(census) == pytest.approx(t_eq ** 4, abs=0.03)
def test_large_step_overshoots():
# With dt = 100 the frozen Fleck factor lets the cold material absorb almost all
# the radiation in one step: T jumps above the radiation temperature 1.
temp, census = 0.1, [1.0 / 2000] * 2000
expected_t = 0.1 + 1.0 - expected_census(1.0, 0.1, 100.0)
new_t, _, _ = imc_step(temp, census, 100.0, 2000, random.Random(4))
assert expected_t > 1.09
assert new_t == pytest.approx(expected_t, abs=0.01)
assert new_t > 1.0
History
Joseph Fleck and J. D. Cummings at the Lawrence Radiation Laboratory published the method in 1971, with frequency dependence and the effective scattering interpretation. It became the standard Monte Carlo method for thermal radiation in the codes of the US national laboratories. Larsen and Mercier analysed it in 1987 and proved that it satisfies a maximum principle for small enough time steps and can violate it for large ones. Wollaber's 2016 review describes four decades of analysis and variants, including acceleration methods for thick media and corrections for the teleportation error.
References
- J. A. Fleck, Jr. and J. D. Cummings, An implicit Monte Carlo scheme for calculating time and frequency dependent nonlinear radiation transport, Journal of Computational Physics 8(3), 1971, 313-342, the time discretization of the coupled equations, the Fleck factor and effective scattering
- Edward W. Larsen and Bertrand Mercier, Analysis of a Monte Carlo method for nonlinear radiative transfer, Journal of Computational Physics 71(1), 1987, 50-64, the maximum principle, which holds for small time steps and can fail for large ones
- Allan B. Wollaber, Four decades of implicit Monte Carlo, Journal of Computational and Theoretical Transport 45(1-2), 2016, 1-70, a review of the method, its derivation, its accuracy and its variants
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 CX3297 Edit this page History Report an error Markdown