0% found this document useful (0 votes)
6 views77 pages

MN Notes..... ,.... ,........

The document outlines a course on Numerical Analysis at Escuela Politécnica Nacional, detailing rules, evaluation criteria, and key topics such as error analysis, differential equations, and finite element methods. It emphasizes the importance of programming languages like Fortran and Python for numerical computing, alongside various visualization tools. Additionally, it discusses the significance of discretization and error analysis in numerical methods.

Uploaded by

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

MN Notes..... ,.... ,........

The document outlines a course on Numerical Analysis at Escuela Politécnica Nacional, detailing rules, evaluation criteria, and key topics such as error analysis, differential equations, and finite element methods. It emphasizes the importance of programming languages like Fortran and Python for numerical computing, alongside various visualization tools. Additionally, it discusses the significance of discretization and error analysis in numerical methods.

Uploaded by

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

Numerical analysis

Roberto Carlos Rojas Molina

Escuela Politécnica Nacional


Facultad de Ingeniería Mecánica

11

Rules & Evaluation


• Ask, work, comment, criticize, etc. during the class
• Be punctual*; Respect: listen to, silence (mute)
• No cell phones unless it is an emergency call
• NOT CHEAT
• No postponed examinations (valid reason)
• USB
Evaluation 100 100
Class participation 10 10
Project/homework 20 20
Test1 35 35
Test2 35 35

1
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
• Class of Akira Kageyama at Kobe University
• Any Fortran language & compiler user reference guide
• Any python guide: NumPy, SymPy, SciPy, pandas, matplotlib

Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations
8. Partial differential equations
9. Finite element method

2
There are three main scientific approaches to
study a problem

Experimental Simulation More complicated


approach * MH4 Laboratory, Kobe University
situation

Multiscale modeling: there are “three” scales to


study a physical phenomenon
Microscopic scale Mesoscopic scale Macroscopic scale

* 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

Molecular dynamics Lattice Boltzmann Discretization of Navier-


(Newton) method Stokes equations

3
Fluid Mechanics & Heat Transfer equations

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    uu  p                0

t x t x r   x x  x 

 1 2   1 2   e  u u  u 
 e  u    e  p  u u   '   u         u    0
t   r   x 
2  2  x  x   x  x 

f
t
 c

x
1
 
f  x ,t    f  x ,t   f eq  x ,t 

Elasticity & Plasticity equations

 ji  2 ui
 Fi   2
x j t

1  ui u j 
 ij  
2  x j xi 

ij  Cijkl  kl

4
Numerical analysis involves some fields
• Numerical analysis: mathematics, computer science,
engineering and others that create and implement
algorithms for solving problems. NUMBERS IN A
COMPUTER
• E.g. numerical study of fluid dynamics (differential
equations): computer science (programming language)
and numerical analysis (discretization and solution
techniques)
• A computer can be viewed as a virtual laboratory
• Effect of computer hardware and techniques for
optimizing calculations

Software&Tools
• Programming: Fortran (Gfortran)
• Text editor: Notepad++

• Visualization tools: gnuplot

5
Text editor
• File extension can be changed: *.f90
• Colors appear depending on the programming language
• Different font colors for: functions, comments, commands, etc.

0visualizatecolorstexteditor.f90

WINDOWS
How to show file extensions

1. Explorer
2. View and then Options
3. Change folders and search
options
4. Uncheck hide extensions

6
Visualization application: ParaView
• Read files: *.vtk (special format, numbers)
• Color distribution of parameters: low (blue) and high (red)
• http://www.paraview.org/

Visualization application: gnuplot


• Plot functions and data files
• Read text files: *.txt, *.dat, *.d, *.csv
• http://www.gnuplot.info/

Gnuplot folder:

scripts

screenshoots

Screen shots

7
Visualization application:
Graph digitizing system-GSYS
• Digitalize images for comparison
• Text files with selected format
• http://www.jcprg.org/gsys/
• Java

Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations
8. Partial differential equations
9. Finite element method

8
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. CALL name ……..
functions: part of the code to perform nv=name2(x) def name2(variable):
calculations and return a value for given calculation=f(variable)
arguments, new_variable= name2(x) return calculation
modules: usually used to separate parts of the import module_name
code and improve readability, e.g declare
common variables, libraries. use module_name

Basic programming concepts (continued)


• Syntax errors: depend on the programming language
• Conditional and repeated instructions

• Good program (code)


• readability
• self checking code (/0, logarithms of negative numbers)
• represent physics
• We are going to live in the terminal so let’s practice!

9
Why Fortran? Also why python?
• Scientific and numerical computing: normally taken from a
research group
• Could be free
• Programming can be a little tedious but it gives good
understanding from the mathematical point of view
• Easy for parallelization
• *.exe file is portable
• Not good for handling text and system interface but it focuses
on “numerical computing”, for this, python is better
• Since it is a compiled language like C, C++, Visual Basic, and
so on (opposite to interpreted language like MATLAB,
MATHEMATICA, python, etc.), it is very fast

gfortran name_of_program python3 name_of_program

Data type in Python


• Data: variables, constants or parameters, operators and
reserved words
• Reserved words: if, else, for, etc.
• Variable types
• Integer numbers
• Real numbers (floating point numbers)
• Text strings
• Arrays (NumPy):(dim1,dim2), (dim)
• Parameters or constants
• Logical statements

10
Double vs. single precision floating point format
• It is useful for understanding use of computer memory
Double (8bytes or 64 bits)* Single (4bytes or 32 bits)

Sign (number) 1 bit 1 bit

Exponent width (2n) 11 bit (consider 1 bit for sign) 8 bit (consider 1 bit for sign)

Significant precision 52 bit 23 bit


(Mantissa)

Approximately 253~ 15 -17 digits 224~ 6 -9 digits


