Heat Equation
While the trampoline is a good example for showing the power
of using PDE, it is too complicated for the first contact with the
implementation of this type of equation with FDS method.
Learning new methods is best with a simple example, and one
of the simplest PDE is the Heat Equation, it models the problem of heat
distribution. We shall solve it in one dimension, and in that case the equation
looks like this:
Here u(x,t) represents the heat
distribution or what temperature is at each point of space at different moments
in time. What do we wish to see in real time games? How things change over
time. That is just what this equation shows us, the change. ut is called the partial differential of u over t, and it represents how u changes over time (t). It is equal to:
Since we are interested in viewing the heat distribution, we should first find a representation of u , in some useful way. Let's say that un(x) = u(x,dt*n) , where dt is our time step and n is some fixed number (it is not the same as t which is a variable).
This way n*dt just represents some moment in time. Now we want to observe how the heat is distributed in space at that moment. The best way to do this is to use of a grid, xi = x0+i*h , where h is the step in the grid.
The heat distribution at moment n can be seen as an
array of points uin = un(xi) . This is best understood by looking at this image:
Now we get to the Finite Difference Scheme. The idea is to approximate ut at each point in the grid. Using the time step dt we have the following approximation for equation (2):
This is actually a good approximation if dt is small. The next thing that we notice in the equation is uxx . This is called the second partial derivative of u over x .
This is nothing more that doing the partial derivative twice on u over x . The partial derivative of u over x , represents how u changes over space( x ). The approximation will be exactly that.
Now we can write the approximated version
of equation (1) at every point in the grid.
We are at a point from where we can take a time step, or to move from a moment n at which we know how u looks, to moment n + 1 where we don't know how u looks. If we look closely at the equation (5) we notice that there is only one element that is at the time step n + 1 . So let us solve it:
Equation (6) is the end of the simple
use of FDS. Now we can add a mathematical "trick" to make it more
precise. First let us take a look at
equation (6), it is actually very similar to the approximation of the Euler method.
So we
can use an approximation of Runge-Kutta (another
time step method) instead to make it more accurate. It is calculated by the
following formulas:
|