Sei sulla pagina 1di 5

Computational Fluid Dynamics

1-D Convection-Diffusion Lab


The lab. uses scientificWorkplace symbolic calculus and maths editor software (SWP)
This file Concevtion-Diffusion-Lab is available from Blackboard or
http://cfd.mace.manchester.ac.uk/twiki/bin/view/Main/DlsTaughtCoursesMaterial.
Copy it in a new directory on your local work drive, then open it with SWP
Remember to save frequently it as SWP can crash or hang rather more frequently when handled by
beginers)
Consider the 1D steady-state convection diffusion of a scalar f :
2
u df d 2f = 0
dx dx
with boundary conditions f(x = 0) = 0 and f(x = L) = 1.
The problem is characterized by the global Peclet number P e = uL/ and the equation is then
written:
2
P e df L d 2f = 0
dx dx
The domain L is divided into n equal intervals of size x. We divide the ODE by and
multiply by x 2 to render it non-dimensional
ux x df (x) 2 d 2 f = 0
dx dx 2
or:
2
px df (x) 2 d 2f = 0
dx dx
where p = ux/ is the cell Peclet number. This allows to introduce dimensionless convection
and diffusion operators
2
C = (x) d D = (x) 2 d 2
dx dx
The diffusion operator is discretized as:
d2f = f i1 2f i 2+ f i+1 = 1 2 (D. F) i
2
dx i (x) (x)
Line i of the vector D. F is (D. F) i = f i1 2f i + f i+1
Define the corresponding Matrix D by deleting the ? mark, and following the sequence of
commands:
Maple, Matrix, Fill Matrix, rows 11, lines 11, banded, a,b,c,
(a,b,c,are the 3 coefficients appearing on the diagonals).
Place the cursor to the right of D = [?] then click on the new
definition button f(x)= to define D
D=?
The objective of the lab is to compare the upwind and centered discretizations of the

convection term.

Upwind Convection Scheme (UCS)


