Diffusion Equation with a Discontinuity

Q: I would like to solve the following standard diffusion equation:

[Graphics:inoutbgr2.gif][Graphics:inoutbgr15.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr16.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr17.gif]

This equation has an analytical solution, even though the initial and boundary conditions have a discontinuinity. How can I modify the input so [Graphics:inoutbgr18.gif] can solve the equation ?

Robert Knapp (rknapp@wolfram.com) suggests changing the initial condition from [Graphics:inoutbgr19.gif] to [Graphics:inoutbgr20.gif].

[Graphics:inoutbgr2.gif][Graphics:inoutbgr21.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr22.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr23.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr24.gif]

[Graphics:inoutbgr2.gif][Graphics:inoutbgr25.gif]

The discretization used in the [Graphics:inoutbgr26.gif]-direction uses finite difference formulas. Such formulas typically do poorly on discontinuities, so the result may not be correct. The [Graphics:inoutbgr27.gif] message means that the error estimate that Mathematica made did not satisfy the error tolerance in the default settings of the [Graphics:inoutbgr28.gif] and [Graphics:inoutbgr29.gif] options (the default [Graphics:inoutbgr30.gif] setting for these options gives 4 when [Graphics:inoutbgr31.gif] is set to [Graphics:inoutbgr32.gif]). Because of the discontinuity, this tolerance can never be satisfied, however many points you have.

However, for this problem, the given solution is probably reasonable because the diffusion tends to smooth out the discontinuity quickly. If the solution is not correct, it is because the finite differences were not able to catch the discontinuity well enough. One way to increase the number of grid points without swamping your computer's memory is to use an unevenly spaced grid.

[Graphics:inoutbgr2.gif][Graphics:inoutbgr33.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr34.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr35.gif]
[Graphics:inoutbgr2.gif][Graphics:inoutbgr36.gif]

[Graphics:inoutbgr2.gif][Graphics:inoutbgr37.gif]

This method has the advantage that the grid spacing is close where it needs to be. Also, the solution is around ten times faster than that using the uniform grid. However, the method is not without potential problems. First, highly irregular spacing can cause artifacts of the grid to show up in numerical solutions. Second, for some problems, the discontinuity may move, leaving the place where the grid is spaced most closely. The method does not yet have adaptive gridding, though that is a future possibility. Third, when you specify the grid, Mathematica does not check that it is fine enough to meet the [Graphics:inoutbgr38.gif] and [Graphics:inoutbgr39.gif] specified.