significant digits
Max. and min. 211-1~ 1024 21024~ 10308 28-1~ 128 2128~ 1038
number 10-308 10-38

* 1 byte = 8 bites, example: one character is one bite 1characterbit.txt 2numbers.f90

python: operators, conditionals, loops, and


others
• Operators: +,-,*,/,//,=,**,%,+
• Logical expressions: true or false
• <; .<=; >; >=; ==; !=
• Logical operators: and; or
• Conditional statements: if (logical expression): 3writedisplay.py
expression
elif:
else: 4readdisplayif.py

• Loops: for var in range(exp1, exp2, exp3): 5sum.py


while (logical expressions):
• Break ends the loop and goes to the line after the loop,
continue skips the rest of the loop and goes to the next item
in the loop

11
Discretization
 Space and time are continuous
 Infinite  finite (discretize)
Space

Continuous
1D
Discrete

2D

Continuous Discrete

python: I/O
• Read for input and write for output, e.g. read ‘r’ and write ‘w’
• 6d : 1 integer number of width 6 digits
• 12.3f: 1 real number of width 12 with 3 decimal digits (no
exponent)
• 10.5E: 1 real number in exponent notation of width 10 and
5 decimal digits in the mantissa (exponent E)
• 10: string with 10 characters aligned left
6readmatrix.py
• >10: string with 10 characters aligned right
7readfromfile.py
• : spaces
8example read from input
• \t : tab
9grid

• File I/O name = open (‘name.dat’; ‘name.txt’; ‘name.d’; any


file, ‘r’; ‘w’)

12
Tips for writing good codes
• Readable: avoid jumps to other statements
• Simple: to increase performance
• Add comments: collaboration with others, and use “!” “#”. At
the beginning with name and date, and when necessary
• Test: to confirm accuracy with a benchmark problem
• Improve efficiency: by testing optimization tools
• Declare all the variables: IMPLICIT NONE
• When getting “segmentation fault”, check arrays
• Parenthesis, exponentiation, multiplication, addition
• Fortran is not sensible to upper&lower cases, but python is

Calculation speed
• FLOPS: floating point operation per second
• For a human, multiply once two floating point numbers and
check the time 1FLO
 10 3 FLOPS  1mFLOPS
1000s
• Human living only for this task, she or he could perform:
1mFLOPS *100 years  3*106 FLOP
• In a computer, this is easy
• Computer speed: GFLOPS (109)
• Supercomputer: TFLOPS(1012)-PFLOPS(1015) www.top500.org
• Walk ~ 1m/s, light velocity ~ 3*108m/s: 108
• Supercomputer vs. brain : 1018 Taken from Akira Kageyama

13
Tokyo Institute of Technology
Tsubame supercomputer 2.5

1442 nodes with 4264 GPUs: 2.5PFLOPS


Walk ~ 1m/s vs. light velocity ~ 3*108m/s: 108
Brain ~ 1*10-3FLOPS vs. supercomputer : 1018

Streamlines for a given velocity field: vtk files


example taken from Fox&McDonald’s Introduction to Fluid Mechanics

Paraview: plot over line

14
Numerical Analysis
1. Introduction
2. Basic programming concepts 0

3. Error analysis

Falling velocity [m/s]


-0.05

4. Roots of equations
IB-FDLBM Measured
(Present) (ten Cate et al., 2002)
-0.1
5. Linear algebraic equations Case
1
Case
1
2 2
3 3

6. Curve fitting
4 4

-0.15
0 1 2 3 4
t [s]
7. Ordinary differential equations
8. Partial differential equations
9. Finite element method

Error analysis
• Perfect matching is IMPOSSIBLE
• Error: discrepancy between analytical, experimental and
numerical 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
x1 x 2 x3 x 4 x5 x 6 Code this equation
e  1        ......
x and test diferent
1! 2! 3! 4! 5! 6! approximations

• Accuracy: closed to true value


• Precision: not closed to true value but in same position

15
True and approximated errors
• Relative error is a tool for comparison or assessment of a
scientific technique

predicted  analytical Determine the


%errorT  100% relative error of
the previous
analitycal example

• Approximated error: for iterative methods


current  previous
%errorA  100%
current
• Error can be calculated until a condition is fulfilled (error
within a given range, es)
• Always look for the worst prediction
• Errors propagate and worst scenario UNSTABLE

Truncation error: relative error comparison

16
Total error

Examples of error analysis: Poiseuille flow


Uniform inflow at U0 2
Analytical Solution
Present method
No-slip
y
2R u/U0 1
x

No-slip Reynolds number


U 0 (2R )
Re  0
Continuous outflow  -1 0 1
Velocity field y/R
1

u/Uo

-1

Pressure field Developed velocity profile

17
Examples of error analysis: Streamlines of
driven cavity flows
Re = 100 Re = 100

U0

No-slip boundary
No-slip boundary

y Re = 10000 Re = 10000

x No-slip boundary

H=201, Re=100 and 1000


H=601, Re=5000 and 10000

Evolution of the secondary vortices

Examples of error analysis: Velocity profiles of


driven cavity flows
Re = 100 x/L0 Re = 1000
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1 LBM (Hou et al.)
1 1 1
FDM (Ertuk at al.)
FDLBM FDLBM
0.8 0.8
U0
v/U0

v/U0
No-slip boundary
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

18
Errors in arrays: Norms

Maximum

f IJpredicted  f IJexact
l  max
IJ domain f IJexact

L1-norm

f IJpredicted  f IJexact
Norm  
IJ domain f IJexact

Errors in arrays: norms (continued)

L2-norm
2
 f IJpredicted  f IJexact 
Norm 2   
IJ domain  f IJexact

L2-norm

  f IJpredicted  f IJexact 
2

Norm 2  IJ domain

 f
IJ domain

exact 2
IJ

19
Examples of error analysis: Circular Couette
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 Rout R
 0.5
U Rin Rout

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)

