1D Diffusion Solver Back
Numerical Analysis

1D Diffusion Equation Solver

Solve the diffusion equation with a stable Crank-Nicolson update. Adjust diffusivity, domain length, grid count, initial condition, and boundary condition while the curve evolves.

Diffusion setup
Diffusivity D (×10-5 m²/s)
Domain length L (m)
m
Grid points N
Initial condition
Boundary condition
Results
0.000s
Elapsed time t
1.0
D value
1.000
Maximum u
1.000
Energy E/E0
1.00
Domain length L
Solution curve
Profile chart
Energy history
Theory & key formulas
$$\frac{\partial u}{\partial t}=D\frac{\partial^2u}{\partial x^2}$$

What This Simulator Shows

The curve represents temperature, concentration, or another scalar quantity diffusing along a one-dimensional domain. Higher diffusivity flattens the curve faster, while the boundary condition controls whether material escapes or remains trapped.

$$\frac{\partial u}{\partial t}=D\frac{\partial^2u}{\partial x^2}$$

Design Notes

The Fourier number summarizes how far diffusion has progressed relative to the domain length. Use the animation for physical intuition and the energy chart to confirm that the distribution is smoothing over time.

Applications And Limits

The same equation appears in heat conduction, dopant diffusion, concentration smoothing, and random-walk models. Treat the result as a one-dimensional idealization: convection, reactions, nonlinear material properties, and multidimensional geometry require a richer model.

How to Use

  1. Set diffusion coefficient D (m²/s), domain length L (m), and spatial grid points Ngrid (50-500 recommended)
  2. Choose initial condition: Gaussian (sigma parameter), step function, or sine wave
  3. Select boundary condition type: Dirichlet (fixed values), Neumann (zero flux), or periodic
  4. Configure time step and total simulation time; solver uses Crank-Nicolson implicit scheme
  5. Execute and monitor elapsed time t, maximum concentration u, normalized energy E/E0, and stability metrics

Worked Example

Heat diffusion in steel rod: D=1.2e-5 m²/s (thermal diffusivity), L=0.5 m, Ngrid=200, Gaussian IC (sigma=0.05 m, peak=100 K). After t=10 s with Neumann BC: peak drops to 62 K, energy ratio E/E0≈0.38. Crank-Nicolson ensures stability for Fourier number Fo=D*t/L²≈0.48, avoiding oscillations from explicit FTCS schemes. Spatial discretization: dx=0.0025 m, temporal: dt=0.05 s.

Practical Notes

  1. Increase Ngrid>300 for sharp Gaussian peaks; periodic BC preserves total mass exactly, Dirichlet with fixed boundaries causes artificial diffusion near edges
  2. For D values <1e-7 m²/s (slow diffusion), extend simulation time proportionally or reduce domain L to maintain physical relevance
  3. Energy decay E/E0 asymptotes toward zero; monitor it to confirm convergence—deviation >5% suggests inadequate grid resolution or too-large timestep relative to Fo criterion
  4. Step function IC with Neumann BC yields smooth exponential relaxation; sine IC decays faster due to higher-frequency content amplifying diffusive damping