100% found this document useful (1 vote)
648 views

Lecture 4 Finite Difference PDF

The document discusses the history and development of finite difference methods and computational fluid dynamics (CFD). It covers: 1) Leonhard Euler introduced the finite difference technique in 1768 based on Taylor series expansion. 2) Lewis Fry Richardson developed the first numerical weather prediction system in 1922 using finite difference approximations on a gridded domain, though his initial attempt took 6 weeks to calculate an 8-hour forecast. 3) Early CFD solutions in the 1930s-1950s required extensive manual calculation. Commercial CFD codes emerged in the 1980s-1990s, making CFD more accessible.

Uploaded by

Mega Games
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
648 views

Lecture 4 Finite Difference PDF

The document discusses the history and development of finite difference methods and computational fluid dynamics (CFD). It covers: 1) Leonhard Euler introduced the finite difference technique in 1768 based on Taylor series expansion. 2) Lewis Fry Richardson developed the first numerical weather prediction system in 1922 using finite difference approximations on a gridded domain, though his initial attempt took 6 weeks to calculate an 8-hour forecast. 3) Early CFD solutions in the 1930s-1950s required extensive manual calculation. Commercial CFD codes emerged in the 1980s-1990s, making CFD more accessible.

Uploaded by

Mega Games
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 96

Computer Aided Design

Lecture 5
Finite Difference

Dr./ Ahmed Nagib Elmekawy


Leonhard Euler (1707-1783)
• In 1768, Leonhard Euler introduced the finite
difference technique based on Taylor series
expansion.

2
Lewis Fry Richardson (1881-1953)
• In 1922, Lewis Fry Richardson developed the first numerical
weather prediction system.
• Division of space into grid cells and the finite
difference approximations of Bjerknes's
"primitive differential equations.”
• His own attempt to calculate weather for a single
eight-hour period took six weeks and ended in
failure.
• His model's enormous calculation requirements led Richardson
to propose a solution he called the “forecast-factory.”
• The "factory" would have filled a vast stadium
with 64,000 people.
• Each one, armed with a mechanical calculator,
would perform part of the calculation.
• A leader in the center, using colored signal lights
and telegraph communication, would coordinate
the forecast.
3
1930s to 1950s
• Earliest numerical solution: for flow past a cylinder (1933).
• A.Thom, ‘The Flow Past Circular Cylinders at Low Speeds’, Proc. Royal Society, A141, pp.
651-666, London, 1933
• Kawaguti obtained a solution for flow around a cylinder, in 1953 by
using a mechanical desk calculator, working 20 hours per week for 18
months, citing: “a considerable amount of labour and endurance.”
• M. Kawaguti, ‘Numerical Solution of the NS Equations for the Flow Around a Circular
Cylinder at Reynolds Number 40’, Journal of Phy. Soc. Japan, vol. 8, pp. 747-757, 1953.

4
1960s and 1970s
• During the 1960s the theoretical division at Los Alamos contributed many numerical
methods that are still in use today, such as the following methods:
• Particle-In-Cell (PIC).
• Marker-and-Cell (MAC).
• Vorticity-Streamfunction Methods.
• Arbitrary Lagrangian-Eulerian (ALE).
• k- turbulence model.
• During the 1970s a group working under D. Brian Spalding, at Imperial College, London,
develop:
• Parabolic flow codes (GENMIX).
• Vorticity-Streamfunction based codes.
• The SIMPLE algorithm and the TEACH code.
• The form of the k- equations that are used today.
• Upwind differencing.
• ‘Eddy break-up’ and ‘presumed pdf’ combustion models.
• In 1980 Suhas V. Patankar publishes Numerical Heat Transfer and Fluid Flow, probably
the most influential book on CFD to date.

5
1980s and 1990s
• Previously, CFD was performed using academic, research
and in-house codes. When one wanted to perform a CFD
calculation, one had to write a program.
• This is the period during which most commercial CFD
codes originated that are available today:
• Fluent (UK and US).
• CFX (UK and Canada).
• Fidap (US).
• Polyflow (Belgium).
• Phoenix (UK).
• Star CD (UK).
• Flow 3d (US).
• ESI/CFDRC (US).
• SCRYU (Japan).
• and more, see www.cfdreview.com.

6
Navier-Stokes Equation Derivation

• Refer to
• Ch. 3 and Appendix A of
• Jiyuan Tu, Computational Fluid Dynamics -A Practical Approach, Second Edition,
2013.
• Ch. 2
• Wendt, Anderson, Computational Fluid Dynamics - An Introduction, 3rd edition 2009.
7
LAGRANGIAN AND EULERIAN DESCRIPTIONS
Kinematics: The study of motion.
Fluid kinematics: The study of how fluids flow and how to describe fluidmotion.
There are two distinct wa ys to describe motion: Lagrangian a n d Eulerian
Lagrangian description: To follow the path of individual objects.
This method requires us to track the position and velocity of each individual
fluid parcel (fluid particle) and take to be a parcel of fixedidentity.

