Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

2. Steady diffusion and the harmonic mean at an interface

School of Engineering, Nazarbayev University

Suppose a copper heat spreader (k1=100 W/(m⋅K)k_1 = 100\ \mathrm{W/(m\cdot K)}) is bonded to a porous ceramic thermal barrier coating (k2=1 W/(m⋅K)k_2 = 1\ \mathrm{W/(m\cdot K)}). If your finite-volume solver interpolates the interface thermal conductivity at the shared face using the arithmetic mean ke=12(k1+k2)=50.5 W/(m⋅K)k_e = \frac{1}{2}(k_1 + k_2) = 50.5\ \mathrm{W/(m\cdot K)}, it treats the insulating face as 25×25\times more conductive than it truly is, and on a coarse grid overpredicts the heat flux by more than 30%30\%. In this lecture, we derive Patankar’s exact series-resistance harmonic_interface_conductivity, solve steady 1-D heat/mass diffusion in O(N)O(N) operations with solve_tridiagonal and fvm_diffusion_1d_steady, and verify machine-precision cell-by-cell conservation across composite walls and volumetric heat sources.

Learning objectives

  1. Discretize conservative 1-D steady diffusion −ddx(k dϕdx)=q-\frac{\mathrm{d}}{\mathrm{d}x}(k\,\frac{\mathrm{d}\phi}{\mathrm{d}x}) = q with Dirichlet and Neumann boundary conditions using fvm_diffusion_1d_steady.

  2. Solve N×NN \times N tridiagonal FVM systems in O(N)O(N) work and zero fill-in via the NumPy Thomas algorithm solve_tridiagonal.

  3. Derive Patankar’s harmonic_interface_conductivity from series thermal resistance and show why arithmetic face averaging fails across 100:1100:1 conductivity jumps.

  4. Verify exact global and cell-by-cell flux conservation (max_cell_balance_residual ≈10−15\approx 10^{-15}) on uniform, stretched, and composite meshes.

Time: about 60 min

1. Conservative 1-D FVM Diffusion & Half-Cell Boundary Conductance

1.1 Control-Volume Integration of Fourier / Fick Diffusion

Integrating −ddx ⁣(k(x)dϕdx)=q(x)-\frac{\mathrm{d}}{\mathrm{d}x}\!\left(k(x)\frac{\mathrm{d}\phi}{\mathrm{d}x}\right) = q(x) over cell Ωi=[xi−1/2,xi+1/2]\Omega_i = [x_{i-1/2}, x_{i+1/2}] of width ΔVi\Delta V_i with conductive flux J(x)=−k(x)dϕdxJ(x) = -k(x)\frac{\mathrm{d}\phi}{\mathrm{d}x} gives the exact discrete conservation balance:

Ji+1/2−Ji−1/2=qi ΔVi(1.1)J_{i+1/2} - J_{i-1/2} = q_i\,\Delta V_i \tag{1.1}

Approximating interior face fluxes between centroids xix_i and xi+1x_{i+1} via diffusive conductance Gi+1/2=ki+1/2xi+1−xiG_{i+1/2} = \frac{k_{i+1/2}}{x_{i+1} - x_i} yields a symmetric positive-definite tridiagonal system:

−Gi−1/2ϕi−1+(Gi−1/2+Gi+1/2)ϕi−Gi+1/2ϕi+1=qi ΔVi(1.2)-G_{i-1/2}\phi_{i-1} + \left(G_{i-1/2} + G_{i+1/2}\right)\phi_i - G_{i+1/2}\phi_{i+1} = q_i\,\Delta V_i \tag{1.2}
  • Dirichlet wall at xmin⁡x_{\min} (ϕ=ϕL\phi = \phi_L): the distance from the boundary face xmin⁡x_{\min} to the first centroid x0x_0 is the half-cell ΔV0/2\Delta V_0 / 2, giving wall conductance GL=k0x0−xmin⁡G_L = \frac{k_0}{x_0 - x_{\min}} and inward flux J0=−GL(ϕ0−ϕL)J_0 = -G_L(\phi_0 - \phi_L).

  • Neumann wall: specifies boundary conductive flux directly (J0=JleftJ_0 = J_{\mathrm{left}} inward at xmin⁡x_{\min}, or JN=JrightJ_N = J_{\mathrm{right}} outward at xmax⁡x_{\max}).


