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

Tutorial de OpenFOAM Con Ubuntu Linux 12.04

- The document provides instructions for installing Ubuntu Linux 12.04 LTS and OpenFOAM version 2.2 to run external aerodynamics simulations. - It describes running a cavity tutorial case using the solver icoFoam to demonstrate that OpenFOAM has been correctly installed and configured. - Directories containing the solved pressure and velocity fields are generated at different time intervals, showing the transient nature of the simulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views

Tutorial de OpenFOAM Con Ubuntu Linux 12.04

- The document provides instructions for installing Ubuntu Linux 12.04 LTS and OpenFOAM version 2.2 to run external aerodynamics simulations. - It describes running a cavity tutorial case using the solver icoFoam to demonstrate that OpenFOAM has been correctly installed and configured. - Directories containing the solved pressure and velocity fields are generated at different time intervals, showing the transient nature of the simulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.

04 LTS 32-bit

External Aerodynamics 
Using OpenFOAM
Dr. Tom Scanlon

July 2013

Dr Tom Scanlon 2013 1


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

1. Introduction

OpenFOAM (Open Field Operation and Manipulation) is an open­source 
set   of   computationally­efficient,   parallelised,   C++,   CFD   modules   for 
solving   complex   fluid   flows.   It   is   freely   available   to   download 
(www.openfoam.com) under the GNU general public licence. OpenFOAM 
runs under the Linux operating system (OS). Linux is also freely available 
to download and various ‘flavours’ of Linux are available. The version of 
Linux selected to run with OpenFOAM v2.2 is Ubuntu Linux v12.04 LTS 
32­bit (www.ubuntu.com). This means that it is possible to set­up and run 
high­end,   CFD   software   and   an   OS   with   no   commercial   fees.   This 
document   assumes   the   user   has   no   experience   of   Linux   but   it   is 
recommended   that,   for   reference,   you   search   for   and   download   “basic 
Linux   commands”   on­line.  You   will   be   given   a   memory   stick   with  
Ubuntu/OpenFOAM pre­installed. You will boot into Ubuntu from  
the memory stick and run and save your OpenFOAM cases from the  
stick.   When   booting   into   the   memory­stick   select   “Try   Ubuntu”   ­  
note it may take a few minutes to boot into linux.

2.0 Installing Ubuntu Linux v.12.04 LTS and OpenFOAM on your 
own PC/laptop

If you wish, you can also install Ubuntu 12.04 LTS Linux on your own 
PC/laptop side­by­side with your normal Windows OS. You will be able to 
select Ubuntu Linux or your original Windows OS when you turn­on your 
PC/laptop. 

Before   installing   Ubuntu,   you   should   make   a   back­up   copy   of   any 


important   files   on   your   PC   (just   in   case!).   Firstly,   check   if   your   PC   or 
workstation is 32­bit or 64­bit, most PCs being 32­bit. To check this using 
Windows click on: 

Start/Programs/Accessories/System Tools/System Information.

If   the   “System   Type”   item   shows   “X86­based   PC”   then   it   is   a   32­bit 


computer. If it shows “X64­based PC” then it is a 64­bit computer. 

Now, download the appropriate version of Ubuntu v.12.04 (32­bit or 64­
bit) from  the Ubuntu web­site (www.ubuntu.com) and burn it  to CD to 

Dr Tom Scanlon 2013 2


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

create an installation CD. The instructions on how to do this are on the 
Ubuntu web­site. 

You   now   need   to   change   the   boot   sequence   of   your   PC   such   that   the 
CD/DVD drive is accessed before the hard­disk drive (HDD). To change 
the boot­sequence, restart your PC and hit one (or all) of the function keys 
(F1,F2 etc.) as the PC boots up (each PC will have a different F key to 
enter the set­up options). Search the set­up options to move the CD/DVD 
drive to be the 1st in the boot­sequence.

Follow the Ubuntu instructions to install Linux  side­by­side  with your 


Windows OS. Be very careful not to select the option which over­writes 
your Windows OS! 

The 'side­by­side' installation option allows you to select either Windows 
or Linux when your PC is switched on. On re­booting your PC, change the 
boot sequence back to its original configuration (HDD first).

After   Ubuntu   has   been   installed,   you   need   to   install   some   additional 
software from the web (you need to be on­line). This additional software is 
necessary to run Linux/OpenFOAM correctly. The software is located in 
on­line   'repositories'   (software   warehouses)   which   are   free   to   access.   To 
install   the   software   using  Ubuntu,   activate   the  update   manager 
by clicking on the dash button  and   type  update  to   search   for   the 
update manager, then click on  the  update   manager  icon 
and select install updates.

Depending upon your internet connection speed, the additional software 
should download and install in around 10 minutes.

When you are on­line, the Ubuntu OS will prompt you from time to time to 
download and install certain other packages to keep your Linux system 
updated   and   secure.   You   should   install   these   packages   whenever 
prompted to do so. However, if prompted, do not update the Ubuntu OS 
itself to a newer version as OpenFOAM is designed to be used with specific 
versions of Ubuntu (in our case Ubuntu v12.04 LTS).

After  installing  Ubuntu  on  your  PC/laptop you   can boot  into linux  and 


install   OpenFOAM   v2.2   by   following   the   Ubuntu   Deb   Pack   download 
instructions at www.openfoam.com.

Dr Tom Scanlon 2013 3


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

3. Running OpenFOAM v2.2.

Assuming you are running OpenFOAM from either the memory­stick or 
from a correctly­installed version on your PC/laptop:

Type:

run

This will take you into your run directory. Typing:

pwd

should show that you are in the following directory:

/home/tom/OpenFOAM/tom­2.2.0/run

Now, create a directory called ‘tutorials’ in your run directory by typing:

mkdir –p tutorials

(i.e. mkdir[space]­p[space]tutorials)

Go into the tutorials directory by typing:

cd tu[hit tab key now]

(i.e. cd tutorials)

Now,  check  that   OpenFOAM  is   working  by  running  one  of the tutorial 
cases. Firstly, copy the tutorial case called ‘cavity’ into your run/tutorials 
directory by typing (or copy and pasting the line below):

(Note: to copy and paste in Linux, highlight the line below using the left­
hand mouse button, release the left­hand button and move the cursor into 
the terminal window. Now, click the middle­button and the highlighted 
text will be pasted).

cp ­r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .

(note the space, dot at the end of this line). The dot means ‘copy to here’.

Dr Tom Scanlon 2013 4


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Now, type:

ls

to check the cavity directory has been created.

Go into the ‘cavity’ directory by typing:

cd ca[hit tab key now]

(i.e. cd cavity)

Typing ‘pwd’ [return] shows that you should be in the directory:

/home/tom/OpenFOAM/tom­2.2.0/run/tutorials/cavity

The ‘cavity’ case describes transient, laminar flow in a lid­driven cavity, as 
shown in figure 1:

Figure 1 Sketch of the lid­driven cavity tutorial case.

Dr Tom Scanlon 2013 5


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

We   will   use   the   incompressible   OpenFOAM   solver   called   ‘icoFoam’ 


(meaning ‘Incompressible Foam’). 

Note, this is the way that OpenFOAM is designed to be used. You search 
in the tutorials for a case which resembles the one you are trying to solve, 
copy this to your run directory and modify it to suit your own conditions.

In   the   ‘cavity’   directory,   typing   ‘ls’   shows   that   OpenFOAM   is   set­up 


