A solver for a nonlinear reaction-diffusion equation is written for on

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

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

Problem

A solver for a nonlinear reaction-diffusion equation is written for ∂tu=∂x2u−u3+S(x,t)\partial_t u = \partial_x^2 u - u^3 + S(x,t) on x∈[0,1]x\in[0,1], with centred differences in space and forward Euler in time at Δt=0.4 Δx2\Delta t = 0.4\,\Delta x^2, so that Δt/Δx2=0.4\Delta t/\Delta x^2 = 0.4 on every grid, inside the stability limit 1/21/2. It starts from, and takes Dirichlet data at both ends from, a manufactured solution u~(x,t)=e−tsin⁡(πx)\tilde{u}(x,t) = e^{-t}\sin(\pi x). ((a)) Find the source term S(x,t)S(x,t) (by differentiating u~\tilde{u}) that makes u~\tilde{u} an exact solution of the equation at every xx and tt, and evaluate SS at x=0.5x=0.5, t=0t=0. ((b)) Running the code to tf=0.05t_f = 0.05 on grids N=20,40,80,160N = 20, 40, 80, 160 (so Δx=1/N\Delta x = 1/N) gives maximum errors 1.21×10−21.21\times10^{-2}, 1.16×10−21.16\times10^{-2}, 1.15×10−21.15\times10^{-2}, 1.15×10−21.15\times10^{-2}: the error stops shrinking as the grid is refined. Inspection of the code shows the source array is built once, from S(x,0)S(x,0), before the time loop starts, and reused at every step, instead of being rebuilt from S(x,tn)S(x,t^n) at each step nn. Apply the chapter's debugging method. First reduce: the plateau is already present on the coarsest grid, so work at N=20N=20 from here on. Then test the hypothesis twice. (i) The mismatch S(0.5,t)−S(0.5,0)S(0.5,t)-S(0.5,0) grows roughly linearly from zero, so estimate the error it accumulates by tft_f as 12∣S(0.5,tf)−S(0.5,0)∣ tf\tfrac12|S(0.5,t_f)-S(0.5,0)|\,t_f, and compare it with the N=20N=20 error. (ii) The frozen source predicts that halving the run length cuts the error by about a factor of 44, whereas a fault in a time-independent part of the scheme, such as a wrong coefficient in the spatial operator, adds a roughly constant forcing from the first step and predicts a factor of about 22. The N=20N=20 run to tf=0.025t_f=0.025 gives a maximum error of 3.54×10−33.54\times10^{-3}. Compute the ratio of the two N=20N=20 errors and say which prediction it supports. ((c)) The frozen-source line is fixed so that S(x,tn)S(x,t^n) is rebuilt every step. Rerunning the order-of-accuracy study confirms the formal order 22 is recovered, with a maximum error of 1.13×10−51.13\times10^{-5} at N=160N=160, tf=0.05t_f=0.05. Using a safety factor of 33 on this baseline error as a chosen (not derived) pass/fail margin, state the numeric tolerance for a regression test asserting that this configuration's error has not grown, and describe where that test is run so the bug cannot return unnoticed.

Browse the problem library