With a small number of objects, such In the Lagrangian description, one


a s billiard balls on a pool table, must keep track of the position and
individual objects can be tracked. velocity of individual particles. 4

8
• A more common method is Eulerian description of fluid motion.
• In the Eulerian description of fluid flow, a finite volume called a flow domain
or control volume is defined, through which fluid flows in and out.
• Instead of tracking individual fluid particles, we define field variables,
functions of space and time, within the control volume.
• The field variable at a particular location at a particular time is the value of
the variable for whichever fluid particle happens to occupy that location at
that time.
• For example, the p r e s s u r e field is a scalar field variable. We define the
velocity field a s a vector field variable.

Collectively, these (and other) field variables define the flow field. The
velocity field can be expanded in Cartesian coordinates a s

9
• In the Eulerian description we
don’t really care what happens to
individual fluid particles; rather we
are concerned with the pressure,
velocity, acceleration, etc., of
whichever fluid particle happens
to be at the location of interest at
the time of interest.
• While there are many occasions in
which the Lagrangian description
is useful, the Eulerian description
In the Eulerian description, one is often more convenient for fluid
defines field variables, such as mechanics applications.
the pressure field and the
velocity field, at any location • Experimental measurements are
and instant in time. generally more suited to the
Eulerian description.

1
0

10
CONSERVATION OF MASS—THE CONTINUITY
EQUATION

The net rate of change of mass within the


control volume is equal to the rate at
which mass flows into the control volume
minus the rate at which mass flows out of
the control volume.

To derive a differential
conservation equation, we
imagine shrinking a control
volume to infinitesimal size.

1
1

11
12
13
Conservation of Mass: Alternative forms
• Use product rule on divergence term

   
V =u i +v j +w k
      
= i + j+ k
x y z
Conservation of Mass: Cylindrical coordinates
• There are many problems which are simpler to solve if the
equations are written in cylindrical-polar coordinates
• Easiest way to convert from Cartesian is to use vector
form and definition of divergence operator in cylindrical
coordinates
Conservation of Mass: Cylindrical coordinates
Conservation of Mass: Special Cases
• Steady compressible flow

 ( u )  ( v)  ( w)
Cartesian + + =0
x y z
Cylindrical
Conservation of Mass: Special Cases
• Incompressible flow

 = constant, and hence

   
V =u i +v j +w k
      
= i + j+ k
x y z
u v w
+ + =0
Cartesian x y z

Cylindrical
Conservation of Mass
• In general, continuity equation cannot be used by
itself to solve for flow field, however it can be used
to
1. Determine if a velocity field represents a flow.
2. Find missing velocity component
Example
For an incompressible flow
u = x2 + y2 + z 2
v = xy + yz + z
w=?
Determine : w , required to satisfy the continuity equation.
z2
Solution : w = −3 xz − + c( x, y )
2
Conservation of Momentum
Types of forces:
1. Surface forces: include all forces acting on the
boundaries of a medium though direct contact such
as pressure, friction,…etc.
2. Body forces are developed without physical contact
and distributed over the volume of the fluid such as
gravitational and electromagnetic.
• The force F acting on A may be resolved into two
components, one normal and the other tangential to
the area.
2
4

If the differential fluid


element is a material
element, it moves with the
flow and Newton’s second
law applies directly.
Body Fo rc e s

Positive components of the stress


tensor in Cartesian coordinates on the
positive (right, top, and front) faces of
an infinitesimal rectangular control
volume. The blue dots indicate the
center of each face. Positive
components on the negative (left,
bottom, and back) faces are in the
opposite direction of those shown here.

25
Stresses (forces per unit area) Surface of
Surface of constant x
constant -x

Double subscript notation for stresses.


• First subscript refers to the surface
• Second subscript refers to the direction
• Use  for normal stresses and  for tangential stresses
27
28
29
30
31
32
33
Complete Navier–Stokes equations

34
3
5

Newtonian ve rs u s Non-Newtonian Fluids

Rheology: The study of the


deformation of flowing fluids.
Newtonian fluids: Fluids for which the
shear stress is linearly proportional to the
shear strain rate.
Non-Newtonian fluids: Fluids for which the
shear stress is not linearly related to the
shear strain rate.
Viscoelastic: A fluid that returns (either
fully or partially) to its original shape after
the applied stress is released.

Rheological behavior of fluids—shear


