0% found this document useful (0 votes)
32 views

EngAn3 CFD 2013 14 Lect - 2

This document discusses an introduction to computational fluid dynamics (CFD) lecture. It covers the formulation of partial differential equation (PDE) problems, including the domains of solution, boundary and initial conditions. Some common PDE models are presented, including the heat equation, wave equation, Laplace equation, and Poisson equation. The steps of the numerical approach in CFD are outlined as modeling, discretizing the domain and equations, and solving the discretized equations. Discretization involves dividing the domain into discrete points and elements.

Uploaded by

raphael.sanches
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)
32 views

EngAn3 CFD 2013 14 Lect - 2

This document discusses an introduction to computational fluid dynamics (CFD) lecture. It covers the formulation of partial differential equation (PDE) problems, including the domains of solution, boundary and initial conditions. Some common PDE models are presented, including the heat equation, wave equation, Laplace equation, and Poisson equation. The steps of the numerical approach in CFD are outlined as modeling, discretizing the domain and equations, and solving the discretized equations. Discretization involves dividing the domain into discrete points and elements.

Uploaded by

raphael.sanches
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/ 48

Dr Edmondo Minisci EngAn3-CFD

Engineering Analysis 3
2013-2014 / 2nd semester

Introduction to Computational Fluid


Dynamics ( CFD )
Dr Edmondo MINISCI
[email protected]
Twitter: https://twitter.com/edmondo_minisci https://twitter.com/MAE_Strath
1
Dr Edmondo Minisci EngAn3-CFD

Lecture 2

2
Dr Edmondo Minisci EngAn3-CFD

Formulation of a PDE problem [1]


A complete PDE problem consists of
- an equation (or set of equations)
- a domain of solution
- boundary and initial conditions.

The problem has to be solved in a spatial domain, Ω, and, in the case of


time-dependency, in a time interval between t0 and tend .

Domains can be finite of infinite.

Boundary conditions have to be imposed at the boundaries of the spatial


domain ∂Ω.
Only a problem with properly set boundary conditions is well-posed (i.e.,
consistent and having a unique solution).

3
Dr Edmondo Minisci EngAn3-CFD

Formulation of a PDE problem [2]


Physical boundary conditions are usually expressed in terms of the
boundary values of
- the unknown field u (Dirichlet boundary condition) or
- its normal derivative (Neumann boundary condition), or, again,
- a mix of both (Robin, mixed, boundary condition).

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

Formulation of a PDE problem [3]

The time-independent problems appear when the interest is in a steady


state of the system, where the properties do not significantly change with
time.
In this case, as an approximation, it is assumed that the distributed
properties are functions of space but not time, and the time derivatives in
the governing equations are replaced by zeros.

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

Formulation of a PDE problem [4]


The time-independent problems appear when the interest is in a steady
state of the system, where the properties do not significantly change with
time.
As an approximation, we assume that the distributed properties are
functions of space but not time and replace the time derivatives in the
governing equations by zeros.

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

Model equations [1]


Heat Equation:
It expresses the energy conservation principle in the case of conduction heat
transfer with constant physical properties and absent sources of internal heat
generation:
    
T (t , x )  T (t , x )   2
T (t , x )  2
T (t , x )  2
T (t , x )
 a 2 2T or  a 2    
t  t  x 2
y 2
z 2

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.

In the one-dimensional case, the equation reduces to:

T (t , x ) 2  T
2
a
t x 2

7
Dr Edmondo Minisci EngAn3-CFD

Model equations [2]


Wave Equation:
It describes wavelike phenomena such as sound propagation or oscillations
of a string or membrane:
    
 2u (t , x )  2
u (t , x )   2
u (t , x )  2
u (t , x )  2
u (t , x )
 a  u or
2 2
a 
2
   
t 2
t 2
 x
2
y 2
z 2

 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

Model equations [3]


Laplace Equation:
Can be considered as the steady-state heat equation:
  
or  2
u ( x )  2
u ( x )  2
u ( x )
 2u  0   0
x 2
y 2
z 2

An important generalization is the Poisson equation:



 2u  f  x 

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

Model equations [4]

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

Steps of numerical approach

1- Modeling: definition of the mathematical model describing the phenomenon

2- Discretisation of the domain and the equations

3- Solution of the discretised equations

11
Dr Edmondo Minisci EngAn3-CFD

Discretisation [1] node

 all computational methods start with dividing


the flow domain (geometry) into discrete face
computational points where physical properties
are to be calculated cell

2D mesh

y
i, j  1
x
node
i  1, j i, j i  1, j edge
cell
face
i, j  1 3D mesh

x , y steps : separation between two


2-Dimensional grid nodes (can be uniform or not)
12
Dr Edmondo Minisci EngAn3-CFD

