Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example...

11
Lecture 7 18.086

Transcript of Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example...

Page 1: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Lecture 718.086

Page 2: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Last time: Diffusion - Numerical scheme (FD)

• Heat equation is dissipative, so why not try Forward Euler:

Uj,n+1 � Uj,n

�t

=Uj+1,n � 2Uj,n + Uj�1,n

�x

2

• Expected accuracy: O(Δt) in time, O(Δx2) in space.

• Stability in the usual way gives

• We can use previous ODE methods using the old method of lines, of course…

• Or implicit methods (see book, 6.5). Notice that matrix contains O(Δx-2

) terms and is stiff!

R =�t

�x

2 1

2

Page 3: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Advection + diffusionFor incompressible flows, a concentration c advects and diffuses via a combination of a heat with 1-way wave equation:

1D: ct

= Dcxx

+ vcx

Remember: Diffusion is easy, but advection (1-way!) is tricky: numerical dispersion, oscillations (e.g. Lax-Wendroff). So, for Pe<<1, it is usually ok tojust solve the diffusion problem!

Peclet number measures dominance of diffusion vs. advection:

What about Pe>>1? Can we do the same (drop diffusion term)?

=cL

D

Page 4: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Advection + diffusionFor a characteristic scale of L0=D/c:

Lecture: Example

Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution significantly deviates from the pure advection solution u(x) = 0

L0=D/c=1/40

L0=D/c=1/10L0=D/c=1/20

~L0

Length scales below L0: Diffusion-dominated Length scales above L0: Advection-dominated

Page 5: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Advection + diffusionIn other words: To correctly resolve physics at smaller scales L<L0 (in particular inside the boundary layer!), one typically wants

We can express this using the Cell-Peclet number:

CFL for advection, e.g.

Stability for diffusion, e.g.

r = c

�t

�x

1

=> Can define Cell-Peclet number:P =

�x

2L0=

c�x

2D=

r

2R

�x L0

The difficulty is now to choose a numerical scheme that is good for advection & diffusion, while keeping P below 1 (to resolve small features, e.g. boundary layers)

R =D�t

�x

2 1

2

Page 6: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

FD schemes for AD problems

First try: Centered differences:

6.5 Diffusion, Convection, and Finance 509

The unreduced and reduced equations (U, + U, = 0 for E = 0) have exact solutions:

That pair has u = U a t the inflow boundaries, where x = 0 or y = 0. The fractional term in u(x, y) is very small. The outflow boundary has x = 1 or y = 1. Then the fraction increases quickly to give u = 0 a t outflow. This is correct for u in the unreduced equation and it is wrong for U in the limit equation.

The vertical layers in Figure 6.13b show the difference u - U. At the upper corner (x, y) = (1,l) the layer disappears and u = U = 0. That point is on a streamline from the characteristic inflow point (x, y) = (0,O). Jumps in the inflow conditions will propagate along the streamlines (two rivers in parallel with slow diffusion between them).

Streamline diffusion helps to resolve steep layers parallel to the wind w [47,98]. It is an extra diffusion c(wl u,, + w2 u,,), produced by changing the test functions. This is the way to move finite element equations from centered toward upwind. The IFISS codes [48] add cw - grad g5 to the test functions for streamline diffusion.

Finite Differences for Convection-Diffusion

In finite difference equations, the ratios r = cAtlAx and 2R = 2 d A t / ( A ~ ) ~ are dimensionless. That is why the stability conditions r 5 1 and 2R 5 1 were natural for the wave and heat equations. The new problem combines c u, with d u,, and the cell Peclet number P uses Ax12 as the length scale L in c Lld:

Cell Peclet Number

We still don't have agreement on the best finite difference approximation to use ! Here are three natural candidates (you may have an opinion after you try them):

1. Forward in time, centered convection, centered explicit diffusion

2. Forward in time, upwind convection, centered explicit diffusion

3. Explicit convection (centered or upwind), with implicit diffusion.

Each method will show the effects of r and R and P (we replace 7-12 by RP) :

Uj,n+l - Uj,n Uj+l,n - Uj-1,n 1. Centered explicit = c + d A: 4 , n At 2Ax AX)^ '

(37)

Using R and P, every new value Uj,n+l is a combination of three values at time n.

ut

= cux

+ duxx

Stable for R 1

2, |P | 1

510 Chapter 6 Initial Value Problems

Explicit U j , n + l = ( 1 - 2 R ) U j , n + ( R + R P ) U J + l , n + ( R - R P ) U J - 1 , n . (38)

Those three coefficients add to 1, and U = constant certainly solves equation (37). If all three coeficients are positive, the method is surely stable. More than that, oscillations will not appear. Positivity of 1 - 2R requires R 5 $, as usual for diffusion. Positivity of the other two coefficients requires IPI < - 1. In avoiding numerical oscillations, cell sizes Ax 5 2d/c are crucial to the quality of U .