stress a s a function of shear strain rate. Some non-Newtonian fluids are called
s h e a r thinning fluids or
p s eu d o pl as tic fluids, because the
In some fluids a finite stress called the more the fluid is sheared, the less
yield s t r e s s is required before the viscous it becomes.
fluid begins to flow at all; such fluids
Plastic fluids are those in which the
are called Bingham plastic fluids.
shear thinning effect is extreme.
36
3
7

Derivation of the Navier–Stokes Equation for


Incompressible, Isothermal Flow
The incompressible flow
approximation implies constant
density, and the isothermal
approximation implies constant
viscosity.
38
Navier-Stokes Equations
u u u u p  u 2  
 ( + u + v + w ) = g x − + [  (2 − .V )]
t x y z x x x 3
x-
 v u  w u momentum
+ [  ( + )] + [  ( + )] (a)
y x y z x z
v v v v p  v u
 ( + u + v + w ) = g y − + [  ( + )]
t x y z y x x y y-
momentum
 v 2    v w
+ [  (2 − .V )] + [  ( + )] (b)
y y 3 z z y
w w w w p  w u
( + u +v + w ) = g z − + [  ( + )]
t x y z z x x z z-
momentum
 v w  w 2  
+ [  ( + )] + [  (2 − .V )] (c )
y z y z z 3
Navier-Stokes Equations
• For incompressible fluids, constant µ:
• Continuity equation: .V = 0
 u 2    v u  w u
[  (2 − .V )] + [  ( + )] + [  ( + )] =
x x 3 y x y z x z
 u  v u  w u
{ [(2 )] + [( + )] + [( + )]} =
x x y x y z x z
 2u  2u  2u  2u  2 v  2 w
( 2 + 2 + 2 ) + ( 2 + + )=
x y z x xy xz
 2u  2u  2u  u v w
( 2 + 2 + 2 ) +  ( + + ) =
x y z x x y z
 2u  2u  2u
 ( 2 + 2 + 2 ) =  2u
x y z
Navier-Stokes Equations
• For incompressible flow with constant dynamic viscosity:

Du p  2u  2u  2u
• x- momentum  = g x − +  ( 2 + 2 + 2 ) (a)
Dt x x y z

Dv p  2v  2v  2v
• Y- momentum  = g y − +  ( 2 + 2 + 2 ) (b)
Dt y x y z

Dw p 2w 2w 2w


• z-momentum  = g z − +  ( 2 + 2 + 2 ) (c )
Dt z x y z
• In vector form, the three equations are given by:

DV   Incompressible NSE
 = g − p +  V
2

Dt written in vector form


Navier-Stokes Equations
u u u u p  u 2  
 ( + u + v + w ) = g x − + [  (2 − .V )]
t x y z x x x 3
x-momentum
 v u  w u
+ [  ( + )] + [  ( + )] (a)
y x y z x z
v v v v p  v u
 ( + u + v + w ) = g y − + [  ( + )]
t x y z y x x y y-momentum
 v 2    v w
+ [  (2 − .V )] + [  ( + )] (b)
y y 3 z z y
w w w w p  w u
( + u +v + w ) = g z − + [  ( + )]
t x y z z x x z z-momentum
 v w  w 2  
+ [  ( + )] + [  (2 − .V )] (c )
y z y z z 3
Navier-Stokes Equations
• For incompressible fluids, constant µ:
• Continuity equation: .V = 0
 u 2    v u  w u
[  (2 − .V )] + [  ( + )] + [  ( + )] =
x x 3 y x y z x z
 u  v u  w u
{ [(2 )] + [( + )] + [( + )]} =
x x y x y z x z
 2u  2u  2u  2u  2 v  2 w
( 2 + 2 + 2 ) + ( 2 + + )=
x y z x xy xz
 2u  2u  2u  u v w
( 2 + 2 + 2 ) +  ( + + ) =
x y z x x y z
 2u  2u  2u
 ( 2 + 2 + 2 ) =  2u
x y z
Navier-Stokes Equations
• For incompressible flow with constant dynamic viscosity:

• x- momentum Du p  2u  2u  2u
 = g x − +  ( 2 + 2 + 2 ) (a)
Dt x x y z

• Y- momentum Dv p  2v  2v  2v
 = g y − +  ( 2 + 2 + 2 ) (b)
Dt y x y z

• z-momentum Dw p  2
w  2
w  2
w
 = g z − +  ( 2 + 2 + 2 ) (c )
Dt z x y z
• In vector form, the three equations are given by:

DV   Incompressible NSE
 = g − p +  V
2

Dt written in vector form


Navier-Stokes Equation
• The Navier-Stokes equations for incompressible flow in
vector form:

Incompressible NSE
written in vector form

• This results in a closed system of equations!


• 4 equations (continuity and 3 momentum equations)
• 4 unknowns (u, v, w, p)
• In addition to vector form, incompressible N-S equation can
be written in several other forms including:
• Cartesian coordinates
• Cylindrical coordinates
• Tensor notation
Euler Equations
• For inviscid flow (µ = 0) the momentum equations are given by:

• x- momentum u u u u p
 ( + u + v + w ) = g x − (a)
t x y z x

v v v v p
• Y- momentum  ( + u + v + w ) = g y − (b)
t x y z y

w w w w p
• z-momentum ( + u +v + w ) = g z − (c )
t x y z z
• In vector form, the three equations are given by:

DV 
 = g − p Euler equations
Dt written in vector form
Differential Analysis of Fluid Flow Problems

• Now that we have a set of governing partial differential equations,


there are 2 problems we can solve
• Calculate pressure (P) for a known velocity field
• Calculate velocity (U, V, W) and pressure (P) for known geometry, boundary
conditions (BC), and initial conditions (IC)
• There are about 80 known exact solutions to the NSE
• Solutions can be classified by type or geometry, for example:
1. Couette shear flows
2. Steady duct/pipe flows (Poisseulle flow)
Exact Solutions of the NSE
Procedure for solving continuity and NSE
1. Set up the problem and geometry, identifying all relevant
dimensions and parameters
2. List all appropriate assumptions, approximations,
simplifications, and boundary conditions
3. Simplify the differential equations as much as possible
4. Integrate the equations
5. Apply BCs to solve for constants of integration
6. Verify results
• Boundary conditions are critical to exact, approximate, and
computational solutions.
▪ BC’s used in analytical solutions are
• No-slip boundary condition
• Interface boundary condition
Summary of Fluid Dynamic Equations in CFD
Analysis

49
3D Compressible Navier–Stokes Equations
C.E. in conservative form

Complete Navier–Stokes equations in conservation form

50
3D Compressible Navier–Stokes Equations
C.E. in conservative form

By expanding
 ( u ) ( v) ( w)
+ + + =0
t x y z

51
3D Compressible Navier–Stokes Equations
Momentum Equations in conservative form

52
3D Compressible Navier–Stokes Equations
when expanded using Stokes’ hypothesis (λ= - 2/3 μ) gives

53
3D Incompressible Navier–Stokes Equations
Continuity Equation
𝜕𝑢 𝜕𝑣 𝜕𝑤
+ + =0
𝜕𝑥 𝜕𝑦 𝜕𝑧

𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕𝑝 𝜕2𝑢 𝜕2𝑢 𝜕2𝑢


X-Momentum 𝜌 +𝑢 +𝑣 +𝑤 = 𝜌𝑔𝑥 − +𝜇 2
+ 2+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝜕𝑥 𝜕𝑥 𝜕𝑦 𝜕𝑧

𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕𝑝 𝜕2𝑣 𝜕2𝑣 𝜕2𝑣


Y-Momentum 𝜌 +𝑢 +𝑣 +𝑤 = 𝜌𝑔𝑦 − +𝜇 2
+ 2+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝜕𝑦 𝜕𝑥 𝜕𝑦 𝜕𝑧
𝜕𝑤 𝜕𝑤 𝜕𝑤 𝜕𝑤 𝜕𝑝 𝜕2𝑤 𝜕2𝑤 𝜕2𝑤
Z-Momentum 𝜌 +𝑢 +𝑣 +𝑤 = 𝜌𝑔𝑧 − +𝜇 2
+ 2+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝜕𝑧 𝜕𝑥 𝜕𝑦 54 𝜕𝑧
2D Incompressible Navier–Stokes Equations
Continuity Equation
𝜕𝑢 𝜕𝑣
+ =0
𝜕𝑥 𝜕𝑦

X-Momentum
𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕𝑝 𝜕2𝑢 𝜕2𝑢
𝜌 +𝑢 +𝑣 = 𝜌𝑔𝑥 − +𝜇 2
+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑥 𝜕𝑦

Y-Momentum
𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕𝑝 𝜕2𝑣 𝜕2𝑣
𝜌 +𝑢 +𝑣 = 𝜌𝑔𝑦 − + +𝜇 2
+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑦 𝜕𝑥 𝜕𝑦
55
Euler Equations
Continuity Equation
𝜕𝑢 𝜕𝑣 𝜕𝑤
+ + =0
𝜕𝑥 𝜕𝑦 𝜕𝑧

𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕𝑝
X-Momentum 𝜌 +𝑢 +𝑣 +𝑤 = 𝜌𝑔𝑥 −
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝜕𝑥
𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕𝑝
Y-Momentum 𝜌 +𝑢 +𝑣 +𝑤 = 𝜌𝑔𝑦 −
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝜕𝑦

𝜕𝑤 𝜕𝑤 𝜕𝑤 𝜕𝑤 𝜕𝑝
Z-Momentum 𝜌 +𝑢 +𝑣 +𝑤 = 𝜌𝑔𝑧 −
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝜕𝑧 56
Poisson Equation
𝜕2𝑢 𝜕2𝑢
2
+ 2 = 𝑓 𝑥, 𝑦
𝜕𝑥 𝜕𝑦

or 𝜕2𝜓 𝜕2𝜓
2
+ 2 = 𝑓 𝑥, 𝑦
𝜕𝑥 𝜕𝑦

Laplace Equation
𝜕2𝑢 𝜕2𝑢
2
+ 2=0
𝜕𝑥 𝜕𝑦

or 𝜕2𝜓 𝜕2𝜓
2
+ 2 =0
𝜕𝑥 𝜕𝑦 57
2D Viscous Burgers’ Equation (Convection)

𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕2𝑢 𝜕2𝑢
+𝑢 +𝑣 =𝜐 2
+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑦

𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕2𝑣 𝜕2𝑣
+𝑢 +𝑣 =𝜐 2
+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑦

2D Heat Equation (Diffusion)

𝜕𝑢 𝜕2𝑢 𝜕2𝑢
=𝜐 2
+ 2
𝜕𝑡 𝜕𝑥 𝜕𝑦
58
2D Inviscid Burgers’ Equation (Convection)

𝜕𝑢 𝜕𝑢 𝜕𝑢
+𝑢 +𝑣 =0
𝜕𝑡 𝜕𝑥 𝜕𝑦
𝜕𝑣 𝜕𝑣 𝜕𝑣
+𝑢 +𝑣 =0
𝜕𝑡 𝜕𝑥 𝜕𝑦

2D Wave Equation (Linear Convection)

𝜕𝑢 𝜕𝑢 𝜕𝑢
+𝑐 +𝑐 =0
𝜕𝑡 𝜕𝑥 𝜕𝑦

59
1D Viscous Burgers’ Equation
𝜕𝑢 𝜕𝑢 𝜕2𝑢
+𝑢 =𝜐 2
𝜕𝑡 𝜕𝑥 𝜕𝑥
1D Heat Equation (Diffusion)
𝜕𝑢 𝜕2𝑢
=𝜐 2
𝜕𝑡 𝜕𝑥
1D Inviscid Burgers’ Equation (Convection)
𝜕𝑢 𝜕𝑢
+𝑢 =0
𝜕𝑡 𝜕𝑥
1D Wave Equation (Linear Convection)
𝜕𝑢 𝜕𝑢
+𝑐 =0
𝜕𝑡 𝜕𝑥 60
Basics of Finite Difference Formulations

Refer to
Ch. 2
Hoffmann, A., Chiang, S., Computational Fluid Dynamics for Engineers, Vol. I, 4th ed.,
Engineering Education System, 2000.
Ch. 3, 4 and 5
Pletcher, R. H., Tannehill, J. C., Anderson, D., Computational Fluid Mechanics and Heat Tranfer,
3rd ed., CRC Press, 2011.
Ch. 5
Wendt, Anderson, Computational Fluid Dynamics - An Introduction, 3rd edition 2009.
Discretization methods (Finite Difference)

• First step in obtaining a numerical solution is to discretize the geometric domain→


to define a numerical grid
• Each node has one unknown and needs one algebraic equation, which is a relation
between the variable value at that node and those at some of the neighboring
nodes.
• The approach is to replace each term of the PDE at the particular node by a finite-
difference approximation.
• Numbers of equations and unknowns must be equal
Discretization (Grid Generation)
• Numerical solutions can give answers at only discrete points in the domain, called
grid points.

• If the PDEs are totally replaced by a system of algebraic equations which can be
solved for the values of the flow-field variables at the discrete points only, in this
sense, the original PDEs have been discretized.
• Moreover, this method of discretization is called the method of finite differences.
Taylor’s series expansion
• A partial derivative replaced with a suitable algebraic difference quotient is called
finite difference.
• Most finite-difference representations of derivatives are based on Taylor’s series
expansion.
• Taylor’s series expansion:
Consider a continuous function of x, namely, f(x), with all derivatives defined at x.
Then, the value of f at a location x+Δx can be estimated from a Taylor series
expanded about point x, that is,
f 1 2 f 1 3 f 1 n f
f ( x + x ) = f ( x ) + x + (x )2
+ (x )3
+ ... + ( x ) n
+ ...
x 2! x 2
3! x 3
n! x n

f 1 2 f 1 3 f 1 n f
f ( x i +1 ) = f ( x i ) + ( x i +1 − x i ) + ( x i +1 − x ) 2
+ ( x i +1 − x ) 3
+ ... + ( x i +1 − x ) n
+ ...
x 2! x 2 3! x 3 n! x n
i i i

• In general, to obtain more accuracy, additional higher-order terms must be included.


