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.

4. Convection and diffusion: the cell Péclet number and the power-law scheme

School of Engineering, Nazarbayev University

Suppose you solve steady convective heat or species transport u dϕ/dx=Γ d2ϕ/dx2u\,\mathrm{d}\phi/\mathrm{d}x = \Gamma\,\mathrm{d}^2\phi/\mathrm{d}x^2 between an inlet at ϕ(0)=0\phi(0) = 0 and a heated outlet wall at ϕ(L)=1\phi(L) = 1 using textbook second-order central differencing. Everything looks fine at slow speeds, until the cell Péclet number PeΔx=uΔx/Γ\mathrm{Pe}_{\Delta x} = u\Delta x / \Gamma crosses 2.0, at which point your predicted concentration oscillates below 0 (negative mass) and above 1. Switching to first-order upwind eliminates the wiggles, but adds a numerical diffusivity Γnum=∣u∣Δx/2\Gamma_{\mathrm{num}} = |u|\Delta x / 2. In this lecture, we analyze M-matrix positivity, audit all five schemes in convection_diffusion ("central", "upwind", "hybrid", Patankar’s "power_law", and Scharfetter–Gummel "exponential"), and explore multi-dimensional cross-wind false diffusion.

Learning objectives

  1. Evaluate the overflow-safe analytical outflow boundary-layer solution exact_steady_convection_diffusion_1d across Pe∈[−100,+500]\mathrm{Pe} \in [-100, +500].

  2. Prove from discrete M-matrix positivity (aE≥0a_E \geq 0) why "central" differencing produces unphysical spatial oscillations whenever ∣PeΔx∣>2|\mathrm{Pe}_{\Delta x}| > 2.

  3. Derive the artificial numerical diffusivity Γnum=∣u∣Δx/2\Gamma_{\mathrm{num}} = |u|\Delta x / 2 of first-order "upwind" and compare "hybrid", Patankar "power_law", and nodal-exact "exponential" weighting functions A(∣Pe∣)A(|\mathrm{Pe}|).

  4. Simulate 2-D oblique advection–diffusion–reaction with fvm_convection_diffusion_2d_steady and diagnose cross-wind false diffusion.

Time: about 60 min

1. Exact Outflow Boundary Layers in 1-D Convection–Diffusion

1.1 Analytical Two-Point Boundary-Value Solution

Steady 1-D conservation of a scalar ϕ(x)\phi(x) convected at constant velocity uu against molecular diffusivity Γ>0\Gamma > 0 on x∈[0,L]x \in [0, L] with ϕ(0)=ϕ0\phi(0) = \phi_0 and ϕ(L)=ϕL\phi(L) = \phi_L satisfies:

ddx ⁣(uϕ−Γdϕdx)=0  ⟹  ϕ(x)−ϕ0ϕL−ϕ0=exp⁡(Pe x/L)−1exp⁡(Pe)−1,Pe=uLΓ(1.1)\frac{\mathrm{d}}{\mathrm{d}x}\!\left(u\phi - \Gamma\frac{\mathrm{d}\phi}{\mathrm{d}x}\right) = 0 \implies \frac{\phi(x) - \phi_0}{\phi_L - \phi_0} = \frac{\exp(\mathrm{Pe}\,x/L) - 1}{\exp(\mathrm{Pe}) - 1}, \qquad \mathrm{Pe} = \frac{u L}{\Gamma} \tag{1.1}
  • As Pe→0\mathrm{Pe} \to 0, L’Hôpital’s rule recovers pure linear conduction ϕ(x)=ϕ0+(ϕL−ϕ0)(x/L)\phi(x) = \phi_0 + (\phi_L - \phi_0)(x/L).

  • For Pe≫1\mathrm{Pe} \gg 1 (u>0u > 0), inlet fluid sweeps ϕ≈ϕ0\phi \approx \phi_0 almost all the way across the domain until a thin exponential outflow boundary layer of thickness δ∼L/Pe=Γ/u\delta \sim L / \mathrm{Pe} = \Gamma / u forms right against x=Lx = L. A direct evaluation of ePee^{\mathrm{Pe}} overflows in double precision for Pe>710\mathrm{Pe} > 710; exact_steady_convection_diffusion_1d rewrites the ratio in overflow-safe form exp⁡(Pe(x/L−1))\exp(\mathrm{Pe}(x/L - 1)).