Maximum error for circular Couette flows

Maximum

upredicted ( xIJ )  uexact ( xIJ )


l  max
IJ  fluid uexact ( xIJ )

20
Examples of error analysis: Circular Couette
flow-errors at different grid resolutions
0.5 Error
0.45 +=10; A=0.5
u predicted  uexact
0.4 201x201 l  max
IJ  fluid u exact
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
-3
10
0 -4 -3 -2 -1 0 1 2 3 10-1 100 101 102
10 10 10 10 10 10 10 10  for SRT, + for TRT
 Read the given files and calculate the norm
(maximum error) in the velocity profiles

Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations
8. Partial differential equations
9. Finite element method

21
Roots of equations
Find the solution of linear and non linear equations

1. Bracketing methods
2. Opened method

Graphical method
• Easy and it allows to identify the points
where a given a function is zero
• Low accuracy
• This result can be used as an input for more
accurate methods
gm
v
c
1  e  ( c / m )t  explicit
Try now to isolate c (implicit)
gm
f (c ) 
c
1  e(c / m)t   v
Plot the function with g=9.81m/s2,c=1,v=40m/s, t=10s, and
determine the roots in a given interval m [0:50 kg]

g=9.81m/s2,m=70kg,v=40m/s, t =10s

f (x) = sin 2x + cos 10x [0:pi]

22
Bisection method
• Function changes its sign,
that is the half that contains
the root
• Reduce width of the bracket
• Halve the increment and
check where the prediction is
• Run until finding a
convergent solution

xrnew  xrold Code the method


a  100%
xrnew

Relative error comparison

23
False-point method
• Bisection: inefficient since the
magnitude of f is not considered
• Intersection with x is an
improved prediction
f ( xl ) f ( xu )

xr  xl xr  xu
f ( xu )  xl  xu 
xr  xu 
f ( xl )  f ( xu )

• Replace xu or xl with xr Code the method

• Check the sign of f (xl)*f (xr)


• Run until convergence

Relative error comparison

24
Roots of equations
1. Bracketing methods
2. Opened method

Introduction
• Bracketing methods are convergent, and they need an interval
• Opened methods require only a single starting value or two
values that do not necessarily include the root. Sometimes,
these diverge. However, when these converge, it is very fast

25
Newton-Raphson method
• Initial guess and a tangent to the x-axis
• The intersection with x-axis is the estimated root
f ( xi )  0
f '( xi ) 
xi  xi 1
f ( xi )
xi 1  xi 
f '( xi )
Code the method

Example
e x  x

Poor convergence
• Inflection points and oscillations
• Multiple roots

26
Secant method
• Derivative is an issue
• Derivative can be approximated by a backward FD

f ( xi )
xi 1  xi 
f '( xi )
f ( xi 1 )  f ( xi )
f '( xi ) 
xi 1  xi
f ( xi )  xi 1  xi 
xi 1  xi 
f ( xi 1 )  f ( xi )

Secant method-continued
f ( xu )  xl  xu 
xr  xu 
f ( xl )  f ( xu )

f ( xi )  xi 1  xi 
xi 1  xi 
f ( xi 1 )  f ( xi )
• May diverge
• Fast convergence
Modification
f ( xi   xi )  f ( xi )
f '( xi ) 
 xi
 xi f ( xi )
xi 1  xi 
f ( xi   xi )  f ( xi )

27
Application of roots of equations

Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations
8. Partial differential equations
9. Finite element method

28
Linear algebraic equations
Direct methods:
1. Gauss elimination
2. LU decomposition and matrix inversion

Point iterative methods


1. Special matrices and Gauss-Seidel

Application: linear equation system

Join A Join B Join D

29
Application: linear equation system (continued)

Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations
8. Partial differential equations
9. Finite element method

30
Curve fitting
1. Least-squares regression
2. Interpolation
3. Fourier approximation

Fast Fourier transformation (FFT)


 Converts a signal into individual components with
characteristic amplitudes and frequencies

31
Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations (Section taken from Prof. Tomiyama)
8. Partial differential equations
9. Finite element method

Integration
 Integral  What functions?
b
I   f ( x)dx A continuous function
a

A discrete function
 Summation Zero-degree (order) polynomial (constant)
f(x) f(x) f(x)

n=6 n=6

a b x a b x a b x
D D

32
Integration trapezoidal rule
 First-degree polynomial (line)  Slope straight line equation
b b
y1  mx  B
I   f ( x)dx   f1 ( x)dx f (b)  f (a )
a a f1 ( x)  f (a )   x  a
ba
 Exact for linear functions
 Multiple applications
improve the solution

f (a )  f (b)
I  b  a 
2

Integration trapezoidal rule-multiple


applications
 Interval: equal width
ba
D
n
D n 1

I   f  x0   2 f  xi   f  xn  
2 i 1 

 n 1

 f  x0   2 f  xi   f  xn  
I  b  a  i 1

 2n 
 

a D b

33
Integration Simpson’s 1/3 rule-multiple
applications
 Higher-order polynomial
 3 points: limits and midway
 Second order polynomial
b b
I   f ( x) dx   f 2 ( x ) dx a b
a a

y2  f 2  x   Ax 2  Bx  C

f ( x0 )  4 f ( x1 )  f ( x2 ) n=2
I  b  a 
6
n1 n2
f (x0 )  4  f (xi )  2  f (xj )  f (xn ) ba
D
I   b  a
i1,3,5 j 2,4,6
n
3n n: even

Example: Flow past a circular cylinder (bluff


body), drag and lift coefficients
Fluid in motion: pressure and shear stress
Differential force (vector)
Area: vector or
scalar? dFD   PdAcos    w dA sin  x-axis
dFL   PdA sin   w dAcos  y-axis