Discretisation [2]

Discretisation of the continuum flow domain


into discrete computational points where
physical properties will be computed

regular Mesh (structured)


The type of mesh :
 depends on the PDE
and the geometry of the body

 influences the numerical solutions

 mesh generator softwares (Gambits,


GridCAD, TriGrid, Vgrid) are used to generate
mesh for complex geometry
irregular Mesh (unstructured)
13
Dr Edmondo Minisci EngAn3-CFD

Discretisation [3]

a mesh to simulate flow over Porsche 911 turbo


14
Dr Edmondo Minisci EngAn3-CFD

Discretisation [4]
 we also discretise the fluid dynamic equations (PDEs) and transform them
into linear algebraic equations

PDEs are valid over continuum domain: i.e, at any position

Discretisation: transform a Partial Differential Equation into


a set of (linear) algebraic equations

Discretized equations are valid on discrete domain or grid

 the most common PDEs discretisation methods are


1. the finite difference method (FD)
2. the finite element method (FE)
3. the finite volume method (FV)

15
Dr Edmondo Minisci EngAn3-CFD

Discretisation [5]

 Finite Difference method (FD)


- employs a cartesian grid with the computational
points located at the gridline intersections
- approximates partial derivatives directly

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]

 Finite Volume method (FV)

- 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, j  1 computational cell (control volume)


where approximated values of the
dependent variable are calculated

i  1, j i, j i  1, j
i, j  1

17
Dr Edmondo Minisci EngAn3-CFD

Finite Difference Method:

18
Dr Edmondo Minisci EngAn3-CFD

The finite difference method (FD) [1]

 FD employs a cartesian grid with the computational points located at the gridline
intersections.

 the basics of Finite Difference methods is to approximate derivatives involved


in the partial differential equation with a Finite Differences

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

The finite difference method (FD) [2]

 Taylor expansions are the basics to obtain Finite Differences

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

The finite difference method (FD) [3a]


examples of Finite Differences:

Taylor series expansions:

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

The finite difference method (FD) [3]


examples of Finite Differences:

Taylor series expansions:

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

The finite difference method (FD) [4]


examples of Finite Differences

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

The finite difference method (FD) [5a]


examples of Finite Differences

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!
2x 3

(a) - (b) f ( x  x)  f ( x  x)  2xf ' ( x)  f ( x)  ...


( 3)

3!

24
Dr Edmondo Minisci EngAn3-CFD

The finite difference method (FD) [5b]


examples of Finite Differences

2x 3

f ( x  x)  f ( x  x)  2xf ' ( x)  f ( x)  ...


( 3)

3!
from which

f ( x  x)  f ( x  x) x 2 ( 3)
 f ' ( x)  f ( x)  ...
2x 3!
f ( x  x)  f ( x  x)
2x
 
 f ' ( x)  O x 2

f ( xi 1 )  f ( xi 1 ) f second order
 central difference
2x x i

25
Dr Edmondo Minisci EngAn3-CFD

The finite difference method (FD) [6]


 the previous three finite differences are all used to substitute the first derivative
and can be visualized graphically:

Forward difference

Backward difference

different approximations to Central difference


the first derivative

26
Dr Edmondo Minisci EngAn3-CFD

The finite difference method (FD) [7]


Other examples of Finite Differences
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!
(a) + (b)
f ( x  x)  2 f ( x)  f ( x  x)  x 2 f ' ' ( x)  o(x 4 )

f ( xi 1 )  2 f ( xi )  f ( xi 1 ) 2 f second order central


 second difference
x 2
x 2 i

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 2x

dT ( x) T ( xi  2 )  8T ( xi 1 )  8T ( xi 1 )  T ( xi  2 )
3. 
dx 12x

compare the different approximations with exact values of the derivatives.

28
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab (part 2)

29
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [14]


Operators

List of the available arithmetic operators:


+ addition
- subtraction
* multiplication
^ power
\ left division
/ right division
.* elementwise multiplication
.^ elementwise power
.\ elementwise left division
./ elementwise right division
' transpose

30
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [15]


Relational operators

Can be applied between:


- a scalar and a scalar;
- a matrix and a scalar; or
- two matrices of the same dimension.
The following are available:
< less than
> greater than
<= less than or equal
>= greater than or equal
== equal
~= not equal
Boolean values (or matrices) may be connected by the following
logical operators:
& and
| or
~ not

31
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [16]


Built-in functions

Special Functions:

help Displays help information for any MATLAB command.


lookfor A keyword search function. Useful for finding unknown commands.
who Lists the current variables in the workspace.
whos Lists current variables with detailed information.
clear Clears current variables.
exit Closes interactive mode.

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

