HEAD | PREVIOUS |

Diffusion. Parabolic Partial Differential Equations

$\frac{\partial \mathit{\psi}}{\partial t}=\nabla .(D\nabla \mathit{\psi})+s,$ | $(5.1)$ |

Figure 5.1: Solving a diffusion problem generally requires a
combination of spatial boundary conditions and temporal initial
condition. Then the solution is propagated upward (forward in
time), to fill in the multi-dimensional (time and space) solution
domain.

Consequently, boundary conditions
are not applied all around a closed contour (in the $x$-$t$ plane) but
generally only at the two ends of the spatial range, and at one
"initial" time, as illustrated in Fig. 5.1. The
dependent variable solution is propagated from the initial condition
forward in time (conventionally drawn as the vertical direction).
$\frac{{\mathit{\psi}}_{j}^{(n+1)}-{\mathit{\psi}}_{j}^{(n)}}{\mathit{\Delta}t}=D\frac{{\mathit{\psi}}_{j+1}^{(n)}-2{\mathit{\psi}}_{j}^{(n)}+{\mathit{\psi}}_{j-1}^{(n)}}{\mathit{\Delta}{x}^{2}}+{s}_{j}^{(n)}.$ | $(5.2)$ |

Figure 5.2: Forward Time, Centered Space, (FTCS) difference scheme.

We immediately know from our previous experience that, because it is
not centered in time, this scheme's accuracy is going to be only first
order in $\mathit{\Delta}t$. Also, this scheme is
${\mathit{\psi}}_{j}^{(n+1)}={\mathit{\psi}}_{j}^{(n)}+\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}({\mathit{\psi}}_{j+1}^{(n)}-2{\mathit{\psi}}_{j}^{(n)}+{\mathit{\psi}}_{j-1}^{(n)})+\mathit{\Delta}t\mathrm{\hspace{0.5em}\hspace{0.5em}}{s}_{j}^{(n)}.$ | $(5.3)$ |

${\mathit{\psi}}_{j+1}-2{\mathit{\psi}}_{j}+{\mathit{\psi}}_{j-1}=({e}^{{\mathit{ik}}_{x}\mathit{\Delta}x}-2+{e}^{-{\mathit{ik}}_{x}\mathit{\Delta}x}){\mathit{\psi}}_{j}=-4{\mathrm{sin}}^{2}(\frac{{k}_{x}\mathit{\Delta}x}{2}){\mathit{\psi}}_{j}.$ | $(5.4)$ |

${\mathit{\psi}}^{(n+1)}=\underset{\mathrm{Amplification}\hspace{0.5em}\mathrm{factor}}{\underset{\u23df}{[1-\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}4{\mathrm{sin}}^{2}(\frac{{k}_{x}\mathit{\Delta}x}{2})]}}{\mathit{\psi}}^{(n)}.$ | $(5.5)$ |

$\frac{4D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}<2.$ | $(5.6)$ |

${\mathit{\psi}}_{j}^{(n+1)}={\mathit{\psi}}_{j}^{(n)}+\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}({\mathit{\psi}}_{j+1}^{(n+1)}-2{\mathit{\psi}}_{j}^{(n+1)}+{\mathit{\psi}}_{j-1}^{(n+1)})+\mathit{\Delta}t\mathrm{\hspace{0.5em}\hspace{0.5em}}{s}_{j}^{(n+1)};$ | $(5.7)$ |

$\underset{\mathrm{Inverse}\hspace{0.5em}\mathrm{of}\hspace{0.5em}\mathrm{Amplification}\hspace{0.5em}\mathrm{factor}}{\underset{\u23df}{[1+\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}4{\mathrm{sin}}^{2}(\frac{{k}_{x}\mathit{\Delta}x}{2})]}}{\mathit{\psi}}^{(n+1)}={\mathit{\psi}}^{(n)}.$ | $(5.8)$ |

$\begin{array}{ccc}\multicolumn{1}{c}{{\mathit{\psi}}_{j}^{(n+1)}={\mathit{\psi}}_{j}^{(n)}}& +\hfill & \mathit{\theta}[\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}({\mathit{\psi}}_{j+1}^{(n+1)}-2{\mathit{\psi}}_{j}^{(n+1)}+{\mathit{\psi}}_{j-1}^{(n+1)})+\mathit{\Delta}t\hspace{0.5em}{s}_{j}^{(n+1)}]\hfill \\ \multicolumn{1}{c}{}& +\hfill & (1-\mathit{\theta})[\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}({\mathit{\psi}}_{j+1}^{(n)}-2{\mathit{\psi}}_{j}^{(n)}+{\mathit{\psi}}_{j-1}^{(n)})+\mathit{\Delta}t\hspace{0.5em}{s}_{j}^{(n)}].\hfill & \hfill \hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}(5.9)\end{array}$ |