Area?
FD   dFD    Pcos w sindA In 2D for a circle
A A
dA=dS*span
FL   dFL    Psinw cos dA dS=rd
dA=D/2d*span
A A
FD
CD  Given values:
1
V Aprojected
2
: fluid density
2
V: freestream velocity
FL
CL  A projected: depends on
1
V Aprojected
2
the body shape
2
Briefly explanation Paraview and file.vtk

34
Flows past a circular cylinder at a wide range of
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)
IB-FDLBM (Present)
101

CD St 0.2
0
10
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 

Streamlines of flows past a stationary circular


cylinder at different Re
Re = 100 Re = 100000

Re = 20

Re = 40
A Pair of stationary Vortex shedding Irregular vortex
vortices shedding

Flow patterns are in good agreement with


experimental and numerical patterns

35
Shear stress in flow past a circular cylinder
n
v


v cos 
u

u sin 
t

ut= u sin  - v cos 

Derivation
 Derivative dy f  xi  Dx   f  xi 
 lim
dx Dx 0 Dx

 First derivative: slope


 Second derivative: curvature

36
Discretization (time and space)
 Space and time are continuous
 Infinite  finite (discretize)
Continuous
Discrete

Time 1 Time 2
1D
space space

Time 1 Time 2

2D

space space

Taylor expansion
df  xi  d 2 f  xi  Dx 2 d 3 f  xi  Dx3
f  xi  Dx   f  xi    xi  Dx  xi     ...
dx dx 2 2 dx3 6

Constant f  xi  Dx   f  xi   O  Dx  Order of Dx

Line df  xi 
f  xi  Dx   f  xi  
dx

Dx  O Dx 2  Order of Dx2

df  xi  d 2 f  xi  Dx 2
Capture
curvature
f  xi  Dx   f  xi  
dx
Dx 
dx 2
2
 O Dx 3  
Order of Dx3

37
Basic finite difference schemes
 Discretization of space and time
xi  iDx ,t n  nDt f ( xi ,t n )  fin f ( xi ,t n 1 )  fi n 1 f ( xi 1 ,t n )  f in1
 Difference approximation of derivative using Taylor expansion
1    
f xi  Dx ,t n  f xi ,t n 
f n
x i
Dx 
 2 f n Dx 2  3 f n Dx3
x 2 i 2
 3
x i 6
 O Dx 4  
2 
f xi  Dx ,t n   
 f xi ,t n 
f n
x i
Dx 
 2 f n Dx 2  3 f n Dx3
x 2 i 2
 3
x i 6
 O Dx 4   f(x)

f n f in1  fi n f n f in  f in1
  ODx    ODx  i-1 i i+1
x i Dx x i Dx
1 Forward (downwind) 2 Backward (upwind)

 
2
fi n1  2 f in  fin1
f n f in1  f i n1
x i

2Dx
 O Dx 2    f n
x 2
i

Dx 2
 O Dx 2

1 - 2 Centered 1 + 2 Centered

High-accuracy differentiation formulas


First derivative for a second-order forward scheme
f i 1  f i fi ''
f 'i   Dx  O  Dx 2 
Dx 2
f i  2  2 f i 1  f i
f i ''   O  Dx 
Dx 2

f i 1  f i f i  2  2 f i 1  f i
f 'i   Dx  O  Dx 2 
Dx 2 Dx 2

 f i  2  4 f i 1  3 fi
f 'i   O  Dx 2 
2 Dx

38
High-accuracy differentiation formulas
Forward schemes

High-accuracy differentiation formulas


Backward schemes

39
High-accuracy differentiation formulas
Centered schemes

Example

40
Example

Example

41
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  f 2
 f
2
2 f 2
  2  ui 1  ui   2  ui 1  ui  vi 1  vi   2  vi 1  vi    ....
2

2 !  u uv v 

Partial derivatives
 For a two-dimensional function f (x,y)
f f  x  Dx, y   f  x  Dx, y 

x 2 Dx
f f  x, y  Dy   f  x, y  Dy 

y 2 Dy
 Mixed partial derivative
2 f  f

xy x y
f  x  Dx, y  f  x  Dx, y 

 f
2
y y

xy 2Dx
f  x  Dx, y  Dy   f  x  Dx, y  Dy  f  x  Dx, y  Dy   f  x  Dx, y  Dy 

2 f 2 Dy 2Dy
 O  Dx  , Dy  
2 2

xy 2Dx  

42
Initial value problem of ODE
 Standard form of the initial value problem of ODE
df t 
 F  f t , t  I.C. (Initial condition) f 0   f
0
dt
df f d2 f
Ex.1:   , f  0  f 0 Ex. 2: 2   f , f  0   f , f '  0   f '
2 0 0

dt  dt
t df
 f1  f , f 2  f ' 
f  f 0e  dt
df1
 f2 d  f1   0 1   f1 
:time constant dt
 f    2 0  f 
relaxation time df 2 dt  2     2
 2 f1
f

0
f =5,=1 dt
df
 Af , f 0  f 0
dt

time

Discretization of time

f n-1 fn
f0 f nmax
f n+1

t0 t n-1 tn t n+1 t nmax

43
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 and backward finite differences for a derivative
n
df d 2 f n Dt 2 df n f n 1  f n
f  t n  Dt   f  t n   Dt  2  ...  Forward
dt dt 2 dt Dt
n Backward
df d 2 f n Dt 2 n
 n 1
f  t  Dt   f  t  
n
n n
Dt  2  ... df f f
dt dt 2  (no new
dt Dt information)

df
n 1
d2 f n 1
Dt 2 df n 1
f n 1  f n Backward
f  t n   f  t n  Dt   Dt   ... 
dt dt 2 2 dt Dt
n n 1
df df
f n 1 n
 f  Dt Explicit Euler Implicit Euler f n 1  f n  Dt
dt dt

Euler method (pseudo code)


 Ex.: df f fn
  , f (0)  f 0 Explicit Euler: f n 1  f n  Dt