initially   with   three   working   directories,   namely,   ‘0’,   ‘constant’   and 
‘system’. The ‘0’ time directory is where the boundary conditions for the 
‘fields’ that we are solving for are set (in this case the velocity vector field, 
U,   and   the   scalar   pressure   field,   p).   We   will   analyse   the  constant  and 
system directories later.

When solving this transient  (unsteady) problem, other ‘time’ directories 
will be created in addition to the ‘0’ directory. In the ‘cavity’ case, 0.1, 0.2, 
0.3, 0.4 and 0.5 will also be created. The final time directory ‘0.5’ is where 
it is assumed that we have reached steady­state conditions. Even when 
using steady­state solvers (as we will see later with 'simpleFoam') ‘time’ 
directories will be created that represent field outputs (p, U etc) after a 
certain number of iterations.

For the  transient  'cavity'  case, the  time­step size is  set  using  what are 


called   OpenFOAM   ‘dictionaries’.   Such   dictionaries   are   widely­used   in 
OpenFOAM as the means of setting boundary conditions / units / control 
parameters such as time­step size / frequency of data output etc. 

The   time­step   size   is   set   in   the   dictionary   called   controlDict   which   is 
located in  system/controlDict. Take a moment to explore the dictionaries 
in the ‘0’, ‘constant’ and ‘system’ directories using the editor ‘gedit’, e.g., 
type:

gedit system/controlDict

Further information can be found at (http://www.openfoam.com/docs/user).

To run the cavity case you should be in the ‘cavity’ directory.

To run the mesh pre­processor (i.e. format the mesh), type:

blockMesh

Dr Tom Scanlon 2013 6


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

To solve (run) the problem, type:

icoFoam
Now, type:

ls

to list the files/directories in your ‘cavity’ directory. You will see that 5 new 
‘time’   directories   have   been  created  (0.1,  0.2,  0.3,  0.4   and  0.5).   Each  of 
these directories contain solved data for the fields (p, U) at time intervals 
0.1 secs to 0.5 secs.

In order to view the solved­for fields of pressure (p) and velocity (U) we 
will use the open­source visualisation tool called paraView, which is part 
of the OpenFOAM software suite that you have downloaded and installed.

Type:
paraFoam

When in paraView, advance the time to be the last time (frame) directory 
by setting the time directory as 5 (0.5 secs), as shown in figure 2 below, 
then select apply:

Figure 2 Advance to the last time frame in paraView.

In the Solid Color drop­down menu (figure 3), choose the velocity field, U: 

Dr Tom Scanlon 2013 7


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 3 Select the velocity field U in paraView

This should produce the plot shown in figure 4:

Figure 4 Velocity field U plotted in paraView.

Dr Tom Scanlon 2013 8


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

If necessary, change the color map in the Object Inspector/Display panel 
(Edit Color Map/Choose Preset) to be ‘Blue to Red’, as shown in figure 5:

Figure 5 Change the Color Map to be 'Blue to Red'.

Now, select the ‘Color legend’ button (top/left of screen)  .   This   will 


show the velocity scale for ‘U Magnitude’ as shown in figure 6 below:

Figure 6 Velocity field using 'Blue to Red' colour legend.

Dr Tom Scanlon 2013 9


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Un­select the central cross by clicking on the 'show­center' 
button 

Clicking in the gray area and using the left­mouse button allows you to 
rotate,   the   middle­button   to   pan   and   the   right­button   to   zoom.   Take   a 
moment to play around with these buttons. You can also reposition the U­
Magnitude colour legend by dragging it to another location on the screen. 

To return to the standard view, click on the ‘­z’  coordinate  button.

Now   draw   the   velocity  vectors (called ‘glyphs’ in paraView) by 


clicking   on  the  glyph  button  and   click   ‘apply’.   In   the   ‘solid   colour’ 
drop   down   menu,   change  from   p  to   U.   You   should   now   see   the 
vectors and the contours on the same plot, as shown in figure 7. 

Figure 7 Contours and glyphs (velocity vectors) on the same plot.

You can switch on/off any plots by clicking on the ‘eye’  icon   in   the 


Pipeline Browser.

Now, create a 2D section using the slice  icon   .   Select   the   z­normal 


plane as shown in figure 8 below.

Dr Tom Scanlon 2013 10


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 8 Creating a z­normal slice.

Click on 'Apply' and then un­select the 'Show Plane' option. 

Now,   hide   the   glyph   vectors   by   clicking   on   the   'eye'  beside   'Glyph 
1'.

You should now see the velocity contours on the 2D slice you have created, 
as shown in figure 9 below:

Figure 9 2D slice showing velocity contours.

Dr Tom Scanlon 2013 11


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

In paraView, you can save plotted images to a .jpg, .bmp, .png etc format 
using: 
File/Save Screenshot/ok

or by using Ubuntu's own powerful screenshot facility by selecting:

Applications/Accessories/Take Screenshot

Try   also   plotting   the   pressure   field   contours,   as   well   as   the  x­   and  y­ 
velocity   components   and   saving   the   images   using   both   techniques 
described above.

You have now completed the first tutorial case. We will now move on to 
look at external flow aerodynamics with OpenFOAM.

Dr Tom Scanlon 2013 12


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

4. External Aerodynamics using OpenFOAM

4.1 Introduction

The aim of this section is to set up and run an OpenFOAM tutorial case 
involving   external   aerodynamics.   The   problem   considers   flow   over   a 
motorbike and rider. The geometry is supplied as a .obj format surface (obj  
is a standard output format from CAD packages – other formats that may 
be used in OpenFOAM include  .stl  format). The  .obj  geometry is shown 
below in figure 10.

Figure 10 Motorbike geometry in .obj format.

The flow velocity is U = 20 m/s and the dimension of a box containing the 
bike and rider is approximately 2.0 m length x 0.8 m width x 1.3 m height. 
We estimate the length scale for the bike/rider to be L = 0.5 m.

For air, the laminar kinematic viscosity is:

 = 1.5×10−5 m2 /s

While the Reynolds number is:

Re = U L/ = 6.7 × 105

Dr Tom Scanlon 2013 13


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

The problem is steady­state and the turbulence model will be one of the 
Reynolds­Averaged   Stress   models   (called   'RAS'   models   in   OpenFOAM) 
with wall­functions to determine the shear stresses at solid surfaces. The 
turbulence model used in this problem is the k­omegaSST model.

4.2 Meshing considerations

Use   will   be   made   of   the   OpenFOAM   meshing   utility   called 


snappyHexMesh.   This   utility   takes   a   large   outer   box,   filled   with 
hexahedral elements (6­sided, box­type cells) and 'snaps' these cells on to 
the complex geometry described by the CAD .obj file (in our case the bike 
and rider of figure 10). 

At  wall  surfaces, in order  for  the  wall­functions   to work  effectively,  we 


require 30  y +  200 where the dimensionless distance, y + , is defined 
as:
U y
y+ = *

where  U * =

w

is the shear velocity,   w is the wall shear stress,  is 

the  fluid  density,   and  y  is  the   distance  from   any  wall   to   the  first   cell­
centre, as shown in figure 11.

Figure 11 Cell height, y, used in wall y+ calculation.

Let's try to obtain a mesh for which y + ≈ 200 . For the case of turbulent 


flow over a flat plate, the skin­friction coefficient, Cf , correlation is: 

Dr Tom Scanlon 2013 14


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit
2 −0.2 −3
C f /2 = w / U  = 0.0359 Re = 2.5×10

The   shear   velocity U * =


w

=U

Cf
2 
≈ 1 m/s .   Hence,   the   cell­centre 
distance, y, (and hence a reasonable estimate of the first cell size) may be 
determined from:
+
y= y / U *≈3 mm

4.3 Setting up the motorBike case

Before   we   begin   the   case   we   should   point   out   an   important   feature   in 
OpenFOAM/Linux/C++   which   relates   to   the  file/directory/utility   naming 
convention.   This   convention,   which   should   be   adhered   to   if   you   are 
creating new files/directories etc., states that all names begin with lower 
case and any second or third names begin with upper case.

For example,  the dictionary   file  controlDict  contains  two  words,  control 


and  Dict  with the first word beginning with lower case and the second 
adjoining word with upper case. Within controlDict there are parameters 
that  require to be set, such as  startTime,  latestTime  etc. Note that the 
naming   convention   for   these   files,   directories,   parameters   and   utilities 
remains consistent and is something you should be careful to adhere to. 
Other examples  include  the meshing utility  we are  going  to use in the 
following motorBike example, i.e. snappyHexMesh.

Firstly, open a terminal window   by clicking on the dash home icon 
and type 'terminal'.  You will see the terminal icon  which   you   can 
click on.

Note: you can drag the Terminal icon (or any other icon) to the task bar at 
the   left   of   the   screen   using   the   left­button   of   the   mouse.   In   this   way, 
commonly­used icons can be kept at hand, as shown in figure 12 

                                   calculator
                       terminal
                           screenshot

Figure 12 Additional icons in the task bar.

Dr Tom Scanlon 2013 15


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Typing   'run'   will   take   you   automatically   into   your 


/home/tom/OpenFOAM/tom­2.2.0/run  directory.   Now,   type   'cd   tut[hit  
tab key]' to go into your 'tutorials' directory.