Figure 6.14 from Strikwerda [146] shows the oscillations for P > 1. Notice how the initial hat function is smoothed and spread and shrunk by diffusion. The oscillations might pass the usual stability test IGI 5 1, but they are unacceptable.

Figure 6.14: Convection-diffusion with and without numerical oscillations from P > 1.

The one-sided accuracy has dropped to first order. But oscillations are eliminated whenever r + 2R 5 1. That condition ensures three positive coefficients in (39):

Arguments are still going, comparing the centered method and the upwind method. The difference between the two convection terms, upwind minus centered, is a diffusion term hidden in (39): this is an interesting identity !

Extra diffusion U,+l - U, - U3+1 - U,-l from upwind Ax 2Ax - (41)

So the upwind met hod has this extra numerical diffusion or "art.ificia1 viscosity." It is a non-physical damping and it reduces the accuracy. The upwind approximation is distinctly below the exact solution. Nobody is perfect.

3. Implicit diffusion Uj,n+l - Uj,n = C Uj+l,n - Uj,n + d a: u,,n+l

a t Ax (Ax)Z

Second order accurate in spacePotentially stable for P>1, but oscillations!

see Lecture

Page 7: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

FD schemes for AD problems

Upwind differences (c>0)ut

= cux

+ duxx

Stable for

510 Chapter 6 Initial Value Problems

Explicit U j , n + l = ( 1 - 2 R ) U j , n + ( R + R P ) U J + l , n + ( R - R P ) U J - 1 , n . (38)

Those three coefficients add to 1, and U = constant certainly solves equation (37). If all three coeficients are positive, the method is surely stable. More than that, oscillations will not appear. Positivity of 1 - 2R requires R 5 $, as usual for diffusion. Positivity of the other two coefficients requires IPI < - 1. In avoiding numerical oscillations, cell sizes Ax 5 2d/c are crucial to the quality of U .

Figure 6.14 from Strikwerda [146] shows the oscillations for P > 1. Notice how the initial hat function is smoothed and spread and shrunk by diffusion. The oscillations might pass the usual stability test IGI 5 1, but they are unacceptable.

Figure 6.14: Convection-diffusion with and without numerical oscillations from P > 1.

The one-sided accuracy has dropped to first order. But oscillations are eliminated whenever r + 2R 5 1. That condition ensures three positive coefficients in (39):

Arguments are still going, comparing the centered method and the upwind method. The difference between the two convection terms, upwind minus centered, is a diffusion term hidden in (39): this is an interesting identity !

Extra diffusion U,+l - U, - U3+1 - U,-l from upwind Ax 2Ax - (41)

So the upwind met hod has this extra numerical diffusion or "art.ificia1 viscosity." It is a non-physical damping and it reduces the accuracy. The upwind approximation is distinctly below the exact solution. Nobody is perfect.

3. Implicit diffusion Uj,n+l - Uj,n = C Uj+l,n - Uj,n + d a: u,,n+l

a t Ax (Ax)Z

0 r2 2R 1

r + 2R 1No oscillations for , because then all coefficients are positive:

510 Chapter 6 Initial Value Problems

Explicit U j , n + l = ( 1 - 2 R ) U j , n + ( R + R P ) U J + l , n + ( R - R P ) U J - 1 , n . (38)

Those three coefficients add to 1, and U = constant certainly solves equation (37). If all three coeficients are positive, the method is surely stable. More than that, oscillations will not appear. Positivity of 1 - 2R requires R 5 $, as usual for diffusion. Positivity of the other two coefficients requires IPI < - 1. In avoiding numerical oscillations, cell sizes Ax 5 2d/c are crucial to the quality of U .

Figure 6.14 from Strikwerda [146] shows the oscillations for P > 1. Notice how the initial hat function is smoothed and spread and shrunk by diffusion. The oscillations might pass the usual stability test IGI 5 1, but they are unacceptable.

Figure 6.14: Convection-diffusion with and without numerical oscillations from P > 1.

The one-sided accuracy has dropped to first order. But oscillations are eliminated whenever r + 2R 5 1. That condition ensures three positive coefficients in (39):

Arguments are still going, comparing the centered method and the upwind method. The difference between the two convection terms, upwind minus centered, is a diffusion term hidden in (39): this is an interesting identity !

Extra diffusion U,+l - U, - U3+1 - U,-l from upwind Ax 2Ax - (41)

So the upwind met hod has this extra numerical diffusion or "art.ificia1 viscosity." It is a non-physical damping and it reduces the accuracy. The upwind approximation is distinctly below the exact solution. Nobody is perfect.

