340 likes | 397 Views
Hyperbolic PDEs: Assignment #4 Numerical Methods for PDEs Spring 2007. Jim E. Jones. Finite difference method for wave equation. Wave equation. Choose step size h in space and k in time. k. t. x. h. Finite difference method for wave equation. Wave equation.
E N D
Hyperbolic PDEs: Assignment #4 Numerical Methods for PDEs Spring 2007 Jim E. Jones
Finite difference method for wave equation Wave equation Choose step size h in space and k in time k t x h
Finite difference method for wave equation Wave equation Choose step size h in space and k in time
Finite difference method for wave equation Wave equation Choose step size h in space and k in time Solve for ui,j+1
Finite difference method for wave equation Stencil involves u values at 3 different time levels k t x h
Finite difference method for wave equation Can’t use this for first time step. U at initial time given by initial condition. ui,0 = f(xi) k t x h
Finite difference method for wave equation Use initial derivative to make first time step. U at initial time given by initial condition k t x h
CFL (Courant, Friedrichs, Lewy) Condition A necessary condition for an explicit finite difference scheme for a hyperbolic PDE to be stable is that for each mesh point the domain of dependence of the PDE must lie within the discrete domain of dependence.
CFL (Courant, Friedrichs, Lewy) Condition The constant c is the wave speed, CFL condition says that a wave cannot cross more than one grid cell in one time step.
Optional Programming assignment #4 • Implement the finite difference method we talked about last time for the hyperbolic PDE: • Exact solution
Optional Programming assignment #4 Investigate stability and accuracy issues • What relationship between h and k must hold for stability? Do your results agree with the CFL condition? • How does the error behave: • O(h+k)? • O(h2 + k)? • O(h2 + k2)? • ???
First: when do we expect the method to be stable? • CFL condition says the method will be unstable whenever k > h. • Numerical Results: infinity norm of error at T=1
First: when do we expect the method to be stable? • CFL condition says the method will be unstable whenever k > h. • Numerical Results: infinity norm of error at T=1 These results generally agree with the CFL condition: note the particularly bad results when h=1/40, k=1/20.
Second: What accuracy do we expect? • Truncation error analysis • Truncation error is the degree to which the actual PDE solution fails to satisfy the difference equation • From Taylor’s theorem • Plugging this into the difference equation
Truncation error analysis • Similar analysis for time term gives • Combining the space and time terms
Truncation error analysis • Similar analysis for time term gives • Combining the space and time terms • Using the PDE utt – uxx = 0
Truncation error analysis • Similar analysis for time term gives • Combining the space and time terms • Truncation error is O(h2 + k2)
Results 1: Infinity norm of error at T=1 These results don’t agree with the truncation error analysis: the errors are really small, around the size of machine precision
Back to truncation error analysis • Combining the space and time terms • Truncation error is O(h2 + k2) • When k=h, we have
PDE PDE Back to truncation error analysis • The PDE gives a relation between time and space derivatives: utt = uxx • Similarfor other even derivatives Interchange derivative order
Back to truncation error analysis • When k=h, we have • Great numerical results are because all terms in () are zero!
Results 2: Infinity norm of error at T=1 These results don’t agree with the truncation error analysis: reducing h and k by a factor of 2 reduces the error by a factor of 8
Curious Results • I’m somewhat at a loss here… maybe a bug? • Maybe there is something special about T=1? • Lets change the time interval to [0,0.5]
Results 3: Infinity norm of error at T=.5 These results don’t agree with the truncation error analysis: reducing h and k by a factor of 2 reduces the error by a factor of 2
More Curious Results • I’m at a loss here… • We know we make an O(k) error in the first time step • Perhaps this is causing the reduced accuracy
Finite difference method for wave equation Use initial derivative to make first time step. U at initial time given by initial condition k t x h
More Curious Results • I’m at a loss here… • We know we make an O(k) error in the first time step • Perhaps this is causing the reduced accuracy • Let’s cheat and put the exact PDE solution in for the first time step.
Results 4: Infinity norm of error at T=.5 These results do agree with the truncation error analysis: reducing h and k by a factor of 2 reduces the error by a factor of 4
OK – but how do we get around the cheat? • Ideas? • Give me a good one and I’ll implement it by Wednesday.