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.

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

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 4. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.

Exercise 1

Problem. 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.


Exercise 1: Scharfetter-Gummel Nodal Exactness & Flow-Reversal Symmetry
=======================================================================
Exponential scheme (N=8, Pe= -80.0) | max centroid error = 1.11e-16
Exponential scheme (N=8, Pe= -10.0) | max centroid error = 6.66e-16
Exponential scheme (N=8, Pe=  -1.0) | max centroid error = 9.99e-16
Exponential scheme (N=8, Pe=  +0.0) | max centroid error = 1.67e-16
Exponential scheme (N=8, Pe=  +1.0) | max centroid error = 3.33e-16
Exponential scheme (N=8, Pe= +10.0) | max centroid error = 1.11e-16
Exponential scheme (N=8, Pe= +80.0) | max centroid error = 8.67e-19
Flow-reversal symmetry (central    ): max |phi_rev(x) - phi_fwd(L-x)| = 3.47e-18
Flow-reversal symmetry (upwind     ): max |phi_rev(x) - phi_fwd(L-x)| = 1.39e-17
Flow-reversal symmetry (hybrid     ): max |phi_rev(x) - phi_fwd(L-x)| = 0.00e+00
Flow-reversal symmetry (power_law  ): max |phi_rev(x) - phi_fwd(L-x)| = 2.78e-17
Flow-reversal symmetry (exponential): max |phi_rev(x) - phi_fwd(L-x)| = 1.73e-18

Explanation. Between any two grid nodes, the homogeneous 1-D flux J=uϕ−ΓϕxJ = u\phi - \Gamma\phi_x is constant; integrating that two-point ODE analytically yields the exact Scharfetter–Gummel interface flux, making "exponential" exact at all centroids on any 1-D grid when sources vanish.


Exercise 2

Problem. 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.


Exercise 2: Central-Difference Wiggle Threshold & Upwind Modified-Diffusivity Proof
===================================================================================
Central Pe_dx = 1.50 | min(phi) =  +0.000000 | bounded = True
Central Pe_dx = 1.99 | min(phi) =  +0.000000 | bounded = True
Central Pe_dx = 2.50 | min(phi) =  -0.025641 | bounded = False
Central Pe_dx = 5.00 | min(phi) =  -0.111110 | bounded = False
Central Pe_dx = 8.00 | min(phi) =  -0.332796 | bounded = False

Upwind (Gamma=0.02, Gamma_num=0.0025): error vs true Gamma=0.02 PDE = 3.9436e-02 | error vs inflated Gamma_eff=0.0225 PDE = 5.9504e-03

Explanation. Even on N=200N = 200 cells (PeΔx=0.25\mathrm{Pe}_{\Delta x} = 0.25), first-order "upwind" in effect solves the inflated diffusivity Γeff=Γ+uΔx/2=0.0225\Gamma_{\mathrm{eff}} = \Gamma + u\Delta x/2 = 0.0225 (+12.5%+12.5\% artificial diffusion), matching the Γ=0.0225\Gamma = 0.0225 analytical curve 6.6×6.6\times closer than the true Γ=0.02\Gamma = 0.02 PDE.


Exercise 3

Problem. 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.


Exercise 3: Implement It Yourself — 1-D Axial-Dispersion Convection-Diffusion-Reaction Solver
=============================================================================================
1-D Axial-Dispersion CDR max |phi_fvm - phi_exact| (N=100) = 9.303e-05

Summary. Adding linear reaction −krϕ-k_r\phi increases the main diagonal aP←aP+krΔVa_P \leftarrow a_P + k_r\Delta V (k_react >= 0), strengthening diagonal dominance and preserving M-matrix positivity across tubular catalytic reactors.