11
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Rules & evaluation
• Ask, work, comment, criticize, etc during the class and USB
• Be punctual*
• Respect: listen to, silence (mute)
• No cell phones unless it is an emergency call, ???
• NOT CHEAT
• No postponed examinations (valid reason)
Evaluation 100 100
Class participation (attendance), homework 10 10
Project 1.5+1.5 1.5+1.5
Test1 30 30
Exam 30 30
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
References
• Chapra, S. & Canale, R.; Numerical methods for engineering;
7th edition; Mc Graw Hill Education; 2015
• Weber, H. & Arfken, G.; Essential mathematical methods for
physicist; Academic Press; 2003
• Ghaboussi, J. & Wu, X.; Numerical methods in computational
mechanics; CRC Press; 2017
• Akio Tomiyama, Kosuke Hayashi, Takeshi Seta, Tomohiro
Takaki, Michihisa Tsutahara
• Some classes at Kobe University: Akira Kageyama
• Any Fortran language & compiler user reference guide
• Any Python guide: numpy, sympy, scipy, pandas, matplotlib
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
There
Do not are three
distribute main
or use scientific
without approaches
permission of thetoauthor
study a problem
* This Photo by Unknown Author is licensed under CC BY-SA * This Photo by Unknown Author is licensed under CC BY-SA
Numerical methods
* MH4 Laboratory, Kobe University
Windows
Linux
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or useWINDOWS
without permission of the author
Gfortran installation by MinGW
• Free Fortran compiler
https://sourceforge.net/projects/mingw-
w64/files/Toolchains%20targetting%20Win32/Personal%20Build
s/mingw-builds/installer/
WINDOWS
Property of Roberto Rojas Property of Roberto Rojas
Change
Do not system
distribute pathwithout
or use to enable commands
permission at the
of the author
terminal: Gfortran
1. My computer: properties
2. Advanced system settings
3. Advanced
4. Environment variables
5. Path and then edit
6. New
Property of Roberto Rojas Property of Roberto Rojas
LINUX permission of the author
Do not distribute or use without
Gfortran and Python installation
1. This tutorial is available at the shared folder
2. If the installation goes well, you will have this:
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Text editor
• Create a new text file and rename it to ****.f90
• Write the code: programming language Fortran
• Different font colors for: functions, comments, commands, etc.
0visualizatecolorstexteditor.f90
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Text editor: Visual Studio Code
• Shift+Control+p
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or useWINDOWS
without permission of the author
How to show file extensions
1. Explorer
2. View and then Options
3. Change folders and search
options
4. Uncheck hide extensions
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Compilation: Option 1
• Open Command Prompt from Windows Start button
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Compilation: Option 1 (continued)
• Go to the folder containing the code : clase.f90
Windows
Linux
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or useWindows
without permission of the author
Compilation: Option 1-Problems
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or useWindows
without permission of the author
Compilation: Option 2
• Open Run Terminal directly from the compiler MinGW
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Visualization application: ParaView
• Read files: *.vtk (special format, numbers)
• Color distribution of parameters: low (blue) and high (red)
• http://www.paraview.org/
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Visualization application: gnuplot
• Plot functions and data files
• Read files: *.txt, *.dat, *.d, *.csv
• http://www.gnuplot.info/
Gnuplot folder:
scripts
screenshoots
Screen shots
Property of Roberto Rojas Property of Roberto Rojas
Visualization
Do not distribute application:
or use without permission of the author
Graph digitizing system-GSYS
• Digitalize images for comparison
• Text files with selected format
• http://www.jcprg.org/gsys/
• Java
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Basic programming concepts
• Program: sequential instructions in a defined language [math,I/O]
• Language to tell the computer what to do [instructions]
• Interactive(short) and Script(long): *.f90 *.py (source code) [syntax]
• Structure: Red for Fortran Blue for Python
Fortran Python
main program (PROGRAM): starting point
subroutines: part of the code to perform a name() def name():
determined task and return a value. CALL name ……..
functions: part of the code to perform a name2(x) def name2(variable):
determined task and return a value with given calculation=f(variable)
arguments. name2(x) return calculation
modules: usually used to separate parts of the import module_name
code and improve readability, e.g declare
common variables. use module_name
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Basic programming concepts (continued)
• Syntax errors: depends on the programming language
• Conditional and repeated instructions
Exponent width (2n) 11 bit (consider 1 bit for sign) 8 bit (consider 1 bit for sign)
u 0
u 1
u u P 2 u g
t
u u u u 1 2u 2u 2u
u v w P 2 2 2 g
t x y z x y z
u u u
u 0 u uu p
0
t x t x r x x x
f
t
c
x
1
f x ,t f x ,t f eq x ,t
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Elasticity & plasticity equations
ji ui 2
Fi 2
x j t
1 ui u j
ij
2 x j xi
ij Cijkl kl
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Error analysis
• Perfect matching is IMPOSSIBLE
• Error: discrepancy between analytical, numerical and
experimental solution
• Round-off errors: finite number of digits in a computer
Chopping or rounding: 3.141592653589793238…2numbers.f90
• Truncation error: finite number of mathematical operations
in a computer
2 3 4 5 6
x x x x x Code this equation
e x 1 x ...... and test diferent
2! 3! 4! 5! 6! approximations
u/Uo
-1
U0
No-slip boundary
No-slip boundary
y Re = 10000 Re = 10000
x No-slip boundary
v/U0
No-slip boundary
v/U0
No-slip boundary
0.6 0.6
0 0
y/L0
y/L0
0.4 0.4
H 0.2 0.2
0 Good predictions of -1 the
0 velocity profiles -1
-1 0 1 -1 0 1
u/U0
Re = 5000 Re = 10000
y 0 0.2 0.4 0.6 0.8 1 x/L0 0 0.2 0.4 0.6 0.8 1
1 FDM (Ertuk et al.)
1 1 FDM (Ertuk at al.)
1
FDLBM FDLBM
x No-slip boundary 0.8 0.8
v/U0
v/U0
0.6 0.6
H=201, Re=100 and 1000 0 0
y/L0
y/L0
0.4 0.4
H=601, Re=5000 and 10000 0.2 0.2
0 -1 0 -1
-1 0 1 u/U0 -1 0 1
Property of Roberto Rojas Property of Roberto Rojas
Examples
Do not distributeofor
error
useanalysis: Sedimentation
without permission of theofauthor
single particles falling through stagnant liquids
Dimensions (10, 10, 16) cm Time step Re
Case
[kg/m3] [Pa s] [s]
Initial position (5, 5, 12.75) cm 1 970 373x10-3 0.86 1.56x10-4 1.3
Diameter 1.5 cm (762) 2 965 212x10-3 0.86 2.73x10-4 3.7
3 962 113x10-3 0.74 3.405x10-4 10.5
Density 1120 kg/m3
4 960 58x10-3 0.64 4.14x10-4 30.1
Falling velocity [m/s] 0
-0.05
IB-FDLBM Measured
-0.1 (Present) (ten Cate et al., 2002)
Case Case
1 1
2 2
3 3
4 4
-0.15
0 1 2 3 4
Reasonable predictions of
t [s] the falling velocity
Property of Roberto Rojas Property of Roberto Rojas
Examples
Do not distributeoforerror
use analysis: Drafting-kissing-
without permission of the author
tumbling motion of two particles
2
2 cm 1.8
P2(0.999,7.2) 1.6
1.4
Drafting
XP [cm]
1.2
P1(1,6.8) 1
Niu et al. (2006)
0.8
D= 0.2 cm 20 s-1 Particle 1
Particle 2
0.6 IB-LBM based on Dupuis (2008)
20Dx for D 0.4 Particle 1
Nm = 360 Kissing Particle 2
Present
0.2 Particle 1
1010 kg/m3 0 Particle 2
0 1 2 3 4 5
Vorticity
t [s]
g =981 cm/s2
8 cm 8
Niu et al. (2006)
7 Particle 1
Particle 2
IB-LBM based on Dupuis (2008)
6
Tumbling
Particle 1
= 1.0x10-3 5
Particle 2
Present
YP [cm]
Particle 1
Pa·s Particle 2
-20 s-1 4
= 1.0x103 3
kg/m3
2
= 0.65
1
A = 0.5 0
Reasonable predictions
0 1 of the
2 particle
t [s]
3 paths
4 5
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Errors in arrays: norm
Maximum
u predicted u exact
l max
IJ fluid u exact
L2-norm
u x u x
predicted exact 2
x fluid
Error
u x
exact 2
x fluid
Property of Roberto Rojas Property of Roberto Rojas
Examples
Do not distributeoforerror
use analysis: Circular Couette
without permission of the author
flows
1.5
(Re, ) = (0.038, 20) Analytical Analytical Solution (Eq. (1.23))
SRT: (Re, ) =(0.079,10)
TRT: (Re, , )=(0.079,10,0.53)
solution
1
R R
out
u/U
uT R R
out 0.5
U Rin R
out
Rout Rin
0
Non-physical distortion
TRT agrees Outer Cylinder Fluid Inner Cylinder
Region Region Region
better than SRT -0.5
0 20 40 60 80 100
x
u/U 0 1
Axisymmetric
flow fields at
low Re
(Re,,) = (1.5,1,1) (0.17, 5, 0.56) (0.079, 10, 0.53) (0.038, 20, 0.51)
Property of Roberto Rojas Property of Roberto Rojas
Examples
Do not distributeoforerror
use analysis: Circular Couette
without permission of the author
flow-errors at different grid resolutions
0.5 Error
0.45 +=10; A=0.5
upredicted uexact
0.4 201x201 l max
IJ fluid uexact
401x401
0.35 801x801 1.5
Re
Re 0.038
0
0.3 10
Smaller error
0.25 with TRT
l
-1
10
0.2
0.15
l
10-2
0.1
SRT
0.05 TRT, =1/4
10-3 -1
0 -4 -3 -2 -1 0 1 2 3 10 100 101 102
10 10 10 10 10 10 10 10 for SRT, + for TRT
Read the given files and calculate the norm
(maximun error) in the velocity profiles
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Linear algebraic equations
1. Gauss elimination
2. LU decomposition and matrix inversion
3. Special matrices and Gauss-Seidel
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Roots of equations
1. Bracketing methods
2. Opened method
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Graphical method
• Easy and allows to identify the points
where a given a function is cero
• Low accuracy
• This result can be used as input for more
accurate methods
explicit
Try now to isolate c (implicit)
g=9.81m/s2,m=70,v=40m/s, t=10s
• May diverge
• Fast convergence
Modification
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Optimization
1. One-dimensional unconstrained optimization
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Curve fitting
1. Least-squares regression
2. Interpolation
3. Fourier approximation
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Introduction-derivation
Derivative
a b x a x
b
D n=6 D n=5
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Integration
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Integration-trapezoidal rule
First order polynomial (line) Slope straight line equation
y1 mx B
y2 Ax 2 Bx C
n=2
n: even
Property of Roberto Rojas Property of Roberto Rojas
Do notExample:
distributeFlow past
or use a circular
without cylinderof(bluff
permission the author
body), drag and lift coefficient
Fluid in motion: pressure and shear stress
Differential force (vector)
Area vector or
scalar? x-axis
y-axis
Area?
In 2D circle
dA=dS*span
dS=rd
dA=Dd/2*span
Given values:
projected : fluid density
V: freestream velocity
A projected: depends on
projected the body shape
Briefly explanation Paraview and file.vtk
Property of Roberto Rojas Property of Roberto Rojas
Flows
Do not past a circular
distribute cylinder
or use without at a wide range
permission of the of
author
Re: IBFDLBM
50D
Uniform inflow
at U0
(20D,20D)
40D
Cylinder
40Dx for D
y Nm = 126
x Continuous outflow
102 0.4
Measured (Wieselsberger, 1922) Measured (Roshko, 1954)
FDM (Lei et al., 2000) Measured (Schewe, 1983)
FDM (Matsumiya et al., 1993) FDM (Lei et al., 2000)
IB-FDLBM (Present) 0.3 FDM (Matsumiya et al., 1993)
1 IB-FDLBM (Present)
10
CD St 0.2
100
0.1
10-1 -1 0 1
10 100 101 102 103 104 105 10 102 103 104 105
High (High Re Low (Low High (High Re Low (Low
Property of Roberto Rojas Property of Roberto Rojas
Streamlines
Do not of flows
distribute or past a permission
use without stationary circular
of the author
cylinder at different Re
Re = 100 Re = 100000
Re = 20
Re = 40
A Pair of stationary Vortex shedding Irregular vortex
vortices shedding
v cos()
u
u sin()
t
Time 1 Time 2
1D
space space
Time 1 Time 2
2D
space space
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Taylor expansion
f xi 2 f xi Dx 2 3 f xi Dx3
f xi Dx f xi Dx ....
x x 2
2 x 3
6
5
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Example
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Example
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Taylor expansion: multivariable
For a two-dimensional function f(u,v)
f f
f ui 1 ,vi 1 f ui ,vi ui 1 ui vi 1 vi
u v
1 2 f 2 f 2 f 2
2 ui 1 ui 2 ui 1 ui vi 1 vi 2 vi 1 vi ....
2
2 ! u uv v
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Partial derivatives
For a two-dimensional function f(x,y)
dt dt 2
t df
f1 f , f 2 f '
f f e
0
dt
df1
f2 d f1 0 1 f1
:time constant dt 2
dt f 0 f
relaxation time df 2 2 2
f12
f
f0=5,=1 dt
df
Af , f 0 f 0
dt
time
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Discretization in 1D
f ni-1 f ni f ni+1
tn
x1 xi-1 xi xi+1 ximax
i=1 i = imax
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Explicit and Implicit Euler Methods
Discretization of time
f t n f nDt f n , f t n 1 f t n Dt f n 1
Forward, backward and centered differences for a derivative
f t Dt f t
n n n n 1
n n df d 2
f Dt 2
df f f n
dt
Dt 2
2
... Forward
dt dt Dt
n n
df d2 f Dt 2
n n
f t Dt f t Dt 2 ... df n
f n f n1
dt dt 2 Backward
dn Dt
df n
f n 1 f n 1
Centered
dt 2Dt
f(t)
n n 1
df df
f n 1 n
f Dt f n 1 f n Dt
dt dt
n-1 n n+1
Explicit Euler Implicit Euler
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Euler method (pseudo code)
Ex.: df f fn
, f (0) f 0 Explicit Euler: f n1 f n Dt
dt
INPUT PARAMETERS tau, f0, dt, tend
f=f0
t=0.d0 Numerical stability
do n = 1, tend Dt n
n 1
t=t+dt f 1 f rf n
f=f-(f/tau)*dt
write(*,*) t,f r 1
end do f n rn f 0
Unstable
stop Dt 2 FAIL
IMPORTANT: Know-How
Dt in explicit method must be less than the time constant!
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Round-off Error
Limitation of the digit numbers computer
n 1 n fn If 1, Dt 0.000001
f f Dt
f n 1 0.999999 f n
n 1
If CPU can handle only 5 digits, 0.9999991, then f f n
round-off
Mathematically Dt0 makes FDE solution converge to exact
solution
In reality, too small Dt results in increasing errors
Error
Dt
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Other schemes for time derivation 1
Euler type 1 Euler
f n 1 f n F n 1 F n 1 Dt 0 Backward Euler impl.
1 / 2 Trapezoidal
2
n
1
f n 1 f n Dt F f 2
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Other schemes for time derivation 2
f n 1 n
n
f 55F 59 F n 1
37 F n2
9F n 3
Dt
24
Predictor-corrector method
dz
0.6 z 8 y 0 z new z old Dx 8 y old 0.6 z old
dx
y0 4
z0 0
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Other examples
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Other examples
Solution
dx x new
x old
Dt v old
v
dt Dt
dv v new
v old
cv kx
old old
m cv kx 0 m
dt
x 0 1[m]
v 0 0[m / s ]
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Other examples
2D damped oscillator
x 0 1[m]
dx dy
u v y 0 1[m]
dt dt
du dv u 0 1[m / s]
m cu kx m cv ky
dt dt v 0 0[m / s ]
m 1[kg ]
c 0.25[ Ns / m]
k 1[ N / m]
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Other examples Solution
E Ekinetic E potential
1 1 2
E mV (t ) kx (t )
2
2 2
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Some equations in Mechanical Engineering
4. Linear algebraic equations
5. Roots of equations
6. Optimization
7. Curve fitting
8. Numerical differentiation and integration
9. Ordinary differential equations (Section taken from Prof. Tomiyama)
10.Partial differential equations
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Partial differential equations
Order
f 2 f
5f 5f
t t 2
Linear or non-linear
2 f 2 f 2 f 2 f
2 S f 2
x 2
y x 2 y 2
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Types of partial differential equations
General form of 2nd order linear PDE
2 f 2 f 2 f f f
A 2 B C 2 a b cf g 0
x xy y x y
B 2 AC 0 Elliptic
B 2 AC 0 Parabolic
B 2 AC 0 Hyperbolic
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Typical equations
Diffusion equation
f 2 f : diffusion coefficient [m2/s] Parabolic
2
t x
Wave equation
2 f 2
f c: phase velocity [m/s] Hyperbolic
c 2
0
t 2
x 2
Poisson equation
Laplace equation
2 f 2 f Elliptic
2 S S: source & sink
x 2
y
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Examples of 2 nd order PDF
Advection-diffusion equation
f f 2 f f
u 2 S u f 2 f S
t x x t
Advection f u f 0 f f f f
u v w 0 Hyperbolic
eq. t x t x y z
f 2
f f 2 f 2 f 2 f
Diffusion 2 2 2 2 Parabolic
eq . t x t x y z
Poisson d2 f 2 f 2 f 2 f Elliptic
S 2 2 S
eq. dx 2
x 2
y z
Navier- u u 2
u 1 P
u 2 Parabolic
Stokes eq. t x x x Hyperbolic
Elliptic
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Advection-diffusion equation
Property of Roberto Rojas Property of Roberto Rojas
Discretization
Do not distribute orofuse
partial differential
without equations
permission of the by
author
finite difference method
Using the following functions
f iDx f xi , f ( xi ,t n ) f i n , f ( xi , y j ,t n ) f ijn , f ( xi , y j , zk ,t n ) f ijkn
Write down FDE:
f 2 f Time: centered, space: centered
2 Time: backward, space: centered
t x
f f f Time: forward, space: upwind (u,v >0)
u v 0 Time: forward, space: upwind (u>0, v <0)
t x y
2 f 2 2 f
2
u 2
0 Time: centered, space: centered
t x
2 f 2 f 2 f
2 2 S ( x, y, z ) Space: centered and solve for f
x 2
y z ijk
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Solution
f i n 1 fi n 1 fi n1 2 fi n fi n1 f i n 1 f i n fi n11 2 fi n 1 f i n11
2Dt Dx 2
Dt D x 2
f ijn 1 fijn f ijn f i n1 j f ijn fijn1
u v
Dt Dx Dy
f ijn 1 fijn f ijn f i n1 j f ijn1 f ijn
u v
Dt Dx Dy
f i n 1 2 f i n fi n 1 f n
2 f n
f n
u 2 i 1 i i 1
Dt 2 Dx 2
1 fi 1 jk fi 1 jk f1 j 1k fij 1k fijk 1 fijk 1
fijk 2 2 2 2
2
2
2( x Dy Dz ) Dx Dy Dz
Sijk
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Elliptic equations
Relevant phenomena: potential and steady diffusion problems,
e.g. potential flow, electric potential, steady state T&C profiles
Basic form:
d2 f
2
S
dx
2 f 2 f 2 f
2 2 S 2 f S
x 2
y z
div grad f S
f1 1
f1 2 f2 f3 2Dx2
f2 2 f3 f4 3Dx2
... ... ... ...
fi1 2 fi fi1 i Dx2
... ... ... ...
fi max3 2 fi max2 fi max1 i max2Dx2
fi max2 2 fi max1 fi max i max1Dx2
fi max fi max1
imax equations
imax unknows ( fi )
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
1D Poisson equation-solution-linear system
1 f1 1
1 2 1 f Dx2
2 2
1 2 1 f3 3Dx 2
... ... ... ... ...
1 2 1 fi iDx2
... ... ... ... ...
1 2 1 fi max2 i max2Dx2
1 2 1 fi max1 i max1Dx
2
1 f f
i max i max1
This matrix is imax x imax
This can be large
Sparse matrix
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Example 27.1
Problem sketch and conditions 2T
h(Ta T ) 0
x 2
L 10m
Ta 20C
TBC1 TBC2
T1 40C
T2 200C
h ' 0.01m2
T1 T2 T3 T4
1
2 i 1
T 2Ti Ti 1 h ' Ta Ti 0 Discretization
Dx
Valid for all interior nodes.
Ti 1 2 h ' Dx Ti Ti 1 h ' Dx Ta 0
2 2
First and last terms are BC
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Solution Ex. 27.1
Linear system
Temperature
distribution
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Parabolic equations
Relevant phenomena: diffusion, heat conduction, viscous flow
Basic form:
f 2 f
2
t x
f 2 f 2 f 2 f f
2 2 2 2 f
t t
x y z
f
div grad f
t
Conditions for obtaining solution f (r,t):
Initial conditions: f (r,0)
Boundary conditions
Steady state solution of parabolic eq.= solution of elliptic eq.
Property of Roberto Rojas Property of Roberto Rojas
Do notExample-parabolic equation:
distribute or use without heat equation
permission of the author
(diffusion)
Problem f t , x 2 f
2 (0 x L)
t x
L 10m
Ta 20C
T1 40C
T2 200C
h 0.01m 2
T 2T
2 h(Ta T ) 0 Steady state solution
t x
Dt
Ti n 1
Ti 2 Ti n1 2Ti n Ti n1 Dt * h * Ta Ti n
n
Dx
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Solution Ex. 27.1
Temperature distribution in steady state
Property of Roberto Rojas Property of Roberto Rojas
Example-parabolic
Do not distribute or use equation: 2D heat diffusion
without permission of the author
in a plate
Problem
T 2T 2T
2 2
t x y
T Example of boundary
0 condition
y
T
T T BiT
0 BiT x
x x Ti max Ti max 1
BiTi max 1
Dx
Bi 5 Ti max Ti max 1 DxBiTi max 1
T 1
Property of Roberto Rojas Property of Roberto Rojas
2D heat diffusion
Do not distribute in a plate-temperature
or use without permission of the author
distribution
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Hyperbolic equations
Relevant phenomena: all kind of waves sound, light, water
wave
Basic form: 2 f 2
f
c 2
0
t 2
x 2
2 f 2 f
2
2 f 2 f 2 f
c 2 2 2 0 c f 0
2 2
t 2
x y z t 2
2 f
c 2
div grad f 0
t 2
Dx
i i 1
n
CFL (Courant-Friedrich-Levy) number
in 1 in c in in1 u Dt c<1
c
Dx stable
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Finite difference schemes for advection
First order upwind scheme f f xI , y J f xI m , y J
ODx
Second order u.s. x Dx
f 3 f xI , y J 4 f xI m , y J f xI 2 m , y J
ODx 2
x 2Dx
Third order u.s.
f f xI 2 m , y J 6 f xI m , y J 3 f xI , y J 2 f xI m , y J
ODx 3
x 6Dx
m 1,u 0; m 1,u 0
Fourth order central difference scheme
f f xI 2 , y J 8 f xI 1 , y J 8 f xI 1 , y J f xI 2 , y J
O Dx 4
x 12Dx
D n 1
uijn 1 uin11j
vijn 1 vijn11
0
u u
n
ij
n
i 1 j
ij 0
u n
u
n
u 0
ij
Dx Dy x
u u
n
i 1 j
n
ij
n
ij
uijn1 uijn u n
u n
y P n1
i 1 j P n1
ij
u n
i 1 j 2u n
ij u n
i 1 j u n
ij 1 2u n
ij u n
ij 1
uij
n x
vC
n
Dt Dx Dy Dx Dx 2
Dy 2
Pij+1
( j +1 ) ui-1j+1 uij+1
vij vi+1j
Staggered mesh
Pij Pi+1j
(j) ui-1j
uij
vij-1 vi+1j-1
(i) ( i +1 )
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
134
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Elliptic equation solvers
Linear equation system
Iterative methods
Point Jacobi method
Gauss-Seidel method
SOR method
ICCG (Incomplete conjugate gradient)
ILUCR (Incomplete LU conjugate residual)
BiCGStab (Bi-conjugate conjugate gradient stabilize)
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Point Jacobi method
Poisson equation
d2 f f i 1 2 f i fi 1
S Si
dx 2
Dx 2
2
The iteration process finishes (convergence) if the maximum
error is less than the admissible error
max fi m 1 f i m
This method is very slow
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Gauss-Seidel method
Poisson equation
d2 f f i 1 2 f i fi 1
S Si
dx 2
Dx 2
2
The iteration process finishes (convergence) if the maximum
error is less than the admissible error
max fi m 1 f i m
This method is slow
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Successive over-relaxation SOR method
Poisson equation
d2 f f i 1 2 f i fi 1
S Si
dx 2
Dx 2
vij-1 vi+1j-1
2 i i +1
1 Staggered mesh
1 2 i Dx imax
n 1
uijn 1 uin11j
vijn 1 vijn11
0
u n
u n
u n
ij 0
D u xn ijn i 1nj
u 0
ij
Dx Dy ui 1 j uij n
ij
uijn1 uijn n u
n
u n
y P n1
i 1 j P n1
ij
u n
i1 j 2u n
ij u n
i 1 j u n
ij 1 2u n
ij u n
ij 1
uij vC
n
x
Dt Dx Dy Dx
Dx 2
Dy 2
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Simplified Marker & Cell Method (SMAC)
uijn 1 uin11j vijn 1 vijn11
0 un 1
Dx Dy
n1 n1
Dt Pi 1 j P
uijn1 ij
Fxijn Solution of parabolic
Dx
equation
n1 n1
Dt P P Dt n1 Dt n
n1
vij ij 1 ij n1
Fyij u P F ,
n n
u P F n
Dy
Dt u un1 u
u P P P n1
P n
un1 u u 0 u u
Solution of
2P u Poissons’ equation
Dt
Pn1 Pn P Dt Update
n 1
u u u u P
Property of Roberto Rojas Property of Roberto Rojas
SimplifiedorMarker
Do not distribute & Cellpermission
use without Method (SMAC)
of the author
(continued)
Dt n
Solution of parabolic equation u P F n
Dt Pi1 j Pij
n n n n
D t P P
uij Fxijn , vij
ij 1 ij
Fyijn
Dx Dy
uij ui 1 j vij vij 1
Computation of divu Dij 0
Dx Dy
Solution of Poisson’s equation P u 2
Dt
Pi 1 j 2Pij Pi 1 j Pij 1 2Pij Pij 1
Dij
Dx 2
Dy 2
Dt
Dt
Update Pij Pij Pij , u u P
n1 n n 1
Dt Pi1 j Pij Dt Pij 1 Pij
uij uij
n1
, vij vij
n1
Dx Dy
Property of Roberto Rojas Property of Roberto Rojas
Do not distribute or use without permission of the author
Boundary conditions
Velocity B.C. Pressure B.C.
No-slip wall Inflow Continuous outflow
v1j v2j v1j v2j normal
u1 j 0 u1 j uin
j u1j
j
u1j
j
Pimax-1 j Pimax j
Pimax j 0
v1 j v2 j v1 j 2vin v2 j
1 2 1 2 imax-1 imax
Inflow Dy Outflow
u=uin Pout=0
=const
v=0
2
1
1 2 Dx imax