dt  
INPUT PARAMETERS tau, f0, dt, tend
f=f0
t=0.0 Numerical stability
for n = 1, tend  Dt 
t=t+dt f n 1   1   f n  rf n
f=f-(f/tau)*dt   
write(*,*) t,f r 1
end for example : f  rf
1 0

Unstable
stop  Dt  2 FAIL
IMPORTANT: Know-How
Dt in explicit method must be less than the time constant!

44
Round-off error
 Limitation of the digit numbers  computer
 Dt    1, Dt  0.000001
f new  1   f old If
   f new  0.999999 f old
If CPU can handle only 5 digits, 0.9999991, then f
new
 f old
round-off
Mathematically Dt0 makes FDE solution converge to exact
solution
In reality, too small Dt results in increasing errors

Error

Dt

Other schemes for time derivation 1


 Euler type  1 Euler  exp l.
f  f   F  1    F  Dt
n 1 n n n 1
0 Backward Euler  impl.
  1 / 2 Trapezoidal
 k Dt Dt 
 4th-order Runge-Kutta k1  F n k 2  F  f n  1 ,t n  
 2 2 
k1  2k2  2k3  k4  k Dt Dt 
f n 1  f n  Dt k3  F  f n  2 ,t n  
6  2 2 

 2nd-order Runge-Kutta 
k4  F f n  k3Dt ,t n 1 
Dt
1
 F  f n , t n 
n
f 2
 fn
2  
n 1
  n  12 n  12  
f  f  Dt  F  f , t  
n

   

45
Other schemes for time derivation 2

 Adams-Bashforth (coefficients calculated using Runge-Kutta)


f n 1  f n  55 F n  59 F n 1  37 F n  2  9 F n 3 24Dt
 Predictor-corrector method

f *  f n  F n Dt : explicit solution (predictor)

f n1  f n 
 
F n  F f * , t n1
Dt : implicit solution (corrector)
2

Exercise 25.4
y (0)  4
d2y dy
2
 0.6  8 y  0 y '(0)  0
dx dx
x[0 : 5]
Numerical solution Dx  0.5

dy
z new
 y old  Dx  z old
dx Explicit Euler y

dz 
z new  z old  Dx  8 y old  0.6 z old 
 0.6 z  8 y  0
dx y0  4
z0  0

46
Exercise 25.16

Numerical solution-exercise 25.16 (explicit Euler


method)

dx
v Explicit Euler
x new  x old  Dt  v old
dt
Dt
v new  v old   cv old  kx old 

dv
m  cv  kx  0 m
dt

x 0  1m
v 0  0m / s

47
Numerical solution-exercise 25.16 (implicit Euler
method)

dx
v Implicit Euler
x new  x old  Dt  v new
dt
Dt
v new  v old   cv new  kx new 

dv
m  cv  kx  0 m
dt
Linear equation system
x new  Dt  v new  x old
Dt k new  Dt c  new
x  1  v  v
old

m  m 
 1 Dt  new
 Dt k   x   x old 
 Dt c   new    old 
 1 v  v 
 m m 

2D damped oscillator
dx dy
u v x 0  1m
dt dt
du dv y 0  1m
m    cu  kx  m    cv  ky 
dt dt u 0  1m / s
v 0  0m / s
m  1kg
c  0.25 Ns / m
k  1N / m

48
Numerical solution of 2D damped oscillator

E  Ekinetic  E potential
1 1
E mV 2 (t )  kx 2 (t )
2 2

Boundary value problem (boundary conditions)


 Space variation
 Types of boundary conditions:
 Dirichlet condition (B.C. of first kind)  specify the values of f
 Neumann condition (B.C. of second kind)  specify f / n
 Robin condition (Mixed B.C.)  specify af  bf / n
 Types of boundary value problem
Dirichlet problem Neumann problem Mixed problem

49
Examples of boundary conditions

Pipeline:Navier-Stokes equations
(u, P)

Fin: heat diffusion equation (T)

Beam: deflection equation (y)

Numerical Analysis
1. Introduction
2. Basic programming concepts
3. Error analysis
4. Roots of equations
5. Linear algebraic equations
6. Curve fitting
7. Ordinary differential equations (Section taken from Prof. Tomiyama)
8. Partial differential equations
9. Finite element method

50
Partial differential equations
 Order

f 2 f
5f 5f
t t 2

 Linear or non-linear

2 f 2 f 2 f 2 f
 S   f2
x 2 y 2 x 2 y 2

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 xy y x y

B 2  AC  0 Elliptic

B 2  AC  0 Parabolic

B 2  AC  0 Hyperbolic

51
Typical equations

Diffusion equation
f 2 f : diffusion coefficient [m2/s] Parabolic
 2
t x
Wave equation
2 f 2  f
2
c: phase velocity [m/s] Hyperbolic
c 0
t 2 x 2

Poisson equation
Laplace equation
2 f 2 f Elliptic
 S S: source & sink
x 2 y 2

Examples of 2nd-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   f  f 2 f 
2 2
Diffusion f    f
2
  2  2  2  Parabolic
eq . t x 2 t  x y  z 
Poisson d2 f  f  f  f
2 2 2
Elliptic
S   S
eq. dx 2 x 2 y 2 z 2

Navier- u u  2u 1 P Parabolic
u  2 
Stokes eq. t x x  x Hyperbolic
Elliptic

52
Advection and diffusion

Modeling a physical phenomenon

 Governing equation (mathematical model, variables)

 Conditions: initial (time) or boundary (space)

 Computational domain

 Discretization technique

53
Discretization in 1D&time (point data)
 
f xi ,t n  fi n ,  
f xi ,t n 1  fi n 1 ,  
f xi 1 ,t n 1  f i n11
f ni-1 f ni
f n f nimax
1 f ni+1

tn
x1 xi-1 xi xi+1 ximax
i=1 Dx i = imax