Demonstration 1: Nuclear Fuel Slab With Volumetric Heat Generation (Dirichlet & Neumann BCs)
============================================================================================
Dirichlet-Dirichlet max |T_fvm - T_exact| = 0.6944 K (= exact O(dx^2) half-cell offset q*dx^2/(8k) = 0.6944 K)
Dirichlet wall fluxes: FVM = (-100000.00, 60000.00) vs Exact = (-100000.00, 60000.00) W/m^2
Neumann-Dirichlet   max |T_fvm - T_exact| = 0.6944 K | J_right = 160000.00 W/m^2 (= q*L = 160000.00)
Max cell balance residual = 5.88e-10 W/m^2
<Figure size 704x462 with 1 Axes>

Figure 2.1. Interface conductivity between two cells of equal size against the ratio of their conductivities. The harmonic mean never exceeds twice the smaller conductivity (dotted line); the arithmetic mean grows with the larger one.

What Demonstration 1 shows. Two exact FVM properties on N=12N = 12 cells:

  1. Machine-precision wall fluxes & linear profiles: Both Dirichlet wall heat fluxes (-100,000 and +60,000 W/m2\mathrm{W/m^2}) and the adiabatic-cladding outward flux (q′′′L=160 000 W/m2q''' L = 160\,000\ \mathrm{W/m^2}) are exact to 10-12 regardless of NN.

  2. Exact O(Δx2)O(\Delta x^2) boundary-secant shift on quadratics: Interior centered slopes are exact on quadratics, while the half-cell boundary secant over [0,Δx/2][0, \Delta x/2] shifts interior centroids by the exact analytical constant q′′′Δx28k=0.6944 K\frac{q''' \Delta x^2}{8 k} = 0.6944\ \mathrm{K}.


2. Patankar’s Harmonic Interface Conductivity Across Composite Walls

Now consider an interior face xi+1/2x_{i+1/2} separating cell ii (conductivity kik_i, half-width δL=ΔVi/2\delta_L = \Delta V_i / 2) from cell i+1i+1 (conductivity ki+1k_{i+1}, half-width δR=ΔVi+1/2\delta_R = \Delta V_{i+1} / 2). Continuity of steady conductive heat flux Ji+1/2J_{i+1/2} across the interface demands that the two half-cells act as thermal resistors in series:

Rtotal=δLki+δRki+1=δL+δRki+1/2harm  ⟹  ki+1/2harm=δL+δRδL/ki+δR/ki+1(2.1)R_{\mathrm{total}} = \frac{\delta_L}{k_i} + \frac{\delta_R}{k_{i+1}} = \frac{\delta_L + \delta_R}{k_{i+1/2}^{\mathrm{harm}}} \implies k_{i+1/2}^{\mathrm{harm}} = \frac{\delta_L + \delta_R}{\delta_L / k_i + \delta_R / k_{i+1}} \tag{2.1}

On a uniform mesh (δL=δR\delta_L = \delta_R), Equation (2.1) simplifies to the harmonic mean ki+1/2harm=2kiki+1ki+ki+1k_{i+1/2}^{\mathrm{harm}} = \frac{2 k_i k_{i+1}}{k_i + k_{i+1}}. We test a 100:1100:1 composite wall (k1=100 W/(m⋅K)k_1 = 100\ \mathrm{W/(m\cdot K)} for x∈[0,0.5]x \in [0, 0.5], k2=1 W/(m⋅K)k_2 = 1\ \mathrm{W/(m\cdot K)} for x∈[0.5,1.0]x \in [0.5, 1.0], TL=1000 KT_L = 1000\ \mathrm{K}, TR=300 KT_R = 300\ \mathrm{K}) against a naive arithmetic-mean face solver.