Taylor’s series expansion
f ( x i )
f ( x i +1 )  f ( x i ) + f ( x i )( x i +1 − x i ) + ( x i +1 − x i ) 2 + 
2!
f ( n) ( xi )
+ ( x i +1 − x i ) n + Rn
n!
(xi+1-xi)= Δx step size (define first)

f ( x i ) 2
f ( x i +1 )  f ( x i ) + f ( x i )x + x + 
2!
f ( n) ( xi ) n 
(x ) n n
+ x + Rn = f ( x i ) +  f ( xi )
n! 1 n!
• The term, Rn, accounts for all terms from (n+1) to infinity, Truncation
error.
Taylor’s series expansion

𝑥𝑖+1 − 𝑥𝑖 = ∆𝑥 = ℎ
Truncation Error
• Need to determine f n+1(x), to do this you need f'(x).

• If we knew f(x), there wouldn’t be any need to perform the


Taylor series expansion.

• However, R=O(Δxn+1), (n+1)th order, the order of truncation


error is Δxn+1.

• O(Δx), halving the step size will halve the error.

• O(Δx2), halving the step size will quarter the error.


Forward, Backward and Central
Differences:
(1) Forward difference:

Neglecting higher-order terms,


we can get
f
f ( x i +1 ) = f ( x i ) + ( ) i ( x i +1 − x i ) +
( x i +1 − x i ) 2  2 f
( 2 )i +
( x i +1 − x i )  3 f
3
( 3 )i
x 2! x 3! x
( x i +1 − x i ) n  n f
+ ... + ( n ) i + ...
n! x
f
Solve for ( )i , we get
x
Finite Differences:
Recall the Definition of a derivative:

𝜕𝑦 𝑦2 − 𝑦1
= lim
𝜕𝑥 ∆𝑥→0 𝑥2 − 𝑥1
𝜕𝑦 𝑦2 − 𝑦1
= lim
𝜕𝑥 ∆𝑥→0 ∆𝑥
Finite Differences:
Recall the Definition of a derivative:
𝜕𝑢 𝑢 𝑥𝑖 +∆𝑥 −𝑢 𝑥𝑖
= lim
𝜕𝑥 𝑥𝑖 ∆𝑥→0 ∆𝑥

𝑥
Forward, Backward and Central
Differences:
(1) Backward difference:
𝑢

𝑥
Forward, Backward and Central
Differences:
(2) Forward difference:
𝑢

𝑥
Forward, Backward and Central
Differences:
(3) Central difference:

𝑥
74
(1) Forward difference:
f
( )i =
f ( xi +1 ) − f ( xi ) ( xi +1 − xi )  f

2 2
( 2 )i −
( xi +1 − xi )3 3 f
( 3 )i
x ( xi +1 − xi ) 2!( xi +1 − xi ) x 3!( xi +1 − xi ) x
( xi +1 − xi ) n  n f
− ... − ( n ) i − ...
n!( xi +1 − xi ) x

f f i +1 − f i x  2 f x 2  3 f x n−1  n f
( )i = − ( 2 )i − ( 3 ) i − ... − ( n ) i − ...
x x 2 x 6 x n! x
f i +1 − f i
= + O (x ) (a )
x
• This equation is known as the first forward difference
approximation of f of order (Δx).
x
• It is obvious that as the step size decreases, the error term
is reduced and therefore the accuracy of the approximation
is increased.
(2) Backward difference
Taylor series expansion:
Neglecting higher-order terms, we can get

f
f ( x i −1 ) = f ( x i ) − ( ) i ( x i − x i −1 ) +
( x i − x i −1 ) 2  2 f
( 2 )i −
( x i − x i −1 )  3 f
3
( 3 )i
x 2! x 3! x
n ( x i − x i −1 )
n
n f 
 n ( x )   f
n n
+ ... + (−1) ( n ) i + ... = f ( x ) +  (−1)  n
n! x n =1  n!  x

Solve for ( f ) , we get


x
i

f
( )i =
f ( x i ) − f ( x i −1 ) ( x i − x i −1 )  2 f
+ ( 2 )i −
( x i − x i −1 )  3 f
( 3 )i
2

x ( x i − x i −1 ) 2 x 6 x
( x i − x i −1 ) n −1  n f f i − f i −1
+ ... + (−1) n
( n ) i + .. = + O (x ) (b )
n! x x
(2) Backward difference
• which represents the slope of the function at B using the values of
the function at points A and B, as shown in Figure 2-2.
• Equation (2-6) is the first backward difference approximation