Demonstration 1: Overflow-Safe Analytical Outflow/Inflow Boundary Layers Across Pe
==================================================================================
Pe = -4.0e+01 | phi(0.5) = 1.000000e+00 | 90% transition x = 0.0050
Pe =  1.0e-09 | phi(0.5) = 5.012531e-01 | 90% transition x = 0.9023
Pe =  5.0e+00 | phi(0.5) = 7.637761e-02 | 90% transition x = 0.9799
Pe =  2.5e+01 | phi(0.5) = 3.845237e-06 | 90% transition x = 0.9975
Pe =  2.0e+02 | phi(0.5) = 4.779666e-44 | 90% transition x = 1.0000
Pe =  8.0e+02 | phi(0.5) = 5.219035e-174 | 90% transition x = 1.0000

What Demonstration 1 shows. At Pe=800\mathrm{Pe} = 800 (where np.exp(800) would return inf), exact_steady_convection_diffusion_1d remains smooth and finite: ϕ(x)\phi(x) stays essentially zero across 99.5%99.5\% of the tube and jumps from 0 to 1 inside the final δ≈3/Pe=0.0038 L\delta \approx 3/\mathrm{Pe} = 0.0038\,L.


2. Cell Péclet Number & Why Central Differencing Oscillates for ∣PeΔx∣>2|\mathrm{Pe}_{\Delta x}| > 2

Integrating (uϕ−Γϕx)x=0(u\phi - \Gamma\phi_x)_x = 0 over cell PP with convective flux F=uF = u and diffusive conductance D=Γ/ΔxD = \Gamma / \Delta x defines the cell Péclet number PeΔx=F/D=uΔx/Γ\mathrm{Pe}_{\Delta x} = F / D = u\Delta x / \Gamma. Writing aPϕP=aWϕW+aEϕEa_P \phi_P = a_W \phi_W + a_E \phi_E:

  • Central differencing ("central"): interpolates ϕe=12(ϕP+ϕE)\phi_e = \frac{1}{2}(\phi_P + \phi_E), giving east neighbor coefficient:

aEcentral=D−F2=D(1−12PeΔx)(2.1)a_E^{\mathrm{central}} = D - \frac{F}{2} = D\left(1 - \frac{1}{2}\mathrm{Pe}_{\Delta x}\right) \tag{2.1}

Whenever PeΔx>2\mathrm{Pe}_{\Delta x} > 2, aEcentral<0a_E^{\mathrm{central}} < 0. Increasing downstream ϕE\phi_E now decreases ϕP\phi_P, violating Scarborough’s discrete maximum principle and generating sawtooth (−1)i(-1)^i spatial oscillations.


Demonstration 2: Benchmarking All 5 FVM Schemes at Pe = 50 on N = 10 Cells (Pe_dx = 5.0 > 2)
============================================================================================
Scheme        | Pe_cell |   min(phi) |   max(phi) | Bounded [0,1]? | Max Nodal Err
----------------------------------------------------------------------------------
central       |    5.00 |   -0.11110 |   +0.04762 |          False |     1.932e-01
upwind        |    5.00 |   +0.00000 |   +0.28571 |           True |     2.036e-01
hybrid        |    5.00 |   +0.00000 |   +0.00000 |           True |     8.208e-02
power_law     |    5.00 |   +0.00000 |   +0.08669 |           True |     4.608e-03
exponential   |    5.00 |   +0.00000 |   +0.08208 |           True |     3.903e-18
<Figure size 704x462 with 1 Axes>

