2D heat conduction solver

Set the plate size, the grid and the four side temperatures. The solver runs Jacobi, Gauss-Seidel and SOR side by side and shows the temperature field, the iteration counts, the best SOR factor and how far the answer is from the exact solution. The transient tab marches the explicit and implicit schemes and tells you the largest stable time step. The third tab checks the iteration counts from your own MATLAB or Python code. Free, no sign-up, runs in your browser.

Finite differences, 5-point stencil · Dirichlet sides · checked against a direct solve and the analytical solution · Updated 19 Nov 2026

nx and ny count the points including the boundary, as in the course codes (nx = 10 gives Δx = L/9). One iteration = one sweep over the grid; the error is the largest |Tnew − Told| in that sweep, like max(max(abs(Told − T))). Up to 81 × 81 points.

Sweeps: Jacobi / GS / SOR207 / 111 / 74SOR at ω 1.200; optimum ω 1.490: 29 sweeps
Mid-plate temperature675.00 Kanalytical at the centre 675.00 K
Steady temperature on the grid, isotherms every 50 K400525650775900K0x = 110
  • Jacobi spectral radius 0.9397: each Jacobi sweep removes 6.0% of the error, Gauss-Seidel 11.7%.
  • ω 1.20 is below the optimum 1.490, which needs 29 sweeps instead of 74.
  • Jacobi stopped about 1.6e-3 K from its converged answer (tolerance × ρ/(1 − ρ)): the change per sweep is not the error.
Largest change per sweep1e-51e-41e-31e-21e-11e01e11e21e3050100150200toleranceJacobiGauss-SeidelSOR ω 1.20iteration (sweep)

What is the 2D heat conduction problem?

A thin square plate has each side held at a fixed temperature: top 600 K, bottom 900 K, left 400 K, right 800 K. What is the temperature everywhere inside, once the plate settles, and how does it get there from 300 K? That is the mid-term project in Skill-Lync's Introduction to CFD using MATLAB and OpenFOAM, and more than 850 students have published their solvers for it. Heat flows from hot to cold by conduction, which is governed by

Replace each second derivative by a central difference on a grid of points, set the time derivative to zero, and every interior temperature becomes a weighted average of its four neighbours:

On a 10 × 10 grid that is 64 equations in 64 unknowns. Instead of solving them all at once, point-iterative methods sweep across the grid again and again, updating each point from its neighbours, until nothing changes by more than the tolerance.

How many iterations should Jacobi, Gauss-Seidel and SOR take?

On the course grid with a 10⁻⁴ K tolerance: Jacobi 207, Gauss-Seidel 111, SOR 74 at ω = 1.2 and 28 at ω = 1.5. The three methods differ only in which values they use. Jacobi uses only the old sweep. Gauss-Seidel uses each new value as soon as it has it, so information crosses the plate faster. SOR (successive over-relaxation) takes the Gauss-Seidel update and pushes it further in the same direction:

Largest change per sweep against sweep number for Jacobi, Gauss-Seidel and SOR on the 10 x 10 grid1e-51e-41e-31e-21e-11e01e11e21e3050100150200toleranceJacobi (207)Gauss-Seidel (111)SOR ω 1.2 (74)SOR ω 1.49 (29)iteration (sweep)
Largest change in one sweep (log scale) against sweep number, 10 × 10 grid. Jacobi and Gauss-Seidel settle into straight lines with slopes set by the spectral radius (0.9397 and 0.8830 per sweep); SOR at the optimum ω drops almost straight down.
Grid (points)JacobiGauss-SeidelSOR ω = 1.2SOR at ωoptωopt
10 × 1020711174291.490
20 × 20825440302591.717
30 × 301,783953657881.805
50 × 504,5872,4641,7081451.880

Jacobi and Gauss-Seidel slow down roughly with the square of the grid size: going from 10 to 50 points a side multiplies the Jacobi count by 22, while SOR at the optimum ω grows only 5.0 times. That is why reports of this project quote Jacobi counts from about 200 to over 4,000: they used different grids.

If your counts are 208, 112 and 29, your code is right and your counter starts at 1 (iter = 1 before the loop). In our sample, starting at 1 is about twice as common as starting at 0.

What is the best SOR relaxation factor?

For the 10 × 10 course grid, about 1.5: theory gives ωopt = 1.490, and Skill-Lync's runs need the fewest sweeps (28) at ω = 1.50 to 1.52. The optimum depends only on the grid, and for a rectangle with fixed side temperatures it is known in closed form (Frankel and Young, 1950):

For 10 × 10 points, ρJ = cos(20°) = 0.9397 and ωopt = 1.490. Running SOR at every ω from 1.00 to 1.95 confirms it: the count falls from 111 (ω = 1, which is Gauss-Seidel) to 28 at ω = 1.50, then climbs steeply. Above the optimum the error oscillates instead of decaying smoothly, and at ω = 1.95 it takes 305 sweeps.

