Introduction To Openfoam, Part 1: Theoretical Foundations of Nite Volume Approach
Introduction To Openfoam, Part 1: Theoretical Foundations of Nite Volume Approach
Sibgatullin I.
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.
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
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
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
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
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:
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
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Dierence between solids and uids
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Dierence between solids and uids
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 16 / 89
Dierence between solids and uids
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
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
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
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
div ~v = 0 , (30)
∂ui 1
+ div (ui~v ) = div (ν grad ui ) − div (p~ii ) + bi , (31)
∂t ρ
∂(ρ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
~=Q
Aφ ~ , (38)
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
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:
φW
φS
AW AS AP AN AE * φP = QP
φN
φE
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
<++>
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.
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
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
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:
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
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
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 40 / 89
Approximation of Volume Integrals
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 41 / 89
Interpolation and Dierentiation Practices
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 42 / 89
The Algebraic Equation System
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 43 / 89
Client server model
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
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 47 / 89
Access to computational clusters
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)
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
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
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
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];
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
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
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 67 / 89
Postprocessing
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
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 69 / 89
Plotting graphs
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
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)
);
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.
Support for source code generation programs, e.g. lex, yacc, IDL, MOC.
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
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:
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
mv icoFoam.C icoFoamHeat.C
Next, you have to change Make/files (3! changes):
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.
Ilias Sibgatullin (Moscow University) OpenFOAM course 1: theory of FVM 19 ìàÿ 2016 ã. 89 / 89