f n+1i+1 Dt
f n+11 f n+1
f n+1i imax
f n+1i-1

tn+1
Initial condition & Boundary conditions

Discretization in 2D&time (point data)


    
f xi , y j ,t n  fijn , f xi , y j 1 ,t n  fijn1 , f xi , y j ,t n 1  f ijn 1 
Time 1: tn Time 2: tn+1
jmax

j+1 f nij+1 f n+1ij+1

f ni-1j f nij f ni+1j f n+1i-1j f n+1ij f n+1i+1j


j Dt
Dy
f nij-1 f n+1ij-1
j-1

j=1
x1 xi-1 xi xi+1 ximax
i=1 Dx i = imax

54
Discretization of partial differential equations by
using the finite difference method
 Using the following functions
f  xi   fi ,  
f xi ,t n  f i n ,  
f xi , y j ,t n  fijn ,  
f xi , y j , zk ,t n  f ijkn

 Write down discrete equation:


f 2 f Time: forward (Euler explicit), space: centered
 2
t x Time: backward(Euler implicit), space: centered
f f f Time: forward,space:upwind (u,v >0)
u v 0
t x y Time: forward, space: upwind (u>0)
downwind (v <0)
2 f 2 f
 u2 0 Time: centered, space: centered
t 2 x 2
2 f 2 f 2 f Space: centered and solve for fijk
   S ( x, y , z )
x 2 y 2 z 2

Solution
fi n 1  fi n  f n  2 fi n  f i n1  fi n 1  fi n  f n 1  2 f i n 1  f i n11 
   i 1     i 1 
Dt  Dx 2  Dt  Dx 2 
fijn 1  fijn f ijn  f i n1 j f ijn  fijn1
 u v
Dt Dx Dy
fijn 1  fijn f ijn  f i n1 j f ijn1  fijn
 u v
Dt Dx Dy

fi n 1  2 fi n  f i n 1 2 f i 1  2 f i  f i 1
n n n
 u
Dt 2 Dx 2
1  fi 1 jk  fi 1 jk fij 1k  fij 1k fijk 1  fijk 1 
fijk  2 2 2 
  
2(Dx  Dy  Dz )  Dx 2 Dy 2 Dz 2 
 Sijk

55
Elliptic equations
 Relevant phenomena: potential and steady diffusion problems,
e.g. potential flow, electric potential, steady state T & C profiles
 Basic form:
d2 f
S
dx 2
2 f 2 f 2 f
  S 2 f  S
x 2 y 2 z 2

div grad f  S

S=0  Laplace equation S≠0  Poisson equation

Example of an elliptic equation: 1D Poisson


equation (ODE)
 Problem d2 f
 (0  x  L)
dx 2
x=0 x=L
 Dirichlet condition: f =1 at x=0
i=1 i=imax

df
 Neumann condition:  0 at x=L
dx

 FDE
fi 1  2 f i  f i 1 f1  1 f i max  fi max 1
 i
Dx 2

56
Variation of the number of divisions for 1D
Poisson equation (ODE)
f1  1
i=1 i=imax=2 f 2  f 2 1  f1

f1  1
f 2 1  2 f 2  f 2 1 f1  2 f 2  f3
i=1 Dx i=2 i=imax=3   2
Dx 2 Dx 2
f 3  f 31  f 2

i=1 i=2 i=3 i=4 i=imax=5

Solution of 1D Poisson equation (ODE)

f1  1
f1 2 f2 f3  2Dx2
f2 2 f3 f4  3Dx2
... ... ...  ...
fi1 2 fi fi1  iDx2
... ... ...  ...
fi max3 2 fi max2 fi max1  i max2Dx2
fi max2 2 fi max1 fimax  i max1Dx2
fi max  fi max1

This is a system of linear equations with imax equations and


imax unknowns ( fi )

57
Linear system for 1D Poisson equation
1   f1   1 
1 2 1   f    Dx2 
  2   2 
 1 2 1   f3   3Dx2 
    
 ... ... ...   ...   ... 
 1 2 1   fi    iDx2 
    
 ... ... ...   ...   ... 
 1 2 1  f   Dx2 
   i max2   i max2 2 
 1 2 1  fi max1  i max1Dx 
 1 fi max   fimax1 

This matrix is imax x imax
This can be huge
Sparse matrix

Example 27.1
 Problem sketch and conditions d 2T
 h '(Ta  T )  0
dx 2
L  10m
Ta  20C
TBC1 TBC2
Tx 0  40C
Tx  L  200C
h '  0.01m 2
T2 T3 T4 T5

1
Dx 2
Ti 1  2Ti  Ti 1   h ' Ta  Ti 0 Discretization

Valid for all interior nodes.


Ti 1   2  h ' Dx 2  Ti  Ti 1  h ' Dx 2Ta
First and last terms are BC

58
Solution Ex. 27.1
Linear equation system 2.04 1 0 0  T2   40.8 
 1 2.04 1 0  T   0.8 
   3    

 0 1 2.04 1  T4   0.8 
 
 0 0 1 2.04 T5  200.8

Temperature
distribution

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 (x,t):
 Initial conditions: f (x,0)
 Boundary conditions
 Steady state solution of parabolic eq.= solution of elliptic eq.

59
Example of a parabolic equation: heat equation
(diffusion)
 Problem f  t , x  2 f
  2 (0  x  L)
t x

 Dirichlet condition: f =1 at x=0 x=0 x=L


i=1 i=imax
 Neumann condition: f  0 at x=L f
x 1
 Initial condition: f 0
i=2:imax = 0
 FDE x
Explicit Euler
fi n 1  fi n f n  2 fi n  f i n1
  i 1
Dt Dx 2 Dt
d Diffusion number
fi n 1
 fi  d  f
n n
i 1  2 fi  f
n n
i 1  Dx 2
d<½
B.C.: f1n  1 f i nmax  f i nmax 1 stable