Figure 4.1. Largest error of four schemes against the cell Péclet number for a problem with Pe=uL/Γ=50\mathrm{Pe} = uL/\Gamma = 50, obtained by changing the number of cells from 5 to 320. The dotted line marks PeΔx=2\mathrm{Pe}_{\Delta x} = 2, above which the central scheme is unbounded.

What Demonstration 2 shows. At PeΔx=5.0\mathrm{Pe}_{\Delta x} = 5.0:

  • "central" predicts an unphysical negative concentration min⁡(ϕ)=−0.1111\min(\phi) = -0.1111 (bounded_no_overshoot == False).

  • "upwind" restores strict positivity ([0, 1]), but smears the boundary layer (max_error = 2.04e-1) because Taylor-expanding (uϕP−uϕW)/Δx=uϕx−12uΔx ϕxx+O(Δx2)(u\phi_P - u\phi_W)/\Delta x = u\phi_x - \frac{1}{2}u\Delta x\,\phi_{xx} + O(\Delta x^2) reveals artificial numerical diffusivity Γnum=12∣u∣Δx\Gamma_{\mathrm{num}} = \frac{1}{2}|u|\Delta x.

  • "exponential" (Scharfetter–Gummel 1969) is exact at the cell centers to rounding error (3.9×10−183.9\times 10^{-18}).

  • Patankar’s "power_law" (A(∣Pe∣)=max⁡(0,(1−0.1∣Pe∣)5)A(|\mathrm{Pe}|) = \max(0, (1 - 0.1|\mathrm{Pe}|)^5)) achieves max_error = 4.61e-3 (44×44\times more accurate than upwind) using only cheap algebraic multiplications.


3. Patankar’s Generalized A(∣Pe∣)A(|\mathrm{Pe}|) Weighting Framework

In convection_diffusion, all five schemes share a unified neighbor formula:

aW=D A(∣PeΔx∣)+max⁡(F,0),aE=D A(∣PeΔx∣)+max⁡(−F,0)(3.1)a_W = D\,A(|\mathrm{Pe}_{\Delta x}|) + \max(F, 0), \qquad a_E = D\,A(|\mathrm{Pe}_{\Delta x}|) + \max(-F, 0) \tag{3.1}

We plot A(∣Pe∣)A(|\mathrm{Pe}|) across ∣Pe∣∈[0,12]|\mathrm{Pe}| \in [0, 12] alongside the N=10N=10 boundary-layer profiles from Demonstration 2.


Demonstration 3: Visualizing Patankar Weighting Functions A(|Pe|) & Outflow Profiles
====================================================================================
<Figure size 1254x473 with 2 Axes>
Max |A_power_law - A_exponential| over [0, 12] = 0.01467

Figure 4.2. (a) The weighting function A(∣PeΔx∣)A(|\mathrm{Pe}_{\Delta x}|) of the five schemes. (b) The outflow boundary layer at PeΔx=5\mathrm{Pe}_{\Delta x} = 5 on ten cells: the central scheme oscillates, the upwind scheme is too diffusive and the power-law scheme stays close to the exact solution.

What Demonstration 3 shows. Panel (a) shows why Patankar’s fifth-power formula is widely used: (1−0.1∣Pe∣)+5(1 - 0.1|\mathrm{Pe}|)_+^5 tracks the exact Bose–Einstein / Scharfetter–Gummel curve ∣Pe∣/(e∣Pe∣−1)|\mathrm{Pe}|/(e^{|\mathrm{Pe}|}-1) within 0.0147 everywhere, shutting off molecular diffusion smoothly around ∣Pe∣≈10|\mathrm{Pe}| \approx 10 instead of prematurely chopping it off at ∣Pe∣=2|\mathrm{Pe}| = 2 like Spalding’s "hybrid" scheme.