This is sometimes called the "$\mathit{\theta}$-implicit" scheme. The amplification factor is straightforwardly

$A=\frac{1-(1-\mathit{\theta})\frac{4D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}{\mathrm{sin}}^{2}(\frac{{k}_{x}\mathit{\Delta}x}{2})}{1+\mathit{\theta}\frac{4D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}{\mathrm{sin}}^{2}(\frac{{k}_{x}\mathit{\Delta}x}{2})}.$ | $(5.10)$ |

$\mathit{\Delta}t<\frac{\mathit{\Delta}{x}^{2}}{2D(1-2\mathit{\theta})}.$ | $(5.11)$ |

$\left(\begin{array}{ccccc}\hfill \ddots \hfill & \hfill \ddots \hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill \\ \hfill \ddots \hfill & \hfill \ddots \hfill & \hfill \ddots \hfill & \hfill 0\hfill & \hfill 0\hfill \\ \hfill 0\hfill & \hfill {B}_{-}\hfill & \hfill {B}_{0}\hfill & \hfill {B}_{+}\hfill & \hfill 0\hfill \\ \hfill 0\hfill & \hfill 0\hfill & \hfill \ddots \hfill & \hfill \ddots \hfill & \hfill \ddots \hfill \\ \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill \ddots \hfill & \hfill \ddots \hfill \end{array}\right)\left(\begin{array}{c}\hfill {\mathit{\psi}}_{1}^{(n+1)}\hfill \\ \hfill :\hfill \\ \hfill {\mathit{\psi}}_{j}^{(n+1)}\hfill \\ \hfill :\hfill \\ \hfill {\mathit{\psi}}_{J}^{(n+1)}\hfill \end{array}\right)=\left(\begin{array}{ccccc}\hfill \ddots \hfill & \hfill \ddots \hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill \\ \hfill \ddots \hfill & \hfill \ddots \hfill & \hfill \ddots \hfill & \hfill 0\hfill & \hfill 0\hfill \\ \hfill 0\hfill & \hfill {C}_{-}\hfill & \hfill {C}_{0}\hfill & \hfill {C}_{+}\hfill & \hfill 0\hfill \\ \hfill 0\hfill & \hfill 0\hfill & \hfill \ddots \hfill & \hfill \ddots \hfill & \hfill \ddots \hfill \\ \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill \ddots \hfill & \hfill \ddots \hfill \end{array}\right)\left(\begin{array}{c}\hfill {\mathit{\psi}}_{1}^{(n)}\hfill \\ \hfill :\hfill \\ \hfill {\mathit{\psi}}_{j}^{(n)}\hfill \\ \hfill :\hfill \\ \hfill {\mathit{\psi}}_{J}^{(n)}\hfill \end{array}\right)+\left(\begin{array}{c}\hfill {s}_{1}\hfill \\ \hfill :\hfill \\ \hfill {s}_{j}\hfill \\ \hfill :\hfill \\ \hfill {s}_{J}\hfill \end{array}\right)$ | $(5.12)$ |

$\mathbf{B}{\mathit{\psi}}_{n+1}=\mathbf{C}{\mathit{\psi}}_{n}+\mathbf{s},$ | $(5.13)$ |

${B}_{0}=1+2\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}\mathit{\theta},\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}}{B}_{+}={B}_{-}=-\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}\mathit{\theta},$ | $(5.14)$ |

${C}_{0}=1-2\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}(1-\mathit{\theta}),\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}}{C}_{+}={C}_{-}=+\frac{D\mathit{\Delta}t}{\mathit{\Delta}{x}^{2}}(1-\mathit{\theta}),$ | $(5.15)$ |

$\mathrm{and}\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}{s}_{j}=\mathit{\Delta}t[\mathit{\theta}{s}_{j}^{(n+1)}+(1-\mathit{\theta}){s}_{j}^{(n)}].$ | $(5.16)$ |

${\mathit{\psi}}_{n+1}={\mathbf{B}}^{-1}\mathbf{C}{\mathit{\psi}}_{n}+{\mathbf{B}}^{-1}\mathbf{s}.$ | $(5.17)$ |

Figure 5.4: Example solution, at a particular time, of a diffusion
equation in two space dimensions. The value of $\mathit{\psi}$ is
visualized in this perspective plot as the height of the
surface.

