The one-dimensional diffusion equation with a heat source,

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 A repository others can build on: collaboration, history and workflows

Problem

The one-dimensional diffusion equation with a heat source, ∂tu=D∂x2u+S(x,t)\partial_t u = D\partial_x^2 u + S(x,t), is discretised as uin+1=uin+α(ui+1n−2uin+ui−1n)+Δt Sin,u_i^{n+1} = u_i^n + \alpha\left(u_{i+1}^n - 2u_i^n + u_{i-1}^n\right) + \Delta t\,S_i^n, with α=DΔt/Δx2\alpha=D\Delta t/\Delta x^2. A localised heater at x=x0x=x_0 is modelled by Sin=+QS_i^n=+Q with Q>0Q>0 there and zero elsewhere, meaning uu should increase at x0x_0. A reviewed and merged change rewrites the last term as −Δt Sin-\Delta t\,S_i^n, leaving Sin=+QS_i^n=+Q unchanged in the calling code, so the "heater" now cools rather than heats. The repository's existing known-answer test initialises uu as a Gaussian pulse with S≡0S\equiv0 everywhere (pure diffusion, no source) and checks the pulse width against the analytic solution; it passes unchanged before and after the merge. ((a)) Explain why the existing test cannot detect the sign error. ((b)) Using the review checklist (the physical claim of the change, and whether a test would fail if it were reverted), state what a reviewer should have asked before approving this change. ((c)) Describe a test, with S≠0S\ne0, that fails for the buggy code and passes for the corrected code.

Browse the problem library