---
title: "Example 6 — Five-Pointed Star with a Volumetric Heat Source"
---
```{julia}
#| echo: false
#| output: asis
using RayTraceHeatTransfer # needed here for its version number
println("*Rendered with RayTraceHeatTransfer.jl v", pkgversion(RayTraceHeatTransfer), " and Julia ", VERSION, ".*")
```
Domains in RayTraceHeatTransfer.jl are assembled from triangles and quadrilaterals, and because the elements are ordinary Julia objects, a geometry can be generated by a loop instead of being drawn by hand. This example builds a five-pointed star from 10 triangles. Five triangles meet at the centre and form an inner pentagon; all of their edges are open (transparent to radiation). Each of the five arms is one more triangle: its base joins the pentagon and is open, and its two outer edges are black walls held at 0 K. The star has tip radius R = 1 m and pentagon radius r = 0.3 m, which gives thinner arms than a regular star.
The medium absorbs and emits but does not scatter (κ = 1 m⁻¹). Instead of being heated by a wall, it carries a uniform volumetric heat source of 10 kW in total, much like the heat released in a combustion chamber. In steady state all of that power must leave through the cold walls as radiation, and the gas temperature settles where its emission balances the source.
## Step 1: Build the star from triangles
```{julia}
using RayTraceHeatTransfer # the GERT solver
using GeometryBasics, StaticArrays # points and fixed-size vectors for the geometry
R = 1.0 # radius of the star tips [m]
r = 0.3 # radius of the inner pentagon's corners [m]
kappa = 1.0 # absorption coefficient [m⁻¹]
source_total = 10000.0 # total volumetric heat source over the whole star [W]
Ndiv = 11 # subdivisions of every triangle
tip(k) = Point2(R * cosd(90 + 72k), R * sind(90 + 72k)) # tip of arm k, the first pointing straight up
inner(k) = Point2(r * cosd(126 + 72k), r * sind(126 + 72k)) # pentagon corner between arm k and arm k + 1
centre = Point2(0.0, 0.0) # centre of the star
faces = PolyVolume2D{Float64}[] # the 10 coarse triangles
for k in 0:4 # one centre triangle and one arm per corner of the pentagon
# Centre triangle: centre → corner k−1 → corner k, counter-clockwise; every edge is open
centre_tri = PolyVolume2D{Float64}(SVector(centre, inner(k - 1), inner(k)),
SVector(false, false, false), 1, kappa, 0.0)
centre_tri.T_in_w = [0.0, 0.0, 0.0] # no walls, so no wall temperatures are used
centre_tri.epsilon = [1.0, 1.0, 1.0] # no walls, so no emissivities are used
centre_tri.T_in_g = -1.0 # gas temperature unknown; its heat source is set below
push!(faces, centre_tri) # add it to the domain
# Arm triangle: corner k−1 → tip k → corner k, counter-clockwise; the two outer edges are walls, the base is open
arm_tri = PolyVolume2D{Float64}(SVector(inner(k - 1), tip(k), inner(k)),
SVector(true, true, false), 1, kappa, 0.0)
arm_tri.T_in_w = [0.0, 0.0, 0.0] # outer walls at 0 K (the base entry is unused)
arm_tri.epsilon = [1.0, 1.0, 1.0] # black outer walls
arm_tri.T_in_g = -1.0 # gas temperature unknown; its heat source is set below
push!(faces, arm_tri) # add it to the domain
end
area_total = sum(face.volume for face in faces) # total area of the star (the "volume" of a 2D element) [m²]
q_density = source_total / area_total # uniform heat source density [W/m²]
for face in faces # every triangle gets the same source density ...
face.q_in_g = q_density * face.volume # ... so its heat source is proportional to its area [W]
end
mesh = RayTracingDomain2D(faces, fill((Ndiv, Ndiv), length(faces)); verbose = false) # every triangle subdivided 11 × 11
println("star area: ", round(area_total; digits = 4), " m², heat source density: ", round(q_density; digits = 1), " W/m²")
```
The faces are pushed in pairs, so the centre triangles are faces 1, 3, 5, 7 and 9 and the arms are faces 2, 4, 6, 8 and 10. Each triangle's heat source is set on the coarse face, and the mesh hands it down to the fine cells in proportion to their areas, so the source density stays uniform after subdivision.
## Step 2: Ray trace, smooth and solve
```{julia}
mesh(10^8; method = :exchange, verbose = false) # exchange factors by ray tracing (Sobol sampler)
smooth!(mesh; verbose = false) # enforce energy conservation and reciprocity
solveEquilibrium!(mesh, mesh.F_smooth; verbose = false) # solve the GERT system
```
## Step 3: Visualise
```{julia}
using Plots
p = plotField(mesh; field = :T) # gas temperature in every cell
Plots.plot!(p; xlabel = "x / m", ylabel = "y / m", # axis labels
title = "Temperature / K", # the field shown by the colour bar
aspect_ratio = :equal) # keep the star's shape
```
## Step 4: Check the energy balance and the symmetry
Two checks need no reference solution. The first is the energy balance: the walls are at 0 K and emit nothing, so all 10 kW of the heat source must be removed by the walls. For a wall of known temperature the solver stores the net source `q_w` (emitted minus absorbed power), so the wall sources must sum to −10 kW.
```{julia}
q_gas = sum(cell.q_g for fine in mesh.fine_mesh for cell in fine) # heat released in the gas [W]
q_wall = sum(cell.q_w[i] for fine in mesh.fine_mesh for cell in fine
for i in eachindex(cell.solidWalls) if cell.solidWalls[i]) # net source of every wall element [W]
println("heat released in the gas : ", round(q_gas; digits = 3), " W")
println("heat removed by the walls: ", round(-q_wall; digits = 3), " W")
println("relative imbalance : ", abs(q_gas + q_wall) / q_gas)
```
The second check is the symmetry. Every arm is the same triangle rotated by 72°, with its corners listed in the same order, so the mesher subdivides every arm in the same way and numbers its cells in the same order: cell i of one arm corresponds to cell i of every other arm. The same holds for the centre triangles. Any difference in temperature between corresponding cells is sampling noise in the exchange factors.
```{julia}
# Largest temperature difference between corresponding cells of five rotated copies of a triangle
function symmetry_spread(copies)
T = [[cell.T_g for cell in mesh.fine_mesh[f]] for f in copies] # cell temperatures of every copy
return maximum(maximum(Tc[i] for Tc in T) - minimum(Tc[i] for Tc in T) # spread over the five copies ...
for i in eachindex(T[1])) # ... in the worst cell
end
T_all = [cell.T_g for fine in mesh.fine_mesh for cell in fine] # every gas temperature in the star
println("temperature range : ", round(minimum(T_all); digits = 1), " K to ", round(maximum(T_all); digits = 1), " K")
println("spread, arms : ", round(symmetry_spread(2:2:10); sigdigits = 2), " K") # arms are faces 2, 4, …, 10
println("spread, centre : ", round(symmetry_spread(1:2:9); sigdigits = 2), " K") # centre triangles are faces 1, 3, …, 9
```
The gas is hottest at the centre, which sees the cold walls only through the absorbing gas of the arms, and coldest at the tips, where a cell is surrounded mostly by cold wall; the printed range spans the two. The heat removed by the walls matches the heat released in the gas to machine precision, as the printed relative imbalance shows. This holds for any number of rays, because energy conservation is built into the formulation ([Example 1](example-01.qmd), Step 6). The symmetry spread, by contrast, measures accuracy: it is pure sampling noise and shrinks as the number of rays grows.