4. Multi-Dimensional Oblique Flow & Cross-Wind False Diffusion

If "exponential" and "power_law" are nearly exact in 1-D, why don’t they solve every multi-dimensional CFD problem? We run fvm_convection_diffusion_2d_steady on a 32×3232 \times 32 square [0,1]2[0, 1]^2 with a diagonal 45∘45^\circ velocity (u,v)=(1,1)(u, v) = (1, 1) at Γ=0.02\Gamma = 0.02 (Pe=50\mathrm{Pe} = 50), left/top walls at ϕ=1\phi = 1, and bottom/right walls at ϕ=0\phi = 0, comparing "upwind" vs. "power_law" across the anti-diagonal perpendicular to the y=xy = x streamline.


Demonstration 4: 2-D Oblique 45-Degree Advection — Diagnosing Cross-Wind False Diffusion
========================================================================================
2-D oblique Upwind    (60 sweeps): 10%-90% cross-stream width = 10 cells
2-D oblique Power-Law (80 sweeps): 10%-90% cross-stream width = 8 cells
Exact skew-symmetry check max |phi(x,y) + phi(y,x) - 1| = 4.06e-13

Inside the algorithm

Below we inspect convection_diffusion._peclet_weighting_A and convection_diffusion.fvm_convection_diffusion_1d, and verify the formal asymptotic orders of accuracy (O(Δx1)O(\Delta x^1) for "upwind" vs. O(Δx2)O(\Delta x^2) for "central", "power_law", and "exponential" in the resolved regime ∣PeΔx∣<2|\mathrm{Pe}_{\Delta x}| < 2).

Check against the library


Inside the Algorithm: Asymptotic Convergence Orders of Upwind O(dx) vs Power-Law/Central O(dx^2)
================================================================================================
def _peclet_weighting_A(pe_abs: float, scheme: str) -> float:
    """Evaluate Patankar generalized neighbor-conductance weighting function A(|Pe|)."""
    key = scheme.strip().lower()
    if key == "central":
        return 1.0 - 0.5 * pe_abs
    if key == "upwind":
        return 1.0
    if key == "hybrid":
        return max(0.0, 1.0 - 0.5 * pe_abs)
    if key == "power_law":
        return max(0.0, (1.0 - 0.1 * pe_abs) ** 5)
    if key == "exponential":
        if pe_abs < 1e-8:
            return 1.0 - 0.5 * pe_abs + (pe_abs**2) / 12.0
        if pe_abs > 60.0:
            return 0.0
        return pe_abs / (np.exp(pe_abs) - 1.0)
    raise ValueError(f"Unsupported convection-diffusion scheme: {scheme!r}.")

