Exercises
Exercises
Burgerscentrum
Research School for Fluid Mechanics
2015
Introduction
In this note we treat some exercises that are meant as illustration for the
theory treated in the course CFD 2. The exercises can be seen as two
separate parts.
Part 1 (exercises 1-13) is meant to illustrate the use of finite elements in the
flows. Besides that, implicitly some linear algebra aspects will be treated.
Part 1 is executed with the aid of the finite element package SEPRAN. Part
1 is planned for Monday and Wednesday till Friday.
part 2 (exercises 14-15) deals only with linear algebra aspects. This part is
planned for Tuesday and must be executed with the aid of MATLAB.
The exercises are planned for several days. Of course one is free to finish the
exercises of the previous day. The exercises are ordered in increasing degree
of difficulty and it is not necessary to make all of them. Exercises marked
with a star (*) are only meant for those who have time left. In general they
are more difficult than the other ones.
The SEPRAN manuals can all be found at the following Internet ad-
dress:
http://ta.twi.tudelft.nl/nw/users/vuik/burgers/burg.html
Alternatively they can also be found on the local system in the following
way:
Schedule
Monday: Exercises 1, 2 and 3
Tuesday: Exercises 14 and 15
Wednesday: Exercises 4 and 5
Thursday: Exercises 6 and 7
Friday: Exercises 8, 9 and 16
The exercises 10-13 are meant for those that have time left. These exercises
require much more effort and have more an investigating character.
All these exercises have been preprogrammed. In your directory you will find
2 subdirectories: sepran and matlab. In sepran you will find the sepran files,
in Matlab the Matlab files. It is wise to create a new directory, for example
workdir in which you run the sepran exercises and update the files. Make a
copy of the files corresponding to a specific exercise from the sepran directory
to this new directory. In this way the original files are kept undisturbed and
may be reused. For example in case of Exercise 1:
mkdir workdir
cp sepran/exercise1c.msh workdir
cp sepran/exercise1d.prb workdir
cd workdir
After that you may run SEPRAN.
b0
h/2 h
0
0 b/2 b
divkT = . (1)
We assume that in the case of the plate in Figure 1, the left and right-hand
wall are kept at a constant temperature T = 0. The lower wall is kept at
temperature T = 1. The heat production is assumed to be constant.
On the boundary of the hole we assume that qn = 0 (insulated) or that
qn = q0 (constant heat flux).
In first instance we assume that the upper wall is insulated (qn =0) and in
second instance we use the heat transfer relation T + kT n = 0.
Exercises:
1b Derive the weak formulation for the heat conduction problem. If you
have a choice, use the most general of the boundary conditions includ-
ing the symmetry boundary conditions.
Why is it not necessary to use the symmetry boundary condition ex-
plicitly in the finite element method?
mkdir workdir
(workdir is your own work directory,
you may choose the name freely)
cp sepran/exercise1c.msh workdir
cd workdir
sepmesh exercise1c.msh (Make the mesh)
sepview sepplot.001 (View the mesh)
kwrite exercise1c.msh
cp ../sepran/exercise1d.prb .
sepcomp exercise1d.prb (Solve problem)
kwrite exercise1d.prb
Program sepcomp solves the problem prints the temperature and plot
the isotherms and make a vector plot of q.
You can inspect the plots by sepview:
Practical exercises CFD II 7
In this case we need to define more boundaries than in the first case.
Therefore two new files are needed:
exercise1f.msh
exercise1f.prb
First run sepmesh and then sepcomp with these files and view the re-
sults.
sepmesh exercise1f.msh
sepcomp exercise1f.prb
sepview sepplot.001
Also in this case the mesh is adapted since more boundaries are needed
to define the boundary conditions. These new files are:
exercise1g.msh
exercise1g.prb
For that reason we solve the Poisson equation on the rectangle (0,5) (0,1).
T = 1. (2)
Exercises:
exercise2.msh
2b Solve the Poisson equation with a direct method and the matrix stored
as symmetrical matrix. Inspect the number of entries of the matrix and
the computation time required for building the equations and solving
the linear system of equations. In order to measure the memory usage
and the computational time we put two extra lines in the input file:
set output on
set time on
The line
start
renumber not
end
problem
.
.
end
exercise2c.prb
1
if you put a # before renumber not, the command is ignored
Practical exercises CFD II 10
The goal of this exercise is practicing the writing of your own standard el-
ement. For that reason we reuse exercise 1, however, in this case we use
element type 1 for the inner region and element types 2 and 3 respectively
for the boundary elements. Due to this choice it is necessary to add your
own subroutine ELEM to program SEPCOMP.
Exercises:
3b Program subroutine ELEM using the results of 3a. Use the users man-
ual Section 4.2. Repeat the exercises 1c, 1d and 1f using your own
element.
Practical exercises CFD II 12
For that reason we compute the temperature in a straight pipe. The lower
wall and the upper wall of the pipe consist of parallel circles with radius
1. The outer wall is perpendicular to these circles and has height 5. The
temperature in the pipe satisfies the Laplace equation
divkT = 0. (3)
The pipe is insulated on the upper wall and on the under wall we have a
constant temperature T0 . On the outer wall we assume the heat transfer
relation: qn = (Tw T )
To solve this problem, we can use the axi-symmetry or we can solve the
problem as a three-dimensional one.
First we carry out the axi-symmetrical approach.
Exercises:
exercise4a.msh
exercise4a.prb
4c Now repeat the exercises 4a and 4b with an iterative solver (CG) and
an accuracy of 103 . Compare the results.
The corresponding file is:
exercise4c.prb
Practical exercises CFD II 13
4d We will now repeat the exercise with a real three dimensional mesh.
Although this is senseless for this exercise, in practice many problems
are purely three-dimensional.
Subdivide the lower surface into triangular elements by the submesh
generator GENERAL. Use 20 elements along the circle.
The upper face must be constructed by translation of the lower face.
The side wall must be generated by the generator PIPESURFACE. Use
25 elements in the z-direction.
To generate the 3D grid the volume generator PIPE is used.
Carry out the same exercises as in 4a with a direct solver.
The corresponding files are:
exercise4d.msh
exercise4d.prb
exercise4e.prb
Consider the flow in a pipe as sketched in Figure 2. We suppose that the flow
T1
0
T0
uz z
ur r
with P e the Peclet number , Umax the maximum velocity and a the so-called
temperature adjustment coefficient.
T0 = 0
T1 = 1
ur = 0, uz = 1 - r 2
R = 1 P e = 700
Exercises:
exercise5b.msh
exercise5c.prb
exercise5d.prb
Practical exercises CFD II 17
0.5
-0.5
-0.5 0 0.5
The velocity field starts on the line B, rotates counter clockwise and ends on
the line B. We convect a cosine shaped concentration by the velocity field.
The concentration c satisfies the convection-diffusion equation
c + u c = 0. (5)
Exercises:
Practical exercises CFD II 18
exercise6a.msh
exercise6b.prb
exercise6c.prb
exercise6d.msh
Practical exercises CFD II 19
First we start with the Poisson equation, in which the discretization matrix
is symmetric and positive definite. This is done by using poisson as type in
the problem input block.
Record the memory usage and the computation time used. Plot the
computed solution by sepview. Repeat this by adding the following
input block before end_of_sepran_input
solve
positive_definite
end
to the file.
The corresponding files are:
exercise7.msh
exercise7a.prb
and
Practical exercises CFD II 20
solve
iteration=method = cg, print_level = 1, preconditioner = ilu
end
Read the memory usage, the number of iterations and the computa-
tion time required. Choose the following preconditioners: diagonal,
eisenstat, ilu and mod eisenstat. If time is left vary the number of dis-
cretization points.
The corresponding file is:
exercise7b.prb
start
renumber not
end
start
renumber cuthill profile
end
or
start
renumber sloan profile
end
exercise7d.prb
solve
iteration_method = bicgstab, print_level = 1, preconditioner = ilu
end
exercise7e.prb
7f From now on we use upwind discretization. Solve the system with the
Bi-CGSTAB method without preconditioning. Record also the begin
and end residual. Repeat this with eisenstat, ilu and mod eisenstat
preconditionings. Conclusion?
Practical exercises CFD II 22
Consider the flow between two flat plates. At the inflow we prescribe a con-
stant velocity. After some time the flow will have been converted to a fully
developed flow . In this exercise we shall simulate this numerically. Consider
the configuration as sketched in Figure 4. Due to symmetry it is sufficient
y
h/2
0 x
l
to consider a half channel only. The liquid satisfies the Navier-Stokes equa-
tions. At the inflow we prescribe a constant velocity field parallel to the flat
plates. On the fixed walls we have a no-slip condition. At the outflow we
assume that the flow is parallel to the plates. Furthermore we suppose that
the pressure is equal to 0.
Exercises:
exercise8.msh
Practical exercises CFD II 24
8b Solve the Stokes equations by the grid created in 8a. Use as inflow
velocity u = 1, a density = 1 and a viscosity = 0.01. What is
the corresponding Reynolds number based on the distance h? Choose
= 106 as penalty parameter, i.e. = 106 .
Make a vector plot of the velocity and a streamline plot.
The corresponding files are:
exercise8b.prb
exercise8d.prb
H
l
Exercises:
H=1
Practical exercises CFD II 26
h = 0.5
l=6
L = 38
The corresponding file is:
exercise9.msh
9b Solve the Stokes equations for Re = 50. Check if the solution satisfies
the boundary conditions.
The corresponding files are:
exercise9b.prb
9c Solve the Navier-Stokes equations for Re = 50. Make a stream line plot
and a vector plot of the velocity. You can also make a contour plot of
the pressure.
The corresponding file is:
exercise9c.prb
for various Reynolds numbers, where the Reynolds number is based on the
width of the channel. For Re = 500 the flow must be laminar and stationary.
The corresponding files are:
exercise10.msh
exercise10.prb
exercise11.msh
exercise11a.prb
exercise11b.prb
section for r > 0 has been drawn. In the inner pipe the liquid is warm in the
outer pipe it is cold. The outer temperature is assumed to be constant.
Exercise 14
Experiments with the Gaussian elimination method
In this exercise we consider various properties of the Gaussian elimination
method. The function [a,f] = poisson(n1,n2,u1,u2,disc) is used to
construct a matrix, which originates from a discretization of the following
equation:
2
c 2c c c
( x 2 + y 2
) + u1 x + u2 y = g where x, y (0, 1) (0, 1),
14a First the fill-in is investigated for small matrices. Therefore the com-
mand [l,u,p] = gauss(a); can be used. This function computes the
LU-decomposition of a with pivoting such that pa = lu. Furthermore
the number of nonzero elements and the bandwidth in l and u are given.
Finally the nonzero structures of the matrices are shown.
[a,f] = poisson(3,10,0,0,central);
[l,u,p] = gauss(a);
[a,f] = poisson(5,5,0,0,central);
[l,u,p] = gauss(a);
[a,f] = poisson(5,5,100,0,central);
[l,u,p] = gauss(a);
[a,f] = poisson(5,5,0,100,central);
[l,u,p] = gauss(a);
Try also some other values. Warning: for large matrices the CPU-time
can increase considerably (ctrl c kills a job).
14c Do the same exercises as before for upwind differences. Compare the
results.
14d In this exercise matrices are considered where the amount of fill-in can
be very large. The matrices are not related to the Poisson equation.
The matrices used here are known as arrowhead matrices. This type
of matrix occurs in Domain Decomposition methods. Call uparrow
Practical exercises CFD II 33
14e In the following part we investigate the solution of the discretized Pois-
son equation. Execute [a,f] = poisson(10,10,0,0,central);.
The LU-decomposition of the matrix a can be obtained by:
[l,u,p] = lu(a);
y = l\f;
norm(a*x-f)
plotsol(10,10,x)
[a,f] = poisson(10,10,200,0,central);
Practical exercises CFD II 34
Compute again norm(a*x-f). Its value should be less than 1010 . Fi-
nally the same problem can be solved using upwind differences. Com-
pare both solutions.
14g Finally some experiments are done with iterative improvement. First
the matrix and right-hand side are formed by [a,f] = poisson(5,5,0,0,central);
Compute the LU-decomposition with
[l,u,p] = lu(a);
l = random(l,10^(-5));
This function changes the lower triangular matrix l with random num-
bers of order less than 105 . Compute norm(a-l*u) to check that a 6=
lu (the matrix u can also be changed). Write a function iterna(a,l,u,p,f)
which uses the disturbed matrix l (and possible the disturbed matrix
u). First construct a termination criterion and make the function such
that it stops after 100 iterations.
Exercise 15
Experiments with iterative methods
In this exercise we consider various iterative methods to solve linear systems.
We start with systems where the coefficient matrix is symmetric and positive
definite. These systems are solved by basic iterative methods and the Con-
jugate Gradient method. Finally we investigate if these methods can also be
applied to non-symmetric systems.
15a Construct the matrix a and the right-hand-side vector f using the call
[a,f] = poisson(10,11,0,0,central); Compute the solution of
the linear system with the Gauss-Jacobi method:
x = jacobi(a,f,10^-10);
Write down the number of iterations for comparison with other meth-
ods.
15b First try to modify the program jacobi.m to obtain the Gauss-Seidel
method. To check your implementation you also use:
x = seidel(a,f,10^-10);
15c In this exercise we use the SOR method. The estimate of the optimal
is not straightforward. Therefore we do some experiments with various
choices of . Type
Practical exercises CFD II 36
x = sor(a,f,10^-10,omega);
x = sor(a,f,10^-10,0);
x = cg(a,f,10^-10);
Compare the results with the results obtained with the basic iterative
methods.
x = cganal(a,f,10^-10);
Practical exercises CFD II 37
15f There are matrices where the theory for the CG method no longer
holds, due to rounding errors. One of them is a discretization of the
bending beam equation:
d4 c
= f.
dx4
The matrix can be constructed by beam; Take for the dimension 40
(thereafter also try 80 and 160). Solve the system by
x = cganal(a,f,10^-10);
Exercise aims:
Exercise aims:
Exercise aims:
Exercise aims:
div(p) = 0 , (6)
with p the excess pressure and the permeability. At the earths surface the
excess pressure is prescribed. When the pressure field is required in some
reservoir it is not practical to calculate the pressure in every position of the
earths crust. Therefore the domain of interest is restricted artificially. We
assume that the lowest layer is bounded by an impermeable layer, so there
is no flux through this boundary. The artificial vertical boundaries are taken
at a sealing fault, or far away from the reservoir. Again a zero flux condition
is a reasonable assumption at these boundaries.For our model problem we
assume that in sandstone is equal to 1 and in shale is equal to 107 .
Furthermore the Dirichlet boundary condition at the earths surface is set
equal to 1. The solution of equation (6) with these boundary conditions is of
course p = 1, but if we start with p = 0 or a random vector, our linear solver
will not notice the difference with a real problem. Numerical experiments
show that the choice of one of these start vectors has only marginal effects
on the convergence behavior. An advantage of this problem is that the exact
error can easily be calculated. We consider this problem on a rectangular
domain with 7 straight layers. In each layer 10 elements in the horizontal
and 5 elements in the vertical direction are used.
Exercises:
Before starting this exercise copy the files exercise16* from the sepran direc-
tory to your working directory.
16a We start by solving this problem without preconditioning and stop the
CG iterations if the residual has been reduced by a factor accuracy =
106 . Give the following commands:
sepmesh exercise16.msh
Practical exercises CFD II 40
sepcomp exercise16a.prb
sepview sepplot.001
Note that the residual is small but the solution is not close to the exact
solution p = 1. Repeat the computation with accuracy = 107 and
accuracy = 108 . Inspect the solution and measure the number of
iterations.
16b We now include IC preconditioning. Therefor you can use the file
exercise16b.prb
16c Make a table with the number of iterations where the k shale in exer-
cise16b.prb is chosen equal to 102, 104 , and 107 .
16d Repeat exercise c with deflation. The deflation choices are specified in
exercise16d.prb
16e Finally, use the file exercise16d.prb and chose k shale equal to 107 and
vary accuracy: 102 , 104 , 106 , and 108 . Compare the number of
iterations and the quality of the solution.