Sunteți pe pagina 1din 17

1

Engineering Computation ECL8-1


ENGINEERING COMPUTATION Lecture 8

Stephen Roberts Michaelmas Term

Computing Solutions of Partial Differential Equations

Topics covered in this lecture:

1. Overview of second order partial differential equations

2. Numerical solution of
a. Elliptic PDEs (Laplace/Poisson equation)
b. Parabolic PDEs (diffusion equation)
c. Hyperbolic PDEs (wave equation)

And the error analysis (stability/convergence) of these approaches

Engineering Computation ECL8-2

Motivation


Partial differential equations (PDEs) arise in many engineering problems.


Special cases can be solved exactly using analytic methods (see PDE
lecture series notes)


In practice, numerical methods are essential


In this lecture, we consider PDEs involving two variables
.

For more sophisticated methods refer to textbooks (eg Burden & Faires
Ch12)

2
Engineering Computation ECL8-3
Example of PDE: Unsteady heat conduction equation
x
T
k q
x

=
( )
, , z y x T
x
x
T
k
x x
T
k q
x x
d
d
|
.
|

\
|

=
+
dx
dy
dz

Consider the temperature T of an elemental cube dxdydz inside a body made
of material conductivity k
c
, density , and specific heat capacity c.

There is a heat flux q
x
into the y-z face etc. Then, as shown on the diagram, the
total heat transfer into the cube in the x- direction is

( ) z y x
x
T
k z y x
x
T
k
x x
T
k
x
T
k z y q q
c c c c x x x
d d d d d d d d
2
2
d

