ME - 733 Computational Fluid Mechanics Lecture 2drahmednagib.com/CFD_2018/CFD_Lecture_2.pdf ·...
Transcript of ME - 733 Computational Fluid Mechanics Lecture 2drahmednagib.com/CFD_2018/CFD_Lecture_2.pdf ·...
ME - 733Computational Fluid Mechanics
Lecture 2
Dr./ Ahmed Nagib Elmekawy Oct 21, 2018
2
Leonhard Euler (1707-1783)
• In 1768, Leonhard Euler introduced the finite difference technique based on Taylor series expansion.
3
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.
4
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.
5
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.
6
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.
7
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.
4
LAGRANGIAN AND EULERIAN DESCRIPTIONS
Kinematics: The study of motion.
Fluid kinematics: The study of how fluids flow and how to describe fluidmotion.
With a small number of objects, such
as billiard balls on a pool table,
individual objects can be tracked.
In the Lagrangian description, one
must keep track of the position and
velocity of individual particles.
There are two distinct ways to describe motion: Lagrangian and 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.
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 pressure field is a scalar field variable. We define the
velocity field as a vector field variable.
Collectively, these (and other) field variables define the flow field. The
velocity field can be expanded in Cartesian coordinates as
9
9
In the Eulerian description, one
defines field variables, such as
the pressure field and the
velocity field, at any location
and instant in time.
10
• 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
is often more convenient for fluid
mechanics applications.
• Experimental measurements are
generally more suited to the
Eulerian description.
10
CONSERVATION OF MASS—THE CONTINUITYEQUATION
To derive a differential
conservation equation, we
imagine shrinking a control
volume to infinitesimal size.
11
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.
11
12
13
Conservation of Mass: Alternative forms
• Use product rule on divergence term
kz
jy
ix
kwjviuV
+
+
=
++=
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
Cartesian
Cylindrical
0)()()(=
+
+
z
w
y
v
x
u
Conservation of Mass: Special Cases
• Incompressible flow
Cartesian
Cylindrical
= constant, and hence
0=
+
+
z
w
y
v
x
u
kz
jy
ix
kwjviuV
+
+
=
++=
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
equation. continuity hesatisfy t torequired , w: Determine
?
flow ibleincompressan For
Example
222
=
++=
++=
w
zyzxyv
zyxu
),(2
3 :Solution2
yxcz
xzw +−−=
Conservation of MomentumTypes 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.
If the differential fluid
element is a material
element, it moves with the
flow and Newton’s second
law applies directly.
24
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.
Body Forces
25
Stresses (forces per unit area)
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
Surface of constant xSurface of
constant -x
27
28
29
30
31
32
33
34
Complete Navier–Stokes equations
Newtonian versus Non-Newtonian Fluids
Rheological behavior of fluids—shear
stress as a function of shear strain rate.
35
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.
Some non-Newtonian fluids are called
shear thinning fluids or
pseudoplas t ic fluids, because the
more the fluid is sheared, the less
viscous it becomes.
Plastic fluids are those in which the
shear thinning effect is extreme.
In some fluids a finite stress called the
yield s t ress is required before the
fluid begins to flow at all; such fluids
are called Bingham plastic fluids.
36
Derivation of the Navier–Stokes Equation for Incompressible, Isothermal Flow
The incompressible flow
approximation implies constant
density, and the isothermal
approximation implies constant
viscosity.
37
38
Navier-Stokes Equations
)()]([)]([
)].3
22([)(
az
u
x
w
zy
u
x
v
y
Vx
u
xx
pg
z
uw
y
uv
x
uu
t
ux
+
+
+
+
−
+
−=
+
+
+
)()]([)].3
22([
)]([)(
by
w
z
v
zV
y
v
y
y
u
x
v
xy
pg
z
vw
y
vv
x
vu
t
vy
+
+−
+
+
+
−=
+
+
+
)()].3
22([)]([
)]([)(
cVz
w
zy
w
z
v
y
z
u
x
w
xz
pg
z
ww
y
wv
x
wu
t
wz
−
+
+
+
+
+
−=
+
+
+
x-momentum
y-momentum
z-momentum
Navier-Stokes Equations• For incompressible fluids, constant µ:
• Continuity equation: .V = 0
uz
u
y
u
x
u
z
w
y
v
x
u
xz
u
y
u
x
u
zx
w
yx
v
x
u
z
u
y
u
x
u
z
u
x
w
zy
u
x
v
yx
u
x
z
u
x
w
zy
u
x
v
yV
x
u
x
2
2
2
2
2
2
2
2
2
2
2
2
2
22
2
2
2
2
2
2
2
2
)(
)()(
)()(
)]}[()][()]2[({
)]([)]([)].3
22([
=
+
+
=
+
+
+
+
+
=
+
+
+
+
+
=
+
+
+
+
=
+
+
+
+−
Navier-Stokes Equations• For incompressible flow with constant dynamic viscosity:
• x- momentum
• Y- momentum
• z-momentum
• In vector form, the three equations are given by:
)()(2
2
2
2
2
2
az
u
y
u
x
u
x
pg
Dt
Dux
+
+
+
−=
)()(2
2
2
2
2
2
bz
v
y
v
x
v
y
pg
Dt
Dvy
+
+
+
−=
)()(2
2
2
2
2
2
cz
w
y
w
x
w
z
pg
Dt
Dwz
+
+
+
−=
VpgDt
VD
2+−= Incompressible NSEwritten in vector form
Navier-Stokes Equations
)()]([)]([
)].3
22([)(
az
u
x
w
zy
u
x
v
y
Vx
u
xx
pg
z
uw
y
uv
x
uu
t
ux
+
+
+
+
−
+
−=
+
+
+
)()]([)].3
22([
)]([)(
by
w
z
v
zV
y
v
y
y
u
x
v
xy
pg
z
vw
y
vv
x
vu
t
vy
+
+−
+
+
+
−=
+
+
+
)()].3
22([)]([
)]([)(
cVz
w
zy
w
z
v
y
z
u
x
w
xz
pg
z
ww
y
wv
x
wu
t
wz
−
+
+
+
+
+
−=
+
+
+
x-momentum
y-momentum
z-momentum
Navier-Stokes Equations• For incompressible fluids, constant µ:
• Continuity equation: .V = 0
uz
u
y
u
x
u
z
w
y
v
x
u
xz
u
y
u
x
u
zx
w
yx
v
x
u
z
u
y
u
x
u
z
u
x
w
zy
u
x
v
yx
u
x
z
u
x
w
zy
u
x
v
yV
x
u
x
2
2
2
2
2
2
2
2
2
2
2
2
2
22
2
2
2
2
2
2
2
2
)(
)()(
)()(
)]}[()][()]2[({
)]([)]([)].3
22([
=
+
+
=
+
+
+
+
+
=
+
+
+
+
+
=
+
+
+
+
=
+
+
+
+−
Navier-Stokes Equations• For incompressible flow with constant dynamic viscosity:
• x- momentum
• Y- momentum
• z-momentum
• In vector form, the three equations are given by:
)()(2
2
2
2
2
2
az
u
y
u
x
u
x
pg
Dt
Dux
+
+
+
−=
)()(2
2
2
2
2
2
bz
v
y
v
x
v
y
pg
Dt
Dvy
+
+
+
−=
)()(2
2
2
2
2
2
cz
w
y
w
x
w
z
pg
Dt
Dwz
+
+
+
−=
VpgDt
VD
2+−= Incompressible NSEwritten in vector form
Navier-Stokes Equation• The Navier-Stokes equations for incompressible flow 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
Incompressible NSEwritten in vector form
Euler Equations• For inviscid flow (µ = 0) the momentum equations are given by:
• x- momentum
• Y- momentum
• z-momentum
• In vector form, the three equations are given by:
)()( ax
pg
z
uw
y
uv
x
uu
t
ux
−=
+
+
+
pgDt
VD−=
Euler equationswritten in vector form
)()( by
pg
z
vw
y
vv
x
vu
t
vy
−=
+
+
+
)()( cz
pg
z
ww
y
wv
x
wu
t
wz
−=
+
+
+
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
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
Procedure for solving continuity and NSE
Summary of Fluid Dynamic Equations in CFD Analysis
49
50
3D Compressible Navier–Stokes EquationsC.E. in conservative form
Complete Navier–Stokes equations in conservation form
51
3D Compressible Navier–Stokes EquationsC.E. in conservative form
0)()()(=
+
+
+
z
w
y
v
x
u
t
By expanding
52
3D Compressible Navier–Stokes EquationsMomentum Equations in conservative form
53
3D Compressible Navier–Stokes Equationswhen expanded using Stokes’ hypothesis (λ= - 2/3 μ) gives
54
3D Incompressible Navier–Stokes Equations
Continuity Equation
X-Momentum
Y-Momentum
Z-Momentum
𝜕𝑢
𝜕𝑥+𝜕𝑣
𝜕𝑦+𝜕𝑤
𝜕𝑧= 0
𝜌𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥+ 𝑣
𝜕𝑢
𝜕𝑦+ 𝑤
𝜕𝑢
𝜕𝑧= 𝜌𝑔𝑥 −
𝜕𝑝
𝜕𝑥+ 𝜇
𝜕2𝑢
𝜕𝑥2+𝜕2𝑢
𝜕𝑦2+𝜕2𝑢
𝜕𝑧2
𝜌𝜕𝑣
𝜕𝑡+ 𝑢
𝜕𝑣
𝜕𝑥+ 𝑣
𝜕𝑣
𝜕𝑦+ 𝑤
𝜕𝑣
𝜕𝑧= 𝜌𝑔𝑦 −
𝜕𝑝
𝜕𝑦+ 𝜇
𝜕2𝑣
𝜕𝑥2+𝜕2𝑣
𝜕𝑦2+𝜕2𝑣
𝜕𝑧2
𝜌𝜕𝑤
𝜕𝑡+ 𝑢
𝜕𝑤
𝜕𝑥+ 𝑣
𝜕𝑤
𝜕𝑦+ 𝑤
𝜕𝑤
𝜕𝑧= 𝜌𝑔𝑧 −
𝜕𝑝
𝜕𝑧+ 𝜇
𝜕2𝑤
𝜕𝑥2+𝜕2𝑤
𝜕𝑦2+𝜕2𝑤
𝜕𝑧2
55
2D Incompressible Navier–Stokes Equations
Continuity Equation
X-Momentum
Y-Momentum
𝜕𝑢
𝜕𝑥+𝜕𝑣
𝜕𝑦= 0
𝜌𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥+ 𝑣
𝜕𝑢
𝜕𝑦= 𝜌𝑔𝑥 −
𝜕𝑝
𝜕𝑥+ 𝜇
𝜕2𝑢
𝜕𝑥2+𝜕2𝑢
𝜕𝑦2
𝜌𝜕𝑣
𝜕𝑡+ 𝑢
𝜕𝑣
𝜕𝑥+ 𝑣
𝜕𝑣
𝜕𝑦= 𝜌𝑔𝑦 −
𝜕𝑝
𝜕𝑦++𝜇
𝜕2𝑣
𝜕𝑥2+𝜕2𝑣
𝜕𝑦2
56
Euler Equations
Continuity Equation
X-Momentum
Y-Momentum
Z-Momentum
𝜕𝑢
𝜕𝑥+𝜕𝑣
𝜕𝑦+𝜕𝑤
𝜕𝑧= 0
𝜌𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥+ 𝑣
𝜕𝑢
𝜕𝑦+ 𝑤
𝜕𝑢
𝜕𝑧= 𝜌𝑔𝑥 −
𝜕𝑝
𝜕𝑥
𝜌𝜕𝑣
𝜕𝑡+ 𝑢
𝜕𝑣
𝜕𝑥+ 𝑣
𝜕𝑣
𝜕𝑦+𝑤
𝜕𝑣
𝜕𝑧= 𝜌𝑔𝑦 −
𝜕𝑝
𝜕𝑦
𝜌𝜕𝑤
𝜕𝑡+ 𝑢
𝜕𝑤
𝜕𝑥+ 𝑣
𝜕𝑤
𝜕𝑦+ 𝑤
𝜕𝑤
𝜕𝑧= 𝜌𝑔𝑧 −
𝜕𝑝
𝜕𝑧
57
Poisson Equation
𝜕2𝑢
𝜕𝑥2+𝜕2𝑢
𝜕𝑦2= 𝑓 𝑥, 𝑦
or 𝜕2𝜓
𝜕𝑥2+𝜕2𝜓
𝜕𝑦2= 𝑓 𝑥, 𝑦
Laplace Equation𝜕2𝑢
𝜕𝑥2+𝜕2𝑢
𝜕𝑦2= 0
or 𝜕2𝜓
𝜕𝑥2+𝜕2𝜓
𝜕𝑦2= 0
58
2D Viscous Burgers’ Equation (Convection)
2D Heat Equation (Diffusion)
𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥+ 𝑣
𝜕𝑢
𝜕𝑦= 𝜐
𝜕2𝑢
𝜕𝑥2+𝜕2𝑢
𝜕𝑦2
𝜕𝑣
𝜕𝑡+ 𝑢
𝜕𝑣
𝜕𝑥+ 𝑣
𝜕𝑣
𝜕𝑦= 𝜐
𝜕2𝑣
𝜕𝑥2+𝜕2𝑣
𝜕𝑦2
𝜕𝑢
𝜕𝑡= 𝜐
𝜕2𝑢
𝜕𝑥2+𝜕2𝑢
𝜕𝑦2
59
2D Inviscid Burgers’ Equation (Convection)
2D Wave Equation (Linear Convection)
𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥+ 𝑣
𝜕𝑢
𝜕𝑦= 0
𝜕𝑣
𝜕𝑡+ 𝑢
𝜕𝑣
𝜕𝑥+ 𝑣
𝜕𝑣
𝜕𝑦= 0
𝜕𝑢
𝜕𝑡+ 𝑐
𝜕𝑢
𝜕𝑥+ 𝑐
𝜕𝑢
𝜕𝑦= 0
60
1D Viscous Burgers’ Equation
1D Heat Equation (Diffusion)
𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥= 𝜐
𝜕2𝑢
𝜕𝑥2
𝜕𝑢
𝜕𝑡= 𝜐
𝜕2𝑢
𝜕𝑥2
1D Inviscid Burgers’ Equation (Convection)
1D Wave Equation (Linear Convection)𝜕𝑢
𝜕𝑡+ 𝑐
𝜕𝑢
𝜕𝑥= 0
𝜕𝑢
𝜕𝑡+ 𝑢
𝜕𝑢
𝜕𝑥= 0
Basics of Finite Difference Formulations
Refer to
Ch. 2Hoffmann, A., Chiang, S., Computational Fluid Dynamics for Engineers, Vol. I, 4th ed., Engineering Education System, 2000.
Ch. 3, 4 and 5Pletcher, R. H., Tannehill, J. C., Anderson, D., Computational Fluid Mechanics and Heat Tranfer, 3rd ed., CRC Press, 2011.
Ch. 5Wendt, Anderson, Computational Fluid Dynamics - An Introduction, 3rd edition 2009.
• 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 methods (Finite Difference)
• 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.
Discretization (Grid Generation)
• 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,
• In general, to obtain more accuracy, additional higher-order terms must be included.
Taylor’s series expansion
( ) ( ) ...)(!
1...
!3
1
!2
1)()(
3
3
32
2
2
+
++
+
+
+=+ n
n
n
xx
f
nx
x
fx
x
fx
x
fxfxxf
...)(!
1...)(
!3
1)(
!2
1)()()( 1
3
13
32
12
2
11 +−
++−
+−
+−
+= +++++
n
iin
n
iiiiiiii xxx
f
nxx
x
fxx
x
fxx
x
fxfxf
Taylor’s series expansion
n
n
iii
n
iii
iiiii
Rxxn
xf
xxxf
xxxfxfxf
+−+
+−
+−+
+
+++
)(!
)(
)(!2
)())(()()(
1
)(
2
111
(xi+1-xi)= Δx step size (define first)
• The term, Rn, accounts for all terms from (n+1) to infinity, Truncation error.
)(!
)()(
!
)(
!2
)()()()(
1
)(
2
1
i
nn
in
ni
n
iiii
xfn
xxfRx
n
xf
xxf
xxfxfxf
+
+=++
+
++
Taylor’s series expansion
𝑥𝑖+1 − 𝑥𝑖 = ∆𝑥 = ℎ
• 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.
Truncation Error
(1) Forward difference:
Neglecting higher-order terms,
we can get
Forward, Backward and Central Differences:
( )
...)(!
)(...
)(!3
)(!2
)()()()()(
1
3
33
1
2
22
111
+
−++
−+
−+−
+=
+
++++
in
nn
ii
iii
iii
iiiii
x
f
n
xx
x
fxx
x
fxxxx
x
fxfxf
Solve for , we geti
x
f)(
Recall the Definition of a derivative:
𝜕𝑦
𝜕𝑥= lim
∆𝑥→0
𝑦2 − 𝑦1𝑥2 − 𝑥1
𝜕𝑦
𝜕𝑥= lim
∆𝑥→0
𝑦2 − 𝑦1∆𝑥
Finite Differences:
Recall the Definition of a derivative:𝜕𝑢
𝜕𝑥 𝑥𝑖= lim
∆𝑥→0
𝑢 𝑥𝑖+∆𝑥 −𝑢 𝑥𝑖
∆𝑥
Finite Differences:
𝑢
𝑥
(1) Backward difference:
Forward, Backward and Central Differences:
𝑥
𝑢
(2) Forward difference:
Forward, Backward and Central Differences:
𝑥
𝑢
(3) Central difference:
Forward, Backward and Central Differences:
𝑥
𝑢
74
• This equation is known as the first forward difference approximation of of order (Δx).
• It is obvious that as the step size decreases, the error term is reduced and therefore the accuracy of the approximation is increased.
(1) Forward difference:( )
...)()(!
)(...
)()(!3
)()(!2
)(
)(
)()()(
1
1
3
3
1
3
1
2
2
1
2
1
1
1
−
−
−−−
−
−−
−
−−
−
−=
+
+
+
+
+
+
+
+
in
n
ii
n
ii
i
ii
iii
ii
ii
ii
iii
x
f
xxn
xx
x
f
xx
xx
x
f
xx
xx
xx
xfxf
x
f
)()(
...)(!
...)(6
)(2
)(
1
1
3
32
2
2
1
axOx
ff
x
f
n
x
x
fx
x
fx
x
ff
x
f
ii
in
nn
iiii
i
+
−=
−
−−
−
−
−=
+
−
+
x
f
Taylor series expansion:
Neglecting higher-order terms, we can get
Solve for , we get
(2) Backward difference
( )
n
n
n
nn
in
nn
iin
iii
iii
iiiii
x
f
n
xxf
x
f
n
xx
x
fxx
x
fxxxx
x
fxfxf
−+=+
−−++
−−
−+−
−=
=
−
−−−−
1
1
3
33
1
2
22
111
!
)()1()(...)(
!
)()1(...
)(!3
)(!2
)()()()()(
ix
f)(
( )
)()(..)(!
)()1(...
)(6
)(2
)(
)(
)()()(
1
1
1
3
32
1
2
2
1
1
1
bxOx
ff
x
f
n
xx
x
fxx
x
fxx
xx
xfxf
x
f
iiin
nn
iin
iii
iii
ii
iii
+
−=+
−−++
−−
−+
−
−=
−
−
−
−−
−
−
• 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
of of order (Δx).
(2) Backward difference
x
f
Figure 2-2. Illustration of grid points used in Equation (2-6).
• Adind (a)+(b) and neglecting higher-order terms, we can get
(3) Central difference:
HOTx
fx
x
ffff
x
f iiiii +
−
−+−=
−+
3
32
11
3)(2
)()(
...)(!
...)(6
)(2
)(
1
1
3
32
2
2
1
axOx
ff
x
f
n
x
x
fx
x
fx
x
ff
x
f
ii
in
nn
iiii
i
+
−=
−
−−
−
−
−=
+
−
+
)()(
..)(!
)()1(...)(
6)(
2)(
1
1
3
32
2
2
1
bxOx
ff
x
f
n
x
x
fx
x
fx
x
ff
x
f
ii
in
nnn
iiii
i
+
−=
+
−++
−
+
−=
−
−
−
)()(2
)( 211 cxOx
ff
x
f iii +
−=
−+
• which represents the slope of the function f at point B using the values of the function at points A and C, as shown in Figure 2-3.
• This representation of is known as the central difference approximation of order (Δx)2•
(3) Central difference:
x
f
The higher-order term neglecting in Eqs. (a), (b), (c) constitute the truncation error.
Forward:
Backward:
Central:
Truncation error:
)()( 1 xOx
ff
x
f iii +
−=
+
)()( 1 xOx
ff
x
f iii +
−=
−
211 )(2
)( xOx
ff
x
f iii +
−=
−+
if , then (a)+(b) becomes
* Central difference:
Second derivatives:
xxx ii == +1
2
2
11
2
2
)()(
2)( xO
x
fff
x
f iiii +
+−=
−+
( )...)(
!
)(...)(
!3)(
!2
)()(
3
33
2
22
1 +
++
+
+
+=+ in
nn
iiiiix
f
n
x
x
fx
x
fxx
x
fff
( )...)(
!
)()1(...)(
!3)(
!2
)()()(
3
33
2
22
1 +
−++
−
+
−=− in
nnn
iiiiix
f
n
x
x
fx
x
fxx
x
fff
HOTxOx
fxfff iiii ++
+=+ −+
4
2
22
11 )()()(2
If , then (b)-2(a) becomes
* Forward difference:
Second derivatives:
xxx ii == +1
)()(
2)(
2
12
2
2
xOx
fff
x
f iiii +
+−=
++
( ) ( )HOT
x
fx
x
fx
x
fx
x
fxffff iiiiii +
−
+
−
+−=− ++ )(
!32)(
!3
2)(
!2
)(2)(
!2
)2(22
3
33
3
33
2
22
2
22
12
3
2
22
12 )()(2 xOx
fxfff iiii +
=+− ++
( )...)(
!
)(...)(
!3)(
!2
)()(
3
33
2
22
1 +
++
+
+
+=+ in
nn
iiiiix
f
n
x
x
fx
x
fxx
x
fff
( )...)(
!
)2(...)(
!3
2)(
!2
)2(2)(
3
33
2
22
2 +
++
+
+
+=+ n
nn
iiix
f
n
x
x
fx
x
fxx
x
fff
If , then (b)-2(a) becomes
* Backward difference:
Second derivatives:
xxx ii == +1
)()(
2)(
2
21
2
2
xOx
fff
x
f iiii +
+−=
−−
( )...)(
!
)2(...)(
!3
2)(
!2
)2(2)(
3
33
2
22
2 +
++
−
+
−=− n
nn
iiix
f
n
x
x
fx
x
fxx
x
fff
( ) ( )HOT
x
fx
x
fx
x
fx
x
fxffff iiiiii +
+
−
−
+−=− −− )(
!32)(
!3
2)(
!2
)(2)(
!2
)2(22
3
33
3
33
2
22
2
22
12
3
2
22
12 )()(2 xOx
fxfff iiii +
=+− −−
( )...)(
!
)()1(...)(
!3)(
!2
)()()(
3
33
2
22
1 +
−++
−
+
−=− in
nnn
iiiiix
f
n
x
x
fx
x
fxx
x
fff
• By considering additional terms in the Taylor series expansions, a more accurate approximation of the derivatives is produced.
( )HOT
x
fx
x
fxx
x
fff iiiii ...)(
!3)(
!2
)()(
3
33
2
22
1 +
+
+
+=+
2
2
2
1 )()(2
)( xOx
fx
x
ff
x
fi
iii +
−
−=
+
Substitute a forward difference expression for 2f/ x2 , i.e.,
)()(
2)(
2
12
2
2
xOx
fff
x
f iiii +
+−=
++
2
2
121 )()()(
2
2)( xOxO
x
fffx
x
ff
x
f iiiiii +
+
+−−
−=
+++
212 )(2
34)( xO
x
fff
x
f iiii +
−+−=
++
More Accurate Approximations
gives:
ORa second-order accurate finite difference approximation
• For convenience, define the first forward difference fi+1 – fi as Δxf; and the first backward difference fi – fi-1 as ∇x f.
• In general, first order forward and backward differences can be
expressed as and
• Various central difference operators can be similarly defined. Some typical operators are:
Method of Operators
)(1
ix
n
xi
n
x ff = − )(1
ix
n
xi
n
x ff = −
ixixiiix fffff −=−= −+ 11
*2
1
2
1−+
−=ii
ix fff
1111
2
1
2
1
2
2)()(
)()(
−+−+
−+
+−=−−−=
−==
iiiiiii
iixixxix
fffffff
ffff
11 2)( −+ +−=−= iiiixixixx ffffff
2112
2 464)( −−++ +−+−= iiiiiixx ffffff
• Using the operators just defined, the approximations of the higher derivatives by forward, backward, and central differencing may be expressed as
Method of Operators
)()(
)( xOx
f
x
fn
i
n
xin
n
+
=
)(
)()( xO
x
f
x
fn
i
n
xin
n
+
=
even)()(2
)( 222 nforxOx
ff
x
fn
ni
n
xni
n
x
in
n
+
+
=
+−
ddnforxOx
ff
x
fn
ni
n
xni
n
x
in
n
o)()(2
)( 22
1
2
1
+
+
=
−
+−
−
Using operator method
Finite Difference Polynomial • Assume a second order polynomial
• Substituting with discrete points:
• Solving for A, B, and C
• Differentiating:
Finite Difference Equation• Consider the following equation:
Finite Difference Equation – Mixed Derivatives• Consider the 2D Taylor series expansion:
• Using i, j indices in replacement of x,y:
Finite Difference Equation – Mixed Derivatives• Similarly:
* Taylor series expansion:
* Central difference:
* Forward difference:
* Backward difference:
Mixed derivatives:
])(,)[(!2
))((2
!2
)(
!2
)(),(),( 33
2
2
22
2
22
yxoyx
fyx
y
fy
x
fx
y
fy
x
fxyxfyyxxf +
+
+
+
+
+=++
])(,)[())((4
221,11,11,11,1
,
2
yxoyx
ffff
yx
f jijijiji
ji
+
+−−=
−−−++−++
])(,)[())((
,,11,1,1
,
2
yxOyx
ffff
yx
f jijijiji
ji
+
+−−=
++++
])(,)[())((
1,11,,1,
,
2
yxOyx
ffff
yx
f jijijiji
ji
+
+−−=
−−−−
• The finite difference approximations just discussed are used to replace the derivatives that appear in the PDEs.
• Consider an example involving time (t) and two spatial coordinates (x,y); i.e., the dependent variable f is f = f(t,x,y).
• A governing PDE of the form:
• where is assumed constant.
• It is required to approximate the PDE by a finite difference equation in a domain with equal grid spacing.
• The subscript indices i and j are used to represent the Cartesian coordinates x and y, and the superscript index n is used to represent time.
• It is specified that a first-order finite difference approximation in time and central differencing of second-order accuracy in space be used.
• The spatial grid spacings are Δx and Δy, whereas Δt designates the time step.
• The grid system is shown in Figure 2-6.
Finite Difference Equations
Computational grid system for the solution of Equation (2-26).
• Note that the value of f at time level n is known, and the value of f at time level n + 1 is to be evaluated.
• Therefore, Equation may be expressed at time level n or at time level n + 1.
• First, consider Eq. at time level n.
• For this case, a forward difference approximation which is first-order accurate is used.
• Hence,
• Therefore, the finite difference formulation of the partial differential equation (2-26) is:
• The second case, Eq. is evaluated at n + 1 time level.
• Therefore, a first-order backward difference approximation in time is employed, and the spatial approximations are at time level n+ 1.
• Hence, the finite difference formulation takes the form:
• The resulting finite difference equations, (2-27a) and (2-27b), are classified as explicit and implicit formulations, respectively.
• An obvious distinction between two finite difference equations is the number of unknowns appearing in each equation.
• Explicit equation involves only one unknown, fi,jn+1 , whereas Equation (2-
27b) involves five unknowns.
• Thus, the solution procedures based on explicit and implicit formulations
• are different.
Explicit and Implicit Formulations
• In the explicit formulation, only one unknown appears and may therefore be solved for directly at each grid point.
• In the implicit formulation, more than one unknown exists and therefore the finite difference equation must be written for all the spatial grid points at n+ 1 time level to provide the same number of equations as there are unknowns and solved simultaneously.
• Obviously, the solution of explicit formulation is simpler than the implicit equation.
• However, as will be seen shortly, implicit formulations are more stable than explicit formulations.
• Other differences between explicit and implicit formulations are discussed in future chapters.
• If the approximation of the original PDE was such that the truncation error was of the order [(Δt)2 , (Δx)2, (Δy)2 ], in which case the lowest term is of order two, then it would be classified as a second-order accurate method.
Explicit and Implicit Formulations
• Determine a backward difference approximation for f /x which is of the order (Δx)3
• Solution. Consider the Taylor series expansion,
• Substitute the backward difference approximations for 2 f I x2 and 3f I x3
Applications: Hoffman, Example 2.3
( ) 4
3
33
2
22
1 )()(!3
)(!2
)())(( xO
x
fx
x
fxx
x
fff ii +
−
+
−=−
• Substituting the expressions above into (2-33) produces:
Solution
• Using the Taylor series expansion, find a second-order forward difference approximation for f/x with unequally spaced grid points.
Hoffman, Example 2.4.
• . Given the function f(x) = ¼ x2 , compute the first derivative of f at x = 2 using forward and backward differencing of order (Δx). Compare the results with a central differencing of O(Δx)2
and the exact analytical value. Use a step size of Δx = 0.1. Repeat the computations for a step size of 0.4.
• Solution.
• From Equation (2-4), the forward difference approximation of order (Δx)
Hoffman, Example 2.6
• The backward difference approximation which is of order Δx
• The results obtained from backward and forward differencing deviate from the exact value when a larger step size is used. Selection of the step size is extremely important in numerical analysis.
Find a forward difference approximation of 0( Δx) for 4f/x4.
Hoffman, Example 2.1
• Therefore
Solution
• Determine the approximate forward difference representation for 3f /x3 which is of the order (Δx), given evenly spaced grid (a) Taylor series expansion
• (b) Forward difference recurrence formula
• Solution.
• (a) The Taylor series expansions of f(x+Δx), f(x+2Δx), and f(x+3Δx) about x are
Hoffman, Example 2.2.
Using Taylor series
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
𝑛
109
1-D Wave equation
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝑐∆𝑡
∆𝑥× 𝑢𝑖+1
𝑛 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
Assume initial conditions of
𝑢 = 2@ 0.5 ≤ 𝑥 ≤ 1𝑢 = 1@ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒
Assume Boundary conditions𝑢 = 1@ 𝑥 = 0, 2
110
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝑐∆𝑡
∆𝑥× 𝑢𝑖+1
𝑛 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
111
I.C.𝑢 = 2@ 0.5 ≤ 𝑥 ≤ 1
𝑢 = 1@ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒
B.C.𝑢 = 1@ 𝑥 = 0, 2
1-D Wave equation
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𝑛
112
1-D Inviscid Burgers’ equation
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝑐∆𝑡
∆𝑥× 𝑢𝑖
𝑛 × 𝑢𝑖+1𝑛 − 2𝑢𝑖
𝑛 + 𝑢𝑖−1𝑛
Assume initial condition of
𝑢 = 2@ 0.5 ≤ 𝑥 ≤ 1𝑢 = 1@ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒
Assume Boundary condition𝑢 = 1@ 𝑥 = 0, 2
113
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝑐∆𝑡
∆𝑥× 𝑢𝑖
𝑛 × 𝑢𝑖+1𝑛 − 2𝑢𝑖
𝑛 + 𝑢𝑖−1𝑛
114
I.C.𝑢 = 2@ 0.5 ≤ 𝑥 ≤ 1
𝑢 = 1@ 𝑒𝑣𝑒𝑟𝑦𝑤ℎ𝑒𝑟𝑒 𝑒𝑙𝑠𝑒
B.C.𝑢 = 1@ 𝑥 = 0, 2
1-D Inviscid Burgers’ equation
1-D Diffusion equation
𝜕𝑢
𝜕𝑡= 𝜐
𝜕2𝑢
𝜕𝑦2
By applying Forward in time and central in space (FTCS)
𝑢𝑖𝑛+1 − 𝑢𝑖
𝑛
∆𝑡= 𝜐
𝑢𝑖+1𝑛 − 2𝑢𝑖
𝑛 + 𝑢𝑖−1𝑛
∆𝑥 2
By rearranging
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝜐∆𝑡
∆𝑥 2× 𝑢𝑖+1
𝑛 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
115
1-D Diffusion equation𝜕𝑢
𝜕𝑡= 𝜐
𝜕2𝑢
𝜕𝑦2
By applying Forward in time and central in space (FTCS)
𝑢𝑖𝑛+1 − 𝑢𝑖
𝑛
∆𝑡= 𝜐
𝑢𝑖+1𝑛 − 2𝑢𝑖
𝑛 + 𝑢𝑖−1𝑛
∆𝑥 2
By rearranging
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝜐∆𝑡
∆𝑥 2× 𝑢𝑖+1
𝑛 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝑑 × 𝑢𝑖+1𝑛 − 2𝑢𝑖
𝑛 + 𝑢𝑖−1𝑛
116
Application to FTCS-Explicit scheme for the parabolic model equation
117
Application to FTCS-Explicit scheme for the parabolic model equation
118
• Implicit scheme:𝑢𝑖𝑛+1 − 𝑢𝑖
𝑛
∆𝑡= 𝜐
𝑢𝑖+1𝑛+1 − 2𝑢𝑖
𝑛+1 + 𝑢𝑖−1𝑛+1
∆𝑥 2
By rearranging
𝑢𝑖𝑛+1 = 𝑢𝑖
𝑛 + 𝜐∆𝑡
∆𝑥 2× 𝑢𝑖+1
𝑛+1 − 2𝑢𝑖𝑛+1 + 𝑢𝑖−1
𝑛+1
Let r = 𝜐∆𝑡
∆𝑥 2
𝑢𝑖𝑛+1 += 𝑢𝑖
𝑛 + 𝑟 × −2𝑢𝑖𝑛+1 + 𝑢𝑖−1
𝑛+1
− 𝑟 𝑢𝑖+1𝑛+1 + 1 + 2𝑟 𝑢𝑖
𝑛+1 − 𝑟𝑢𝑖−1𝑛+1 = 𝑢𝑖
𝑛
Compare the previous Eq. with the following(where 𝑖 = 1: m)𝑎𝑖 𝑢𝑖+1
𝑛+1+ 𝑑𝑖 𝑢𝑖𝑛+1+ 𝑏𝑖 𝑢𝑖−1
𝑛+1= 𝑐𝑖
where m: number of nodes in y direction,
𝑎𝑖 = −𝑟, 𝑑𝑖 = 1 + 2𝑟, 𝑏𝑖 = −𝑟, 𝑐𝑖 = 𝑢𝑖𝑛
• Implicit scheme:We will get that
Rewriting previous Eqns. In matrix form
• Implicit scheme:
• Implicit scheme:
Parabolic PDEs:
• Richardson method:
– The scheme is second order time and space
– Unconditionally unstable (has no practical value)
Parabolic PDEs:
• DuFort-Frankel method
– The scheme is second order in time and second order in space
– For stability considerations the term in the diffusion term isreplaced with an average between and
– The resulting equation is explicit formulation
– The scheme is unconditionally stable
uin
uin+1
uin-1
Parabolic PDEs: Implicit Methods• Crank-Nicolson method
– The scheme is second order time and space
– The diffusion term is replaced by a time average value of thesecond order central space difference term
– The second order in time is unclear, but if we thought of as asummation of two-step computations:
1. Explicit step
2. Implicit step
Programming Assignment 1Consider 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 𝑢 𝑡, 𝑦 .
126
Programming Assignment 1Assume 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
127
Programming Assignment 1Apply FTCS scheme.
Calculate and plot the velocity distribution by usingMatlab 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.
128