← Learning map

MATHEMATICAL MODELING WORKSHOP / 06

When a smooth picture lies

How do spatial resolution and boundary conditions change diffusion?

About 150 minutesSynthetic teaching experimentv1.0.0Reading local draft…
Learning objectives & prerequisites

Derivatives, ODE time stepping and linear systems.

  • Derive diffusion from a flux balance.
  • Connect the numerical stability ratio with step and grid size.
  • Use boundary-specific mass checks and grid convergence.

01 / 08 · 10 MIN

Observe

A one-meter domain contains a synthetic concentration field. With fixed zero endpoints, use sin(πx); with periodic boundaries, use 1+0.5 cos(2πx). The exact time evolution of each mode is known, making these useful verification problems before considering measured spatial data.

YOUR TURN

Sketch both initial fields and explain how the two boundaries exchange or retain total material.

02 / 08 · 10 MIN

Ask

Separate a physical question (how fast the field spreads) from a numerical question (how closely a grid approximates the PDE). A finer grid changes resolution, not the physical diffusivity. An animation alone cannot distinguish these changes.

YOUR TURN

Define an error norm and a comparison time before choosing the grid.

03 / 08 · 15 MIN

Assume

Assume constant isotropic diffusivity in one dimension, no sources and the specified boundary. Fick's flux is J=−D ux. Integrating local accumulation over a cell gives a flux-in minus flux-out balance. Fixed endpoints allow loss; periodic boundaries must conserve total amount.

YOUR TURN

Record the units of D and identify which mass test belongs to each boundary.

04 / 08 · 20 MIN

Formulate

Combining ut=−Jx with Fick's law yields ut=Duxx. A centered second difference approximates uxx. Fixed endpoint derivatives are set to zero in the state update because endpoint values are prescribed. Periodic stencils wrap around without duplicating the last grid node.

ut=Duxx,ujn+1=ujn+λ(uj+1n2ujn+uj1n),λ=DΔt/Δx2u_t=D u_{xx},\qquad u_j^{n+1}=u_j^n+\lambda(u_{j+1}^n-2u_j^n+u_{j-1}^n),\quad \lambda=D\Delta t/\Delta x^2
YOUR TURN

Hand-compute the stencil at u=[0,1,4,9,0] with dx=0.1 and compare boundary treatments.

05 / 08 · 15 MIN

Design

Forward Euler requires λ≤1/2 for this one-dimensional centered diffusion scheme. Halving dx therefore requires roughly quartering dt. Backward Euler solves a linear system and avoids that stability restriction, but it still has time-discretization error. Stability is not accuracy.

YOUR TURN

Derive the amplification factor for a Fourier mode and predict the most dangerous wavelength.

06 / 08 · 25 MIN

Experiment

Complete the spatial operator in student_model. The runner chooses an integer number of time steps ending exactly at the requested time; the effective λ may be slightly below the requested ratio. Compare your explicit curve, the exact mode and backward Euler.

YOUR TURN

Run 20 and 40 cells with λ=0.4, then repeat under periodic boundaries. Record error and total amount.

07 / 08 · 25 MIN

Challenge

Increase λ beyond 1/2. A smooth low-frequency initial mode may still look plausible for a while because unstable high-frequency components begin near rounding error. The stability check should fail even before a dramatic image appears. Longer runs or perturbed modes can expose the instability.

YOUR TURN

Explain why a good-looking result cannot override a failed stability condition. Distinguish boundary loss from numerical leakage.

08 / 08 · 15 MIN

Communicate

Report the PDE, boundary, initial field, grid, effective time step and error. A convergence result for one exact mode verifies a limited setting. A reaction–diffusion extension needs new positivity and equilibrium checks rather than borrowing the pure-diffusion conclusion.

YOUR TURN

Write a convergence table and propose a reaction term with its own limiting-case test.

Need a little guidance?

1. Concept hint

For interior nodes use u[j+1]−2u[j]+u[j−1]. Remember the dx² denominator.

2. Mathematical / algorithm hint

Use np.roll for periodic neighbors; for fixed boundaries update only indices 1:-1.

3. Reference implementation guide

Trace the reference stencil on the hand-worked grid before running a long simulation.

Compare the reasoning before applying it. Your current code is backed up before replacement.

Experiment protocol: comparison, failure & extension

Required comparison

Compare 20 and 40 cells at fixed λ; compare explicit and backward Euler against the exact mode.

Failure experiment

Set λ=1.0. The stability condition fails even if the low-frequency curve initially looks smooth.

Research extension

Add a reaction term and test homogeneous equilibria before exploring pattern formation.

PYTHON WORKBENCH

Predict. Then run.

Parameters & random seed

Edit directly above or open the syntax-highlighting editor. The starter's unfinished student_model should fail relevant checks; use your derivation to complete it.

The runtime downloads only when started. Each experiment uses a fresh namespace and a 30-second limit.

Unable to load? Download the standalone notebook and run it in Python with NumPy, SciPy and Matplotlib. Reference notebook

Connect this lesson to your bookshelf.

Confirm draft change

Baseline and my run

The baseline uses the specified synthetic data; the right column shows only your last completed run.