An explicit diffusion code solves on with

PHYSICS · Multi-part · Fermi University Physics · Mathematical Methods for Physics · Computational Physics · Research software practice, verification and validation

Scientific Computing for Physicists, Ch Is the equation solved right? Testing, debugging and code verification

Problem

An explicit diffusion code solves ∂tu=D∂x2u\partial_t u = D\partial_x^2 u on [0,1][0,1] with D=0.5 m2 s−1D=0.5\,\mathrm{m^2\,s^{-1}}, diffusion number α=DΔt/Δx2=0.4\alpha=D\Delta t/\Delta x^2=0.4 held fixed, and zero-flux (insulating) boundaries at both ends imposed with mirror ghost nodes. It starts from u(x,0)=1+cos⁡(πx)u(x,0)=1+\cos(\pi x) and runs to t=0.08 st=0.08\,\mathrm{s}; the exact solution u=1+e−Dπ2tcos⁡(πx)u=1+e^{-D\pi^2t}\cos(\pi x) has zero slope at both ends, so it satisfies the boundary conditions exactly. Maximum errors against it are measured as e(N=50)=1.23×10−4e(N{=}50)=1.23\times10^{-4} and e(N=100)=3.06×10−5e(N{=}100)=3.06\times10^{-5}, where NN is the number of grid intervals. ((a)) Using the two measured errors and the fact that this scheme's error scales as Δx2∝N−2\Delta x^2 \propto N^{-2}, predict the maximum error at N=200N=200. A unit test at N=200N=200 compares the computed field with the exact solution; set its tolerance at twice the prediction, and say whether a measured error of 7.66×10−67.66\times10^{-6} passes it. ((b)) Because the boundaries are insulating, ∫01u dx\int_0^1 u\,\mathrm{d}x is conserved exactly in time. A property test integrates uu with the trapezium rule on the N+1=401N+1=401 grid points at N=400N=400 and checks this integral against its initial value to relative tolerance 10(N+1)ϵmach/210(N{+}1)\epsilon_{\rm mach}/2, with ϵmach=2−52\epsilon_{\rm mach}=2^{-52}. Compute the tolerance, and say whether a measured relative change of 4.4×10−164.4\times10^{-16} passes it. ((c)) Errors are also measured at N=200N=200 and N=400N=400: e(200)=7.66×10−6e(200)=7.66\times10^{-6} and e(400)=1.91×10−6e(400)=1.91\times10^{-6}. Using all four grids N=50,100,200,400N=50,100,200,400, compute the observed order p^\hat{p} from each consecutive pair via p^=ln⁡[e(N)/e(2N)]/ln⁡2\hat{p}=\ln[e(N)/e(2N)]/\ln2, and say whether the code is verified against the formal order pformal=2p_{\rm formal}=2.

Browse the problem library