Lecture 3 18.086

advertisement
Lecture 3
18.086
Info
•
PSet 1 will be posted this afternoon/evening (due in 2 weeks)
•
Until Feb. 22: Decide for a computational project (50% grade) and submit
proposal to me by email (content: see next slide)
•
March 28: Submit short (max 1page) written mid-term project report
•
Until Friday, May 6: Submit written final project report
•
May 5, 10, 12: Presentation (in class): 12 minutes + 3 minutes questions/
discussion
•
Content of project: Free choice, as long as related to course contents/computational aspect
(can also go beyond!). No recycling of existing/old projects!
Implementation/testing/comparison of methods is ok
Term project
•
When submitting your project proposal (Feb. 22), use this template:
•
Project title
•
Project background: Does it relate to your work in another field
(e.g. your thesis)? If yes, briefly outline the questions and goals
of your work in the other field.
•
Questions and Goals: Briefly describe the questions you wish
to investigate in your project. What are your expectations?
•
Plan: Which language do you plan to program in? Do you intend
to use special software? Does your project work relate to the
work of other people at MIT?
Plan for today
•
Runge-Kutta time integration
•
Basic time integration algorithm
•
1-way wave equation
FD schemes for ODEs
•
Equation: u’ = f(u) with u(0) given
•
First order accuracy (p=1): Euler methods
•
2
3
Second order (p=2): global error O(Δt ), local error O(Δt ):
Trapezoidal implicit
AdamsBashford
explicit
Backward
explicit
ward differences/BDF2
differences
Un+1
Un
t
Un+1
1
= [f (Un+1 , tn+1 ) + f (Un , tn )]
2
Un6.2 3 Finite Difference
1 Methods 467
= f (Un , tn )
f (Un 1 , tn 1 )
t
2
2
3un+1- 4 u n
2At
+ un-1 = f (Un+l, t n + l ) . (19)
Un+1 Unmethod
1
Runge-Kutta
t about
stability? The trapezoidal
(15)
is
stable
eventf for
stiff
equa=
[f
(U
,
t
)
+
f
(U
+
(U
,
t
),
t
n n
n
n n
n+1 )]
explicit
2 negative: l - $atA t (left2 side) will be larger than 1 l a A t
hen a is very
de). (19) is even more
stable
and&accurate.
Lecture:
Stability
Accuracy The Adams method (17) will be
+
FD schemes for ODEs
•
Runge-Kutta is actually a family of methods!
•
The most famous is Runge-Kutta-4 (RK4), which has p=4:
RK4
explicit
Un+1
Un
t
k1
(ode45 in
matlab)
k2
with
k3
k4
1
= [k1 + 2k2 + 2k3 + k4 ]
3
1
= f (Un , tn )
2
1
= f (Un + tk1 , tn+1/2 )
2
1
= f (Un + tk2 , tn+1/2 )
2
1
= f (Un + 2 tk3 , tn+1 )
2
6.2 Finite Difference Methods
Adams-Bashforth
46
Adams-Moulton
5
i
Stabilityi
diagrams
•
So far, we obtained stability conditions such as (RK2):
1 2
|1 + z + z |  1
2
•
(z = a Δt for u’=au)
6.2consider
Finite Difference
Methods
It makes sense (see lecture) to
complex
z,
and draw the stability region in the complex plane
Backward Differences
Adams-Bashforth
Runae-Kutta
Adams-Moulton
5 i i
469
Basic ODE time integration
•
Given: RHS f(u,t), initial conditions u(0)
•
Solve u’(t) = f(u,t):
Nsteps=1000; %Perform 1000 integration steps
dt = 0.1;
u = zeros(Nsteps+1); % Preallocate space for solution u
% Set initial conditions:
u(1)=u0;
t = 0;
If you use integrator that requires U
% Forward Euler:
for i=1:1000
u(i+1) = u(i) + dt*f(u(i),t);
t=t+dt;
end
% Plot solution u etc.
from past:
Start doing a single Forward Euler
step to get the first 2 values of U,
then use your integrator of choice!
1-way wave equation
•
So far we only considered ODE’s: u’ = f(u,t) and we
only considered methods for the time integration
•
Now: PDEs! Simplest example: 1-way wave
equation: u = cu
t
•
x
We need to use “good” time integration and good
approximation of spatial derivatives.
1-way wave equation
ut = cux
•
Properties of
•
Conservative equation (modes neither grow nor shrink)
•
:
Solution to initial condition u(x, 0) = e
lecture
ikx
:
u(x, t) = eik(x+ct)
lecture
•
c is the speed by which the wave travels
•
wave does not change its form
Spatial finite difference (FD) schemes
•
Common FD schemes for 1D ux:
Forward diff, O(Δx):
u(x)
Backw. diff, O(Δx):
i
Central diff, O(Δx2):
x
But this is only spatial accuracy! How does it affect overall accuracy?
Lecture:
accuracy
FD for the 1-way wave equation
•
Now: How to do time and space discretization in optimal way?
Upwind/
forward
differences
U (x, t +
t)
t
U (x, t)
U (x, t +
t)
t
U (x,
t)
until here
LaxWendroff
U (x, t +
LaxFriedrich
•
t)
=c
U (x +
x, t)
x
U (x, t)
x, t) U (x
x, t)
=c
2 x
say next time why r<1 is stability
criterium
t 2 U (x + x, t) 2U (x, t) + U (x
+
c
2
x2
1
2 (U (x
=c
Multiplying by ▵t gives various terms on RHS with factor
U (x +
+
t
U (x +
x, t) + U (x
x, t) U (x
2 x
t
r=c
x
x, t)
x, t))
x, t)
CFL condition for stability:
r≤1 (lecture)
Courant-Friedrichs-Lewy
condition
•
t
 1 is necessary but not sufficient for stability!
The CFL condition r = c
x
•
Sufficient criteria for stability: Neumann stability analysis
•
Idea: Remember, wave equation has solution in terms of exponentials: u(x,
t) = G(k, t)e
ikx
=> We found |G|=1 analytically, but how does this look for discrete
approximations? => Will tell us stability for each mode k separately
•
We find: Upwind: 0  r  1
Lax-Friedrichs: 1  r  1
Neumann stab. analysis for upwing
and Lax-Friedrichs: Lecture
Lecture 4
18.086
Last time
ut = cux
•
1-way wave equation (also called advection equation)
•
t
1
CFL criterium for stability r = c
x
•
von Neumann stability analysis
•
ikx
u(x,
t)
=
G(k,
t)e
solution in terms of single modes:
•
|G|=1 analytically
•
|G|<1 for stability of numerical scheme
FD for 1-way wave eq: summary
Upwind
differences
U (x, t +
U (x, t +
LaxWendroff
t)
t
t)
t
U (x, t +
LaxFriedrich
U (x, t)
U (x, t)
t)
=c
U (x +
x, t)
x
U (x, t)
x, t) U (x
x, t)
2 x
t 2 U (x + x, t) 2U (x, t) + U (x
+
c
2
x2
=c
U (x +
1
2 (U (x
=c
+
t
U (x +
x, t) + U (x
x, t) U (x
2 x
x, t))
x, t)
Lecture
t
r=c
x
O(Δt)
0r1
O(Δt2)
x, t)
1r1
O(Δt) ! 1  r  1
The LW difference equation combines U,,, and Uj-l,n and Uj+1,, to compute U,,n+l:
1
G = (1 - r 2 ) -(r2
2
+
Lax- Wendroff
+
+ r)e
zk Ax
+
1
-(r2 - r)e-zkAx .
2
Notation
+
(23)
This is G = 1 - r2 r2cos k A x ir sin kAx. At the dangerous frequency k A x
the growth factor is 1 - 2r2. That stays above -1 if r2 5 1.
=T,
<
5 shows that IGI
1 for every kAx. Lax-Wendroff is stable when• Problem
We have seen different schemes for 1-way wave equation.
ever the CFL condition r 2 <
- 1 is satisfied. The wave can go either way (or both
The
schemes
are often
stencils
depicted
like this:
c can be negative.
LWcalled
is the most
accurateand
of these
five methods.
ways)
since
upwind
stable
ifrL1
wrong way
unstable
all At
centered
unstable
all At
Lax-Friedrichs
stable
if Irl 5 1
Lax-Wendroff
stable
if Irl 5 1
The centered methods
for -1 < r < 1.
U (x, t + t)of Umaximum
(x, t)
U (x +accuracy
x, t) U (x arex,stable
t)
=c
t
2 x
Lax-uses three values at time level
Lax-Wendroff
n
for
accuracy two. For
every even
t 2 U (x + x, t) 2U (x, t) + U (x
x, t)
c so that the difference
p = 2q, Wendroff
there are p+ 1 coefficients a_,, .+. .2, a,
equation U,,n+l =
x2
C amU,+,,, has accuracy p. Matching G = C ameimkAx with the exact factor
- eikrAx gives pU+(x,
1 tequations
forUthe
e
+ t) 12C
(Uamm&
(x + x,rj
t) +
(x a's.x, t))
Laxt
Using all
those values, the CFL condition allows
the possibility of stability out to
U (x is
+ -1x,5t)r 5U 1.
(x
x, t)
Friedrich
-q 5 c A
t l A x 5 q. The actual requirement
=c
5.
2 x
Real-world accuracy
Veque — AMath 585–6 Notes
Veque — AMath 585–6 Notes
Upwind:
183
183
Upwind solution at time 4
1
Upwind solution at time 4
1
0.5
0.5
0
0
−0.5
−0.5
0
0
1
1
2
2
3
3
Lax-Wendroff:
4
4
5
6
5
6
5
6
Lax−Wendroff solution at time 4
1
Lax−Wendroff solution at time 4
1
0.5
0.5
0
0
−0.5
0
1
2
3
4
Real-world accuracy
478
Chapter 6
Initial Value Problems
step-like initial condition:
121.
08.
Upwind
06.
04.
02.
0
Figure 6.6: Three approximations to a sharp signal show smearing and oscillation.
Can
we
understand
this
behavior?
For a n ideal difference equation, we only want dissipation
very close to the shock.
This can avoid oscillation without losing accuracy. A lot of thought has gone into
high resolution met hods (Section 6.6), t o capture shock waves cleanly.
Modified equations
•
see lecture notes
Veque —
Real-world accuracy
AMath 585–6 Notes
183
Upwind:
Upwind solution at time 4
1
0.5
0
−0.5
0
1
2
3
4
5
6
Smeared out due to diffusive term in modified equations!
Lax−Wendroff solution at time 4
1
0.5
0
0.5
0
−0.5
0
Real-world accuracy
1
2
Lax-Wendroff:
3
4
5
6
4
5
6
Lax−Wendroff solution at time 4
1
0.5
0
−0.5
0
1
2
3
13.4: Numerical solution using upwind (diffusive) and Lax-Wendroff (dispersive) methods.
Dispersion due to term vxxx in modified equations
Lax-Wendroff
High
freq. modes travel slower (=> on the left of the envelope)
me procedure is followed for the Lax-Wendroff method, we find that all O(k) terms drop out of
fied equation, as is expected since this method is second order accurate on the advection equamodified equation obtained by retaining the O(k 2 ) term and then replacing time derivatives
l derivatives is
!
" #2 $
1 2
ak
vt + avx + ah 1 −
vxxx = 0.
(13.37)
R. J. LeVeque —
AMath 585–6 Notes
Phase vs. group velocity
time = 0
•
1
Remember from physics:
group
velocity
0.5
0
phase
velocity
−0.5
−1
−3
−2
−1
0
time = 0.4
1
0.5
0
−0.5
1
2
time = 0.8
1
0.5
0
ue —
Dispersion in LW scheme
AMath 585–6 Notes
187
−0.5
−1
−3
−2
−1
1
1
0.5
0.5
0
0
−0.5
−0.5
−1
−1
−2
−1
0
1
2
3
1
2
3
1
2
3
time = 1.2
time = 0
−3
0
1
2
−3
3
−2
−1
0
time = 1.6
time = 0.4
1
1
0.5
0.5
0
0
−0.5
−0.5
−1
−1
−3
−2
−1
0
1
2
3
−3
−2
−1
0
time = 0.8
Figure 13.6: The oscillatory wave packet satisfies the dispersive equation u t + aux + bu
shown is a black dot, translating at the phase velocity cp (ξ0 ) and a Gaussian that is tran
group velocity cg (ξ0 ).
1
0.5
0
−0.5
−1
−3
−2
−1
0
time = 1.2
1
1
2
3
Download