NumMethodsPDEs

Numerical Methods for PDEs: Solving PDEs on a computer

=Introduction=

In this tutorial, we'll take a look at how we might model aspects of the world around us on a computer. When we use mathematics to describe many of the phenomena that we see we end up using Partial Differential Equations (PDEs), and so we seek ways to solve these numerically. As a notation shorthand, we'll use $$u_x$$ to represent the partial derivative of u with respect to x:


 * $$u_x = \frac{\partial u}{\partial x}$$

=Looking at Nature (& a quick philosophical aside)=

When we observe nature, certain patterns crop up again and again. For example, in the the field of electrostatics, if a function $$f$$ describes a distribution of electric charge, then Poisson's equation:


 * $${\nabla}^2 \varphi = f.$$

gives the electric potential $$\varphi$$.

However, Poisson's equation also describes the steady state temperature of a material when subjected to some heating and also crops up when considering gravitational potentials..

What's going on here? Why the recycling of the same equation? Is Poisson's equation fundamental in some way? Well, yes I suppose it is. However, we can look at it another way and say that Poisson's equation is the way we describe--using the language of maths--steady state phenomena which involve potentials. OK, this sounds a bit out there, but consider the following very general equation for a moment (it's a second-order linear equation in two variables):

$$Au_{xx} + Bu_{xy} + Cu_{yy} + Du_x + Eu_y + Fu = G$$

It turns out that we can categorise certain instances of this equation and then relate these categories to the kind of phenomena that they describe:


 * Parabolic: $$B^2 - 4AC = 0$$.  This family of equations describe heat flow and diffusion processes.
 * Hyperbolic: $$B^2 - 4AC > 0$$.  Describe vibrating systems and wave motion.
 * Elliptic: $$B^2 - 4AC < 0$$.  Steady-state phenomena.

That's pretty handy!

=Discritisation=

OK, so far so good. However, the functions and variables that we've considered thus far are continuous, meaning that they could have an infinite number of values. This is fine when solving equations analytically, but we need to deal with a finite number of values when working with a digital computer. We need a way to discritise our problems. Happily, help is at hand from the Taylor series. Recall that we can approximate the value of a function at a point distant (displaced by an amount h) from x using a linear summation of derivatives of the function at x:


 * $$f(x+h) \approx f(x) + \frac{f'(x)}{1!}h + \frac{f''(x)}{2!}h^2 + \cdots$$

Let's truncate this series after the first differential and rearrange:


 * $$f'(x) \approx \frac{f(x+h) - f(x)}{h} $$

This is called the forward-difference approximation to the first derivative, $$f'(x)$$. If we were to consider a displacement of -h, we would end up with:


 * $$f'(x) \approx \frac{f(x) - f(x-h)}{h} $$,

which is called the backward-difference. Subtracting the backward from the forward we can generate:


 * $$f'(x) \approx \frac{1}{2h}(f(x+h) - f(x-h))$$,

the central-difference approximation.

=Eliptical Equations: Discrete Laplacian Operator=




 * $$\frac{\partial^2u}{\partial x^2} + \frac{\partial^2u}{\partial y^2} = 0$$

=Parabolic Equations: Forward Euler=



The 1D heat equation:


 * $$\frac{\partial u}{\partial t}=\alpha \frac{\partial^2u}{\partial x^2} $$

where $$\alpha$$--the thermal diffusivity--is set to 1 for simplicity.


 * $$\frac{u^{i+1}_j - u^i_j }{k} = \frac{u^i_{j+1} - 2u^i_j + u^i_{j-1}}{h^2}$$


 * $$u^{i+1}_j = u^i_j + r(u^i_{j+1} - 2u^i_j + u^i_{j-1})$$

where:

$$r=\frac{k}{h^2}$$



=Parabolic Equations: Crank-Nicolson=

The CFL condition:


 * $$r=\frac{k}{h^2} \le 0.5 $$

for stability.

The 1D heat equation:


 * $$\frac{\partial u}{\partial t}=\alpha \frac{\partial^2u}{\partial x^2} $$

where $$\alpha$$--the thermal diffusivity--is set to 1 for simplicity.

Create a finite difference equation using the Crank-Nicolson stencil:


 * $$\frac{u^{i+1}_j - u^i_j }{k} = \frac{1}{2}(\frac{u^{i+1}_{j+1} - 2u^{i+1}_{j} + u^{i+1}_{j-1}}{h^2} + \frac{u^i_{j+1} - 2u^i_j + u^i_{j-1}}{h^2})$$

rearrange,


 * $$u^{i+1}_j - u^i_j = \frac{1}{2}\frac{k}{h^2}(u^{i+1}_{j+1} - 2u^{i+1}_{j} + u^{i+1}_{j-1} + u^i_{j+1} - 2u^i_j + u^i_{j-1})$$


 * $$2(u^{i+1}_j - u^i_j) = r(u^{i+1}_{j+1} - 2u^{i+1}_{j} + u^{i+1}_{j-1} + u^i_{j+1} - 2u^i_j + u^i_{j-1})$$

where $$r=\frac{k}{h^2}$$

collect the unknowns (values of u at the next timestep, i+1) to the LHS and the knowns (values of u at current timestep, i):


 * $$2u^{i+1}_j + 2ru^{i+1}_j - ru^{i+1}_{j+1} - ru^{i+1}_{j-1} = 2u^i_j +ru^i_{j+1} -2ru^i_j + ru^i_{j-1}$$


 * $$(2+2r)u^{i+1}_j - ru^{i+1}_{j+1} - ru^{i+1}_{j-1} = (2-2r)u^i_j +ru^i_{j+1} + ru^i_{j-1}$$

if we choose $$h=1/10$$ and $$k=1/100$$, then $$r=1$$.