0% found this document useful (0 votes)
91 views43 pages

Lecture O03: ENGR90024 Computational Fluid Dynamics

This is a lecture note on CFD subject taught at University of Melbourne. It focuses on ODE topic. This is the 3rd lecture note on this subject

Uploaded by

Abdul Rahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views43 pages

Lecture O03: ENGR90024 Computational Fluid Dynamics

This is a lecture note on CFD subject taught at University of Melbourne. It focuses on ODE topic. This is the 3rd lecture note on this subject

Uploaded by

Abdul Rahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

ENGR90024

COMPUTATIONAL FLUID DYNAMICS

Lecture O03
Analysis of the Eulers Method!

Higher Order Taylor Method


In general, Eulers method is not very accurate because it is
derived by truncating Taylor series at t2.
Taylor series
(t

l+1

td
) = (t ) +
1! dt
l

tl

Eulers method

(t

l+1

t f (tl , l )
) = (t ) +
1!
l

To get a more accurate formula, we will derive a formula


by truncating Taylor series at t3

Taylor series
td
l+1
l
(t ) = (t ) +
1! dt

t2 d 2
+
2
2!
dt
l
t

tl

Taylor method order 2


2 2
t
t
d
l
l
l+1
l
f
(t
,
)
(t ) = (t ) +
+
1!
2! dt2

tl

t l
l+1
l
(t ) = (t ) +
f (t ,
1!

2 2
t
d
l
)+
2! dt2

t l
l+1
l
(t ) = (t ) +
f (t ,
1!

2
t
d d
l
)+
2! dt dt

t l
l+1
l
(t ) = (t ) +
f (t ,
1!

2
t
d
l
)+
f (t, (t))
2! dt

(t

(t

l+1

l+1

t l
) = (t ) +
f (t ,
1!
l

t l
) = (t ) +
f (t ,
1!
l

t
)+
2!
2

t
)+
2!

@f l
(t ,
@t

@f l
(t ,
@t

tl

tl

Chain rule
tl

@f l
)+
(t ,
@

@f l
)+
(t ,
@

)f (tl ,

d
)
dt
l

(tl+1 ) = (tl ) +

t l
f (t ,
1!

)+

t
2!

@f l
(t ,
@t

)+

@f l
(t ,
@

)f (tl ,

O03.1

Equation (O03.1) is called the Taylor Method order 2. It is!


more accurate than the Eulers method because it has a local!
truncation error O(t3)
Taylor method order 2
Advantage - More accurate
Disadvantage - Need to calculate derivatives of f(t,)

Example O03.1:
!

Using Taylors method order 2, solve

!
!
!
!
!

d
=1
dt

For 0 < t < 8 with (t=0)=0 and


a) t=2
b) t=1
c) t=0.5
d) t=0.1

Compare your solution with Eulers method

Taylors method order 2


(tl+1 ) = (tl ) +

t l
f (t ,
1!

)+

t
2!

@f l
(t ,
@t

)+

