22.520 numerical methods for pdes : video 9: 2d finite di
TRANSCRIPT
22.520 Numerical Methods for PDEs : Video 9: 2DFinite Difference Equations
David J. Willis
February 14, 2015
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 1 / 29
Thought Experiment
Let’s extend the string equation to a membrane:
∇2u =∂2u
∂x2+
∂2u
∂y2= f (x , y) (1)
Figure : The membrane problem domain.
With boundary conditions on both ends of:
uL = uR = 0 (2)
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 2 / 29
Thought Experiment
Goal: Satisfy the governing equation at each location on themembrane
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 3 / 29
Step 1: Discretization
Break membrane into a series of equally sized ”chunks”.Let’s break the membrane into N nodes in the x−direction and Mnodes in the y−direction:
Total number of nodes = N ∗M.∆x = ∆y → N = M.
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 4 / 29
Step 1: Discretization
Recall, we would like to satisfy the PDE at each node (equation pernode)To simplify life, let’s number the nodes
Relating the node number (NN) to m and n index:
NN = N ∗ (m − 1) + n
This node numbering scheme will become quite useful later.
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 5 / 29
Step 2: Discretize the Governing Equation
Governing equation: At each node of the domain, we wish to ensure:(∂2u
∂x2+
∂2u
∂y2
)i
= fi (x , y)
We can write the discrete finite difference equation:
un−1 − 2un + un+1
(∆x)2+
um−1 − 2um + um+1
(∆y)2' fn,m(x , y)
Finite Differences: Determine the solution u that satisfies theapproximate difference equations at each of the nodes of the discretedomain.
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 6 / 29
Step 2: Discretize the Governing Equation
Let’s look at node 12 to begin:(un−1,m − 2un,m + un+1,m
(∆x)2
)+
(un,m−1 − 2un,m + un,m+1
(∆y)2
)' fn,m
u1,3 − 2u2,3 + u3,3
(∆x)2+
u2,2 − 2u2,3 + u2,4
(∆y)2' f2,3
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 7 / 29
Step 2: Discretize the Governing Equation
Consider now, how the equation at node 12 looks when written usingthe node numbers (not m, n locations) :
u1,3 − 2u2,3 + u3,3
(∆x)2+
u2,2 − 2u2,3 + u2,4
(∆y)2' f2,3
u11 − 2u12 + u13
(∆x)2+
u7 − 2u12 + u17
(∆y)2' f12
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 8 / 29
Step 2: Discretize the Governing Equation
So, according to the node numbering scheme used here, the equationapproximating the PDE at node 12 is:
u11 + u13 + u7 + u17 − 4u12
(∆x)2' f12
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 9 / 29
Step 2: Discretize the Governing Equation
Let’s try this for node 13:
So, for node 13, the equation approximating the PDE is:
Node 13 :u12 + u14 + u8 + u18 − 4u13
(∆x)2' f13
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 10 / 29
Step 2: Discretize the Governing Equation
Let’s try this for node 18:
So, for node 18, the equation approximating the PDE is:
Node 18 :u17 + u19 + u13 + u23 − 4u18
(∆x)2' f18
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 11 / 29
Step 2: Discretize the Governing Equation
Summary: for the internal nodes
Node 12 :u11 + u13 + u7 + u17 − 4u12
(∆x)2' f12
Node 13 :u12 + u14 + u8 + u18 − 4u13
(∆x)2' f13
Node 18 :u17 + u19 + u13 + u23 − 4u18
(∆x)2' f18
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 12 / 29
Step 3: Form a Linear System of Equations
Each node’s finite difference equation has 5-unknowns
This will become a system of equations (recall multiplication of amatrix and a vector):
Node 12 :1
(∆x)2(u11 + u13 + u7 + u17 − 4u12) ' f12
1
(∆x)2
: . . . : : : : : : : . . . :0 . . . 1 . . . 0 . . . 1 −4 1 . . . 0 . . . 1 . . . :: . . . : : : : : : : . . . :
u1
:u7
:u11
u12
u13
:u17
:uN
=
f1
::::
f12
::::
uN
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 13 / 29
Step 3: Form a Linear System of Equations
Node 13 :1
(∆x)2(u12 + u15 + u8 + u18 − 4u13) ' f13
1
(∆x)2
: . . . : : : : : : : . . . :0 . . . 1 . . . 0 . . . 1 −4 1 . . . 0 . . . 1 . . . :: . . . : : : : : : : . . . :
u1
:u8
:u12
u13
u14
:u18
:uN
=
:::::
f13
::::
uN
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 14 / 29
Step 3: Form a Linear System of Equations
Node 18 :1
(∆x)2(u17 + u19 + u13 + u23 − 4u18) ' f18
1
(∆x)2
: . . . : : : : : : : . . . :0 . . . 1 . . . 0 . . . 1 −4 1 . . . 0 . . . 1 . . . :: . . . : : : : : : : . . . :
u1
:u13
:u17
u18
u19
:u23
:uN
=
f1
::::
f18
::::
uN
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 15 / 29
Step 3: Form a Linear System of Equations
This results in a linear system of equations, Au = f
Looking only at the A-matrix for right now:
Examining the Structure of A (for internal nodes):The value −4 is on the diagonal entry for equations with internal nodesThe value 1 is in the off diagonal entries
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 16 / 29
Step 3: Form a Linear System of Equations
Don’t forget to setup the RHS vector
In this example f = 1 at each of the internal nodes
f =
f1
:f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
:
=
0:0111001110:
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 17 / 29
Step 4: Incorporate Boundary Conditions
Introduce boundary conditions.We know that u = 0 at all boundary nodes
bottom : u1 = u2 = u3 = u4 = u5 = 0
top : u21 = u22 = u23 = u24 = u25 = 0
left : u6 = u11 = u16 = 0
right : u10 = u15 = u20 = 0
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 18 / 29
Step 4: Incorporate Boundary Conditions
Need to incorporate these boundary conditions into the A-matrix:Example: u22 = 0 = f22:
Make the 22nd-row of the A-matrix = 0Insert a value of 1 on the diagonal (A22,22 = 1)Set the 22nd-entry of the f-vector = 0 (f22 = 0)
When applied to all boundary conditions, the A-Matrix takes the form:
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 19 / 29
Step 4: RHS Vector Boundary Nodes
Don’t forget to setup the RHS vector
In this example RHS = 0 at each of the boundary nodes
f =
f1
:f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
:
=
0:0111001110:
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 20 / 29
Examine the A-Matrix Structure
The banded A-Matrix Structure (1, zeros,1,-4,1,zeros,1):
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 21 / 29
Examine the A-Matrix Structure
The A-Matrix Structure (21 x 21 nodes: Use, spy(A)):
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 22 / 29
Solve using matlab
Solve the linear system of equations using Matlab.
We will use the ’backslash’ operator in Matlab:
Solution = A\f (3)
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 23 / 29
Solution
Figure : Solution for N = M = 5,NumNodes = 25, Max Deflection = -0.06667
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 24 / 29
Solution
Figure : Solution for N = M = 11,NumNodes = 121, Max Deflection =-0.073010
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 25 / 29
Solution
Figure : Solution for N = M = 21,NumNodes = 441, Max Deflection =-0.07353
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 26 / 29
Solution
Figure : Solution for N = M = 41,NumNodes = 1681, Max Deflection =-0.07364
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 27 / 29
Starting to think about the Error
Figure : Convergence of the Max Deflection Value (compared withdeflection for N = 101)
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 28 / 29
What have we learned?
Finite difference expressions in 2D follow the same structure as 1D:
Approximate the PDE expression at nodes in the domainDetermine the solution at those nodes
The general steps for a finite difference problem are:
Step 1: Discretize the domain (in 1D: N − 1 intervals, N points).Step 2: Write finite difference equations that approximate governingequation at each internal node of the problemStep 3: Form a linear system (Ax = b)Step 4: Enforce the boundary conditions where relevantStep 5: Solve the system of equations
David J. Willis 22.520 Numerical Methods for PDEs : Video 9: 2D Finite Difference EquationsFebruary 14, 2015 29 / 29