0% found this document useful (0 votes)
63 views95 pages

Introduction To Openfoam, Part 1: Theoretical Foundations of Nite Volume Approach

1) The document introduces the theoretical foundations of the finite volume method (FVM) used in OpenFOAM, including conservation principles, the control volume approach, and Reynolds transport theorem. 2) Reynolds transport theorem is used to convert time derivatives within a control mass to derivatives within a fixed control volume, resulting in convection terms that account for flux through boundaries. 3) Applying conservation principles to mass, scalar quantities, and momentum using the control volume approach and Reynolds transport theorem results in the differential conservation equations for these quantities.

Uploaded by

Xingxing Huang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views95 pages

Introduction To Openfoam, Part 1: Theoretical Foundations of Nite Volume Approach

1) The document introduces the theoretical foundations of the finite volume method (FVM) used in OpenFOAM, including conservation principles, the control volume approach, and Reynolds transport theorem. 2) Reynolds transport theorem is used to convert time derivatives within a control mass to derivatives within a fixed control volume, resulting in convection terms that account for flux through boundaries. 3) Applying conservation principles to mass, scalar quantities, and momentum using the control volume approach and Reynolds transport theorem results in the differential conservation equations for these quantities.

Uploaded by

Xingxing Huang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 95

Introduction to OpenFOAM, part 1: theoretical

foundations of nite volume approach

Sibgatullin I.

[email protected]

Moscow Lomonosov State University

19 ìàÿ 2016 ã.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 1 / 89
To work in CFD, one needs a solid background in both uid mechanics
and numerical analysis; signicant errors have been made by people
lacking knowledge in one or the other.

Estimation of numerical errors. A qualitatively incorrect solution of a


problem may look reasonable (it may even be a good solution of
another problem), the consequences of accepting it may be severe.

Computational Methods for Fluid Dynamics.


Professor Joel H. Ferziger, Dr. Milovan Peric

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 2 / 89
OpenFOAM is rst and foremost a C++ library, used primarily to create
executables, known as applications.
OpenFOAM User Guide

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 3 / 89
Conservation principles

Conservation laws can be derived by considering a given quantity of matter


or control mass (CM) and its extensive properties, such as mass,
momentum and energy.

zero 0
Z
d  
ϕρ dΩ = + sources + ows through boundaries
dt
ΩCM

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 4 / 89
The conservation equation for mass:

dm
=0. (1)
dt
On the other hand, momentum can be changed by the action of forces and
its conservation equation is Newton's second law of motion:

d(m~v ) X ~
= F , (2)
dt

where t stands for time, m for mass, ~v for the velocity, and f~ for forces
acting on the control mass.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 5 / 89
CM approach is used to study the dynamics of solid bodies, where the CM
(sometimes called the system) is easily identied.
In uid ows, however, it is dicult to follow a parcel of matter. It is more
convenient to deal with the ow within a certain spatial region we call a
control volume (CV), rather than in a parcel of matter which quickly passes
through the region of interest. This method of analysis is called the control
volume approach.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 6 / 89
Closer look to control volume

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 7 / 89
Reynolds transport theorem
φ  conserved intensive property (for mass conservation, φ = 1; for momentum
conservation, φ = ~v ; for conservation of a scalar, φ represents the conserved
property per unit mass) The corresponding extensive property Φ can be expressed
as: Z
Φ= ρφ dΩ , (3)

ΩCM

ΩCM stands for volume occupied by the CM


LHS of each conservation equation for a control volume can be written:
Z Z Z
d d
ρφ dΩ = ρφ dΩ + ρφ (~v − ~vb ) · ~n dS , (4)
dt dt
ΩCM ΩCV SCV

ΩCV is the CV volume, SCV is the surface enclosing CV,


~n is the unit vector orthogonal to SCV and directed outwards,
~vb is the velocity with which the CV surface is moving.
For xed CV ~ vb = ~0, rst derivative on the RHS becomes a local (partial).
The last term is usually called the convective (or sometimes, advective) ux of φ
through the CV boundary.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 8 / 89
Reynolds transport theorem if CV is xed in space

∂ ∂

If CV does not change in time vb = 0, ∂t CV = ∂t :
Z Z Z
d ∂
ρφ dΩ = (ρφ) dΩ + ρφ (~v , ~n) dS = (5)
dt ∂t
ΩCM ΩCV SCV

(Homework: Consider Dierentiation under the integral sign


https://en.wikipedia.org/wiki/Dierentiation_under_the_integral_sign
and describe its connection to dierentiation over CM and to Reynolds
Transport Theorem.)
Z  

= (ρφ) + div (ρφ~v ) dΩ (6)
∂t
ΩCV

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 9 / 89
Mass Conservation

φ→1 (7)
Z Z

ρ dΩ + ρ~v · ~n dS = 0 . (8)
∂t Ω S
By applying the Gauss-Ostrogradsky divergence theorem to the convection
term, we can transform the surface integral into a volume integral.
Allowing the control volume to become innitesimally small leads to a
dierential coordinate-free form of the continuity equation:

∂ρ
+ div (ρ~v ) = 0 . (9)
∂t

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 10 / 89
Scalar Conservation

