Thermal Diffusion Lab models heat conduction along a rod with insulated ends. A C++17 solver advances the same temperature field with Forward Euler, Backward Euler or Crank–Nicolson. The web interface displays the computed profiles at matched times, alongside the mean temperature, the temperature range and a fixed-position probe.
| Initial temperature field | Physical behaviour | Reported quantity |
|---|---|---|
| Hot–cold interface | The left and right halves start at 1 and 10. Diffusion smooths the jump while the spatial mean remains 5.5. | Temperature profile and maximum–minimum temperature difference |
| Single cosine mode | The profile retains its shape as its amplitude decays exponentially. | Maximum absolute error against the analytical solution |
| Local heat pulse | A Gaussian pulse spreads from the midpoint toward both insulated ends. | Space–time field and temperature history at a selected cell |
The web dataset covers 24 combinations of initial field, time integrator and diffusion ratio. Each run contains 41 snapshots on the same time grid. Both the 64-cell profile at a selected time and the 41-sample history at a selected position are available as CSV.
The model has constant diffusivity
The default rod has length 20 and diffusivity 1 in model units. A cell-centred finite-volume discretization uses equal and opposite fluxes across each internal face. These contributions cancel when summed over the grid, conserving the spatial mean.
| Time integrator | Temporal order | Update |
|---|---|---|
| Forward Euler | 1 | Explicit update with diffusion ratio |
| Backward Euler | 1 | Implicit tridiagonal solve using end-of-step fluxes |
| Crank–Nicolson | 2 | Implicit tridiagonal solve using the average of the initial and final fluxes within the time step |
Both implicit schemes factor the constant tridiagonal matrix once. Each step takes
I use a single cosine mode to check the solution at every cell centre. Its closed-form temperature is
The refinement test uses
| Scheme | Maximum absolute error on 64 cells | Error ratio, 32 cells to 64 |
|---|---|---|
| Forward Euler | 0.00010235 | 3.998 |
| Backward Euler | 0.00051144 | 3.991 |
| Crank–Nicolson | 0.00020462 | 3.994 |
Halving the cell width at fixed
The project requires a C++17 compiler and CMake 3.20 or newer.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
ctest --test-dir build -C Release --output-on-failure
./build/diffusion_cli --method crank-nicolson --profile step --ratio 0.5 --cells 64 --steps 128 --output profile.csv
./build/diffusion_cli --method crank-nicolson --steps 128 --probe 4 --output trace.csvWith Visual Studio on Windows, the executable is build\Release\diffusion_cli.exe. The first command-line example exports the final temperature profile. The second records the cell nearest
To regenerate and serve the web dataset locally, run the following commands from the repository root.
./build/diffusion_cli --gallery docs/data/profiles.json
python -m http.server 8000 --directory docsThe local viewer is available at http://localhost:8000. The project figure is generated from the same dataset with Matplotlib. Figure script