Now,   copy   the   motorBike   case   from   the   OpenFOAM   tutorials   directory 
into your own tutorials directory, by typing (or copy and paste):

cp ­r $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike .

(i.e. cp[space]­r[space]$FOAM_TUT.../motorBike[space]dot)

You will now have a directory called motorBike in your tutorials directory. 
Now 'cd' into the motorBike directory you have just created by typing:

cd motorBike

Typing 'ls' should show the following output in your terminal window:

Figure 13 Terminal window showing motorBike directories

Next, copy the motorBike surface geometry from the resources directory: 

cp   $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz 
constant/triSurface

(i.e. cp[space]$FOAM_TUT.../motorBike.obj.gz[space]constant/triSurface)

Now, copy the 0.org directory to 0 by typing: 

cp ­r 0.org 0 

Go into the constant/triSurface directory: 

Dr Tom Scanlon 2013 16


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

cd constant/triSurface 

and uncompress the motorBike geometry file: 

gunzip motorBike.obj.gz 

Now, have a look at the motorBike.obj file by running paraview. 

Type:
paraview

and   open  the  motorBike.obj  file  using   the  'open'   icon.  .Use   the 
mouse to set the position of the bike such that it is as  shown   below 
in figure 14.

Figure 14 paraview window showing motorBike.stl geometry

Now, exit paraview and return to the terminal window.

*********************************************************************
Useful Tip
A useful  tip when  typing  commands  is  to use the 'up'  arrow  key. Your 
.bashrc  file   contains   a   setting   that   allows   Linux   to   recall   all   of   the 
commands you have already used. So, for example, typing 'su' followed by 
the 'up'  arrow key will  recall all  of the commands that  began with the 

Dr Tom Scanlon 2013 17


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

letters 'su'. Continue to hit the 'up' arrow key until you find the command 
you want and modify it accordingly.
*********************************************************************
4.4 Meshing with snappyHexMesh

4.4.1 Setting up the background mesh

The meshing utility  snappyHexMesh  works by taking a large hexahedral 


background mesh (6­sided, box­type elements) and 'snaps' these regular, 
orthogonal   cells   on   to   the   complex   geometry   represented   by   the  .obj 
surface.

