Tutorial de OpenFOAM Con Ubuntu Linux 12.04
Tutorial de OpenFOAM Con Ubuntu Linux 12.04
04 LTS 32-bit
External Aerodynamics
Using OpenFOAM
Dr. Tom Scanlon
July 2013
1. Introduction
OpenFOAM (Open Field Operation and Manipulation) is an opensource
set of computationallyefficient, 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
32bit (www.ubuntu.com). This means that it is possible to setup and run
highend, 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” online. You will be given a memory stick with
Ubuntu/OpenFOAM preinstalled. You will boot into Ubuntu from
the memory stick and run and save your OpenFOAM cases from the
stick. When booting into the memorystick 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 sidebyside with your normal Windows OS. You will be able to
select Ubuntu Linux or your original Windows OS when you turnon your
PC/laptop.
Start/Programs/Accessories/System Tools/System Information.
Now, download the appropriate version of Ubuntu v.12.04 (32bit or 64
bit) from the Ubuntu website (www.ubuntu.com) and burn it to CD to
create an installation CD. The instructions on how to do this are on the
Ubuntu website.
You now need to change the boot sequence of your PC such that the
CD/DVD drive is accessed before the harddisk drive (HDD). To change
the bootsequence, 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 setup options). Search the setup options to move the CD/DVD
drive to be the 1st in the bootsequence.
The 'sidebyside' installation option allows you to select either Windows
or Linux when your PC is switched on. On rebooting 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 online). This additional software is
necessary to run Linux/OpenFOAM correctly. The software is located in
online '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 online, 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).
3. Running OpenFOAM v2.2.
Assuming you are running OpenFOAM from either the memorystick or
from a correctlyinstalled 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/tom2.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 lefthand button and move the cursor into
the terminal window. Now, click the middlebutton 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’.
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/tom2.2.0/run/tutorials/cavity
The ‘cavity’ case describes transient, laminar flow in a liddriven cavity, as
shown in figure 1:
Figure 1 Sketch of the liddriven cavity tutorial case.
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.
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 steadystate conditions. Even when
using steadystate 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.
The timestep 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 preprocessor (i.e. format the mesh), type:
blockMesh
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 solvedfor fields of pressure (p) and velocity (U) we
will use the opensource 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 dropdown menu (figure 3), choose the velocity field, U:
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.
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'.
Figure 6 Velocity field using 'Blue to Red' colour legend.
Unselect the central cross by clicking on the 'showcenter'
button
Clicking in the gray area and using the leftmouse button allows you to
rotate, the middlebutton to pan and the rightbutton 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.
Figure 7 Contours and glyphs (velocity vectors) on the same plot.
Figure 8 Creating a znormal slice.
Click on 'Apply' and then unselect 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.
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.
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:
The problem is steadystate and the turbulence model will be one of the
ReynoldsAveraged Stress models (called 'RAS' models in OpenFOAM)
with wallfunctions to determine the shear stresses at solid surfaces. The
turbulence model used in this problem is the komegaSST model.
4.2 Meshing considerations
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.
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.
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 leftbutton of the mouse. In this way,
commonlyused icons can be kept at hand, as shown in figure 12
calculator
terminal
screenshot
Figure 12 Additional icons in the task bar.
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:
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
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 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 bluffbody (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 (nonstreamlined 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 bluffbody
external flows
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 xdirection extent of the bounding box is from
0.291665 m to 1.75115 m, the ydirection extent from 0.350289 m to
0.332267 m and the zdirection extent from 4.232e05 m to 1.35156 m.
The positive xdirection is the flow direction, the ydirection is normal to
the flow and the zdirection is the height.
Figure 17 shows the motorBike with its bounding box.
Figure 17 motorBike and its bounding box
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 nonediting 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 xdirection and 8 cells in y and zdirections. 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 cuboidshaped 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:
blockMesh
We have now created our background mesh. You can view the mesh and
the position of the bike in paraFoam, type:
paraFoam
In paraFoam select 'Apply' and view the background mesh using the
'Wireframe' option as shown in figure 18:
Figure 18 Background mesh
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.
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 reopen paraFoam, use 'Load/State'.
Now, exit paraFoam and return to the terminal window in your motorBike
directory.
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 bluffbody (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.
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 .
surfaceFeatureExtract
gedit system/snappyHexMeshDict &
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 xdirection 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 zdirections.
4.4.3 Creating a mesh
Figure 23 The intermediate castellated mesh
Now, edit the snappyHexMeshDict file, type
gedit sy[hit tab key]/sna[hit tab key]
(i.e. gedit system/snappyHexMeshDict)
Figure 24 Edge feature refinement.
Note the section on 'refinementSurfaces' as shown in figure 25:
Figure 25 snappyHexMeshDict setting for level of refinement.
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
< 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
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':
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.
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:
Figure 29 Bottom of log.snappy file
CtrlC 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:
Figure 30 Final mesh for motorBike case.
5. Solving the problem
Firstly, we go into the tutorials directory by typing, in a terminal window:
run
followed by:
cd tutorials/motorBike
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.
The CFD solver we will be using is called simpleFoam and simpleFoam is
hardcoded 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
5.1 Flowfield 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:
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:
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:
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 userdefined parameter that can be used in any part of the
field initialisation or boundary condition implementation.
Figure 33 Userdefined macro variables in the
0/include/initialConditions dictionary
We can also create dictionary files that can be called from inside other
dictionaries, e.g. you will see that a userdefined dictionary called
frontBackUpperPatches has been created in the 0/include 'time' directory.
This dictionary file is shown in figure 46:
Figure 34 Userdefined dictionary 'frontBackUpperPatches'
Figure 35 Userdefined 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 userdefined values
'flowVelocity', 'pressure' etc. contained in the initialConditions dictionary
file of figure 33.
5.3 Initialisation of the turbulence fields
Take a moment to look at these files and note the use of the '#include'
command to link to the data contained in the userdefined 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.
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.
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, steadystate, incompressible,
inviscid (zero viscosity, zero shear) solution. Such a solution can then be
used as the initial conditions for a solution including viscous effects
(NavierStokes 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.
potentialFoam writep
The solution converges fairly rapidly with full nonorthogonal correction
as shown in figure 38:
Figure 38 Terminal window output showing rapid convergence of
potentialFoam solution
5.7 Running the case with simpleFoam
gedit monitorResiduals
The 'monitorResiduals' file should contain the commands shown in figure
39 (copy and paste the commands below into 'monitorResiduals'):
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.
gedit system/forceCoeffs
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, equispaced, 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:
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.
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 speedup
calculation times. This will be discussed in a later section. CtrlC 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
Once more, CtrlC 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 Postprocessing
We will postprocess 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.
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:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
reset
set term postscript portrait enhanced mono "TimesRoman" 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 xdirection (drag) force from the file force_bins into a new
file called drag.txt such that the newlycreated file drag.txt is similar to
that shown below:
Figure 46 Drag force data in file drag.txt .
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 Postprocessing
We will postprocess 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 YNormal direction
Select 'Apply' and unselect the 'Show Plane' option as shown in figure 48.
Figure 5
48 Unselecting the Show Plane option.
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:
Figure 50 Choosing Volume Fields for postprocessing.
Now, either create a new 2D slice in the YNormal plane as previously, or
use the previouslycreated slice to display the kcontours, 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:
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 UMagnitude.
Figure 54 Pressure contours (Pa) on the bike and surroundings.
Streamlines may be created using the streamtracer icon .
In the Object Inspector, select the 'Zaxis' and 'Line Source'. Now, set the
(x, y, z) endpoints 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 streamtracers
Now, select 'Apply' and unselect the 'Showline' 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).
Figure 56 Using 'Edit View Options' to set the background colour as a
gradient.
The streamtube plot should resemble figure 57:
Figure 57 Streamtube 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 streamtube creation from these new line sources.
The finished streamtube plot is shown in figure 58:
Figure 58 Completed streamtube plot coloured by velocity magnitude.
Isosurfaces 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 .
Figure 59 Isosurfaces of k
Figure 60 Calculator settings for the dimensionless velocity field.
Figure 61 shows the 'nondim velocity' field on a slice through the bike
geometry.
Figure 61 'nondim velocity' field on a slice through the bike.
Figure 62 Surface streamlines.
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.
Type:
yPlusRAS latestTime
Figure 64 shows the terminal screen output from the yPlusRAS command.
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' dropdown menu in the File
Browser and copying from the OpenFOAM installation directory located in
/opt as shown in figure 65:
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:
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.
Activate the sampling on the line by typing:
sample latestTime
cd postProcessing/sets/500/
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 solvedfor fields (U, p, k, userdefined variables using
Calculator etc.) can be plotted.
Figure 69 Axial velocity magnitude on sampling line using gnuplot
6.0 Parallelprocessing
The speedup 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. nprocessors
should lead to an ntimes speedup 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 computeintensive scientific problems e.g. F1 car
dynamics and weather predictions.
Now, edit the system/controlDict file and commentout the section for the
function objects as shown in figure 70:
Figure 70 Commentedout section in controlDict file.
The settings for the parallel feature are contained in the dictionary file
system/decomposeParDict. For a PC with a dualcore CPU, i.e. 2
processors, we may split our problem into 2 parts in the xdirection. These
settings are shown in the decomposeParDict file of figure 71:
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:
Figure 72 Directory structure after running decomposePar
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
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:
Figure 75 Output from 'top' command showing 2 processors running
simpleFoam in parallel.
CtrlC will take you out of the 'top' command.
Now, run gnuplot to view the residuals by typing:
gnuplot monitorResiduals
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
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.