=
)
`

|
|
.
|

\
|
|
.
|

\
|

=
+


Engineering Computation ECL8-4

The total heat transfer rate into the cube in all directions determines the rate at
which it heats up:
t
T
z y x c z y x
z
T
y
T
x
T
k
c

=
|
|
.
|

\
|

d d d d d d
2
2
2
2
2
2


This gives the Unsteady Diffusion Equation in 3 dimensions, a typical PDE

t
T
k
c
z
T
y
T
x
T


2
2
2
2
2
2
or
t
T
T

=
2

where
c
k
c
= is the thermal diffusivity of the material.
3
Engineering Computation ECL8-5

Some Special Cases
Case 1: If the heat conduction is steady state (i.e. 0 =

t
T
) we get
Laplaces Equation 0
2
2
2
2
2
2
2
= =

T
z
T
y
T
x
T
.

Case 3: Another PDE you know already, but perhaps not in three dimensions, is

The Wave Equation
2
2
2
2
2
2
2
2
2
t
V
c
z
V
y
V
x
V





Case 2: If there is a driving function on the right hand side, such as in electrostatics
with charge present, we get
Poissons Equation ( ) z y x f T
z
V
y
V
x
V
, ,
2
2
2
2
2
2
2
= =




Engineering Computation ECL8-6
Classification of Second-order Partial Differential Equations

The general form of second-order PDEs is:

( ) ( ) ( ) ( )
y x yy xy xx
V V V y x F f V y x c V y x b V y x a , , , , , , , = = + +

They are classified according to the values of a, b, c:

Equation
Type:
If Example Applications
Elliptic ac - b
2
> 0 Laplace Equation
0 = +
yy xx
V V
Steady Heat conduction.
Electrostatics.
Fluid flow
Parabolic ac - b
2
= 0 Diffusion equation
t xx
V V =
Unsteady heat conduction.
Water seepage.
EM fields in conductors
Hyperbolic ac - b
2
< 0 Wave equation
tt xx
V V =
Waves
Fluid flow

4
Engineering Computation ECL8-7
Since the coefficients a, b, c are all functions of the variables
in the problem, they may change value in different parts of the
solution area.

Equations may change type in different regions of the solution
space



The general form of second-order PDEs is:

( ) ( ) ( ) ( )
y x yy xy xx
V V V y x F f V y x c V y x b V y x a , , , , , , , = = + +

They are classified according to the values of a, b, c:
Engineering Computation ECL8-8
e.g. The Euler equations which describe compressible fluid flow are
elliptic if the flow is subsonic, but hyperbolic if it is supersonic.

This can happen in the flow-field around an aeroplane at
speeds just less than Mach 1, the speed of sound.

Solutions for the subsonic (elliptic) and supersonic
(hyperbolic) zones have to be obtained by different methods
and patched together!
5
Engineering Computation ECL8-9
Boundary Conditions for Second-order Partial Differential Equations

Generally, the solution area of a PDE is surrounded
by a boundary, conditions on which determine the
solution.

It is a Dirichlet or first boundary value problem
if T
b
is specified on the boundary.

It is a Neumann or second boundary value
problem if
n
T

, the normal derivative is


specified on the boundary.

It is a Mixed boundary value problem if T
b
and
n
T

, are specified on different


parts of the boundary.

n
T


T(x,y)
T
b
Boundary b
Engineering Computation ECL8-10
The General Approach
Approximate the continuous solution
domain by a discrete set of points
N j M i jk y ih x , 1 , , 1 , , = = = =
spaced at intervals h and k .
Note: we will start indexing at 1, since
MATLAB arrays start at 1. Many books
start at 0!
Then derive a suitable discrete
approximation to the PDE and choose a
suitable technique to solve it, subject to
the boundary conditions.
x = nh
y = jk
h
k
i,j i+1,j i-1,j
i,j +1
i,j -1
6
Engineering Computation ECL8-11





Numerical Solution of Elliptic Equations
(Laplace Equation)
Engineering Computation ECL8-12
Elliptic Example: Solve Laplaces Equation to obtain the steady
state temperature in the rectangular region x = 1 to 5, y = 1 to 5,
subject to the boundary conditions


which will have a peak of 100 in the (5,5) corner.

Step 1: Approximate the second derivatives in the 2-D Laplaces
equation

0
2
2
2
2
=

y
T
x
T


by the central difference formula from lecture 6 :

( ) ( ) 0
2 2
2
2
1 , , 1 , 2
2
, 1 , , 1
= +
+
+ +
+
+ +
k O
k
T T T
h O
h
T T T
j i j i j i j i j i j i
.

Put h = k (i.e. equal step size), and rearrange to give:

( ) ( )
2
1 , 1 , , 1 , 1 ,
4
1
h O T T T T T
j i j i j i j i j i
+ + + + =
+ +


T(1,:) = [0 25 50 75 100] and T(:,5) = [100 75 50 25 0].
7
Engineering Computation ECL8-13
Solving the Discrete Approximation Equation

For fixed boundary conditions, this is a set of ( )( ) 2 2 N M
simultaneous equations, ( )( ) 9 2 5 2 5 = in this example, which
could be solved completely by, say, Gaussian elimination. Note that
the matrices will be sparse, with few non-zero elements, and direct
solution could be lengthy for, e.g., a 5050 domain!

Alternatively, we take an initial guess at the solution set T(ih,kh) and
iterate by applying the above algorithm to update all points on the
solution area one step at a time.
Seen this before? It is very similar to the Jacobi algorithm used in
Lecture 3.

It is an Implicit Method since the values at the point (i,j) depend on
the four surrounding points, and we must update all the values at
each iteration stage.

Error analysis: It can be shown to converge with an error ) ( 0
2 2
k h +

( ) ( )
2
1 , 1 , , 1 , 1 ,
4
1
h O T T T T T
j i j i j i j i j i
+ + + + =
+ +
Engineering Computation ECL8-14
Lets try it out with MATLAB:

function [T2] = Laplace1(T1,N)
% Computes solution of Laplace's equation
% with T1 as starting value.
%
% Boundary conditions are the edges of T1.
% It performs N iterations and prints out the arrays
% on each iteration.

[TM,TN] = size(T1); %Get size of T1

T2 = T1;
T2new = T2;
fprintf('\n');

for n=1:N %N iterations
fprintf('Iteration number %3.0f \n', n);
fprintf('%3.0f',T2(1,:));
fprintf('\n');

8
Engineering Computation ECL8-15
for i = 2:TM-1
for j = 2:TN-1
T2new(i,j) = (T2(i+1,j)+T2(i-1,j)+T2(i,j+1)+T2(i,j-1))/4;
end
fprintf('%3.0f',T2new(i,:));
fprintf('\n');
end
fprintf('%3.0f',T2new(TM,:));
fprintf('\n');
fprintf('\n');
pause
T2 = T2new;
end
Engineering Computation ECL8-16
Here are the results for a starting point with T(1,:) = [0 25 50 75 100] and
T(:,5) = [100 75 50 25 0].
Iteration number 1
0 0 0 0 0
25 6 0 0 0
50 13 0 0 0
75 38 13 6 0
100 75 50 25 0
Iteration number 2
0 0 0 0 0
25 9 2 0 0
50 23 6 2 0
75 44 23 9 0
100 75 50 25 0
Iteration number 3
0 0 0 0 0
25 13 4 1 0
50 27 13 4 0
75 49 27 13 0
100 75 50 25 0
Iteration number 4
0 0 0 0 0
25 14 6 2 0
50 31 16 6 0
75 51 31 14 0
100 75 50 25 0
Iteration number 5
0 0 0 0 0
25 16 8 3 0
50 33 19 8 0
75 53 33 16 0
100 75 50 25 0
Iteration number 6
0 0 0 0 0
25 16 9 4 0
50 34 20 9 0
75 54 34 16 0
100 75 50 25 0
Iteration number 7
0 0 0 0 0
25 17 10 5 0
50 35 22 10 0
75 55 35 17 0
100 75 50 25 0
Iteration number 8
0 0 0 0 0
25 18 11 5 0
50 36 23 11 0
75 55 36 18 0
100 75 50 25 0
Iteration number 9
0 0 0 0 0
25 18 11 5 0
50 36 23 11 0
75 55 36 18 0
100 75 50 25 0
9
Engineering Computation ECL8-17
Starting values with zero everywhere except at (x,0) and (0,y)
Engineering Computation ECL8-18
Final solution surface
10
Engineering Computation ECL8-19
Other Solution Methods



For large systems a method such as Successive-Over-Relaxation is
often used in practice as this has good resistance to round-off errors
(see Lecture 3).


Dont forget that for small systems you can use Gaussian Elimination
Engineering Computation ECL8-20





Numerical Solution of Parabolic Equations
(Diffusion Equation)
11
Engineering Computation ECL8-21

Numerical methods for Parabolic PDEs

Again, approximate the continuous solution domain by a discrete set of points

N j M i jk t ih x , 1 , , 1 , , = = = =

spaced at intervals h and k .

Then derive a suitable discrete approximation to the PDE and choose a suitable
technique to solve it, subject to the boundary conditions.

Engineering Computation ECL8-22

.Finding the Discrete Approximation Equation

In this case, we can use a central difference approximation in space
x but a forward difference in time t :
the diffusion equation
t
T
x
T

2
2
becomes
( ) ( ) k O
k
T T
h O
h
T T T
j i j i j i j i j i
+ |
.
|

\
|
= +
+
+ + , 1 , 2
2
, 1 , , 1
2


Rearranging this,
( ) ( ) ( )
2 2
, 1 , , 1 2 , 1 ,
2 kh O k O T T T
h
k
T T
j i j i j i j i j i
+ + + + =
+ +



Example: Solve Diffusion Equation to obtain the transient
temperature ithrough a one-dimensional region x = 1 to 10, subject
to the boundary conditions

T(x,1) = 0, T(1,t) = 100. In other words, the temperature in a bar
which has one end suddenly raised by 100 while the other end
T(10,t) = 0.is kept cold.

12
Engineering Computation ECL8-23
Rearranging this,
( ) ( ) ( )
2 2
, 1 , , 1 2 , 1 ,
2 kh O k O T T T
h
k
T T
j i j i j i j i j i
+ + + + =
+ +

This is an Explicit
formula which gives the temperatures in
row j+1 in terms of row j .
i,j
i+1,j i-1,j
i,j +1
Solution of Discrete Approximation Equations
Thus the calculation can be progressed row by
row from the initial condition, T(x,1), and the
changes of T with time t can be calculated
directly in a progressive fashion.
Engineering Computation ECL8-24
Of course, the error ( ) ( )
2 2
kh O k O + is different in the xand t direction, and the accuracy of
the final result may depend on a suitable choice of r =
2
h
k

. Analysis shows that the method converges if


2
1
r .
Error Analysis
(i.e. it is conditionally stable)
(the update weighting factor)
13
Engineering Computation ECL8-25
Lets take r = 0.4, and modify our MATLAB code, to diffuse1(T1,r) using the loop
for j=1:TN-1 %TN -1 time steps
for i = 2:TM-1 % calculate a new column
T2(i,j+1) = T2(i,j) + r*(T2(i+1,j)+ -2*T2(i,j) + T2(i-1,j));
end
end
to give:
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
0 40 48 56 60 64 66 69 70 72 73 74 75 76 77 78 78 79 80 80
0 0 16 22 29 34 38 42 45 47 49 51 53 54 56 57 58 59 60 61
0 0 0 6 10 15 18 22 25 28 30 32 34 36 38 39 41 42 44 45
0 0 0 0 3 5 7 10 12 14 16 19 20 22 24 26 27 28 30 31
0 0 0 0 0 1 2 3 5 6 8 10 11 13 14 15 17 18 19 20
0 0 0 0 0 0 0 1 2 2 3 4 5 6 7 9 10 11 12 13
0 0 0 0 0 0 0 0 0 1 1 2 2 3 4 4 5 6 6 7
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 2 2 2 3 3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
In this case, increasing time is horizontal, and the solution is beginning to approach the
steady state at the right hand end.
Engineering Computation ECL8-26

this is clearly seen on the 3-
D plot

If a value of r greater than
0.5 is chosen, then the
solution blows up and
diverges!

0
5
10
15
20
0
5
10
0
20
40
60
80
100
time
Diffusion equation
distance
T
e
m
p
e
r
a
t
u
r
e
14
Engineering Computation ECL8-27
Other Solution Methods



More robust, but more complex, methods (e.g. the Crank-Nicholson
method) are described in the text books.


In particular, the Crank-Nicholson method is unconditionally stable
and has an order of convergence ) (
2 2
h k O +
Engineering Computation ECL8-28





Numerical Solution of Hyperbolic Equations
(Wave Equation)
15
Engineering Computation ECL8-29

Numerical methods for Hyperbolic PDEs

These can usually be solved by an Explicit numerical technique, similar to that for
parabolic equations.

For example, take the one-dimensional wave equation,
scaled to unity phase velocity (c = 1),
2
2
2
2
t
V
x
V

.

Use central difference formula to give

( ) ( )
2
2
1 , , 1 , 2
2
, 1 , , 1
2 2
k O
k
V V V
h O
h
V V V
j i j i j i j i j i j i
+
+
= +
+
+ +


If we use a square grid, h = k, the V
i,j
term drops
out, and we get the recurrence relation

( )
2
1 , , 1 , 1 1 ,
h O V V V V
j i j i j i j i
+ + =
+ +


i,j-1
i,j
i+1,j i-1,j
i,j+1
Engineering Computation ECL8-30
Error Analysis



As with parabolic equation solution, the method is conditionally stable
i.e. will only converge if 1 / h k


(for the proof and discussion of the general case see, for example,
Burden and Faires 4
th
Edition, p. 704)



16
Engineering Computation ECL8-31
Solving initialisation problems:

1. The method involves 3 time steps as V
i,j+1
depends on V
i,j-1
, two
rows back in the scheme.
2. We need two initial conditions, the initial displacements V
i,1
and the
initial velocities, or gradients g
i,1.


Using the central difference formula for the first derivative,

k
V V
g
i i
i
2
0 , 2 ,
1 ,

= .
So, set 1 2 2
1 , 2 , 1 , 2 , 0 ,
= = = k g V kg V V
i i i i i
for .

Thus the first step becomes

1 , 2 , 1 , 1 1 , 1 0 , 1 , 1 1 , 1 2 ,
2
i i i i i i i i
g V V V V V V V + = + =
+ +


Or ( )
1 , 1 , 1 1 , 1 2 ,
2
2
1
i i i i
g V V V + =
+
.

We can then step through the remainder of the numerical solution as
before using
1 , , 1 , 1 1 , + +
+ =
j i j i j i j i
V V V V

Engineering Computation ECL8-32
Propagation of standing wave from initial displacement
17
Engineering Computation ECL8-33
Standing wave solution
Engineering Computation ECL8-34
Summary



This lecture has introduced using finite-difference methods to solve PDEs
with 2 variables

This led us to consider iterative solutions.

For explicit methods, stability is an issue (parameters h and k have
constraints)

For implicit methods, stability is guaranteed.


Finite Element Methods are the natural extension of the ideas
described in this lecture. This approach more easily handles boundary
conditions involving derivatives and irregular shaped boundaries.

S-ar putea să vă placă și