When there is more than one spatial coordinate dimension, as
illustrated in Fig. 5.4, nothing
changes formally about our method of solution of parabolic equations.
What changes, however, is that we need a systematic way to turn the
entire spatial mesh in multiple
dimensions
into a column vector like
those in eq. (5.12). In other words, we must index
all the spatial positions with a single index $j$. But generally if we
have multiple dimensions, the natural (physical) indexing of the
elements of the mesh is by a number of multiple indices equal to the
number of dimensions: e.g. ${\mathit{\psi}}_{k,l,m}$, where $k$, $l$,
$m$ correspond to the coordinates $x$, $y$, $z$.
Reordering the mesh elements is not
a particularly difficult task algebraically, but it requires an
intuitively tricky geometrical mental shift. In general, if we have a
quantity ${\mathit{\psi}}_{k,l,...}$ indexed on a multidimensional mesh whose
lengths in the different mesh dimensions are $K$, $L$, ... then we
re-index them into a single index $j$ as follows. Start with all
indices equal to 1. Count through the first index, $k=1,...,K$. Then
increment the second index $l$ and repeat $k=1,...,K$. Continue this
process for $l=1,...,L$. Then increment the next index (if any), and
continue till all indices are exhausted. Incidentally, this is
precisely the order in which the elements are
stored in computer memory when using a
language like Fortran when using the entire
allocated array.
Figure 5.5: Conversion of a two-dimensional array into a single column
vector using column order is like stacking all the columns below
one another.

The result is that for the giant column vector ${\mathit{\psi}}_{j}$, the first $K$
elements are the original multidimensionally indexed elements
${\mathit{\psi}}_{k,1,...},\hspace{0.5em}k=1,...,K$; the next $K$ elements, $j=K+1,...,2K$,
are the original ${\mathit{\psi}}_{k,2,...}$ and so on.${}^{31}$
In multiple dimensions, the second derivative operator (something like
${\nabla}^{2}$) is represented by a stencil, as illustrated
in eq. (4.23). The importance of the reordering of the
elements into a column vector is that although the components of the
stencil that are adjacent in the first index ($k$) remain adjacent in
$j$, those in the other index(es) ($l$) do not. For example the
elements ${\mathit{\psi}}_{k,l}$ and ${\mathit{\psi}}_{k,l+1}$ have $j$-indices
$j=K.(l-1)+k$ and $j=K.l+k$ respectively; they are a distance $K$
apart. This fact means that for multiple spatial dimensions the
matrices $\mathbf{B}$ and $\mathbf{C}$ are no longer simply
tridiagonal. Instead, they have an additional non-zero diagonal, a
distance $K$ from the main diagonal. If the boundary conditions are
$\mathit{\psi}=0$, each matrix is
"Block-Tridiagonal",
having a form like this:
$L\hspace{0.5em}\mathrm{blocks}\left\{\left[\begin{array}{ccccc}\hfill \begin{array}{ccccc}\hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill a\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \hfill & \hfill \hfill & \hfill \}\begin{array}{c}\hfill \mathrm{Block}\hfill \\ \hfill \mathrm{size}\hfill \\ \hfill K\hfill \\ \hfill \hfill \end{array}\hfill \\ \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill a\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill a\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill a\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \begin{array}{ccccc}\hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill a\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill a\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill \end{array}\right]\right\}J=K\times L\hspace{0.5em}\text{rows}.$ | $(5.18)$ |

${\nabla}^{2}\mathit{\psi}=\frac{1}{{r}^{2}}\frac{\partial}{\partial r}\left({r}^{2}\frac{\partial \mathit{\psi}}{\partial r}\right)+\frac{1}{{r}^{2}}\frac{{\partial}^{2}\mathit{\psi}}{\partial {\mathit{\phi}}^{2}}=\frac{\partial \mathit{\psi}}{\partial t}.$ | $(5.19)$ |

Let $k$ and $l$ be indices in the $r$ and $\mathit{\phi}$ coordinates, and let $\mathit{\Delta}r$ and $\mathit{\Delta}\mathit{\phi}$ denote their grid spacings. The finite difference form of the spatial derivative terms is

