← CFD

Unsteady Heat Conduction Equation

Introduction

The unsteady heat conduction (diffusion) equation is the simplest model problem for studying how a partial differential equation is discretised in space and marched in time. In this study, the equation was discretised with the finite volume method (FVM) and solved in two ways: (i) an explicit scheme (forward Euler), in which each new temperature is computed directly from known values, and (ii) an implicit Crank–Nicolson scheme, in which a tri-diagonal system of equations must be solved at every time step using the tri-diagonal matrix algorithm (TDMA). The 2D problem was solved with the line-by-line TDMA. All numerical results were compared with the analytical Fourier-series solution.

Key equation

The governing equation is the 1D (or 2D) heat conduction equation with thermal diffusivity $\alpha$ (here $\alpha = 1$, i.e. non-dimensional form):

\[\frac{\partial T}{\partial t} = \alpha \frac{\partial^2 T}{\partial x^2} \qquad \left( \text{2D:}\ \ \frac{\partial T}{\partial t} = \alpha \left( \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} \right) \right)\]

With the initial condition $T(x,0) = 1$ and the boundary conditions $T(0,t) = T(1,t) = 0$, the analytical solution on $0 \le x \le 1$ is the Fourier series below. In 2D, the exact solution is simply the product $T_{2D}(x,y,t) = T(x,t)\,T(y,t)$.

\[T(x,t) = \sum_{m = 1,3,5,\dots} \frac{4}{m\pi} \sin(m\pi x)\, \exp\!\left(-\alpha (m\pi)^2 t\right)\]

Integrating the equation over a control volume of width $\Delta x$ and over one time step $\Delta t$ gives the θ-scheme, where the diffusive fluxes are a weighted average of the old ($n$) and new ($n+1$) time levels:

\[\Delta x \frac{T_i^{n+1} - T_i^n}{\Delta t} = \theta \left[ \frac{T_{i+1}^{n+1} - T_i^{n+1}}{\Delta x} - \frac{T_i^{n+1} - T_{i-1}^{n+1}}{\Delta x} \right] + (1-\theta) \left[ \frac{T_{i+1}^{n} - T_i^{n}}{\Delta x} - \frac{T_i^{n} - T_{i-1}^{n}}{\Delta x} \right]\]

$\theta = 0$ gives the explicit (forward Euler) scheme, $\theta = 1/2$ the Crank–Nicolson scheme and $\theta = 1$ the fully implicit scheme. The key non-dimensional parameter is the diffusion number (local Fourier number):

\[r = \frac{\alpha \Delta t}{\Delta x^2}\]

Explicit scheme. With $\theta = 0$, each new value is obtained directly from the old values:

\[T_i^{n+1} = T_i^n + r \left( T_{i+1}^n - 2T_i^n + T_{i-1}^n \right)\]

This is simple but only conditionally stable: interior cells require $r \le 1/2$. With cell-centred volumes, the first and last cells lie only $\Delta x / 2$ from the wall, so the boundary flux has a factor 2 and the stricter limit $r \le 1/3$ applies there:

\[T_1^{n+1} = T_1^n + r \left[ \left( T_2^n - T_1^n \right) - 2 \left( T_1^n - T_W \right) \right]\]

Implicit scheme and TDMA. With $\theta > 0$, the unknown $T_i^{n+1}$ is coupled to its neighbours $T_{i\pm1}^{n+1}$, so each time step requires solving a linear system of the form

\[a_P T_i = a_E T_{i+1} + a_W T_{i-1} + S_u, \qquad a_E = a_W = \frac{\theta}{\Delta x}, \qquad a_P = a_E + a_W + \frac{\Delta x}{\Delta t}\]

where the source term $S_u$ contains only known values from the old time level. Because each equation involves only three unknowns, the matrix is tri-diagonal and can be solved in $O(N)$ operations by the TDMA (Thomas algorithm). In the forward elimination ($i = 1 \to N$), the lower diagonal is eliminated and each equation is rewritten as $T_i = P_i T_{i+1} + Q_i$:

\[P_i = \frac{a_E}{a_P - a_W P_{i-1}}, \qquad Q_i = \frac{S_{u,i} + a_W Q_{i-1}}{a_P - a_W P_{i-1}}\]

Since $P_N = 0$, the last value is known directly ($T_N = Q_N$), and the back substitution ($i = N \to 1$) recovers all the other temperatures one by one:

\[T_i = P_i\, T_{i+1} + Q_i\]

