160199
160199
ij
Kronecker delta -
Kolmogorov length scale [m]
Turbulent energy dissipation rate [m
2
/s
3
]
Dynamic viscosity [Pa s]
t
(v
i
) +
x
j
(v
i
v
j
) =
p
v
i
+
x
j
_
_
v
i
x
j
+
u
j
x
i
__
+ S
M
(2.1.1)
The momentum equations (one equation in each coordinate direction) together with the
continuity equation (eq. 2.1.2), energy equation (eq. 2.1.3) and an equation of state (the
perfect gas law has been used in this thesis, eq. 2.1.4)can be seen as the governing equations
of compressible uid dynamics.
t
(u
i
) +
x
j
= 0 (2.1.2)
(i)
t
+
x
j
(iv
j
) = p
v
j
x
j
+
x
j
_
k
T
x
i
_
+ + S
i
(2.1.3)
p = RT (2.1.4)
If the ow is incompressible and temperature independent only the Navier-Stokes and continuity
equation are needed. In this thesis, both incompressible and compressible ows are used, since
the ow speeds can be higher than Mach 0.3 in thinner sections.
A ow is either laminar or turbulent, with the Reynolds number being the deciding factor.
When the Reynolds number of a ow is above a certain critical value the ow becomes turbulent.
4 , Applied mechanics, Masters Thesis 2012:13
2.1. FLUID MECHANICS CHAPTER 2. THEORY
2.1.2 Turbulence
In laminar ow the adjacent layers slide past each other in an orderly fashion. Turbulent ow
on the other hand is random and chaotic in its nature. There are six main characteristics for
turbulent ow:
Irregular
Diusive
Has a relatively high Reynolds number
Three-dimensional
Dissipative
Property of the ow (i.e. not the uid)
In turbulence unsteady vortices called eddies appear. The largest eddies extract energy from
the mean ow, called turbulent kinetic energy. This energy is then transferred to smaller and
smaller eddies until it reaches the smallest ones where it is dissipated into heat. This process
of energy transfer is called the cascade process. The scale of the smallest eddies are called
the Kolmogorov scales and where dened in 1941 by A.N. Kolmogorov [2]. There are three
Kolmogorov scales: length, velocity and time and they are dened as :
=
_
_1
4
(2.1.5)
=
_
_1
2
(2.1.6)
= ()
1
4
(2.1.7)
In theory one could resolve all of the turbulent scales. The problem with this is that the
Kolmogorov scales are usually very small which means that this would require a tremendous
amount of computing power and memory. Therefore resolving all the turbulent scales is only an
option (with todays computers) for simple problems with low Reynolds numbers. To compute
more realistic problems some kind of turbulence modelling has to be used.
Reynolds Averaged Navier-Stokes
The Reynolds averaged Navier-Stokes (RANS) equations are time-averaged versions of the
original equations. They are obtained by introducing the Reynolds decomposition of the
pressure and velocity and then time-averaging the equations. The Reynolds decomposition
consists of dividing the instantaneous pressure and velocity into one time-averaged and one
uctuating part, i.e.
u = U + u
(2.1.8)
, Applied mechanics, Masters Thesis 2012:13 5
2.1. FLUID MECHANICS CHAPTER 2. THEORY
p = P + p
(2.1.9)
After insertion of the decomposition and time-averaging of the Navier-Stokes equations one
additional term appears, u
i
u
j
. This term is called the Reynolds stress tensor and means
additional unknowns have been introduced. Since the number of equations has not increased,
this creates a closure problem. To solve this the Reynolds stress tensor can be modelled using
an eddy viscosity and the velocity gradients. This is called the Boussinesq assumption (Eq.
2.1.10) and the basic idea behind it is to model the small-scale eddies with a viscosity term.
u
i
u
j
=
t
_
u
i
x
j
+
u
j
x
i
2
3
u
k
x
k
ij
_
2
3
k
ij
(2.1.10)
ij
is the Kronecker delta and k is the turbulent kinetic energy dened as
k =
1
2
_
u
2
+ v
2
+ w
2
_
(2.1.11)
There are plenty of models to describe the turbulent quantities including one-equation models,
two-equation models and algebraic models.
Realizable k model
To compute the turbulent quantities the realizable k model is normally used at VCC, and
as such also in this thesis. The realizable k model is a two-equation model by Jones and
Launder [3] with one equation for k and one for . The turbulent dissipation rate is a small
scale variable but it is here used as the dissipation rate for large eddies. This is possible because
the dissipation rate of the small eddies matches the rate at which the large eddies extract
energy from the mean ow through the energy spectrum [4]. The two additional transport
equations for k and are dened in equation 2.1.12 and 2.1.13 respectively.
t
(k) +
x
i
(ku
i
) =
x
j
__
+
t
k
_
k
x
j
_
+ P (2.1.12)
t
() +
x
j
(u
j
) =
x
j
__
+
t
_
x
j
_
+ C
1
S C
2
2
k +
+ C
1
k
(2.1.13)
where
C
1
= max
_
0.43,
+5
_
, = S
k
, S =
_
2S
ij
S
ij
,
t
= C
k
2
and C
=
1
A
0
+A
s
kU
= 0.09, A
0
= 4, C
2
= 1.9,
k
= 1 and
= 1.2. For further details of the realizable k model, please see Jones and
Launder [3].
6 , Applied mechanics, Masters Thesis 2012:13
CHAPTER 3. METHODOLOGY
3 Methodology
This chapter contains a brief description of the softwares used, a description of how the air
lter system simulations were setup and an introduction of the adjoint method.
3.1 Softwares used
3.1.1 OpenFOAM version 2.1.0
OpenFOAM is in this thesis being evaluated as a CFD solver for air induction systems, but
it is more than that. The core of OpenFOAM is a C++ toolbox that enables the creation
of customised numerical solvers. The distribution also contains a wide selection of solvers
designed to solve specic problems. For more information on OpenFOAM and how to set up a
case, please see appendix A.
3.1.2 ANSYS Fluent 14.0
The currently used CFD software for ow calculations in the air induction system group is the
commercial package Fluent. It contains a variety of physical modelling capabilities to model
most kinds of ow situations encountered in engineering. Fluent is the software against which
the OpenFOAM calculations in this thesis have been compared.
3.1.3 ANSA version 13.1.5
ANSA is the pre-processing tool of choice for meshing the air induction systems. Models are
created in the CAD system CATIA V5 and imported into ANSA for meshing. One of the
great advantages of ANSA for this thesis project is that it can export meshes directly into
OpenFOAM format. This means that it generates the le structure of an OpenFOAM case
directly. It is also possible to set some solver settings in ANSA, although the selection of
solvers isnt complete.
3.1.4 ParaView version 3.4.0
This is the main post-processing software distributed with OpenFOAM. It is an open-source
data analysis and visualisation tool and it can either be invoked by using paraFoam wrapper
script or by converting the data to VTK format and open with ParaView. Data processing
can be done either interactively in a 3D environment or using command line batch processing.
, Applied mechanics, Masters Thesis 2012:13 7
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
3.1.5 CATIA V5
CATIA is a CAD/CAE/CAM system developed by Dassault Systemes. It is widely used in
the automotive and aerospace industries and is also the primary CAD system used at VCC. In
this thesis it has been used to create the models of the air induction systems simulated.
3.1.6 swak4foam version 6.3.7
Swak4foam stands for Swiss Army Knife for Foam and is a set of libraries and utilities to
perform various kinds of data manipulation and representation. It can be used to set complicated
boundary conditions depending on expressions. In this thesis the part of swak4foam that
contains extended functionObjects (used to perform calculations after each iteration) has been
used to compute total pressure and uniformity index at internal sections.
3.2 Air lter system simulations
The currently performed air lter simulations are run as steady state simulations in several
stages. This is because it can be dicult to reach convergence if all of the options such as
second order accurate numerical schemes were to be used from the start of the simulation. As
stated in section 1.3 this thesis is not about improving existing simulation methods, but they
will be used as a starting point when setting up the OpenFOAM simulations. Fluent has been
used for a relatively long time at the department and boundary conditions etc. are tweaked
to suit this software package, which is why all options can not be directly used with another
software package.
3.2.1 Simulation setup
Geometry and mesh generation
The models used are created in the CAD system CATIA V5 and the computational mesh is
created in ANSA. The geometry is split up into separate volumes with interior surfaces in
between. This is to simplify volume meshing and also to get interior surfaces which can be
used for evaluation. Also, the air lter itself must be a separate cellZone for the solver to know
where to apply porosity settings (see section 3.2.1). The volume mesh consists of tetrahedral
elements. To increase accuracy in the boundary layers 2 prism layers of ca 1 mm thickness each
are used along the walls of the ducts. A part of the mesh with layers are shown in gure 3.2.1.
8 , Applied mechanics, Masters Thesis 2012:13
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
Figure 3.2.1: Mesh with prism layers along walls
No prism layers are created in the inlet spheres, the air lter box or in the volume around
the AMM (usually located after the air lter box). To take entrance losses of the air intake
into account a half sphere is added at every inlet. At the exit of the clean air duct, a volume
extrusion is added to reduce the outlet boundary eects. Figure 3.2.2 shows a model with and
without the added bulbs and outlet extrusion.
, Applied mechanics, Masters Thesis 2012:13 9
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
Figure 3.2.2: Example model with and without added spheres at inlets and extrusion at outlet
ANSA has native OpenFOAM support and by using this the mesh was directly exported into
OpenFOAM format. The version of ANSA used (13.1.5) does not completely support the le
structure and syntax used in the current OpenFOAM version (2.1.0). This necessitated some
manual editing of solver settings and boundary conditions. An alternative way would have
been to export the mesh in Fluent format and then convert it with the OpenFOAM utility
uentMeshToFoam. After the mesh was exported to OpenFOAM the utility checkMesh was
used to check the mesh for skewness and other mesh quality parameters.
Choice of solver
OpenFOAM comes with a long list of dierent solvers written for dierent applications. The
requirements on the solver for the air lter system simulations are:
Steady state
Compressible
Able to handle porous zones
These requirements made it easy to choose a solver, since only the rhoPorousMRFSimpleFoam
solver handles all of these demands. It uses the SIMPLE algorithm for pressure-velocity
coupling, RANS turbulence modelling (see section 2.1.2) and handles both implicit and explicit
porosity treatment. The solver also handles MRF, Multiple Reference Frames, which is used
when a part of the mesh needs to move in relation to the rest (not used in this thesis).
Boundary conditions
The OpenFOAM boundary conditions found to work best for the air lter systems are presented
in table 3.2.1. The inletOutlet boundaries are set to zero to prevent back ow. If the ow is in
the forward direction they act as homogenous Neumann boundaries.
10 , Applied mechanics, Masters Thesis 2012:13
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
Table 3.2.1: OpenFOAM boundary conditions used for the air lter systems
Quantity Inlet(s) Outlet Walls
U owRateInletVelocity inletOutlet No-slip
p zeroGradient xedValue zeroGradient
k turbulentIntensityKineticE-
nergyInlet
inletOutlet compressible::kqRWallFunction
epsilon compressible::turbulentMix-
ingLengthDissipation-
RateInlet
inletOutlet compressible::epsilonWallFunction
T xedValue inletOutlet zeroGradient
mut calculated calculated mutkRoughWallFunction
alphat calculated calculated alphatWallFunction
Setting the owRateInletVelocity with a negative magnitude at the outlet (resulting in an outlet
boundary) has also been tested. This approach would be preferable but produces signicantly
less stable simulations. Since setting the ow rate at the outlet doesnt produce stable results,
cases with several inlets has to have the mass ows for the respective inlets determined. This
has been done by using an incompressible solver with which it has been possible to run a
simulation with an outlet having a negative magnitude ow rate. This simulation has been
run for 500 iterations after which reasonable convergence was reached. Afterwards the mass
ows of the dierent inlets have been noted and used for the real (compressible) simulation
with the ow rates set at the inlets. There are several reasons why it would be preferable to
set the ow rate as a negative value on the outlet. The major one is that this is the way the
ow is initiated when the air induction systems are used in conjunction with an engine. It also
gives a better comparison with the experimental results since the ow is created by sucking
air through the system. It would also make the extra step of nding the division of the ow
between the inlets unnecessary.
Solver settings and numerical schemes
As a start the corresponding settings as used in the Fluent computational procedure were
tested. These did not provide enough numerical stability in OpenFOAM and a big part of the
project has been nding settings that do. These are presented in section 4.1.
Air lter
The air lter is basically a wrinkled paper designed to lter the air while at the same time
being cost-eective with long service intervals. To model the resistances in dierent coordinate
directions the lter is modelled as a porous material. This is done using the Darcy-Forcheimer
equation which means that a source term is added to the Navier-Stokes equations and the
time derivative is attenuated (although this is irrelevant here because the air lter systems
are simulated in a steady-state). Equation 3.2.1 together with source term 3.2.2 is the Darcy-
Forchheimer equation where D
ij
and F
ij
species the viscous and inertial resistances in the
, Applied mechanics, Masters Thesis 2012:13 11
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
dierent coordinate directions.
t
(v
i
) + v
j
x
j
(v
i
) =
p
x
i
+
ij
x
j
+ S
i
(3.2.1)
The source term S
i
is dened as:
S
i
=
_
D
ij
+
1
2
|u
jj
|F
ij
_
v
i
(3.2.2)
In rhoPorousMRFSimpleFoam the porous zone(s) is dened in the dictionary porousZones. It
contains the name of the cellZone having the porous properties, the values of the diagonals of
D
ij
and F
ij
as vectors and two vectors dening the coordinate system of the porous zone. The
resistance values used are obtained from previous experiments at VCC. All of the simulations
have been run with implicit porosity treatment since it increases numerical stability. For more
information about the porous media implementation in OpenFOAM, please see [7].
3.2.2 Comparison with ANSYS Fluent
Since the equations upon which CFD rely are just models of reality, validation is very important.
Validation means to compare the results of a simulation to experimental results and is the
most important step in securing that the results obtained are of any use. In this thesis the
OpenFOAM calculations are also compared against Fluent calculations as a rst step. This is
since Fluent has been used for a long time at the department and the results are known to
usually be reasonably close to experimental data. The test cases were run with the following
values for the boundary conditions:
Table 3.2.2: Boundary conditions for test cases
Boundary condition Value
Velocity on inlet Volvo reference mass ow rate
Pressure on outlet Ambient pressure
Temperature on inlet Ambient temperature
Mut roughness 0 roughness height (i.e. no roughness)
The two test cases used will be evaluated using a number of dierent measures that are of
interest to VCC. These are presented below.
Streamlines coloured by velocity. Streamlines are a good way to get an idea of how the
ow actually looks. If there are any unphysical eects or strange ow behaviours they can be
seen here. The streamlines also show if the ow is, for example, swirling.
Pressure drop at all sections. The most important parameter to measure as an increased
pressure drop will translate into a less ecient engine. The pressure drop is measured in
relation to the total pressure at the inlet. The average on each section is taken with respect to
mass weighting because the ow is compressible, and hence the density can dier on dierent
12 , Applied mechanics, Masters Thesis 2012:13
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
cell faces. The measurement sections are shown in Figure 3.2.3 and 3.2.4 for the two test cases
respectively.
Uniformity index. The uniformity index is an industry standard measure of how uniform
the velocity distribution of the ow is at a particular section. It is dened by Equation 3.2.3:
= 1
_
A
_
(u u)
2
2Au
dA (3.2.3)
The sections where ow uniformity is of special interest for the air lter systems are:
The surface of the air lter. A uniform ow here is important for lter utilisation.
In front of the air mass meter. Important with a high ow uniformity to ensure correct
signal from the sensor.
The outlet, for even distribution to the engine.
Visual representation of ow distribution at sections. A visual representation of the
ow distribution is also shown to get an idea of where the possibly uneven velocities are located
on the surface.
To extract total pressure and uniformity index on the internal sections in OpenFOAM the
swak4foam extension has been used. As described in section 3.1.6 swak4foam is among other
things an extension to the functionObjects in OpenFOAM. The functionObjects execute a piece
of code on each iteration/time-step and as such the total pressure and uniformity index can be
read at every iteration. To produce images with data from the internal surfaces (faceZones
in OpenFOAM) the only way known to the author is to use Paraview with the paraFoam
wrapper, which is supplied with OpenFOAM. Data not belonging to the internal surfaces can
be converted to a range of formats but Paraview has been used throughout for the OpenFOAM
results.
3.2.3 Test case one: I5D P1
This is the air induction system found in Volvos small car platform (P1) in conjunction with
the 5 cylinder diesel engine. It has two inlets on the dirty side (before the ow passes the lter)
and one outlet. Figure 3.2.3 shows the model with the measurement sections highlighted in
black.
The mesh consists of approximately 6.8 million cells which makes it one of the larger used at
VCC for this type of simulation.
, Applied mechanics, Masters Thesis 2012:13 13
3.2. AIR FILTER SYSTEM SIMULATIONS CHAPTER 3. METHODOLOGY
Figure 3.2.3: I5D P1 model with highlighted measurement sections
3.2.4 Test case two: I5D EuCD
The model used here is that of the air induction system for Volvos 5 cylinder diesel engine in
the EuCD Platform (models V70, S80). Figure 3.2.4 shows the model with the measurement
sections highlighted in black.
The number of cells in this model totals a little over 6 million. The main reason for it being
smaller is that the geometry is physically smaller. It has two inlets in the same way as case
one, but one of them is only a hole in the lter box and the other one is connected with a
shorter duct.
14 , Applied mechanics, Masters Thesis 2012:13
3.3. TOPOLOGY OPTIMISATION CHAPTER 3. METHODOLOGY
Figure 3.2.4: I5D EuCD model with highlighted measurement sections
3.2.5 Validation with experiments
It is not enough to compare to another CFD software, because either could be the more
accurate one. Therefore the pressure drops obtained from the two CFD softwares are compared
to measurements from the VCC ow rig. The rig measures the total pressure drop from inlet
to outlet. Hence it is only one value to compare against, but it still serves as an indication on
which software is closest to the real values. Figure 3.2.5 shows the setup of the ow rig with
the system pertaining to the P1 platform in place.
3.3 Topology optimisation
As mentioned in section 1.1 the single biggest constraint in the design of the air induction
systems is packaging. The topologies of the air induction systems need to be optimised mainly
for pressure loss and for uniformity at certain sections. There are a number of optimisation
methods such as using a DOE to test how variations in certain parameters aect the result
(basically trial and error), gradient based methods or by just using the experience of the
designer.
, Applied mechanics, Masters Thesis 2012:13 15
3.3. TOPOLOGY OPTIMISATION CHAPTER 3. METHODOLOGY
Figure 3.2.5: I5D P1 air induction system mounted in the ow rig
A previous thesis work [8] has shown how to use the optimisation software modeFrontier in the
optimisation process for air induction systems. ModeFrontier uses a DOE to test how variations
in parameters aect the variables optimised against. Even though a dierent CFD-solver was
used in [8] (STAR-CCM+), the workow would be the same with OpenFOAM. And since
OpenFOAM is command-line based it is very easy to integrate with modeFrontier. Instead of
using a DOE-approach to optimisation this thesis has focused on using the adjoint method.
3.3.1 Adjoint method
The adjoint method is a gradient based method. It has been widely used for some time in the
aerospace industry, but has fairly recently been introduced within the automotive industry.
It is a method which evaluates the derivative of a function I(w, F) with respect to F even if
I(w, F) only depends on F indirectly via an intermediate variable w [9]. The derivation of the
basic equations below follow [9] and [10].
Starting with a scalar function I
I = I(w, F) (3.3.1)
where w are ow eld variables and F are grid variables.
16 , Applied mechanics, Masters Thesis 2012:13
3.3. TOPOLOGY OPTIMISATION CHAPTER 3. METHODOLOGY
Dierentiate the cost function once to obtain:
I =
I
w
w +
I
F
F (3.3.2)
The ow eld is:
R(w, F) = 0 (3.3.3)
And the rst perturbation:
R =
R
w
w +
R
F
F (3.3.4)
Since R = 0 [9] it can be multiplied with an arbitrary term . Subtracting this from 3.3.2
gives:
I =
I
w
w +
I
F
F
_
R
w
w +
R
F
F
_
(3.3.5)
If is chosen so that:
R
w
=
I
w
(3.3.6)
The derivative of I(w, F) may be calculated without taking the derivative with respect to w as:
I =
_
I
F
R
F
_
F (3.3.7)
Equation 3.3.6 is called the adjoint equation and this together with 3.3.7 is called the discrete
adjoint method. The adjoint method calculates the derivative of the cost function with respect
to grid variables, but doesnt model the variables. In other words, it models the sensitivity of
the cost function to some chosen variables. The cost function can be chosen so that it reects
the quantity that is optimised against. The computational cost doesnt depend on the number
of objectives solved for, since it just means incorporating them into the cost function.
3.3.2 Adjoint method and OpenFOAM
There is already one solver distributed with OpenFOAM utilising the adjoint method called
adjointShapeOptimizationFoam. It is a steady-state solver for incompressible turbulent ows.
It optimises a geometry for low pressure loss by blocking cells where the sensitivity to pressure
loss is high. The blocking is achieved by adding an individual porosity to each cell via Darcys
law (see section 3.2.1). The optimised topology can then be extracted as the boundary between
, Applied mechanics, Masters Thesis 2012:13 17
3.3. TOPOLOGY OPTIMISATION CHAPTER 3. METHODOLOGY
cells with porous blockage and no blockage. The existing solver optimises the whole domain it
is given, and as such has no means of treating some parts as frozen.
To test the solver a ctitious design space was used. As a baseline design a constant radius
pipe was inserted. At the thinnest section of the design space the pipe was removed and a
volume utilising the maximum available packaging space was inserted. In this box the adjoint
solver can create blockages to optimise the geometry against pressure loss. The resulting
geometry is showed in gure 3.3.1. A mass ow was set at the inlet and a static pressure at
the outlet. The adjoint velocity and pressure used the required adjoint boundary conditions
adjointOutletVelocity and adjointOutletPressure on the outlet. Also, the adjoint velocity was
set to a negative value at the inlet. The approach is to compare the results before and after the
adjoint solver has blocked some of the cells in the design space and see if the pressure losses
have been lowered.
Figure 3.3.1: Geometry used when testing the OpenFOAM adjoint solver
18 , Applied mechanics, Masters Thesis 2012:13
CHAPTER 4. RESULTS
4 Results
This chapter starts out with presenting the OpenFOAM settings found to work best for the air
induction system simulations. The next part contains results from the comparison between
Fluent and OpenFOAM and also to experimental values. A small study of the parallel scaling
in OpenFOAM is also presented and last there is a small evaluation of the OpenFOAM adjoint
solver.
4.1 OpenFOAM settings
The rst approach was to try and mimic the computational procedure for Fluent, and to
achieve this a Python script was developed which performs the switch from incompressible
to compressible simulation and also changed discretization schemes at certain intervals. In
OpenFOAM it is a little bit more involved to automatically change from incompressible to
compressible settings. The solver has to be changed, the dissipation and turbulent kinetic
energy k needs dierent wall functions and the pressure and ux phi have dierent dimensions.
This approach was abandoned mainly because of stability problems and also because it was
unnecessarily complicated for day-to-day usage. Although not used for these simulations the
script is attached in Appendix C as an alternative way to initialise the simulations. Instead of
the incompressible to compressible switch a dierent approach for achieving a stable solution
was used. The air induction system simulations are very sensitive to numerical settings.
None of the two tested models could be run with all discretization schemes set to second
order. Despite a great number of combinations of settings for under relaxation factors, linear
solvers and tolerances etc tested or by using methods such as starting with rst order schemes,
starting with incompressible simulations or ramping up the velocity gradually made for stable
solutions. Since none of the tested methods made the simulation converge with all second
order discretization schemes some had to be only rst accurate, which will implicate the results.
Even though not all of the elds could use the increased accuracy of second order schemes, the
momentum eld could. Since this is the most important eld, the eects on accuracy should
not be too severe. All of the above mentioned methods were able to start the simulations,
and the easiest to use is ramping up the velocity and as a consequence it was used for the
comparison cases. The ow rate was set to increase every 200th iteration during the rst 1000
iterations where the full ow rate was set.
The solver settings specied in the fvSolution dictionary used for the comparison runs were:
, Applied mechanics, Masters Thesis 2012:13 19
4.1. OPENFOAM SETTINGS CHAPTER 4. RESULTS
s o l v e r s
{
p
{
s o l ve r GAMG;
t ol e r anc e 1e 8;
r e l Tol 0. 001;
smoother Gaus sSei del ;
cacheAggl omerati on o f f ;
nCe l l s I nCoar s e s t Le ve l 20;
aggl omerator f aceAr eaPai r ;
mergeLevel s 1;
}
U // not needed when us i ng i mpl i c i t por os i t y treatment
{
s o l ve r smoothSol ver ;
smoother Gaus sSei del ;
nSweeps 2;
t ol e r anc e 1e 7;
r e l Tol 0 . 0 1 ;
}
( k | e ps i l on )
{
s o l ve r smoothSol ver ;
smoother Gaus sSei del ;
nSweeps 2;
t ol e r anc e 1e 10;
r e l Tol 0;
}
h
{
s o l ve r smoothSol ver ;
smoother Gaus sSei del ;
t ol e r anc e 1e 07;
r e l Tol 0. 0001;
}
}
SIMPLE
{
nUCorrectors 2;
nNonOrthogonal Correctors 2;
rhoMin rhoMin [ 1 3 0 0 0 ] 0 . 5 ;
rhoMax rhoMax [ 1 3 0 0 0 ] 1 . 5 ;
}
With under relaxation factors as presented in Table 4.1.1
20 , Applied mechanics, Masters Thesis 2012:13
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
Table 4.1.1: Under relaxation factors
Field URF
p 0.1
rho 0.9
U 0.8
k 0.7
epsilon 0.7
h 0.7
Worth noting is that lowering the under relaxation factor for the momentum U results in not
just a slower solution but decreases stability as well. The tolerances of the solvers have been
set low to lower the residuals, even though it increases solution time.
Discretization schemes used were the default ones except for divergence, where the second
order accurate scheme linearUpwind(V) cellMDLimited Gauss linear 1 was used for div(phi,U)
and div(U,p) while the rst order accurate upwind scheme was used for the rest.
4.2 Fluent - OpenFOAM comparison
4.2.1 Case one: I5D P1
The simulation was run for 3000 iterations, after which the highest residual (pressure) was 10
3
.
The mesh contained a few non-orthogonal cells and because of that nNonOrthogonalCorrectors
was set to 2. This improved the pressure residual one order of magnitude. The PCG
(Preconditioned Conjugate Gradient) solver was also tested with this case but was found to
be a lot slower and also caused the solution to diverge after about 800 iterations, i.e. even
before the full ow rate had been reached. The resulting ow is pictured in gure 4.2.1 and for
comparison the model calculated with Fluent is shown in gure 4.2.2. The streamlines in both
plots are tracked in reverse from the outlet since there is more than one inlet. The ows look
similar with approximately the same velocities and swirls in the dirty side duct (before the air
lter) and at the outlet. One thing to notice is that fewer of the streamlines seem to make it
through the air lter box in the OpenFOAM simulation (as tracked from the outlet).
, Applied mechanics, Masters Thesis 2012:13 21
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
Figure 4.2.1: Streamlines in the P1 system as calculated with OpenFOAM
Figure 4.2.2: Streamlines in the P1 system as calculated with Fluent
To study the pressure drop in more detail, the absolute values for total pressure drop from
the inlet are presented in Table 4.2.1 together with corresponding values from Fluent. The
22 , Applied mechanics, Masters Thesis 2012:13
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
pressure drop and uniformity index from OpenFOAM are calculated with the swak4foam script
in Appendix B, while the Fluent values are calculated with built-in Fluent methods.
Table 4.2.1: Mass weighted average of total pressure drop (Pa)
Fluent OpenFOAM Dierence
sec2 entrance -893 -1248 39.8%
sec3 dsd out -1623 -1662 2.4%
sec4 lter inlet -2752 -2878 4.6%
sec5 lter out -3115 -3165 1.6%
sec6 amm in -3481 -3418 -1.8%
sec7 csd1 in -4366 -4121 -5.6%
sec8 csd2 in -5449 -5185 -4.8%
sec9 outlet -5903 -5515 -6.6%
The rst thing to note is that the OpenFOAM solver predicts the intake losses as a lot
higher. This could be down to the dierence in the way the boundary conditions are applied.
OpenFOAM has been unable to achieve a stable solution with a negative mass ow on the
outlet, and instead the mass ow has been set at the inlets. When going downstream the
pressure losses are much more similar in magnitude between the two softwares, and just after
the lter OpenFOAM starts to predict a lower pressure loss than Fluent. That is, OpenFOAM
predicts a higher intake loss but a lower loss for the ow through the ducts. Figure 4.2.3 shows
the lter inlet velocity distribution for Fluent and OpenFOAM. The velocity distributions are
relatively similar but the solution from OpenFOAM is more chaotic in its nature. As will be
shown later (section 4.2.3) OpenFOAM has problems with the velocities at the lter inlet.
Even so, the correlation here is good compared to case two (gure 4.2.7). At the outlet (gure
4.2.4) the velocity distributions are similar from both codes, as they should be.
Figure 4.2.3: Velocity distributions at the lter inlet in the P1 system with Fluent on the left
and OpenFOAM on the right
The uniformity indexes (table 4.2.2) are similar at the outlet and before the air mass meter,
but the gure that stands out is at the lter inlet. This is not only a bad correlation to Fluent,
which is not necessarily correct, but the log les indicate that the uniformity index at the
, Applied mechanics, Masters Thesis 2012:13 23
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
Figure 4.2.4: Velocity distributions at the outlet of the P1 system with Fluent on the left and
OpenFOAM on the right
lter inlet varies between iterations. The other two uniformity indexes are constant, indicating
that there is a problem with the velocity eld at the lter inlet. This phenomenon is studied
in more detail in section 4.2.3.
Table 4.2.2: Area weighted uniformity index
Fluent OpenFOAM Dierence
sec4 lter inlet 0.763 0.854 11.9%
sec6 amm in 0.924 0.948 2.6%
sec9 outlet 0.869 0.854 -1.7%
4.2.2 Case two: I5D EuCD
The geometry of case two is simpler than that of case one with no duct connecting inlet two to
the air lter box and a shorter duct from inlet 1. With the same level of mesh renement this
led to a shorter solution time of just under 2 hours for the same amount of iterations as in case
one. As in case one the highest residual (pressure) was in the region of 10
3
. Also in this case
both softwares capture the outlet swirl in the same way (gures 4.2.5 and 4.2.6). Interesting to
note is that in this case as well a smaller part of the streamlines (tracked in reverse direction)
seem to make it past the air lter. The reason for this is unknown, but could be related to the
phenomenon described in section 4.2.3.
24 , Applied mechanics, Masters Thesis 2012:13
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
Figure 4.2.5: Streamlines in the EuCD system as calculated with Fluent
Figure 4.2.6: Streamlines in the EuCD system as calculated with OpenFOAM
, Applied mechanics, Masters Thesis 2012:13 25
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
Also in this case the same trend with a prediction of a much higher pressure loss in the intake
but then a lower loss in the rest of the system can be observed (Table 4.2.3). Worth noting
is that in this model OpenFOAM only predicts a pressure loss of 44 Pa for the air lter,
something which is very low compared to the Fluent simulation. In case one the pressure loss
over the air lter is almost 300 Pa despite the same viscous and inertial resistances and the
same mass ow in both systems. One possible reason for the low pressure drop over the air
lter is that it is the total pressure that is measured. The total pressure has been calculated as
p
0
=
1
2
U
2
+ p and since it includes the velocity it can be aected by the oscillating velocities
seen in the interface to a porous zone.
Table 4.2.3: Mass weighted average of total pressure drop (Pa)
Fluent OpenFOAM Dierence
sec2 dsd in -234 -289 23.5%
sec3 dirtysideduct out -555 -708 27.6%
sec4 lter inlet -1101 -1245 13.1%
sec5 lteroutlet -1293 -1289 -0.3%
sec6a amm in -1401 -1522 8.6%
sec6b amm out -2120 -2178 2.7%
sec7 csd2 in -2355 -2394 1.6%
sec8 csd3 in -2968 -2744 -7.5%
sec9 outlet -3430 -3130 -8.8%
Next, velocity distributions at the lter inlet and system outlet are compared. It is evident that
the velocity distribution at the lter inlet diers quite a lot between Fluent and OpenFOAM
for the EuCD model (Figure 4.2.7). The outlet shows a good correlation between the two
softwares (Figure 4.2.8).
As in case one the uniformity index at the lter inlet diers signicantly between the two
softwares while at the outlet and in front of the AMM they are similar. Also in this case the
uniformity index at the lter inlet oscillates as if the solution was transient. The rest of the
ow is steady indicating unphysical velocity patterns at the interface of the porous zone.
Table 4.2.4: Area weighted uniformity index
Fluent OpenFOAM Dierence
sec4 lterinlet 0.787 0.940 19.4%
sec6 amm in 0.959 0.942 -1.7%
sec9 outlet 0.907 0.890 -1.9%
26 , Applied mechanics, Masters Thesis 2012:13
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
Figure 4.2.7: Velocity distributions at the lter inlet in the EuCD system with Fluent on the
left and OpenFOAM on the right
Figure 4.2.8: Velocity distributions at the outlet of the EuCD system with Fluent on the left
and OpenFOAM on the right
, Applied mechanics, Masters Thesis 2012:13 27
4.2. FLUENT - OPENFOAM COMPARISON CHAPTER 4. RESULTS
4.2.3 Oscillating velocity at porous interface
The uniformity indexes at the lter inlet as calculated with OpenFOAM are signicantly
dierent in both the test cases from the ones calculated with Fluent. This prompted further
investigation and it was found that it also varied between subsequent iterations. The rest
of the ow is steady, and it is just around the interface between non-porous/porous media
that this behaviour with an oscillating velocity can be observed. Figure 4.2.9 shows how the
velocities in the three coordinate directions vary along a straight line thru the porous zone
(air lter). The porous zone itself starts at a curve length of 0.037 and ends at 0.074.
The plot is from test case two, but the same behaviour has been observed in the rst case as
well. The velocity in x-direction goes towards zero as it enters the porous zone, which is as
expected since this is the direction with the highest resistance. In the Y-direction, which is
the direction along the lter paper ribs, the oscillation can be observed. At the start of the
lter the velocity uctuates between positive and negative values. Also the Z-velocity shows
oscillations, but stays at positive values. These oscillations are not visible in the data from the
Fluent simulation.
Figure 4.2.9: Velocity prole through the lter as computed with OpenFOAM
A search in the OpenFOAM bug reporting system shows that this problem is a known one
28 , Applied mechanics, Masters Thesis 2012:13
4.3. VALIDATION WITH EXPERIMENTS CHAPTER 4. RESULTS
[11]. In the bug report there is also a suggested x. It consists of replacing the line of
code U -= rUA*fvc::grad(p) for U = fvc::reconstruct(phi)/rho in the pEqn.H le used in the
rhoPorousMRFSimpleFoam source le. This change was made and the solver recompiled.
Although this is somewhat outside of the scope set up in the limitations (section 1.3) it was
deemed important for the conclusions to evaluate the x. Both of the test cases were run again
with the new solver but otherwise identical settings. The results were similar to the original
solver and the velocity patterns remained unphysical and changing on every iteration at the
start of the porous zone.
4.3 Validation with experiments
Total pressure drops over the systems as measured from experiments are presented in Table
4.3.1. For these cases the OpenFOAM simulations are further from the experimental results.
In the P1 case OpenFOAM is o by 9% and in the EuCD case by a substantial 25%, compared
to 2 and 18% for Fluent. The measurements in the ow rig are taken by a pressure sensor
mounted between the outlet and the attachment to ow rig, visible in gure 3.2.5. One thing
to have in mind during this comparison is that OpenFOAM could not be made to run with
the ow set at the outlet, and even though the mass ows through the systems are the same,
the boundary conditions are not identical.
Table 4.3.1: Total pressure drop computed from CFD simulations and measurements (Pa)
Case OpenFOAM Fluent Experiment
P1 5515 5903 6052
EuCD 3130 3430 4177
4.4 Parallel scaling
Since CFD is very demanding with respect to computing power, it is important to use the
optimal number of processors/cores when doing an analysis utilising parallel computing. This
is important both in respect to shortening lead times in development projects and to use the
available computing resources as eciently as possible. OpenFOAM uses domain decomposition
for processing in parallel. This means that the geometry and associated elds are divided
into parts for each processor/core going to be used for the computation. To determine the
optimal number of cores to use when running cases in parallel, a test has been conducted by
solving the same case using a varying amount of cores. The model used is similar to the test
cases and consists of 6 million cells. This is a typical size for air induction system models.
The type of simulation is the same as in the test cases, i.e. steady state, compressible with
realizable k-epsilon turbulence model and porous media for the lter. To obtain a simulation
time, the case was run for 2000 iterations and the clocktime read from the log le. The case
was run with 16,32,48,64,96,128,144,160,172,192, 256 and 384 cores. The number of cores used
is only relevant for a case with around the same number of cells as the one used in this test.
Instead, the average number of cells per core has been used as a measure to help decide the
, Applied mechanics, Masters Thesis 2012:13 29
4.5. TOPOLOGY OPTIMISATION CHAPTER 4. RESULTS
optimum number of cores for any given case. Presented in gure 4.4.1, the conclusion is that
the optimum lies around 50000 cells per core used. With more cells than this per core the
interconnections arent saturated and so more cores equals shorter solution time. And with
fewer cells per core, the interconnections between the cores/nodes become the bottleneck and
this might actually lead to a slower calculation.
Figure 4.4.1: Number of cells/core for optimum computing performance
4.5 Topology optimisation
To achieve convergence with the adjoint solver proved to be dicult, but after raising the
value alphaMax to 10
6
, which corresponds to the maximum porosity in the blocked cells, a
satisfactory level of convergence was achieved with the highest residual in the region of 10
4
.
The obtained geometry is shown in gure 4.5.1. The new geometry created in the box resembles
the shape of a circular duct, but with a varying radius. The rough edges seen in the new
geometry are the individual cells that have been blocked.
The ow changed signicantly between the unmodied and adjoint optimised design space.
Figure 4.5.2 shows streamlines for both the modied and unmodied geometry. The optimised
geometry removes all of the large scale swirl and this should lower the pressure drop. However,
the total pressure drop from inlet to outlet was about the same for both geometries. Since the
solver is supposed to optimise with respect to lowering pressure loss, this was unexpected. One
reason for the pressure drop not being lower in the modied design could be because of the
rough walls created by the blocked cells. The mesh used here had approximately 300000 cells.
To try and lower the eect of the rough edges a rened mesh with 800000 cells was tested as
30 , Applied mechanics, Masters Thesis 2012:13
4.5. TOPOLOGY OPTIMISATION CHAPTER 4. RESULTS
Figure 4.5.1: Geometry obtained after adjoint optimisation
well. The results were still the same and it was concluded that if the rough cell edges were
responsible for the pressure drop being unchanged before and after optimisation, rening the
mesh does not help. To get the real benet of an adjoint optimisation with blocked cells the
rough surface obtained would probably have to be imported into the CAD model and used as
a guide when updating the design.
Figure 4.5.2: Streamlines for original and optimised geometries
, Applied mechanics, Masters Thesis 2012:13 31
CHAPTER 5. DISCUSSION AND CONCLUSIONS
5 Discussion and conclusions
The most important part of this work has been to assess whether OpenFOAM can be used
as a tool to reliably predict the ow in automotive air induction systems. Also part of the
thesis has been to investigate the possibilities and suitability of using OpenFOAM as a tool in
optimising the shape of future air induction systems.
5.1 System simulations
Comparing the results from Fluent and OpenFOAM simulations it is evident that there are
some dierences between the softwares. The absolute numbers on pressure loss obtained with
OpenFOAM were further from the experimental values than the ones obtained with Fluent.
OpenFOAM simulations show a pressure drop almost 10% lower than the simulation from
Fluent. The problem here is that already Fluent tends to under predict the losses compared to
experimental results. There are also dierences in where the losses take place in the system.
Fluent shows a higher loss in the ducts compared to OpenFOAM, while the latter shows a
higher loss in the intake. It is hard to tell exactly where these dierences come from, but it
should be noted that the same numerical settings and boundary conditions have not been
possible to use. OpenFOAM couldnt handle the ow being prescribed at the outlet, but instead
it had to be set at the inlets. If the same boundary conditions would have been possible to use
in experiments and simulations they could have been validated in more thorough way against
each other. The simulations involving porous zones turned out to be highly unstable. Despite
several initiation techniques such as starting with incompressible ow, 1st order numerical
schemes and low ow speeds the OpenFOAM simulations couldnt be made to use all second
order schemes for the numerics. This will of course aect the results, but at least the most
important eld (momentum) could be run with a second order scheme. The tolerances of the
linear solvers were set to low values. This increased solution time but was necessary to achieve
reasonably low residuals. Even with the low tolerances, OpenFOAM had a speed advantage
compared to Fluent.
The work carried out when writing this thesis has included testing a great number of combina-
tions of URFs, numerical schemes and solver settings. Even so, it can not be ruled out that
further tests and trials could nd settings that can be used to better predict the air induction
system ows. There is also the problem encountered with the oscillating ow speeds in the
transition to a porous zone (the air lter). As no solution to this is presently known this must
be considered a drawback for OpenFOAM when simulating complete air lter systems. Even if
this phenomenon does not aect the pressure loss over the whole system in a signicant way, it
makes the uniformity index at the lter inlet useless. When simulating single ducts without an
air lter there are no problems in using all second order numerical schemes, further indicating
that it is the porous media implementation that suers from a problem. In post-processing,
the total pressure drop and uniformity indexes can easily be read in the log-le with the use
of swak4foam. This is an advantage compared to Fluent as no post-processing is needed (or
rather post-processing is done on-the-y). OpenFOAM data can easily be converted to most
post-processing software formats. It should be noted though that the conversion isnt optimal
32 , Applied mechanics, Masters Thesis 2012:13
5.2. TOPOLOGY OPTIMISATION CHAPTER 5. DISCUSSION AND CONCLUSIONS
as data from internal surfaces doesnt follow. The only way found to present plots of the
data on internal surfaces such as gure 4.2.3 is to use the paraFoam wrapper for Paraview.
One of the greatest advantages with OpenFOAM is that it is command-line based. This
makes it easy to automatise and integrate with other softwares. Outside of the scope of this
thesis, but nevertheless also signicant merit for OpenFOAM is the possibility for users to add
functionality.
The parallel scalability with regard to number of cores used does depend on certain variables
such as the geometry of the mesh, the decomposition method used and resulting number of
shared interfaces between processors. The main reason for the scalability not being linear is
usually that the processors and nodes have to shue a lot of data between each other and the
memory (depending on the number of shared faces). The speed of the interfaces between nodes
and processors are one of the most important variables when considering the eectiveness in
increasing the number of cores to use for a simulation. The test conducted reects the optimal
with the current setup used at VCC.
This thesis has shown that there are problems in simulating the air lter systems with
OpenFOAM, the most severe being the oscillating velocities at the porous interface (see section
4.2.3). If a solution to this is found there are no substantial obstacles for using OpenFOAM as
the main CFD-package for the air induction systems.
5.2 Topology Optimisation
When optimising the absolute numbers are not as important as long as the dierences with
changing geometry are correct. OpenFOAM is command-line based and this makes it very easy
to integrate with optimisation softwares such as modeFrontier. Together with the fact that it
is free [5] and thus lowering the licensing costs for simulation runs this makes OpenFOAM very
suitable to use for DOE-based optimisation loops. The integrated pre- and post-processing
such as the swak4foam script used in this thesis is also very useful in an optimisation loop as it
enables extraction of a wide variety of data without user interaction.
The adjoint solver currently distributed with OpenFOAM (version 2.1.0) is a very basic solver.
The solver optimises against one variable, total pressure loss. It also changes the geometry
by adding blockages to the cells that contribute to pressure loss as suggested by the adjoint
equations. While this works well to get an idea of where the losses occur, the geometry achieved
with the blocked cells is less than optimal in the sense that it creates very rough walls. It is
possible to extract this surface and use it as input in CAD software when improving a design.
A better approach for changing the geometry would probably be to use some kind of CAD
parametrisation or mesh morphing to get an optimised model directly.
Another thing to take into consideration with the adjoint method is that it does not take other
factors such as manufacturability and manufacturing cost into account when computing the
optimal shape. This can create good geometries with respect to the optimised variable, but
which are not possible to manufacture. The result will therefore always require at least some
interpretation by a designer before it can be used. For this reason the results obtained from an
adjoint method optimisation are best suited as a guide to where changes need to be made in a
design rather than using the geometry directly. A conclusion regarding the adjoint method
, Applied mechanics, Masters Thesis 2012:13 33
5.2. TOPOLOGY OPTIMISATION CHAPTER 5. DISCUSSION AND CONCLUSIONS
for optimising air induction system topologies is that it is a good tool to use for a designer
in determining where to make changes. But it is not a tool producing a geometry ready for
production.
34 , Applied mechanics, Masters Thesis 2012:13
CHAPTER 6. RECOMMENDATIONS FOR FURTHER WORK
6 Recommendations for further work
Even though time consuming, continued investigations into nding numerical schemes
etc. could possibly improve the performance and stability when using OpenFOAM for
simulating complete air lter systems.
Finding a solution to the porous boundary problem would enable OpenFOAM to be used
in predicting lter utilisation, something which is now not possible.
While the adjoint method holds great potential the solver currently distributed with
OpenFOAM is of a very simple nature. To improve the usability of the adjoint method a
new solver would have to be developed. On the wish list for a new solver would be, for
example, the ability to handle compressible ows, more variables to optimise against (for
example uniformity index) and to only apply the adjoint equations to certain parts of
the mesh, for example a cellZone.
Investigate the OpenFOAM meshing tool snappyHexMesh for meshing the air induction
systems.
, Applied mechanics, Masters Thesis 2012:13 35
REFERENCES
References
[1] F. M. White. Fluid Mechanics. Sixth Edition. McGraw-Hill, 2008.
[2] A. N. Kolmogorov. Equation of turbulent motion of an incompressible uid. In: Physics
6 (1941), pp. 5658.
[3] W. P. Jones and B. E. Launder. The prediction of laminarization with a two-equation
model of turbulence. In: International Journal of Heat and Mass Transfer 15 (1972),
pp. 301314.
[4] H. K. Versteeg and W Malalasekera. An Introduction to Computational Fluid Dynamics,
The Finite Volmue Method. Second Edition. Pearson Education, 2007.
[5] GNU General Public License. Version 3. 2007. url: http://www.gnu.org/licenses/
gpl.html.
[6] OpenFOAM Userguide. Version 2.1. OpenCFD, 2011. url: http://www.openfoam.org/
docs/user/.
[7] H. E. Hafsteinsson. Porous Media in OpenFOAM. 2009.
[8] M. Dybeck. CFD-procedures for Air Induction Systems. MA thesis. Lulea University
of Technology, 2011.
[9] R. Schneider. Applications of the Discrete Adjoint Method in Computational Fluid
Dynamics. PhD thesis. University of Leeds, 2006.
[10] C. Hinterberger and M. Olesen. Industrial application of continuous adjoint ow solvers
for the optimization of automotive exhaust systems. In: ECCOMAS. 2011.
[11] 0000134: Unphysical velocity patterns at the interface of a porous zone. 2011. url:
http://www.openfoam.org/mantisbt/view.php?id=134.
36 , Applied mechanics, Masters Thesis 2012:13
APPENDIX A. INTRODUCTION TO OPENFOAM
A Introduction to OpenFOAM
OpenFOAM is an abbreviation which stands for Open source Field Operation And Manipula-
tion and is an open source numerical simulation software with extensive capabilities in solving
uid ows and other multi-physics problems. From the beginning (circa 1993) the software
was called simply FOAM and was rst developed as part of a PhD project at Imperial College
London. In 2004 it became open source under the GNU GPL license [5] and changed name to
OpenFOAM. Today it is developed by SGI
R
and widely used by both academic institutions
and corporations worldwide.
The OpenFOAM distribution includes a lot of things, but the basis is the C++ libraries.
The libraries contain the OpenFOAM classes which are designed to make it easier to write
applications that solve continuum mechanics problems. Even though you still need some
programming knowledge, a thorough knowledge of C++ is not a hard requirement to create
or edit OpenFOAM applications. The classes provide a syntax which resembles the original
equation. This example from the OpenFOAM userguide [6] is probably one of the simpler ones
but shows the idea behind the OpenFOAM classes. The equation A.0.1
U
t
+ U U = p (A.0.1)
is in OpenFOAM represented by the code:
s ol ve
(
fvm : : ddt ( rho , U)
+ fvm : : di v ( phi , U)
fvm : : l a pl a c i a n (mu, U)
==
f vc : : grad ( p)
) ;
The OpenFOAM distribution includes a large number of solvers. Each solver is designed to solve
a specic type of problem. Most are designed to solve some kind of CFD problem but there are
also solvers for other types of problems such as electro magnetic and nancial problems. The
other type of application distributed with OpenFOAM are the utilities. They handle mostly
pre- and post-processing functions such as mesh conversion and data manipulation.
Table A.0.1 and Table A.0.2 contains a selection of solvers and utilities that are part of the
OpenFOAM distribution and have been used in this thesis.
, Applied mechanics, Masters Thesis 2012:13 37
APPENDIX A. INTRODUCTION TO OPENFOAM
Table A.0.1: A selection of solvers distributed with OpenFOAM used in this thesis
Solver Description
simpleFoam Incompressible steady-state solver utilising the SIMPLE
pressure-velocity coupling
porousSimpleFoam Same as the above but with included implicit or explicit
porosity treatment.
rhoPorousMRFSimpleFoam Further extension of the above solvers for handling com-
pressible ow (i.e. variable density, hence the rho in
the name).
Table A.0.2: A selection of utilities distributed with OpenFOAM used in this thesis
Utility Description
checkMesh Checks the mesh for certain quality parameters such as
skewness.
uent3DMeshToFoam Converts a mesh from uent to OpenFOAM format.
foamMeshToFluent Converts a mesh from OpenFOAM to uent format.
foamDataToFluent Converts data from OpenFOAM to uent format.
ptot Calculates the total pressure from pressure and velocity
elds (if compressible also rho).
foamLog Extracts residuals from a log le for plotting.
decomposePar Decomposes a mesh together with data elds for parallel
processing.
reconstructPar Reconstructs the mesh and elds after parallel processing
is done.
foamToVTK Converts mesh and data to VTK format. Useful for
example if Paraview is to be used on another computer.
A.1 Case setup
An OpenFOAM case is contained in a folder with the name of the case. Inside this folder
the case has a basic le structure shown in Figure A.1.1. The system/ folder holds les for
setting options associated with the solution procedure. In the constant/ directory the case is
described, that is, it contains the mesh (subdirectory polyMesh/ ) and physical properties. The
time directories contains the data for all the elds at dierent times. The times refers to
actual time in the case of transient simulations, but in the case of steady state simulations it is
only a means of keeping track of iterations. The 0/ directory contains initial values (the 0:th
iteration) and subsequent time directories are created during the simulation as specied in
controlDict.
This le structure is almost the same for all OpenFOAM cases with small dierences due to
the required les for dierent solvers. The conguration les for solvers and utilities are called
dictionaries. Table A.1.1 contains a description of the most important ones.
A summary of the necessary steps for setting up an OpenFOAM case are:
Create the mesh for example with the blockMesh utility or with ANSA (Subsection 3.1.3)
38 , Applied mechanics, Masters Thesis 2012:13
APPENDIX A. INTRODUCTION TO OPENFOAM
Figure A.1.1: Directory structure of an OpenFOAM case
Table A.1.1: Description of the most important OpenFOAM dictionaries used in this thesis
Dictionary Description
controlDict Controls start/stop, iterations, data writing and also
contains function objects. Function objects are pieces of
code that runs on every iteration.
fvSolution Species the types of linear solvers, algorithms and under
relaxation factors to use.
fvSchemes Species numerical schemes.
boundary Sets boundary types.
transportProperties Denes uid properties for incompressible solvers.
thermophysicalProperties Species thermophysical properties of a uid when using
the energy equation (with compressible solvers).
RASProperties Species RAS turbulence model, cf. LES modelling.
decomposeParDict Options for the mesh decomposition required for parallel
computing.
or convert the mesh from another format with a utility such as uent3DMeshToFoam.
Set boundary types in the polyMesh/boundary dictionary. In this thesis patch has been
used for inlets/outlets etc and wall for walls.
Set boundary conditions in the 0/ directory. Depending on the method used to create
the mesh, it may be necessary to create/edit the volume eld dictionaries manually.
Set turbulence model in RASProperties/LESProperties dictionary for turbulent simula-
tions.
Set uid properties such as and c
p
. For most solvers this is done in either transport-
, Applied mechanics, Masters Thesis 2012:13 39
APPENDIX A. INTRODUCTION TO OPENFOAM
Properties or thermophysicalProperties.
Set solution algorithms in fvSolution dictionary.
Set schemes in fvSchemes dictionary.
Set simulation controls in the controlDict dictionary.
Decompose the case with decomposePar if using more than one core for solving.
When all the settings are set to appropriate values, the solver of choice is started by running
the solver from the case directory. For parallel processing, the process of starting the solver
depends on the type of parallel processing/queuing system used.
40 , Applied mechanics, Masters Thesis 2012:13
APPENDIX B. SWAK4FOAM SCRIPT
B swak4foam script
Below are examples of the entries used to calculate total pressure and uniformity index on the
interior sections, in OpenFOAM dened as faceZones. Last is the code used to display mass
ows on the inlets and outlet.
Entry for calculating the total pressure on a faceZone (mass weighted average)
Totalpr e s s ur e s e c 9 o ut l e t
{
f unct i onObj ect Li bs ( l i bsi mpl eSwakFuncti onObj ect s . so ) ;
type swakExpressi on ;
outputControl outputTime ;
val ueType f aceZone ;
zoneName s e c 9 o ut l e t ;
e xpr e s s i on
sum( ( 0. 5 rhopow(mag(U) , 2)+p) ( area ( ) rho ) ) /
(sum( area ( ) rho ) ) ;
accumul ati ons
(
average
) ;
ver bos e t r ue ;
aut oI nt e r pol at e t r ue ;
warnAutoI nterpol ate f a l s e ;
}
Entry for calculating the uniformity index on a faceZone (area weighted average)
UI s e c 9 out l e t
{
type swakExpressi on ;
outputControl ti meStep ;
val ueType f aceZone ;
zoneName s e c 9 o ut l e t ;
accumul ati ons
(
max
) ;
e xpr e s s i on
1sum( ( s qr t (pow( ( average (mag(U))mag(U) ) , 2 ) ) /
(2sum( area ( ) ) average (mag(U) ) ) ) area ( ) ) ;
ver bos e t r ue ;
aut oI nt e r pol at e t r ue ;
, Applied mechanics, Masters Thesis 2012:13 41
APPENDIX B. SWAK4FOAM SCRIPT
warnAutoI nterpol ate f a l s e ;
}
Entry for printing mass ows across the boundaries
massFlow
{
f unct i onObj ect Li bs ( l i bsi mpl eSwakFuncti onObj ect s . so ) ;
type patchMassFlow ;
ver bos e t r ue ;
patches
(
i nl e t 1
i nl e t 2
pr e s s ur e o ut l e t
) ;
f a c t o r 1;
}
42 , Applied mechanics, Masters Thesis 2012:13
APPENDIX C. PYTHON SCRIPT
C Python script
Python script for automation of the solving process. It changes from incompressible to
compressible simulation settings and switches divergence schemes. Uses the Python library
PyFoam.
#!/ usr / bi n/python
i mport os , sys , s hut i l
from PyFoam. Appl i cat i ons . Decomposer i mport Decomposer
from PyFoam. Appl i cat i ons . Runner i mport Runner
from PyFoam. Appl i cat i ons . Pl otRunner i mport Pl otRunner
from PyFoam. Executi on . Basi cRunner i mport Basi cRunner
cas e=s ys . argv [ 1 ]
proc=i nt ( s ys . argv [ 2 ] ) #number of c or e s
i t e i ncomp=i nt ( s ys . argv [ 3 ] ) #number of i t e r a t i o n s f o r i nc ompr e s s i bl e
#Schemes to use f o r di ver gence ( i n or der of use )
divSchemesV=[ upwind , linearUpwindV ] ;
di vSchemes =[ upwind , l i nearUpwi nd ] ;
#s o l v e r s to use
s ol ver i ncomp=porousSimpleFoam
sol ver comp=rhoPorousMRFSimpleFoam
# Se t t i ng appl i c at i on to porousSimpleFoam
pr i nt \ nSet t i ng appl i c at i on to porousSimpleFoam
i nf i l e name=%s /system/ cont r ol Di ct %cas e
out f i l ename=%s /system/control Di ctTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
words = l i n e . s p l i t ( )
f o r word i n words :
i ndex = words . i ndex ( word)
i f word == appl i c at i on :
words [ i ndex +1] = s ol ver i ncomp + ;
cont i nue
newl i ne = . j o i n ( words )
o f i l e . wr i t e ( %s \n % newl i ne )
i f i l e . c l o s e ( )
, Applied mechanics, Masters Thesis 2012:13 43
APPENDIX C. PYTHON SCRIPT
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#Decompose f o r gi ven number of c or e s
Decomposer ( ar gs=[pr ogr e s s ,method=s cot ch , case , s t r ( proc ) ] )
#Set the divScheme to Gauss upwind ; ( f i r s t or der accur at e )
#s hut i l . copy ( %s /system/fvSchemes %cas e , %s /system/fvSchemes . ol d %cas e )
#pr i nt \ nSet t i ng divScheme to Gauss %s f o r Momentum, k , eps , h and pr es s ur e % . j o i n (map( s t r , di vSchemes [ 0 ] ) )
#i nf i l e name=%s /system/fvSchemes %cas e
#out f i l ename=%s /system/fvSchemesTemp %cas e
#i f i l e = open ( i nf i l ename , r )
#o f i l e = open ( out f i l ename , w )
#l i n e s = i f i l e . r e a dl i ne s ( )
#
#f o r l i n e i n l i n e s :
# words = l i n e . s p l i t ( )
# f o r word i n words :
# i ndex = words . i ndex ( word)
# i f word == di v ( phi , U) :
# words [ i ndex +2] = divSchemesV [ 0 ] + ;
# cont i nue
# i f word == di v ( phi , k ) :
# words [ i ndex +2] = di vSchemes [ 0 ] + ;
# cont i nue
# i f word == di v ( phi , e ps i l on ) :
# words [ i ndex +2] = di vSchemes [ 0 ] + ;
# cont i nue
# i f word == di v ( phi , h ) :
# words [ i ndex +2] = di vSchemes [ 0 ] + ;
# cont i nue
# i f word == di v (U, p ) :
# words [ i ndex +2] = di vSchemes [ 0 ] + ;
# cont i nue
# newl i ne = . j o i n ( words )
# o f i l e . wr i t e ( %s \n % newl i ne )
#i f i l e . c l o s e ( )
#o f i l e . c l o s e ( )
#os . remove ( i nf i l e name )
#os . rename ( out f i l ename , i nf i l e name )
#Run s o l ve r wi th i nc ompr e s s i bl e s o l ve r
pr i nt \ nRunning 500 i t e r a t i o n s wi th %s %s ol ver i ncomp
Runner ( ar gs=[proc=%d%proc ,pr ogr e s s , sol ver i ncomp ,cas e , cas e ] )
44 , Applied mechanics, Masters Thesis 2012:13
APPENDIX C. PYTHON SCRIPT
#Reconstruct the cas e to be abl e to mani pul ate f i e l d s
Runner ( ar gs =[ r econs t r uct Par ,cas e , cas e ] )
#change to compr es s i bl e s e t t i ng s
#(p and phi di mensi ons , c ont r ol di c t , k & e ps i l on wal l f unc t i ons )
pr i nt \ nSwi tchi ng to compr es s i bl e s o l ve r s e t t i ngs
#k wal l F
i nf i l e name=%s /500/k %cas e
out f i l ename=%s /500/kTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
l i n e = l i n e . r e pl ac e ( kqRWallFunction , compr es s i bl e : : kqRWallFunction )
o f i l e . wr i t e ( l i n e )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#eps wal l F
i nf i l e name=%s /500/ eps i l on %cas e
out f i l ename=%s /500/ epsilonTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
l i n e = l i n e . r e pl ac e ( eps i l onWal l Funct i on , compr es s i bl e : : eps i l onWal l Funct i on )
o f i l e . wr i t e ( l i n e )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#eps i n l e t
i nf i l e name=%s /500/ eps i l on %cas e
out f i l ename=%s /500/ epsilonTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
, Applied mechanics, Masters Thesis 2012:13 45
APPENDIX C. PYTHON SCRIPT
l i n e = l i n e . r e pl ac e ( t ur bul ent Mi xi ngLengt hDi s s i pat i onRat eI nl et , compr es s i bl e : : t ur bul ent Mi xi ngLengt hDi s s i pat i onRat eI nl et )
o f i l e . wr i t e ( l i n e )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#change appl i c at i on i n c ont r ol Di c t
i nf i l e name=%s /system/ cont r ol Di ct %cas e
out f i l ename=%s /system/control Di ctTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
l i n e = l i n e . r e pl ac e ( sol ver i ncomp , sol ver comp )
o f i l e . wr i t e ( l i n e )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#changi ng di mensi on f o r p to compr es s i bl e dim
i nf i l e name=%s /500/p %cas e
out f i l ename=%s /500/pTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
l i n e = l i n e . r e pl ac e ( [ 0 2 2 0 0 0 0 ] , [ 1 1 2 0 0 0 0] )
o f i l e . wr i t e ( l i n e )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#changi ng di mensi on f o r phi to compr es s i bl e dim
i nf i l e name=%s /500/ phi %cas e
out f i l ename=%s /500/phiTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
l i n e = l i n e . r e pl ac e ( [ 0 3 1 0 0 0 0 ] , [ 1 0 1 0 0 0 0] )
46 , Applied mechanics, Masters Thesis 2012:13
APPENDIX C. PYTHON SCRIPT
o f i l e . wr i t e ( l i n e )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#copy bc f i l e s f o r compr es s i bl e to new r e s ul t di r e c t or y
s hut i l . copy ( %s /0/ al phat %case , %s /500/ al phat %cas e )
s hut i l . copy ( %s /0/mut%case , %s /500/mut%cas e )
s hut i l . copy ( %s /0/T%cas e , %s /500/T%cas e )
#Decompose the cas e agai n wi th new boundary c ondi t i ons
Runner ( ar gs =[decomposePar ,f o r c e ,cas e , cas e ] )
#Run s o l ve r
pr i nt \ nRunning 500 i t e r a t i o n s wi th %s %sol ver comp
Runner ( ar gs=[proc=%d%proc ,pr ogr e s s , sol ver comp ,cas e , cas e ] )
#Change the divScheme to Gauss l i ne a r ; ( second or der accur at e ) f o r Mom, k and eps
pr i nt \ nSet t i ng divScheme to Gauss %s f o r momentum, k and eps % . j o i n (map( s t r , di vSchemes [ 1 ] ) )
i nf i l e name=%s /system/fvSchemes %cas e
out f i l ename=%s /system/fvSchemesTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
words = l i n e . s p l i t ( )
f o r word i n words :
i ndex = words . i ndex ( word)
i f word == di v ( phi , U) :
words [ i ndex +2] = divSchemesV[ 1] + l i mi t e d ;
cont i nue
i f word == di v ( phi , k ) :
words [ i ndex +2] = di vSchemes [ 1] + l i mi t e d ;
cont i nue
i f word == di v ( phi ,K) :
words [ i ndex +2] = di vSchemes [ 1] + l i mi t e d ;
cont i nue
i f word == di v ( phi , e ps i l on ) :
words [ i ndex +2] = di vSchemes [ 1] + l i mi t e d ;
cont i nue
newl i ne = . j o i n ( words )
o f i l e . wr i t e ( %s \n % newl i ne )
i f i l e . c l o s e ( )
, Applied mechanics, Masters Thesis 2012:13 47
APPENDIX C. PYTHON SCRIPT
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#Run s o l ve r
pr i nt \ nRunning 500 i t e r a t i o n s wi th %s %sol ver comp
Runner ( ar gs=[proc=%d%proc ,pr ogr e s s , sol ver comp ,cas e , cas e ] )
# change the divScheme to Gauss l i n e a r ; ( second or der accur at e ) f o r p
pr i nt \ nSet t i ng divScheme to Gauss %s f o r pr es s ur e % . j o i n (map( s t r , di vSchemes [ 1 ] ) )
i nf i l e name=%s /system/fvSchemes %cas e
out f i l ename=%s /system/fvSchemesTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
words = l i n e . s p l i t ( )
f o r word i n words :
i ndex = words . i ndex ( word)
i f word == di v (U, p ) :
words [ i ndex +2] = di vSchemes [ 1] + l i mi t e d ;
cont i nue
newl i ne = . j o i n ( words )
o f i l e . wr i t e ( %s \n % newl i ne )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#Run s o l ve r
pr i nt \ nRunning 500 i t e r a t i o n s wi th %s %sol ver comp
Runner ( ar gs=[proc=%d%proc ,pr ogr e s s , sol ver comp ,cas e , cas e ] )
# change the divScheme to Gauss l i n e a r ; ( second or der accur at e ) f o r h
pr i nt \ nSet t i ng divScheme to Gauss %s f o r enthal py % . j o i n (map( s t r , di vSchemes [ 1 ] ) )
i nf i l e name=%s /system/fvSchemes %cas e
out f i l ename=%s /system/fvSchemesTemp %cas e
i f i l e = open ( i nf i l ename , r )
o f i l e = open ( out f i l ename , w )
l i n e s = i f i l e . r e a dl i ne s ( )
f o r l i n e i n l i n e s :
words = l i n e . s p l i t ( )
48 , Applied mechanics, Masters Thesis 2012:13
APPENDIX C. PYTHON SCRIPT
f o r word i n words :
i ndex = words . i ndex ( word)
i f word == di v ( phi , h ) :
words [ i ndex +2] = di vSchemes [ 1] + l i mi t e d ;
cont i nue
newl i ne = . j o i n ( words )
o f i l e . wr i t e ( %s \n % newl i ne )
i f i l e . c l o s e ( )
o f i l e . c l o s e ( )
os . remove ( i nf i l e name )
os . rename ( out f i l ename , i nf i l e name )
#Run s o l ve r
pr i nt \ nRunning 500 i t e r a t i o n s wi th %s %sol ver comp
Runner ( ar gs=[proc=%d%proc ,pr ogr e s s , sol ver comp ,cas e , cas e ] )
#Reconstruct the cas e
Runner ( ar gs =[ r econs t r uct Par ,cas e , cas e ] )
}
, Applied mechanics, Masters Thesis 2012:13 49