#„
Z Z Z
d
ϕρ dv = sϕ ρ dv − ~qϕ · ds (10)
dt
ΩCM ΩCV ∂ΩCV


(ρφ) + ∇i (ρφv i ) = sφ − ∇k qϕk (11)
∂t
sφ  source of ϕ, ~q  ux of ϕ through boundaries.
Diusive transport is always present (even in stagnant uids), and it is
usually described by a gradient approximation, e.g. Fourier's law for heat
diusion and Fick's law for mass diusion:
Z
~qϕ = −λ ∇ϕ , Qϕ = − λ ∇ϕ · ~n dS , (12)
S

where λ is the diusivity for the quantity ϕ.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 11 / 89
Momentum Conservation

φ → ~v (13)
Z Z
∂ X
ρ~v dΩ + ρ~v (~v , ~n) dS = F~ . (14)
∂t Ω S
To express the right hand side in terms of intensive properties, one has to
consider the forces which may act on the uid in a CV:

body forces (gravity, centrifugal and Coriolis forces, electromagnetic


forces, etc.).

surface forces (pressure, normal and shear stresses, surface tension


etc.);

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 12 / 89
Momentum Conservation

Z Z Z Z

ρ~v dΩ + ρ~v (~v , ~n) dS = f~ρ dΩ + ~σn dS . (15)
∂t Ω S Ω S

f~  body mass forces per unit of mass, σ~n  surface forces per unit of area.
σ~n = ~σ i ni , ~σ i  surface forces per unit of area on i-th coordinate plane.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 13 / 89
Momentum Conservation

Z Z Z Z

ρ~v dΩ + ρ~v (~v , ~n) dS = f~ρ dΩ + ~σn dS . (15)
∂t Ω S Ω S

f~  body mass forces per unit of mass, σ~n  surface forces per unit of area.
σ~n = ~σ i ni , ~σ i  surface forces per unit of area on i-th coordinate plane.
Z Z Z Z
∂ i ~
ρ~v dΩ + ρ~v v ni dS = f ρ dΩ + ~σ i ni dS . (16)
∂t Ω S Ω S

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 13 / 89
Momentum Conservation

Z Z Z Z

ρ~v dΩ + ρ~v (~v , ~n) dS = f~ρ dΩ + ~σn dS . (15)
∂t Ω S Ω S

f~  body mass forces per unit of mass, σ~n  surface forces per unit of area.
σ~n = ~σ i ni , ~σ i  surface forces per unit of area on i-th coordinate plane.
Z Z Z Z
∂ i ~
ρ~v dΩ + ρ~v v ni dS = f ρ dΩ + ~σ i ni dS . (16)
∂t Ω S Ω S

Z   Z 
∂ 
i
(ρ~v ) + ∇i (ρ~v v ) dΩ = f~ρ + ∇i~σ i dΩ . (17)
Ω ∂t Ω

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 13 / 89
Momentum Conservation

Z Z Z Z

ρ~v dΩ + ρ~v (~v , ~n) dS = f~ρ dΩ + ~σn dS . (15)
∂t Ω S Ω S

f~  body mass forces per unit of mass, σ~n  surface forces per unit of area.
σ~n = ~σ i ni , ~σ i  surface forces per unit of area on i-th coordinate plane.
Z Z Z Z
∂ i ~
ρ~v dΩ + ρ~v v ni dS = f ρ dΩ + ~σ i ni dS . (16)
∂t Ω S Ω S

Z   Z 
∂ 
i
(ρ~v ) + ∇i (ρ~v v ) dΩ = f~ρ + ∇i~σ i dΩ . (17)
Ω ∂t Ω


(ρ~v ) + ∇i (ρ~v v i ) = f~ρ + ∇i~σ i . (18)
∂t

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 13 / 89
Dierence between solids and uids

Fluid is a substance that continually deforms (ows) under an applied shear


stress.
Fluid is a substance whose molecular structure cannot resist any shear force
applied to it.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Dierence between solids and uids

Fluid is a substance that continually deforms (ows) under an applied shear


stress.
Fluid is a substance whose molecular structure cannot resist any shear force
applied to it.
In ideal uid:
~σ~n = −p~n (20)

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Dierence between solids and uids

Fluid is a substance that continually deforms (ows) under an applied shear


stress.
Fluid is a substance whose molecular structure cannot resist any shear force
applied to it.
In ideal uid:
~σ~n = −p~n (20)

In viscous incompressible uid: ~σ~n = ~σ i ni = σ ik~ek ni

σ ik = −pg ik + 2µeik (21)

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Dierence between solids and uids

Fluid is a substance that continually deforms (ows) under an applied shear


stress.
Fluid is a substance whose molecular structure cannot resist any shear force
applied to it.
In ideal uid:
~σ~n = −p~n (20)

In viscous incompressible uid: ~σ~n = ~σ i ni = σ ik~ek ni

σ ik = −pg ik + 2µeik (21)

In viscous compressible uid (second viscosity assumed to be 0):

 
ik 2
σ = − p + µ div ~v g ik + 2µeik (22)
3

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Navier  Stokes equations

Convective form:
 
∂~v µ
ρ + v k ∇k~v = −∇p + ∇k µ∇k~v + ∇(∇ · v) + ρ~g
∂t 3

Conservative form:

∂ µ
(ρv k ) + ∇i (ρv k v i ) = −∇p + µ∆~v + ρ~g + ∇(∇ · v)
∂t 3

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 17 / 89
Dierence between solids and uids

An ideal elastic solid will deform under load and, once the load is removed,
will return to its original state. Some solids are plastic. These deform under
the action of a sucient load and deformation continues as long as a load
is applied, providing the material does not rupture. Deformation ceases
when the load is removed, but the plastic solid does not return to its
original state.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 18 / 89
Dierence between solids and uids

An ideal elastic solid will deform under load and, once the load is removed,
will return to its original state. Some solids are plastic. These deform under
the action of a sucient load and deformation continues as long as a load
is applied, providing the material does not rupture. Deformation ceases
when the load is removed, but the plastic solid does not return to its
original state.
In ideal elastic solid stess vector and so stress tensor depends on
deformations: ~σ~n = ~σ i ni = σ ik~ek ni

σ ik = λI1 (ε)g ik + 2µεik (23)

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 18 / 89
Dierence between solids and uids

An ideal elastic solid will deform under load and, once the load is removed,
will return to its original state. Some solids are plastic. These deform under
the action of a sucient load and deformation continues as long as a load
is applied, providing the material does not rupture. Deformation ceases
when the load is removed, but the plastic solid does not return to its
original state.
In ideal elastic solid stess vector and so stress tensor depends on
deformations: ~σ~n = ~σ i ni = σ ik~ek ni

σ ik = λI1 (ε)g ik + 2µεik (23)

3λ + 2µ λ
E=µ , σ= (24)
λ+µ 2(λ + µ)

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 18 / 89
Dierentianl equations of continuum media:
divergence form
Mass conservation:
∂ρ
+ ∇i (ρv i ) = 0 (25)
∂t
Momentum conservation:


(ρv k ) + ∇i (ρv k v i ) = ∇i σ ik + ρf k (26)
∂t
Scalar conservation:


(ρϕ) + ∇i (ρϕv i ) = sϕ ρ − div ~qϕ
∂t
Such a form is somtimes also called conservation form since as we will see
in FV mehod integral quantities are conserved after space discretisation
(decomposition to nite volumes).
So this form of equations is essential for OpenFOAM

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 19 / 89
Divergence form of dierentianl equations in tensor notation
∂ρ
+ div (ρ~v ) = 0
∂t

(ρ~v ) + div (ρ~v~v ) = div σ + ρf~
∂t

(ρϕ) + div (ρϕ~v ) = sϕ ρ − div ~qϕ
∂t
 
v1 v1 v1 v2 v1 v3
~v~v means ~v ⊗ ~v = [vi vk ] =  v2 v1 v2 v2 v2 v3 
v3 v1 v3 v2 v3 v3

div (ρ~v~v ) means div (ρv k~v )ek ; div (σ) means ∇i pik ek
Do you think that engeneers who uses OpenFOAM and commercial
packages for years always understand it? You're wrong!

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 20 / 89
Boundary condirions

Slip, No-slip  boring

Stressfree Stressful

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 21 / 89
Dimensionless form of equations

t xi ui p T − T0
t∗ = ; x∗i = ; u∗i = ; p∗ = ; T∗ = .
t0 L0 v0 ρv02 T1 − T0

∂u∗i
=0, (27)
∂x∗i
∂u∗i ∂(u∗j u∗i ) 1 ∂ 2 u∗i ∂p∗ 1
St ∗
+ ∗ = ∗2 − ∗ + 2 γi , (28)
∂t ∂xj Re ∂xj ∂xi Fr
∂T ∗ ∂(u∗j T ∗ ) 1 ∂2T ∗
St + ∗ = . (29)
∂t∗ ∂xj Re Pr ∂x∗2
j

In theoretical books on Mechanics of Continua Media you can often see


that when they describe the problem, they add asteriscs * to all the
varables (dimensional). And later they use usual notation for dimensionless
variables. In CFD books this kind of notiation is less popular, since for
complex problems and geometry dimensionless form is often useless.
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 23 / 89
Simplied models
Incompressible ows

div ~v = 0 , (30)

∂ui 1
+ div (ui~v ) = div (ν grad ui ) − div (p~ii ) + bi , (31)
∂t ρ

Inviscid (Euler) ow:

∂(ρui )
+ div (ρui~v ) = −div (p~ii ) + ρbi . (32)
∂t

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 24 / 89
Simplied models
Potential ows

div ~v = 0 , (33)

∂ui 1
+ div (ui~v ) = div (ν grad ui ) − div (p~ii ) + bi , (34)
∂t ρ

rot ~v = 0 . (35)

~v = −grad Φ
For incompressible ows:
div (grad Φ) = 0 .

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 25 / 89
Simplied models
Creeping (Stokes) Flow

When the ow velocity is very small, the uid is very viscous, or the
geometric dimensions are very small (i.e. when the Reynolds number is
small), the convective (inertial) terms in the Navier-Stokes equations play a
minor role and can be neglected.