Example 27.1 for steady state


 Problem sketch, conditions, assumptions and discretization
d 2T
 h '(Ta  T )  0
dx 2
L  10m
Ta  20C
Tx 0  40C
Tx  L  200C
h  0.01m 2
T  2T T
  h '(Ta  T ) Steady state solution 0
t x 2 t
Explicit Euler
Dt
Ti n 1  Ti n  2 Ti n1  2Ti n  Ti n1   Dt h ' Ta  Ti n 
Dx

60
Solution-Ex. 27.1
 Temperature distribution in steady state

Example 27.1 for steady state-Implicit Euler


Implicit Euler
Ti n 1  Ti n 1
 2 Ti n11  2Ti n 1  Ti n11   h ' Ta  Ti n 1 
Dt Dx

Dt n 1  2Dt  Dt
 T
2 i 1 
1  2  h ' Dt  Ti n 1  2 Ti n11  Ti n  h ' DtTa
Dx  Dx  Dx

 c d 0 0  T2n1  T2n  h' DtTa  d T1 


d c d 0   n1   
 T3    T3  h' DtTa 
n

 0 d c d  T4n1   T4n  h' DtTa 
  n1
 0 0 d c  T5  T5  h' DtTa  d T6 
n

61
Example of a parabolic equation: 2D heat
diffusion in a plate
 Problem
T   2T  2T 
 2  2 
t  x y 

T : thermal diffusivity
0
y : termal conductivity
h: convection heat
T T transfer coefficient
0   h T  T 
x x

T  T0

Example of a parabolic equation: convection


boundary condition (cooling)

qin qout qin qin

qin  qout  0 qin  qout  0


qin  qout qin  0
T T
  h T  T    h  T  T   0
x x

62
Example of a parabolic equation: non-
dimensional equation

T   2T  2T  x * t * T  T
  2  2  x*  , t  ,T  T0  T : cooling
t  x y  L0 t0 T0  T
  2 

* 
T *
 T0  T   T 
    2 *2 T T0  T   T   ... 
*

t0 t  L0 x 
T *   2T *  2T *   t0
  *  *2  *2  * 
t *  x y  L20
T
  h T  T 
x

 T * T0  T   T   h T * T0  T   T  T 
* 
L0 x
T * hL0 *
 *  T  BiT *
x 

Example of a parabolic equation: non-


dimensional 2D heat diffusion in a plate
 Problem
T *   2T *  2T * 
  *  *2  *2 
t *  x y 

T * Example of boundary
0
y * condition
T *
T*   BiT *
0 T * x*
x*   BiT *
x* T* T*
 i max * i max 1  BiT *i max
hL Dx
Bi  0  5
 T *i max 1
T *i max 
1  Dx* Bi

T* 1

63
Example of a parabolic equation: discretization
of 2D heat diffusion in a plate-Explicit Euler
method
 Problem
T   2T  2T 
 2  2 
t  x y 
Tijn 1  Tijn  Ti n1 j  2Tijn  Ti n1 j Tijn1  2Tijn  Tijn1 
   
Dt  D x 2
D y 2
 j

Example of a parabolic equation: discretization


of 2D heat diffusion in a plate-Implicit Euler
method
 Problem
T   2T  2T 
 2  2 
t  x y 
Tijn 1  Tijn  Ti n11j  2Tijn 1  Ti n11j Tijn11  2Tijn 1  Tijn11 
   
Dt  D x 2
Dy 2
 

64
System of equations for 2D heat diffusion in a
plate-Implicit Euler method
For example: imax=5, jmax=5
Excluding the borders, there are 3 interior points in x and y
13F F 0 F 0 0 0 0 0 T2,2n1 FT0 T2,2n 
 F 14F F    
0 F 0 0 0 0 T3,2n1 FT0 T3,2n 
 
 0 F 14FC 0 0 F 0 0 0 T4,2n1 FT0 T4,2n 
    
 F 0 0 13F F 0 F 0 0 T2,3n1  T2,3n 
 0 F 0 F 14F F 0 F 0 T3,3n1  T3,3n 
  n1  n 
 0 0 F 0 F 14 F C 0 0 F T4,3   T4,3 
 0 0 0 F 0 0 12F F 0 T2,4n1  T2,4n 
    
 0 0 0 0 F 0 F 13F F T3,4n1  T3,4n 
 0    
 0 0 0 0 F 0 F 13FCT4,4n1  T4,4n 
Dt F
F C
Dx 2 1  Dx Bi

2D heat diffusion in a plate-temperature


distribution

65
Hyperbolic equations
 Relevant phenomena: all kind of waves (sound, light, water
wave)
 Basic form:  2 f 2 f
c 0
2

t 2 x 2
2 f 2 f
2
2 f 2 f  2 f
 c  2   2 0  c 2 2 f  0
t 2   x y 2
z  t 2

 f
2
 c 2 div grad f  0
t 2

 Conditions for obtaining the solution f (x,t):


 Two initial conditions: f (x,0) and f
t x ,0
 Boundary conditions

Example of a hyperbolic equation: advection


equation in 1D
2 f 2  f
2
     
 u    u   u  f  0
t 2
x 2
 t x   t x 
f f
u 0
t x
f i n 1  fi n f n  f i n1
 u i First-order upwind scheme
Dt Dx
Dt n Dt n
f i n 1  fi n  u fi  u f i 1
Dx Dx
Dt n
f i n 1  f i n  u
Dx

fi  f i n1  CFL (Courant-Friedrich-Levy) number

f i n 1  f i n  c fi n  f i n1  c
u Dt c<1
Dx stable

66
Example of a hyperbolic equation: advection
equation in 2D
 General form and discretization
f
 u  f  0
t
f f f
u v 0
t x y
f  f f 
 u  v 
t  x y 
n
f ijn 1  f ijn  f f 
 u  v 
