# Temperature (`kicad2ems.pcbqs.thermal`) A trial of a lightweight thermal solver inside pcbqs: the steady temperature of a board from what its parts dissipate, in a fraction of a second, on a regular grid. The 3D reference remains Elmer through kicad2ems-fem, and the two agree within 2 K on eleven boards (below). python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss Q1=0.35 --loss D1=0.5 python -m kicad2ems.pcbqs.thermal --circuit circuit-results # the board and losses of a circuit run python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss U1=1.2 --theta U1=8 --film 12 --ambient 40 python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss Q1=0.35 --film-edge 0 # the edges insulated python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss Q1=2 --theta Q1=3 --air Q1=15 # a heatsink on Q1 python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss Q1=2 --hold H1=40 --air-speed 1.5 --transient 1800 In kicad2ems-gui it is the **Thermal** analysis (`kicad2ems.pcbqs.analyses.Thermal`, a kicad2ems analysis): its form is its options table, and with no losses typed it takes the latest circuit run's, on that run's board. It writes `thermal.json` (each part's temperature, each layer's hottest and mean, heat in and out, the board and the circuit case they came from), `thermal.npz` (the maps) and `thermal.png`. The maps also go where kicad2ems's viewer reads a run's (`thermal/viewer.py`): `thermal_board.json` and, under `thermal/exc_board/`, each layer's temperature as a field dump in °C (NaN off the board), so the Viewer turns, cuts and probes them in 2D and 3D on a colour scale from the board's coolest point to its hottest. The report (`reports.thermal_report`: the parts' and the layers' tables) is on its Report and Tables pages. ## The model The board is a stack of sheets, one per copper layer (`problem.py`): - **Along the board** a sheet conducts through its copper (390 W/m/K x its thickness, where there is copper) and its share of the laminate (0.8 W/m/K; half of the dielectric on each side of it). - **Between sheets** heat crosses the dielectric (0.3 W/m/K over its thickness, per area) and the vias (each a plated barrel, 25 um). - **To the air** the two outer sheets lose heat through a film coefficient, convection and radiation together (10 W/m2/K a face unless told otherwise; `--film`, `--film-bottom`), to the ambient (25 C; `--ambient`). - **At the edges** (the outline and its cut-outs) every sheet loses heat over the height of the board it stands for, its share of the laminate, so the edges are the board's whole thickness high. Their coefficient is the mean of the faces' unless told otherwise (`--film-edge`; 0 insulates them). On a small board they matter: on the demo boards (17 to 62 mm across) they carry 6 to 15 % of the heat and lower every rise by 4 to 13 %. - **Heat comes in** over the pads of the parts that dissipate: each part's loss, shared over its pads by area. - **A part's temperature** is the mean temperature of the copper under its pads, plus its loss times its theta (K/W from its pads to the part itself: its junction, with a datasheet's junction-to-board figure), when one is given: `--theta REF=K/W`, or the footprint's field `thermal.theta`. Without one the report says the figure is its pads'. **A limit**, `--tmax REF=C` or the field `thermal.tmax` (its junction's maximum), gives each part its margin, and a part over it is in the report's headline. It is the DC drop's equation with thermal conductivities and a sink over the whole face, and it is linear: one sparse solve. ### Beyond the films - **A part's own path to the air**, `--air REF=K/W` or the footprint's field `thermal.air`: its body's convection and radiation, or a heatsink on it (the sink's K/W, with its interface). The part becomes a node of its own, joined to its pads through its theta (0.001 K/W where none is given: it is at its pads') and to the air through this, so its heat splits between the board and the air; `parts[REF].to_air_W` is the air's share and `heat_out_parts_air_W` the sum. - **A footprint held at a temperature**, `--hold REF=C`: its pads tied to it (a cold plate, a chassis screw, a heatsink clamped to the board). `held[REF].out_W` is the heat that leaves through it (negative: it heats the board). - **Moving air**, `--air-speed m/s` (and `--air-length mm` along the flow, the outline's longer side unless given): both faces' coefficient from a laminar flat plate's convection, 3.84 √(v/L) W/m²/K, joined to the still air's convection as assisting flows join ((h_n³ + h_f³)^⅓), with radiation (6 W/m²/K of the 10) on top. - **Over time**, `--transient s`, with each part's loss by a profile: [below](#over-time). In code: `p.air = {'Q1': 15.0}`, `p.hold(board, {'H1': 40.0})`, `forced_film(1.5, 80.0)`, and `solve(p, 0.5, transient=1800)` (its `r.transient`). With a circuit run on its board's copper and `--fields`, the copper's own loss heats the board where its currents are (the run's `copper-loss.npz`: each triangle's share, gathered into 1 mm squares); without `--fields` the report says it is left out. `--circuit FOLDER` takes the board and the losses from a circuit run (`python -m kicad2ems.pcbqs.circuit`): every part's average power, summed per footprint. A coupled winding gives its own loss (`loss_W`: its resistances', the DCR and the core's), not its V·I, which is the power it passes to the other windings too; a switch's gate drive is counted on the switch (its gate resistance). A source and a load are not on the board, nor is a part bound to a connector, and each is said. In code: ```python from kicad2ems.pcbqs.thermal import Problem, solve p = Problem.of(board, {'Q1': 0.35, 'D1': 0.5}, film=10.0, theta={'Q1': 2.0}) p.edge_film # W/m2/K at the edges: the faces' mean (edge_film=0: none) p.heat('shunt', [('F.Cu', polygon)], 0.2) # heat over any area of a layer r = solve(p, 0.5) # the grid's pitch, mm r.parts['Q1'] # dict(power_W, board_C, part_C) r.out_W, r.edge_W # the heat given off, and of it through the edges r.T # (layers, ny, nx) C r.sample('F.Cu', x, y) # at points (mm) ``` `sample` interpolates between cell centres (NaN off the board, and in its holes). ## Over time `--transient SECONDS`: the temperature over that long, from the board's own heat capacity (FR-4 2.0 MJ/m³/K, copper 3.45; the parts' bodies hold none, so a part's first seconds read quick), each part's loss by a profile: python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss Q1=2 --transient 1800 # the heating from cold python -m kicad2ems.pcbqs.thermal board.kicad_pcb --loss Q1=2 --loss U1=0.5 --transient 600 \ --profile Q1=pulse:20,40@10 --profile U1=step:0.3,1@60 --start steady # bursts; a load step from 30 % python -m kicad2ems.pcbqs.thermal board.kicad_pcb --profile Q1=q1_watts.csv --transient 3600 # t_s, W rows A profile (`--profile REF=SHAPE`, repeat; `all=SHAPE` for every part without its own) scales a part's loss: `step[:A,B][@T]` (A before T, B from it; 0 and 1 unless given), `off@T` (on until T: a cooling), `pulse:ON,OFF[,LOW,HIGH][@T]` (HIGH for ON seconds, LOW for OFF, repeating from T), or a file of `t_s, W` (the part's loss in watts, linear between the rows; its `--loss` need not be given). `--start cold` runs from the ambient, `--start steady` from the steady temperature of the profiles' values before t = 0. The stepping (`thermal/transient.py`) is TR-BDF2: a trapezoidal stage then BDF2, second order and L-stable, so a step far longer than the copper's own time constants damps them instead of ringing, and both stages take one matrix, factored once for each step length. Each step's local error is estimated from the stages' slopes (Hosea and Shampine's estimate: matrix-vector products alone) against 1 mK + 1e-4 of the largest rise; a step over it is taken again at half the length, one well inside it lets the next double. The lengths are a ladder of powers of two, so the factors are few and every pulse of a train reuses them (kept within a memory budget, the longest unused given up first; an interval's last step, which ends on its break, by conjugate gradients on the rung below's factor). No step crosses a profile's break. The board's longest time constants come from the generalized eigenproblem C v = τ A v (ARPACK on A's factor). **A large grid** (over 40,000 unknowns) is run as a reduced model: a factor per step length of the Jetson carrier's 179,000 unknowns is 0.8 GB and 6 s, and a pulse train wants a dozen or more. The heats gathered by their profiles, the start and the copper's self-heating are the inputs of a rational block Krylov basis (six moments at the steady state, whose factor the steady solve has, and at two shifts set by the shortest stretch between breaks: two more factors); the grid projected on it by congruence (PRIMA: stable and passive, the steady state exact) and diagonalised is stepped as the grid is, each step's temperatures lifted back. On the Jetson's SYS_VIN_HV at 6 A in 60 s bursts every 300 s over 1200 s: 36 unknowns, 20 s against 244 s and 4.7 GB at most against 18.9, within 0.1 mK of the grid stepped itself at every break; its time constants 135.4, 78.1, 41.9 s. It writes `thermal-transient.json` (the times, each part's temperature and the hottest copper against time, each part's peak and when, the time constants, `to_63_s` for the heating from cold: when each part is 63 % of the way there) and `thermal-transient.png`; the report's *Over time* section and a curve set of the parts against time. Checks (`tests/pcbqs/test_thermal_transient.py`): a lumped RC within 5e-4 of its closed form, and with a self-heating loss (the electrothermal one) within 1e-3; a plate heated all over (one mode) through a pulse train, a cooling and a load step within 1 % of its exact response; its time constant C / G to 1e-6 and its 63 % time to 2e-4 (backward Euler's, before 2026-11-27: 2 % late); after many time constants every part at its steady temperature (2 mK), and a run from the steady state staying there; the reduced model against the grid stepped itself, a self-heating heat with it, within 5 mK at every break and its time constants to 1e-5. The copper's own loss from the DC drop, with its resistance at its temperature, and both over time for a load profile: [Drop at temperature](electrothermal.md). ## The solver **Grid** (`grid.py`): square cells over the outline's bounding box, one unknown per cell on the board per layer (finite volumes). The copper of each layer is put on a raster much finer than the cells (1/16 mm; exact in area), and the conductance between two neighbouring cells is worked out on that raster: between their centres each fine row is a chain in series, the rows in parallel. So a gap narrower than a cell still holds heat back, a trace narrower than a cell still carries it, a slot in the board still parts it, and nothing follows the outline of the copper: the number of unknowns depends on the board's area and layer count only. ## What the trial found The trial had a second solver to check the grid, a **mesh** (pcbqs's triangle mesher, linear elements, one mesh of the outline carrying every layer's copper outlines); it was removed in 2026-11. Both against the exact solution for a heated disc on a two-layer plate (the sum and the difference of the two layers each obey a screened Poisson equation; 1 W over 10 mm, 15 K rise at the centre): | | size | unknowns | worst error | time | |---|---|---|---|---| | grid | 1 mm | 28,800 | 0.06 K | 0.6 s | | grid | 0.5 mm | 115,200 | under 0.05 K | 1.4 s | | mesh | 2 mm | 12,000 | 0.13 K | 0.2 s | | mesh | 1 mm | 45,710 | under 0.05 K | 1.2 s | (0.04 K of what is left is the plate's edge, which the exact solution does not have.) A face heated all over gives the exact uniform temperatures on both to 1e-6 K, and the heat leaving through the films equals the heat put in. On the ten demo boards, with the losses of their circuit runs (0.006 to 1.26 W, rises of 1 to 62 K), every part's temperature against the mesh at 0.25 mm: | | size | worst part, any board | all ten boards | |---|---|---|---| | grid | 2 mm | 1.1 K | 0.5 s | | grid | 1 mm | 0.2 K | 0.3 s | | grid | 0.5 mm | 0.25 K | 0.6 s | | mesh | 2 mm | 0.8 K | 0.4 s | | mesh | 1 mm | 0.3 K | 0.5 s | | mesh | 0.5 mm | 0.1 K | 1.7 s | On boards this simple the two are the same solver for practical purposes. They part on a dense board. One made in code (100 x 80 mm, four layers, 500 routed traces, a ground plane and a split power plane with 227 clearances each, 400 vias, eight parts, 3.75 W): | | size | unknowns | time | memory | hottest part | |---|---|---|---|---|---| | grid | 1 mm | 32,000 | 0.9 s | | 59.1 C | | grid | 0.5 mm | 128,000 | 3.3 s | 0.5 GB | 59.5 C | | grid | 0.25 mm | 512,000 | 27 s | | 59.5 C | | mesh | 2 mm | 1,572,116 | 53 s | 4.1 GB | 58.8 C | | mesh | 1 mm | 1,985,092 | 91 s | | 59.1 C | The mesh cannot be coarse there: 1.5 million unknowns are spent on following outlines before any are spent on the temperature, and it is still converging from below at 2 million. The grid at 0.5 mm is within 0.1 K of its own answer at 0.25 mm. So the grid is the one taken forward: its cost does not depend on the copper, it needs no mesher, and its maps are images. Elmer (below) is the check on it. Two things the trial turned up in the grid, both fixed and tested: a board that ends inside a cell lost that cell's conduction to its neighbour (the whole board read 1 K hot), and a drawn raster made thin traces a quarter wider than they are (the raster is now exact in area). The grid-mesh tables above were taken before the edges lost heat. ## Against Elmer `validation/pcbqs/thermal_elmer.py` runs each demo circuit and gives its lossiest case's part losses to the grid (0.5 mm) and Elmer through kicad2ems-fem (`elmer/thermal.py`: 3D conduction in the copper, the barrels and an anisotropic laminate, wedge elements, the same film on every exposed face), with the same film, ambient and conductivities. Each part's temperature is the mean under its pads in both. | | parts | worst part | within 1 K | grid time | Elmer time | |---|---|---|---|---|---| | ten demo boards, 2 layers, 0.006-1.26 W | 48 | 2.0 K, 4.5 % of its rise (05 C1); 5.5 % at most (09 C1) | 43 of 48 | 0.02-0.09 s | 0.5-1.5 s | | wpthb, 4 layers, Q1 Q2 L3 1 W | 3 | 0.9 K, 3.1 % (L3) | 3 of 3 | 0.4 s | 12 s | Both are converged: from 1 to 0.125 mm the grid moves under 0.2 K, and from 30,000 to 330,000 wedges Elmer moves under 0.2 K. The mesh, while it was there, agreed with the grid within 0.2 K on the demo boards (0.9 K on wpthb's L3). Two things the comparison found: - **The edges.** Before they lost heat here, every part read 4.5 K hot of Elmer on the 04 buck, a tenth of the rise on every board alike: Elmer's film covers the board's edges, and on a board 20 by 37 mm they give off a tenth of the heat. With the edges in, that offset is gone. - **What is left is the laminate, not the mesh.** The hottest parts read up to 2 K (5 %) low and the coolest up to 2 K high: the sheets spread heat a little more than the 3D board does. Its in-plane conduction is put on the copper sheets at their temperatures, which near a hot pad overstates it (in the 3D board the laminate between the layers is cooler than the copper on top). With the laminate's in-plane conductivity set to zero in both, the difference turns into a near-uniform +0.5 to +1 K. Copper at 385 against 390 W/m/K accounts for 0.05 K. ## What it does not do yet - **The parts' own cooling** is a number the user gives (`--air`); with none, all of a part's heat goes into the board, which reads high for parts that stand tall (inductors, electrolytics). - **The film is one number** a face (or moving air's). Natural convection and radiation both grow with the temperature rise, and the air warmed by one part reaches the next. A film that depends on the temperature is a few repeats of the same solve. - **Resistance against temperature** feeds back into the circuit's losses with `kicad2ems.pcbqs.circuit --warm` ([circuit.md](circuit.md#parts-at-their-temperatures)) and into the DC drop's copper with [the drop at temperature](electrothermal.md); a circuit's copper (`--fields`) is at its run's temperature. - **The laminate between the sheets.** Its in-plane conduction sits on the sheets (above); one more sheet per dielectric, at mid-thickness, would follow the 3D board more closely near hot parts, for 2L-1 unknowns per cell instead of L. - Large grids want a multigrid solve; a direct one is used (about 3 s at 128,000 unknowns on four layers).