44
Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 2 Instructor: Tim Warburton

Numerical Methods for Partial Differential Equations

  • Upload
    viho

  • View
    46

  • Download
    3

Embed Size (px)

DESCRIPTION

Numerical Methods for Partial Differential Equations. CAAM 452 Spring 2005 Lecture 2 Instructor: Tim Warburton. Note on textbook for finite difference methods. - PowerPoint PPT Presentation

Citation preview

Page 1: Numerical Methods for Partial Differential Equations

Numerical Methods for Partial Differential Equations

CAAM 452Spring 2005

Lecture 2Instructor: Tim Warburton

Page 2: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Note on textbook for finite difference methods

• Due to the difficulty some students have experienced in obtaining Gustafasson-Kreiss-Oliger I will try to find appropriate and equivalent sections in the online finite-difference book by Trefethen:

http://web.comlab.ox.ac.uk/oucl/work/nick.trefethen/pdetext.html

Page 3: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Recall Last Lecture

• We considered the model advection PDE:

• defined on the periodic interval [0,2pi)

• We recalled that any 2pi periodic, C1 function could be represented as a uniformly convergent Fourier series, so we considered the evolution of the PDE with a single Fourier mode as initial condition. This converted the above PDE into a simpler ODE for the time-dependent coefficient (i.e. amplitude) of a Fourier mode:

0u uc

t x

ˆ0ˆ

dui cu

dt

Page 4: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Recall: the Advection Equation

• We wills start with a specific Fourier mode as the initial condition:

• We try to find a solution of the same type:

1) Find 2 -periodic , such that 0,2 , 0,

0

given

1 ˆ( ,0) = 0,22

where is a smooth 2 -periodic function of one frequency

i x

u x t x t T

u uc

t x

u x f x e f x

f

1, ,ˆ

2i xu x t e u t

Page 5: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• Substituting in this type of solution the PDE:

• Becomes an ODE:

• With initial condition

0u uc

t x

1 1 ˆ,ˆ ˆ

2 2ˆ

i x i xu u duc c e u t e i cu

t x t x dt

dui cu

dt

ˆ,0u f

Page 6: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• We have Fourier transformed the PDE into an ODE.• We can solve the ODE:

• And it follows that the PDE solution is:

ˆ0ˆ ˆ, ,0ˆ ˆ

ˆ,0ˆ

i ct i ct

dui cu

u t e u e fdtu f

1: , ,ˆ

21ˆ ˆsolution : , ,ˆ2

1 ˆinitial condition: 2

i x

i x cti ct

i x

ansatz u x t e u t

u t e f u x t e f f x ct

f x e f

Page 7: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Note on Fourier Modes

• Note that since the function should be 2pi periodic we are able to deduce:

• We can also use the superposition principle for the more general case when the initial condition contains multiple Fourier modes:

1 ˆ2

1 ˆ,2

i x

i x ct

f x e f

u x t e f f x t

Page 8: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• Let’s back up a minute – the crucial part was when we reduced the PDE to an ODE:

• The advantage is: we know how to solve ODE’s both analytically and numerically (more about this later on).

0u uc

t x

ˆ0ˆ

dui cu

dt

Page 9: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Add Diffusion Back In

• So we have a good handle on the advection equation, let’s reintroduce the diffusion term:

• Again, let’s assume 2-pi periodicity and assume the same ansatz:

• This time:

2

2

u u uc d

t x x

1,ˆ

2i xu e u t

2

2

u u uc d

t x x

2ˆˆ ˆ

dui cu d u

dt 2ˆ

ˆdu

ic d udt

Page 10: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• Again, we can solve this trivial ODE:

2ˆˆ

dui c d u

dt

2

,0ˆ ˆic d t

u u e

2

,0ˆ i ct x d tu u e e

Page 11: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• The solution tells a story:

• The original profile travels in the direction of decreasing x (first term)

• As the profile travels it decreases in amplitude (second exponential term)

2

,0ˆ i ct x d tu u e e

2d tu f ct x e

Page 12: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

What Did Diffusion Do??

• Advection:

• Diffusion:

• Adding the diffusion term shifted the multiplier on the right hand side of the Fourier transformed PDE (i.e. the ODE) into the left half plane.

• We summarize the role of the multiplier…

0u uc

t x

2

2

u u uc d

t x x

ˆ0ˆ

dui cu

dt

2ˆˆ

dui c d u

dt

Page 13: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Categorizing a Linear ODE

Re

Im

Exponential growth Exponential decay

Incr

easi

ngly

osc

illat

ory

In

crea

sing

ly

osc

illat

ory

Here we plot the dependence of the solution to the top left ODE on mu’s position in the complex plane

ˆ 0ˆ ˆ ˆ tduu u u e

dt

Page 14: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Categorizing a Linear ODE