f
of of order (Δx).
x
Figure 2-2. Illustration of grid
points used in Equation (2-6).
(3) Central difference:
f f i +1 − f i x  2 f x 2  3 f x n−1  n f
( )i = − ( 2 )i − ( 3 ) i − ... − ( n ) i − ...
x x 2 x 6 x n! x
f i +1 − f i
= + O (x ) (a )
x
n −1
f f i − f i −1 x  2 f x 2  3 f n ( x ) n f
( )i = + ( 2 )i − ( 3 ) i + ... + (−1) ( n ) i + ..
x x 2 x 6 x n! x
f i − f i −1
= + O (x ) (b )
x
• Adind (a)+(b) and neglecting higher-order terms, we
can
f get f − f + f − f x 2  3 f
2( )i = i +1 i i i −1
− + HOT
x x 3 x 3

f f − f i −1
( ) i = i +1 + O (x ) 2 (c )
x 2x
(3) Central difference:
• which represents the slope of the function f at point B using the
f A and C, as shown in Figure 2-3.
values of the function at points
x
• This representation of is known as the central difference
approximation of order (Δx)2•
Truncation error:
The higher-order term neglecting in Eqs. (a), (b), (c)
constitute the truncation error.

Forward: f f i +1 − f i
( )i = + O ( x )
x x

Backward: f f − f i −1
( )i = i + O ( x )
x x

f f − f i −1
Central: ( ) i = i +1 + O ( x ) 2
x 2x
Second derivatives:
f
f i +1 = f i + ( ) i x +
(x ) 2  2 f
( 2 )i +
(x )  3 f
3
( 3 ) i + ... +
(x ) n  n f
( n ) i + ...
x 2! x 3! x n! x
f
f i −1 = f i − ( ) i (x ) +
(x ) 2  2 f
( 2 )i −
(x )  3 f
3
( 3 ) i + ... + (−1) n
( x ) n
 n
f
( n ) i + ...
x 2! x 3! x n! x

if xi = xi +1 = x , then (a)+(b) becomes

* Central difference:
 2
f
f i +1 + f i −1 = 2 f i + (x ) ( 2 ) i + O (x ) 4 + HOT
2

x
2 f f i +1 − 2 f i + f i −1
( 2 )i = + O (x ) 2

x (x ) 2
Second derivatives:
f
f i +1 = f i + ( ) i x +
(x )  f2
( 2 )i
2
+
( )
x  3 f
3
( ) + ... +
(x ) n  n f
( n ) i + ...
x 2! x x 3 n! x
i
3!

f i +2 = f i + (
f
)2x +
(2x )  f2
( 2 )i
2
+
( )
2x  3 f
3
( ) + ... +
(2x ) n  n f
( ) + ...
x 2! x 3! x 3 n! x n

If xi = xi +1 = x , then (b)-2(a) becomes


f i + 2 − 2 f i +1 = f i − 2 f i +
(2x ) 2  2 f
( 2 )i − 2
(x ) 2  2 f
( 2 )i +
(2x )  3 f
3
( 3 )−2
(x )  3 f
3
( 3 ) + HOT
2! x 2! x 3! x 3! x

 2
f
f i + 2 − 2 f i +1 + f i = x ( 2 ) i + O (x ) 3
2

x
* Forward difference: 2 f f i + 2 − 2 f i +1 + f i
( 2 )i = + O (x )
x (x ) 2
Second derivatives:
f
f i −1 = f i − ( ) i (x ) +
(x ) 2  2 f
( 2 )i −
(x )  3 f
3
( 3 ) i + ... + (−1) n
( x ) n
 n
f
( n ) i + ...
x 2! x 3! x n! x

f i −2
f
= f i − ( )2x +
(2x ) 2  2 f
( 2 )i −
(2x )  3 f
3
( 3 ) + ... +
(2x ) n  n f
( n ) + ...
x 2! x 3! x n! x

If xi = xi +1 = x , then (b)-2(a) becomes


f i − 2 − 2 f i −1 = f i − 2 f i +
(2x ) 2  2 f
( 2 )i − 2
(x ) 2  2 f
3
( 2 )i −
(2x )  3 f
( 3 )+2
(
3
x )  3 f
( 3 ) + HOT
2! x 2! x 3! x 3! x

 2
f
f i − 2 − 2 f i −1 + f i = x ( 2 ) i + O (x ) 3
2

x
* Backward difference: 2 f f i − 2 f i −1 + f i − 2
( 2 )i = + O (x )
x (x ) 2
1-D Wave equation
𝜕𝑢 𝜕𝑢
+𝑐 =0
𝜕𝑡 𝜕𝑥
By applying Forward in time and central in space (FTCS)

𝑢𝑖𝑛+1 − 𝑢𝑖𝑛 𝑛
𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
+𝑐 =0
∆𝑡 ∆𝑥
By rearranging

∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 +𝑐 𝑛
× 𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
∆𝑥
84
1-D Wave equation
∆𝑡
𝑢𝑖𝑛+1 =𝑢𝑖𝑛 +𝑐 𝑛
× 𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
∆𝑥
Assume initial conditions of

