Exploring OpenFOAM
Exploring OpenFOAM
Exploring OpenFOAM
DR
AF
T
Comflics
Sadiq Huq
Shuaib Ahmed Idrees
Mehran Saeedi Ramakrishna Nanjundiah
Disclaimer
DR
AF
T
This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAMrand OpenCFDrtrade marks.
ii
Preface
R
The response to OpenFOAM
tutorials in Youtube has been overwhelming. The videos
R
were made to give a quick start to using OpenFOAM
. Continuing our efforts at making
R
OpenFOAM easy to understand, we now bring to you an ebook. Each chapter will demonstrare a key topic in Computational Fluid Dynamics, the simulation cases used in this book
will also be made available to you. We encourage you to tweak the simulations, experiment
new possibilities and whenever possible share your findings in a public domain.
You can download the files used in this ebook from https://github.com/Comflics/comflicsTutor.
And you can also follow our blog, www.comflics.de, for updates.
DR
AF
T
iii
Contents
1 Introduction to OpenFOAM - (coming soon)
S. Huq
2.4
2.5
Fluid Mechanics . . . .
Numerics . . . . . . .
OpenFOAM . . . . . .
2.3.1 Preprocessing .
2.3.2 Solver . . . . .
2.3.3 Post processing
Exercise . . . . . . . .
References . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
4
7
7
11
14
16
16
DR
AF
T
2.1
2.2
2.3
DR
AF
T
S. Huq
DR
AF
T
The most decisive non-dimensional parameter for describing the flow pattern around a cylinder
is the Reynolds number:
Re =
UL
(2.1)
It is defined as the ratio of inertial to viscous forces. At low Reynolds numbers viscous
forces dominate the flow and the flow is laminar, as the Reynold number increases viscous
forces cease to dominate the flow and the flow becomes turbulent. For very low Reynolds
numbers Re < 5 there is no flow separation, fluid particles from upstream of the flow can be
divided to two groups flowing symmetrically around upper and lower part of the cylinder
and reaching together the back of the cylinder without separation. As the Reynolds number
is increased a small separation region is formed behind the cylinder where two eddies of
opposite sign are formed (twin vortices), these vortices are not shed into the flow and the
separation region does not extend downstream. With further increase in the Reynolds number
the twin vortices elongate and a harmonic oscillation is observed in the wake region. At
Re 90 eddies start to shed alternatively from the upper and lower part of the cylinder and
form the so-called Karman Vortex Street. At this range of Reynolds number, the flow is
still laminar in the wake. As the Reynolds number increases (200 < Re < 300) the flow in
the wake becomes turbulent, while the boundary layer flow near the cylinder is still laminar
and remains laminar up to Re 3 105 (subcritical regime). We then have the critical
regime for 3 105 < Re < 3.5 105 where transition to turbulence spreads to the boundary
(2.2)
DR
AF
T
St =
where L is the characteristic length. For flow around a cylinder the diameter is taken as
the characteristic length. For 200 < Re < 3 105 Strouhal numbers remains approximately
constant and St 0.2 is a good estimate for it. Then there is a jump in Strouhal number at
transition Reynolds number. Figure 2.3 shows how Strouhal number changes with Reynolds
number for a smooth cylinder.
2.2 Numerics
Using discretization schemes the Navier-Stokes equations are transformed form partial
differential equations to algebraic equations. Different schemes are available to discretize
convection, diffusion and gradient terms. They have different properties in terms of accuracy
and stability and should be choose properly with respect to the specific problem. First order
schemes are in general too diffusive and would under predict forces and gradients.
Laplacian schemes
Laplacian terms are computed using Gaussian integration over the cell. In order to perform the
Gaussian integration values of the gradients at Gauss points should be calculated first. These
values are calculated via interpolation schemes and using the data at cell and face centers.
An interpolation scheme should also be assigned to the chosen laplacian scheme, usually a
linear interpolation is chosen. Other available interpolation schemes include: cubicCorrection,
midPoint, upwind, linearUpwind, limitedLinear, vanLeer, etc.
DR
AF
T
2.2 Numerics
Figure 2.2: Drag coefficient as a function of Reynolds number for a smooth cylinder, from [2]
DR
AF
T
Gradient schemes
Gradient terms can be calculated by either Gauss integration or using leastSquares method.
Second and fourth order least square methods are available. In contrast to the Gauss
integration method, least square methods do not need an interpolation scheme. The schemes
available for discretizing gradient terms are listed in table 2.1. Gradient limiters can also be
used in discretizing gradient terms, they will avoid under shoots and over shoots in calculation
of the gradients. faceLimited schemes are in general more diffusive than cellLimited ones.
Divergence schemes
Similar to Laplacian schemes, Gauss integration is the only discretization method available
for discretizing convective terms. A proper interpolation method should be chosen. The
simplest method for calculating the divergence is the central difference scheme, which is
equivalent to Gauss integration with linear interpolator. This method is however not stable,
Discretization scheme
Description
Gauss <interpolationScheme>
Second order, Gaussian integration
leastSquares
Second order, least squares
fourth
Fourth order, least squares
cellLimited <gradScheme>
Cell limited version of one of the above schemes
faceLimited <gradScheme>
Face limited version of one of the above schemes
2.3 OpenFOAM
DR
AF
T
thus upwind scheme is normally used as the standard method for interpolation. Table 2.2
lists available interpolation schemes in OpenFOAM.
2.3 OpenFOAM
In the following the steps towards simulation of laminar flow around a cylinder are explained.
The schematic of the problem is presented in figure 2.4.
2.3.1 Preprocessing
Preprocessing mainly consists of preparing the blockMeshDict to generate the block-structured
mesh, setting the required boundary conditions in the 0 folder and setting the parameters in
linear
Second order, unbounded
skewLinear
Second order, (more) unbounded, skewness correction
cubicCorrected
Fourth order, unbounded
upwind
First order, bounded
linearUpwind
First/second order, bounded
QUICK
First/second order, bounded
TVD schemes
First/second order, bounded
SFCD
Second order, bounded
NVD schemes
First/second order, bounded
.
contolDict. Based on what you want to simulate you might also need to modify the schemes
used within the solver for discretizing and solving the governing PDEs which is done in
fvSchemes file in system directory.
Meshing
DR
AF
T
The mesh can be generated using different blocking strategies. Here we use four blocks to
generate an o-grid type mesh around the cylinder. A fifth block is attached to the o-grid
mesh to extend the domain in the downstream region of the flow, figure 2.5. The four edges
.
3 4, 4 6, 6 5 and 5 3 are straight lines by default. In order to represent cylinder
edges using them, they should be changed to arcs. It can be done in the edges section of the
blockMeshDict using arc command:
1
2
3
4
edges
(
arc 3 5 ( -1 0 0)
);
2.3 OpenFOAM
The first two numbers indicate the start and end point of the arc. Infinite number of circular
arcs can be defined between two points, we need a third point to specify the exact arc we
need. The coordinate of this third point follows after start and end point numbers in the arc
command, (1, 0, 0) in this case. There are other options for defining curved edges between
to vertices. Using splines for example, one can represent an airfoil profile using just 3 vertices
and defining 3 splines for edges connecting them. Available options for defining curved
edges in blockMeshDict are: arc, simpleSpline, PolyLine and polySpline. Their description is
available in OpenFOAM user guide.
Boundary conditions
DR
AF
T
Six patches are defined in this problem: inlet, outlet, top, bottom, cylinder, sides. Top and
bottom patches are defined to be far enough from the cylinder, they are defined as slip walls.
Since it is a 2D problem, side walls are defined in a single patch with type empty. The
boundary conditions used are summarized in table 2.3. The zeroGradient boundary condition
implies the gradient to be zero normal to the patch and slip is the same as zeroGradient
for scalar parameters while for vectors it implies fixedValue zero to the normal to the patch
component of the vector and zeroGradient to tangential components of the vector. Other
used boundary conditions are more or less self-explanatory. The magnitude of the velocity at
the inlet is set to a fixed value of 1m/s, to fulfill Re = 100 we can later play with dynamic
viscosity.
Table 2.3: Boundary conditions
BC
U
Patch
Boundary condition
inlet
fixedValue, uniform (1 0 0)
outlet
zeroGradient
cylinder fixedValue, uniform (0 0 0)
top
slip
bottom
slip
sides
empty
inlet
zeroGradient
outlet
fixedValue, uniform 0
cylinder
zeroGradient
top
zeroGradient
bottom
zeroGradient
sides
empty
controlDict
We have already explained the controlDict in our tutorial #3. Here we explain how to define
functions to calculate forces and force coefficients on a certain patch during run time. We
can later use these outputs to validate our simulation.
A function block can be defined at the end of controlDict. Functions perform a postprocessing step at the end of each time step. Different functions are available including:
faceZonesIntegration, fieldAverage, fieldMinMax, probes, etc.
DR
AF
T
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
forces
// given name
{
type
forces ;
functionObjectLibs ( " libforces . so " ) ;
outputControl
timeStep ;
outputInterval
10;
patches
pName
UName
rhoName
log
CofR
rhoInf
}
forceCoeffs: calculates lift, drag and pitching moment coefficients for a patch list.
These coefficients are defined as:
Cl =
10
L
1
2
AU
2
(2.3)
2.3 OpenFOAM
Cd =
CM =
(2.4)
1
2
AU
2
(2.5)
1
2 c
AU
2
To calculate the coefficients the reference area and reference length (for moment
coefficient) should be specified by the user. By definition, the lift force acts perpendicular
to the velocity vector and drag acts parallel to it. These directions as well as pitching
moment direction are declared in function block:
Listing 2.3: Definition of forceCoeff function in controlDict
forceCoeffs
{
type
functionObjectLibs
outputControl
outputInterval
forceCoeffs ;
( " libforces . so " ) ;
timeStep ;
10;
patches
pName
UName
rhoName
log
liftDir
dragDir
CofR
pitchAxis
(0
(1
(0
(0
magUInf
rhoInf
lRef
Aref
1;
1.225;
1;
2;
DR
AF
T
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
0
0
0
0) ;
0) ;
0) ;
1) ;
2.3.2 Solver
pisoFoam is a transient solver for incompressible flow. Both laminar and turbulent flows can
be simulated using pisoFoam. It is based on the PISO algorithm, which stands for Pressure
Implicit with Splitting of Operators, proposed by Issa in 1995. It is a pressure-velocity
coupling algorithm with a predictor step and two corrector steps. In the predictor step the
momentum equations are solved for an intermediate pressure field. The predicted velocity
field at this stage do not satisfy continuity condition. Then during the two predictor steps,
velocity and pressure fields are corrected in a way to fulfill both, momentum and continuity
equations. The PISO algorithm consists of the following steps:
11
DR
AF
T
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
if ( momentumPredictor )
{
solve ( UEqn == - fvc :: grad ( p ) ) ;
}
// --- PISO loop
12
2.3 OpenFOAM
DR
AF
T
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
13
Increase time
Yes
Correct non-orthogonality
No
Correct the velocity
Yes
DR
AF
T
No
No
14
2.3 OpenFOAM
Figure 2.7: Velocity distribution around the cylinder and the von Karman vortex street
Cl
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0
DR
AF
T
50
The next quantity to be validated is the frequency of vortex shedding. It can be done by
Fourier analysis of the forces acting on the cylinder. Using Fourier transform the amplitude of
different frequencies present in a signal (here lift coefficient) are calculated (figure 2.10). As
can be seen in the figure the oscillations in lift coefficient is dominated by a single frequency
at f = 0.084 Hz, which is the frequency at which vortices are being shed into the wake. The
corresponding Strouhal number can be calculated from equation 2.2:
St =
fL
0.084 2
=
= 0.168
V
1
(2.6)
It matches very well with the reported value of 0.17 from [3].
15
Cd
1.5
1.45
1.4
1.35
1.3
1.25
1.2
1.15
1.1
0
50
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
0.02
0
DR
AF
T
Amplitude
0.05
0.1
0.15 0.2
0.25
Frequency [Hz]
0.3
2.4 Exercise
Laminar pipe flow is another benchmark for laminar fluid flow. Use the same fluid setup, to
simulate laminar flow in pipes. Observe the development of velocity profile from the entrance
to the region of fully developed flow. The velocity profile, together with the entrance length
and pressure drop in the pipe could be good candidates to evaluate your results.
2.5 References
1. Sumer, B. Mutlu, et al. Hydrodynamics Around Cylindrical Structures. Singapore:
World Scientific, 2006
2. Fox, Robert W., et al. Introduction to Fluid Mechanics. Hoboken, NJ: Wiley, 2010
16
2.5 References
DR
AF
T
3. Durbin, Paul A., et al. Fluid Dynamics with a Computational Perspective. Cambridge:
Cambridge Univ. Press, 2007
17