Dopant diffusion along a silicon nanowire is modelled with the explicit…
PHYSICS · Multi-part · Fermi University Physics · Computational Physics · Scientific programming for physicists · Scientific programming for physicists
Scientific Computing for Physicists, Ch Arrays in memory: layout, cost and the data structures of physical problems
Problem
Dopant diffusion along a silicon nanowire is modelled with the explicit one-dimensional scheme from the first course, uin+1=uin+α(ui+1n−2uin+ui−1n), on a grid of 1001 points with spacing Δx=2×10−9m, using a solid-state diffusion coefficient D=5×10−14m2s−1 and time step Δt=2×10−5s. To study run-to-run variation, M=50 independent realisations (different random initial fluctuations) are advanced together and stored as an array U of shape (1001,50), dtype float64 (8 bytes per element), with the space index as axis 0 and the realisation index as axis 1. Because the stencil sweeps along the space axis for every realisation at each step, U is stored in Fortran order (column-major), so that axis 0 is contiguous.
((a)) Compute the diffusion number α=DΔt/Δx2 and state, quoting the stability limit for the explicit scheme in one dimension, whether this run is stable.
((b)) Give the strides (in bytes) of U in this Fortran-order layout, and say which of the two natural traversals, fixed realisation with varying space index, or fixed space index with varying realisation, is contiguous.
((c)) A first draft advances the ensemble with a Python loop over realisations, for k in range(50): U[1:-1,k] = U[1:-1,k] + alpha*(U[2:,k] - 2*U[1:-1,k] + U[:-2,k]), repeated for 20000 time steps, allocating a new temporary array at every inner iteration. Rewrite the update to operate on all 50 realisations at once with no array allocated inside the time loop, and state which cost of the calculation this rewrite leaves unchanged.