OpenFOAM Multiphase Solver Guide
OpenFOAM Multiphase Solver Guide
• Incompressible flows
Description and utilization of interFoam multiphase solver
• Compressible flows
• Amongst the first major scientific packages written in C++ (other leading CFD compa-
2 Introduction to Volume of Fluid Theory. Surface recon-
nies have released or are working on next-generation C++ codes), struction strategies
• Use of C++ operator overloading to permit relatively simple, top-level human-readable
2.1 Finite Volume Method
descriptions of partial differential equations makes OpenFOAM akin to a programming
language for physical simulation, Respect of Finite Volume Method, among all the bibliography, books from Versteeg and
Malalasekera [4] and Ferziger and Peric [3] are the most referenced and authoritative. Fur-
• First major general-purpose CFD package to use polyhedral cells. This functionality is thermore Jasak’s PhD thesis [5] provides an excellent description of the method using com-
a natural consequence of the hierarchical description of simulation objects, pact and powerful vector and tensorial notation suitable for comprehension and implemen-
tation especially in the OpenFOAM’s frame.
• First and most capable general purpose CFD package to be released under an open-
source license,
Following is an annotated version of chapter 3 of Jasak’s PhD thesis. Original text is
between quotes and annotations are added as footnotes.
OpenFOAM compares favourably with the capabilities of most leading general-purpose
commercial closed-source CFD packages. It relies on the user’s choice of third party pre-
and post-processing utilities, and ships with: 2.1.1 Introduction
”The purpose of any discretisation practice is to transform one or more partial differential
• a plugin (paraFoam) for visualisation of solution data and meshes in ParaView.
equations into a corresponding system of algebraic equations. The solution of this system
• a wide range of mesh converters allowing import from a number of leading commercial produces a set of values which correspond to the solution of the original equations at some
packages pre-determined locations in space and time, provided certain conditions, to be defined later,
are satisfied. The discretisation process can be divided into two steps: the discretisation of
• an automatic hexahedral mesher to mesh engineering configurations the solution domain and equation discretisation ([[6], [5] ref. 97]).
OpenFOAM was conceived as a continuum mechanics platform but is ideal for building The discretisation of the solution domain produces a numerical description of the com-
multi-physics simulations. For example, it comes with a library and solvers for efficiently putational domain, including the positions of points in which the solution is sought and the
tracking particles in a multiphase flow using the lagrangian approach. description of the boundary. The space is divided into a finite number of discrete regions,
called control volumes or cells. For transient simulations, the time interval is also split into
Standard Solvers include: a finite number of time-steps. Equation discretisation gives an appropriate transformation
1 2
governing equations are subsequently solved. It also determines the positions of
points in space and time where the solution is sought. The procedure can be split
into two parts: discretisation of time and space.
of terms of governing equations into algebraic expressions.
z N
This [section] presents the Finite Volume method (FVM) of discretisation, with the fol- S
x
lowing properties:
• The method is based on discretising the integral form of governing equations over each f
control volume. The basic quantities, such as mass and momentum, will therefore be
conserved at the discrete level. P
• Equations are solved in a fixed Cartesian coordinate system on the mesh that does not
change in time. The method is applicable to both steady-state and transient calculations.
• The control volumes can be of a general polyhedral shape, with a variable number of
neighbours, thus creating an arbitrarily unstructured mesh. All dependent variables
share the same control volumes, which is usually called the colocated or non-staggered
variable arrangement ([See [5] refs. 117 and 109]). Figure 3.1: Control volume.
Figure 1: Control volume
• Systems of partial differential equations are treated in the segregated way ([See [5]
refs. 107 and 137]), meaning that they are solved one at a time, with the inter-equation Since time is a parabolic coordinate (Patankar [105]), the solution is obtained
coupling treated in the explicit manner. Non-linear differential equations are linearised centroid of the control volumes1 , such that:
by marching in time from the prescribed
Z initial condition. For the discretisation of
before the discretisation and the non-linear terms are lagged.
(x − xPthe
time, it is therefore sufficient to prescribe ) dVsize
= 0of the timestep that will be used (1)
VP
during
The the volume
control calculation.
is bounded by a set of flat faces and each face is shared with only
[. . . ] one neighbouring CV. The topology of the
The discretisation of space for thecontrol
Finite volume
Volume ismethod
not important
used in–this
it is study
a general
polyhedron.
requires a subdivision of the domain into control volumes (CV). Control volumes do
The cell faces in the mesh can be divided into two groups – internal faces (between two
2.1.2 Discretisation of the Solution Domain control volumes) and boundary faces, which coincide with the boundaries of the domain.
The face area vector S f is constructed for each face in such a way that it points outwards from
Discretisation of the solution domain produces a computational mesh on which the govern- the cell with the lower label, is normal to the face and has the magnitude equal to the area of
ing equations are subsequently solved. It also determines the positions of points in space and the face. The cell with the lower label is called the ’owner’ of the face – its label is stored in
time where the solution is sought. The procedure can be split into two parts: discretisation the ’owner’ array. The label of the other cell (’neighbour’) is stored in the ’neighbour’ array.
of time and space. Boundary face area vectors point outwards from the computational domain – boundary faces
1
By definition centroid position implies:
Since time is a parabolic coordinate ([7]), the solution is obtained by marching in time
Z
from the prescribed initial condition. For the discretisation of time, it is therefore sufficient
VP x P = x dV
to prescribe the size of the time-step that will be used during the calculation. VP
3 4
are ’owned’ by the adjacent cells. For the shaded face in Fig. 1, the owner and neighbour
cell centres are marked with P and N , as the face area vector S f points outwards from the P
1
control volume. For simplicity, all faces of the control volume will be marked with f , which φ (x) = φP + (x − xP ) • ∇φ + (x − xP )2 : ∇∇φ
also represents the point in the middle of the face (see Fig. 1).
P 2 P
1 3
+ (x − xP ) :: ∇∇∇φ
The capability of the discretisation practice to deal with arbitrary control volumes gives 3! P
considerable freedom in mesh generation. It is particularly useful in meshing complex
1
geometrical configurations in three spatial dimensions. Arbitrarily unstructured meshes + . . . + (x − xP ) ::: ∇∇ . . . ∇ φ + . . .
n
(7)
n! |{z} | {z }
also interact well with the concept of local grid refinement, where the computational points n n P
are added in the parts of the domain where high resolution is necessary, without disturbing
n
the rest of the mesh. The expression (x − xP ) in Eqn. (7) and consequent equations in this study represents
the nth tensorial product of the vector (x − xP ) with itself, producing an nth rank tensor. The
operator ’:::’ is the inner product of two nth rank tensors, creating a scalar.
2.1.3 Discretisation of the Transport Equation
The standard form of the transport equation for a scalar property φ is: Comparison between the assumed variation, Eqn. (3), and the Taylor series
expansion,
Eqn. (7), shows that the first term of the truncation error scales with (x − xP )2 , which is for
∂ρφ a 1-D situation equal to the square of the size of the control volume. The assumed spatial
+ ∇• ρUφ − ∇• ρΓφ ∇φ = Sφ φ (2) variation is therefore second-order accurate in space. An equivalent analysis shows that the
∂t | {z } | {z } |{z}
|{z} truncation error in Eqn. (4) scales with ∆t2 , resulting in the second-order temporal accuracy.
temporal derivative convection term diffusion term source term
This is a second-order equation, as the diffusion term includes the second derivative of The Finite Volume method requires that Eqn. (2) is satisfied over the control volume VP
φ in space. For good accuracy, it is necessary for the order of the discretisation to be equal to around the point P in the integral form:
or higher than the order of the equation that is being discretised. The discretisation practice
adopted in this study is second-order accurate in space and time and will be presented in the Z t+∆t " Z Z Z #
∂
rest of this [section]. The individual terms of the transport equation will be treated separately. ρφ dV + ∇• ρUφ dV − ∇• ρΓφ ∇φ dV dt
t ∂t VP VP VP
In certain parts of the discretisation it is necessary to relax the accuracy requirement, either Z t+∆t Z !
to accommodate for the irregularities in the mesh structure or to preserve the boundedness = Sφ φ dV dt (8)
t VP
of the solution . Any deviation from the prescribed order of accuracy creates a discretisation
error, which is of the order of other terms in the original equation and dissappers only in the The discretisation of Eqn. (8) will now be examined term by term.
limit of excessively fine mesh. Particular attention will therefore be paid to the sources of
discretisation error representing such behaviour.
2.1.4 Discretisation of Spatial Terms
The accuracy of the discretisation method depends on the assumed variation of the Let us first examine the discretisation of spatial terms. The generalised form of Gauss’
function φ = φ (x, t) in space and time around the point P . In order to obtain a second-order theorem will be used throughout the discretisation procedure, involving these identities:
accurate method, this variation must be linear in both space and time, i.e. it is assumed that:
Z I
φ (x) = φP + (x − xP ) • ∇φ (3) ∇•a dV = a•dS (9)
P V ∂V
Z I
!t
∂φ ∇φ dV = φ dS (10)
φ (t + ∆t) = φt + ∆t (4) V ∂V
∂t
Z I
where ∇a dV = a ⊗ dS (11)
V ∂V
φP = φ (xP ) (5) where ∂V is the closed surface bounding the volume V and dS represents an infinitesimal
surface element with associated outward pointing normal on ∂V.
φt = φ (t) (6)
A series of volume and surface integrals needs to be evaluated. Taking into account the
Let us consider the Taylor series expansion in space of a function around the point x: prescribed variation of φ over the control volume P , Eqn. (3), it follows:
5 6
area vector S f point outwards from P only if f is ’owned’ by P . For the ’neighbouring’ faces
Z Z h i S f points inwards, which needs to be taken into account in the sum in Eqn. (15). The sum
φ (x) dV = φP + (x − xP ) • ∇φ dV over the faces is therefore split into sums over ’owned’ and ’neighbouring’ faces:
P
VP VP
Z "Z # X X X
= φP dV + (x − xP ) dV • ∇φ S•a f = S f •a f − S f •a f (16)
P owner
VP VP f neighbour
= φP VP (12)
This is true for every summation over the faces. In the rest of the text, this split is
where VP is the volume of the cell. The second integral in Eqn. (3) is equal to zero because automatically assumed.
the point P is the centroid of the control volume.
Convection term The discretisation of the convection term is obtained using Eqn. (15):
Let us now consider the terms under the divergence operator. Having in mind that the
CV is bounded by a series of flat faces, Eqn. (9) can be transformed into a sum of integrals
Z X
over all faces:
∇• ρUφ dV = S• ρUφ
f
VP f
Z I X
∇•adV = a•dS = S• ρU f φ f
VP ∂VP f
X Z ! X
= a•dS (13) = F φf (17)
f f f
The assumption of linear variation of φ leads to the following expression for the face where F in Eqn. (17) represents the mass flux through the face:
integral in Eqn. (13)2 :
F = S• ρU f (18)
Z Z ! "Z #
adS = dS •a f + x − x f dS : (∇a) f The calculation of these face fluxes will later be discussed separately in Section 2.1.8. For
f f f
now it can be assumed that the flux is calculated from the interpolated values of ρ and U4 .
= S•a f (14)
Eqs. (17 and 18) also require the face value of the variable φ calculated from the values
Combining Eqs. (12, 13 and 14), a second-order accurate discretised form of the Gauss’
in the cell centres, which is obtained using the convection differencing scheme.
theorem is obtained3 :
X Before we continue with the formulation of the convection differencing scheme, it is
(∇•a) VP = S•a f (15)
necessary to examine the physical properties of the convection term. Irrespective of the
f
distribution of the velocity in the domain, the convection term does not violate the bounds
Here, the subscript f implies the value of the variable (in this case, a) in the middle of the of φ given by its initial distribution. If, for example, φ initially varies between 0 and 1, the
face and S is the outward-pointing face area vector. In the current mesh structure, the face convection term will never produce the values of φ that are lower than zero or higher than
2
In the first term of right hand side, expresion a f is taken off the integral symbol due it is constant, it is the
unity. Considering the importance of boundedness in the transport of scalar properties of
value at the centroid of the face. interest [. . . ]5 , it is essential to preserve this property in the discretised form of the term.
3
Starting with Gauss’ theorem for a continuum we have:
Z I
∇•a dV = a•dS Convection Differencing Scheme The role of the convection differencing scheme is to de-
V ∂V termine the value of φ on the face from the values in the cell centres. In the framework of
applying equation 12 to left hand side term and 14 to right hand side term: arbitrarily unstructured meshes, it would be impractical to use any values other than φP and
X φN , because of the storage overhead associated with the additional addressing information.
∇•a VP = S•a f
f
We shall therefore limit ourselves to differencing schemes using only the nearest neighbours
of the control volume.
another useful relation is
P
f S•a f
4
∇•a = These are interpolated values at the faces.
VP 5
See Section 1.2.1 of Jasak’s thesis
7 8
the storage overhead associated with the additional addressing information. We shall
introduced. Perić [109] proposes a constant γ for all faces of the mesh. For γ = 0
therefore limit ourselves to differencing schemes using only the nearest neighbours
the scheme reduces to UD.
of the control volume.
Many
or
other attempts to find an acceptable compromise between accuracy and
φN boundedness have been made (see Section 1.2.1). The most promising approach at
φ f = 1 − γ max
this stage combines a higherorder sgn (F) , 0 +Upwind
γ fx φP Differencing on a faceby
scheme with
φf + 1 − γ min sgn (F) , 0 + γ 1 − fx φN (23)
φP face basis, based on different boundedness criteria. We shall return to the issues
The blending factor γ, 0 ≤ γ ≤ 1, determines how much numerical diffusion will be
d of boundedness,
introduced. Pericaccuracy
([See [5] ref.and
109])convergence of convection
proposes a constant differencing
γ for all faces schemes
of the mesh. For γ = 0 in
the scheme reduces to UD.
P f N Section 3.4.
Many other attempts to find an acceptable compromise between accuracy and bound-
Figure3.2:
Figure 2: Face interpolation
Face interpolation. edness have been made [. . . ]7 . The most promising approach at this stage combines a
3.3.1.3 Diffusion
higher-order Term
scheme with Upwind Differencing on a face-by-face basis, based on different
boundedness criteria8 .
Assuming the linear variation of φ between P and N , Fig. 2, the face value is calculated The diffusion term will be discretised in a similar way. Using the assumption of
according
Assuming to: the linear variation of φ between P and N , Fig. 3.2, the face value is Diffusion term The diffusion term will be discretised in a similar way. Using the assump-
linear
tion variation of φ and
of linear variation of φEqn. (3.15),
and Eqn. itfollows:
15), it follows:
calculated according to: φ f = fx φP + 1 − fx φN (19) � �
Z∇•(ρΓ ∇φ) dV = X S.(ρΓ
Here, the interpolation factorφffx =
is defined
fx φP +as(1the−ratio
fx )φofN distances
. f N and PN : (3.19) φ φ ∇φ)
f
VP ∇• ρΓφ ∇φ dV = f
S• ρΓφ ∇φ
f
VP
fN �
f
X
fx = (20)
PN =
= (ρΓ
ρΓ φ φ )Sf S.(∇φ)
∇φ f. (3.24)
(24)
f f
ff
The differencing scheme using Eqn. (19) to determine the face value of φ is called Central
Differencing (CD). Although this has been the subject of some debate, Ferziger and Peric [3] If the mesh is orthogonal, i.e. vectors d and S in Fig. 3.3 are parallel, it is possible
show that it is second order accurate even on non-uniform meshes. This is consistent with
the overall accuracy of the method. It has been noted, however, that CD causes unphysical
oscillations in the solution for convection-dominated problems ([7], [6]), thus violating the S
boundedness of the solution.
Boundedness of the solution is guaranteed through the sufficient boundedness criterion Figure3.3:
3: Vector d and S on
Figure Vectors d and S aonnon-orthogonal mesh
a nonorthogonal mesh.
for systems of algebraic equations (see e.g. [7]). [. . . ], boundedness of UD is effectively
insured at the expense of the accuracy, by implicitly introducing the numerical diffusion
term6 . This term violates the order of accuracy of the discretisation and can severely distort If the mesh is orthogonal, i.e. vectors d and S in Fig. 3 are parallel, it is possible to use
the solution.
to usefollowing
the expression:
the following expression:
Blended Differencing (BD) ([See [5] ref. 109]) represents an attempt to preserve both φN − φP
S• ∇φ = |S| φN − φP (25)
boundedness and accuracy of the solution. It is a linear combination of UD, Eqn. (19) and S.(∇φ)f f = |S| |d| . (3.25)
CD, Eqn. (19): |d|
Using Eqn. (25), the face gradient of φ can be calculated from the two values around the
face.Eqn.
Using An alternative
(3.25), would be togradient
the face calculate the
of φcell-centred gradient for the
can be calculated twothe
from cellstwo
sharing
values
φf = 1 − γ φf + γ φf (22)
UD CD
7
around Seethe
Jasak’s thesisAn
face. Section 1.2.1
alternative would be to calculate the cellcentred gradient for
6 8
See Jasak’s thesis section 3.6 See Jasak’s thesis Section 3.4
9 10
the face as9 : The two vectors introduced in Eqn. (28), ∆ and k, have got to satisfy the following
condition:
1 X
∇φ = Sφ f (26)
P VP S=∆+k (29)
f
interpolate it to the face: Vector ∆ is chosen to be parallel with d. This allows us to use Eqn. (25) on the orthogonal
contribution, limiting the less accurate method only to the non-orthogonal part which cannot
be treated in any other way.
∇φ = fx ∇φ + 1 − fx ∇φ (27)
f P N
and dot it with S. Although both of the above-described methods are second-order ac- Many possible decompositions exist and we will examine three:
curate, Eqn. (27) uses a larger computational molecule10 . The first term of the truncation
error is now four times larger than in the first method, which in turn cannot be used on • Minimum correction approach. The decomposition of S, Fig. 4, is done in such a way
non-orthogonal meshes. to keep the non-orthogonal correction in Eqn. (28) as small as possible, by making ∆
and k orthogonal:
Unfortunately, mesh orthogonality is more an exception
than a rule. In order to make
use of the higher accuracy of Eqn. (25), the product S• ∇φ is split into two parts: d•S
f ∆= d (30)
d•d
S• ∇φ = ∆• ∇φ + k• ∇φ (28) with k calculated from Eqn. (29). As the non-orthogonality increases, the contribution
f f f
| {z } | {z } from φP and φN decreases.
orthogonal contribution non-orthogonal correction 3.3
3.3 Discretisation
Discretisation of
of the
the Transport
Transport Equation
Equation 85
85
9
By Gauss’ theorem
Z I
∇φ dV = φ dS
VP ∂V S
S
X k
k
∇φ VP = Sφ d
d
f
1 X P
P f
f ∆
∆ N
N
∇φ = Sφ
VP
f
10
Taking in account that to calculate gradient by 27 equation it is necessary to know all face values in cell P
and N, it implies interpolate this values using second neighbours.
According Eqn. 27 for gradient calculation is necessary to do sum in Eqn. 26 for cell N, this sum uses φ fPN , φ fNNn ,
φ fNNe , φ fNNs values. Last three of them requires second neighbours for its calculation, for example to calculate Figure
Figure
Figure 3.4:4:Nonorthogonality
3.4: Non-orthogonalitytreatment
Nonorthogonality treatmentin
treatment ininthe
the“minimum
the ’minimum correction”
“minimum correction’ approach
correction” approach.
approach.
φ fNNe , it is neccesary to use φN and φNe values.
S
Nn
S k
k
fNNn d
d
P
P f
f ∆
∆ N
P
fPN
N
fNNe
Ne
N
fNNs
Ns
Figure 3.5:
Figure Nonorthogonality treatment
3.5: Nonorthogonality treatment in
in the
the “orthogonal
“orthogonal correction”
correction” approach.
approach.
Figure 5: Non-orthogonality treatment in the ’orthogonal correction’ approach
11
•• Orthogonal
Orthogonal correction
correction approach. This approach keeps the contribution
12 This approach keeps the contribution
approach.
from φPP and
from φ and φ
φN the same as on the orthogonal mesh irrespective of the non
N the same as on the orthogonal mesh irrespective of the non
Figure 3.5: Nonorthogonality treatment in the “orthogonal correction” approach.
• Orthogonal correction approach. This approach keeps the contribution from φP and The face interpolate of ∇φ is calculated using Eqn. (27)13
φN the same as on the orthogonal mesh irrespective of the non-orthogonality, Fig. 5.
• To achieve thiscorrection
Orthogonal we define: approach. This approach keeps the contribution Source Terms All terms of the original equation that cannot be written as convection, dif-
from φP and φN the same as on the orthogonal mesh irrespective of the non fusion or temporal terms are treated as sources. The source term, Sφ φ , can be a general
d function of φ. When deciding on the form of the discretisation for the source, its interaction
∆= |S| (31)
|d| with other terms in the equation and its influence on boundedness and accuracy should be
orthogonality, Fig. 3.5. To achieve this we define:
• Over-relaxed approach. In this approach, the importance of the term in φP and φN is examined. Some general comments on the treatment of source terms are given in Patankar
caused to increase with the increase in non-orthogonality: [7]. A simple procedure will be explained here.
d
Δ= |S|. (3.31)
|d| Before the actual discretisation, the source term needs to be linearised:
d
∆= |S|2 (32)
d•S
Sφ φ = Su + Sp φ (36)
• Overrelaxed approach.
The decomposition In this
of the face area vectorapproach,
is shown inthe
Fig. importance
6. of the term in where Su and Sp can also depend on φ. Following Eqn. (3.12), the volume integral is
calculated as:
Z
Sφ φ dV = Su VP + Sp VP φP (37)
S k VP
13 14
The above expression is usually called the ’semi-discretised’ form of the transport equa- equation for the control volume, Eqn. (43).
tion ([6]).
When this system is solved, it gives a new set of φ values – the solution for the new time-
Having in mind the prescribed variation of the function in time, Eqn. (4), the temporal step. As will be shown later, the coefficient aP in Eqn. (43) includes the contribution from all
integrals and the time derivative can be calculated directly as: terms corresponding to φn – the temporal derivative, convection and diffusion terms as well
! as the linear part of the source term. The coefficients aN include the corresponding terms
∂ρφ ρnP φnP − ρ0P φ0P for each of the neighbouring points. The summation is done over all CV-s that share a face
= (39)
∂t P
∆t with the current control volume. The source term includes all terms that can be evaluated
Z without knowing the new φ’s, namely, the constant part of the source term, and the parts of
t+∆t
1 0 the temporal derivative, convection and diffusion terms corresponding to the old time-level.
φ (t) = φ + φn ∆t (40)
t 2
The Crank-Nicholson method of temporal discretisation is unconditionally stable ([6]),
where
but does not guarantee boundedness of the solution. Examples of unrealistic solutions given
by the Crank-Nicholson scheme can be found in Patankar and Baliga [See [5] ref. 106]. As in
φn = φ (t + ∆t) the case of the convection term, boundedness can be obtained if the equation is discretised
to first order temporal accuracy.
φ0 = φ (t) (41)
It has been customary to neglect the variation of the face values of φ and ∇φ in time ([7]).
Assuming that the density and diffusivity do not change in time, Eqs. (38, 39 and 40) This leads to several methods of temporal discretisation. The new form of the discretised
give: transport equation combines the old and new time-level convection, diffusion and source
terms, leaving the temporal derivative unchanged:
ρP φnP − ρP φ0P 1X n 1 n
VP + Fφ f − ρΓφ S• ∇φ X X
∆t 2 2 f f ρP φnP − ρP φ0P
f VP + Fφ f − ρΓφ S• ∇φ
f f
1X 0 1 0 ∆t
f f
+ Fφ f − ρΓφ S• ∇φ
2 2 f f = Su VP + Sp VP φP (45)
f
1 1 The resulting equation is only first-order accurate in time and a choice has to be made
= Su Vp + Sp VpφnP + Sp Vpφ0P (42)
2 2 about the way the face values of φ and ∇φ are evaluated.
This form of temporal discretisation is called the Crank-Nicholson method. It is second-
In explicit discretisation, the face values of φ and ∇φ are determined from the old
order accurate in time. It requires the face values of φ and ∇φ as well as the cell values for
time-field:
both old and new time-level. The face values are calculated from the cell values on each side
of the face, using the appropriate differencing scheme for the convection term, and Eqn. (34)
φ f = fx φ0P + 1 − fx φ0N (46)
for diffusion. The evaluation of the non-orthogonal correction term will be discussed
later
(see Section 2.1.7). Our task is to determine the new value of φP . Since φ f and ∇φ also
f φ0 − φ0P 0
depend on values of φ in the surrounding cells, Eqn. (42) produces an algebraic equation: S• ∇φ = |∆| N + k• ∇φ (47)
f |d| f
X
aP φnP + aN φnN = RP (43) The linear part of the source term is also evaluated using the old-time value. Eqn. (45)
N
can be written in the form:
For every control volume, one equation of this form is assembled. The value of φnP depends
∆t X X
on the values in the neighbouring cells, thus creating a system of algebraic equations: n 0
φP = φP + Fφ f − ρΓφ S• ∇φ + Su VP + Sp VP φP
0
(48)
ρP VP f f
h i f f
[A] φ = [R] (44) The consequence of this choice is that all terms on the r.h.s. of Eqn. (48) depend only on
the old-time field. The new value of φP can be calculated directly – it is no longer necessary
h i where [A] is a sparse matrix, with coefficients aP on the diagonal and aN off the diagonal, to solve the system of linear equations. The drawback of this method is the Courant number
φ is the vector of φ-s for all control volumes and [R] is the source term vector. The sparse-
limit (Courant et al. [See [5] ref. 32]). The Courant number is defined as:
ness pattern of the matrix depends on the order in which the control volumes are labelled,
with every off-diagonal coefficient above and below the diagonal corresponding to one of U f •d
the faces in the mesh. In the rest of this study, Eqn. (44) will be represented by the typical Co = (49)
∆t
15 16
If the Courant number is larger than unity, the explicit system becomes unstable. This is
a severe limitation, especially if we are trying to solve a steady-state problem. 3 X X
ρ φn
2 P
− 2ρP φ0 + 12 ρP φ00 n
VP + Fφnf − ρΓφ S• ∇φ
The Euler Implicit method expresses the face-values in terms of the new time-level cell ∆t f
f f
values:
= Su VP + Sp VP φnP (56)
φf = fx φnP + 1− fx φnN (50) This produces a system of algebraic equations that must be solved for φPn .
φn − φnP Steady-state problems are quite common in fluid flows. Their characteristic is that the
S• ∇φ = |∆| N + k• ∇φ (51)
f |d| f solution is not a function of time, i.e. the transport equation reduces to:
This is still only first order accurate but, unlike the explicit method, it creates an system
of equations like Eqn. (43). The coupling in the system is much stronger than in the explicit ∇• ρ∇φ − ∇• ρΓφ ∇φ = Su + Sp φ (57)
approach and the system is stable even if the Courant number limit is violated ([6]). Unlike If we are solving a single equation of this type, the solution can be obtained in a single step.
the explicit method, this form of temporal discretisation guarantees boundedness. This is generally not the case: fluid flow problems require a solution of non-linear systems
of coupled equations. If the non-linearity of the system is lagged, which is the case in the
Backward Differencing in time is a temporal scheme which is second-order accurate in segregated approach used in this study, it is still necessary to solve the system in an iterative
time and still neglects the temporal variation of the face values. In orderto achieve this, each manner. In order to speed up the convergence, an implicit formulation is preferred. The
individual term of Eqn. (38) needs to be discretised to second order accuracy. convergence of the iterative procedure can be improved through under-relaxation, which
will be described in Section 2.1.7
The discretised form of the temporal derivative in Eqn. (45) can be obtained in the
following way: consider the Taylor series expansion of φ in time around φ (t + ∆t) = φn : 2.1.6 Implementation of Boundary Conditions
∂φ 1∂ φ 2 Let us now consider the implementation of boundary conditions. The computational mesh
φ (t) = φ0 = φn −∆t + + o ∆t3 (52)
∂t 2 ∂t2 includes a series of faces which coincide with the boundaries of the physical domain under
The temporal derivative can therefore be expressed as: consideration. The conditions there are prescribed through the boundary conditions.
∂φ φn − φ0 1 ∂2 φ In order to simplify the discussion, the boundary conditions are divided into numerical
= + ∆t + o ∆t2 (53)
∂t ∆t 2 ∂t2 and physical boundary conditions.
In spite of the prescribed linear variation of φ in time, Eqn. (39) approximates the tempo-
ral derivative only to first order accuracy, since the first term of the truncation error in Eqn. There are two basic types of numerical boundary conditions. Dirichlet (or fixed value)
(53) scales with ∆t. However, if the temporal derivative is discretised up to second order, boundary condition prescribes the value of the variable on the boundary. Von Neumann
the whole discretisation of the boundary condition, on the other hand, prescribes the gradient of the variable normal to the
transport
equation will be second-order accurate even if the
boundary. These two types of boundary conditions can be built into the system of algebraic
temporal variation of φ f and ∇φ is neglected.
f equations, Eqn. (43), before the solution.
In order to achieve this, the Backward Differencing in time uses three time levels. The
Physical boundary conditions are symmetry planes, walls, inlet and outlet conditions for
additional Taylor series expansion for the ’second old’ time level is:
fluid flow problems, adiabatic or fixed temperature boundaries for heat transfer problems
δφ δ2 φ 2 etc. Each of these conditions is associated with a set of numerical boundary conditions on
φ (t − ∆t) = φ00 = φn − 2
∆t + 2 ∆t + o ∆r3 (54) each of the variables that is being calculated. Some more complicated boundary conditions
δt δt
(radiation boundaries, for example) may specify the interaction between the boundary value
It is now possible to eliminate the term in the truncation error which scales with ∆t.
and the gradient on the boundary.
Combining Eqs. (52 and 54) the second-order approximation of the temporalderivative is:
∂φ 3
− 2φ0 + 12 φ00 Numerical Boundary Conditions Before we consider the implementation of numerical
= 2 (55) boundary conditions, we have to address the treatment of non-orthogonality on the bound-
∂t ∆t
ary. Consider a control volume with a boundary face b, shown in Fig. 7. In this situation,
Again, the boundedness of the solution cannot be guaranteed [. . . ]14 . The final form of
the vector d extends only to the centre of the boundary face.
the discretised equation with Backward Differencing in time is:
14
For a comparison between the Backward Differencing and the Crank-Nicholson method see Jasak’s thesis It is assumed that a boundary condition specified for the boundary face is valid along
Section 3.6 the whole of the face. The decomposition of the face area vector into the orthogonal and
17 18
volume with a boundary face b, shown in Fig. 3.7. In this situation, the vector d
The face gradient at b is calculated from the known face value and the cell centre value:
φb − φP
P S• ∇φ = |S| (62)
d b |dn |
dn b because S and dn are parallel.
Physical Boundary Conditions Let us now consider some physical boundary conditions
It is known that the value of φ on the boundary face is φb . Therefore, the term for the for fluid flow calculations. For simplicity, we shall start with the incompressible flow.
boundary face is:
• Inlet boundary. The velocity field at the inlet is prescribed and, for consistency, the
Fb φb (60) boundary condition on pressure is zero gradient ([6]).
• Outlet boundary. The outlet boundary condition should be specified in such a way
wher Fb is the face flux. that the overall mass balance for the computational domain is satisfied.
Diffusion term. The diffusion term is discretised according to Eqn.(24).
This can be done in two ways:
Z X
∇• ρΓφ ∇φ dV = ρΓφ S• ∇φ (61) 15
However, an of the same type is neglected for the internal faces of the mesh and this correction is omitted
f f
VP f for the sake of consistency, see Jasak’s thesis Section 3.6
19 20
The velocity distribution for the boundary is projected from the inside of the domain make the use of iterative solvers very attractive.
(first row of cells next to the boundary). These velocities are scaled to satisfy overall
continuity. This approach, however, leads to instability if inflow through a boundary Iterative solvers require diagonal dominance in order to guarantee convergence. A ma-
specified as outlet occurs. The boundary condition on pressure is again zero gradient. trix is said to be diagonally equal if the magnitude of the diagonal (central) coefficient is
The other approach does not require the velocity distribution across the outlet – the equal to the sum of magnitudes of off-diagonal coefficients. The additional condition for
pressure distribution is specified instead. The fixed value boundary condition is used diagonal dominance is that |aP | > |aN | for at least one row of the matrix.
for the pressure, with the zero gradient boundary condition on velocity. Overall mass
conservation is guaranteed by the pressure equation [. . . ]16 . In order to improve the solver convergence, it is desirable to increase the diagonal domi-
nance of the system. Discretisation of the linear part of the source term, Eqn. (37), is closely
• Symmetry plane boundary. The symmetry plane boundary condition implies that related to this issue. If Sp < 0, its contribution increases diagonal dominance and Sp is
the component of the gradient normal to the boundary should be fixed to zero. The included into the diagonal. In the case of Sp > 0, diagonal dominance would be decreased.
components parallel to it are projected to the boundary face from the inside of the It is more effective to include this term into the source and update it when the new solution
domain. is available. This measure is, however, not sufficient to guarantee the diagonal dominance
• Impermeable no-slip walls. The velocity of the fluid on the wall is equal to that of of the matrix.
the wall itself, so the fixed value boundary conditions prevail. As the flux through the
solid wall is known to be zero, the pressure gradient condition is zero gradient. The analysis of the structure of the matrix brings us back to the issue of boundedness.
The sufficient boundedness criterion for systems of algebraic equations mentioned in Sec-
Compressible flows at low Mach numbers are subject to the same approach as above. tion 2.1.4 states that the boundedness of the solution will be preserved for diagonally equal
The situation is somewhat more complex in case of transonic and supersonic flows – the systems of equations with positive coefficients. This allows us to examine the discretised
number of boundary conditions fixed at the inlet and outlet depends on the number of char- form of all the terms in the transport equation from the point of view of boundedness and
acteristics pointing into the domain. For these cases the reader is referred to [6] or [5] ref. 135. diagonal dominance and identify the troublesome parts of discretisation.
For turbulent flows, the inlet and outlet boundary conditions on turbulence variables (k The convection term creates a diagonally equal matrix only for Upwind Differencing.
and , for example) are typically assigned to fixed values and zero gradients, respectively. Any other differencing scheme will create negative coefficients, violate the diagonal equality
The boundary conditions for the turbulence properties on the wall depend on the form of and potentially create unbounded solution. In the case of Central Differencing on a uniform
the selected turbulence model and the near-wall treatment. mesh, the problem is further complicated by the fact that the central coefficient is equal to
zero. In order to improve the quality of the matrix for higher-order differencing schemes,
2.1.7 Solution Techniques for Systems of Linear Algebraic Equations Khosla and Rubin (See [[5] ref. 73]) propose a deferred correction implementation for the
convection term. Here, any differencing scheme is treated as an upgrade of UD. The part of
Let us again consider the system of algebraic equations created by the discretisation, Eqn.
the convection term corresponding to UD is treated implicitly (i.e. built into the matrix)
(43):
and the other part is added into the source term. This, however, does not affect the bound-
X edness in spite of the fact that the matrix is now diagonally equal, as the ’troublesome’ part
aP φnP + aN φnN = RP
of the discretisation still exists in the source term.
N
This system can be solved in several different ways. Existing solution algorithms fall into
The diffusion term creates a diagonally equal matrix only if the mesh is orthogonal. On
two main categories: direct and iterative methods. Direct methods give the solution of the
non-orthogonal meshes, the second term in Eqn. (34) introduces the ’second neighbours’ of
system of algebraic equations in a finite number of arithmetic operations. Iterative methods
the control volume into the computational molecule with negative coefficients, thus violat-
start with an initial guess and then continue to improve the current approximation of the so-
ing diagonal equality. As a consequence of mesh non-orthogonality, the boundedness of the
lution until some ’solution tolerance’ is met. While direct methods are appropriate for small
solution cannot be guaranteed. The increase in the computational molecule would result
systems, the number of operations necessary to reach the solution raises with the number
in a higher number of non-zero matrix coefficients, implying a considerable increase in the
of equations squared, making them prohibitively expensive for large systems (See [[5] ref.
computational effort re-quired to solve the system. On the other hand, the non-orthogonal
97]). Iterative methods are more economical, but they usually pose some requirements on
correction is usually small compared to the implicit part of the diffusion term. It is therefore
the matrix.
reasonable to treat it through the source term. In this study, the diffusion term will therefore be
split into the implicit orthogonal contribution, which includes only the first neighbours of the cell
The matrix resulting from Eqn. (43) is sparse – most of the matrix coefficients are equal to
and creates a diagonally equal matrix and the non-orthogonal correction, which will be added to the
zero. If it were possible to choose a solver which preserves the sparsity pattern of the matrix,
source. If it is important to resolve the non-orthogonal parts of the diffusion operators (like
the computer memory requirements would be significantly decreased. Unlike direct solvers,
in the case of the pressure equation, see 2.1.8), non-orthogonal correctors are included. The
some iterative methods preserve the sparseness of the original matrix. These properties
system of algebraic equations, Eqn. (43), will be solved several times. Each new solution will
16
See Section 2.1.8 be used to update the non-orthogonal correction terms, until the desired tolerance is met.
21 22
It should again be noted that this practice only improves the quality of the matrix but does Here, φ0P here represents the value of φ from the previous iteration and α is the under-
not guarantee boundedness. If boundedness is essential, the non-orthogonal contribution relaxation
factor (0 < α ≤ 1). Additional terms cancel out when steady-state is reached
should be discarded, thus creating a discretisation error [. . . ]17 . φnP = φ0P .
At this point, the difference between the non-orthogonality treatments proposed in Sec- In this study, the iterative solution procedure used to solve the system of algebraic
tion [Diffusion Term] becomes apparent. The decomposition of the face area vector into the equations is the Conjugate Gradient (CG) method, originally proposed by Hestens and
orthogonal and non-orthogonal part determines the split between the implicit and explicit Steifel ([See [5] ref. 63]). It guarantees that the exact solution will be obtained in the number
part of the term, with the consequences on the accuracy and convergence of non-orthogonal of iterations smaller or equal to the number of equations in the system. The convergence rate
correctors. The comparison of different treatments is based on several criteria: of the solver depends on the dispersion of the eigenvalues of the matrix [A] in Eqn. (44) and
and can be improved through pre-conditioning. For symmetric matrices, the Incomplete
• On which angle of non-orthogonality is it necessary to introduce non-orthogonal cor- Cholesky preconditioned Conjugate Gradient (ICCG) solver will be used. The method is
rectors – how good an approximation of the converged solution can be obtained after described in detail by Jacobs, ([See [5] ref. 67]). The adopted solver for asymmetric matrices
only one solution of the system? is the Bi-CGSTAB by van der Vorst ([See [5] ref. 136]).
• How many non-orthogonal correctors are needed to meet a certain tolerance?
2.1.8 Discretisation Procedure for the Navier-Stokes System
• How does the number of solver iterations change with the number of correctors?
In this Section, a discretisation procedure for the Navier-Stokes equations will be presented.
• If the non-orthogonal correction needs to be discarded for the sake of boundedness, We shall start with the incompressible form of the system [given by the continuity equation
which approach causes the smallest discretisation error?18 and the Navier-Stokes equations]:
[. . . ]
The discretisation of the temporal derivative creates only the diagonal coefficient and ∇•U = 0 (69)
a source term contribution, thus increasing the diagonal dominance. Unfortunately, the ∂U
sufficient boundedness criterion cannot be used to establish the boundedness of the discreti- + ∇• (UU) − ∇• (ν∇U) = −∇p (70)
∂t
sation, as it does not take into account the influence of the source term.
Two issues require special attention: non-linearity of the momentum equation and the
The above discussion concentrates on the analysis of the discretisation on a term-by-term pressure-velocity coupling.
basis. In reality, all of the above coefficients contribute to the matrix, thus influencing the
properties of the system. It has been shown that the only terms that actually enhance the The non-linear term in Eqn. (70) is ∇• (UU), i.e. velocity is ’being transported by itself’.
diagonal dominance are the linear part of the source and the temporal derivative. The discretised form of this expression would be quadratic in velocity and the resulting
system of algebraic equations would therefore be non-linear. There are two possible solutions
In steady-state calculations, the beneficial influence of the temporal derivative on the for this problem – either use a solver for non-linear systems, or linearise the convection term.
diagonal dominance does not exist. In order to enable the use iterative solvers, the diagonal Section 2.1.4 describes the discretisation of this term:
dominance needs to be enhanced in some other way, namely through under-relaxation. X
Consider the original system of equations, Eqn. (43): ∇• (UU) = S• (U) f (U) f
X f
aP φnP + aN φnN = RP X
N
= F (U) f
f
Diagonal dominance is created through an artificial term added to both left and right- X
hand side of Eqn. (43): = aP UP + aN UN
f
1−α X 1−α
aP φnP + aP φnP + aN φnN = RP + aP φ0P (67) where F, aP and aN are a function of U. The important issue is that the fluxes F should
α α
N satisfy the continuity equation, [first equation in 70]. Eqs. (70) should therefore be solved
or together, resulting in an even larger (non-linear) system. Having in mind the complexity of
non-linear equation solvers and the computational effort required, linearisation of the term
aP n X 1−α
φ + aN αnN = RP + aP φ0P (68) is preferred. Linearisation of the convection term implies that an existing velocity (flux) field
α P α
N that satisfies [continuity] will be used to calculate aP and aN .
17
See Jasak’s thesis Section 3.6.
18
The discretisation error for the diffusion term is be derived in Jasak’s thesis Section 3.6. For numerical The linearisation does not have any effect in steady-state calculations. When the steady-
results for the convergence of three non-orthogonality see Section 3.7.of same work state is reached, the fact that a part of the non-linear term has been lagged is not significant.
23 24
In transient flows two different approaches can be adopted: either to iterate over non-linear This will be used later to calculate the face fluxes.
terms or to neglect the lagged non-linearity effects. Iteration can significantly increase the
computational cost, but only if the time-step is large. The advantage is that the non-linear When Eqn. (75) is substituted into Eqn. (73), the following form of the pressure equation
system is fully resolved for every time-step, whose size limitation comes only from the tem- is obtained:
poral accuracy requirements. If it is necessary to resolve the temporal behaviour well, a
small time-step is needed. On the other hand, if the time-step is small, the change between !
consecutive solutions will also be small and it is therefore possible to lag the non-linearity 1 H (U)
∇• ∇p = ∇•
without any significant effect. In this study, the PISO procedure proposed by Issa (See [[5] aP aP
ref. 66]) is used for pressure-velocity coupling in transient calculations. For steady-state X H (U) !
calculations, a SIMPLE pressure-velocity coupling procedure by Patankar [7] is used. = S (76)
aP f
f
X " # X !
In order to derive the pressure equation, a semi-discretised form of the momentum equation 1 H (U)
will be used: S• ∇p f = S (78)
aP f aP f
f f
25 26
The PISO Algorithm for Transient Flows This pressure-velocity treatment for transient • A new set of conservative fluxes is calculated using Eqn. (79). As it has been noticed
flow calculations has been originally proposed by Issa [[5] ref. 66]. Let us again consider before, the new pressure field includes both the pressure error and convection-diffusion
the discretised Navier-Stokes system for incompressible flow, Eqs. (77 and 78). The PISO error. In order to obtain a better approximation of the ’correct’ pressure field, it would
algorithm can be described as follows: be necessary to solve the pressure equation again. On the other hand, the non-linear
effects are more important than in the case of transient calculations. It is enough to
• The momentum equation is solved first. The exact pressure gradient source term is not obtain an approximation of the pressure field and recalculate the H (U) coefficients with
known at this stage – the pressure field from the previous time-step is used instead. the new set of conservative fluxes. The pressure solution is therefore under-relaxed in
This stage is called the momentum predictor. The solution of the momentum equation, order to take into account the velocity part of the error:
Eqn. (77), gives an approximation of the new velocity field.
• Using the predicted velocities, the H (U) operator can be assembled and the pressure pnew = pold + αp pp − pold (80)
equation can be formulated. The solution of the pressure equation gives the first
estimate of the new pressure field. This step is called the pressure solution. where
pnew is the approximation of the pressure field that will be used in the next momen-
• Eqn. (79) gives a set of conservative fluxes consistent with the new pressure field. The tum predictor,
velocity field should also be corrected as a consequence of the new pressure distribution.
Velocity correction is done in an explicit manner, using Eqn. (74). This is the explicit pold is the pressure field used in the momentum predictor,
velocity correction stage. pp is the solution of the pressure equation,
A closer look to Eqn. (74) reveals that the velocity correction actually consists of two parts αp is the pressure under-relaxation factor, 0 < αp ≤ 1 .
– a correction due to the change in the pressure gradient ( a1P ∇p term) and the transported
If the velocities are needed before the next momentum solution, the explicit velocity cor-
influence of corrections of neighbouring velocities ( H(U)aP
term). The fact that the velocity rection, Eqn. (74), is performed.
correction is explicit means that the latter part is neglected – it is effectively assumed that
the whole velocity error comes from the error in the pressure term. This, of course, is not Peric, [[5] ref. 109] gives an analysis of the under-relaxation procedure based on the
true. It is therefore necessary to correct the H (U) term, formulate the new pressure equation expected behaviour of the second corrector in the PISO sequence. The recommended values
and repeat the procedure. In other words, the PISO loop consists of an implicit momentum of under-relaxation factors are (Peric, [[5] ref. 109]):
predictor followed by a series of pressure solutions and explicit velocity corrections. The
loop is repeated until a pre-determined tolerance is reached. • αp = 0.2 for the pressure and
Another issue is the dependence of H (U) coefficients on the flux field. After each pressure • αU = 0.8 for momentum.
solution, a new set of conservative fluxes is available. It would be therefore possible to
recalculate the coefficients in H (U). This, however, is not done: it is assumed that the non- 2.1.11 Solution Procedure for the Navier-Stokes System
linear coupling is less important than the pressure-velocity coupling, consistent with the
linearisation of the momentum equation. The coefficients in H (U) are therefore kept constant It is now possible to describe the solution sequence for the Navier-Stokes system with addi-
through the whole correction sequence and will be changed only in the next momentum tional coupled transport equations (e.g. a turbulence model, combustion equations, energy
predictor. equation or some other equations that influence the system).
27 28
5. Using the conservative fluxes, solve all other equations in the system. If the flow is Let us repeat the same set of operations on the block form of the pressure-velocity system,
turbulent, calculate the effective viscosity from the turbulence variables. attempting to assemble a pressure equation. Note that the operators in the block system could
be considered both as differential operators and in a discretised form
6. If the final time is not reached, return to step 2. " #" # " #
[Au ] [∇(.)] u 0
= (86)
The solution procedure for steady-state incompressible turbulent flow is similar: [∇•(.)] [0] p 0
Formally, this leads to the following form of the pressure equation:
1. Set all field values to some initial guess.
h i
[∇•(.)] A−1
u [∇(.)] p = 0 (87)
2. Assemble and solve the under-relaxed momentum predictor equation.
Here, A−1
u represent the inverse of the momentum matrix in the discretised form, which
3. Solve the pressure equation and calculate the conservative fluxes. Update the pressure acts as diffusivity in the Laplace equation for the pressure.
field with an appropriate under-relaxation. Perform the explicit velocity correction
using Eqn. (74) From the above, it is clear that the governing equation for the pressure is a Laplacian, with
the momentum matrix acting as a diffusion coefficient. However, the form of the operator is
4. Solve the other equations in the system using the available fluxes, pressure and velocity
very inconvenient:
fields. In order to improve convergence, under-relax the other equations in an implicit
manner, as shown in Eqn. (68). • While [Au ] is a sparse matrix, its inverse is likely to be dense
5. Check the convergence criterion for all equations. If the system is not converged, start • Discretised form of the divergence
h and
i gradient operator are sparse and well-behaved.
a new iteration on step 2.” However, a triple product with A−1u would result in a dense matrix, making it expen-
sive to solve
2.1.12 An alternative derivation of the Pressure Equation The above can be remedied be decomposing the momentum matrix before the triple
In order to provide more clarity in the derivation of pressure equation following is a new product into the diagonal part and off-diagonal matrix:
approach on this topic introduced by Prof. Jasak in his Lecture Notes for the University of
Zagreb[9]. This is based on the Schur Complement concept. [Au ] = [Du ] + [LUu ] (88)
where [Du ] only contains diagonal entries. [Du ] is easy to invert and will preserve the
”Consider a general block matrix system M, consisting of 4 block matrices, A, B, C, and sparseness pattern in the triple product. Revisiting Eqn. (86) before the formation of the Schur
D, which are respectively p × p, p × q, q × p and q × q matrices and A is invertible: complement and moving the off-diagonal component of [Au ] onto r.h.s. yields:
" # " #" # " #
A B [Du ] [∇(.)] u − [LUu ] [u]
(81) = (89)
C D [∇•(.)] [0] p 0
This structure will arise naturally when trying to solve a block system of equations A revised formulation of the pressure equation via a Schur’s complement yields:
h i h i
[∇•(.)] D−1 −1
u [∇(.)] p = [∇ (.)] Du [LUu ] [u]
• (90)
Ax + By = a h i
In both cases, matrix D−1
u is simple to assemble.
Cx + Dy = b (82)
It follows that the pressure equation is a Poisson equation with the diagonal part of the
The Schur complement arises when trying to eliminate x from the system using partial
discretised momentum acting as diffusivity and the divergence of the velocity on the r.h.s.
Gaussian elimination by multiplying the first row with A?1 :
A−1 Ax + A−1 By = A−1 a (83) Derivation of the pressure equation We shall now rewrite the above derivation formally
without resorting to the assembly of Schur’s complement in order to show the identical result
and
We shall start by discretising the momentum equation using the techniques described be-
x = A−1 a − A−1 By (84) fore. For the purposes of derivation, the pressure gradient term will remain in the differential
form. For each CV, the discretised momentum equation yields:
Substituting the above into the second row:
X
auP uP + auN uN = r − ∇p (91)
D − CA−1 B y = b − CA−1 a (85) N
29 30
For simplicity, we shall introduce the H(u) operator, containing the off-diagonal part of 2.2 Volume of Fluid Method
the momentum matrix and any associated r.h.s. contributions:
2.2.1 Introduction
X
H (u) = r − auN uN (92) Volume of Fluid (VOF) Method was presented by Hirt & Nichols [10] and started a new
N trend in multiphase flow simulation. It relies on the definition of an indicator function. This
Using the above, it follows: function allows us to know wheter the cell is occupied by one fluid or another, or a mix of
both, quoting the original paper:
auP uP = H (u) − ∇p (93)
and ”Suppose [. . . ] that we define a function F whose value is unity at any point
−1 occupied by fluid an zero otherwise. The average value of F in a cell would then
represent the fractional volume of the cell occupied by fluid. In particular, a unit
uP = auP H (u) − ∇p (94)
value of F would correspond to cell full of fluid, while a zero value would indicate
Substituting the expression for uP into the incompressible continuity equation ∇•u = 0
that the cell contained no fluid 19 . Cell with F values between zero and one must
yields
then contain a free surface [. . . ]
−1 −1 The normal direction to the boundary lies in the direction in which de value of F
∇• auP ∇p = ∇• auP H (u) (95) changes most rapidly. Because F is a step function, however, its derivatives must
We have again arrived to the identical form of the pressure equation be computed in a special way [. . . ]. When properly computed, the derivatives
can be used to determine the boundary normal. Finally, when both the normal
Note the implied decomposition of the momentum matrix into the diagonal and off- direction and the value of F in the boundary cell are known, a line cutting the cell
diagonal contribution, where auP is an coefficient in [Du ] matrix and H (u) is the product can be constructed that approximates the interface there. This boundary location
can then be used in the setting of boundary conditions”.
[LUu ] [u], both appearing in the previous derivation
There are several ways to implement this concept, but in the framework of OpenFOAM
Assembling Conservative Fluxes Pressure equation has been derived from the continuity is worthy to analize its special way to do so. Methodology is described in extenso by Ubbink
condition and the role of pressure is to guarantee a divergence-free velocity field [11] and Rusche [12], but a concise and up to date20 explanation is given by Berberovic et.
al. [13]. Following are cited some sections of this paper and an explanation of PISO loop in
Looking at the discretised form of the continuity equation VOF solvers is added.
X X
∇•u = s f •u = F (96)
f f
2.2.2 Mathematical model
where F is the face flux ”In the conventional volume-of-fluid (VOF) method [10], the transport equation for an
indicator function, representing the volume fraction of one phase, is solved simultaneously
F = s f •u (97) with the continuity and momentum equations:
Therefore, conservative face flux should be created from the solution of the pressure
equation. If we substitute expression for u into the flux equation, it follows: ∇•U = 0 (100)
−1 −1
F = − auP s f •∇p + auP s f •H (u) (98) ∂γ
+ ∇• U γ = 0 (101)
−1 ∂t
A part of the above, auP s f •∇p appears during the discretisation of the Laplacian, for
each face. This is discretised as follows: ∂ ρU
+ ∇• ρUU = −∇p + ∇•T + ρfb (102)
∂t
−1 −1 s f
u
aP s f •∇p = aP u p
pN − pP = aN pN − pP (99) where U represents the velocity field shared by the two fluids troughout the flow domain,
|d| γ is the phase fraction, T is the deviatoric tensor T = 2µS − 2µ (∇•U) I/3, with
−1 |s f |
h viscous stress
i
p
Here, aN = auP is equal to the off-diagonal matrix coefficient in the pressure Lapla- the mean rate of strain tensor S = 0.5 ∇U + (∇U)T and I = δij , ρ is density, p is pressure,
|d|
cian. fb are body forces pero unit mass. In VOF simulations the latter forces include gravity and
19
This statament can be interpreted how F = 1 means cell completely occupied by one fluid and F = 0
Note that in order for the face flux to be conservative, assembly of the flux must be completely occupied by another fluid.
completely consistent with the assembly of the pressure equation (e.g. non-orthogonal 20
It has be taken in account that OpenFOAM is evolving constantly and some implementation details can
correction) ”. change, its important to use actualized bibliography
31 32
surface tension effects at the interface. The phase fraction γ can take values whithin the proportional to the corresponding phase fraction, and defining the velocity of the effective
range 0 6 γ 6 1, with the values of zero and one corresponding to regions accomodating fluid in a VOF model as a weighted average [14]
only one phase. e.g., γ = 0 for gas and γ = 1 for liquid. Accordingly, gradients of the phase
fraction are encountered only in the region of the interface. U = γUl + 1 − γ U g (107)
Eq. (105) can be rearranged21 and used as an evolution equation for the phase fraction γ,
Two inmiscible fluids are considered as one effective fluid throughout the domain, the physical
properties of which are calculated as weighted averages based on the distrubution of the ∂γ
liquid volume fraction, thus being equal to the properties of each fluid in their corresponding + ∇• Uγ + ∇• Ur γ 1 − γ = 0 (108)
∂t
occcupied regions and varying only across the interface,
where Ur = Ul − U g is the vector of relative velocity, designated as the ’compression
velocity’.
ρ = ρl γ + ρ g 1 − γ (103)
Accordingly, the equation governing the volume fraction [Eq. (108)] contains an addi-
µ = µl γ + µ g 1 − γ (104) tional convective term, referred to as the ’compression term’ keeping in mind its role to
’compress’ the free surface towardss a sharper one (it should be noted that the wording
where ρl and ρ g are densities of liquid and gas, respectively.
compression represents just a denotation and does not relate to compressible flow). In com-
parison to Eq. (101), this term appears as an artificial contribution to convection of the phase
One of the critical issues in numerical simulations of free surface flows using the VOF
fraction, but since the derivation of Eq. (108) relies on the velocity defined by Eq. (107), a
model is the conservation of the phase fraction. This is specially the case in flows with
strong coupling between the classical VOF and two-fluid model is achieved. The additional
high density ratios, where small errors in volume fraction may lead to significant errors in
convective term contributes significantly to a higher interface resolution, thus avoiding the
calculations of physical properties. Accurate calculation of the phase fraction distribution is
crucial for a proper evaluation of surface curvature, which is required for the determination 21
Starting with the transport equation for γ we have:
of surface tension force and the corresponding pressure gradient acrosss the free surface. ∂γ
The interface region between two phases is tipically smeared over a few grid cells and is ∂t
+ ∇• Uγ
therefore highly sensitive to grid resolution. now, replacing the velocity U by its definition as a weighted average,
∂γ nh i o
Is not a simple task to assure boundedness and conservativeness of the phase fraction.
+ ∇ γUl + 1 − γ U g γ = 0
Various attemps have been made in order to overcome these difficulties (see [13], refs. 26-29). ∂t
Furthermore, the definition of velocity by which the free surface is advancesd, as a single from the definition of the relative velocity we can isolate U g
velocity being shared by both phases, is misleading, e.g. no conclusion can be made as to U g = Ul − Ur
what extent the velocity of each particular phase contributes to the velocity of the efective
then replacing in the above transport equations
fluid.
∂γ
+ ∇ • Ul − 1 − γ Ur γ = 0
In the present study a modified approach similar to one proposed in [12] is used, with ∂t
an advanced model formulated by OpenCFD Ltd. [2], relying on a two-fluid formulation rearranging terms
of the conventional volume-of-fluid model in the framework of finite volume method. Its ∂γ
systematic derivation is outlined below. In this model an additional convective term origi- ∂t
+ ∇• Ul γ −∇• 1 − γ γ Ur = 0
nating from modeling the velocity in terms of weighted average of the corresponding liquid | {z }
=0
and gas velocities is introduced into the transport equation for phase fraction, providing
a sharper interface resolution. The model makes use of the two-fluid Eulerian model for the first two terms of left hand side are zero by the definition of tranport equation for γ at the ’liquid’ phase,
then we have,
two-phase flow, where phase fraction equations are solved separately for each individual
phase (see [13], ref. 32); hence the equations for each of the phase fractions can be expressed ∇• 1 − γ γ Ur = 0
as as it’s expressed above this term vanishes in the continuum formulation because in this case interface front
is step function, then is term is ever completely zero.
∂γ
+ ∇• Ul γ = 0 (105)
∂t Now adding this new term to the γ transport equation we obtain
h
∂ 1−γ i ∂γ
+ ∇• Uγ + ∇• Ur γ 1 − γ = 0
+ ∇• U g 1 − γ = 0 (106) ∂t
∂t
this term has no meaning in the continuum formulation but is suitable to compresss the interface in the
where the subscripts l and g denote the liquid and gaseous phase, respectively. Assuming discrete formulation, specially when the interface is not sharp enough.
that the contributions of the liquid and gas velocities to the evolution of the free surface are
33 34
need to devise a special scheme for convection, such as CICSAM (see [13], ref. 34). This term Body forces due to pressure gradient and gravity are implicitly accounted for by the first
is active only within the interface region and vanishes at both limits of the phase fraction. two terms on the right-hand side of the Eq. (113). Summing up, the present mathematical
Therefore it does not affect the solution outside this region. Moreover if free surface is defined model is given by the continuity equation, Eq. (100), phase fraction equation, Eq. (108), and
in a theoretical sense as having an infinitesimally small thickness, the (relative) velocity Ur vanishes momentum equation, Eq. (113).
and the expression (108) reduces to the conventional form (101).
The model is closed by supplying an appropriate expression for the compression velocity
In addition to properly reflecting the physics of the flow, the main advantage of such Ur . In order to ensure that this velocity does not bias the solution in any way, it must act
formulation is in the possibility of capturing the interface region much more sharply in only in the perpendicular direction to the interface. Furthermore, by inspection of Eq. (113) it
comparison to the classical VOF approach. Numerical diffusion, unavoidably introduced is evident that only the values of Ur on the grid cell faces will be used, being in accordance
through the discretization of convective terms, can be controlled and minimized through the with the discretization of the convective term. The model for Ur is described in detail [later].
discretization of the compression term, thus allowing sharp interface resolution. The details
of its numerical treatment are given [later]. [. . . ].
2.2.3 Computational method
The momentum equation, Eq. 102, is modified in order to account for the effects of surface Discrezation of the ”compression term” For the discretization of the compression term
tension. The surface tension at the liquid-gas interface generates an additional pressure in Eq. (108) the relative velocity at cell faces, formulated based on the maximum velocity
gradient resulting in a force, which is evaluated per unit volume using the continuum magnitude at the interface region and its direction, is determined from the gradient of phase
surface force (CSF) model (see [13], ref. 35). fraction as follows:
fσ = σκ∇γ (109) φ φ
Ur, f = n f min Cγ , max
(114)
where κ is the mean curvature of the free surface, determined from the expressions S f S f
∇γ where φ is face volume flux, and n f is face unit normal flux, calculated at cell faces in the
κ = −∇
• (110) interface region using the phase fraction gradient at cell faces,
∇γ
Equation (109) is only valid for the cases with constant surface tension, as considered ∇γ f
here. In the case of variable surface tension, e.g., due to nonuniformly distributed tempera- n f = •S f (115)
∇γ f + δn
ture, surface tension gradients are encountered, generating an additional shear stress at the
interface, which should be taken into account. In the normalization of the phase fraction gradient in Eq. (115) and Eq. (110), a stabiliza-
tion factor δn is used, which accounts for nonuniformity of the grid,
Both fluids are considered to be Newtonian and incompressible ∇•U = 0, and the rate
of strain tensor is linearly related to the stress tensor, which is decomposed into a more ε
δn = P 1/3 (116)
convenient form for discretization, N Vi
N
h i
∇•T = µ ∇U + (∇U)T = ∇• µ∇U + (∇U) •∇µ (111) where N is the number of computational cells and ε is a small parameter, set to 10?8 here.
In a single pressure system as considered for the present VOF method, the normal com-
ponent of the pressure gradient at a stationary nonvertical solid wall, with no-slip condition The model is relatively simple and robust, relying basically on the definition of the
on velocity, must be different for each phase due to the hydrostatic component ρg when the velocity in Eq. (107). If there is a small bulk motion of the gaseous phase in the vicinity of
phases are separated at the wall, i.e., if a contact line exists. In order to simplify the definition the free surface, the relative velocity will be close to the velocity of the liquid phase. If the
of boundary conditions, it is common to define a modified pressure as velocities of both phases are of the same order of magnitude, the intensity of the free surface
compression is controlled by the constant Cγ , which yields no contribution if set to zero,
pd = p − ρg•x (112) a conservative compression if the value is one [. . . ], and enhanced compression for values
greater than one [16]. It should be noted that the face volume flux in Eq. (114) is not evaluated
where x is the position vector. It can be easely show that the gradient of modified pressure using the face interpolation of the velocity, but is determined as a conservative volume flux resulting
pd of the static pressure gradient, the body force due to gravity and an additional contribution from the pressure-velocity coupling algorithm.22
originating from the density gradient. In order to satisfy the momentum equation, the pres-
sure gradient is expressed using Eq. (112) whereas the momentum equation is rearranged
to read [12] Adaptive time step control In order to ensure stability of the solution procedure, the
calculations are performed using a self-adapting time step which is adjusted at the beginning
ρU
+ ∇• ρUU − ∇• µ∇U − (∇U) •∇γ = −∇pd − g•x∇ρ + σκ∇γ (113) 22
This topic has been discused in Section 2.1.12, paragraph Assembling Conservative Fluxes.
∂t
35 36
of the time iteration loop based on the Courant number defined as In addition to providing a more accurate solution of the phase fraction equation, this
algorithm also enables the global time step size to be greater for the solution of other
U f •S f transport equations, thereby considerably speeding up the solution procedure”.
Co = ∆t (117)
d•S f
where d is a vector between calculation points of control volumes sharing the face.
PISO loop In order to achieve a properly coupling between velocity and pressure in
i.e. d = PN and ∆t is time step. Using values for U f and ∆t from previous time step, a interFoam is necessary to adapt the PISO loop to the momentum equation for interphase
maximum local Courant number Co0 is calculated and the new time step is evaluated from solver and derive a new pressure equation. Starting with momentum equation (113) we
the expression have:
Comax 0 Comax 0 0
∆nt = min ∆t , 1 + λ1 ∆t , λ2 ∆t , ∆tmax (118) ρU
Co0 Co0 + ∇• ρUU − ∇• µ∇U − (∇U) •∇γ = −∇pd − g•x∇ρ + σκ∇γ
∂t
where ∆tmax and Comax are prescribed limit values for the time step and Courant number,
respectively. Now following the guidelines given in Section 2.1.12 we can obtain a discretized form of
momentum equation (compare it with Eq. 93)
According to this prescription the new time step will decrease if Co0 overshoots Comax
and increase otherwise. To avoid time step oscillations that may lead to instability, the in- auP uP = H (u) − ∇pd − g•x∇ρ + σκ∇γ (122)
crease of the time step is damped using factors λ1 and λ2 , according to the conditions in Eq.
(118). isolating the velocity at cell centres:
h i−1
[. . . ] uP = auP H (u) − g•x∇ρ + σκ∇γ − ∇pd (123)
[. . . ] At the startup of the simulation, usually some very small initial time step ∆tinit is replacing this velocity in continuity equation is possible to assemble a Poisson equation
used, which could lead to a very small maximum local value of the Courant number and for pressure pd
a new time step that would be too large for the start, and vice versa. Therefore, at the
h i−1 h i−1
beginning of the calculation an intermediate value for the initial time step is calculated as
∇• auP ∇pd = ∇• auP H (u) − g•x∇ρ + σκ∇γ (124)
Comax ∆tinit
∆t∗init = min 0
; ∆tmax (119) Finally it is necessary to obtain fluxes that obeys continuity, it is achieved by
Co
This intermediate value is than used as ∆t0 in Eq. (118) providing the value of Co0 for the −1 −1
first time step to be close to the prescribed limit value Comax . [. . . ]. F = − auP s f •∇pd + auP s f • H (u) − g•x∇ρ + σκ∇γ (125)
Temporal subcycling It is common in VOF-based methods that the convergence and sta-
bility of the solution procedure are very sensitive with respect to the equation for phase 3 OpenFOAM library overview. Solver examples
fraction. Bounded discretization schemes for divergence terms and time step control are
both used to overcome these difficulties and, although it is generally recommended to keep 3.1 Fields and variables. Discrete differential operators
the maximum local Courant number much below unity, it is beneficial to solve the phase
fraction equation in several subcycles within a single time step. The time step to be used in a Computational implementation of above explained discretisation is carried out by means
single time subcycle is set by dividing the global time step by the preset number of subcycles, of OpenFOAM C++ libraries. These libraries can be used for general purposes like field
handling, postproccesing and calculus. Libraries are accompanied by a huge solver set mod-
∆t elling different physical phenomena.
∆tsc = (120)
nsc
After the phase fraction γ in each subcycle is updated, a corresponding mass flux Fsc,i A brief description of this libraries was published in [15], further information can be
through cell faces is calculated. found in OpenFOAM User Guide chapter 3 [16] and Programmer’s Guide chapters 1-2 [17]
whose reading is highly encouraged.
The total mass flux F corresponding to the global time step, which is needed in the
momentum equation, is then obtained from Following are several excerpts from Weller et. al. paper with the aim to introduce in
nsc
OpenFOAM libraries. Can be some differences between actual notation and sources’s nota-
X ∆t
F = ρU f •S f =
sc
Fsc,i (121) tion because of the natural evolving of the software.
i=1
∆t
37 38
3.1.1 Implementation of tensor fields however, usually quite descriptive). This also illustrates the ease with which [OpenFOAM]
can be used to manipulate tensorial data as a postprocessing exercise. Any [OpenFOAM]
”The majority of fluid dynamics can be described using the tensor calculus of up to rank
code can be thought of as an exercise in mapping from one tensor field to another, and it
2, i.e., scalars, vectors, and second-rank tensors. Therefore three basic classes have been
matters little whether the mapping procedure involves the solution of a differential equation
created: scalarField, vectorField, and tensorField. [. . . ]
or not. Hence, writing a short code to calculate the vorticity of a vector field is a matter of
reading in the data (for which other functions, not described here, are provided), performing
These tensor field classes are somewhat different from a mathematical tensor field in that
this manipulation, and writing out the results. Very complicated expressions can be built up
they contain no positional information; they are essentially ordered lists of tensors, and so
in this way with considerable ease.
only pointwise operations (i.e., tensor algebra) can be performed at this level. The operators
implemented [in OpenFOAM] include addition and subtraction, multiplication by scalars,
All possible tensorial derivatives are implemented in [OpenFOAM]: ∂/∂t, ∇•, ∇ and ∇×.
formation of various inner products, and the vector and outer products of vectors (resulting
In addition, the Laplacian operator is implemented independently rather than relying on the
in vectors and tensors, respectively). In addition, operations such as taking the trace and
use of ∇ followed by ∇•. This enables improved discretization practices to be used for this
determinant of a tensor are included as well as functions to obtain the eigenvalues and
operator. The one numerical issue that has to be dealt with at the top level of the code is the
eigenvectors; these are not necessary for solution of fluid systems but are of importance for
choice of differencing scheme to be used to calculate the derivative. Again, because of the
postprocessing the data [. . . ].
data hiding in OOP, the numerics can be effectively divorced from the high-level issues of
modeling: improved differencing schemes can be implemented and tested separately from
Since C++ implements operator overloading, it is possible to make the tensor algebra
the codes that they will eventually be used in. The choice can be made at the modeling level
resemble mathematical notation by overloading +, -, *, etc. The one problem inherent here is
by using a switch in the operator. Hence, the temporal derivative ∂/∂t can be invoked as
that the precedence of the various operators is preset, which makes it quite difficult to find
an operator for the dot product with the correct precedence and that looks correct.
volVectorField dUdt = fvc::ddt(U, EI)
The next level of tensors are referred to as ’geometric tensor fields’ and contain the positional
information lacking in the previous classes. Again, there are classes for the three ranks of ten- where the second entry specifies which differencing scheme to use (in this case Euler
sors currently implemented, volScalarField, volVectorField, and volTensorField. At implicit). Several temporal differencing schemes are available, with a default corresponding
first, the relationship between, for example, scalarField and volScalarField should be [. . . ], to the scheme that gets the most use, in this case, backward differencing. Other selection
derivation. However, this would allow the compiler to accept scalarField1+volScalarField methods are possible, but this one is the simplest.
as an operation, which would not be appropriate, and so encapsulation is used instead. In
addition to the additional metrical information necessary to perform differentiation, which 3.1.2 Implementation of partial-differential-equation classes
is contributed by a reference to a ’mesh class’ fvMesh (see below), these classes contain
boundary information, previous time steps necessary for the temporal discretization, and The fvc methods correspond directly to tensor differential operators, since they map tensor fields to
dimension set information. All seven base SI dimensions are stored, and all algebraic expres- tensor fields. [CFD] requires the solution of partial differential equations, which is accom-
sions implemented above this level are dimensionally checked at execution. It is therefore plished by converting them into systems of difference equations by linearizing them and
impossible to execute a dimensionally incorrect expression in [OpenFOAM]. This has no applying discretization procedures. The resulting matrices are inverted using a suitable
significant runtime penalty whatsoever: typical fields have 104 -105 tensors in them, and matrix solver.
dimension checking is done once per field operation.
The differential operators ∇•, ∇, and ∇× lead to sparse matrices, which for unstructured
Currently two types of tensor-derivative classes are implemented in [OpenFOAM]: meshes have a complex structure requiring indirect addressing and appropriate solvers.
finiteVolumeCalculus or fvc, which performs an explicit evaluation from predetermined data [OpenFOAM] currently uses the conjugate-gradient method, with incomplete Cholensky
and returns a geometric tensor field, and finiteVolumeMethod or fvm, which returns a matrix preconditioning (ICCG), to solve symmetric matrices. For asymmetric matrices the Bi-
representation of the operation, which can be solved to advance the dependent variable(s) by a time CGSTAB method is used23 . The matrix inversion is implemented using face addressing throughout,
step. fvm will be described later in more detail [. . . ]. The fvc class has no private data and a method in which elements of the matrix are indexed according to which cell face they are associated
merely implements static member functions that map from one tensor field to another. Use with. Both transient and steady-state solutions of the equation systems are obtained by time-marching,
of a static class in this manner mimics the concept of a namespace [. . . ], and by implement- with the time step being selected to guarantee diagonal dominance of the matrices, as required by the
ing the operations in this manner, a clear distinction is drawn between the data and the solvers24 .
operations on the data. The member functions of this class implement the finite-volume
equivalent of various differential operators, for example, the expression In order that standard mathematical notation can be used to create matrix representations
of a differential equation, classes of equation object called [fvScalarMatrix], [fvVectorMatrix],
vorticity = 0.5*fvc::curl(U);
23
See original paper cites for details of these methods
calculates the vorticity of a vector field U as 12 ∇ × U. (For reasons of space, not all the 24
Face addressing is a key concept in OpenFOAM because relates mesh generation and description, matrix
variables in the program fragments used to illustrate points will be defined. The names are, element indexing and solving
39 40
etc., are defined to handle addressing issues, storage allocation, solver choice, and the so- with ease, although the 3D set tetrahedron (four vertices), pyramid (five vertices), prism
lution. These classes store the matrices that represent the equations. The standard mathe- (six vertices), and hexahedron (eight vertices) cover most eventualities. In addition, each n-
matical operators + and - are overloaded to add and subtract matrix objects. In addition, dimensional primitive shape knows about its decomposition into (n-1)-dimensional shapes,
all the tensorial derivatives ∂/∂t, ∇•, ∇×, etc., are implemented as member functions of a which are used in the creation of addressing lists as, for example, cell-to-cell connectivity.
class finiteVolumeMethod (abbreviated to fvm), which construct appropriate matrices using
the finite-volume discretization. Numerical considerations are relevant in deciding the exact Boundary conditions are regarded as an integral part of the field rather than as an added extra.
form of many of the member functions. For instance, in the FVM, divergence terms are fvMesh incorporates a set of patches that define the exterior boundary ∂D of the domain. Every patch
represented by surface integrals over the control volumes δVi . Thus the divergence function carries a boundary condition, which is dealt with by every fvm operator in an appropriate
call is div(phi,Q), where phi is the flux, a field whose values are recorded on the cell faces, and Q manner. Different classes of patch treat calculated, fixed value, fixed gradient, zero gradient,
is the quantity being transported by the flux, and is a field whose values are on the cell centers. For symmetry, cyclic, and other boundary conditions, all of which are derived from a base class
this reason, this operation cannot be represented as a function call of the form div(phi*Q). patchField. All boundary conditions have to provide the same types of information, that
Again, the Laplacian operator is implemented as a single separate call rather than as calls to div and is, that they have the same interface but different implementations. This is therefore a good
grad, since its numerical representation is different. Various forms of source term are also im- example of polymorphism within the code. From these basic elements, boundaries suitable
plemented. A source term can be explicit, in which case it is a special kind of equation object for inlets, outlets, walls, etc., can be devised for each specific situation. An additional
with entries only in the source vector [. . . ], or it can be made implicit, with entries in the patchField, processor is also available”.
matrix [. . . ]. Construction of an explicit source term is provided for by further overloading
+ (and -) to provide operations such as fvm+volScalarField. Construction of an implicit
source is arranged by providing a function Sp(a,Q), thus specifying the dependent variable
3.2 Solver examples
Qto be solved for. 3.2.1 Scalar transport equation
Thus it is possible to build up the matrix system appropriate to any equation by summing the One of the simplest solvers and a good starting point in OpenFOAM solver comprehension
is scalarTransportFoam, this solver allows solving an unsteady scalar advection-diffusion
individual terms the equation. As an example, consider the mass conservation equation
in equation such as:
∂/partialt + ∇• φ = 0, where φ = ρU. The matrix system can be assembled by writing
∂C
fvMatrixScalar rhoEq + ∇• (U C) − Γ ∇2 C = 0 (126)
∂t
(
fvm::ddt(rho) + fvc::div(phi) where C is the scalar concentration, U the advective velocity field and Γ the diffusivity.
); In this case the solver’s code is:
1 #include "fvCFD.H"
where the velocity flux phi has been evaluated previously,and solved by the call 2
3 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
4
rhoEq.solve( ); 5 int main(int argc, char *argv[ ])
6 {
to advance the value of ρ by one timestep. Where necessary, the solution tolerance can be 7
explicitly specified. For completeness, the operation == is defined to represent mathematical 8 # include "setRootCase.H"
9
equality between two sides of an equation. This operator is here entirely for stylistic reasons,
10 # include "createTime.H"
since the code automatically rearranges the equation (all implicit terms go into the matrix, and all 11 # include "createMesh.H"
explicit terms contribute to the source vector). In order for this to be possible, the operator 12 # include "createFields.H"
chosen must have the lowest priority, which is why == was used; this also emphasizes that 13
this represents equality of the equation, not assignment. 14
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
3.1.3 Mesh topology and boundary conditions 17 Info<< "\nCalculating scalar transport\n" << endl;
18
Geometric information is contributed to the geometric fields by the class fvMesh, which con- 19 # include "CourantNo.H"
sists of a list of vertices, a list of internal cells, and a list of boundary patches (which in turn are lists 20
of cell faces). The vertices specify the mesh geometry, whereas the topology of any cell–be 21 for (runTime++; !runTime.end(); runTime++)
it one dimension (1D) (a line), two dimensions (2D) (a face), or three dimensions (3D) (a 22 {
23 Info<< "Time = " << runTime.timeName() << nl << endl;
cell)–is specified as an ordered list of the indices together with a shape primitive describing 24
the relationship between the ordering in the list and the vertices in the shape. These prim- 25 # include "readSIMPLEControls.H"
itive shapes are defined at run time, and so the range of primitive shapes can be extended 26
41 42
27 for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) 87 IOobject
28 { 88 (
29 solve 89 "transportProperties",
30 ( 90 runTime.constant(),
31 fvm::ddt(T) 91 mesh,
32 + fvm::div(phi, T) 92 IOobject::MUST READ,
33 − fvm::laplacian(DT, T) 93 IOobject::NO WRITE
34 ); 94 )
35 } 95 );
36 96
37 runTime.write(); 97
38 } 98 Info<< "Reading diffusivity D\n" << endl;
39 99
40 Info<< "End\n" << endl; 100 dimensionedScalar DT
41 101 (
42 return(0); 102 transportProperties.lookup("DT")
43 } 103 );
44 104
45 105 # include "createPhi.H"
46 106
47 // ************************************************************************* // 107
48 108 // ************************************************************************* //
49 // createFields.H 109
50 110 // createPhi.H
51 Info<< "Reading field T\n" << endl; 111
52 112 #ifndef createPhi H
53 volScalarField T 113 #define createPhi H
54 ( 114
55 IOobject 115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 ( 116
57 "T", 117 Info<< "Reading/calculating face flux field phi\n" << endl;
58 runTime.timeName(), 118
59 mesh, 119 surfaceScalarField phi
60 IOobject::MUST READ, 120 (
61 IOobject::AUTO WRITE 121 IOobject
62 ), 122 (
63 mesh 123 "phi",
64 ); 124 runTime.timeName(),
65 125 mesh,
66 126 IOobject::READ IF PRESENT,
67 Info<< "Reading field U\n" << endl; 127 IOobject::AUTO WRITE
68 128 ),
69 volVectorField U 129 linearInterpolate(U) & mesh.Sf()
70 ( 130 );
71 IOobject 131
72 ( 132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 "U", 133
74 runTime.timeName(), 134 #endif
75 mesh,
76 IOobject::MUST READ, Let’s comment the code:
77 IOobject::AUTO WRITE
78 ), • Line 1: fvCFD.H is included with the aim of have available all the FVM machinery.
79 mesh
80 ); • Lines 2-11: starts the main function. Command line parameters, time variables and
81
82
mesh set up.
83 Info<< "Reading transportProperties\n" << endl;
84
• Line 12: createFields.H reads the initial conditions for U, T and diffusivity DT (Γ)
85 IOdictionary transportProperties (see code in lines 47-107). This file include at the end createPhi.H (lines 108-134), read
86 ( (if it’s present) or calculate the face flux field φ.
43 44
• Line 17: Shows a message by standard output indicating that calculation begins. 4
5 int main(int argc, char *argv[ ])
• Line 19: CourantNo.H is included it calculates and outputs the mean and maximum 6 {
Courant Numbers. 7
8 # include "setRootCase.H"
• Lines 21-38: temporal main cycle controlled by runTime object. 9 # include "createTime.H"
10 # include "createMesh.H"
11 # include "createFields.H"
• Line 23: now within the temporal cycle, this commands prints the actual time.
12 # include "initContinuityErrs.H"
13
• Line 25: readSIMPLEControls.H is included, allowing in this case to read the number
14 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
of non-orthogonal corrections. 15
16 Info<< "\nStarting time loop\n" << endl;
• Lines 27-35: As was expressed in Section 2.1.4, paragraph Diffusion Term, laplacian 17
term is discretized by means of face gradient. This discretizacion requires non- 18 for (runTime++; !runTime.end(); runTime++)
orthogonal corrections in case of non orthogonal mesh is used. Then this loop ap- 19 {
plies this correction as many times as is indicated by the nNonOrthCorr variable. 20 Info<< "Time = " << runTime.timeName() << nl << endl;
21
Note that the function solve solves every time the same problem. It requires some
22 # include "readPISOControls.H"
explanation, solve(fvm::ddt(T)+fvm::div(phi, T)-fvm::laplacian(DT, T)); im- 23 # include "CourantNo.H"
plies that three systems of equations are assembled, one for each term. Every system 24
has it own matrix, guess values and r.h.s. values. Because fvm methods only con- 25 fvVectorMatrix UEqn
tributes to matrix and T is the guess field, these terms when are added form a system 26 (
27 fvm::ddt(U)
of equations with zero r.h.s. Right hand side remains zero because == operator hasn’t 28 + fvm::div(phi, U)
been used indicating no source term. In each temporal step r.h.s. starts being zero, 29 − fvm::laplacian(nu, U)
but we have n steps of orthogonal corrections, then as was expressed in Section 2.1.4, 30 );
paragraph Diffusion Term and in section 2.1.7, orthogonal correction is applied by 31
means of a contribution to source term from the face gradient (calculated by previous 32 solve(UEqn == −fvc::grad(p));
33
step values). So in each non-orthogonal correction step the r.h.s. changes forcing the 34 // −−− PISO loop
system to a correct diffusion term calculation25 . 35
36 for (int corr=0; corr<nCorr; corr++)
• Line 37: this line indicates writing the fields to hard disk. 37 {
38 volScalarField rUA = 1.0/UEqn.A();
• Line 39-43: finally program shows a message by standard output indicating end of 39
calculation and returns the control to the system. 40 U = rUA*UEqn.H();
41 phi = (fvc::interpolate(U) & mesh.Sf())
42 + fvc::ddtPhiCorr(rUA, U, phi);
3.2.2 Isothermal, incompressible and laminar Navier-Stokes solver 43
44 adjustPhi(phi, U, p);
As our next step in complexity let’s study the isothermal, incompressible and laminar Navier- 45
Stokes solver, namely icoFoam, this solves the system of equations: 46 for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
47 {
48 fvScalarMatrix pEqn
∇•U = 0 49 (
50 fvm::laplacian(rUA, p) == fvc::div(phi)
∂U 51 );
+ ∇• (UU) − ∇• (ν∇U) = −∇p
∂t 52
53 pEqn.setReference(pRefCell, pRefValue);
as was explained in Sections 2.1.8-2.1.12 using the PISO algorithm for unsteady calcula- 54 pEqn.solve();
tions. 55
56 if (nonOrth == nNonOrthCorr)
57 {
The code is that follows: 58 phi −= pEqn.flux();
1 #include "fvCFD.H" 59 }
2 60 }
3 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 61
62 # include "continuityErrs.H"
25
See Section 3.1 of [17] for an excellent example of non-orthogonal correction 63
45 46
64 U −= rUA*fvc::grad(p); 124 runTime.timeName(),
65 U.correctBoundaryConditions(); 125 mesh,
66 } 126 IOobject::MUST READ,
67 127 IOobject::AUTO WRITE
68 runTime.write(); 128 ),
69 129 mesh
70 Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" 130 );
71 << " ClockTime = " << runTime.elapsedClockTime() << " s" 131
72 << nl << endl; 132 # include "createPhi.H"
73 } 133
74 134 label pRefCell = 0;
75 Info<< "End\n" << endl; 135 scalar pRefValue = 0.0;
76
136 setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);
77 return(0);
78 } Respecto to this code we have:
79
80 // ************************************************************************* //
• Lines 1-15: the initialization is similar to scalarTransportFoam but in this case init
81
82 // createFields.H ContinuityErrs.H file is included to initilialize the calculations of error and in createFields.H
83 reference pressure is set (see lines 134-136).
84 Info<< "Reading transportProperties\n" << endl;
85 • Line 16: a message indicating the starting of time loop is sent to standard output.
86 IOdictionary transportProperties
87 ( • Lines 18-73: temporal loop controlled by runTime object.
88 IOobject
89 ( • Line 20: a message indicating the actual time is sent to standard output.
90 "transportProperties",
91 runTime.constant(), • Line 22: the inclusion of readPISOControls.H archive allows reading the PISO solver
92 mesh,
93 IOobject::MUST READ,
parameters, in this case specially the number of non-orthogonal corrections (nNonOrthCorr)
94 IOobject::NO WRITE in pressure equation solving and the number of PISO loops (nCorr).
95 )
96 ); • Line 23: Courant number is calculated for actual step.
97
98 dimensionedScalar nu • Lines 25-32: Navier-Stokes equations are solved for U using φ and p from a previous
99 ( (or initial) step. Firstly left hand side of equation is assembled and then solve(UEqn
100 transportProperties.lookup("nu") == -fvc::grad(p)); sentence is used meaning the right hand side is the face gradient
101 );
102
of p, this is explicitely calculated because a previous p field value is used. So, fvm
103 Info<< "Reading field p\n" << endl; operators contribute to system matrix and fvc to the source term. Solving this system
104 volScalarField p is called the momentum predictor. ”This gives us a velocity field that is not divergence
105 ( free, but aproximately satisfies momentum” [18].
106 IOobject
107 ( • Lines 34-66: PISO loop is performed (see Section 2.1.12) (check Section 2.1.12 para-
108 "p",
109 runTime.timeName(),
graph Derivation of the pressure equation). This loop is performed as many times as
110 mesh, indicated by the nCorr variable. As is indicated in this section we have to calculate the
111 IOobject::MUST READ, reciprocal of diagonal coefficients UEqn realated matrix, to use it in later calculus, so
112 IOobject::AUTO WRITE in line 38 we have: volScalarField rUA = 1.0/UEqn.A(); where have made use of
113 ), UEqn.A() method to extract the diagonal coefficients.
114 mesh
115 );
The next step is to solve the Pressure Equation created specially for this incompressible
116 problem or Eq. (95), this is achieved by several intermediate steps. First of all the
117 part between parenthesis of r.h.s in Eq. (95) is calculated in line 40, using the method
118 Info<< "Reading field U\n" << endl; UEqn.H() to extract the off-diagonal part of the UEqn associated matrix. Here is impor-
119 volVectorField U tant to note that by Eq. (17), the divergence is calculated as a sum of face fluxes, then
120 (
121 IOobject it is important to give to this operator an appropriate face flux. This is calculated in
122 ( lines 41-42, 44.; fvc::interpolate(U) & mesh.Sf() recalls the standard calculation
123 "U", of φ (or F by Jasak’s Thesis nomenclature), like in createPhi.H, but in this case we can
47 48
apply different interpolation schemes indicated in system/fvSchemes file. Another 26
term is added to φ calculation, fvc::ddtPhiCorr(rUA, U, phi) which ”accounts for 27 while (runTime.run())
the divergence of the face flux of the face velocity field by taking out the difference 28 {
29 #include "readPISOControls.H"
between the interpolated velocity and the flux” [18]26 30 #include "readTimeControls.H"
In line 44 there is another correction, in this case with the aim of ”[adjusting] the inlet 31 #include "CourantNo.H"
and outlet fluxes to obey continuitym, which is neccesary for creating a well-possed 32 #include "setDeltaT.H"
problem where a solution for pressure exists” [18]. 33
34 runTime++;
Now is possible to solve Eq. (95) (line 54), but being involved a gradient calculation is
35
newly necessary to do the non-orthogonal corrections. Another thing to do is set the 36 Info<< "Time = " << runTime.timeName() << nl << endl;
reference pressure (line 53) before solving. 37
Once non-orthogonal correction loop is finalized φ flux is corrected by p as is indicated 38 twoPhaseProperties.correct();
in equation (98), then continuity errors are calculated and reported in line 62. 39
40 #include "gammaEqnSubCycle.H"
Now it is possible to refresh U by Eq. (94) (line 64) and correct boundary field of this
41
this volVectorField (line 65). 42 #include "UEqn.H"
43
• Lines 68-78: program finalizes writing data to disk and execution times to standard 44 // −−− PISO loop
output. 45 for (int corr=0; corr<nCorr; corr++)
46 {
47 #include "pEqn.H"
3.2.3 Volume of Fluid laminar solver 48 }
49
Having analized previous solvers it is time to face the description of interFoam solver. Previ- 50 #include "continuityErrs.H"
uos work is worthy because for VOF method is necessary to solve scalar transport equations 51
and manage pressure-velocity coupling in momentum equations solving. 52 p = pd + rho*gh;
53
Thus, having in mind this theory and code, we recall section 2.2 to analize the following 54 runTime.write();
55
code: 56 Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
1 #include "fvCFD.H" 57 << " ClockTime = " << runTime.elapsedClockTime() << " s"
2 #include "MULES.H" 58 << nl << endl;
3 #include "subCycle.H" 59 }
4 #include "interfaceProperties.H" 60
5 #include "twoPhaseMixture.H" 61 Info<< "End\n" << endl;
6 62
7 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 63 return(0);
8 64 }
9 int main(int argc, char *argv[ ]) 65
10 { 66
11 #include "setRootCase.H" 67 // ************************************************************************* //
12 #include "createTime.H" 68
13 #include "createMesh.H" 69 // createFields.H
14 #include "readEnvironmentalProperties.H" 70
15 #include "readPISOControls.H" 71 Info<< "Reading field pd\n" << endl;
16 #include "initContinuityErrs.H" 72 volScalarField pd
17 #include "createFields.H" 73 (
18 #include "readTimeControls.H" 74 IOobject
19 #include "correctPhi.H" 75 (
20 #include "CourantNo.H" 76 "pd",
21 #include "setInitialDeltaT.H" 77 runTime.timeName(),
22 78 mesh,
23 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 79 IOobject::MUST READ,
24 80 IOobject::AUTO WRITE
25 Info<< "\nStarting time loop\n" << endl; 81 ),
82 mesh
26
See also: http://www.cfd-online.com/Forums/openfoam-solving/60096-ddtphicorr.html and 83 );
http://www.cfd-online.com/Forums/openfoam-solving/59636-why-say-uses-e2-80-98pseudostaggered-e2- 84
80-99-finite-volume-numerics.html for replies on this topic by Henry Weller and Hrvoje Jasak. 85 Info<< "Reading field gamma\n" << endl;
49 50
86 volScalarField gamma 146 "rho*phi",
87 ( 147 runTime.timeName(),
88 IOobject 148 mesh,
89 ( 149 IOobject::NO READ,
90 "gamma", 150 IOobject::NO WRITE
91 runTime.timeName(), 151 ),
92 mesh, 152 rho1*phi
93 IOobject::MUST READ, 153 );
94 IOobject::AUTO WRITE 154
95 ), 155
96 mesh 156 Info<< "Calculating field g.h\n" << endl;
97 ); 157 volScalarField gh("gh", g & mesh.C());
98 158 surfaceScalarField ghf("gh", g & mesh.Cf());
99 Info<< "Reading field U\n" << endl; 159
100 volVectorField U 160
101 ( 161 volScalarField p
102 IOobject 162 (
103 ( 163 IOobject
104 "U", 164 (
105 runTime.timeName(), 165 "p",
106 mesh, 166 runTime.timeName(),
107 IOobject::MUST READ, 167 mesh,
108 IOobject::AUTO WRITE 168 IOobject::NO READ,
109 ), 169 IOobject::AUTO WRITE
110 mesh 170 ),
111 ); 171 pd + rho*gh
112 172 );
113 # include "createPhi.H" 173
114 174
115 175 label pdRefCell = 0;
116 Info<< "Reading transportProperties\n" << endl; 176 scalar pdRefValue = 0.0;
117 twoPhaseMixture twoPhaseProperties(U, phi, "gamma"); 177 setRefCell(pd, mesh.solutionDict().subDict("PISO"), pdRefCell, pdRefValue);
118 178
119 const dimensionedScalar& rho1 = twoPhaseProperties.rho1(); 179
120 const dimensionedScalar& rho2 = twoPhaseProperties.rho2(); 180 // Construct interface from gamma distribution
121 181 interfaceProperties interface(gamma, U, twoPhaseProperties);
122 182
123 // Need to store rho for ddt(rho, U) 183 // ************************************************************************* //
124 volScalarField rho 184
125 ( 185 // correctPhi.H
126 IOobject 186
127 ( 187
128 "rho", 188 {
129 runTime.timeName(), 189 # include "continuityErrs.H"
130 mesh, 190
131 IOobject::READ IF PRESENT 191 wordList pcorrTypes(pd.boundaryField().types());
132 ), 192
133 gamma*rho1 + (scalar(1) − gamma)*rho2, 193 for (label i=0; i<pd.boundaryField().size(); i++)
134 gamma.boundaryField().types() 194 {
135 ); 195 if (pd.boundaryField()[i].fixesValue())
136 rho.oldTime(); 196 {
137 197 pcorrTypes[i] = fixedValueFvPatchScalarField::typeName;
138 198 }
139 // Mass flux 199 }
140 // Initialisation does not matter because rhoPhi is reset after the 200
141 // gamma solution before it is used in the U equation. 201 volScalarField pcorr
142 surfaceScalarField rhoPhi 202 (
143 ( 203 IOobject
144 IOobject 204 (
145 ( 205 "pcorr",
51 52
206 runTime.timeName(), 266 rhoPhiSum += (runTime.deltaT()/totalDeltaT)*rhoPhi;
207 mesh, 267 }
208 IOobject::NO READ, 268
209 IOobject::NO WRITE 269 rhoPhi = rhoPhiSum;
210 ), 270 }
211 mesh, 271 else
212 dimensionedScalar("pcorr", pd.dimensions(), 0.0), 272 {
213 pcorrTypes 273 # include "gammaEqn.H"
214 ); 274 }
215 275
216 dimensionedScalar rUAf("(1|A(U))", dimTime/rho.dimensions(), 1.0); 276 interface.correct();
217 277
218 adjustPhi(phi, U, pcorr); 278 rho == gamma*rho1 + (scalar(1) − gamma)*rho2;
219 279
220 for(int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) 280
221 { 281 // ************************************************************************* //
222 fvScalarMatrix pcorrEqn 282
223 ( 283 // UEqn.H
224 fvm::laplacian(rUAf, pcorr) == fvc::div(phi) 284
225 ); 285 surfaceScalarField muf = twoPhaseProperties.muf();
226 286
227 pcorrEqn.setReference(pdRefCell, pdRefValue); 287 fvVectorMatrix UEqn
228 pcorrEqn.solve(); 288 (
229 289 fvm::ddt(rho, U)
230 if (nonOrth == nNonOrthCorr) 290 + fvm::div(rhoPhi, U)
231 { 291 − fvm::laplacian(muf, U)
232 phi −= pcorrEqn.flux(); 292 − (fvc::grad(U) & fvc::grad(muf))
233 } 293 //− fvc::div(muf*(fvc::interpolate(dev(fvc::grad(U))) & mesh.Sf()))
234 } 294 );
235 295
236 # include "continuityErrs.H" 296 if (momentumPredictor)
237 } 297 {
238 298 solve
239 // ************************************************************************* // 299 (
240 300 UEqn
241 // gammaEqnSubCycle.H 301 ==
242 302 fvc::reconstruct
243 303 (
244 label nGammaCorr 304 (
245 ( 305 fvc::interpolate(interface.sigmaK())*fvc::snGrad(gamma)
246 readLabel(piso.lookup("nGammaCorr")) 306 − ghf*fvc::snGrad(rho)
247 ); 307 − fvc::snGrad(pd)
248 308 ) * mesh.magSf()
249 label nGammaSubCycles 309 )
250 ( 310 );
251 readLabel(piso.lookup("nGammaSubCycles")) 311 }
252 ); 312
253 313
254 if (nGammaSubCycles > 1) 314 // ************************************************************************* //
255 { 315
256 dimensionedScalar totalDeltaT = runTime.deltaT(); 316 // pEqn.H
257 surfaceScalarField rhoPhiSum = 0.0*rhoPhi; 317
258 318 {
259 for 319 volScalarField rUA = 1.0/UEqn.A();
260 ( 320 surfaceScalarField rUAf = fvc::interpolate(rUA);
261 subCycle<volScalarField> gammaSubCycle(gamma, nGammaSubCycles); 321
262 !(++gammaSubCycle).end(); 322 U = rUA*UEqn.H();
263 ) 323
264 { 324 surfaceScalarField phiU
265 # include "gammaEqn.H" 325 (
53 54
326 "phiU", 386 gammaScheme
327 (fvc::interpolate(U) & mesh.Sf()) + fvc::ddtPhiCorr(rUA, rho, U, phi) 387 )
328 ); 388 + fvc::flux
329 389 (
330 phi = phiU + 390 −fvc::flux(−phir, scalar(1) − gamma, gammarScheme),
331 ( 391 gamma,
332 fvc::interpolate(interface.sigmaK())*fvc::snGrad(gamma) 392 gammarScheme
333 − ghf*fvc::snGrad(rho) 393 );
334 )*rUAf*mesh.magSf(); 394
335 395 MULES::explicitSolve(gamma, phi, phiGamma, 1, 0);
336 adjustPhi(phi, U, pd); 396
337 397 rhoPhi = phiGamma*(rho1 − rho2) + phi*rho2;
338 for(int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) 398 }
339 { 399
340 fvScalarMatrix pdEqn 400 Info<< "Liquid phase volume fraction = "
341 ( 401 << gamma.weightedAverage(mesh.V()).value()
342 fvm::laplacian(rUAf, pd) == fvc::div(phi) 402 << " Min(gamma) = " << min(gamma).value()
343 ); 403 << " Max(gamma) = " << max(gamma).value()
344 404 << endl;
345 pdEqn.setReference(pdRefCell, pdRefValue); 405 }
346 406
347 if (corr == nCorr−1 && nonOrth == nNonOrthCorr)
407
348 {
349 pdEqn.solve(mesh.solver(pd.name() + "Final"));
350 } • Lines 1-6: especific .H files are included.
351 else
352 {
• Lines 9-21: main function begins, case initialization. Particularly readEnvironmental
353 pdEqn.solve(mesh.solver(pd.name()));
354 } Properties.H reads the gravitational acceleration. createFields.H includes some
355 additional lines respect other solvers, in lines 116-120 twoPhaseProperties object is
356 if (nonOrth == nNonOrthCorr) created with properties read from disk, from this densities are loaded in rho1 and
357 { rho2. Another important fields are gh ghf accounting the product of distance and
358 phi −= pdEqn.flux();
gravitational acceleration for further calculations (see lines 156-158). p field is created
359 }
360 } from relative pressure and fluid column contribution, and reference pressure is set (see
361 lines 161-177). At the end interface object is created to hold interface properties such
362 U += rUA*fvc::reconstruct((phi − phiU)/rUAf); as surface tension, curvature, etc.
363 U.correctBoundaryConditions(); In line 19 correcPhi.H file is included (see lines 185-236), here field phi previously
364 }
365
created is corrected by imposed pressures at boundaries.
366
367 // ************************************************************************* // • Lines 25-32: after starting messages main loop begins reading controls, calculating
368 Courant number and setting the timestep. Last action is performed by setDeltaT.H
369 // gammaEqn.H code, to mantain a constant maximum Courant number, following the steps outlined
370 in section 2.2.3 paragraph Adaptive Time Step Control.
371 {
372 word gammaScheme("div(phi,gamma)"); • Lines 34-36: time is avanced and reported by standar output.
373 word gammarScheme("div(phirb,gamma)");
374
• Line 38: correct() method of twoPhaseProperties object is invoked to calculate the
375 surfaceScalarField phic = mag(phi/mesh.magSf());
376 phic = min(interface.cGamma()*phic, max(phic)); new kinematic viscosity field as a division of Eq. (104) by Eq. (103).
377 surfaceScalarField phir = phic*interface.nHatf();
378 • Line 40: Gamma equation subcycle is performed by gammaEqnSubCycle.H. In order to
379 for (int gCorr=0; gCorr<nGammaCorr; gCorr++) analize this subscycle we continue our analysis in lines 244-278. First of all nGammaCorr
380 { and nGammaSubCycles values are read from PISO section of ./system/fvSolution
381 surfaceScalarField phiGamma = dictionary. These parameters indicates the number of corrections in gamma equation
382 fvc::flux
383 ( (108) necessary to converge to a solution (this is equation is implicit in γ) and the number
384 phi, of subcycles (nsc )as was explained in Section 2.2.3. In line 254 if nGammaSubCycles is
385 gamma, greater tha one the subcycle is started, firstly storing the ∆t of Eq. (120) (the main loop
55 56
time interval), then F in Eq. (121) is initialized in zero. In lines 254-267 gamma subcycle • Lines 44-48: PISO loop over pressure equation, number of correction loops is indicated
is formally performed using a subCycle object. In this loop Eq. (121) summation is by nCorr which was read from dictionaries. To perfor this loop lines in pEqn.H are
calculated next solving gamma in equation by gammaEqn.H code. Finally rhoPhi is executed (lines 316-364). In line 319 the reciprocal of diagonal coefficients (rUA)is
overwritten by the value calculate in the subcycle. In case if nGammaSubCycles is equal calculated (see first term of r.h.s in Eq. 123), this magnitude is used often later. Next,
to one, gammaEqn.H is solved once. As the last thing in the gammaEqnSubCycle.H, rUA is calculated at faces via interpolation with central differencing scheme (line 320),
curvature κ and density field are updated [Eq. 103]. this is necessary due some operators needs face values as arguments.
Now looking inside gammaEqn.H, it is possible to understand the method used for Now, is necessary to assemble the argument of divergence at r.h.s. of Eq. (124).
gamma field advection. Then, let’s in lines 372-405. In lines 372-373, words are defined This argument in two fluxes, one involving only the non-diagonal coefficients of the
to indicate the divergence schemes to flux calculating methods. Next in line 375, matrix and another including gravity and surface tension terms. The first one phiU is
|φ| calculated in lines 322-328, including the correction described in icoFoam solver, then
term S in Eq. 114 is calculated, them in the next line the expresion of minimum is
| f| the extra terms are added in lines 330-334, giving the flux phi. This flux is adjust like
obtained. Cγ coefficient is obtained by a method of interface object. Finally Ur, f ,
in icoFoam in line 336. Now we have the argument of divergence in r.h.s. of pressure
i.e. the compressive velocity at the faces is obtained in line 377, in this case interface
equation. Due it an equation involving a laplacian, which discretized by a gradient,
normal (n f ) is obtained by nHatf() method of interface object. Is important to take
non orthogonal corrections are needed. This correction loop is performed in lines 338-
in account that phir are compressive velocities at faces not fluxes.
360, as many times as is indicated by nNonOrthCorr. Equation for pressure is defined
In order to integrate Eq. (108) an special technique, called MULES27 , is used. This
in lines 340-343 as in indicated by Eq. (124). In line 345 reference pressure is set to start
technique requires giving the advective field as a flux. Due this equation is implicit in
the equation solution (lines 347-354). Once pressure equation is solved as many time
gamma (velocity fields changes if gamma changes) an iterative solution is performed
as was indicated for the non-orthogonal correction loop, new conservative fluxes are
in lines 379-398. This loop is controlled by nGammaCorr that indicates the maximum
assembled as in Eq. (125) in lines 356-359.
number of correction loops. To a best understanding of loop’s code let’s explain the
Velocity field is finally recovered in line 362 by means of Eq. (123) that is implemented
equations implementation.
as:
27
where a0 is the amplitude of the sinusoidal initial perturbation and x is the coordinate
”[interFoam] uses the multidimensional universal limiter for explicit solution (MULES) method, created
by OpenCFD, to maintain boundedness of the phase fraction independent of underlying numerical scheme, along the free surface of fluid in rest state (dashed line in Figure 8). Movement is driven by
mesh structure, etc. The choice of schemes for convection are therfore not restricted to those that are strongly gravitational forces and damped by viscous shear. Boundary conditions are slip in all over
stable or bounded, e.g. upwind differencing”[16]. the boundaries. On the free surface pressure is zero. In the example, inferior fluid is named
57 58
Free surface
h = 1.5 a0
d = 1.0
d = 1.0
Figure 8: Dimensions and initial position for free surface in sloshing problem
Grid (Time=0.0000e+00) a) Grid (Time=0.0000e+00)
Dec 04, 2009 b) Dec 04, 2009
FLUENT 6.3 (2d, dp, pbns, vof, lam, unsteady)
FLUENT 6.3 (2d, dp, pbns, vof, lam, unsteady)
59 60
Figure 10: Comparison of analytical solution and different numerical solutions varying
gamma subcycles, default setting for residuals were kept, time step: 0.001, maximum
Courant number: 0.5 and maximum time step: 1.
Figure 11: Comparison of analytical solution and different numerical solutions varying
residuals from original to change in velocity and all equations residuals. Time step: 0.001,
maximum Courant number: 0.5 and maximum time step: 1.
Is important to note that residuals were, in all cases, decreased. No test were carried out
with greater residuals, but elapsed time for default residuals was acceptable.
In last tests time step and temporal discretization were changed (see Figure 12 and 13).
In the first one time step was decreased from the original (0.001) to 10 times smaller, and
100 times smaller, maximum Courant number and maximum time step was decreased by
the same ratio, temporal discretization scheme was kept isn in default settings (Backward
Euler). As is shown in Figure 12, time step has an important impact in free surface tracking.
Finally to avoid to small timestep (0.001/100 time step gives an acceptable solution but
requires relatively longer calculation time), temporal discretization is changed (see Figure
13. For original timestep (0.001) Crank-Nicholson has no effect, so smaller timestep is tested
(decreasing maximum Courant number and maximum timestep as was explained) with this
scheme in two cases, one with default residuals (d.r.) and another with all residuals set in
1e-10. As is shown in the figure best results of all (from Figure 12 and 13) are obtained with
default setting for residuals and Crank-Nicholson scheme (for 0.001/10 time step).
5 Conclusions
In this work a brief description of the Finite Volume Method and Volume of Fluid Method
were given. These description is based on bibliography related to the OpenFOAM suite,
where results were obtained. Figure 12: Comparison of analytical solution and different numerical solutions varying times
step for Backward Euler discretization scheme (For time step, maximum Courant number
Nowadays OpenFOAM community is growing fast, and this software is starting to be and and maximum time step see text).
considerated a threaten for commercial companies and an interisting tool for academics.
So the importance of a good understanding of this tool is superlative. In this way, this
work is a contribution to this comprehension, describing in detail three important solvers as
advection-diffusion solver, Navier-Stokes and VOF.
61 62
References
[1] http://en.wikipedia.org/wiki/OpenFOAM
[2] http://www.openfoam.org
[3] Ferziger, J.H.; Peric, M. Computational Methods for Fluid Dynamics, 1995
[4] Versteeg, H.K.; Malalasekera, W. An introduction to Computational Fluid Dynamics, 1st. edition.
[5] Jasak, H. Error Analysis and Estimation for the Finite Volume Method with Applications to Fluid Flows,
Ph.D Thesis, Imperial College of Science, Technology and Medicine, London, 1996.
[7] Patankar, S.V. Numerical Heat Transfer and Fluid Flow, 1981.
[10] Hirt, C.W.; Nichols B.D. Volume of Fluid (VOF) Method for the Dynamics of Free Boundaries, Journal
of Computational Physics, Vol. 39, 1, p. 201-225
Writing this description required a lot research in forums, personal contact with devel-
opers and users, reverse engineering and theoretical revising. All this factors are now joined [11] Ubbink, O. Numerical prediction of two fluid systems with sharp interfaces, Ph.D Thesis, Imperial
and crosslinked, in order to connect the code with the underlying theory. College of Science, Technology and Medicine, London, 1997.
[12] Ubbink, H. Computational Fluid Dynamics of Dispersed Two-Phase Flows at High Phase Fractions,
As a practical example sloshing problem was solved showing relative concordance with Ph.D Thesis, Imperial College of Science, Technology and Medicine, London, 2002.
theoretical results. Obviously a lot of another important parameters weren’t changed, as the
mesh, compressive schemes, corrections in MULES solver, preconditioners, solvers, etc. but [13] Berberovic, E.; Van Hinsberg, N.P.; Jakirlic, S.; Roisman, I.V; Tropea, C. Drop impact onto a liquid
it’s a good start point, and the intention was only show an example using the examined tool. layer of finite thicness: Dynamics of the cavity evolution, Physical Review E, 79, 2009.
More research can be done fixing a real problem and working on it.
[14] OpenCFD, Technical Report No. TR/HGW/02, 2005 (unpublished).
[15] A tensorial approach to computational continuum mechanics using object-oriented techniques, Comput-
ers in Physics, Vol. 12, 6, p. 620-631, 1998
6 Acknowledgements
[16] OpenCFD Ltd. OpenFOAM, The Open Source CFD Toolbox, User Guide, 2009.
I would give my sincere thanks to my advisors Noberto M. Nigro, Mario A. Storti and
[17] OpenCFD Ltd. OpenFOAM, The Open Source CFD Toolbox, Programmer’s Guide, 2009.
Damian Ramajo (from CIMEC-INTEC, CONICET/UNL, Argentin) for their support. I want
to recognize also free help received from Patricio Bohorquez (Universidad de Malaga, Spain), [18] http://openfoamwiki.net/index.php/IcoFoam
Ola Widlund (CEA, Grenoble, France), Laurence R. McGlashan (Computational Modelling
Group, University of Cambridge), Martin Romagnoli (Universidad Nacional de Rosario, [19] Prosperetti, A Motion of Two Superposed Viscous Fluids, Physics of Fluids, 24(7):1217-1223, 1981.
Argentina) and Daniel Wei (Tongji University, Shangai, China) and all contributors in CFD-
Online forums, OpenFOAMWiki, OpenFOAM Workshops, etc.
63 64