3. Implicit diffusion Uj,n+l - Uj,n = C Uj+l,n - Uj,n + d a: u,,n+l

a t Ax (Ax)Z

First order accuracy…

Extra diffusion… see Lecture

Page 8: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Summary• Simple explicit schemes: Low accuracy and / or dispersion and / or

extra diffusion.

• Implicit schemes: Possible, unconditionally stable (see e.g. Crank-Nicholson scheme in book), but usually not efficient enough.

• Another possibility: Do everything explicit, except the problematic diffusion term:

510 Chapter 6 Initial Value Problems

Explicit U j , n + l = ( 1 - 2 R ) U j , n + ( R + R P ) U J + l , n + ( R - R P ) U J - 1 , n . (38)

Those three coefficients add to 1, and U = constant certainly solves equation (37). If all three coeficients are positive, the method is surely stable. More than that, oscillations will not appear. Positivity of 1 - 2R requires R 5 $, as usual for diffusion. Positivity of the other two coefficients requires IPI < - 1. In avoiding numerical oscillations, cell sizes Ax 5 2d/c are crucial to the quality of U .

Figure 6.14 from Strikwerda [146] shows the oscillations for P > 1. Notice how the initial hat function is smoothed and spread and shrunk by diffusion. The oscillations might pass the usual stability test IGI 5 1, but they are unacceptable.

Figure 6.14: Convection-diffusion with and without numerical oscillations from P > 1.

The one-sided accuracy has dropped to first order. But oscillations are eliminated whenever r + 2R 5 1. That condition ensures three positive coefficients in (39):

Arguments are still going, comparing the centered method and the upwind method. The difference between the two convection terms, upwind minus centered, is a diffusion term hidden in (39): this is an interesting identity !

Extra diffusion U,+l - U, - U3+1 - U,-l from upwind Ax 2Ax - (41)

So the upwind met hod has this extra numerical diffusion or "art.ificia1 viscosity." It is a non-physical damping and it reduces the accuracy. The upwind approximation is distinctly below the exact solution. Nobody is perfect.

3. Implicit diffusion Uj,n+l - Uj,n = C Uj+l,n - Uj,n + d a: u,,n+l

a t Ax (Ax)Z

Page 9: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Nonlinear transport & conservation laws

• What if transport becomes nonlinear?

Page 10: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Nonlinear transport & conservation laws

• A first attempt at understanding what is going on comes from analyzing the characteristic lines

• Simplest example:

6.6 Nonlinear Flow and Conservation Laws 519

We mention two proposals that in principle can pass all our tests (but the fourth requirement of computational eficiency is a constant challenge to everybody):

IV. Spectral methods (often in the form of "mortared" finite elements)

V. Discontinuous Galerkin (different polynomials within each element)

That list is almost a rough guide to conferences on computational engineering. Look for accuracies p > 10 in spectral methods and p > 4 in DG methods. For stability, finite volume methods can add diffusion. Finite differences can use upwinding.

This section will explain how p = 2 has been attained without oscillation at shocks. Nonlinear smoot hers are added to Lax- Wendroff (I think only nonlinear terms can truly defeat Gibbs). Do not underestimate that achievement. Second order accuracy is the big step forward, and oscillation was once thought to be unavoidable.

Burgers' Equation and Characteristics

The outstanding example, together with traffic flow, is Burgers' equat ion wi th flux f (u) = $u2. The "inviscid" equation has no viscosity vu,, to prevent shocks:

du lnviscid Burgers' equation

dx

We will approach this conservation law in three ways:

1. By following characteristics until they separate or collide (trouble arrives)

2. By an exact formula (17), which is possible in one space dimension

3. By finite difference and finite volume methods, which are the practical choice.

A fourth (good) way adds vu,,. The limiting u as v -+ 0 is the viscosity solution. Start with the linear equation ut = c u, and u(x, t) = u(x + ct, 0). The initial

value at xo is carried along the characteristic line x + ct = xo. Those lines are parallel when the velocity c is a constant. No chance that characteristic lines will meet.

The conservation law ut + uu, = 0 will be solved by u(x, t) = u(x - ut, 0). Every initial value uo = u(xo, 0) is carried along a characteristic line x - uot = xo. Those lines are not parallel because their slopes depend on the initial value uo. For the conservation law ut + f (u), = 0, the characteristic lines are x - f '(uo)t = xo.

Example 3 The formula u ( x , t ) = u ( x - ut, 0) involves u on both sides. I t gives the solution "implicitly." If u(x, 0) = 1 - x at the start, the formula must be solved for u:

1-x Solution u = 1 - (x - ut) gives (I - t)u = I - x and u = -

1 - t This u solves Burgers' equation, since ut = (1 - x) / ( l - t)2 is equal to -2121,.

