#| echo: false
#| output: asis
using RayTraceHeatTransfer # needed here for its version number
println("*Rendered with RayTraceHeatTransfer.jl v", pkgversion(RayTraceHeatTransfer), " and Julia ", VERSION, ".*")
Rendered with RayTraceHeatTransfer.jl v0.27.0 and Julia 1.13.4.
Warning
This example traces a billion rays through a million cells. It took about two minutes on the machine listed at the end of the example, and needs a lot of memory.
The last example is a reward for reading this far. It is the diffusion benchmark of the GERT formulation paper [Bielefeld (2026)], taken to a million elements: a 1000 m × 1 m rectangle with κ = 100 m⁻¹, a hot wall along one long side and cold walls elsewhere. The long walls are 1 m apart, so across the gap the optical thickness is τ_L = 100, and far from the short ends the medium behaves as an infinite slab. The mesh has 1001 × 1001 cells, which makes 1,006,005 elements, so the exchange factor matrix has 10¹² entries. At this optical thickness a ray is absorbed close to where it starts, so the matrix is sparse and fits in memory. Deep inside an optically thick medium the diffusion approximation is accurate, which gives an analytical reference for the centreline.
Step 1: The mesh
In [2]:
usingRayTraceHeatTransfer, GeometryBasics, StaticArraysNlarge =1001# cells in each directionvertices =SVector(Point2(0.0, 0.0), Point2(1000.0, 0.0), Point2(1000.0, 1.0), Point2(0.0, 1.0)) # 1000 m long, 1 m between the long wallsface =PolyVolume2D{Float64}(vertices, SVector(true, true, true, true), 1, 100.0, 0.0) # κ = 100 m⁻¹, no scatteringface.T_in_w = [1000.0, 0.0, 0.0, 0.0] # hot bottom wall, three cold wallsface.epsilon = [1.0, 1.0, 1.0, 1.0] # black wallsface.T_in_g =-1.0# gas temperature unknownface.q_in_g =0.0# radiative equilibrium: no heat source in the gast_build =@elapsed big =RayTracingDomain2D([face], [(Nlarge, Nlarge)]; verbose =false) # 1001 × 1001 cells
8.2629755
Step 2: A billion rays, then smoothing
The counting tracer :exchange is used here: pseudorandom sampling leaves the most noise, so it shows the effect of smoothing most clearly.
In [3]:
sampler =:random # pseudorandom; :sobol is the defaultemitters =length(big.surface_mapping) +length(big.volume_mapping) # 4 × 1001 wall elements and 1001² cellsrays = emitters *2^10# 2¹⁰ rays per emitter, about 10⁹ in totalt_trace =@elapsedbig(rays; method =:exchange, sampler = sampler, verbose =false) # the exchange factorst_smooth =@elapsed stats =smooth!(big; verbose =false) # reciprocity and conservationstats # which smoother ran, and how many iterations
Step 3: Solving with the raw and the smoothed factors
The raw factors are solved only to have something to compare with. Each solve overwrites the previous solution, so the centreline is extracted after each.
In [4]:
# Centreline source function S = (T/T_hot)⁴ of a solved mesh, from the hot wall upwardsfunctioncentreline_S(m, N) T =reshape([cell.T_g for cell in m.fine_mesh[1]], N, N) # temperatures as T[column, row], rows from the hot wallreturn (T[div(N +1, 2), :] ./1000.0) .^4# the middle column; T_hot = 1000 Kendt_solve_raw =@elapsedsolveEquilibrium!(big, big.F_raw; verbose =false) # the raw factors, for comparison onlyS_raw =centreline_S(big, Nlarge) # their centrelinet_solve =@elapsedsolveEquilibrium!(big, big.F_smooth; verbose =false) # the smoothed factorsS_smooth =centreline_S(big, Nlarge); # their centreline
Step 4: The diffusion reference
Between two parallel walls, the diffusion approximation gives an emissive power that falls linearly across the medium, with a jump at each wall [Howell et al. (2021)]. Because the profile is linear, its average over a cell equals its value at the cell centre, so it compares directly with the solution. The smoother is given only reciprocity and energy conservation; it knows nothing of the diffusion solution.
In [5]:
# Emissive power in the diffusion approximation between two parallel grey walls:# z is the distance from wall 1, β the extinction coefficient, D the distance between the wallsfunctiondiffusion_emissive_power(z, β, D, ε_w1, ε_w2, E_bw1, E_bw2) q_z = (E_bw1 - E_bw2) / (3β * D /4+1/ ε_w1 +1/ ε_w2 -1) # net radiative flux between the walls E_b1 = E_bw1 + q_z * (1/2-1/ ε_w1) # emissive power just inside wall 1return E_b1 - (3β * z /4) * q_z # falling linearly across the mediumendσ_SB =5.670374419e-8# Stefan–Boltzmann constant, W m⁻² K⁻⁴E_hot = σ_SB *1000.0^4# emissive power of the hot wallz = ((1:Nlarge) .-0.5) ./ Nlarge # cell centres: distance from the hot wall, mS_ref =diffusion_emissive_power.(z, 100.0, 1.0, 1.0, 1.0, E_hot, 0.0) ./ E_hot # the reference, as Srms_raw =sqrt(sum(abs2, S_raw .- S_ref) / Nlarge) # rms deviation, raw factorsrms_smooth =sqrt(sum(abs2, S_smooth .- S_ref) / Nlarge) # rms deviation, smoothed factorsprintln("rms deviation from diffusion: raw = ", round(rms_raw; sigdigits =3),", smoothed = ", round(rms_smooth; sigdigits =3),", reduction = ", round(100* (1- rms_smooth / rms_raw); digits =1), " %")println("time: build ", round(t_build; digits =1), " s, trace ", round(t_trace; digits =1)," s, smooth ", round(t_smooth; digits =1), " s, solve ", round(t_solve; digits =1)," s (raw solve ", round(t_solve_raw; digits =1), " s), on ", Threads.nthreads(), " threads")
rms deviation from diffusion: raw = 0.0314, smoothed = 0.000749, reduction = 97.6 %
time: build 8.3 s, trace 62.4 s, smooth 12.4 s, solve 29.8 s (raw solve 32.9 s), on 28 threads
In [6]:
usingPlotsp = Plots.scatter(z, S_raw; markersize =5.0, markerstrokewidth =0.5, # 1001 points merge into a band color =:dodgerblue, label ="Raw factors", dpi =400)Plots.scatter!(p, z, S_smooth; markersize =5.0, markerstrokewidth =0.25, color =:darkorange, label ="Smoothed factors")Plots.plot!(p, z, S_ref; color =:black, linewidth =2.5, label ="Diffusion approximation")Plots.plot!(p; xlabel ="Optical depth τ/τ_L", ylabel ="Source function S = (T/T_hot)⁴", title ="Centreline, 1001 × 1001 cells, τ_L = 100", legend =:topright, size = (700, 480))display("image/png", p) # hand the figure over as a PNG image, which a captioned and embedded figure needs
Figure 1: A million elements: the centreline of a 1000 m × 1 m domain with extinction coefficient 100 m⁻¹, meshed into 1001 × 1001 cells and traced with a billion rays on a desktop PC. Raw Monte Carlo exchange factors (blue) scatter around the diffusion approximation (black); smoothed factors (orange) fall onto it.
With about a thousand rays per element, the raw factors leave the centreline scattered around the diffusion line. Smoothing brings it onto the line across the whole gap, and the printed reduction shows how much of the deviation is removed by enforcing nothing but reciprocity and energy conservation. The default smoother, :ml, keeps the traced zero pattern, so the matrix stays sparse; Dykstra’s projection (:dykstra) works on dense arrays and would need all 10¹² entries.
The printed timings were measured on an Intel Core i7-14700KF (20 cores, 28 threads) with 64 GB of RAM, running Windows 11 and Julia 1.13 on 28 threads.
Bielefeld, Nikolaj Maack. 2026. Non-Negativity, Non-Singularity and Energy Conservation of the Zonal Method with Non-Reciprocal Exchange Factors. https://doi.org/10.48550/arXiv.2512.22157.
Howell, John R., M. Pinar Mengüç, Kyle J. Daun, and Robert Siegel. 2021. Thermal Radiation Heat Transfer. 7th ed. CRC Press. https://doi.org/10.1201/9780429327308.