HEAD | PREVIOUS |

Diffusion. Parabolic Partial Differential Equations

$\frac{\partial \psi}{\partial t}=\nabla .(D\nabla \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{{\psi}_{j}^{(n+1)}-{\psi}_{j}^{(n)}}{\Delta t}=D\frac{{\psi}_{j+1}^{(n)}-2{\psi}_{j}^{(n)}+{\psi}_{j-1}^{(n)}}{\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 $\Delta t$. Also, this scheme is
${\psi}_{j}^{(n+1)}={\psi}_{j}^{(n)}+\frac{D\Delta t}{\Delta {x}^{2}}({\psi}_{j+1}^{(n)}-2{\psi}_{j}^{(n)}+{\psi}_{j-1}^{(n)})+\Delta t\mathrm{\hspace{0.5em}\hspace{0.5em}}{s}_{j}^{(n)}.$ | $(5.3)$ |

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

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

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

${\psi}_{j}^{(n+1)}={\psi}_{j}^{(n)}+\frac{D\Delta t}{\Delta {x}^{2}}({\psi}_{j+1}^{(n+1)}-2{\psi}_{j}^{(n+1)}+{\psi}_{j-1}^{(n+1)})+\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\Delta t}{\Delta {x}^{2}}4{\mathrm{sin}}^{2}(\frac{{k}_{x}\Delta x}{2})]}}{\psi}^{(n+1)}={\psi}^{(n)}.$ | $(5.8)$ |

