Diffusion in multi-dimensions

Diffusion in multi-dimensions#

Sometimes it can be useful to mix explicit and implicit methods. In 1D, the Crank-Nicholson method is

\[T^{n+1}_i-T^n_i = \alpha\left[{1\over 2}\left(T^{n+1}_{i-1} -2 T^{n+1}_i + T^{n+1}_{i+1}\right) + {1\over 2}\left(T^n_{i-1} -2 T^n_i + T^n_{i+1}\right)\right]\]

where on the right-hand side we take the average of the explicit and implicit updates. This method is described as semi-implicit. Also stable for any \(\Delta t\), the advantage of Crank-Nicholson over the fully-implicit method is that it is second order in time instead of first order.

The alternating-direction implicit scheme is a way to solve the 2D diffusion equation

\[{\partial T\over \partial t} = {\partial^2 T\over \partial x^2} + {\partial^2 T\over \partial y^2}.\]

The idea is to split the update into two half timesteps:

\[T^{n+1/2}_{i,j} = T^n_{i,j} + {\alpha\over 2}\left(T^{n+1/2}_{i-1,j} -2T^{n+1/2}_{i,j} + T^{n+1/2}_{i+1,j} + T^n_{i,j-1} -2T^n_{i,j} + T^n_{i,j+1}\right)\]
\[T^{n+1}_{i,j} = T^{n+1/2}_{i,j} + {\alpha\over 2}\left(T^{n+1/2}_{i-1,j} -2T^{n+1/2}_{i,j} + T^{n+1/2}_{i+1,j} + T^{n+1}_{i,j-1} -2T^{n+1}_{i,j} + T^{n+1}_{i,j+1}\right)\]

In the first step we treat the \(x\)-direction update implicitly and the \(y\)-direction explicitly, and then alternate for the second step.

Exercise: 2D diffusion

Implement this scheme to solve for the time evolution of the temperature profile in a 2D square box that is at \(T=0\) initially. One side of the box is held at \(T=1\) for \(t>0\), the other sides are kept at \(T=0\).

[Solution]