EngAn3 CFD 2013 14 Lect - 2
EngAn3 CFD 2013 14 Lect - 2
Engineering Analysis 3
2013-2014 / 2nd semester
Lecture 2
2
Dr Edmondo Minisci EngAn3-CFD
3
Dr Edmondo Minisci EngAn3-CFD
In general, all fluid flow and heat transfer processes evolve with time, but
depending on their behaviour it is advisable to consider two different
groups:
- time-independent and
- time-evolving.
4
Dr Edmondo Minisci EngAn3-CFD
In the other case, the evolution toward the equilibrium state is of interest
or the equilibrium state does not exist even as an approximation.
5
Dr Edmondo Minisci EngAn3-CFD
In the other case, the evolution toward the equilibrium state is of interest
or the equilibrium state does not exist even as an approximation.
6
Dr Edmondo Minisci EngAn3-CFD
where T(x, t ) is the temperature field and a2 = κ/ρC is the temperature diffusivity
coefficient, while κ is thermal conductivity [W/(m·K)], ρ is density [kg/m³], and C is
the specific heat capacity [J/(kg·K)]
The same equation can be used to describe many other diffusive processes.
T (t , x ) 2 T
2
a
t x 2
7
Dr Edmondo Minisci EngAn3-CFD
2u (t , x ) 2 u
2
In the one-dimensional case, the equation reduces to: a
t 2
x 2
8
Dr Edmondo Minisci EngAn3-CFD
where f is a known function of spatial coordinates. The simplest PDE form of the
Poisson equation is for the two-dimensional case u = u(x, y):
2u 2u
f ( x, y )
x 2
y 2
9
Dr Edmondo Minisci EngAn3-CFD
T (t , x) 2 T
2
Heat Equation:
t
a
x 2
B 2 4 AC 0 parabolic
2u (t , x) 2
u
Wave Equation: a 2
B 2 4 AC 0 hyperbolic
t 2 x 2
2u 2u elliptic
Laplace Equation: 0 B 2 4 AC 0
x 2
y 2
10
Dr Edmondo Minisci EngAn3-CFD
11
Dr Edmondo Minisci EngAn3-CFD
2D mesh
y
i, j 1
x
node
i 1, j i, j i 1, j edge
cell
face
i, j 1 3D mesh
Discretisation [2]
Discretisation [3]
Discretisation [4]
we also discretise the fluid dynamic equations (PDEs) and transform them
into linear algebraic equations
15
Dr Edmondo Minisci EngAn3-CFD
Discretisation [5]
i, j 1
computational nodes where
approximate values of the
y dependent variable are calculated
x
i 1, j i, j i 1, j
x steps : separation between two
y nodes (can be uniform or not)
i, j 1
structured mesh : the node indexing system follows an algebraic relation
16
Dr Edmondo Minisci EngAn3-CFD
Discretisation [6]
- employs a structured grid with the computational points located at the cell centres
- use an integral form of the fluid equation (calculate the values of
conserved quantities)
i 1, j i, j i 1, j
i, j 1
17
Dr Edmondo Minisci EngAn3-CFD
18
Dr Edmondo Minisci EngAn3-CFD
FD employs a cartesian grid with the computational points located at the gridline
intersections.
i, j 1
computational nodes where
approximate values of the
y dependent variable are calculated
x
i 1, j i, j i 1, j
x Steps : separation between two
y nodes (can be uniform or not)
i, j 1
19
Dr Edmondo Minisci EngAn3-CFD
curvature
slope
origin correction
correction
h2 h3 ''' h 4 ''''
f ( x h) f ( x) hf ' ( x) f ' ' ( x) f ( x) f ( x)...
2! 3! 4!
( x h) is a position close to x
f ' ( x) Taylor series expansions provide the
value of a function at nearby points
f ' ' ( x) using an origin
derivatives of f (x)
f ''' ( x )
... 20
Dr Edmondo Minisci EngAn3-CFD
with h : x
x 2 x3 (3)
f ( x x) f ( x) xf ' ( x) f ' ' ( x) f ( x) ...
2! 3!
from which
f ( x x) f ( x) x x 2 (3)
f ' ( x) f ' ' ( x) f ( x) ...
x 2! 3!
21
Dr Edmondo Minisci EngAn3-CFD
with h : x
x 2 x 3 (3)
f ( x x) f ( x) xf ' ( x) f ' ' ( x) f ( x) ...
2! 3!
from which
f ( x x) f ( x) x x 2 (3)
f ' ( x) f ' ' ( x) f ( x) ...
x 2! 3!
or
f ( x) f ( x x) x x 2 (3)
f ' ( x) f ' ' ( x) f ( x) ...
x 2! 3!
22
Dr Edmondo Minisci EngAn3-CFD
f ( x x) f ( x) f ( xi x) f ( xi ) f
f ' ( x) (x)
x x x i
f ( xi 1 ) f ( xi ) f
First order forward difference
x x i
f ( x) f ( x x) f ( xi ) f ( xi x) f
f ' ( x) (x)
x x x i
f ( xi ) f ( xi 1 ) f
First order backward difference
x x i
23
Dr Edmondo Minisci EngAn3-CFD
x 2 x3 (3)
(a) f ( x x) f ( x) xf ' ( x) f ' ' ( x) f ( x) ...
2! 3!
x 2 x3 (3)
(b) f ( x x) f ( x) xf ' ( x) f ' ' ( x) f ( x) ...
2! 3!
2x 3
3!
24
Dr Edmondo Minisci EngAn3-CFD
2x 3
3!
from which
f ( x x) f ( x x) x 2 ( 3)
f ' ( x) f ( x) ...
2x 3!
f ( x x) f ( x x)
2x
f ' ( x) O x 2
f ( xi 1 ) f ( xi 1 ) f second order
central difference
2x x i
25
Dr Edmondo Minisci EngAn3-CFD
Forward difference
Backward difference
26
Dr Edmondo Minisci EngAn3-CFD
27
Dr Edmondo Minisci EngAn3-CFD
Class exercise
dT
For T ( x) Sin(x / 2) , obtain (x) at x=0.5 with x 0.1 using
dx
dT ( x) T ( xi 1 ) T ( xi )
1.
dx x
dT ( x) T ( xi 1 ) T ( xi 1 )
2.
dx 2x
dT ( x) T ( xi 2 ) 8T ( xi 1 ) 8T ( xi 1 ) T ( xi 2 )
3.
dx 12x
28
Dr Edmondo Minisci EngAn3-CFD
29
Dr Edmondo Minisci EngAn3-CFD
30
Dr Edmondo Minisci EngAn3-CFD
31
Dr Edmondo Minisci EngAn3-CFD
Special Functions:
Use help to know how to use built-in function before using them, or see the online
support at: http://www.mathworks.co.uk
32
Dr Edmondo Minisci EngAn3-CFD
>> rem(12,5)
ans =
2
>> floor(1.4) >> floor(1.8) >> ceil(1.4)
ans= ans = ans=
1 1 2
34
Dr Edmondo Minisci EngAn3-CFD
Other functions operate essentially on vectors returning a scalar value. Such as:
35
Dr Edmondo Minisci EngAn3-CFD
36
Dr Edmondo Minisci EngAn3-CFD
37
Dr Edmondo Minisci EngAn3-CFD
For instance, [val,pos] = max(X) returns the index of the maximum value in pos.
38
Dr Edmondo Minisci EngAn3-CFD
39
Dr Edmondo Minisci EngAn3-CFD
plot
It is a special function to visualise data.
To plot the cosine function, begin by choosing the points along the x-axis, to
evaluate cos(x).
>> x=-pi:0.01:pi; % Smaller increments give a smoother curve.
For more details, you should read the help page on plot.
40
Dr Edmondo Minisci EngAn3-CFD
41
Dr Edmondo Minisci EngAn3-CFD
It is good practice to label the axis on a graph and if applicable indicate what each
axis represents. This can be done with the xlabel and ylabel commands.
>> xlabel('x')
>> ylabel('y=cos(x)')
43
Dr Edmondo Minisci EngAn3-CFD
Multiple curves can appear on the same graph. To show this, we dene another
vector
>> z = sin(x);
we can get both graphs on the same axis, distinguished by their line type, using
>> plot(x,y,'r--',x,z,'b:'), xlabel('x), title('Graph of cosine and sine from -pi to pi')
This gives a plot with the red dashed line for y = cos(x) and a blue dotted line for z
= sin(x). (with xlabel and title)
The command legend provides a legend (or key) to help distinguish multiple plots,
e.g.
>> legend('cos(x)','sin(x)')
44
Dr Edmondo Minisci EngAn3-CFD
45
Dr Edmondo Minisci EngAn3-CFD
46
Dr Edmondo Minisci EngAn3-CFD
The subplot command allows you to plot two curves alongside one another. An
example is
>> x = linspace(0,5,51);
>> subplot(2,1,1)
>> plot(x,sin(x),'-')
>> axis([0 5 -2 2])
>> title('A sine wave')
>> subplot(2,1,2)
>> plot(x,sin(x)+0.1*randn(1,51),'o')
>> title('Noisy points on the sine wave.')
The command randn is used to generate a random vector with elements sampled
from N(0; 1) (the normal distribution with mean = 0 and standard deviation = 1)
47
Dr Edmondo Minisci EngAn3-CFD
48