$\begin{array}{ccc}\multicolumn{1}{c}{\frac{1}{{r}^{2}}\frac{\partial}{\partial r}{\left({r}^{2}\frac{\partial \mathit{\psi}}{\partial r}\right)}_{k,l}}& =\hfill & \frac{1}{{r}_{k}^{2}}({r}_{k+1/2}^{2}\frac{{\mathit{\psi}}_{k+1,l}-{\mathit{\psi}}_{k,l}}{{r}_{k+1}-{r}_{k}}-{r}_{k-1/2}^{2}\frac{{\mathit{\psi}}_{k,l}-{\mathit{\psi}}_{k-1,l}}{{r}_{k}-{r}_{k-1}})\frac{1}{{r}_{k+1/2}-{r}_{k-1/2}}\hfill \\ \multicolumn{1}{c}{}& =\hfill & [{\left(\frac{{r}_{k}+\frac{\mathit{\Delta}r}{2}}{{r}_{k}}\right)}^{2}({\mathit{\psi}}_{k+1,l}-{\mathit{\psi}}_{k,l})-{\left(\frac{{r}_{k}-\frac{\mathit{\Delta}r}{2}}{{r}_{k}}\right)}^{2}({\mathit{\psi}}_{k,l}-{\mathit{\psi}}_{k-1,l})]\frac{1}{\mathit{\Delta}{r}^{2}}\hfill \\ \multicolumn{1}{c}{}& =\hfill & [{(1+\frac{\mathit{\Delta}r}{2{r}_{k}})}^{2}{\mathit{\psi}}_{k+1,l}-(2+\frac{\mathit{\Delta}{r}^{2}}{2{r}_{k}^{2}}){\mathit{\psi}}_{k,l}+{(1-\frac{\mathit{\Delta}r}{2{r}_{k}})}^{2}{\mathit{\psi}}_{k-1,l}]\frac{1}{\mathit{\Delta}{r}^{2}}\hfill \\ \multicolumn{1}{c}{{\frac{1}{{r}^{2}}\frac{{\partial}^{2}\mathit{\psi}}{\partial {\mathit{\theta}}^{2}}|}_{k,l}}& =\hfill & \frac{1}{{r}_{k}^{2}}(\frac{{\mathit{\psi}}_{k,l+1}-{\mathit{\psi}}_{k,l}}{{\mathit{\theta}}_{l+1}-{\mathit{\theta}}_{l}}-\frac{{\mathit{\psi}}_{k,l}-{\mathit{\psi}}_{k,l-1}}{{\mathit{\theta}}_{l}-{\mathit{\theta}}_{l-1}})\frac{1}{{\mathit{\theta}}_{l+1/2}-{\mathit{\theta}}_{l-1/2}}\hfill \\ \multicolumn{1}{c}{}& =\hfill & ({\mathit{\psi}}_{k,l+1}-2{\mathit{\psi}}_{k,l}+{\mathit{\psi}}_{k,l-1})\frac{1}{{r}_{k}^{2}\mathit{\Delta}{\mathit{\theta}}^{2}}.\hfill & \hfill \hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}(5.20)\end{array}$ |

Therefore, expressing the positions across the spatial grid in terms of a single index $j=k+K.(l-1)$ (where $K$ is the size of the $k$-grid, and $L$ of the $l$-grid), the differential operator ${\nabla}^{2}$ becomes a matrix $\mathbf{M}$ multiplying the vector $\mathit{\psi}={\mathit{\psi}}_{j}$, of the form

$\mathbf{M}=\left[\begin{array}{ccccc}\hfill \begin{array}{ccccc}\hfill f\hfill & \hfill e\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill b\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill b\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \hfill & \hfill \hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill \\ \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill f\hfill & \hfill e\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill b\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill b\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \hfill & \hfill \}\begin{array}{c}\hfill \mathrm{Block}\hfill \\ \hfill \mathrm{size}\hfill \\ \hfill K\hfill \\ \hfill \hfill \end{array}\hfill \\ \hfill \hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill f\hfill & \hfill e\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill b\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill b\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill f\hfill & \hfill e\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill b\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill b\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill \\ \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \hfill & \hfill \hfill & \hfill \begin{array}{ccccc}\hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill d\hfill \end{array}\hfill & \hfill \begin{array}{ccccc}\hfill f\hfill & \hfill e\hfill & \hfill \hfill & \hfill \hfill & \hfill \hfill \\ \hfill a\hfill & \hfill c\hfill & \hfill b\hfill & \hfill \hfill & \hfill \hfill \\ \hfill \hfill & \hfill .\hfill & \hfill .\hfill & \hfill .\hfill & \hfill \hfill \\ \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill & \hfill b\hfill \\ \hfill \hfill & \hfill \hfill & \hfill \hfill & \hfill a\hfill & \hfill c\hfill \end{array}\hfill \end{array}\right]\}\text{L blocks}.$ | $(5.21)$ |