1
div (µ grad ui ) − div (p~ii ) + bi = 0 . (36)
ρ
Creeping ows are found in porous media, coating technology,
micro-devices etc.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 26 / 89
The Algebraic Equation System
X
AP φ P + Al φl = QP , (37)
l
where P denotes the node at which the partial dierential equation is
approximated and index l runs over the neighbor nodes involved in
nite-dierence approximations. The node P and its neighbors form the
so-called computational molecule
NN
T
N NW N NE
N
W P E WW W P E EE
W P E
S
S SW S SE
B
SS

Ilias Sibgatullin (Moscow


Ðèñ.: University)
Examples OpenFOAM course 1: theory
of computational of FVM
molecules 19 ìàÿ
in 2D and 3D 2016 ã. 27 / 89
The Algebraic Equation System
This system is sparse, meaning that each equation contains only a few
unknowns. The system can be written in matrix notation as follows:

~=Q
Aφ ~ , (38)

where A is the square sparse coecient matrix, ~


φ is a vector (or column
matrix) containing the variable values at the grid nodes, and ~
Q is the
vector containing the terms on the right-hand side of Eq. (37).

The structure of matrix A depends on the ordering of variables in the


vector ~.
φ For structured grids, if the variables are labeled starting at a
corner and traversing line after line in a regular manner (lexicographic
ordering), the matrix has a poly-diagonal structure. For the case of a
ve-point computational molecule, all the non-zero coecients lie on the
main diagonal, the two neighboring diagonals, and two other diagonals
removed by N positions from the main diagonal, where N is the number of
nodes in one direction. All other coecients are zero. This structure allows
use of ecient iterative solvers.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 28 / 89
The Algebraic Equation System
Conversion of grid indices to one-dimensional storage locations for vectors or column
matrices
Grid location Compass notation Storage location

i, j, k P l = (k − 1)Nj Ni + (i − 1)Nj + j
i − 1, j, k W l − Nj
i, j − 1, k S l−1
i, j + 1, k N l+1
i + 1, j, k E l + Nj
i, j, k − 1 B l − Ni Nj
i, j, k + 1 T l + Ni Nj

NN
T
N NW N NE
N

W P E WW W P E EE
W P E
S
S SW S SE
B
SS

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 29 / 89
The Algebraic Equation System

Because the matrix A is sparse, it does not make sense to store it as a


two-dimensional array in computer memory (this is standard practice for
full matrices). Storing the elements of each non-zero diagonal in a separate
array of dimension 1 × Ni Nj , where Ni and Nj are the numbers of grid
5Ni Nj words of
points in the two coordinate directions, requires only
2 2
storage; full array storage would require Ni Nj words of storage. In three
2 2 2
dimensions, the numbers are 7Ni Nj Nk and Ni Nj Nk , respectively. The
dierence is suciently large that the diagonal-storage scheme may allow
the problem to be kept in main memory when the full-array scheme does
not.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 30 / 89
The Algebraic Equation System
The linearized algebraic equations in two dimensions can now be written in the form:

Al,l−Nj φl−Nj + Al,l−1 φl−1 + Al,l φl + Al,l+1 φl+1 + Al,l+Nj φl+Nj = Ql

φW

φS
AW AS AP AN AE * φP = QP
φN

φE

Ðèñ.: Structure of the matrix for a ve-point computational molecule (non-zero


entries in the coecient matrix on ve diagonals are shaded; each horizontal set
of boxes corresponds to one grid line)
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 31 / 89
The Algebraic Equation System
Matrix storage
As noted above, it makes little sense to store the matrix as an array. If,
instead, the diagonals are kept in separate arrays, it is better to give each
diagonal a separate name. Since each diagonal represents the connection to
the variable at a node that lies in a particular direction with respect to the
central node, we shall call them AW , AS , AP , AN and AE ; their locations
in the matrix for a grid with 5 × 5 internal nodes are shown in Fig. 3. With
this ordering of points, each node is identied with an index l, which is also
the relative storage location. In this notation the equation can be written

AW φ W + AS φ S + AP φ P + AN φ N + AE φ E = Q P , (39)

where the index l, which indicated rows, is understood, and the index
indicating column or location in the vector has been replaced by the
corresponding letter. We shall use this shorthand notation from now on.
When necessary for clarity, the index will be inserted. A similar treatment
applies to three-dimensional problems.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 32 / 89
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 33 / 89
<++>

Lecture 2. Finite Volume Approximations

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 33 / 89
Finite Volume Methods
Z Z Z
ρφ~v · ~n dS = Γ grad φ · ~n dS + qφ dΩ . (40)
S S Ω
The solution domain is subdivided into a nite number of small control
volumes (CVs) by a grid which, in contrast to the nite dierence (FD)
method, denes the control volume boundaries, not the computational
nodes.

Surface integrals over inner CV faces cancel out.


Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 34 / 89
The net ux through the CV boundary is the sum of integrals over the four
(in 2D) or six (in 3D) CV faces:

Z XZ
f dS = f dS , (41)
S k Sk

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 35 / 89
yj+1
NW N NE

yj nw n ne
WW W w P e ne E EE
∆y

yj-1 sw s se

y SW S SE
∆x
j
i x xi-1 xi x i+1

Ðèñ.: A typical CV and the notation used for a Cartesian 2D grid

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 36 / 89
T

n
t N
∆z
n
W w e n E
P
s
n
b
z S
y ∆y
k j B
i x ∆x