• We can use the implicit ansatz

• Characteristics for initial conditions all meet in (x,t)=(1,1)!

u(x, t) = u(x� ut, 0)

u(x, 0) = 1� x

• Solution is not defined at (x,t)=(1,1) => so what do we do?

Lecture

Page 11: Lecture 7 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture7.pdf · 2016-02-25 · Lecture: Example Small L0=D/c (i.e. large Peclet number) creates a boundary layer, where the solution

Nonlinear transport & conservation laws

• A more famous example of issues with characteristics is the Riemann problem:

• Take again Burger’s equation:

6.6 Nonlinear Flow and Conservation Laws 519

We mention two proposals that in principle can pass all our tests (but the fourth requirement of computational eficiency is a constant challenge to everybody):

IV. Spectral methods (often in the form of "mortared" finite elements)

V. Discontinuous Galerkin (different polynomials within each element)

That list is almost a rough guide to conferences on computational engineering. Look for accuracies p > 10 in spectral methods and p > 4 in DG methods. For stability, finite volume methods can add diffusion. Finite differences can use upwinding.

This section will explain how p = 2 has been attained without oscillation at shocks. Nonlinear smoot hers are added to Lax- Wendroff (I think only nonlinear terms can truly defeat Gibbs). Do not underestimate that achievement. Second order accuracy is the big step forward, and oscillation was once thought to be unavoidable.

Burgers' Equation and Characteristics

The outstanding example, together with traffic flow, is Burgers' equat ion wi th flux f (u) = $u2. The "inviscid" equation has no viscosity vu,, to prevent shocks:

du lnviscid Burgers' equation

dx

We will approach this conservation law in three ways:

1. By following characteristics until they separate or collide (trouble arrives)

2. By an exact formula (17), which is possible in one space dimension

3. By finite difference and finite volume methods, which are the practical choice.

A fourth (good) way adds vu,,. The limiting u as v -+ 0 is the viscosity solution. Start with the linear equation ut = c u, and u(x, t) = u(x + ct, 0). The initial

value at xo is carried along the characteristic line x + ct = xo. Those lines are parallel when the velocity c is a constant. No chance that characteristic lines will meet.

The conservation law ut + uu, = 0 will be solved by u(x, t) = u(x - ut, 0). Every initial value uo = u(xo, 0) is carried along a characteristic line x - uot = xo. Those lines are not parallel because their slopes depend on the initial value uo. For the conservation law ut + f (u), = 0, the characteristic lines are x - f '(uo)t = xo.

Example 3 The formula u ( x , t ) = u ( x - ut, 0) involves u on both sides. I t gives the solution "implicitly." If u(x, 0) = 1 - x at the start, the formula must be solved for u:

1-x Solution u = 1 - (x - ut) gives (I - t)u = I - x and u = -

1 - t This u solves Burgers' equation, since ut = (1 - x) / ( l - t)2 is equal to -2121,.

• Riemann problem: How does solution evolve in time for initial conditions

520 Chapter 6 Initial Value Problems

When characteristic lines have different slopes, they can meet (carrying different uo). In this extreme example, all lines x - (1 - xo)t = xo meet at the same point x = 1, t = 1. The solution u = (1 - x ) / ( l - t) becomes 010 at that point. Beyond their meeting point, the characteristics cannot decide u(x, t).

A more fundamental example is the Riemann problem, which starts from two constant values u = A and u = B. Everything depends on whether A > B or A < B. On the left side of Figure 6.15, with A > B, the characteristics meet. On the right side, with A < B, the characteristics separate. In both cases, we don't have a single characteristic through each point that is safely carrying one correct initial value. This Riemann problem has two characteristics through some points, or none:

t t

A > B: shock A < B: fan

Figure 6.15: A shock when characteristics meet, a fan when they separate.

Shock Characteristics collide (light goes red: speed drops from 60 to 0) Fan Characteristics separate (light goes green: speed up from 0 to 60)

The Riemann problem is how to connect 60 with 0, when the characteristics don't give the answer. A shock will be sharp braking. Drivers only see the car ahead in this model. A fan will be gradual acceleration, as the cars speed up and spread out.

Shocks

After trouble arrives, the integral form will guide the choice of the correct solution u. Suppose u has different values UL and UR at points a = XL and b = XR on the left and right sides, close to the shock. Equation (1) decides where the jump must occur:

Integral form

Suppose the position of the shock is x = X ( t ) . Integrate from XL to X to XR. The values of u(x, t) inside the integral are close to the constants u~ and UR:

Left side XL, UL d . - [ ( X - X L ) ~ L + ( x R - X ) U R ] f f(uR)-f(uL) = O . (9) Right side XR, U R dt

u(x, 0) = A, x < 0 , and u(x, 0) = B, x � 0