Re

Im

Here we plot the behavior of the solution for 5 different choices of mu

Page 15: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Summary

• When the real part of mu is negative the solution decays exponentially fast in time (rate determined by the magnitude of the real part of mu).

• When the real part of mu is positive the solution grows exponentially fast in time (rate determined by the magnitude of the real part of mu).

• If the imaginary part of mu is non-zero the solution oscillates in time.

• The larger the imaginary part of mu is, the faster the solution oscillates in time.

Reˆ 0 0 cos Im sin Imˆ ˆ ˆ ˆ ttduu u u e u e t i t

dt

Page 16: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Solving the Scalar ODE Numerically

• We know the solution to the scalar ODE

• However, it is also reasonable to ask if we can solve it approximately.

• We have now simplified as far as possible.

• Once we can solve this model problem numerically, we will apply this technique using the method of lines to approximate the solution of the PDE.

ˆˆ

duu

dt

Page 17: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Stage 1: Discretizing the Time Axis

• It is natural to divide the time interval [0,T] into shorted subintervals, with width often referred to as:

• We start with the initial value of the solution u(0) (and possibly u(-dt),u(-2dt),..) and build a recurrence relation which approximates u(dt) in terms of u(0) and early values of u.

, or dt t k

duf u

dt

Page 18: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Example

• Using the following approximation to the time derivative:

• We write down an approximation to the ODE:

u t dt u tdudt dt

00

u dt uf u

dt

du

f udt

Page 19: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Example cont

• Rearranging:

• We introduce notation for the approximate solution after the n’th time step:

• Our intention is to compute • We convert the above equation into a scheme to

compute an approximate solution:

00

u dt uf u

dt

0 0u dt u dtf u

nu

0

1 0 0

0u u

u u dtf u

nu u ndt

Page 20: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Example cont

• We can repeat the following step from t=dt to t=2dt and so on:

• This is commonly known as the:– Euler-forward time-stepping method

– or Euler’s method

0

1 0 0

2 1 1

1

0

n n n

u u

u u dtf u

u u dtf u

u u dtf u

Page 21: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Euler-Forward Time Stepping

• It is natural to ask the following questions about this time-stepping method:

• Does the answer get better if dt is reduced? (i.e. we take more time-steps between t=0 and t=T)

• Does the numerical solution behave in the same way as the exact solution for general f?(for the case of f(u) = mu*u does the numerical solution decay and/or oscillate as the exact solution)

• How close to the exact solution is the numerical solution?

• As we decrease dt does the end iterate converge to the solution at t=T

0

1

0

n n n

u u

u u dtf u

Page 22: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Experiments

• Before we try this analytically, we can code it up and see what happens.

• This is some matlab code for Euler forward applied to:

0

1

0

n n n

u u

u u dt u

http://www.caam.rice.edu/~caam452/CodeSnippets/EulerForwardODE.m

Page 23: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

What dt can we use?

• With dt=0.1, T=3, uo=1, mu=-1-2*i

The error is quite small.

Matlab

Page 24: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Larger dt=0.5

• With dt=0.5, T=3, uo=1, mu=-1-2*i

The error is visible but the trend is not wildly wrong.

Page 25: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Even Larger dt=1

• With dt=1, T=3, uo=1, mu=-1-2*i

The solution is not remotely correct – but is at least bounded.

Page 26: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

dt=2

• With T=30, dt=2, uo=1, mu=-1-i

Boom – the approximate solution grows exponentially fast, while the true solution decays!

Page 27: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Observations

• When dt is small enough we are able to nicely approximate the solution with this simple scheme.

• As dt grew the solution became less accurate

• When dt=1 we saw that the approximate solution did not resemble the true solution, but was at least bounded.

• When dt=2 we saw the approximate solution grew exponentially fast in time.

Page 28: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• Our observations indicate two qualities of time stepping we should be interested in:

– stability: i.e. is the solution bounded in a similar way to the actual solution?

– accuracy: can we choose dt small enough for the error to be below some threshold?

Page 29: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

ndtf udt

nu

1nt tn

1nu

Geometric Interpretation:

• We can interpret Euler-forward as a shooting method.• We suppose that is the actual solution, compute the

actual slope and shift the approximate solution by

• Note:– the blue line is not the exact solution, but rather the same

ODE started from the last approximate value of u computed.– in this case we badly estimated the behavior of even the

approximately started solution in the interval dt two kinds of error can accumulate!.

ndtf unu

nf u

0

1

0

n n n

u u

u u dtf u

Page 30: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Interpolation Interpretation:

• We start with the ODE:

• Integrate both sides from over a dt interval:

• Use the fundamental theorem of calculus:

• Finally, replace f with a constant which interpolates f at the beginning of the interval…

duf u

dt