Ðèñ.: A typical CV and the notation used for a Cartesian 3D grid

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 37 / 89
To calculate the surface integral exactly, one would need to know the
integrand f everywhere on the surface Se . This information is not available,
as only the nodal (CV center) values of φ are calculated so an
approximation must be introduced. This is best done using two levels of
approximation:

the integral is approximated in terms of the variable values at one or


more locations on the cell face;

the cell-face values are approximated in terms of the nodal (CV


center) values.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 38 / 89
The simplest approximation to the integral is the midpoint rule: the
integral is approximated as a product of the integrand at the cell-face
center (which is itself an approximation to the mean value over the surface)
and the cell-face area:
Z
Fe = f dS = f e Se ≈ fe Se . (42)
Se

This approximation of the integral  provided the value of f at location `e'


is known  is of second-order accuracy.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 39 / 89
Another second-order approximation of the surface integral in 2D is the
trapezoid rule, which leads to:
Z
Se
Fe = f dS ≈ (fne + fse ) . (43)
Se 2

In this case we need to evaluate the ux at the CV corners.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 40 / 89
Approximation of Volume Integrals

The simplest second-order accurate approximation is to replace the volume


integral by the product of the mean value of the integrand and the CV
volume and approximate the former as the value at the CV center:
Z
QP = q dΩ = q ∆Ω ≈ qP ∆Ω , (44)

where qP stands for the value of q at the CV center.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 41 / 89
Interpolation and Dierentiation Practices

The approximations to the integrals require the values of variables at


locations other than computational nodes (CV centers).
f c = ρφ~v · ~n for the convective ux
f d = Γgrad φ · ~n for the diusive ux
We assume that the velocity eld and the uid properties ρ and Γ are
known at all locations.
To calculate the convective and diusive uxes, the value of φ and its
gradient normal to the cell face at one or more locations on the CV surface
are needed. Volume integrals of the source terms may also require these
values. They have to be expressed in terms of the nodal values by
interpolation.
How the value of φ and its normal derivative at cell face `e' can be
approximated?

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 42 / 89
The Algebraic Equation System

By summing all the ux approximations and source terms, we produce an


algebraic equation which relates the variable value at the center of the CV
to the values at several neighbor CVs.
The numbers of equations and unknowns are both equal to the number of
CVs so the system is well-posed.
This is true only for structured grids with quadrilateral or hexahedral CVs;
for other geometries, the matrix structure will be more complex but it will
always be sparse.
The maximum number of elements in any row is equal to the number of
near neighbors for second order approximations.
For higher-order approximations, it depends on the number of neighbors
used in the scheme.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 43 / 89
Client  server model

The providers of a resource or service are called servers and service


requesters are called clients.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 44 / 89
What is relationship of Client  Server to Client  Patron in Rome (clientela)?

Question asked by Mech. & Math. faculty auditorium  obviously it is not Cibernetics faculty.

Modern Clientela 
Italian Maa.

At this moment

Don Corleone

demands:

call me a Server

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 45 / 89
Process of numerical simulation on Unihub.ru

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 46 / 89
вычисл узел n1
Управляющая
вычисл узел n2
Машина
кластера вычисл узел n3
МСЦ РАН

...
vcn.unicluster.ru

управляющая
web-interface Машина
user of UNIHUB.RU для доступа
к ресурсам Кластер
unihub анализа
desktop.weblab.cloud.unihub.ru больших
данных
sl-BIG

для входа на упраляющий узел кластера с sl-BIG:


ssh -X vcn.unicluster.ru

для входа на вычислительные узлы:


...
qsub -I -l walltime=00:10:00,nodes=1:ppn=8

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 47 / 89
Access to computational clusters

To enter on the management node of the cluster:

ssh -X vcn.unicluster.ru

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 48 / 89
Cluster management
Batch queuing for HPC clusters
An important niche for job schedulers is managing the job queue for a
cluster of computers. Typically, the scheduler will schedule jobs from the
queue as sucient resources (cluster nodes) become idle. Some widely used
R , Univa Grid
cluster batch systems are Moab, Argent Job Scheduler
Engine, Portable Batch System, LoadLeveler, Condor, OAR, Simple Linux
Utility for Resource Management (SLURM), OpenLava, and IBM's
Platform LSF.
TORQUE The Terascale Open-source Resource and QUEue Manager
(TORQUE) is a distributed resource manager providing control over batch
jobs and distributed compute nodes.

Portable Batch System (or simply PBS) is the name of computer software
that performs job scheduling. Its primary task is to allocate computational
tasks, i.e., batch jobs, among the available computing resources. It is often
used in conjunction with UNIX cluster environments.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 49 / 89
Background execution (batch mode)

1) Ñîçäàòü çàäàíèå (myjob):


#PBS -l walltime=HH:MM:SS,nodes=[# of nodes]:ppn=[# of cores]
#PBS -q workq@master
#PBS -M [email protected]
#PBS -m abe
#PBS -N jobname
#!/bin/sh
cd [path to the programm/data]
mpirun -np [nodes]õ[cores] -machinefile $PBS_NODELIST [programs]
2) Submit a job in queue for execution
qsub myjob
3) Job status
qstat
qstat -f [ID çàäàíèÿ]

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 50 / 89
Interactive execution on computational nodes
1) Submit an interactive job to the queue for execution