Dt  x y 

Finite difference schemes for advection


 First-order upwind scheme f f  x I , y J   f  xI  m , y J 
m  O  Dx 
 Second-order u.s. x Dx
f 3 f  xI , y J   4 f  xI  m , y J   f  x I  2 m , y J 
m  O  Dx 2 
x 2Dx
 Third-order u.s.
f f  x I  2 m , y J   6 f  x I  m , y J   3 f  xI , y J   2 f  x I  m , y J 
m  O  Dx 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

 WENO fifth-order (homework)

67
Example of a hyperbolic equation: advection-
diffusion equation in 1D
f f 2 f x t
u  2 x*  , t * 
t x x L0 L0 / u
f f 1  f2
Lu
 * , Pe  0
t x
*
Pe x *2

f  f2
x=0 x=L
Pe *  *2  0 Steady state
x x f=0 f=1
Solve with first-order upwind and central difference schemes

Example of a hyperbolic equation: Burgers’


equation (advection-diffusion) in 1D
u u  2u x * u * t
u  2 x*  ,u  ,t 
t x x L0 U0 L0 / U 0

U 0U 0 u * U 0U 0u* u * U 0  2u *
  
L0 t * L0 x* L0 L0 x*2
u * * u
*
  2u * L0U 0
 u  , Pe 
t * x U 0 L0 x*2 
u *
u*
1 u 2 *
Non-dimensional form
 u* 
t *
x Pe x*2

68
Parallel computation with OpenMP (shared
memory)
• Compilation with OpenMP
gfortran code.f90 -fopenmp
• Enable OpenMP in the main program
!$ use omp_lib
!$ call omp_set_num_threads(l)
• Put tags in the code
!$ omp parallel private (m)
!$ omp do
do m = 1, mmax
f ( m)  f old (m)  Dt A(m)  C (m)  F ( m)old !$ omp end do

end do !$ omp end parallel

Equations of fluid motion for fluids


Continuity and Navier-Stokes equations
 u u u u p    u u 
 0         G
t x t x x x x x 
2
    
Velocity divergence 1 Burgers equation  u
p 
Finite difference method Dt
3
Finite element method Poisson equation

Finite volume method


u n1  u*  p  Dt
4
Correction velocity

•Structured or unstructured grids

69
Equations of motion for incompressible fluids &
discretization
u 1
u  0  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 

Discretization
n 1
uijn1  uin11j vijn1  vijn11
D   0
ij
Dx Dy u n  u n u n
ij 0 
u   ijn i 1nj
n

u  0
x
For velocity u ui 1 j  uij n
ij

uijn1  uijn uxn n uy


n
Pin11j  Pijn1  uin1 j  2uijn  uin1 j uijn1  2uijn  uijn1 
u n
 vC     
Dt Dx
ij
Dy Dx  Dx 2
Dy 2
 

Poiseuille flow in 2D

Walls, no-slip B.C. u=v=0

Inflow Outflow
uin =1
Fluid
Pout=0
vin =0

Walls, no-slip B.C. u=v=0

70
Discretization of space by the finite volume
method
Fictitious cells

jmax+1

jmax

Dy

Staggered mesh 1
Pij+1 Pi+1j+1
j +1 ui-1j+1 0
vij uij+1 v
i+1j 0 1 i Dx imax imax+1
Pij Pi+1j
j ui-1j
uij

vij-1 vi+1j-1
i i +1

Available software based on Navier-Stokes

71
OpenFOAM
1. Introduction
https://openfoam.org/
2. Installation
https://openfoam.org/download/windows/
https://www.youtube.com/watch?v=2nX483FKMj0
https://www.youtube.com/watch?v=e90FyyfVbe0
3. Structure

Cavity flow (tutorial)


4. Tutorials
C:\Users\YOURNAME\AppData\Local\Packages\CanonicalGrou
pLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\roo
tfs\opt\openfoam-dev\tutorials

72
Solver
• https://github.com/OpenFOAM/OpenFOAM-
dev/blob/master/applications/solvers/incompressible/icoFoam/i
coFoam.C

Structure of this tutorial


• 0: Initial conditions
• p
• U
• Constant: parameters
• transportProperties (kinematic viscosity)
• system: discretization schemes, time and space increments
• blockMeshDict
• controlDict
• fvSchemes
• fvSolution

73
Units

[0 1 -1 0 0 0 0]

0  Mass[kg] 
1  Length[m] 
   
 1  Time[s] 
   
0  Temperature[K] 
0  Quantity[mol] 
   
0  Current[A] 
0  Luminous intensity[cd]
   

BlockMeshDict

3 2

7 6

• Vertices
• Faces

0 1

4 5

74
Numerical results

• Grid: blockMesh
• Solver: icoFoam
• Visualize: touch example.foam

Non-dimensional 2D heat diffusion in a plate


with OpenFOAM
T *   2T *  2T * 
  *  *2  *2 
t *  x y 

T *
0
y *  laplacianFoam:
Heat conduction
T * T *
0  *  BiT *
x* x
hL
Bi  0  5

T* 1

75
Non-dimensional 2D heat diffusion in a plate
with OpenFOAM
 Problem
T *   2T *  2T * 
  *  *2  *2 
t *  x y 

T *
0
y *

T *
T * BiT *  
0 x*
x* h  Bi, T  0, TB  T *
* 1
   1
T* 1
  Dx / 2

Non-dimensional 2D heat diffusion in a plate


with OpenFOAM-Boundary conditions
 Problem T * * 1
* T*  2T * 
2
   *2  *2 
t *  x y 

T *
0
y *

T *
BiT *  
x*
1 1
f  
T*
 
0 1 1
x* h BiDx / 2
refValue=T∞=0, refGradient=0
T* 1
If Dx=1 and Bi=5, then, valueFraction=f=0.714286

76
167

77

You might also like