1 1n n

n n

t t

t t

dudt f u dt

dt

1

1

1

n

n

n

n

tt

n ntt

dudt u u u

dt

0

1

0

n n n

u u

u u dtf u

Page 31: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

1

1

1 1 1

1

1

n

n

n

n

n n n

n n n

tt

n ntt

t t t

n n n

t t t

n n n

dudt u u t u t

dt

f u t dt f u t dt f u t dt f u t dt

u t u t f u t dt

Again, we have recovered Euler’s method.

Page 32: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Let’s choose f(u) = mu*u

We can solve this immediately:

Next suppose Re(mu)<=0 then we expect the actualsolution to be bounded in time by u(0).For this to be true of the approximate solution werequire:

Stability

0

1

0

1n n n n

u u

u u dt u dt u

0

1

1

0

1 1 0n

n n

u u

u dt u dt u

1 1dt

Page 33: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Stability Condition for Euler Forward

• Since mu is fixed we are left with a condition which must be met by dt

• which is true if and only if:

• The region of the complex plane which satisfies this condition is the interior of the unit circle centered at -1+0*i

1 1dt

2 21 Re Im 1dt dt

x Re

Im

Page 34: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• i.e. will not blow up if it is located inside the unit disk:

• Notice: the exact solutions corresponding to Re(mu)<0 all decay. However, only the numerical solutions corresponding to the interior of the yellow circle decay.

dt

Re

Im

x-1+0i

Page 35: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Disaster for Advection!!!

• Now we should be worried. The stability region:

• only includes one point on the imaginary axis (the origin) but our advection equation for the periodic interval has mu which are purely imaginary!!!.

• Conclusion – the Euler-Forward scheme applied to the Fourier transform of the advection equation will generate exponentially growing solutions.

Re

Im

x-1+0i

ˆ0ˆ

dui cu i c

dt

Page 36: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Nearly a Disaster for Advection-Diffusion!!!

• This time the stability region must contain:

• Because the eigenvalues are shifted into the left half part of the complex plane, we will be able to choose dt small enough to force the mu*dt into the stability region.

• We can estimate how small dt has to be in this case

Re

Im

x-1+0i

2ˆˆ

dui c d u

dt

2dt i c d dt

Page 37: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont (estimate of dt for advection-diffusion)

• For stability we require:

2

2 22

2 22 2

2 2 2

1 1

1 1

1 1

2 0

0 or

0 or

2

dt

i c d dt

dt d cdt

dt d dt d cdt

dt

dt d c d

Page 38: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• The only interesting condition for stability is:

• What does this mean?, volunteer?• i.e. how do influence the maximum stable dt?• Hint: consider

i) d small, c large

ii) d large, c small

2 2 2

2

ddt

d c

, ,d c

Page 39: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Multistep Scheme (AB2)

• Given the failure of Euler-Forward for our goal equation, we will consider using the solution from 2 previous time steps.

• i.e. we consider

• Recall the integral based interpretation of Euler-Forward:

1 1n n n nu u dt af u bf u

1

1

n

n

t

n n n

t

u t u t f u t dt f u t dt

Page 40: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• We interpolate through f(un-1)and f(un) then integrate between tn and tn+1

Ifn+1

f(un-1)

tn+1tntn-1

Approximate integral

fLinear interpolant of the f values

f(un)

Page 41: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

• This time we choose to integrate under the interpolant of f which agrees with f at tn and tn-1

• The unique linear interpolant in this case is:

• We need to compute the following integral of the interpolant..:

11 1

1 1

n nn n

n n n n

t t t tI f f u f u

t t t t

1

n

n

t

t

I fdt

Page 42: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

cont

Last step: homework exercise

1 1

1 1

1 1

11 1

1 1

11

2 21

1

1

2 2

3 12 2

n n

n n

n n

n n

n n

n n

t t

n nn n

n n n nt t

t t

n nn n

t t

t t

n nn n

t t

n n

t t t tI fdt f u f u dt

t t t t

f u f ut t dt t t dt

dt dt

f u f ut tt t t t

dt dt

dt f u f u

Page 43: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Adams-Bashford 2

• The resulting AB2 scheme requires the solution at two levels to compute the update:

1

1 1

1

3 12 2

n

n

t

n n

t

n n n

u u If dt

u f u f u

Page 44: Numerical Methods for Partial Differential Equations

CAAM 452 Spring 2005

Next Time

• Stability region for AB2• Generalization to AB3, AB4 (use more historical data to compute

update)

• Accuracy/consistency of Euler-Forward, AB2,AB3,AB4• Convergence.

• Runge-Kutta schemes (if time permits)

• READING:

http://web.comlab.ox.ac.uk/oucl/work/nick.trefethen/1all.pdf

• p10-p55 (do not do exercises)