Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths...

23
Lecture 21 MA471 Fall 03

Transcript of Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths...

Page 1: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Lecture 21

MA471 Fall 03

Page 2: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Recall Jacobi Smoothing

• We recall that the relaxed Jacobi scheme:

• Smooths out the highest frequency modes fastest

1 11m m m x x f D A D x

Page 3: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Two Grid Algorithm

• First we smooth the solution for a number of steps:

1

1

for 1:

1

end

m

i

x x f D A D x

Page 4: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Next We Apply a Coarse Grid Correction

• Now suppose the current approximation xk satisfies the Ax=b system approximately:

• For some r

• We can figure out how much xk needs to be corrected by:

k r b Ax

1

1

k

k

r AA r b Ax

A x A r b

Page 5: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

cont

• So in an ideal world we could compute:

• And we would be done, as x solves Ax=b

• However, we noted before that the relaxed Jacobi solver does a good job of reducing the error in high-frequency modes so we can assume that the correction is a low frequency correction, so let’s compute the correction in * on a coarse grid.

1k x x A r*

1kc x x P A Rr

Page 6: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Restriction Step (Rr)

• The first step is to compute the residual r on the fine mesh and transfer it to the coarse mesh:

Periodic length

Fine

Coarse

The arrows indicate which fine nodes are linearly combined to obtain the coarse version

Page 7: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Formula For Restriction

2 1 2 2 1

12

4cn n n n r r r r

This is the restriction operator corresponding to the above formula for8 fine nodes and 4 coarse nodes:

We use a weighted average of the residual on the fine grid:

Page 8: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

The Coarse System Ac

• There is a certain freedom in how to build the coarse approximation to the system.

• A simple approach is to set up a matrix for the discrete heat equation, but using the coarse nodes.

Page 9: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Prolongation

• After having computed the correction on the coarse grid we need to transfer it to the fine grid.

• In this case we will preserve the correction values at nodes which belong to both coarse and fine grid.

• For other nodes we will use averaging.

Fine

Coarse

Page 10: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Formula For Prolongation of a Vector v

2 1

2 1

1

2

cn n

c cn n n

v v

v v v

Prolongation operator mapping a vector of 4 coarsevalues to 8 fine values.

Page 11: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Comparison of Prolongation and Restriction Matrices

Note R = 0.5*transpose(P)

Page 12: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Summary of Two-Grid Scheme

• Smooth a few times on the fine grid (using relaxed Jacobi iterations).

• Restrict the r=b-Ax residual to the coarse grid (Rr)

• Solve the coarse grid problem• Prolongate this correction to the fine grid ( )• Update the solution• Smooth a few more times to remove high-

frequency errors from prolongation and restriction

1c c A Rr

c x x PδcPδ

Page 13: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Summary:of a single stage of the two

grid iterative

algorithm

1

1

2

1

for 1:

1

end

for 1:

1

end

c

c

i

i

c

1c c

x x D b A D x

r b Ax

r Rr

δ A r

x x Pδ

x x D b A D x

Page 14: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

1

1

2

1

for 1:

1

end

for 1:

1

end

c

c

i

i

c

1c c

x x D b A D x

r b Ax

r Rr

δ A r

x x Pδ

x x D b A D x

1) Presmoothing:

2) Fine grid residual

3) Fine to coarse gridrestriction

4) Solving the coarsegrid analog

5) Prolongation andcoarse grid correction

6) Post smoothing:

Page 15: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Example: 1D Heat Equation

• I wrote a simple matlab code which solves the 1D equation (see previous lectures):

• On the unit interval [0,1) with periodicity.

2

2

dY f x

dx

Page 16: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Heatmatrix1d Routine

Page 17: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Set up fine grid system

Page 18: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

• Set up coarse grid system

• Set up sparse restriction and prolongation matrices

Page 19: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

80-82) presmooth

85) Coarse grid residual

88) Restriction and coarse gridcorrection solve

91) Prolongation and adding coarse grid correction to finegrid solution

94-96) post smoothing

98) Compute residual

Page 20: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Worst Possible Case

• So to see if the multigrid is working as advertised I set b=sin(2*pi*x) with initial guess x=0

• i.e. I activated one of the lowest frequency error modes.

• I ran relaxed Jacobi – which applies very little damping to the lowest error mode.

• I then ran the two-grid solver…

Page 21: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Comparison of Relaxed Jacobi and the Two Grid Solver

Two-grid: N=2560015 iterations and 2.694 seconds to achieve 10 decimal place convergence.

Relaxed Jacobi: N=25600590 iterations and 89.5680 seconds to achieve 10 decimal place convergence.

Page 22: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Summary

• By design the two-grid solver does indeed increase the decay rate for the lower frequency error modes.

• The results seem great for the two-grid solver – however, in this case we used an exact solve for the coarse grid problem. In reality this would normally be very expensive (although much less expensive than solving the full problem).

• In a multigrid solver we would replace the coarse grid solve with recursively applied smoothing on a sequence of successively coarser grids and apply the coarse grid correction on an extremely coarse grid.

Page 23: Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.

Next Time

• Spectral methods for solving simple PDE’s

• Description of final project options.