numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf ·...

18
Numerical solutions of classical equations of motion Newtons laws govern the dynamics of Ø Solar systems, galaxies,... Ø Molecules in liquids, gases; often good approximation - quantum mechanics gives potentials - large (and even rather small) molecules move almost classically if the density is not too high Ø Everything that movesAlmost no realsystems can be solved analytically Ø Numerical integration of equations of motion

Upload: others

Post on 23-Apr-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Numerical solutions of classical equations of motion

Newton’s laws govern the dynamics ofØ Solar systems, galaxies,...Ø Molecules in liquids, gases; often good approximation

- quantum mechanics gives potentials- large (and even rather small) molecules move almost classically if the density is not too high

Ø “Everything that moves”

Almost no “real” systems can be solved analyticallyØ Numerical integration of equations of motion

Page 2: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

One-dimensional motionØA single “point particle” at x(t)Equation of motion

Notation: velocity:acceleration:

Rewrite second-order diff. eqv. as coupled first-order:

Forces from: potential, damping (friction), driving (can be mix)

Page 3: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Discretized time axis

Start from given initial conditions:

Simplest integration method: Euler forward algorithm

Step error:

Ø Euler is not a very good algorithm in practiceØ Energy error unbounded (can diverge)ØAlgorithms with better precision almost as simple

Fortran 90 implementations:do i=1,nt

t0=dt*(i-1)x1=x0+dt*v0v1=v0+dt*acc(x0,v0,t0)x0=x1; v0=v1

enddo

do i=1,ntt=dt*(i-1)a=acc(x,v,t)x=x+dt*vv=v+dt*a

enddo

Page 4: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Illustration of Euler algorithm: Harmonic oscillator

Integrated equations of motion for k=m=1;

(F = -kx)

Page 5: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Leapfrog algorithm (no damping)Taylor expand x(t) to second order in time step

Contains velocity at “half step”:Substituting this gives

Use similar form for v propagation: Leapfrog algorithm

Starting velocity from:

do i=1,ntt=dt*(i-1)a=acc(x,t)v=v+dt*ax=x+dt*v

enddo

Page 6: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

What is the step error in the leapfrog algorithm?Ø Might expect: ØActually:Ø Can be easily seen in a different derivation

Adding these gives the so-called Verlet algorithm

Same as leapfrog, since

Velocity defined by:

The Verlet algorithmStart from two Taylor expansions:

Page 7: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Properties of Verlet/leapfrog algorithmØ Time reversal symmetry (check for round-off errors)Ø Errors bounded for periodic motion (time-reversal)Ø High accuracy with little computational effort

Illustration: Harmonic oscillator (k=m=1),

do i=1,ntt=dt*(i-1)a=acc(x,t)v=v+dt*ax=x+dt*v

enddo

Code almost identical to Euler (swicth 2lines!)

Remember, initialize v at the half-step -dt/2!

Page 8: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Two equivalent Verlet/leapfrog methods

Verlet:

Leapfrog:

Page 9: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Error build-up in Verlet/leapfrog method

Difference between numerical and exact solution:

Inserting this in Verlet equation

Error in x after N steps, time

Discretized second derivative:

The equation of motion for the error is thus:

gives

Page 10: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Exact solution satisfies: We are thus left with: Integrate to obtain error after time T:Worst case: no error cancellations (same sign for all n):

Assume smoothness on scale of time-step, use continuum derivative(imagine a high-order interpolating polynomial between points)

Page 11: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Verlet/leapfrog methods for damped systemsWe assumed velocity-independent forces in leapfrog method;

With velocity dependent we need vn but have only vn+1/2

To study this problem, separate damping from rest of force

Consider approximation:

The error made in a is which gives x-error We can do a second step usingThis renders the error in x

Page 12: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Summary; leapfrog algorithm with damping:

Requires more work than standard leapfrog:

vn used here in an

Page 13: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Runge-Kutta method

Consider first single first-order equation:

Classic high-order scheme; error (4th order)

Warm-up: 2nd order Runge-Kutta

Use mid-point rule:

But we don’t know

Approximate it using Euler formula;

Sufficient accuracy for formula:

Page 14: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

4th-order Runga-Kutta (the real thing)

Uses Simpson’s formula:

Need to find approximations forSomewhat obscure scheme accomplishes this (can be provencorrect using Taylor expansion)

Page 15: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Runge-Kutta for two coupled equations

Page 16: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

Equations of motion, Runge-Kutta algorithm

Including damping is no problem here

Page 17: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

The RK method does not have time-reversal symmetryØ Errors not bounded for periodic motionØ Time-reversibility important in some applications

Advantages of RK relative to leapfrog:ØVariable time-step can be used (uses only n-data for n+1)Ø Better error scaling (but more computations for each step)

harmonicoscillator(k=m=1)

Page 18: Numerical solutions of classical equations of motionphysics.bu.edu/~py502/slides/l06.pdf · Leapfrog algorithm (no damping) Taylor expand x(t) to second order in time step Contains

What algorithm to use?Recommendation

In the case of energy-conserving systems (no damping or external driving forces)• Use the Verlet/leapfrog algorithm- good energy-conserving property (no divergence)

In the case of non-energy-conserving systems (including damping and/or external driving forces)• Energy is not conserved, so no advantage for Verlet• Use the Runge-Kutta algorithm- smaller discretization error for given integration time T