The background mesh extent should equal the size of the computational 
domain   and,  for   external  flows,   this   extent   normally  depends  upon  the 
expected size of the wake downstream of the body of interest.
*********************************************************************
Useful Tip
As   a   rough   rule   of   thumb,   if   your   bluff­body   (e.g.   motorBike   has   a 
characteristic   length,  L,   then   the   extent   of   your   computational   domain 
should   be   approximately   5L  upstream,   on   each   side   and   above,   and 
approximately 15L downstream to account for wake effects. This is shown 
in figure 15. In general, the greater the bluffness (non­streamlined shape) 
of the body, the larger the wake effects will be and the domain should be 
increased accordingly such that wake effects (recirculation zones etc) do 
not have an influence on the computational boundaries.

Figure 15 Guideline for extent of computational domain for bluff­body  
external flows

Dr Tom Scanlon 2013 18


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

The  motorBike.obj  surface is contained within its own bounding box. We 


need to establish the location of this bounding box. This is done in the 
constant/triSurface directory by typing:

surfaceCheck motorBike.obj | grep ­i 'bounding box'

The '­i' option in the 'grep' command means 'ignore case sensitivity' (i.e. 
treat upper and lower case letters in a word as the same, e.g. in a grep ­i 
search, the phrase 'Bounding Box' is the same as 'bounding box').

This produces the result shown below in figure 16:

Figure 16 Extent of bounding box for motorBike.obj surface

Figure 15 shows that the  x­direction extent of the bounding box is from 
­0.291665   m   to   1.75115   m,   the  y­direction   extent   from   ­0.350289   m   to 
0.332267 m and the  z­direction extent from ­4.232e­05 m to 1.35156 m. 
The positive  x­direction is the flow direction, the  y­direction is normal to 
the flow and the z­direction is the height.

Figure 17 shows the motorBike with its bounding box.

Figure 17 motorBike and its bounding box

Dr Tom Scanlon 2013 19


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Boundary   conditions   in   OpenFOAM   are   described   using   'patches'.   A 


'patch'   just   signifies   a   region   on   the   boundary   of   the   computational 
domain. We can then specify the type of boundary condition (to describe 
inlets/outlets/walls etc) at each 'patch' name. We can see such patches in 
the dictionary file called  blockMeshDict. To view this file, firstly change 
directory   from   your   current   directory   (motorBike/constant/triSurface) 
into the motorBike directory by typing:

cd ../..

The command 'cd ..' takes you up one level, while 'cd ../..' takes you up two 
levels into the motorBike directory.

To view the blockMeshDict file in non­editing mode, type:

more constant/polyMesh/blockMeshDict

Or, to use the gedit file editor, type:

gedit constant/polyMesh/blockMeshDict

*********************************************************************
Useful Tip
Ending a linux command with the character '&' allows an application to 
run   while   the   user   can   still   type   further   commands   in   same   terminal 
window, e.g. typing 'gedit constant/polyMesh/blockMeshDict &' opens the 
gedit editor but still allows the user to input further commands and run 
other applications using the same terminal window. 

The larger bounding box for the computational domain is specified in the 
blockMeshDict dictionary file. The domain size will be set as 20×8×8 m 
with the flow inlet patch located 5 m upstream of the bike.  There are 20 
cells in the x­direction and 8 cells in y­ and z­directions. This means that 
the   edge   length   of   each   computational   cell   is   1   m.  snappyHexMesh 
recommends the cell aspect ratio (ratio of edge width to height to length to 
be   ~   1).   Such   regular   cuboid­shaped   cells   help   improve   the   snapping 
process. Take a moment to analyse the blockMeshDict file to see how the 
domain size,  mesh and patches are specified.

Now, we create the mesh specified in the blockMeshDict dictionary using 
the blockMesh meshing utility. In the motorBike directory, type:

Dr Tom Scanlon 2013 20


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

blockMesh 

We have now created our background mesh. You can view the mesh and 
the position of the bike in paraFoam, type:

paraFoam

Note:   you   could   have   made   use   of   the   Linux   'history­search­backward' 


option by typing 'pa[hit up arrow key]' to find the paraFoam command.

In   paraFoam   select   'Apply'   and   view   the   background   mesh   using   the 
'Wireframe' option as shown in figure 18:

Figure 18 Background mesh

Now,   insert   the  motorBike.obj  geometry   to   see   its   position   in   the 


computational   domain.   Select   'File/Open'   and   go   into   the 
constant/triSurface  directory to select the  motorBike.obj  file as shown in 
figure 19:

Dr Tom Scanlon 2013 21


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 19 Selecting the motorBike.obj file
and click 'Apply'.
You   will   now   see   the   position   of   the   bike   relative   to   the   overall 
computational   domain.   The   bike   geometry   and   background   mesh   are 
shown in figure 20 below:

Figure 20 Bike geometry and background mesh

Note, you can alter the colour of the bike using the 'Edit Color Map' 
key.

Dr Tom Scanlon 2013 22


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Save any images you require using File/Save Screenshot or use Ubuntu's 
useful screenshot program by clicking on the dash home icon and typing 
'screenshot'   –   drag   the   screenshot   icon  into  your   task  bar  on   the 
left of the screen.

You can also save your paraFoam settings by selecting 'Save/State', then 
when you re­open paraFoam, use 'Load/State'. 

Now, exit paraFoam and return to the terminal window in your motorBike 
directory. 

Make a final check of the size of the computational domain ( 20×8×8 m) 


by using the OpenFOAM utility checkMesh by typing:

checkMesh | grep ­i 'bounding box'

The results are shown in figure 21 and confirm that the domain size is 
correct:

Figure 21 Confirmation of domain size 20×8×8 m

4.4.2 Grid refinement using snappyHexMesh

Now, we need to refine our rather large, coarse mesh (cell sizes ~ 1 m) in 
the region of interest. This region of interest will normally be around the 
location of the bluff­body (i.e. the bike) and in the wake zone, immediately 
downstream of the body. We use our engineering judgement to select a 
volume refinement region, within which we will add more computational 
cells. This will create a denser mesh zone (the mesh will be more refined), 
allowing   us   to   capture,   in   finer   detail,   flow   features   such   as   velocity 
gradients,   pressure   effects   and   viscous   stresses   etc.   on   and   around   the 
body.

Dr Tom Scanlon 2013 23


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Recall that we are trying to create a mesh such that we satisfy the  y+ 
criteria 30  y +  200 .   This   is   to   ensure   that   the   turbulent   flow   skin 
friction values on the bike are determined correctly (using turbulent wall 
functions). Our previous calculation determined that the height of the first 
cell at any solid surface should be of the order y= y + /U *≈3 mm .

Prior   to   meshing   we   can   extract   certain   edge   features   of   the 


motorBike.obj  geometry.   This   will   allows   us   to   focus   the   mesh   around 
these edges and create a more accurate rendition of the meshed geometry. 
To do this we use the surfaceFeatureExtract utility; in a terminal window 
in the motorBike directory type:

surfaceFeatureExtract

this   will   create   a   new   file   called   motorBike.eMesh   in   your 


constant/triSurface directory.

We will use the meshing utility  snappyHexMesh  to create our mesh and 


the   controls   for   this   utility   are   in  system/snappyHexMeshDict  file.   By 
editing the snappyHexMeshDict  file we can set the size of the refinement 
region as follows; type

gedit system/snappyHexMeshDict &

The   refinement   region   is   defined   using   the   variable  refinementBox  as 


shown in figure 22:

Dr Tom Scanlon 2013 24


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 22 Refinement box settings in file snappyHexMeshDict

To   activate   the   line   numbers   when   using   the   'gedit'   editor,   click   on 
'Edit/Preferences/Activate line numbers'. 

Recall (figure 16) that the x­direction extent of the motorBike.stl bounding 
box was from ­0.291665 m to 1.75115 m, this means that the refinement 
box begins approximately 0.71 m upstream of the bike's front wheel and 
extends to approximately 6.25 m downstream of the rear wheel. Similar 
calculations can be made for the extent of the y­ and z­directions.

Dr Tom Scanlon 2013 25


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

4.4.3 Creating a mesh

Figure   22   outlines   the   meshing   steps   to   run   (highlighted   as   “true”)   as 


follows:

1) Generate a  castellated  mesh ­ this process will generate a rough 


mesh   which   follows   the   outline   of   the   surface   of   the   bike  .obj 
geometry.
2) Snap  the castellated mesh on to the surface of the  motorBike.obj 
file.
3) Add   a   mesh  layer  on   to   the   surface   of   the   bike   and   rider   and 
smooth out any imperfections.

We   will   carry   out   all   three   of   these   steps   simultaneously   (i.e. 


castellatedMesh, snap and addLayers), however, you can deactivate any of 
the steps by setting them to “false”. For example, Figure 23 shows and 
example   of   running   the   castellated   mesh   only   with   no   snapping   (for 
information only):

Figure 23 The intermediate castellated mesh

Now, edit the snappyHexMeshDict file, type

gedit sy[hit tab key]/sna[hit tab key]

Dr Tom Scanlon 2013 26


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

(i.e. gedit system/snappyHexMeshDict)

The   following   features   are   highlighted:   Figure   24   shows   the   section 


dealing   with   grid   refinement   to   the   edges   that   we   extracted   using   the 
surfaceFeatureExtract utility:
 

Figure 24 Edge feature refinement.

Note the section on 'refinementSurfaces' as shown in figure 25:

Figure 25 snappyHexMeshDict setting for level of refinement.

Add   the   blue   comment   line   to   remind   you   of   the   y+   requirement


30  y +  200 to create a first­cell mesh size of y= y /U *≈3 mm .
+

What we are doing here is taking our original background mesh, with a 
cell   size  of 1   m,  and  reducing   the  cell  size our   refinement   box   using   6 
levels of refinement. In this case we will reduce (by halving) the cell size 6 

Dr Tom Scanlon 2013 27


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

times   and   this   should   produce   near­wall   cells   with   a   dimension   of


1/ 26 ≈ 15 mm . A typical mesh refinement process is shown in figure 26:

        <­­­­­  level 1 ­­­­­­­><­­­­­  level 2 ­­­­­­­><­­ level 3 ­­><­­ level 4 →
          
Figure 26 snappyHexMeshDict typical refinement process showing 4 levels  
of refinement based on a 2:1 halving of grid size

Next,   still   in   the  snappyHexMeshDict  file  note   the   section   on 


'refinementRegions'

Figure 27 snappyHexMeshDict guaranteeing at least 4 levels of  
refinement inside the refinementBox

Add the comment line in blue to remind you of the settings.

The next parameter to note is 'nCellsBetweenLevels':

Dr Tom Scanlon 2013 28


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 28 snappyHexMeshDict number of buffer layers