Line-by-line TDMA (2D). In 2D each node has four neighbours (E, W, N, S), so the matrix is no longer tri-diagonal. The line-by-line method solves one grid line at a time: along a row, the values on the neighbouring rows ($j \pm 1$) are treated as known and moved to the source term, which leaves a 1D tri-diagonal system that the TDMA can solve. An x-sweep (all rows) followed by a y-sweep (all columns) forms one iteration, and the iterations are repeated within each time step until the residual falls below $10^{-6}$.

\[a_P T_{i,j} - a_E T_{i+1,j} - a_W T_{i-1,j} = a_N T_{i,j+1}^{*} + a_S T_{i,j-1}^{*} + S_u \qquad (\,^{*}:\ \text{latest known values})\]

Setting

Both codes solve the same non-dimensional problem: a square plate initially at uniform temperature $T = 1$ whose boundaries are suddenly cooled to $T = 0$. The explicit solver was written in Fortran 90, and the implicit TDMA solver, including the step-by-step animation of the algorithm, in Python.

Table 1. Problem definition
ParameterValue
Domain1D: $0 \le x \le 1$, 2D: $0 \le x, y \le 1$
Thermal diffusivity$\alpha = 1$
Initial condition$T = 1$
Boundary condition$T = 0$ on all boundaries (Dirichlet)
Table 2. Numerical settings
ParameterExplicit (1D, Fortran)Implicit TDMA (1D / 2D, Python)
Spatial discretisationFVM, cell-centredFVM, node-centred
Time integrationForward Euler ($\theta = 0$)Crank–Nicolson ($\theta = 0.5$)
Grid$50$ cells, $\Delta x = 0.02$$21$ nodes ($21 \times 21$ in 2D), $\Delta x = 0.05$
Diffusion number$r = 0.25$ ($\le 1/3$, stable)$r = 1$
Time step$\Delta t = 1.0 \times 10^{-4}$ (1000 steps)$\Delta t = 2.5 \times 10^{-3}$
End time$t = 0.1$1D: $t = 0.5$, 2D: $t = 0.25$
Linear solverNone (direct update)TDMA (1D), line-by-line TDMA (2D), tolerance $10^{-6}$

Result

Figure 1 shows the temperature profiles of the explicit solver every 200 steps ($t = 0, 0.02, \dots, 0.1$). Heat escapes through both walls, and the initially flat profile quickly relaxes into a sine-like shape whose amplitude decays exponentially, as expected from the dominant first Fourier mode $\sin(\pi x)\,e^{-\pi^2 t}$. At $t = 0.1$, the numerical solution lies on top of the analytical solution, with a maximum error of about $1.7 \times 10^{-6}$.

Temperature profiles from the explicit solver compared with the exact solution
Figure 1. Temperature profiles of the explicit scheme ($r = 0.25$) and the exact solution at $t = 0.1$

Figure 2 visualises how the TDMA solves one Crank–Nicolson time step. On the left, the forward elimination removes the lower diagonal row by row, turning the tri-diagonal matrix into a bi-diagonal one; at this stage no new temperature is known yet. The back substitution then determines the new temperatures one point at a time from the right end to the left. The animation then continues with time marching, and the centre temperature $T(0.5, t)$ follows the exact solution even at $r = 1$, a time step four times larger than the explicit scheme can stably use on the same grid.

Animation of the TDMA forward elimination and back substitution for 1D heat conduction
Figure 2. 1D Crank–Nicolson solution by TDMA: matrix structure during elimination (left), temperature profile (top right) and centre temperature history (bottom right)

Figure 3 shows the 2D case solved by the line-by-line TDMA. The cyan frame marks the grid line currently being solved as a 1D problem. During the first iteration, the x-sweep and the y-sweep progressively propagate the effect of the cold boundaries into the plate, and repeated sweeps drive the residual below the tolerance. The centre temperature $T(0.5, 0.5, t)$ agrees well with the exact solution $T(0.5,t)^2$, and decays faster than in 1D because heat is lost through four walls instead of two.

Animation of the line-by-line TDMA for 2D heat conduction
Figure 3. 2D Crank–Nicolson solution by line-by-line TDMA: temperature field with the line being solved (left), 1D problem on that line (top right) and centre temperature history (bottom right)

Summary

Reference

数値流体工学 ↗www.utp.or.jp Crank-Nicolson (CrankNicolson) ↗www.ctcms.nist.gov