Gauss-Seidel/SOR sweeps to 1e-4 against the SOR factor omega on the 10 x 10 grid0761532293051.01.21.41.61.82.0ω opt 1.490SOR factor ω
Sweeps to reach 10⁻⁴ against ω, 10 × 10 grid, Skill-Lync's own runs. The minimum is flat-bottomed on the low side and sharp on the high side: guessing a bit low costs less than guessing high.

Most students pick a cautious ω. In a sample of 120 public Skill-Lync reports of this project (taken 19 Nov 2026), 67 state ω in their code: 42 of them (63%) use 1.25 or less, 31 use exactly 1.2, and 17 use 1.4 to 1.6. At 1.2 the 10 × 10 grid needs 74 sweeps, 2.6 times as many as at 1.5. On finer grids the optimum moves towards 2 (1.717 at 20 × 20, 1.880 at 50 × 50), and a fixed 1.2 falls further behind: 1,708 sweeps against 145 on 50 × 50.

How close is the answer to the exact solution?

Within 0.1 K in the middle of the plate on the 10 × 10 grid, but up to 3.65 K next to the corners. Two different errors hide in the converged picture. The first is the stopping error. A tolerance of 10⁻⁴ on the change per sweep does not mean the answer is within 10⁻⁴ of where the iteration is heading: a slow method takes small steps. Compared with a direct (Gaussian elimination) solve of the same 64 equations, Jacobi stops 1.48 × 10⁻³ K away, Gauss-Seidel 0.67 × 10⁻³ K and SOR at the optimum 0.068 × 10⁻³ K. For Jacobi that is close to tolerance × ρ/(1 − ρ), the sum of all the steps it has not yet taken.

The second is the discretisation error: the grid answer itself differs from the true temperature. The plate has an analytical solution, a sine series for each side added together (Incropera, section 4.2). At the centre it gives exactly 675 K, the average of the four sides. On the 10 × 10 grid the largest difference is 3.65 K, at the node next to the bottom-left corner (554.11 K against 550.46 K), because the side temperature jumps from 400 to 900 K at that corner. At the point (1/3, 1/3), away from the corners, it is second order as it should be:

Grid (points)T at (1/3, 1/3), convergedError vs analytical (661.928 K)
10 × 10662.020 K0.0917 K
19 × 19661.952 K0.0239 K
37 × 37661.934 K0.0060 K

Halving the spacing cuts the error by 3.8 and then 4.0 times, close to the factor of 4 a second-order scheme promises. For this problem, the grid matters far more than the choice of iterative method: all three converge to the same grid answer.

The corner values you set (most codes average the two sides) never enter the calculation: no interior point has a corner as a neighbour. They only change the colours at the corners of your contour plot.

Why does the explicit scheme blow up?

Because the time step is too large. The explicit scheme computes the new temperature directly from the old one, and it is stable only if

(rx and ry are the diffusion numbers that students often call the CFL numbers). With α = 1.4 on the 10 × 10 grid, r = 0.1134 in each direction at Δt = 10⁻³, and the limit is Δt ≤ 2.205 × 10⁻³. In Skill-Lync's runs:

  • Δt = 10⁻³: the explicit scheme reaches the 10⁻⁴ test in 433 steps (t = 0.433) and ends 3.5 × 10⁻³ K from the steady answer.
  • Δt = 0.01 (19 of the 88 sampled reports that state Δt use it): 4.5 times over the limit; the temperatures reach 3.0e+12 K within 60 steps.
  • Just over the limit (1.05 ×): a trap. The run passes the 10⁻⁴ test after 198 steps and looks converged, because the unstable checkerboard pattern starts from round-off. Keep marching and it explodes past 1 K changes at step 843.

The implicit scheme writes the neighbours at the new time level too, so each time step is a small steady-type problem, solved with the same Jacobi, Gauss-Seidel or SOR loop:

Δt = 10⁻³, α = 1.4, 10 × 10Time stepsInner iterations, total
Explicit433none
Implicit, Jacobi inside4372,702
Implicit, Gauss-Seidel inside4392,152
Implicit, SOR ω = 1.2 inside4442,023
Implicit, Gauss-Seidel, Δt = 0.113477

At the same small Δt, implicit costs more work than explicit and gains nothing. Its value is the large time step: at Δt = 0.1, 45 times the explicit limit, it reaches steady state in 13 steps. One more catch: "stop when the change per step is below 10⁻⁴" depends on Δt. Halve Δt to 5 × 10⁻⁴ and the explicit run stops after 820 steps but 7.2 × 10⁻³ K from steady, further away than before, because each step changes less. Divide the change by Δt (a rate) if you want a criterion that does not move with the time step.

