Given by Geoffrey C. Fox at Delivered Lectures of CPS615 Basic Simulation Track for Computational Science on 10 October 96. Foils prepared 28 December 1996
Outside Index
Summary of Material
Secs 44.6
This discusses solution of systems of ordinary differential equations (ODE) in the context of N squared particle dynamics problems |
We start with motivation with brief discussion of relevant problems |
We go through basic theory of ODE's including Euler, Runge-Kutta, Predictor-Corrector and Multistep Methods |
We begin the discussion of solving N body problems using classic Connection Machine elegant but inefficient algorithm |
Note -- Some foils expanded to two after talk and second one is given without audio in script |
Outside Index
Summary of Material
Geoffrey Fox |
NPAC |
Room 3-131 CST |
111 College Place |
Syracuse NY 13244-4100 |
This discusses solution of systems of ordinary differential equations (ODE) in the context of N squared particle dynamics problems |
We start with motivation with brief discussion of relevant problems |
We go through basic theory of ODE's including Euler, Runge-Kutta, Predictor-Corrector and Multistep Methods |
We begin the discussion of solving N body problems using classic Connection Machine elegant but inefficient algorithm |
Note -- Some foils expanded to two after talk and second one is given without audio in script |
Consider Models of physical systems represented as sets of particles rather than densities (fields) evolving over time |
Examples:
|
Laws of Motion are typically ordinary differential Equations |
Ordinary means differentiate wrt One Variable -- typically time |
N particles, each with a mass mi , moving with velocity Vi through 3-dimensional space |
Are governed by Newton's equations of motion |
Basic Kinematics |
Newton's Second Law |
Incorporate laws into equations of motion |
Example of force law for molecular dynamics |
ODE's give an equation for the derivative of X with respect to time t |
They can be classified by the boundary conditions used |
Initial value problems
|
Boundary value
|
Second order equations such as |
can always be rewritten as a system of 2 first-order equations involving X and a new variable Y representing the first order derivative: |
For simplicity, we assume just one first-order equation, where f is the function on right hand side which depends on X and t |
We can always solve this by setting up a grid of equidistant points with grid size h=(B-A)/n where n is an integer. |
Starting from the initial value, we calculate positions one step at a time |
Two sources of error: |
Computational error includes such things as roundoff error, etc. and is generally controlled by having enough significant digits in the computer arithmetic |
Discretization error is the accuracy of the numerical method and has two measures:
|
Euler's method is not practical, but illustrates the technique. |
It involves Linear approximation to get next point |
Use Taylor's theorem to represent the exact solution: |
Whenever f satisfies certain smoothness conditions, there is always a sufficiently small step size h such that the difference between the real function value at ti and the approximation Xi+1 is less than some required error magnitude e. [Burden and Faires] |
Euler's method: one computation of the derivative function f at each step. |
Other methods require less computation in order to produce the specified error e. |
Initial Value Problem with known analytical solution: |
The approximation with Euler's method and h=0.25: |
Calculate a few values of the approximation: |
Note it will take about one million iterations to get an error of order O(10-6) |
The last column shows global error is of order O(h) as expected |
Use the derivative at one time step to extrapolate the midpoint value - use midpoint derivative to extrapolate the function value at the next time step |
Evaluates the derivative function twice at each time step. Global error - O(h2), second order method |
Sometimes called the midpoint method |
Note global error is now O(h2) and we get an error of O(10-5) after 128 iterations which would take about 1000 more iterations for Euler's method to achieve |
So Euler has roughly half the computational effort per iteration but requires the square of the number of iterations |
Runge Kutta methods achieve better results than Euler by using intermediate computations at intermediate time values |
The fourth-order rule is the favorite method as it achieves good accuracy with modest computational complexity -- the algorithm is in words: |
Use derivative of first time step to get trial midpoint |
Use its derivative at first time step to get second trial midpoint |
Use its derivative to get a trial end point |
Integrate by Simpon's Rule, using average of two midpoint estimates |
Global error is fourth order |
Compared with Euler, Runge-Kutta has 4 times more calculation per time step, but should use fourth root as many time steps |
First, predict Xi+1 using an explicit equation, with O(hn) error, and known values. |
Then correct this value by using it in an implicit equation, with O(hn+1) error. |
Simple example: |
The predictor/corrector methods use previous values Xi-1, Xi-2, ...... to increase accuracy p - not extra values between Xi and Xi+1 as in Runge Kutta |
General form of multi-step difference equation: |
Xi+1 = am-1Xi + am-2 Xi-1 + ..... + a0Xi+1-m + h(bmf(ti+1, Xi+1) + bm-1 f (ti, Xi) + .....
|
if coefficient of f evaluation dependent on ti+1 bm=0, this is an explicit equation |
Note these are essentially interpolation formulae for if one uses information from m t values, you can fit a degree m-1 polynomial |
Taylor expansion and Polynomial fitting are essentially the same thing! |
Implicit Multistep Methods are gotten using backwards difference interpolating polynomials starting at ti+1. But wherever we we need f(ti+1,y(ti+1)), we use f(ti+1, X*i+1) where X*i+1is derived from the explicit predictor equation |
Note that implicit formulae should be best as explicit method involves extrapolation from ti to ti+1 whereas in implicit case ti+1 is endpoint of region in which interpolation done |
Extrapolation is always unreliable and to be avoided! |
Adams-Bashforth fourth-order explicit method (4 step) |
Adams-Moulton fourth order method (3 step) is an implicit Multistep method |
Note coefficient of implicit method is a factor of 251/19 smaller than explicit method of same order -- this is why extrapolation is not so good! |
Introduce 3 vectors X V A for position,velocity and acceleration of particles |
Numerical techniques iterate equations over time using |
Euler's Equation gives: |
X(t+dt) = X(t) + h * V(t) |
V(t+dt) = V(t) + h * Grav(X(t)) |
Note i labels particles not time steps |
Positions and velocities are 3 N dimensional arrays, X and V |
other variables
|
subroutine for numerical method will take these arguments and update X and V. |
A subroutine called Grav is assumed to compute new accelerations |
Computation of numerical method is inherently iterative: at each time step, the solution depends on the immediately preceding one. |
At each time step, Grav is computed:
|
We will use 4th order Runge Kutta to integrate in time and the program is designed an overall routine looping over time with parallelism hidden in Grav routine |
C Solves Newton's equations of motion using Runge-Kutta method |
C which is globally 4th order. X and V are initial positions and |
C velocities. The system is evolved over a time interval h*ns. |
C X and V contain the updated state at that time.
|
C Grav is hard parallel algorithm and will be given later! |
Spread positions of particles into 2 3D arrays so that extra dimension is labelled by index in sum over particles that interact with a given particle |
Xj is essentially transpose of Xi in second and third dimension |
function Grav(X,M) |
C accepts positions of particles X and masses of particles M |
C returns accelerations in Grav |
C Uses completely parallel calculation, ignoring anti-symmetry of force
|
! calculates acceleration on body i due to body j in entries ( :,i,j )
|
! diag is true for diagonal of N by N slices
|
! set up arrays of particles Xi and particles Xj
|
! displacements and Euclidean distance
|
! calculate accelerations for all pairs except on main diagonal
|
end function Grav |