Title: Direct Numerical Simulations of Multiphase Flows
1Elementary Numerical Analysis Finite Difference
Approximations-I
Instructor Hong G. Im University of Michigan
Fall 2005
Lecture notes were prepared jointly with Prof.
Gretar Tryggvason, Department of Mechanical
Engineering, Worcester Polytechnic Institute.
2Objectives
Introduce the basic concepts needed to solve a
partial differential equation using finite
difference methods. Discuss basic time
integration methods, ordinary and partial
differential equations, finite difference
approximations, accuracy. Show the
implementation of numerical algorithms into
actual computer codes.
3Outline
- Time integration of an ordinary differential
equation - Integration methods
- Algorithm example
- Error analysis
- The linear advection-diffusion equation
- Finite difference approximations
- Finite Difference Approximation of the linear
- advection-diffusion equation
- Algorithm example
- Accuracy and error quantification
4Integration of Ordinary Differential Equations
in Time
5Integrating a first-order ordinary differential
equation in time
The initial condition must also be specified
6Time Integration
A numerical solution of
consists of discrete values of f at discrete times
7Time Integration
Start with
8Time Integration
To advance
Need to approximate this area to evaluate the
integral
9Time Integration
Approximate
Forward Euler
10Time Integration
Approximate
Backward Euler
11Time Integration
Approximate
Trapezoidal rule
12Time Integration
Summary
Forward Euler
Backward Euler
Trapezoidal Rule
13Example
14Accuracy
Take
15Accuracy
16A short code, using matlab
a simple code for several integration
methods nstep5dt0.5 f1zeros(nstep,1)f2zeros
(nstep,1) f3zeros(nstep,1) fexzeros(nstep,1)
tzeros(nstep,1) t(1)0f1(1)1f2(1)1f3(1)1
fex(1)1 for i2nstep f1(i)f1(i-1)-dtf1(i-
1) Forward Euler
f2(i)f2(i-1)/(1.0dt)
Backward Euler f3(i)f3(i-1)(1.0-0.5dt)/(1
.00.5dt) Trapezoidal Rule
t(i)t(i-1)dt fex(i)exp(-t(i)) end plot(t
,f1)hold onplot(t,f2,'r')plot(t,f3,'k') plot(t
,fex, 'r', 'linewidt',3) set(gca,'fontsize',24,'l
inewidt',2)
17Forward Euler
?t0.5
Backward Euler
Exact
Trapezoidal rule
Time
18Clearly the numerical solutions have the same
behavior as the exact solution but only the
trapezoidal rule results in numerical values that
are approximately the same. The obvious question
is
Can we improve the accuracy of the forward and
backward Euler method?
Re-run the forward Euler method with smaller time
steps
19Forward Euler
Accuracy, effect of ?t
?t0.5
?t0.25
Exact
?t0.125
Notice that the results are plotted versus time,
not time step n!
Time
20The error at t2.5, for the forward Euler Method,
defined by E fnum(2.5)-exp(-2.5)
21E fnum(2.5)-exp(-2.5)
? Forward Euler Backward Euler ? Trapezoidal
rule
As the time step becomes smaller, it is clear
that the error goes to zero
E
? t
22Error Analysis
23Analyze the error in evaluating the integral
using a Taylor series
24(No Transcript)
25The error at each time step is important, but it
is the total error, when integrating over a given
time period T that is most important. If the
number of time steps is N, the total error is
Since the number of time steps is NT/? t
First Order Method
26If the error is of n-th. order
On a log-log plot, the E versus 1/?t curve should
therefore have a slope of -n
27Error at t2.5 for different ?t
Plot the log of the Error versus log of (1/?t)
E
? Forward Euler Backward Euler Trapezoidal
rule
1/? t
28A finite difference approach
29Derive an approximation for the time derivative
using a Taylor series
30The original equation at time level n is