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) on x∈[0,1], with centred differences in space and forward Euler in time at Δt=0.4Δx2, so that Δt/Δx2=0.4 on every grid, inside the stability limit 1/2. It starts from, and takes Dirichlet data at both ends from, a manufactured solution u~(x,t)=e−tsin(πx).
((a)) Find the source term S(x,t) (by differentiating u~) that makes u~ an exact solution of the equation at every x and t, and evaluate S at x=0.5, t=0.
((b)) Running the code to tf=0.05 on grids N=20,40,80,160 (so Δx=1/N) gives maximum errors 1.21×10−2, 1.16×10−2, 1.15×10−2, 1.15×10−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), before the time loop starts, and reused at every step, instead of being rebuilt from S(x,tn) at each step n. Apply the chapter's debugging method. First reduce: the plateau is already present on the coarsest grid, so work at N=20 from here on. Then test the hypothesis twice. (i) The mismatch S(0.5,t)−S(0.5,0) grows roughly linearly from zero, so estimate the error it accumulates by tf as 21∣S(0.5,tf)−S(0.5,0)∣tf, and compare it with the N=20 error. (ii) The frozen source predicts that halving the run length cuts the error by about a factor of 4, 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 2. The N=20 run to tf=0.025 gives a maximum error of 3.54×10−3. Compute the ratio of the two N=20 errors and say which prediction it supports.
((c)) The frozen-source line is fixed so that S(x,tn) is rebuilt every step. Rerunning the order-of-accuracy study confirms the formal order 2 is recovered, with a maximum error of 1.13×10−5 at N=160, tf=0.05. Using a safety factor of 3 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.