Introduction to Matlab [17]


Built-in functions
Scalar functions
Some functions are essentially used on scalars, but operate element-wise when
applied to a matrix (or vector). They are summarized below (angles are in
radians).
sin trigonometric sine
cos trigonometric cosine
tan trigonometric tangent
asin trigonometric inverse sine (arcsine)
acos trigonometric inverse cosine (arccosine)
atan trigonometric inverse tangent (arctangent)
exp exponential
log natural logarithm
abs absolute value
sqrt square root
rem remainder
round round towards nearest integer
floor round towards negative infinity
ceil round towards positive infinity
33
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [18]


Built-in functions
Scalar functions
Some examples of these functions in use are:
>> sin(1)
ans =
0.8415
>> cos([-1:0.5:1]*pi) (pi is a built-in constant)
ans =
-1.0000 0.0000 1.0000 0.0000 -1.0000
OR
-1.0000e+00 6.1232e-17 1.0000e+00 6.1232e-17 -1.0000e+00

>> 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

Introduction to Matlab [19]


Built-in functions
Vector functions

Other functions operate essentially on vectors returning a scalar value. Such as:

max largest component


min smallest component
length length of a vector
sort sort in ascending order
sum sum of elements
prod product of elements
median median value
mean mean value
std standard deviation

35
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [19]


Built-in functions
Vector functions
If
>> z = [0.0099, 0.1389, 0.2028, 0.1987, 0.6038];
then
>> max(z)
ans =
0.6038
>> min(z)
ans =
0.0099
>> sort(z)
ans =
0.0099 0.1389 0.1987 0.2028 0.6038
>> sum(z) >> mean(z)
ans = ans=
1.1541 0.2308

36
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [20]


Built-in functions
Vector functions
Vector commands applied to a matrix act on each column separately to produce a
row vector of results.
So for matrix
>> M = [0.4447, 0.9218, 0.4057; 0.6154, 0.7382, 0.9355; 0.7919, 0.1763, 0.9169];
We can get a vector of the sums of each column with
>> sum(M)
ans =
1.8520 1.8363 2.2581
We can apply sum to the above row vector by typing
>> sum(ans)
ans =
5.9464
Additional input arguments may affect the nature of the function, e.g. sum the
columns of M with sum(M,2). Which is the result of this?

37
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [21]


Built-in functions
Vector functions
Additional output arguments can also sometimes be specified.

For instance, [val,pos] = max(X) returns the index of the maximum value in pos.

>> [val,pos] = max(z)


val =
0.6038
pos =
5

Check the help page for each function you use.

38
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [22]


Built-in functions
Operations on Matrices

Some commands that can be applied to matrices.


size size of a matrix
det determinant of a square matrix
inv inverse of a matrix
rank rank of a matrix
rref reduced row echelon form
eig eigenvalues and eigenvectors
poly characteristic polynomial
norm norm of matrix (1-norm, 2-norm, 1-norm)
cond condition number in the 2-norm
lu LU factorization
qr QR factorization
chol Cholesky decomposition
svd singular value decomposition

39
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [23]


Plotting function

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.

Then define the corresponding y values,


>> y = cos(x);

Finally, we can plot this function with


>> plot(x,y) % The plot appears in a separate window.

For more details, you should read the help page on plot.

40
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [23b]


Plotting function

The resulting figure is:

41
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [24]


Plotting function

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)')

Give the plot a title with the title command.


>> title('Graph of cosine from -pi to pi')

To redraw the graph in green, use


>> plot(x,y,'g')
The third argument, for the colour, appears within single quotes.
We can get a dashed line instead of a solid one with
>> plot(x,y,'--')
or say a red dotted line by typing
>> plot(x,y,‘r:')
Complete
>> plot(x,y,‘r:'), xlabel('x'), ylabel('y=cos(x)'), title('Graph of cosine from -pi to pi')
42
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [24b]


Plotting function

The resulting figure is:

43
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [25]


Plotting function

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

Introduction to Matlab [25b]


Plotting function

The resulting figure is:

45
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [26]


Plotting function

Other commands for data visualization include:

subplot create an array of (tiled) plots in the same window


loglog plot using log-log scales
semilogx plot using log scale on the x-axis
semilogy plot using log scale on the y-axis
errorbar plot with error bars
bar plot a bar chart
hist plot a histogram
surf 3-D shaded surface graph
surfl 3-D shaded surface graph with lighting
mesh 3-D mesh surface (for surface graphs)

46
Dr Edmondo Minisci EngAn3-CFD

Introduction to Matlab [27]


Plotting function
Subplot

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

Introduction to Matlab [27b]


Plotting function

The resulting figure is:

48

You might also like