𝑢 = 2 @ 0.5 ≤ 𝑥 ≤ 1
𝑢 = 1 @ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒

Assume Boundary conditions


𝑢 = 1 @ 𝑥 = 0, 2

85
∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 + 𝑐 𝑛
× 𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
1-D Wave equation ∆𝑥

I.C.
𝑢 = 2 @ 0.5 ≤ 𝑥 ≤ 1
𝑢 = 1 @ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒

B.C.
𝑢 = 1 @ 𝑥 = 0, 2

86
1-D Inviscid Burgers’ equation
𝜕𝑢 𝜕𝑢
+𝑢 =0
𝜕𝑡 𝜕𝑥
By applying Forward in time and central in space (FTCS)

𝑢𝑖𝑛+1 − 𝑢𝑖𝑛 𝑢 𝑛
𝑖+1 − 2𝑢 𝑛
𝑖 + 𝑢 𝑛
𝑖−1
+ 𝑢𝑖𝑛 =0
∆𝑡 ∆𝑥

By rearranging
∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 +𝑐 × 𝑢𝑖𝑛 × 𝑢𝑖+1
𝑛
− 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
∆𝑥
87
1-D Inviscid Burgers’ equation
∆𝑡
𝑢𝑖𝑛+1 =𝑢𝑖𝑛 +𝑐 × 𝑢𝑖𝑛 × 𝑢𝑖+1
𝑛
− 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
∆𝑥
Assume initial condition of

𝑢 = 2 @ 0.5 ≤ 𝑥 ≤ 1
𝑢 = 1 @ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒

Assume Boundary condition


𝑢 = 1 @ 𝑥 = 0, 2

88
1-D Inviscid Burgers’ equation
∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 +𝑐 × 𝑢𝑖𝑛 × 𝑢𝑖+1
𝑛
− 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
∆𝑥
I.C.
𝑢 = 2 @ 0.5 ≤ 𝑥 ≤ 1
𝑢 = 1 @ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒

B.C.
𝑢 = 1 @ 𝑥 = 0, 2

89
1-D Diffusion equation
𝜕𝑢 𝜕2𝑢
=𝜐 2
𝜕𝑡 𝜕𝑦
By applying Forward in time and central in space (FTCS)

𝑢𝑖𝑛+1 − 𝑢𝑖𝑛 𝑛
𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
=𝜐
∆𝑡 ∆𝑥 2
By rearranging

∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 +𝜐 × 𝑢 𝑛
𝑖+1 − 2𝑢 𝑛
𝑖 + 𝑢 𝑛
𝑖−1
∆𝑥 2
90
1-D Diffusion equation
𝜕𝑢 𝜕2𝑢
=𝜐 2
𝜕𝑡 𝜕𝑦
By applying Forward in time and central in space (FTCS)

𝑢𝑖𝑛+1 − 𝑢𝑖𝑛 𝑛
𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
=𝜐
∆𝑡 ∆𝑥 2
By rearranging
∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 +𝜐 × 𝑢 𝑛
𝑖+1 − 2𝑢 𝑛
𝑖 + 𝑢 𝑛
𝑖−1
∆𝑥 2

𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 + 𝑑 × 𝑢𝑖+1


𝑛
− 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
91
Application to FTCS-Explicit scheme for the
parabolic model equation

92
Application to FTCS-Explicit scheme for the
parabolic model equation

93
Programming Assignment
Consider a fluid bounded by two parallel plates extended to
infinity such that no end effects are encountered. The walls
and the fluid are initially at rest. Now, the lower wall is
suddenly accelerated in the x-direction. The Navier-Stokes
equations for this problem may be expressed as:
𝜕𝑢 𝜕2𝑢
=𝜐 2
𝜕𝑡 𝜕𝑦
It is required to compute 𝑢 𝑡, 𝑦 .

94
Programming Assignment 1
Assume initial conditions of
𝑢 = 𝑢𝑜 @ 𝑦 = 0
𝑢 =0@ 0<𝑦 ≤ℎ
where h is the distance between the two plates and
equals 40 mm.
Assume Boundary conditions
𝑢 = 𝑢𝑜 @ 𝑦 = 0
𝑢 =0@ 𝑦 =ℎ
Take 𝜐=0.000217 m2/s, 𝑢𝑜 =40 m/s, max time of 1.08
sec. Assume 40 nodes in y direction 95
Programming Assignment 1
Apply FTCS scheme.
Calculate and plot the velocity distribution by using
Matlab by using the following time steps:
❑ dt = 0.002 sec
❑ dt = 0.00232 sec
❑ dt = 0.003 sec

Bonus points will be given to the student who


• Creates a video of the development of the flow speed with
time. 96

You might also like