Demonstration 2: 100:1 Composite Thermal Barrier — Harmonic vs Arithmetic Face Conductivity
===========================================================================================
Interface face x=0.5 conductivity: Harmonic = 1.9802 W/(m*K) vs Arithmetic = 50.5000 W/(m*K)
Exact composite heat flux J = 1386.1386 W/m^2 (Interface T = 993.07 K)
Harmonic FVM (N=4)   J = 1386.1386 W/m^2 (rel error = 6.50e-12%)
Arithmetic FVM (N=4) J = 1824.3396 W/m^2 (rel error = 31.61%, too high)

What Demonstration 2 shows. On an N=4N = 4 coarse mesh, arithmetic averaging sets k0.5=50.5 W/(m⋅K)k_{0.5} = 50.5\ \mathrm{W/(m\cdot K)}, short-circuiting the first ceramic half-cell and overpredicting heat transfer by 31.6%31.6\% (1824 W/m21824\ \mathrm{W/m^2} vs. exact 1386.14 W/m21386.14\ \mathrm{W/m^2}). Patankar’s harmonic_interface_conductivity gives k0.5=1.9802 W/(m⋅K)k_{0.5} = 1.9802\ \mathrm{W/(m\cdot K)} and reproduces the exact heat flux to rounding error on 4 cells.


3. Visualizing the Composite Kink & Mesh-Refinement Convergence

We plot the exact piecewise-linear temperature profile (gentle ΔT=6.9 K\Delta T = 6.9\ \mathrm{K} drop across the conductive metal vs. steep ΔT=693.1 K\Delta T = 693.1\ \mathrm{K} drop across the ceramic barrier) alongside harmonic vs. arithmetic FVM predictions across N∈{4,8,16,32,64,128}N \in \{4, 8, 16, 32, 64, 128\}.


Demonstration 3: Composite Wall Temperature Profile & Flux Convergence Study
============================================================================
<Figure size 1232x462 with 2 Axes>
Arithmetic mean asymptotic convergence order = 1.011 (degraded to 1st order O(dx)); N=128 still has 0.76% error.

Figure 2.2. (a) Temperature across a two-layer wall with a conductivity ratio of 100, computed with four cells: the harmonic mean at the interface reproduces the exact profile and the arithmetic mean does not. (b) Relative error of the heat flux against the number of cells for the two interface rules.

What Demonstration 3 shows. Not only is arithmetic face averaging inaccurate on coarse meshes, its convergence rate degrades to first order O(N−1)O(N^{-1}) across material discontinuities (an error of 0.76%0.76\% remains at N=128N = 128), whereas harmonic_interface_conductivity is exact to rounding error on every mesh whose face aligns with the material interface.


4. Non-Uniform Stretched Meshes & Spatially Varying k(x)k(x)

Does fvm_diffusion_1d_steady remain second-order accurate and strictly conservative when both the mesh spacing ΔVi\Delta V_i is strongly stretched (tanh_stretched_grid_1d) and thermal conductivity k(x)=k0eγxk(x) = k_0 e^{\gamma x} varies smoothly in space? We test against the manufactured analytical solution ϕ(x)=sin⁡(πx)\phi(x) = \sin(\pi x) on [0,1][0, 1], where q(x)=−ddx ⁣(k0eγxπcos⁡(πx))=k0eγxπ[πsin⁡(πx)−γcos⁡(πx)]q(x) = -\frac{\mathrm{d}}{\mathrm{d}x}\!\left(k_0 e^{\gamma x} \pi \cos(\pi x)\right) = k_0 e^{\gamma x}\pi\left[\pi\sin(\pi x) - \gamma\cos(\pi x)\right].


Demonstration 4: Second-Order Convergence on Stretched Meshes with Exponentially Varying k(x)
=============================================================================================
Stretched N =  16 (beta=2.0) | max |phi - sin(pi*x)| = 2.5138e-02
Stretched N =  32 (beta=2.0) | max |phi - sin(pi*x)| = 6.2578e-03
Stretched N =  64 (beta=2.0) | max |phi - sin(pi*x)| = 1.5756e-03
Stretched N = 128 (beta=2.0) | max |phi - sin(pi*x)| = 3.9433e-04
Observed convergence orders on stretched mesh: [2.006, 1.99, 1.998]

Inside the algorithm