The setting 'nCellsBetweenLevels 3' controls the abruptness of the mesh 
refinement. In this case we have 3 cells between each level of refinement. 
Figure 25 showed a refinement with nCellsBetweenLevels = 1, i.e. a 2:1 
refinement.

Now,   still   in   the  snappyHexMeshDict  file,   consider   the   variable 


'locationInMesh'. This represents an x, y, z coordinate location of a point in 
space which exists outside of the refinement box but still lies within the 
computational domain. In our case the refinement box dimensions are ­1 
to 8 m in  x, ­0.7 to 0.7 m in  y  and 0 to 2.5 m in  z. The computational 
domain   size  is   ­5   to  15   m   in  x,  ­4   to  4   m   in  y  and  0   to   8   m   in  z.  the 
locationInMesh setting of (3    3   0.43) guarantees  a  point  to satisfy the 
above criteria.

We can now mesh the problem; in a terminal window in the motorBike 
directory, type:

snappyHexMesh ­overwrite > log.snappy &

then type:
tail ­f log.s[hit tab key now]

(i.e. tail ­f log.snappy)

The tail ­f command will show the snappyHexMesh command running and 
eventually display the final output of the log.snappy file, as shown in 
figure 29:

Dr Tom Scanlon 2013 29


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 29 Bottom of log.snappy file

Ctrl­C will take you back to your motorBike directory.

Now view the mesh by typing:

paraFoam

and select 'Apply'.

From the drop down menu select the mesh to be displayed as “surface with 
edges” and zoom into the bike as shown in Figure 30:

Dr Tom Scanlon 2013 30


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

 
Figure 30 Final mesh for motorBike case.

5. Solving the problem

We have now completed the meshing process with  snappyHexMesh  and 


are   ready   to   solve   the   problem.   We   will   edit   various   OpenFOAM 
'dictionaries'   which   are   related   to   things   such   as   boundary   conditions, 
initial conditions, choice of solver etc.

Firstly, we go into the tutorials directory by typing, in a terminal window:

run

followed by:

cd tutorials/motorBike

The   laminar   kinematic   viscosity   has   already   been   set   to


 =1.5×10−5 m2 /s in   the  constant/transportProperties  dictionary.   Also, 
recognise that units must be consistent (SI – kg, m, s) in OpenFOAM and 
the   units   are   input   as   shown   in   figure   31   which   shows   the 
constant/transportProperties dictionary.

Dr Tom Scanlon 2013 31


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 31 Specifying units in the constant/transportProperties dictionary

'nu' is the OpenFOAM name for the laminar kinematic viscosity,  , the 
first three values in the square brackets [0  2  ­1...] correspond to the index 
power of the SI units  kg,  m  and  s  respectively, i.e.   kg 0×m 2×s−1=m2 / s   . 
The other arguments in the square brackets […,0  0  0  0] refer to units for 
electrical charge, luminosity etc.

We   will   be   using   the   2­equation,   Reynolds­averaged   stress   (RAS) 


turbulence   model  kOmegaSST,   where  SST  stands   for   'shear   stress 
transport'.   This   is   one   of   many   turbulence   models   available   in 
OpenFOAM, and the  kOmegaSST  model is commonly used for external 
flow aerodynamics.

The CFD solver we will be using is called simpleFoam and simpleFoam is 
hard­coded to use one of the RAS models. The RAS model (kOmegaSST) is 
specified in the dictionary constant/RASproperties as shown in figure 32:

Figure 32 Turbulence model in the constant/RASProperties dictionary

Dr Tom Scanlon 2013 32


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

5.1 Flow­field initialisation and boundary conditions

The   initial   and   inlet   conditions   for   the   turbulence   fields   are   estimated 
from   the   mean   flow   speed  U,   the   turbulence   intensity,  I,   and   the 
characteristic length scale of the turbulence, L.

Assuming our study of flow over the motorbike has been conducted in a 
wind tunnel, typical values for I = 2%, L = 0.1× tunnel  'diameter', while 
the inlet velocity is 20 m/s.

General turbulence values that may be of interest are shown in Table 1 
below:

Turbulent kinetic energy k =1.5U⋅I 2


Turbulent dissipation rate  = C 0.75 1.5
 k /L

Specific turbulent dissipation rate  = C−0.25 k 1.5 /L


2
Turbulent viscosity  t = C k /
Modified turbulent viscosity t = 1.5U⋅I⋅L

Table 1 Typical turbulence values 

Wall   functions   to   resolve   the   turbulent   wall   shear   stresses   are   always 
specified   on   the   OpenFOAM   turbulent   viscosity   field   'nut'   (  t ). 
Examples include  nutWallFunction  and  nutRoughWallFunction. Further 
details can be found in the directory:

src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallF
unctions/nutWallFunctions

Wall function boundary conditions for the turbulence fields are specified 
as shown in table 2:

OpenFOAM Field name Wall functions, high Re Boundary condition, value


nut nut...WallFunction fixedValue, 0
k, q, R kqRWallFunction fixedValue, 0
epsilon epsilonWallFunction zeroGradient
omega omegaWallFunction ---

Dr Tom Scanlon 2013 33


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

zeta --- FixedValue, SMALL


nuTilda zeroGradient fixedValue, 0

Table 2 Boundary conditions for the turbulence fields

Typical OpenFOAM boundary conditions for the fields of pressure, velocity 
and turbulence for external aerodynamic flows are shown in table 3:

Boundary Pressure Velocity Turbulence


Inlet zeroGradient fixedValue fixedValue
Outlet fixedValue inletOutlet inletOutlet
Wall zeroGradient fixedValue see Table 2

Table 3 General boundary conditions for external aerodynamics

The boundary condition 'inletOutlet' offers computational stability in case 
of flow reversal.

5.2 Macro substitution

When using OpenFOAM, a lot of field initialisation and implementation of 
boundary conditions is duplicated, e.g. the internal field value is often the 
same as the inlet value. In order to simplify the field initialisation etc. in 
OpenFOAM we can use what is called macro substitution. This allows us 
to specify a user­defined parameter that can be used in any part of the 
field initialisation or boundary condition implementation.

As  an  example of this,  figure  33  shows  the  0/include/initialConditions 


dictionary file with the principal values for the motorBike case.

Dr Tom Scanlon 2013 34


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 33 User­defined macro variables in the  
0/include/initialConditions dictionary

Note   that   the   variables  flowVelocity,  pressure,  turbulentKE, 


turbulentOmega  are user­defined variables (i.e. they are not OpenFOAM 
variables, but names made up by the user). Note, also that we have been 
consistent with the naming convention (second word capitalised). We can 
then   use   these   macro   variables   elsewhere   in   our   initialisation   and 
boundary condition specification.

We can also create dictionary files that can be called from inside other 
dictionaries,   e.g.   you   will   see   that   a   user­defined   dictionary   called 
frontBackUpperPatches has been created in the 0/include 'time' directory. 
This dictionary file is shown in figure 46:

Figure 34 User­defined dictionary 'frontBackUpperPatches'

Dr Tom Scanlon 2013 35


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

The   dictionary  frontBackUpperPatches  specifies   a   slip   (symmetry) 


boundary condition on  the 'upperWall'  and  'frontAndBack' patches. You 
will also see that another user­defined dictionary file called fixedInlet has 
also been created in the  0/include  directory. This file is shown in figure 
35:

Figure 35 User­defined dictionary 'fixedInlet'