$\begin{array}{ccc}\multicolumn{1}{c}{{\psi}_{j}^{(n+1)}={\psi}_{j}^{(n)}}& +\hfill & \theta [\frac{D\Delta t}{\Delta {x}^{2}}({\psi}_{j+1}^{(n+1)}-2{\psi}_{j}^{(n+1)}+{\psi}_{j-1}^{(n+1)})+\Delta t\hspace{0.5em}{s}_{j}^{(n+1)}]\hfill \\ \multicolumn{1}{c}{}& +\hfill & (1-\theta )[\frac{D\Delta t}{\Delta {x}^{2}}({\psi}_{j+1}^{(n)}-2{\psi}_{j}^{(n)}+{\psi}_{j-1}^{(n)})+\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 "$\theta $-implicit" scheme. The amplification factor is straightforwardly

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

$\Delta t<\frac{\Delta {x}^{2}}{2D(1-2\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 {\psi}_{1}^{(n+1)}\hfill \\ \hfill :\hfill \\ \hfill {\psi}_{j}^{(n+1)}\hfill \\ \hfill :\hfill \\ \hfill {\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 {\psi}_{1}^{(n)}\hfill \\ \hfill :\hfill \\ \hfill {\psi}_{j}^{(n)}\hfill \\ \hfill :\hfill \\ \hfill {\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\Delta t}{\Delta {x}^{2}}\theta ,\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}}{B}_{+}={B}_{-}=-\frac{D\Delta t}{\Delta {x}^{2}}\theta ,$ | $(5.14)$ |

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

$\mathrm{and}\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}{s}_{j}=\Delta t[\theta {s}_{j}^{(n+1)}+(1-\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 $\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. ${\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 ${\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 ${\psi}_{j}$, the first $K$
elements are the original multidimensionally indexed elements
${\psi}_{k,1,...},\hspace{0.5em}k=1,...,K$; the next $K$ elements, $j=K+1,...,2K$,
are the original ${\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 ${\psi}_{k,l}$ and ${\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
$\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}\psi =\frac{1}{{r}^{2}}\frac{\partial}{\partial r}\left({r}^{2}\frac{\partial \psi}{\partial r}\right)+\frac{1}{{r}^{2}}\frac{{\partial}^{2}\psi}{\partial {\phi}^{2}}=\frac{\partial \psi}{\partial t}.$ | $(5.19)$ |

Let $k$ and $l$ be indices in the $r$ and $\phi $ coordinates, and let $\Delta r$ and $\Delta \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 \psi}{\partial r}\right)}_{k,l}}& =\hfill & \frac{1}{{r}_{k}^{2}}({r}_{k+1/2}^{2}\frac{{\psi}_{k+1,l}-{\psi}_{k,l}}{{r}_{k+1}-{r}_{k}}-{r}_{k-1/2}^{2}\frac{{\psi}_{k,l}-{\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{\Delta r}{2}}{{r}_{k}}\right)}^{2}({\psi}_{k+1,l}-{\psi}_{k,l})-{\left(\frac{{r}_{k}-\frac{\Delta r}{2}}{{r}_{k}}\right)}^{2}({\psi}_{k,l}-{\psi}_{k-1,l})]\frac{1}{\Delta {r}^{2}}\hfill \\ \multicolumn{1}{c}{}& =\hfill & [{(1+\frac{\Delta r}{2{r}_{k}})}^{2}{\psi}_{k+1,l}-(2+\frac{\Delta {r}^{2}}{2{r}_{k}^{2}}){\psi}_{k,l}+{(1-\frac{\Delta r}{2{r}_{k}})}^{2}{\psi}_{k-1,l}]\frac{1}{\Delta {r}^{2}}\hfill \\ \multicolumn{1}{c}{{\frac{1}{{r}^{2}}\frac{{\partial}^{2}\psi}{\partial {\theta}^{2}}|}_{k,l}}& =\hfill & \frac{1}{{r}_{k}^{2}}(\frac{{\psi}_{k,l+1}-{\psi}_{k,l}}{{\theta}_{l+1}-{\theta}_{l}}-\frac{{\psi}_{k,l}-{\psi}_{k,l-1}}{{\theta}_{l}-{\theta}_{l-1}})\frac{1}{{\theta}_{l+1/2}-{\theta}_{l-1/2}}\hfill \\ \multicolumn{1}{c}{}& =\hfill & ({\psi}_{k,l+1}-2{\psi}_{k,l}+{\psi}_{k,l-1})\frac{1}{{r}_{k}^{2}\Delta {\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}={\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{\Delta r}{2{r}_{k}})}^{2}\frac{1}{\Delta {r}^{2}},\hspace{1em}b={(1+\frac{\Delta r}{2{r}_{k}})}^{2}\frac{1}{\Delta {r}^{2}},\hspace{1em}d=\frac{1}{{r}_{k}^{2}\Delta {\phi}^{2}},\hspace{1em}c=-(a+b+2d).$ | $(5.22)$ |

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

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

1. Write a computer code to solve the diffusive equation

$\frac{\partial \psi}{\partial t}=D\frac{{\partial}^{2}\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 $\psi $ fixed, equal to ${\psi}_{1}$, ${\psi}_{2}$ at the domain boundaries, $x=-1,1$, and the initial condition to be $\psi =0$ at $t=0$. Construct a matrix $\mathbf{G}={G}_{\mathrm{ij}}$ such that $\mathbf{G}\mathit{\psi}={\nabla}^{2}\mathit{\psi}$. Use it to implement the FTCS scheme

${\mathit{\psi}}^{(n+1)}=(\mathbf{I}+\Delta t\mathbf{G}){\mathit{\psi}}^{(n)}+\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$, ${\psi}_{1}={\psi}_{2}=0$, $t=0\to 1$, storing your results in a matrix $\psi (x,t)={\psi}_{{j}_{x},{j}_{t}}$, and plotting that matrix at the end of the solution, for examination. Experiment with various $\Delta t$ to establish the dependence of the accuracy and stability of your solution on $\Delta t$. In particular,

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

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

in the form

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

(i) Experiment with different $\Delta t$ and $\theta $ values, for the same time-dependent problem and find experimentally the value of $\theta $ for which instability disappears for all $\Delta t$. (ii) Suppose we are limited to only 50 timesteps to solve over the time $0<t\le 1$ so $\Delta t=0.02$. Find experimentally the optimum value of $\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 $\Delta t$ and/or $\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 |