[master@jx0]$qsub -I -l walltime=HH:MM:SS,nodes=[nodes]:ppn=[cores]
[job ID].[job name]
[master@jx64]$
2) Execute a programm

[master@jx64]$ cd [path to a programm/data]


[master@jx64]$ mpirun -np [nodes]õ[cores] -machinefile $PBS_NODELIST
Environmental variables:

echo $PBS_ENVIRONMENT
echo $PBS_JOBNAME
echo $PBS_O_PATH
echo $PBS_QUEUE
echo $PBS_JOBID
echo $PBS_NODEFILE
echo $PBS_O_HOST
echo $PBS_O_WORKDIR
...
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 51 / 89
Important Environment Variables

$WM_PROJECT_DIR  path to the OpenFOAM installation


$WM_PROJECT_USER_DIR  OpenFOAM user directory
$FOAM_TUTORIALS  OpenFOAM tutorials
$FOAM_SRC  source-tree of OpenFOAM libraries
$FOAM_APP  source-tree of OpenFOAM applications
$FOAM_APPBIN  directory with the applications
$FOAM_USER_APPBIN  directory with the applications created by the u
$FOAM_LIBBIN  directory with the libraries provided by OpenFOAM
$FOAM_USER_LIBBIN  directory with the libraries created by the user
$FOAM_RUN  directory where the user can put his/her cases

Important Shell-Aliases