The fixedInlet dictionary file sets a 'fixedValue' boundary condition on the 
patch called 'inlet' with a value of '$internalField'. As we will see later, the 
value   '$internalField'   will   be   used   to   refer   to   the   user­defined   values 
'flowVelocity', 'pressure' etc. contained in the  initialConditions  dictionary 
file of figure 33.

5.3 Initialisation of the turbulence fields

The   turbulence   fields   that   require   to   be   initialised   are   the   turbulence 


kinetic   energy   k,   the   specific   dissipation   rate,   'omega'   (  )   and   the 
turbulent viscosity 'nut' (  t ). These are initialised in the 0/k, 0/omega 
and 0/nut directories respectively. 

Take a moment to look at these files and note the use of the '#include' 
command  to  link   to  the  data   contained  in  the  user­defined  dictionaries 
initialConditions,  fixedInlet  and  frontBackUpperPatches.   The   initial 
internal field for k is uniform (i.e. constant) and has a value specified by 
'$turbulentKE', which was defined in the initialConditions directory.

Dr Tom Scanlon 2013 36


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

5.4 Velocity and pressure field initialisation

The velocity field is initialised in the 0/U file, as shown in figure 36:

Figure 36 Dictionary file 0/U

Note  that  the  'lowerWall'  patch  is   a  moving   boundary   at   20  m/s  (i.e.  a 
rolling road) – you can add the comment in blue to remind you of this 
(don't forget the preceding // for comments using C language).

Finally, the pressure field in initialised in the 0/p file, as shown in figure 
37.

Dr Tom Scanlon 2013 37


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 37 Dictionary file 0/p

5.6 Initial solution using the solver potentialFoam

We   can   quickly   simulate   the   flow   around   the   bike   using   the   solver 
potentialFoam. This solver provides a quick, steady­state, incompressible, 
inviscid (zero viscosity, zero shear) solution. Such a solution can then be 
used   as   the   initial   conditions   for   a   solution   including   viscous   effects 
(Navier­Stokes   solution)   using   the   solver  simpleFoam.   This   method   of 
solution   (i.e.  potentialFoam  first   followed   by  simpleFoam)   can   greatly 
improve the stability of a solution and is recommended for all external 
flow solutions using OpenFOAM.

The  potentialFoam  solution   can   also   provide   an   indication   of   whether 


problems exist with the mesh, particularly in terms of non­orthogonality 
(problem   cells   which   are   oddly   shaped   with   large   aspect   ratios).   Such 
problem   cells   can   cause   convergence   issues   during   a   solution   and   the 
OpenFOAM user has access to controls that can limit the influence of non­

Dr Tom Scanlon 2013 38


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

orthogonality   problems     The   level   of   non­orthogonal   correction   can   be 


modified by editing the system/fvSolutions.

Now,   execute  potentialFoam  with   the   additional   ­writep   option   (writes 


convergence data to screen), by typing:

potentialFoam ­writep

The solution converges fairly rapidly with full non­orthogonal correction 
as shown in figure 38:

Figure 38 Terminal window output showing rapid convergence of  
potentialFoam solution

So,   it   should   be   fine   for   us   to   run   a   Navier­Stokes   solution   with 


simpleFoam, using the potentialFoam results as our initial conditions.

5.7 Running the case with simpleFoam

Before we run the steady­state solver  simpleFoam  we will create a small 


file called 'monitorResiduals'. This file will contain some Linux commands 
to  allow  a  graphic   output   to  the  screen  using   the  open­source   graphics 
package Gnuplot. Type:

gedit monitorResiduals

The 'monitorResiduals' file should contain the commands shown in figure 
39 (copy and paste the commands below into 'monitorResiduals'):

Dr Tom Scanlon 2013 39


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

set logscale y 
set title "Residuals" 
set ylabel 'Residual' 
set xlabel 'Iteration' 
plot "< cat log | grep 'Solving for Ux' | cut ­d' ' ­f9 | tr ­d ','" title 'Ux' with lines,\ 
     "< cat log | grep 'Solving for Uy' | cut ­d' ' ­f9 | tr ­d ','" title 'Uy' with lines,\ 
     "< cat log | grep 'Solving for Uz' | cut ­d' ' ­f9 | tr ­d ','" title 'Uz' with lines,\ 
     "< cat log | grep 'Solving for omega' | cut ­d' ' ­f9 | tr ­d ','" title 'omega' with lines,\ 
     "< cat log | grep 'Solving for k' | cut ­d' ' ­f9 | tr ­d ','" title 'k' with lines,\ 
     "< cat log | grep 'Solving for p' | cut ­d' ' ­f9 | tr ­d ','" title 'p' with lines 
pause 5 
reread
Figure 39 Settings in the monitorResiduals file.

Save the monitorResiduals file.

Forces   acting   on   the   bike   and   rider   may   be   determined   using   an 
OpenFOAM  function   object.   Function   objects   are   pieces   of   coding, 
supplied as  part  of OpenFOAM,  to perform  specific tasks.  In this  case, 
function objects will be used to determine the normal and viscous forces 
acting on the bike object. Moments are also derived together with force 
coefficients such as lift and drag.

The   function   objects   are   activated   using   dictionaries   in   the  system 


directory. Edit the following dictionary by typing:

gedit system/forceCoeffs

Dr Tom Scanlon 2013 40


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 40 Settings in the system/forceCoeffs dictionary.

and set the “cumulative” option to be “no” as shown in Figure 40.

Note that the “bin data” option calculates the forces and forceCoefficients 
in a series of 20 bins, equi­spaced, along the length of the bike and rider. 
The total force and total force coefficient will be the sum of the results 
contained in the 20 bins.

To   calculate   the   forces   acting   on   the   bike   (as   opposed   to   the   force 
coefficents) we create a new forces dictionary by typing:

Dr Tom Scanlon 2013 41


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

cp system/forceCoeffs system/forces

Now edit the forces dictionary (gedit system/forces) such that it as shown 
in Figure 41:

Figure 41 Settings in the system/forces dictionary.

Finally, include the “forces” option by editing system/controlDict as shown 
in Figure 42:

Figure 42 Adding “forces” in system/controlDict.

Dr Tom Scanlon 2013 42


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

We can now solve the problem by running simpleFoam using the foamJob 
command, type:

foamJob simpleFoam &

Hitting return will take you back to the command line in your terminal 
window.   Now,   typing   the   Linux   command   'top'   should   show   that 
simpleFoam  is   running.   The   'top'   command   should   produce   a   terminal 
window output similar to that shown in figure 43:

Figure 43 Typical terminal window output from the 'top' command.

In figure 43 PID stands for 'Process ID'. Each process ID has a unique 
number – in this case, the PID 2209. The '%CPU' shows that simpleFoam 
is using 100% of the CPU compute power. We can also run on multiple 

CPUs   if   your   PC/laptop   has   more   than   one   CPU.   Such  parallel  
processing  is   commonly   used   in   OpenFOAM   as   a   means   to   speed­up 
calculation   times.   This   will   be   discussed   in   a   later   section.   Ctrl­C   will 
allow you to exit from the 'top' command.

Note: If, for any reason, you wish to halt a process, this can be achieved 
by using the command 'kill ­9 “PID number”', e.g. 'kill ­9 2209' or 'killall 
simpleFoam' would kill the simpleFoam job (obviously we don't want to do 
this in this instance).

Then, activate the gnuplot graphics of the residuals by typing:

gnuplot monitorResiduals