What this solver does not cover

  • Heat flux, convection and insulated sides (Neumann and Robin boundaries), heat generation inside the plate and temperature-dependent conductivity. All four sides here are fixed temperatures.
  • Crank-Nicolson, ADI and multigrid. Line and multigrid solvers beat SOR on big grids; commercial codes use them. This page sticks to the point-iterative methods of the assignment.
  • Non-rectangular shapes and unstructured meshes, which need finite volumes or finite elements.
  • Physical units for α. The course codes use α = 1.4 on a 1 × 1 plate as a nondimensional number. For a real plate use α = k/(ρc) in m²/s (plain carbon steel 1.77 × 10⁻⁵, pure aluminium 9.71 × 10⁻⁵, Incropera Table A.1) with lengths in metres; the stability rule is the same.
Write your own CFD solver

2D heat conduction is the mid-term project of Skill-Lync's Introduction to CFD using MATLAB and OpenFOAM, before the MacCormack nozzle, a backward-facing step and automated blockMesh generation. CFD teams hire engineers who understand what the solver does, not only which buttons to press.

Frequently asked questions

How many iterations should Jacobi, Gauss-Seidel and SOR take for the 2D heat conduction problem?

On the course grid (10 × 10 points on a 1 m square, sides 600/900/400/800 K, interior guess 300 K, stop when the largest change in one sweep is below 10⁻⁴): Jacobi 207 sweeps, Gauss-Seidel 111, SOR with ω = 1.2 74, SOR with ω = 1.5 28. If your counts are 208, 112 and 29, your counter simply starts at 1 instead of 0.

What is the optimum relaxation factor for SOR?

For a rectangle with fixed-temperature sides, ω_opt = 2/(1 + √(1 − ρ²)), where ρ is the spectral radius of Jacobi, cos(π/(n − 1)) on a square n × n grid. That gives 1.490 for 10 × 10, 1.717 for 20 × 20 and 1.880 for 50 × 50. Skill-Lync's ω sweep on the 10 × 10 grid finds the fewest sweeps (28) at ω = 1.50 to 1.52.

Why is my explicit solution blowing up?

The explicit (FTCS) scheme is stable only if α Δt (1/Δx² + 1/Δy²) ≤ 1/2. With α = 1.4 on the 10 × 10 grid, Δt must be at most 2.205 × 10⁻³. Δt = 0.01 is 4.5 times too big: our run grows to 3.0e+12 K in 60 steps. The implicit scheme has no such limit.

Is the converged answer the exact temperature?

No. Stopping at a change of 10⁻⁴ leaves Jacobi 1.48 × 10⁻³ K from the fully converged grid answer, and the 10 × 10 grid itself differs from the analytical solution by up to 3.65 K next to the corners, where the side temperatures jump. In the middle the grid answer is within 0.1 K, and halving the spacing cuts that error about four times.

Do the corner temperatures matter?

Not for the answer. The five-point formula at an interior node uses its four neighbours, and no interior node has a corner as a neighbour. Averaging the corners (or leaving them at any value) only changes how your contour plot looks at the four corners.

What is the temperature at the centre of the plate?

Exactly (600 + 900 + 400 + 800)/4 = 675 K, for the analytical solution and for any odd square grid, by symmetry: rotate the plate by 90° four times and add the four problems. A 10 × 10 grid has no centre node; the average of its four middle nodes is 675.00 K.

Related on Skill-Lync

Sources

  • T. L. Bergman, A. S. Lavine, F. P. Incropera, D. P. DeWitt, Fundamentals of Heat and Mass Transfer, Wiley: chapter 4 (two-dimensional steady conduction, separation of variables, finite differences) and chapter 5 (explicit finite-difference stability).
  • S. P. Frankel, "Convergence rates of iterative treatments of partial differential equations", Mathematical Tables and Other Aids to Computation 4 (1950) 65-75, and D. M. Young, "Iterative methods for solving partial difference equations of elliptic type", Transactions of the AMS 76 (1954) 92-111 (successive over-relaxation and its optimum factor).
  • J. D. Anderson, Computational Fluid Dynamics: The Basics with Applications, McGraw-Hill 1995 (finite differences, explicit and implicit schemes, stability).
  • Skill-Lync, sample of 120 public student reports of the 2D heat conduction project, read 19 Nov 2026 (settings in their code: ω, grid, error test).
  • Skill-Lync, scripts/verify/heat2d.mjs: an independent script with its own MATLAB-style solvers, a direct Gaussian-elimination solve, the Fourier-series analytical solution and a power-iteration check of the spectral radius. This page checks its numbers against that script at build time.
Free counselling

From a heat conduction code to a CFD career.

Writing a solver from scratch is how CFD engineers learn why grids, time steps and convergence criteria matter. A Skill-Lync counsellor can map the course that fits the role you want.

Talk to a CFD course counsellor

Free. We call you back, usually the same day.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.