### Diffusion Equation with a Discontinuity

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

`  `
`  `
`  `

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

Robert Knapp (rknapp@wolfram.com) suggests changing the initial condition from to .

`  `
`  `
`  `
`  `  The discretization used in the -direction uses finite difference formulas. Such formulas typically do poorly on discontinuities, so the result may not be correct. The message means that the error estimate that Mathematica made did not satisfy the error tolerance in the default settings of the and options (the default setting for these options gives 4 when is set to ). 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.

`  `
`  `
`  `
`  `  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 and specified.