Instead of calling np.linalg.solve on an N×NN \times N dense array (O(N3)O(N^3) flops and O(N2)O(N^2) RAM), grids_fvm.solve_tridiagonal executes Thomas forward elimination and back-substitution in O(N)O(N) time and O(N)O(N) memory. Below we inspect solve_tridiagonal and harmonic_interface_conductivity, and benchmark solve_tridiagonal against dense np.linalg.solve.

Check against the library


Inside the Algorithm: O(N) Thomas Algorithm vs Dense np.linalg.solve
====================================================================
def solve_tridiagonal(lower: np.ndarray, diag: np.ndarray, upper: np.ndarray, rhs: np.ndarray) -> np.ndarray:
    """Pure-NumPy O(N) Thomas algorithm for an N x N tridiagonal linear system."""
    n = diag.size
    cp = np.zeros(n - 1, dtype=float)
    dp = np.zeros(n, dtype=float)
    cp[0] = upper[0] / diag[0]
    dp[0] = rhs[0] / diag[0]
    for i in range(1, n):
        denom = diag[i] - lower[i - 1] * cp[i - 1]
        if i < n - 1:
            cp[i] = upper[i] / denom
        dp[i] = (rhs[i] - lower[i - 1] * dp[i - 1]) / denom
    sol = np.zeros(n, dtype=float)
    sol[-1] = dp[-1]
    for i in range(n - 2, -1, -1):
        sol[i] = dp[i] - cp[i] * sol[i + 1]
    return sol

def harmonic_interface_conductivity(
    k_cells: np.ndarray,
    volumes: np.ndarray,
) -> np.ndarray:
    """Compute exact series-resistance harmonic face conductivities k_{i+1/2} across interior FVM faces."""
    kc = np.asarray(k_cells, dtype=float).ravel()
    vols = np.asarray(volumes, dtype=float).ravel()
    if kc.size != vols.size or kc.size < 2 or np.any(kc <= 0.0):
        raise ValueError("k_cells and volumes must match in size >= 2 with k_cells > 0.")
    dl = 0.5 * vols[:-1]
    dr = 0.5 * vols[1:]
    return (dl + dr) / (dl / kc[:-1] + dr / kc[1:])

200x200 tridiagonal solve: max |x_thomas - x_dense| = 1.67e-16

Exercises

Worked solutions are in 02_solutions.ipynb. The cell below the list is a short self-check to start from.

  1. Verify a result. Verify the limit of a nearly perfect insulator (k0=200k_0 = 200, k1=10−8 W/(m⋅K)k_1 = 10^{-8}\ \mathrm{W/(m\cdot K)}) of harmonic_interface_conductivity on equal (ΔV=0.05,0.05\Delta V = 0.05, 0.05) and unequal (ΔV=0.02,0.08\Delta V = 0.02, 0.08) cell volumes, confirming k1/2harmk_{1/2}^{\mathrm{harm}} matches exact series thermal resistance.

  2. Find how it fails. Quantify the exact heat-flux error from using full-cell distance Δx\Delta x instead of half-cell Δx/2\Delta x/2 at Dirichlet boundaries on linear conduction (k=10,L=1,TL=100,TR=0,N=10k=10, L=1, T_L=100, T_R=0, N=10), and verify ValueError guards on negative conductivity and unsupported BC names.

  3. Implement it yourself. Implement fvm_diffusion_1d_robin(x_faces, k_cells, q_source, h_left, T_inf_left, h_right, T_inf_right) using series film-plus-half-cell conductance GRobin=(1/h+δhalf/k)−1G_{\mathrm{Robin}} = (1/h + \delta_{\mathrm{half}}/k)^{-1}, and verify to rounding error against the exact Biot-number analytical parabola on [−0.05,0.05] m[-0.05, 0.05]\ \mathrm{m} (q′′′=5×105 W/m3,k=25 W/(m⋅K),h=250 W/(m2⋅K),T∞=300 Kq''' = 5\times 10^5\ \mathrm{W/m^3}, k = 25\ \mathrm{W/(m\cdot K)}, h = 250\ \mathrm{W/(m^2\cdot K)}, T_\infty = 300\ \mathrm{K}).


Self-check for the exercises
============================
Insulator limit verified: k_harm = 2.000e-08 W/(m*K), J = 1.000e-04 W/m^2.
All checks passed.