The upwind discretization (assuming u > 0) is:
df = f i f i1 = 1 (CF) i
dx i x x
Define the corresponding Matrix C
C = [?]
Hence the system of linear equations to solve is:
(pC D)F = B
with
F= f 1 f 2 f 3 f 4 f 5 f 6 f 7 f 8 f 9 f 10 f 11
B = transpose: 0 0 0 0 0 0 0 0 0 0 1
(To define F and B for SWP first transpose the line into column vector using: compute ->
matrices -> transpose
To implement the boundary conditions one needs to modify the first and last lines of C and D
in order that f 1 = 0 and f 11 = 1.
The first and last lines of the system will be:
(pC 1,1 D 1,1 )f 1 + (pC 1,2 D 1,2 )f 2 = B 1
(pC 11,10 D 11,10 )f 10 + (pC 11,11 D 11,11 )f 11 = B 11
Set the coefficients C 1,1 , C 1,2 . . . D 1,1 . . D 11,11 for the Dirichlet conditions f 1 = 0 and f 11 = 1.
Hint:
( 0 p (1))f 1 = 0
(0 p (1))f 11 = 1
To do this, go back and copy C and D below, make the required
modifications for boundary conditions, then click on the
define button again. Also use command define for F and B.
p = 0. 5
Click define while on the right of p = 0. 5
A = pC D
Click define while in the right of the above,
One can see the matrix by selecting Maple evaluate
AF = B
Click Maple, Solve
To check wether your system is correctly set up, replace p = 0. 5 by p = 0.
The expected solution is then obvious ( your are solving dx
d2f
2
= 0 , which function with zero
second derivative verifies the boundary conditions?)
Remember to go through the defineafter A = pC D and AF = B below each time you
change the value of p. The symbolic calculator updates its database only after define, not as
you type.
p=1
A = pC D
AF = B
p=2
A = pC D
AF = B
Creating (x, f) sets
In order to plot the results one needs to create a vector of X = (0. , 0. 1, . . . x i , . . 1) positions.
Instead of filling the vector by hand, first define a function:
a(i) = (i 1)/10
Then delete the ? below , click Maple, fill matrix, lines=11, colums=1, define by
function, and type, a
X = [?]
To create an (x, f) set of results, copy and paste side by side the column of X values and the
column of F values obtained previously, then Maple, matrix, concatenate.
Your results should look like this (in this example all but first and last values have been
deleted )
0 0 0 0 0 0
... ... 1 1 1
8. 823 8 10 3
p = 0. 5: 9 9841
p=1: 10 1023
p=2: 10
9 511 9
10 29 524 10 1023 10
. 660 78
1 1 1 1 1 1. 0
By setting the cursor to the right of any set, and clicking the x-y button (or maple, 2D plot)
one can create a graph. To plot all three on the same graph, copy the second set, click on the
lower right icon of the first graph, select the plot component menu, click add item, and paste
the second set. Get familiar with the various options of the graph tool.

Centered Convection Scheme (CCS)


The centered dicretisation corresponds to:
df = f i+1 f i1 = 1 (CF) i
dx i 2x x
C = [?]
p = 0. 5
A = pC D
AF = B

then repeat with p=1, 1.9, 2 and 3 . Note that the coefficient with the largest magnitude
(absolute value) is now no longer on

Comparison with exact solution:


Previously, Maple was operating on numbers, just like a Fortran program, but it can also
interpret and manipulate mathematical expressions, this is known as symbolic calculus. Consider
now the continuous problem:
2
P e df L d 2f = 0
dx dx
In the numerical application, we have used L = 1, n = 10 intervals and the cell Peclet number
p = P e /n as a parameter. The problem is thus written as:
df
10p dx dx
d2f
2
=0
f(0) = 0
f(1) = 1
Maple can solve this for you, by selecting solve ODE (if the parameter p does not appear, it
is because it is replaced by its last given numerical value, to cure this, use the sequence
undefine under the maple define menu).
1

0.8

0.6

0.4

0.2

0
0.2 0.4 0.6 0.8 1

Upwind

0.8

0.6

0.4

0.2

0
0.2 0.4 0.6 0.8 1

Centered
Solutions for p = 0. 5 (P e = 5) are plotted above. (Numerical in black, exact in red).

Lab Report Questions:


A) Compelete the 2 graphs above for cell Peclet = 1 and cell Peclet = 2 AND COMMENT
THE RESULTS.
B) To personalise your report, take the last two digits xy of your student registration
number and complete the graphs above for p = 1. xy (example, if your student number is
SN=123456, then apply the UDS and CDS schemes for p = 1. 56 )
C) Observe that the upwind solution for p = 2 actually corresponds to (overlaps) the exact
solution for p = 1. Show that this is because the truncation error of the UDS has the same
magnitude as the real diffusion term, hence the error amounts to doubling the viscosity.
D) Apply the centered scheme to p = 2. xy (your SN last digits) and comment.
- Only print the graphs and comments for the above questions, NOT the detailed
introduction, matrices etc.. Your report should not exceed 4 pages.
- Hand in your report to D. Laurence during the CFD lecture, Thursday 25 November.
- You may print directly from the SWP software (menu: file, then print). The style of
the report is not important here (latex typeseting available from menu: typeset, is used
for journal papers or PhD dissertations)

Possible extensions:
(Not part of the Lab report)
- Direclty compute A 1 and observe that all terms are non-zero. What are the eigen-values?
compare the condition number of the matrice for different schemes and Peclet numbers.
- Use the Richardson extrapolation to improve the UDS solution.
- Implement a 3rd order upwind scheme discretisation (except for the boudary conditions)
and test it for p = 1. , p = 1. xy and p = 2
- Test the 3rd order upwind scheme to see if it works for Peclet > 2.

Potrebbero piacerti anche