Dr Tom Scanlon 2013 43


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Once   more,   Ctrl­C   will   allow   you   to   exit   from   Gnuplot.   Your   Gnuplot 
window should show a similar residuals plot as shown in figure 44.

Figure 44 Gnuplot output of residuals

The output from the forces and forceCoefficients acting on the bike and 
rider   are   located   in   the  postProcessing/forces/0/  directory.   Take   a 
moment to analyse these forces and force coefficients.

5.8 Post­processing

We will post­process the CFD results using Paraview; type:

paraFoam

Select the latest time directory (i.e. '500') by clicking on the 'last frame' 
button,  and select 'Apply'.

Now,   bring   in   the  motorBike.obj  file   by   clicking   on   the   'open'   icon   and 
importing from the constant/triSurface directory. 

Dr Tom Scanlon 2013 44


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

The   forces   and   force   coefficients   are   stored   in   the   newly­created 


postProcessing  directory. Take a moment to analyse the data and recall 
that the total force is the sum over the 20 bins. To create the image shown 
in Figure 45 go into the  postProcessing/forces1/500  directory and create 
the following script file by typing:

gedit script_file_drag

Figure 45 Drag force predicted using 20 bins along the bike length.

Now copy and paste the following gnuplot commands into script_file_drag:

Dr Tom Scanlon 2013 45


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
reset 
set term postscript portrait enhanced mono "Times­Roman" 17 
set size 1.4, 0.7 
set xrange [0:2] 
set xlabel "Distance along bike (m)" 
set yrange [­4:16] 
set ylabel "Drag Force (N)" 
set output "drag.ps" 
set ytics ­4, 2, 16 
set mytics 2 
set mxtics 2 

set pointsize 2 

set style line 1 lt 1 lw 12 lc rgb "red" 

set key top right reverse box 
 
plot "drag.txt" using 1:2 w lines smooth csplines linestyle 1 title 'drag force (N)'
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

and save the script_file_drag file.

Now extract the x­direction (drag) force from the file force_bins into a new 
file called  drag.txt  such that the newly­created file drag.txt is similar to 
that shown below: 

Figure 46 Drag force data in file drag.txt .

Dr Tom Scanlon 2013 46


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Crop an image of the bike using paraFoam and using any image viewing 
software (e.g. libreOffice Impress or libreOffice Writer) to create the image 
shown in Figure 45.

5.8 Post­processing

We will post­process the CFD results using Paraview; type:

paraFoam

Select the latest time directory (i.e. '500') by clicking on the 'last frame' 
button,  and select 'Apply'.

Now, bring in the motorBike.obj file by clicking on the 'open' icon. 

The motorBike.obj file is located in the directory constant/triSurface. 

Now, create a 2D slice through the bike to allow us to view the pressure, 
velocity and turbulence fields. Use the slice icon  and   select   the   Y­
Normal direction as shown in figure 47:
      

Figure 47 Creating a slice in the Y­Normal direction

Dr Tom Scanlon 2013 47


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Select 'Apply' and un­select the 'Show Plane' option as shown in figure 48.

Figure 5
48 Un­selecting the Show Plane option.

Now,   select   the   velocity­magnitude   field   U   from 


the 'Solid­Colour' drop­down menu icon.

Select the colour legend icon and position the bike and legend such that 
they are as shown in figure 49:

Figure 49 Velocity magnitude contours on a 2D slice through the bike.

Contours for other fields such as turbulence kinetic energy,  k   m2 /s 2 , 
can be generated. Firstly, select the k field in the Volume Fields section of 
the Object Inspector, as shown in figure 50:

Dr Tom Scanlon 2013 48


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 50 Choosing Volume Fields for post­processing.

Now, either create a new 2D slice in the Y­Normal plane as previously, or 
use   the   previously­created   slice   to   display   the  k­contours,   as   shown   in 
figure 51:

Figure 51 Contours of turbulence kinetic energy, k.

The names of the contours may be changed, for easier identification, in the 
Pipeline   Browser   by   clicking   on   the   name   and   modifying,   as   shown   in 
figure 52:

Dr Tom Scanlon 2013 49


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 52 Changing the contour field names.

Velocity vectors can be created on any 2D slice using the glyph icon. 

The vector plot is shown in figure 53:

Figure 53 Velocity vectors on a 2D slice coloured by U­Magnitude.

Pressure   contours   on   the   bike   and   surroundings   may   be   created   by 


selecting   'surface'   in   the   drop­down   menu   and   zooming   into   the   box 
domain. The resulting pressure field is shown in figure 54:

Dr Tom Scanlon 2013 50


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 54 Pressure contours (Pa) on the bike and surroundings.

Streamlines may be created using the stream­tracer icon  .

In the Object Inspector, select the 'Z­axis' and 'Line Source'. Now, set the 
(x, y, z) end­points for the first line to be as shown in figure 55, i.e. (­0.6, 0,  
0)   and   (­0.6,   0,   2).   This   line   will   be   used   as   a   source   to   'release' 
streamlines.

Figure 55 Setting a line source for stream­tracers

Dr Tom Scanlon 2013 51


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Now,   select   'Apply'   and   un­select   the   'Show­line'   option.   Reduce   the 
'Resolution' to 30 streamlines. Then, colour the streamlines with velocity 
magnitude U.

Now, create solid stream 'tubes' using Filters/Alphabetical/Tube and set 
the following:

1. Number of Sides = 20 (or a setting of your own).
2. Radius = 0.01 (or a setting of your own).

and select  'Apply'. You  can modify the background  to a gradient  colour 


scale using the 'Edit View Options' as shown in figure 56:

Figure 56 Using 'Edit View Options' to set the background colour as a  
gradient.

The stream­tube plot should resemble figure 57:

Dr Tom Scanlon 2013 52


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 57 Stream­tube plot

Now, create other line sources, for example, at:

1. (­0.6, 0.05, 0) and (­0.6, 0.05, 2)
2. (­0.6, 0.1, 0) and (­0.6, 0.1, 2)

and perform the same stream­tube creation from these new line sources. 
The finished stream­tube plot is shown in figure 58:

Dr Tom Scanlon 2013 53


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 58 Completed stream­tube plot coloured by velocity magnitude.

Iso­surfaces can be created using the threshold  icon. Figure 59 shows 
an isosurface of turbulence kinetic energy, k, for  a   threshold   range 
between 6 and 35 m2 /s 2 .

Dr Tom Scanlon 2013 54


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 59 Iso­surfaces of k

Another  useful   feature   of  Paraview  is   the   ability   to   create   user­