@f l
(t ,
@

We need to find all terms in the equation above


For this question

f (t, ) = 1
@f
=0
@t
@f
=
@

)f (tl ,

(tl+1 ) = (tl ) +

t l
f (t ,
1!

)+

t
l+1
l
(t ) = (t ) +
(1
1!

l+1

@f
=
@

@f
=0
@t

f (t, ) = 1

t
l
= +
(1
1!

t
2!

@f l
(t ,
@t

)+

@f l
(t ,
@

)f (tl ,

2
t
l
)+
0 + 1(1
2!

2
t
l
)+
1
2!

Eulers method!
Example O02.1
l+1

t(1

function MPO02p1()
clear all;
close all;
Delta_t=2.0;
t=0:Delta_t:8.0
phi(1)=0.0;

Taylor method order 2!


Example O03.1
l

Only need!
to change one!
line of code!

l+1

t
+
(1
1!

t2
)+
1
2!

function MPO03p1()
clear all;
close all;
Delta_t=0.5;
phi(1)=0.0;
t=0:Delta_t:8.0

for l=1:length(t)-1
phi(l+1)=phi(l)
+Delta_t*(1-phi(l))
end

for l=1:length(t)-1
phi(n+1)=phi(n)+Delta_t*(1phi(l))-(Delta_t^2/2)*(1-phi(l))
end

plot(t,phi,'ko-')
hold on
ezplot(@(t)1-exp(-t),
[0,8,0,2])
xlabel('t');
ylabel('\phi');
legend('Euler','True');

plot(t,phi,'ko-')
hold on
ezplot(@(t)1-exp(-t),[0,8,0,2])
xlabel('t');
ylabel('\phi');
legend('Euler','True');

function MPO03p1()
clear all;
close all;
Delta_t=0.5;
phi(1)=0.0;
t=0:Delta_t:8.0
for l=1:length(t)-1
phi(l+1)=phi(l)+Delta_t*(1-phi(l))-(Delta_t^2/2)*(1-phi(l))
end
plot(t,phi,'ko-')
hold on
ezplot(@(t)1-exp(-t),[0,8,0,2])
xlabel('t');
ylabel('\phi');
legend('Euler','True');

Output

1.6
1.4
1.2

Note: the
Taylor
method for
t=2 predicts
=0 for all
values of t!

Taylor 2nd Order


True

1.8

1
0.8
0.6
0.4
0.2
0

1.8

t=2.0

1.6

1.6

1.2

1.2

1.4

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

Taylor 2nd Order


True

t=1.0

1.8

1.4

4
t

1.6

1.2

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

4
t

4
t

t=0.1

Taylor 2nd Order


True

1.6

1.2

1.8

1.4

1.4

Taylor 2nd Order


True

t=0.5

1.8

Taylor 2nd Order


True

4
t

Taylor 2nd order

Euler
1exp(t)

2
Euler
True

1.8

1.4

1.4

t=1.0

1.2

1.2

1
0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0
0

4
t

4
t

1.4

1.6
1.4
1.2

1.2

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

4
t

Taylor 2nd Order


True

1.8

t=0.5

1.6

2
Euler
True

1.8

t=1.0

1.6

1.6

Taylor 2nd Order


True

1.8

t=0.5

4
t

For a given t, the Taylor 2nd order method is more accurate than
Euler

End of Example O03.1

STABILITY OF THE EXPLICIT


EULER METHOD
(SEE PAGE 8 PRINTED LECTURE NOTES)

In Lecture O02, we looked at the accuracy of the explicit Euler


method. Lets now look at the stability of the Euler method.!

We know from previous lecture, the smaller t, the more accurate


the solution, i.e. the truncation error go to zero. This feature is
known as consistency.!

When we make t big enough, the solution will blow up. Can we
predict the value of t where the solution will blow up? For a
numerical method to be useful, we need it to be stable.

Stability and consistency are two quite different things (see later). It is
possible for a method can be consistent but not stable.

If a numerical method is both consistent and stable, it is convergent.

To carry out stability analysis, consider the model problem

d
=
dt

(O03.2)

where is a constant and is a complex number

Re

+i

Im

In many engineering problems, Re is zero or negative. For


stability analysis, you will always assume that Re is zero or
negative.

Find analytical solution!


at time level lt

Strategy

d
=
dt

Compare
Find approximated Eulers!
solution at time level lt

The analytical solution for Eq. (O03.2) can be written as

(t)

1 (

Re t

ei

Re t

(cos(

e
e

t
Re +i Im )t
Im t

Im t)

where 1 is the initial value of

+ i sin(

Im t))

(t)

Re t

(cos(

Im t)

+ i sin(

(t)

Im

(t)

(t)

Im

(t)

(t)
Re
Re

Analytical solution will decay with time if lRe<0

Re

Im t))

(t)

Re t

(cos(

Im t)

+ i sin(

Im t))

Find analytical solution!


at time level lt

d
=
dt

Compare
Find approximated Eulers!
solution at time level lt

Applying Eulers formula for the model problem (Eq. (O03.2)) gives

l+1

= (1 +
=

t)

where = (1+t) is the amplification factor

(O03.3)

l+1

Thus, running a program using Eulers method will give you


1
2
3
4

..
.
l+1

=
=
=
=
=
=

Given
1
2
3

..
.

=
l

2 1

=
=
=

3 1

..
.
l 1

(O03.4)

For solution to be
stable!| | 1

| |2

1+

(1 +

Re

(1 +

Re ) + ( t

+i t
2

Im )
2

Im ) 1
Im

-2

-1

Re

Example O03.2:
!

Write a Matlab program that uses Eulers method to solve

!
!

!
!
!

d
=
dt

for 0 < t < 2 with (t=0)=1. Using the analysis from the previous slides, what
are the values of t for the numerical solution to be stable?

We have
d
= 8
dt
So for this problem =-8. So Re=-8 and Im=0.0. In order for the
numerical solution to be stable, t need to be within the stable
region.!
Im t

-8t, t large
-2

-1

Re

t0

8 t0
t 1/4

So for solution to !
be stable t must!
be between 0 and
0.25
Im

-2

-1

Re

function MPO03p2()
clear all;
close all;
Delta_t=0.01;
t=0:Delta_t:2.0;
%Preallocating memory
phi=zeros(size(t));
phi(1)=1.0;
for l=1:length(t)-1
phi(l+1)=phi(l)+Delta_t*(-8*phi(l));
end
plot(t,phi,'ko-')
hold on
ezplot(@(t)exp(-8*t),[0,2,-2,2])
xlabel('t');
ylabel('\phi');
legend('Euler','True');

100
Euler
True
80

t=0.5

60

0.5

40

Euler
True

t=0.25

1.5

20
0.5

20

40

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

0.2

1.5

0.8

1
t

1.2

1.4

1.6

1.8

0.5

0.5

0.5

0.5

1.5

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

Euler
True

t=0.01

1.5

t=0.1

0.6

Euler
True

0.4

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

100
Euler
True
80

t=0.5

60

0.5

40

Euler
True

t=0.25

1.5

20
0.5

20

40

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

0.2

1.5

0.8

1
t

1.2

1.4

1.6

1.8

0.5

0.5

0.5

0.5

1.5

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

Euler
True

t=0.01

1.5

t=0.1

0.6

Euler
True

0.4

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

Euler solution is unstable for t=0.5


Euler solution is neutrally stable for t=0.25
Euler solution is stable for t=0.1 & t=0.01

Im

-2

-4

-1

Re

100
Euler
True
80

t=0.5

60

40

20

t=

20

40

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

8 0.5 =

Im

-2

-1

t=0.25

1.5

Re

Euler
True

0.5

0.5

t=

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

8 0.25 =

Im

-2

-1

Re

2
Euler
True

t=0.1

1.5

0.5

0.5

t=

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

8 0.1 =

0.8

Im

-2

-1

Re

2
Euler
True

t=0.01

1.5

0.5

0.5

t=

1.5

0.2

0.4

0.6

0.8

1
t

1.2

1.4

1.6

1.8

8 0.01 =

0.08

End of Example O03.2

Consider now the case where is purely imaginary,

Re

+i

Im

d
=
dt

d
=i
dt

Im

For this case, iImt, is always on the vertical axis of the


stability diagram. It is not within the stability region. Hence,
in this case, Eulers method is always unstable.

Example O03.3:
!

Write a Matlab program that uses Eulers method to solve

!
!
!
!
!

d
= 2i
dt

for 0 < t < 10 with (t=0)=1. Using the analysis from the previous slides, what
are the values of t for the numerical solution to be stable?

d
= 2i
dt

0 t 10

(t = 0) = 1

The analytical solution for this problem can be written as

= Ae2it

= (ARe + iAIm )e2it

= (ARe + iAIm )(cos(2t) + i sin(2t))


= (ARe cos(2t)

AIm sin(2t)) + i(ARe sin(2t) + AIm cos(2t))

But we are given that =1 for t=0

1 + 0i = ARe + iAIm
Hence

ARe = 1
AIm = 0

d
= 2i
dt

0 t 10

= (ARe + iAIm )e2it

(t = 0) = 1

ARe = 1

AIm = 0

So the analytical solution for this equation is

(t)

e2it

cos(2t) + i sin(2t)

function MPO03p3()!
clear all;!
close all;!
Delta_t=0.02;!
!
!
t=0:Delta_t:10.0;!
%Preallocate Memory!
phi=zeros(size(t));!
phi(1)=1.0;!
!
!
for n=1:length(t)-1!
phi(n+1)=phi(n)+Delta_t*(i*2*phi(n));!
end!
!
plot(t,imag(phi),'ko-')!
xlabel('t');!
ylabel('\phi');!
hold on!
ezplot(@(t)sin(2*t),[0,10,-5,5])!
legend('Euler','True');

Im()
sin(2 t)

5
4

t=0.5

Euler
True

t=0.2

4
3

sin(2 t)

5
Euler
True

1
2

2
3

3
4

4
5

5
t

10

sin(2 t)

Euler
True

0
1

5
t

5
t

10

10

Euler
True

t=0.02

2
1

sin(2 t)

t=0.1

5
t

10

Im

t = 2i 0.5 = i

-1

Re

sin(2 t)

Euler
True

t=0.5

3
2
1

-2

0
1
2
3
4
5

10

Im

0.4i
t = 2i 0.2 = 0.4i

-1

Re

sin(2 t)

Euler
True

t=0.2

4
3
2
1

-2

0
1
2
3
4
5

10

Im

t = 2i 0.1 = 0.2i

0.2i

-1

Re

sin(2 t)

Euler
True

t=0.1

4
3
2
1

-2

0
1
2
3
4
5

5
t

10

Im

t = 2i 0.02 = 0.04i

0.04i
-1

Re

t
sin(2 t)

Euler
True

t=0.02

4
3
2
1

-2

0
1
2
3
4
5

10

For all values of t, t is outside the stable region. Hence


the numerical solution obtained using Eulers method will
never be stable for any value of t.

End of Example O03.3

You might also like