$a={(1-\frac{\mathit{\Delta}r}{2{r}_{k}})}^{2}\frac{1}{\mathit{\Delta}{r}^{2}},\hspace{1em}b={(1+\frac{\mathit{\Delta}r}{2{r}_{k}})}^{2}\frac{1}{\mathit{\Delta}{r}^{2}},\hspace{1em}d=\frac{1}{{r}_{k}^{2}\mathit{\Delta}{\mathit{\phi}}^{2}},\hspace{1em}c=-(a+b+2d).$ | $(5.22)$ |

${\mathit{\psi}}^{(n+1)}-{\mathit{\psi}}^{(n)}=\frac{\mathit{\Delta}t}{2}\mathbf{M}{\mathit{\psi}}^{(n+1)}+\frac{\mathit{\Delta}t}{2}\mathbf{M}{\mathit{\psi}}^{(n)},$ | $(5.23)$ |

${\mathit{\psi}}^{(n+1)}=(\mathbf{I}-\frac{\mathit{\Delta}t}{2}\mathbf{M}{)}^{-1}(\mathbf{I}+\frac{\mathit{\Delta}t}{2}\mathbf{M}){\mathit{\psi}}^{(n)}.$ | $(5.24)$ |

1. Write a computer code to solve the diffusive equation

$\frac{\partial \mathit{\psi}}{\partial t}=D\frac{{\partial}^{2}\mathit{\psi}}{\partial {x}^{2}}+s(x)$ |

For constant, uniform diffusivity $D$ and constant specified source $s(x)$. Use a uniform $x$-mesh with ${N}_{x}$ nodes. Consider boundary conditions to be $\mathit{\psi}$ fixed, equal to ${\mathit{\psi}}_{1}$, ${\mathit{\psi}}_{2}$ at the domain boundaries, $x=-1,1$, and the initial condition to be $\mathit{\psi}=0$ at $t=0$. Construct a matrix $\mathbf{G}={G}_{\mathit{ij}}$ such that $\mathbf{G}\mathit{\psi}={\nabla}^{2}\mathit{\psi}$. Use it to implement the FTCS scheme

${\mathit{\psi}}^{(n+1)}=(\mathbf{I}+\mathit{\Delta}t\mathbf{G}){\mathit{\psi}}^{(n)}+\mathit{\Delta}t\hspace{0.5em}\mathbf{s},$ |

paying special attention to the boundary conditions. Solve the time-dependent problem for $D=1$, $s=1$, ${N}_{x}=30$, ${\mathit{\psi}}_{1}={\mathit{\psi}}_{2}=0$, $t=0\to 1$, storing your results in a matrix $\mathit{\psi}(x,t)={\mathit{\psi}}_{{j}_{x},{j}_{t}}$, and plotting that matrix at the end of the solution, for examination. Experiment with various $\mathit{\Delta}t$ to establish the dependence of the accuracy and stability of your solution on $\mathit{\Delta}t$. In particular,

2. Develop a modified version of your code to implement the $\mathit{\theta}$-implicit scheme:

$(\mathbf{I}-\mathit{\Delta}t\mathit{\theta}\mathbf{G}){\mathit{\psi}}^{(n+1)}=(\mathbf{I}+\mathit{\Delta}t(1-\mathit{\theta})\mathbf{G}){\mathit{\psi}}^{(n)}+\mathit{\Delta}t\hspace{0.5em}s,$ |

in the form

${\mathit{\psi}}^{(n+1)}={\mathbf{B}}^{-1}\mathbf{C}{\mathit{\psi}}^{(n)}+{\mathbf{B}}^{-1}\mathit{\Delta}t\mathrm{\hspace{0.5em}\hspace{0.5em}}s$ |

(i) Experiment with different $\mathit{\Delta}t$ and $\mathit{\theta}$ values, for the same time-dependent problem and find experimentally the value of $\mathit{\theta}$ for which instability disappears for all $\mathit{\Delta}t$. (ii) Suppose we are limited to only 50 timesteps to solve over the time $0<t\le 1$ so $\mathit{\Delta}t=0.02$. Find experimentally the optimum value of $\mathit{\theta}$ which produces the most accurate results.

Submit the following as your solution for each part:

- Your code in a computer format that is capable of being executed, citing the language it is written in.
- The requested experimental $\mathit{\Delta}t$ and/or $\mathit{\theta}$ values.
- A plot of your solution for at least one of the cases.
- A brief description of how you determined the accuracy of the result.

HEAD | NEXT |