defined   fields   using   the   Calculator  icon.   Figure   60   shows   how   we 
create   a   field   called   'non­dim  velocity   '   (i.e.   the   magnitude   of 
the velocity field U divided by the inlet velocity 20 m/s.

Figure 60 Calculator settings for the dimensionless velocity field.

Dr Tom Scanlon 2013 55


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 61 shows the 'non­dim velocity' field on a slice through the bike 
geometry.

Figure 61 'non­dim velocity' field on a slice through the bike.

Figure 62 Surface streamlines.

Dr Tom Scanlon 2013 56


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure   62   shows   a   plot   of   surface   streamlines   which   can   be   viewed   in 


paraFoam by opening the file:

postProcessing/sets/wallBoundedStreamLines/500/track0_U_UNear.vtk

Isocontours can be plotted using the contour icon as shown in Figure 63 
for isocontours of the turbulence kinetic energy k.

Figure 63 Isocontours of k.

In order to verify that we have reasonable values of  y+  for the turbulent 


wall functions to work correctly, we can use an OpenFOAM utility called 
'yPlusRAS'.   This   utility   calculates   the  y+  value   on   each   wall   surface, 
writes it to screen and creates new fields called 'y' and 'yPlus', where 'y' is 
the  wall   distance.   This   allows  the  user  to  plot   fields   of  y  and  yPlus  in 
Paraview.

Type:
yPlusRAS ­latestTime

Figure 64 shows the terminal screen output from the yPlusRAS command.

Dr Tom Scanlon 2013 57


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 64 Terminal screen output for yPlusRAS utility

The results show that, for the majority of the wall zones around the bike 
and rider, the y+ values are reasonable as they are of the order of ~300.

We can also sample fields such pressure, velocity etc on points, lines and 
surfaces   using   the   dictionary  sampleDict.  sampleDict  should   be   copied 
from the directory $FOAM_UTILITIES/postProcessing/sampling/sample 
into your system directory by typing:

cp $FOAM_UTILITIES/postProcessing/sampling/sample/sampleDict system

You can also copy this file using the 'Places' drop­down menu in the File 
Browser and copying from the OpenFOAM installation directory located in 
/opt as shown in figure 65:

Dr Tom Scanlon 2013 58


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 65 File browser showing location of sampleDict.

Edit   the  sampleDict  file   in   your  system  directory   and   set   the   the 
parameter  setFormat  to be  raw. Set  the fields to be sampled as  U  and 
comment   out   any   other   fields   not   desired.   Finally,   put   the   following 
parameters in the 'sets' section as shown in figure 66:

Dr Tom Scanlon 2013 59


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 66 sampleDict settings for a vertical line just behind the bike.

Comment out any other lines dealing with 'surfaces' inside the 'surfaces' 
brackets.

Figure 67 shows the location of the vertical line where the sampling of U 
will take place.

Figure 67 Location of sampling line at rear of bike.

Dr Tom Scanlon 2013 60


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Activate the sampling on the line by typing:

sample ­latestTime

This   will   create   a   new  .xy  file   located   in 


postProcessing/sets/500/lineBikeRear_U.xy.   Go   into   the   directory   by 
typing:

cd postProcessing/sets/500/

Edit the file  lineBikeRear_U.xy  and add the following lines to the top of 


the file as shown in figure 68:

Figure 68 Additional settings for plotting in gnuplot

These lines will allow us to plot the velocity magnitude, U, using gnuplot. 
Type:
gnuplot  lineBikeRear_U.xy

This   will   create   a   graphics   file   called  lineBikeRear.png  which   can   be 
included in any report. The .png file is shown in figure 69:

Note that any of the solved­for fields (U, p, k, user­defined variables using  
Calculator etc.) can be plotted.

Dr Tom Scanlon 2013 61


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 69 Axial velocity magnitude on sampling line using gnuplot

6.0 Parallel­processing

One   of   the   principal   attractive   features   of   OpenFOAM   is   its   unlimited 


parallel processing  capability. If you have a computer with more than 
one CPU you can decompose your problem into multiple zones, with each 
zone being processed by an individual CPU. Such an approach is called 
parallel processing and this can greatly speed­up compute times. 

The speed­up in the compute time can, in theory, be directly proportional 
to   the   number   of   processors   in   use,   i.e.   a   2   processor   solution   can 
potentially run twice as fast as   single processor solution. This is called 
scalability.   Ideally,   the   scalability   should   be   linear,   i.e.  n­processors 
should   lead   to   an  n­times   speed­up   factor.   However,   in   reality,   latency 
problems with computer hardware often limit the linear scalability. High 
Performance   Computer   (HPC)   systems   can   have   thousands   of   CPUs 
available   to   solve   compute­intensive   scientific   problems   e.g.   F1   car 
dynamics and weather predictions.

Dr Tom Scanlon 2013 62


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

To   use   the   parallel   solver,   firstly   create   a   new   directory   called 


motorBikeParallel  in   your  run/tutorials  directory.   Now,   copy   the 
directories 0.org, constant, system and the file monitorResiduals from your 
motorBike  directory into the new  motorBikeParallel  directory. Finally, in 
the  motorBikeParallel  directory,   copy   the  0.org  directory   to   a   directory 
called 0.

Now, edit the system/controlDict file and comment­out the section for the 
function objects as shown in figure 70:

Figure 70 Commented­out section in controlDict file.

The settings for the parallel feature are contained in the dictionary file 
system/decomposeParDict.   For   a   PC   with   a   dual­core   CPU,   i.e.   2 
processors, we may split our problem into 2 parts in the x­direction. These 
settings are shown in the decomposeParDict file of figure 71:

Dr Tom Scanlon 2013 63


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 71 decomposeParDict setting for a 2 CPU parallel run using the  
“scotch” decomposition method.

Now,   decompose   (i.e.   split)   the   computational   domain   into   2   parts   for 
parallel processing by typing:

decomposePar

You   will   now   see   that   two   new   directories   have   been   created,   namely, 
processor0 and processor1, as shown in figure 72:

Dr Tom Scanlon 2013 64


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 72 Directory structure after running decomposePar

As before, we will initially solve the  motorBike  problem using the solver 


potentialFoam ­ this time in parallel.

Now, we can run potentialFoam in parallel by typing:

mpirun ­np 2 potentialFoam ­parallel ­writep

Running paraFoam, alternately, from inside the processor0 and processor1 
directories   shows   how   the   computational   domain   has   been   split   for 
parallel processing. The split meshes are shown in figures 73 and 74:

Figure 73 Computational mesh for processor0

Dr Tom Scanlon 2013 65


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 74 Computational mesh for processor1

We can now run the simpleFoam solver in parallel, using the initial fields 
generated by potentialFoam as a starting point.

Firstly, uncomment the function objects in system/controlDict.

Now, run the simpleFoam solver in parallel, by typing:

mpirun ­np 2 simpleFoam ­parallel > log &

Typing the command:
top
writes the active processes to screen and shows that simpleFoam is being 
run on 2 processors, with each CPU running, more or less, at 100%, as 
shown in figure 75:

Dr Tom Scanlon 2013 66


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

Figure 75 Output from 'top' command showing 2 processors running  
simpleFoam in parallel.

Ctrl­C will take you out of the 'top' command.

Now, run gnuplot to view the residuals by typing:

gnuplot monitorResiduals

You   can   analyse   the   speed­up   time   by   comparing   the  ExecutionTime 


between   iterations   for   the   serial  motorBike  case   and   the     parallel 
motorBikeParallel case, by typing the command:

tail ­f log

alternately, in the motorBike and motorBikeParallel directories.

Note that the results in the 'time' directories (100, 200 etc) are written in 
each of the  processor0 and processor1 directories.

Once   the   solution   has   completed,   the   separate   results   in   each   of   the 
processor0  and  processor1  directories may be combined using the utility 
reconstructPar.

To activate reconstructPar type:

reconstructPar ­latestTime

Dr Tom Scanlon 2013 67


External Aerodynamics using OpenFOAM v2.2 with Ubuntu Linux v12.04 LTS 32-bit

This will merge the results for the 2 processors at the last time output, i.e. 
500.   The   results   are   contained   in   a   new  500  directory   within   the 
motorBikeParallel directory. 

The results may then be processed using paraFoam in the usual manner.

Dr Tom Scanlon 2013 68

You might also like