def fvm_convection_diffusion_1d(
    n_cells: int,
    L: float,
    u: float,
    Gamma: float,
    phi_0: float = 0.0,
    phi_L: float = 1.0,
    scheme: str = "power_law",
) -> dict:
    """Solve 1-D steady FVM convection-diffusion u*dphi/dx = Gamma*d^2phi/dx^2 on n_cells uniform cells."""
    if n_cells < 2 or L <= 0.0 or Gamma <= 0.0:
        raise ValueError("Require n_cells >= 2, L > 0, and Gamma > 0.")
    dx = float(L) / int(n_cells)
    xc = (np.arange(n_cells, dtype=float) + 0.5) * dx
    f_conv = float(u)
    d_int = float(Gamma) / dx
    pe_cell = f_conv / d_int
    a_wt = _peclet_weighting_A(abs(pe_cell), scheme)

    a_west = d_int * a_wt + max(f_conv, 0.0)
    a_east = d_int * a_wt + max(-f_conv, 0.0)

    # Half-cell boundary distances dx/2 -> boundary diffusive conductance D_b = 2*Gamma/dx, Pe_b = Pe_cell / 2:
    d_bnd = 2.0 * d_int
    a_wt_bnd = _peclet_weighting_A(0.5 * abs(pe_cell), scheme)
    a_left_bnd = d_bnd * a_wt_bnd + max(f_conv, 0.0)
    a_right_bnd = d_bnd * a_wt_bnd + max(-f_conv, 0.0)

    lower = np.full(n_cells - 1, -a_west, dtype=float)
    upper = np.full(n_cells - 1, -a_east, dtype=float)
    diag = np.full(n_cells, a_west + a_east, dtype=float)
    rhs = np.zeros(n_cells, dtype=float)

    diag[0] = a_east + a_left_bnd
    rhs[0] = a_left_bnd * float(phi_0)
    diag[-1] = a_west + a_right_bnd
    rhs[-1] = a_right_bnd * float(phi_L)

    phi = solve_tridiagonal(lower, diag, upper, rhs)
    phi_exact = exact_steady_convection_diffusion_1d(xc, L=L, u=u, Gamma=Gamma, phi_0=phi_0, phi_L=phi_L)
    lo_b, hi_b = min(phi_0, phi_L), max(phi_0, phi_L)
    bounded = bool(np.all((phi >= lo_b - 1e-12) & (phi <= hi_b + 1e-12)))
    return {
        "x_centers": xc,
        "phi": phi,
        "phi_exact": phi_exact,
        "cell_peclet": pe_cell,
        "max_error": float(np.max(np.abs(phi - phi_exact))),
        "bounded_no_overshoot": bounded,
    }

Scheme upwind     | N=40->320 max_error: 3.938e-02 -> 5.626e-03 | asymptotic order = 0.971
Scheme central    | N=40->320 max_error: 1.754e-03 -> 2.957e-05 | asymptotic order = 1.983
Scheme power_law  | N=40->320 max_error: 3.008e-04 -> 5.804e-06 | asymptotic order = 1.956

Exercises

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

  1. Verify a result. Verify nodal machine-precision exactness (<10−13< 10^{-13}) of scheme="exponential" on N=8N = 8 cells across Pe∈{−80,−10,−1,0,+1,+10,+80}\mathrm{Pe} \in \{-80, -10, -1, 0, +1, +10, +80\}, and verify reflection symmetry ϕ(x;−u,1,0)=ϕ(L−x;+u,0,1)\phi(x; -u, 1, 0) = \phi(L-x; +u, 0, 1) across all five schemes.

  2. Find how it fails. Verify the PeΔx=2\mathrm{Pe}_{\Delta x} = 2 oscillation threshold of scheme="central" across PeΔx∈{1.5,1.99,2.5,5.0,8.0}\mathrm{Pe}_{\Delta x} \in \{1.5, 1.99, 2.5, 5.0, 8.0\} on N=12N = 12 cells, and check numerically that "upwind" at Γ=0.02\Gamma = 0.02 (u=1,L=1,N=200u=1, L=1, N=200) matches the exact analytical profile at Γeff=Γ+uΔx/2=0.0225\Gamma_{\mathrm{eff}} = \Gamma + u\Delta x/2 = 0.0225 over 6×6\times more closely than at true Γ=0.02\Gamma = 0.02.

  3. Implement it yourself. Implement fvm_convection_diffusion_reaction_1d(n_cells, L, u, Gamma, k_react, source, phi_0, phi_L, scheme="power_law") solving uϕx=Γϕxx−krϕ+Su\phi_x = \Gamma\phi_{xx} - k_r\phi + S, and verify against the exact analytical characteristic-root solution for u=2.0,Γ=0.2,kr=3.0,S=1.5,ϕ(0)=1.0,ϕ(1)=0.2u=2.0, \Gamma=0.2, k_r=3.0, S=1.5, \phi(0)=1.0, \phi(1)=0.2.


Self-check for the exercises
============================
Scharfetter-Gummel nodal exactness and flow-reversal symmetry verified