run  cd to $FOAM_RUN
src  cd to $FOAM_SRC
app  cd to $FOAM_APP
util  cd to $FOAM_APP/utilities
sol  cd to $FOAM_APP/solvers

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 52 / 89
Basic Case Structure (Áàçîâàÿ ñòðóêòóðà ïðèìåðà)
Case  boundary value problemm with initial conditions. Çàäà÷à ñ
ãðàíè÷íûìè óñëîâèÿìè è íà÷àëüíûìè äàííûìè.
case  relative or absolute path to the case
case/  the case directory
+ 0/  ñîäåðæèò íà÷àëüíûå è ãðàíè÷íûå óñëîâèÿ
+ constant/  constant data (äàííûå è êîíñòàíòû)
+ polyMesh/  ñîäåðæèò äàííûå ñåòêè
+ transportProperties  âÿçêîñòü
+ system/  run-time control / numerics
+ controlDict  run-time control (ïàðàìåòðû äëÿ êîíòðîëÿ çàäà÷è)
+ fvSchemes  numerical schemes (ðàñ÷åòíûå ñõåìû)
+ fvSolution  ðåøàòåëè äëÿ ÑËÀÓ
case/0/  contains for each variable a e defning the initial and
boundary conditions. May also contain initial and boundary conditions
for a moving grid.
case/constant/polyMesh/  contains the grid data for a non-moving
grid. The es are: boundary, faces, neighbour, owner, points.
case/constant/transportProperties
Ilias Sibgatullin (Moscow University)  1:defnes
OpenFOAM course theory of the
FVM viscosity
19 (also for
ìàÿ 2016 ã. 53 / 89
OpenFOAM structure

OpenFOAM consists of solvers and utilities.


Solvers are designed to solve a specic kind of problem in continuum
mechanics.
Utilities are designed for data manipulation.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 54 / 89
OpenFOAM tutorials
Tutorials are located in directory, indicated by $FOAM_TUTORIALS
environment variable. Tutorials are grouped by directories with descriptive
names:

DNS
basic
combustion
compressible
discreteMethods
electromagnetics
financial
heatTransfer
incompressible
lagrangian
mesh
multiphase
resources
stressAnalysis

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 55 / 89
Case structure
Constant directory contains a description of the
case mesh in a subdirectory polyMesh and les
specifying physical properties for the application
concerned, e.g.transportProperties.
System directory for setting parameters
associated with the solution procedure itself.
It contains at least the following 3 les:
controlDict where run control parameters are
set including start/end time, time step and
parameters for data output; fvSchemes where
discretisation schemes used in the solution
may be selected at run-time; and, fvSolution
where the equation solvers, tolerances and other
algorithm controls are set for the run.
The `time' directories Initial values and boundary
conditions that the user must specify to dene
the problem; or, results written to le by
OpenFOAM.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 56 / 89
Case study: Lid-driven cavity ow

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 57 / 89
Meshing

The most basic and simple mesh generation tool for OpenFOAM is
blockMesh utility. It can create a structured mesh in a rectangular
geometry. The mesh is described in the le blockMeshDict located in
system directory of current case.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 58 / 89
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.1;

vertices
(
(0 0 0)
(1 0 0)
(1 1 0)
(0 1 0)
(0 0 0.1)
(1 0 0.1)
(1 1 0.1)
(0 1 0.1)
);

blocks
(
hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);

edges
(
Ilias
); Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 59 / 89
edges
(
);

boundary
(
movingWall
{
type wall;
faces
(
(3 7 6 2)
);
}
fixedWalls
{
type wall;
faces
(
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 60 / 89
Boundary conditions

Boundary and initial conditions are usually set in the subdirectory 0 of the
case in le, whose name correspond to names of variables.
To set dimensions of variables dimensionSet entry is used.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 61 / 89
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -2 0 0 0 0];

internalField uniform 0;

boundaryField
{
movingWall
{
type zeroGradient;
}

fixedWalls
{
type zeroGradient;
}

frontAndBack
{
type empty;
}
}
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 62 / 89
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
movingWall
{
type fixedValue;
value uniform (1 0 0);
}

fixedWalls
{
type fixedValue;
value uniform (0 0 0);
}

frontAndBack
{
type empty;
Ilias Sibgatullin
} (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 63 / 89
Physical properties

Physical properties are set in constant subdirectory of a case in les, with


names ending by ..Properties
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

nu [0 2 -1 0 0 0 0] 0.01;

// ************************************************************************* //

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 64 / 89
Solution control

Start and end- time of execution, timestep and write control are set in
controlDict le of constant subdirectory
Ensure that Courant number is less than 1:

δt
Co = |U |
δx
d 0.1
δx = = = 0.005m
n 20
0.005
δt < = 0.005
|U | = 1

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 65 / 89
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 66 / 89
Discretisation and linear-solver settings

Finite volume discretisation schemes are set in the fvSchemes dictionary in


the system directory.
The specication of the linear equation solvers and tolerances and other
algorithm controls is made in the fvSolution dictionary,

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 67 / 89
Postprocessing

Viewing the mesh

Isosurface and contour plots

Vector plots

Streamline plots

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 68 / 89
Increasing the mesh resolution. Creating the ner mesh

Mapping the coarse mesh results onto the ne mesh


mapFields utility maps one or more elds relating to a given geometry
onto the corresponding elds for another geometry.
The eld data that mapFields maps is read from the time directory
specied by startFrom/startTime in the controlDict of the target case, i.e.
those into which the results are being mapped.
deltaT -> 0.0025, writeControl: timeStep
Control adjustments: ->
runTime, writeInterval -> 0.1

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 69 / 89
Plotting graphs

foamCalc <calcType> <fieldName1 ... fieldNameN>

cd $FOAM_RUN/tutorials/incompressible/icoFoam/cavity
foamCalc components U

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 70 / 89
Stress analysis of a plate with a hole

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 71 / 89
Stress analysis of a plate with a hole

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 72 / 89
Stress analysis of a plate with a hole

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 73 / 89
Stress analysis of a plate with a hole

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 74 / 89
Stress analysis of a plate with a hole
blockMeshDict I
convertToMeters 1;
vertices
(
(0.5 0 0)
(1 0 0)
(2 0 0)
(2 0.707107 0)
(0.707107 0.707107 0)
(0.353553 0.353553 0)
(2 2 0)
(0.707107 2 0)
(0 2 0)
(0 1 0)
(0 0.5 0)
(0.5 0 0.5)
(1 0 0.5)
(2 0 0.5)
(2 0.707107 0.5)
(0.707107 0.707107 0.5)
(0.353553 0.353553 0.5)
(2 2 0.5)
(0.707107 2 0.5)
(0 2 0.5)
(0 1 0.5)
(0 0.5 0.5)
);
blocks
(
hex (5 4 9 10 16 15 20 21) (10 10 1) simpleGrading (1 1 1)
hex (0 1 4 5 11 12 15 16) (10 10 1) simpleGrading (1 1 1)
hex (1 2 3 4 12 13 14 15) (20 10 1) simpleGrading (1 1 1)
hex (4 3 6 7 15 14 17 18) (20 20 1) simpleGrading (1 1 1)
hex (9 4 7 8 20 15 18 19) (10 20 1) simpleGrading (1 1 1)
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 75 / 89
Stress analysis of a plate with a hole
blockMeshDict II
edges
(
arc 0 5 (0.469846 0.17101 0)
arc 5 10 (0.17101 0.469846 0)
arc 1 4 (0.939693 0.34202 0)
arc 4 9 (0.34202 0.939693 0)
arc 11 16 (0.469846 0.17101 0.5)
arc 16 21 (0.17101 0.469846 0.5)
arc 12 15 (0.939693 0.34202 0.5)
arc 15 20 (0.34202 0.939693 0.5)
);
boundary
(
left
{
type symmetryPlane;
faces
(
(8 9 20 19)
(9 10 21 20)
);
}
right
{
type patch;
faces
(
(2 3 14 13)
(3 6 17 14)
);
}
down
{
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 76 / 89
Applications and libraries

solvers are each designed to solve a specic problem


in computational continuum mechanics;

utilities perform simple pre-and post-processing


tasks, mainly involving data manipulation
and algebraic calculations.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 77 / 89
The programming language of OpenFOAM
OpenFOAM is written in object-oriented C++
Equations representations:

∂ρU
+ ∇ · (φU ) − ∇ · (µ∇U ) = −∇p
∂t
solve
(
fvm::ddt(rho, U)
+ fvm::div(phi, U)
- fvm::laplacian(mu, U)
==
- fvc::grad(p)
);

Solver codes are documented with Doxygen at


$WM_PROJECT_DIR/doc/Doxygen/html/index.html
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 78 / 89
OpenFOAM classes can be compiled to shared object library with .so
extensions.
Later they can be user in other programms or classed with dynamic linking

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 79 / 89
Class declaration
Each class requires a class declaration, contained in a header le with a .H
le extension, e.g.nc.H, that includes the names of the class and its
functions.
This le is included at the beginning of any piece of code using the class,
including the class declaration code itself.
.C code can resource any number of classes and must begin with all the .H
les required to declare these classes.
The classes in turn can resource other classes and begin with the relevant
.H les. By searching recursively down the class hierarchy we can produce a
complete list of header les for all the classes on which the top level .C
code ultimately depends; these .H les are known as the dependencies.
With a dependency list, a compiler can check whether the source les have
been updated since their last compilation and selectively compile only those
that need to be.
Header les are included in the code using # include statements, e.g.

#include "otherHeader.H";
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 80 / 89
Building with wmake
Automatic generation and maintenance of le dependency lists, i.e. lists of
les which are included in the source les and hence on which they depend.

Multi-platform compilation and linkage, handled through appropriate


directory structure.

Multi-language compilation and linkage, e.g. C, C++, Java.

Multi-option compilation and linkage, e.g. debug, optimised, parallel and


proling.

Support for source code generation programs, e.g. lex, yacc, IDL, MOC.

Simple syntax for source le lists.

Automatic creation of source le lists for new codes.

Simple handling of multiple shared or static libraries.

Extensible to new machine types.

Extremely portable, works on any machine with: make; sh, ksh or csh; lex, cc.

Has been tested on Apollo, SUN, SGI, HP (HPUX), Compaq (DEC), IBM
(AIX), Cray, Ardent, Stardent, PC Linux, PPC Linux, NEC, SX4, Fujitsu
VP1000.
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 81 / 89
Compiling with wmake

Including headers: trough Make/options

EXE_INC = \
-I<directoryPath1> \
-I<directoryPath2> \
... \
-I<directoryPathN>

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 82 / 89
Linking to libraries

Make/options le

EXE_LIBS = \
-L<libraryPath1> \
-L<libraryPath2> \
... \
-L<libraryPathN> \
-l<library1> \
-l<library2> \
... \
-l<libraryN>

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 83 / 89
Source les to be compiled
The full list of .C source les must be included in the Make/les le
Most simple case:

newApp.C

EXE = $(FOAM_USER_APPBIN)/newApp

To run wmake:

wmake <optionalArguments> <optionalDirectory>


Options:

all wmake all subdirectories, running Allwmake les if present

exe Compile statically linked executable

lib Compile statically linked archive lib (.a)

libo Compile statically linked lib (.o)

libso Compile dynamically linked lib (.so)

dep Compile lnInclude and dependencies only


Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 84 / 89
Removing dependency lists: wclean and rmdepall

wclean <optionalArguments> <optionalDirectory>

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 85 / 89
Adding temperature transport to icoFoam
Let's check where $FOAM_SOLVERS enviroment variable points to:

echo $FOAM_SOLVERS
ls $FOAM_SOLVERS
Yes, it does point to the residence of all the OpenFOAM default solvers.
Now we will rst go to the directory where we want to keep the source
codes of our own solvers, f.e. $HOME/calc/source/OpenFOAM and we will
copy icoFoam solver to that direcory

cp -rf $FOAM_SOLVERS/incompressible/icoFoam icoFoamHeat


Now change the lename of the .C source le of the new solver:

mv icoFoam.C icoFoamHeat.C
Next, you have to change Make/files (3! changes):

icoFoam.C -> icoFoamHeat.C


EXE = $(FOAM_USER_APPBIN)/icoFoam
-> EXE = $(FOAM_USER_APPBIN)/icoFoamHeat
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 86 / 89
After you have compiled your new solver, you have, of course, to change
the name of the solver in system/controlDict

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 87 / 89
SIMPLE algorithm, SIMPLE is an acronym for Semi-Implicit Method for Pressure

Linked Equations.

1 Set the boundary conditions.


2 Compute the gradients of velocity and pressure.
3 Solve the discretized momentum equation to compute the
intermediate velocity eld.
4 Compute the uncorrected mass uxes at faces.
5 Solve the pressure correction equation to produce cell values of the
pressure correction.
0
6 Update the pressure eld: pk+1 = pk + urf · p where urf is the
under-relaxation factor for pressure.
0
7 Update the boundary pressure corrections pb .
k+1 ∗ 0
8 Correct the face mass uxes: ṁf = ṁf + ṁf
0
~v k+1 = ~v ∗ − Vol~av∇p ; where∇p is the
0
9 Correct the cell velocities:
P
gradient of the pressure corrections, ~ avP is the vector of central
coecients for the discretized linear system representing the velocity
equation and Vol is the cell volume.
10 Update density due to pressure changes
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 88 / 89
PISO algorithm (Pressure Implicit with Splitting of
Operator)

1 Set the boundary conditions.

2 Solve the discretized momentum equation to compute an intermediate


velocity eld.

3 Compute the mass uxes at the cells faces.

4 Solve the pressure equation.

5 Correct the mass uxes at the cell faces.

6 Correct the velocities on the basis of the new pressure eld.

7 Update the boundary conditions.

8 Repeat from 3 for the prescribed number of times.

9 Increase the time step and repeat from 1.

Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 89 / 89

You might also like