Programmers Guide
Programmers Guide
Programmer’s Guide
Version 3.0.1
13th December 2015
P-2
Typeset in LATEX.
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CRE-
ATIVE COMMONS PUBLIC LICENSE (“CCPL” OR “LICENSE”). THE WORK IS PRO-
TECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK
OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PRO-
HIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND
AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LI-
CENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE
RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH
TERMS AND CONDITIONS.
1. Definitions
a. “Adaptation” means a work based upon the Work, or upon the Work and other pre-existing
works, such as a translation, adaptation, derivative work, arrangement of music or other
alterations of a literary or artistic work, or phonogram or performance and includes cine-
matographic adaptations or any other form in which the Work may be recast, transformed, or
adapted including in any form recognizably derived from the original, except that a work that
constitutes a Collection will not be considered an Adaptation for the purpose of this License.
For the avoidance of doubt, where the Work is a musical work, performance or phonogram,
the synchronization of the Work in timed-relation with a moving image (“synching”) will be
considered an Adaptation for the purpose of this License.
b. “Collection” means a collection of literary or artistic works, such as encyclopedias and an-
thologies, or performances, phonograms or broadcasts, or other works or subject matter
other than works listed in Section 1(f) below, which, by reason of the selection and arrange-
ment of their contents, constitute intellectual creations, in which the Work is included in its
entirety in unmodified form along with one or more other contributions, each constituting
separate and independent works in themselves, which together are assembled into a collec-
tive whole. A work that constitutes a Collection will not be considered an Adaptation (as
defined above) for the purposes of this License.
c. “Distribute” means to make available to the public the original and copies of the Work
through sale or other transfer of ownership.
d. “Licensor” means the individual, individuals, entity or entities that offer(s) the Work under
the terms of this License.
e. “Original Author” means, in the case of a literary or artistic work, the individual, individuals,
entity or entities who created the Work or if no individual or entity can be identified, the
OpenFOAM-3.0.1
P-3
publisher; and in addition (i) in the case of a performance the actors, singers, musicians,
dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise
perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram
the producer being the person or legal entity who first fixes the sounds of a performance
or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the
broadcast.
f. “Work” means the literary and/or artistic work offered under the terms of this License
including without limitation any production in the literary, scientific and artistic domain,
whatever may be the mode or form of its expression including digital form, such as a book,
pamphlet and other writing; a lecture, address, sermon or other work of the same nature;
a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb
show; a musical composition with or without words; a cinematographic work to which are
assimilated works expressed by a process analogous to cinematography; a work of drawing,
painting, architecture, sculpture, engraving or lithography; a photographic work to which are
assimilated works expressed by a process analogous to photography; a work of applied art; an
illustration, map, plan, sketch or three-dimensional work relative to geography, topography,
architecture or science; a performance; a broadcast; a phonogram; a compilation of data to
the extent it is protected as a copyrightable work; or a work performed by a variety or circus
performer to the extent it is not otherwise considered a literary or artistic work.
g. “You” means an individual or entity exercising rights under this License who has not pre-
viously violated the terms of this License with respect to the Work, or who has received
express permission from the Licensor to exercise rights under this License despite a previous
violation.
h. “Publicly Perform” means to perform public recitations of the Work and to communicate to
the public those public recitations, by any means or process, including by wire or wireless
means or public digital performances; to make available to the public Works in such a way
that members of the public may access these Works from a place and at a place individu-
ally chosen by them; to perform the Work to the public by any means or process and the
communication to the public of the performances of the Work, including by public digital
performance; to broadcast and rebroadcast the Work by any means including signs, sounds
or images.
i. “Reproduce” means to make copies of the Work by any means including without limitation
by sound or visual recordings and the right of fixation and reproducing fixations of the Work,
including storage of a protected performance or phonogram in digital form or other electronic
medium.
3. License Grant.
Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide,
royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to ex-
ercise the rights in the Work as stated below:
a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to
Reproduce the Work as incorporated in the Collections;
OpenFOAM-3.0.1
P-4
b. and, to Distribute and Publicly Perform the Work including as incorporated in Collections.
The above rights may be exercised in all media and formats whether now known or hereafter
devised. The above rights include the right to make such modifications as are technically necessary
to exercise the rights in other media and formats, but otherwise you have no rights to make
Adaptations. Subject to 8(f), all rights not expressly granted by Licensor are hereby reserved,
including but not limited to the rights set forth in Section 4(d).
4. Restrictions.
The license granted in Section 3 above is expressly made subject to and limited by the following
restrictions:
a. You may Distribute or Publicly Perform the Work only under the terms of this License. You
must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every
copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms
on the Work that restrict the terms of this License or the ability of the recipient of the Work
to exercise the rights granted to that recipient under the terms of the License. You may not
sublicense the Work. You must keep intact all notices that refer to this License and to the
disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform.
When You Distribute or Publicly Perform the Work, You may not impose any effective
technological measures on the Work that restrict the ability of a recipient of the Work from
You to exercise the rights granted to that recipient under the terms of the License. This
Section 4(a) applies to the Work as incorporated in a Collection, but this does not require
the Collection apart from the Work itself to be made subject to the terms of this License. If
You create a Collection, upon notice from any Licensor You must, to the extent practicable,
remove from the Collection any credit as required by Section 4(c), as requested.
b. You may not exercise any of the rights granted to You in Section 3 above in any manner
that is primarily intended for or directed toward commercial advantage or private monetary
compensation. The exchange of the Work for other copyrighted works by means of digital file-
sharing or otherwise shall not be considered to be intended for or directed toward commercial
advantage or private monetary compensation, provided there is no payment of any monetary
compensation in connection with the exchange of copyrighted works.
c. If You Distribute, or Publicly Perform the Work or Collections, You must, unless a request
has been made pursuant to Section 4(a), keep intact all copyright notices for the Work
and provide, reasonable to the medium or means You are utilizing: (i) the name of the
Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author
and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing
entity, journal) for attribution (“Attribution Parties”) in Licensor’s copyright notice, terms
of service or by other reasonable means, the name of such party or parties; (ii) the title of
the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor
specifies to be associated with the Work, unless such URI does not refer to the copyright
notice or licensing information for the Work. The credit required by this Section 4(c) may be
implemented in any reasonable manner; provided, however, that in the case of a Collection,
at a minimum such credit will appear, if a credit for all contributing authors of Collection
appears, then as part of these credits and in a manner at least as prominent as the credits
for the other contributing authors. For the avoidance of doubt, You may only use the credit
required by this Section for the purpose of attribution in the manner set out above and, by
exercising Your rights under this License, You may not implicitly or explicitly assert or imply
any connection with, sponsorship or endorsement by the Original Author, Licensor and/or
OpenFOAM-3.0.1
P-5
Attribution Parties, as appropriate, of You or Your use of the Work, without the separate,
express prior written permission of the Original Author, Licensor and/or Attribution Parties.
6. Limitation on Liability.
EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LI-
CENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDEN-
TAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS
LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
7. Termination
a. This License and the rights granted hereunder will terminate automatically upon any breach
by You of the terms of this License. Individuals or entities who have received Collections
OpenFOAM-3.0.1
P-6
from You under this License, however, will not have their licenses terminated provided such
individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7,
and 8 will survive any termination of this License.
b. Subject to the above terms and conditions, the license granted here is perpetual (for the
duration of the applicable copyright in the Work). Notwithstanding the above, Licensor
reserves the right to release the Work under different license terms or to stop distributing
the Work at any time; provided, however that any such election will not serve to withdraw
this License (or any other license that has been, or is required to be, granted under the terms
of this License), and this License will continue in full force and effect unless terminated as
stated above.
8. Miscellaneous
a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers
to the recipient a license to the Work on the same terms and conditions as the license granted
to You under this License.
b. If any provision of this License is invalid or unenforceable under applicable law, it shall
not affect the validity or enforceability of the remainder of the terms of this License, and
without further action by the parties to this agreement, such provision shall be reformed to
the minimum extent necessary to make such provision valid and enforceable.
c. No term or provision of this License shall be deemed waived and no breach consented to
unless such waiver or consent shall be in writing and signed by the party to be charged with
such waiver or consent.
d. This License constitutes the entire agreement between the parties with respect to the Work
licensed here. There are no understandings, agreements or representations with respect to
the Work not specified here. Licensor shall not be bound by any additional provisions that
may appear in any communication from You.
e. This License may not be modified without the mutual written agreement of the Licensor
and You. The rights granted under, and the subject matter referenced, in this License were
drafted utilizing the terminology of the Berne Convention for the Protection of Literary
and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961,
the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of
1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights
and subject matter take effect in the relevant jurisdiction in which the License terms are
sought to be enforced according to the corresponding provisions of the implementation of
those treaty provisions in the applicable national law. If the standard suite of rights granted
under applicable copyright law includes additional rights not granted under this License,
such additional rights are deemed to be included in the License; this License is not intended
to restrict the license of any rights under applicable law.
OpenFOAM-3.0.1
P-7
Trademarks
OpenFOAM-3.0.1
P-8
OpenFOAM-3.0.1
Contents
Trademarks P-7
Contents P-9
OpenFOAM-3.0.1
Contents P-11
Index P-73
OpenFOAM-3.0.1
P-12 Contents
OpenFOAM-3.0.1
Chapter 1
Tensor mathematics
This Chapter describes tensors and their algebraic operations and how they are represented
in mathematical text in this book. It then explains how tensors and tensor algebra are
programmed in OpenFOAM.
x
Figure 1.1: Right handed axes
1.2 Tensors
The term tensor describes an entity that belongs to a particular space and obeys certain
mathematical rules. Briefly, tensors are represented by a set of component values relating
P-14 Tensor mathematics
to a set of unit base vectors; in OpenFOAM the unit base vectors ix , iy and iz are aligned
with the right-handed rectangular Cartesian axes x, y and z respectively. The base vectors
are therefore orthogonal, i.e. at right-angles to one another. Every tensor has the following
attributes:
Rank 0 ‘scalar’ Any property which can be represented by a single real number, denoted
by characters in italics, e.g. mass m, volume V , pressure p and viscosity µ.
Rank 1 ‘vector’ An entity which can be represented physically by both magnitude and
direction. In component form, the vector a = (a1 , a2 , a3 ) relates to a set of Cartesian
axes x, y, z respectively. The index notation presents the same vector as ai , i = 1, 2, 3,
although the list of indices i = 1, 2, 3 will be omitted in this book, as it is intuitive
since we are always dealing with 3 dimensions.
Rank 2 ‘tensor’ or second rank tensor, T has 9 components which can be expressed in
array notation as:
T11 T12 T13
T = Tij = T21 T22 T23 (1.1)
T31 T32 T33
The components Tij are now represented using 2 indices since r = 2 and the list of
indices i, j = 1, 2, 3 is omitted as before. The components for which i = j are referred
to as the diagonal components, and those for which i 6= j are referred to as the off-
diagonal components. The transpose of T is produced by exchanging components
across the diagonal such that
T11 T21 T31
TT = Tji = T12 T22 T32 (1.2)
T13 T23 T33
Note: a rank 2 tensor is often colloquially termed ‘tensor’ since the occurrence of
higher order tensors is fairly rare.
Symmetric rank 2 The term ‘symmetric’ refers to components being symmetric about the
diagonal, i.e. Tij = Tji . In this case, there are only 6 independent components since
T12 = T21 , T13 = T31 and T23 = T32 . OpenFOAM distinguishes between symmetric
and non-symmetric tensors to save memory by storing 6 components rather than 9
if the tensor is symmetric. Most tensors encountered in continuum mechanics are
symmetric.
OpenFOAM-3.0.1
1.2 Tensors P-15
Rank 3 has 27 components and is represented in index notation as Pijk which is too long
to represent in array notation as in Equation 1.1.
3
X
ai b i = ai b i = a1 b 1 + a2 b 2 + a3 b 3 (1.3)
i=1
P
In the remainder of the book the symbol is omitted since the repeated subscript
indicates the summation.
OpenFOAM-3.0.1
P-16 Tensor mathematics
• The inner product of two tensors T and S produces a tensor P = T • S whose com-
ponents are evaluated as:
Pij = Tik Skj (1.10)
¡ ¢T
It is non-commutative such that T • S = ST • TT
OpenFOAM-3.0.1
1.3 Algebraic tensor operations P-17
• The inner product of a vector a and third rank tensor P produces a second rank tensor
T = a • P whose components are
Tij = ak Pkij (1.11)
Again this is non-commutative so that T = P • a is
Tij = Pijk ak (1.12)
• The inner product of a second rank tensor T and third rank tensor P produces a third
rank tensor Q = T • P whose components are
Qijk = Til Pljk (1.13)
Again this is non-commutative so that Q = P • T is
Qijk = Pijl Tlk (1.14)
OpenFOAM-3.0.1
P-18 Tensor mathematics
• An outer product of a vector a and second rank tensor T produces a third rank tensor
P = aT whose components are
Pijk = ai Tjk (1.20)
This is non-commutative so that P = T a produces
Pijk = Tij ak (1.21)
OpenFOAM-3.0.1
1.3 Algebraic tensor operations P-19
a∗ = T • a (1.25)
S∗ = T • S • TT (1.26)
The identity tensor I is defined by the requirement that it transforms another tensor
onto itself. For all vectors a
a=I•a (1.27)
and therefore
1 0 0
I = δij = 0 1 0 (1.28)
0 0 1
∇ • (∇ × a) ≡ 0
∇ × (∇s) ≡ 0
∇ • (sa) ≡ s∇ • a + a • ∇s
∇ × (sa) ≡ s∇ × a + ∇s × a
∇(a • b) ≡ a × (∇ × b) + b × (∇ × a) + (a • ∇)b + (b • ∇)a (1.29)
∇ • (a × b) ≡ b • (∇ × a) − a • (∇ × b)
∇ × (a × b) ≡ a(∇ • b) − b(∇ • a) + (b • ∇)a − (a • ∇)b
∇ × (∇ × a) ≡ ∇(∇ • a) − ∇2 a
(∇ × a) × a ≡ a • (∇a) − ∇(a • a)
OpenFOAM-3.0.1
P-20 Tensor mathematics
Trace The trace of a tensor T is a scalar, evaluated by summing the diagonal components
Diagonal returns a vector whose components are the diagonal components of the second
rank tensor T
Deviatoric and hydrostatic tensors Every second rank tensor T can be decomposed
into a deviatoric component, for which tr T = 0 and a hydrostatic component of the
form T = sI where s is a scalar. Every second rank tensor can be decomposed into
deviatoric and hydrostatic parts as follows:
1 1
T = T − (tr T) I + (tr T) I = dev T + hyd T (1.34)
| 3{z } |3 {z }
deviatoric hydrostatic
Cofactors The minors of a tensor are evaluated for each component by deleting the row
and column in which the component is situated and evaluating the resulting entries
as a 2 × 2 determinant. For example, the minor of T12 is
¯ ¯
¯ T11 T12 T13 ¯ ¯ ¯
¯ T21 T22 T23 ¯ = ¯ T21 T23 ¯ = T21 T33 − T23 T31
¯ ¯ ¯ ¯
¯ ¯ ¯ T31 T33 ¯ (1.36)
¯ T31 T32 T33 ¯
OpenFOAM-3.0.1
1.4 OpenFOAM tensor classes P-21
The cofactors are signed minors where each minor is component is given a sign based
on the rule
+ve if i + j is even
(1.37)
−ve if i + j is odd
Positive of a scalar s is
(
1 if s ≥ 0,
pos(s) = (1.42)
0 if s < 0.
OpenFOAM-3.0.1
P-22 Tensor mathematics
We can then access the component T13 , or Txz using the xz() access function. For
instance the code
Txz = 3
OpenFOAM-3.0.1
P-24 Tensor mathematics
where each of the values corresponds to the power of each of the S.I. base units of mea-
surement listed in Table 1.3. The line of code declares pressureDims to be the dimensionSet
for pressure kg m s−2 since the first entry in the pressureDims array, 1, corresponds to k1 ,
the second entry, -1, corresponds to m−1 etc.. A tensor with units is defined using the
dimensioned<Type> template class, the <Type> being scalar, vector, tensor, etc.. The dimen-
sioned<Type> stores a variable name of class word,the value <Type> and a dimensionSet
dimensionedTensor sigma
(
"sigma",
dimensionSet(1, -1, -2, 0, 0, 0, 0),
tensor(1e6,0,0,0,1e6,0,0,0,1e6),
);
OpenFOAM-3.0.1
Chapter 2
Discretisation procedures
So far we have dealt with algebra of tensors at a point. The PDEs we wish to solve involve
derivatives of tensors with respect to time and space. We therefore need to extend our
description to a tensor field, i.e. a tensor that varies across time and spatial domains. In
this Chapter we will first present a mathematical description of all the differential operators
we may encounter. We will then show how a tensor field is constructed in OpenFOAM and
how the derivatives of these fields are discretised into a set of algebraic equations.
The nabla operator is a useful notation that obeys the following rules:
• it operates on the tensors to its right and the conventional rules of a derivative of a
product, e.g. ∂i ab = (∂i a) b + a (∂i b);
• otherwise the nabla operator behaves like any other vector in an algebraic operation.
2.1.1 Gradient
If a scalar field s is defined and continuously differentiable then the gradient of s, ∇s is a
vector field
µ ¶
∂s ∂s ∂s ﮔرادﯾﺎن اﺳﮑﺎﻟر ﺑود ﺷد ﺑردار
∇s = ∂i s = , , (2.2)
∂x1 ∂x2 ∂x3
ﮔرادﯾﺎن ﭘﺷت ھر The divergence can operate on any tensor field of rank 1 and above to produce a tensor
ﺗﺎﻧﺳوری ﻗرار that is one rank lower. For example the divergence of a second rank tensor field T is a
ﺑﮕﯾره ﯾﮫ رﻧﮏ vector field (expanding the vector as a column array for convenience)
ﻣﯾﺎرﺗش ﭘﺎﯾﯾن
∂T11 /∂x1 + ∂T21 /∂x2 + ∂T31 /∂x3 ﮔرادﯾﺎن ﺗﺎﻧﺳور ﻣﯾﺷﮫ ﺑردار
∇ • T = ∂j Tji = ∂T12 /∂x1 + ∂T22 /∂x2 + ∂T32 /∂x3 (2.5)
∂T13 /∂x1 + ∂T23 /∂x2 + ∂T33 /∂x3
2.1.3 Curl
If a vector field a is defined and continuously differentiable then the curl of a, ∇ × a is a
vector field
µ ¶
∂a3 ∂a2 ∂a1 ∂a3 ∂a2 ∂a1
∇ × a = eijk ∂j ak = − , − , − (2.6)
∂x2 ∂x3 ∂x3 ∂x1 ∂x1 ∂x2
2.1.4 Laplacian
The Laplacian is an operation that can be defined mathematically by a combination of
the divergence and gradient operators by ∇2 ≡ ∇ • ∇. However, the Laplacian should be
considered as a single operation that transforms a tensor field into another tensor field of
the same rank, rather than a combination of two operations, one which raises the rank by
1 and one which reduces the rank by 1.
ﺗوی ﻻﭘﻼﺳﯾن ﺗﻐﯾﯾر
رﻧﮏ ﻧدارﯾم In fact, the Laplacian is best defined as a scalar operator , just as we defined nabla as a
vector operator, by
∂2 ∂2 ∂2
∇2 ≡ ∂ 2 ≡ + + (2.8)
∂x21 ∂x22 ∂x23
∂ 2s ∂ 2s ∂ 2s
∇2 s = ∂ 2 s = + + (2.9)
∂x21 ∂x22 ∂x23
OpenFOAM-3.0.1
2.2 Overview of discretisation P-27
particle, as it moves and observe the change in the tensorial property φ in time, we have
the total, or material time derivative denoted by
Dφ ∆φ
= lim (2.10)
Dt ∆t→0 ∆t
However in continuum mechanics, particularly fluid mechanics, we often observe the change
of a φ in time at a fixed point in space as different particles move across that point. This
change at a point in space is termed the spatial time derivative which is denoted by ∂/∂t
and is related to the material derivative by:
Dφ ∂φ
= + U • ∇φ (2.11)
Dt ∂t
where U is the velocity field of property φ. The second term on the right is known as the
convective rate of change of φ.
Spatial discretisation Defining the solution domain by a set of points that fill and bound
a region of space when connected;
Temporal discretisation (For transient problems) dividing the time domain into into a
finite number of time intervals, or steps;
OpenFOAM-3.0.1
P-28 Discretisation procedures
y
Space domain
x
∆t t
Time domain
Figure 2.1: Discretisation of the solution domain
P Sf
d N
On a more detailed level, discretisation of space requires the subdivision of the domain
into a number of cells, or control volumes. The cells are contiguous, i.e. they do not overlap
one another and completely fill the domain. A typical cell is shown in Figure 2.2. Dependent
variables and other properties are principally stored at the cell centroid P although they
OpenFOAM-3.0.1
2.3 Discretisation of the solution domain P-29
may be stored on faces or vertices. The cell is bounded by a set of flat faces, given the
generic label f . In OpenFOAM there is no limitation on the number of faces bounding
each cell, nor any restriction on the alignment of each face. This kind of mesh is often
referred to as “arbitrarily unstructured” to differentiate it from meshes in which the cell
faces have a prescribed alignment, typically with the coordinate axes. Codes with arbitrarily
unstructured meshes offer greater freedom in mesh generation and manipulation in particular
when the geometry of the domain is complex or changes over time.
Whilst most properties are defined at the cell centroids, some are defined at cell faces.
There are two types of cell face.
Internal faces Those faces that connect two cells (and it can never be more than two).
For each internal face, OpenFOAM designates one adjoining cell to be the face owner
and the other to be the neighbour ;
Boundary faces Those belonging to one cell since they coincide with the boundary of the
domain. These faces simply have an owner cell.
Points A list of cell vertex point coordinate vectors, i.e. a vectorField, that is renamed
pointField using a typedef declaration;
Faces A list of cell faces List<face>, or faceList, where the face class is defined by a list of
vertex numbers, corresponding to the pointField;
Cells a list of cells List<cell>, or cellList, where the cell class is defined by a list of face
numbers, corresponding to the faceList described previously.
• a slice;
• a word to assign it a name.
FV discretisation uses specific data that is derived from the mesh geometry stored in
polyMesh. OpenFOAM therefore extends the polyMesh class to fvMesh which stores the
additional data needed for FV discretisation. fvMesh is constructed from polyMesh and
stores the data in Table 2.1 which can be updated during runtime in cases where the mesh
moves, is refined etc..
OpenFOAM-3.0.1
P-30 Discretisation procedures
Patch 1
Patch 2
Patch 3
Mesh A reference to an fvMesh, with some additional detail as to the whether the field is
defined at cell centres, faces, etc..
Old values Discretisation of time derivatives requires field data from previous time steps.
OpenFOAM-3.0.1
2.4 Equation discretisation P-31
The geometricField<Type> will store references to stored fields from the previous, or
old, time step and its previous, or old-old, time step where necessary.
Previous iteration values The iterative solution procedures can use under-relaxation
which requires access to data from the previous iteration. Again, if required, geo-
metricField<Type> stores a reference to the data from the previous iteration.
As discussed in Section 2.3, we principally define a property at the cell centres but quite
often it is stored at the cell faces and on occasion it is defined on cell vertices. The geomet-
ricField<Type> is renamed using typedef declarations to indicate where the field variable is
defined as follows:
where [A] is a square matrix, [x] is the column vector of dependent variable and [b] is the
source vector. The description of [x] and [b] as ‘vectors’ comes from matrix terminology
rather than being a precise description of what they truly are: a list of values defined at
locations in the geometry, i.e. a geometricField<Type>, or more specifically a volField<Type>
when using FV discretisation.
1
The diagram is not an exact description of the class hierarchy, rather a representation of the general
structure leading from some primitive classes to geometric<Type>Field.
OpenFOAM-3.0.1
P-32 Discretisation procedures
Patch 1
Internal field
Boundary field
Patch 1 Patch 2
Patch 2
(a) A volField<Type>
Patch 1
Internal field
Boundary field
Patch 1 Patch 2
Patch 2
(b) A surfaceField<Type>
Patch 1
Internal field
Boundary field
Patch 1 Patch 2
Patch 2
(c) A pointField<Type>
Figure 2.4: Types of geometricField<Type> defined on a mesh with 2 boundary patches (in
2 dimensions for simplicity)
OpenFOAM-3.0.1
2.4 Equation discretisation P-33
geometricField<Type>
geometricBoundaryField<Type>
OpenFOAM-3.0.1
P-34 Discretisation procedures
geometricField<Type>
volField<Type>
surfaceField<Type>
pointField<Type>
finiteVolumeCalculus (fvc)
finiteVolumeMethod (fvm)
Other explicit operations
(Implicit)
(Explict)
geometricField<Type>
fvMatrix<Type> volField<Type>
surfaceField<Type>
pointField<Type>
Table 2.2 lists the main functions that are available in fvm and fvc to discretise terms
that may be found in a PDE. FV discretisation of each term is formulated by first integrating
the term over a cell volume V . Most spatial derivative terms are then converted to integrals
over the cell surface S bounding the volume using Gauss’s theorem
Z Z
∇ ⋆ φ dV = dS ⋆ φ (2.13)
V S
where S is the surface area vector, φ can represent any tensor field and the star notation
⋆ is used to represent any tensor product, i.e. inner, outer and cross and the respective
OpenFOAM-3.0.1
2.4 Equation discretisation P-35
OpenFOAM-3.0.1
P-36 Discretisation procedures
The face gradient discretisation is implicit when the length vector d between the centre of
the cell of interest P and the centre of a neighbouring cell N is orthogonal to the face plane,
i.e. parallel to Sf :
φN − φ P
Sf • (∇φ)f = |Sf | (2.15)
|d|
In the case of non-orthogonal meshes, an additional explicit term is introduced which is
evaluated by interpolating cell centre gradients, themselves calculated by central differencing
cell centre values.
OpenFOAM-3.0.1
2.4 Equation discretisation P-37
new values φn ≡ φ(t + ∆t) at the time step we are solving for;
old values φo ≡ φ(t) that were stored from the previous time step;
old-old values φoo ≡ φ(t − ∆t) stored from a time step previous to the last.
One of two discretisation schemes can be declared using the timeScheme keyword in the
appropriate input file, described in detail in section 4.4 of the User Guide.
Euler implicit scheme, timeScheme EulerImplicit, that is first order accurate in time:
Z
∂ (ρP φP V )n − (ρP φP V )o
ρφ dV = (2.21)
∂t V ∆t
2.4.5 Divergence
The divergence term described in this Section is strictly an explicit term that is distinguished
from the convection term of Section 2.4.2, i.e. in that it is not the divergence of the product
of a velocity and dependent variable. The term is integrated over a control volume and
linearised as follows:
Z Z X
∇ φ dV =
• dS • φ = Sf • φf (2.24)
V S f
The fvc::div function can take as its argument either a surface<Type>Field, in which case
φf is specified directly, or a vol<Type>Field which is interpolated to the face by central
differencing as described in Section 2.4.10:
OpenFOAM-3.0.1
P-38 Discretisation procedures
2.4.6 Gradient
The gradient term is an explicit term that can be evaluated in a variety of ways. The scheme
can be evaluated either by selecting the particular grad function relevant to the discretisation
scheme, e.g.fvc::gGrad, fvc::lsGrad etc., or by using the fvc::grad function combined
with the appropriate gradScheme keyword in an input file
Gauss integration is invoked using the fvc::grad function with gradScheme Gauss or
directly using the fvc::gGrad function. The discretisation is performed using the
standard method of applying Gauss’s theorem to the volume integral:
Z Z X
∇φ dV = dS φ = Sf φf (2.25)
V S f
As with the fvc::div function, the Gaussian integration fvc::grad function can take
either a surfaceField<Type> or a volField<Type> as an argument.
Least squares is invoked using the fvc::grad function with timeScheme leastSquares
or directly using the fvc::lsGrad function. The discretisation is performed as by first
calculating the tensor G at every point P by summing over neighbours N :
X
2
G= wN dd (2.26)
N
where d is the vector from P to N and the weighting function wN = 1/|d|. The
gradient is then evaluated as:
X
2
(∇φ)P = wN G−1 • d (φN − φP ) (2.27)
N
Surface normal gradient The gradient normal to a surface nf • (∇φ)f can be evaluated
at cell faces using the scheme
φN − φ P
(∇φ)f = (2.28)
|d|
This gradient is called by the function fvc::snGrad and returns a surfaceField<Type>.
The scheme is directly analogous to that evaluated for the Laplacian discretisation
scheme in Section 2.4.1, and in the same manner, a correction can be introduced to
improve the accuracy of this face gradient in the case of non-orthogonal meshes. This
correction is called using the function fvc::snGradCorrection.
OpenFOAM-3.0.1
2.4 Equation discretisation P-39
2.4.8 Curl
The curl is evaluated from the gradient term described in Section 2.4.6. First, the gradient is
discretised and then the curl is evaluated using the relationship from Equation 2.7, repeated
here for convenience
∇ × φ = 2 ∗(skew ∇φ)
Explicit Every explicit term is a volField<Type>. Hence, an explicit source term can be
incorporated into an equation simply as a field of values. For example if we wished
to solve Poisson’s equation ∇2 φ = f , we would define phi and f as volScalarField and
then do
solve(fvm::laplacian(phi) == f)
Implicit An implicit source term is integrated over a control volume and linearised by
Z
ρφ dV = ρP VP φP (2.29)
V
Implicit/Explicit The implicit source term changes the coefficient of the diagonal of the
matrix. Depending on the sign of the coefficient and matrix terms, this will either
increase or decrease diagonal dominance of the matrix. Decreasing the diagonal dom-
inance could cause instability during iterative solution of the matrix equation. There-
fore OpenFOAM provides a mixed source discretisation procedure that is implicit
when the coefficients that are greater than zero, and explicit for the coefficients less
than zero. In mathematical terms the matrix coefficient for node P is VP max(ρP , 0)
and the source term is VP φP min(ρP , 0).
OpenFOAM-3.0.1
P-40 Discretisation procedures
Average fvc::average
P produces
P an area weighted average of surface<Type>Field face val-
ues, i.e. ( f Sf φf )/ f Sf , and returns a volField<Type>.
Reconstruct
Face interpolate The geometric<Type>Field function faceInterpolate() interpolates volField<Type
cell centre values to cell faces using central differencing, returning a surface<Type>Field.
Using the Euler implicit method of Equation 2.21, the first term can be expressed as
Z t+∆t · Z ¸ Z t+∆t
∂ (ρP φP V )n − (ρP φP V )o
ρφ dV dt = dt
t ∂t V t ∆t (2.31)
(ρP φP V )n − (ρP φP V )o
= ∆t
∆t
The second term can be expressed as
Z t+∆t ·Z ¸ Z t+∆t
Aφ dV dt = A∗ φ dt (2.32)
t V t
where A∗ represents the spatial discretisation of A. The time integral can be discretised in
three ways:
Euler implicit uses implicit discretisation of the spatial terms, thereby taking current
values φn .
Z t+∆t
A∗ φ dt = A∗ φn ∆t (2.33)
t
It is first order accurate in time and is unstable if the Courant number Co is greater
than 1. The Courant number is defined as
Uf • d
Co = (2.35)
|d|2 ∆t
where Uf is a characteristic velocity, e.g. velocity of a wave front, velocity of flow.
OpenFOAM-3.0.1
2.6 Boundary Conditions P-41
Crank Nicolson uses the trapezoid rule to discretise the spatial terms, thereby taking a
mean of current values φn and old values φo .
Z t+∆t µ n ¶
∗ ∗ φ + φo
A φ dt = A ∆t (2.36)
t 2
It is second order accurate in time, is unconditionally stable but does not guarantee
boundedness.
∂φ
= κ∇2 φ (2.37)
∂t
An Euler implicit implementation of this would read
solve(fvm::ddt(phi) == kappa*fvm::laplacian(phi))
where we use the fvm class to discretise the Laplacian term implicitly. An explicit imple-
mentation would read
solve(fvm::ddt(phi) == kappa*fvc::laplacian(phi))
where we now use the fvc class to discretise the Laplacian term explicitly. The Crank
Nicolson scheme can be implemented by the mean of implicit and explicit terms:
solve
(
fvm::ddt(phi)
==
kappa*0.5*(fvm::laplacian(phi) + fvc::laplacian(phi))
)
Dirichlet prescribes the value of the dependent variable on the boundary and is therefore
termed ‘fixed value’ in this guide;
Neumann prescribes the gradient of the variable normal to the boundary and is therefore
termed ‘fixed gradient’ in this guide.
OpenFOAM-3.0.1
P-42 Discretisation procedures
P
When we perform discretisation of terms that include the sum over faces f, we need
to consider what happens when one of the faces is a boundary face.
Fixed value We specify a fixed value at the boundary φb
• We can simply substitute φb in cases where the discretisation requires the value
on a boundary face φf , e.g. in the convection term in Equation 2.16.
• In terms where the face gradient (∇φ)f is required, e.g. Laplacian, it is calculated
using the boundary face value and cell centre value,
φb − φ P
Sf • (∇φ)f = |Sf | (2.38)
|d|
Fixed gradient The fixed gradient boundary condition gb is a specification on inner prod-
uct of the gradient and unit normal to the boundary, or
µ ¶
S
gb = • ∇φ (2.39)
|S| f
• φb can be directly substituted in cases where the discretisation requires the face
gradient to be evaluated,
Sf • (∇φ)f = |Sf | gb (2.41)
OpenFOAM-3.0.1
Chapter 3
In this section we shall describe several test cases supplied with the OpenFOAM distribu-
tion. The intention is to provide example cases, including those in the tutorials in chapter 2
of the User Guide, for every standard solver. The examples are designed to introduce cer-
tain tools and features of OpenFOAM, e.g. within pre-/post-processing, numerical schemes,
algorithms. They also provide a means for validation of solvers although that is not their
principal function.
Each example contains a description of the problem: the geometry, initial and boundary
conditions, a brief description of the equations being solved, models used, and physical
properties required. The solution domain is selected which may be a portion of the original
geometry, e.g. if we introduce symmetry planes. The method of meshing, usually blockMesh,
is specified; of course the user can simply view the mesh since every example is distributed
with the polyMesh directory containing the data files that describe the mesh.
The examples coexist with the tutorials in the tutorials subdirectory of the OpenFOAM
installation. They are organised into a set of subdirectories by solver, e.g. all the icoFoam
cases are stored within a subdirectory icoFoam. Before running a particular example, the
user is urged to copy it into their user account. We recommend that the user stores all
OpenFOAM cases in a directory we recommend that the tutorials are copied into a directory
$FOAM RUN. If this directory structure has not yet been created in the user’s account, it
can be created with
• non-orthogonal meshes;
symmetry
4.0 m
0 x
0.5 m
4.0 m
Figure 3.1: Geometry of flow round a cylinder
Governing equations
• Mass continuity for an incompressible fluid
∇•U=0 (3.1)
• Pressure equation for an incompressible, irrotational fluid assuming steady-state
conditions
∇2 p = 0 (3.2)
Boundary conditions
• Inlet (left) with fixed velocity U = (1, 0, 0) m/s.
• Outlet (right) with a fixed pressure p = 0 Pa.
• No-slip wall (bottom);
• Symmetry plane (top).
Initial conditions U = 0 m/s, p = 0 Pa — required in OpenFOAM input files but not
necessary for the solution since the problem is steady-state.
Solver name potentialFoam: a potential flow code, i.e. assumes the flow is incompressible,
steady, irrotational, inviscid and it ignores gravity.
Case name cylinder case located in the $FOAM TUTORIALS/potentialFoam directory.
OpenFOAM-3.0.1
3.1 Flow around a cylinder P-45
9 4
8 3
9
left right
14 15 5 0 4 3
10
7 16 2
6 5 1
y
13 12 11 x 0 1 2
down cylinder down
OpenFOAM-3.0.1
P-46 Examples of the use of OpenFOAM
13 object blockMeshDict;
14 }
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 convertToMeters 1;
18
19 vertices #codeStream
20 {
21 codeInclude
22 #{
23 #include "pointField.H"
24 #};
25
26 code
27 #{
28 pointField points(19);
29 points[0] = point(0.5, 0, -0.5);
30 points[1] = point(1, 0, -0.5);
31 points[2] = point(2, 0, -0.5);
32 points[3] = point(2, 0.707107, -0.5);
33 points[4] = point(0.707107, 0.707107, -0.5);
34 points[5] = point(0.353553, 0.353553, -0.5);
35 points[6] = point(2, 2, -0.5);
36 points[7] = point(0.707107, 2, -0.5);
37 points[8] = point(0, 2, -0.5);
38 points[9] = point(0, 1, -0.5);
39 points[10] = point(0, 0.5, -0.5);
40 points[11] = point(-0.5, 0, -0.5);
41 points[12] = point(-1, 0, -0.5);
42 points[13] = point(-2, 0, -0.5);
43 points[14] = point(-2, 0.707107, -0.5);
44 points[15] = point(-0.707107, 0.707107, -0.5);
45 points[16] = point(-0.353553, 0.353553, -0.5);
46 points[17] = point(-2, 2, -0.5);
47 points[18] = point(-0.707107, 2, -0.5);
48
49 // Duplicate z points
50 label sz = points.size();
51 points.setSize(2*sz);
52 for (label i = 0; i < sz; i++)
53 {
54 const point& pt = points[i];
55 points[i+sz] = point(pt.x(), pt.y(), -pt.z());
56 }
57
58 os << points;
59 #};
60 };
61
62
63 blocks
64 (
65 hex (5 4 9 10 24 23 28 29) (10 10 1) simpleGrading (1 1 1)
66 hex (0 1 4 5 19 20 23 24) (10 10 1) simpleGrading (1 1 1)
67 hex (1 2 3 4 20 21 22 23) (20 10 1) simpleGrading (1 1 1)
68 hex (4 3 6 7 23 22 25 26) (20 20 1) simpleGrading (1 1 1)
69 hex (9 4 7 8 28 23 26 27) (10 20 1) simpleGrading (1 1 1)
70 hex (15 16 10 9 34 35 29 28) (10 10 1) simpleGrading (1 1 1)
71 hex (12 11 16 15 31 30 35 34) (10 10 1) simpleGrading (1 1 1)
72 hex (13 12 15 14 32 31 34 33) (20 10 1) simpleGrading (1 1 1)
73 hex (14 15 18 17 33 34 37 36) (20 20 1) simpleGrading (1 1 1)
74 hex (15 9 8 18 34 28 27 37) (10 20 1) simpleGrading (1 1 1)
75 );
76
77 edges
78 (
79 arc 0 5 (0.469846 0.17101 -0.5)
80 arc 5 10 (0.17101 0.469846 -0.5)
81 arc 1 4 (0.939693 0.34202 -0.5)
82 arc 4 9 (0.34202 0.939693 -0.5)
83 arc 19 24 (0.469846 0.17101 0.5)
84 arc 24 29 (0.17101 0.469846 0.5)
85 arc 20 23 (0.939693 0.34202 0.5)
OpenFOAM-3.0.1
3.1 Flow around a cylinder P-47
OpenFOAM-3.0.1
P-48 Examples of the use of OpenFOAM
boundary should be an Outlet and the down and cylinder boundaries should be symme-
tryPlane. The top boundary conditions is chosen so that we can make the most genuine
comparison with our analytical solution which uses the assumption that the domain is infi-
nite in the y direction. The result is that the normal gradient of U is small along a plane
coinciding with our boundary. We therefore impose the condition that the normal com-
ponent is zero, i.e. specify the boundary as a symmetryPlane, thereby ensuring that the
comparison with the analytical is reasonable.
OpenFOAM-3.0.1
3.1 Flow around a cylinder P-49
58 #{
59 // Lookup U
60 Info<< "Looking up field U\n" << endl;
61 const volVectorField& U = mesh().lookupObject<volVectorField>("U");
62
63 Info<< "Reading inlet velocity uInfX\n" << endl;
64
65 scalar ULeft = 0.0;
66 label leftI = mesh().boundaryMesh().findPatchID("left");
67 const fvPatchVectorField& fvp = U.boundaryField()[leftI];
68 if (fvp.size())
69 {
70 ULeft = fvp[0].x();
71 }
72 reduce(ULeft, maxOp<scalar>());
73
74 dimensionedScalar uInfX
75 (
76 "uInfx",
77 dimensionSet(0, 1, -1, 0, 0),
78 ULeft
79 );
80
81 Info << "U at inlet = " << uInfX.value() << " m/s" << endl;
82
83
84 scalar magCylinder = 0.0;
85 label cylI = mesh().boundaryMesh().findPatchID("cylinder");
86 const fvPatchVectorField& cylFvp = mesh().C().boundaryField()[cylI];
87 if (cylFvp.size())
88 {
89 magCylinder = mag(cylFvp[0]);
90 }
91 reduce(magCylinder, maxOp<scalar>());
92
93 dimensionedScalar radius
94 (
95 "radius",
96 dimensionSet(0, 1, 0, 0, 0),
97 magCylinder
98 );
99
100 Info << "Cylinder radius = " << radius.value() << " m" << endl;
101
102 volVectorField UA
103 (
104 IOobject
105 (
106 "UA",
107 mesh().time().timeName(),
108 U.mesh(),
109 IOobject::NO_READ,
110 IOobject::AUTO_WRITE
111 ),
112 U
113 );
114
115 Info<< "\nEvaluating analytical solution" << endl;
116
117 const volVectorField& centres = UA.mesh().C();
118 volScalarField magCentres(mag(centres));
119 volScalarField theta(acos((centres & vector(1,0,0))/magCentres));
120
121 volVectorField cs2theta
122 (
123 cos(2*theta)*vector(1,0,0)
124 + sin(2*theta)*vector(0,1,0)
125 );
126
127 UA = uInfX*(dimensionedVector(vector(1,0,0))
128 - pow((radius/magCentres),2)*cs2theta);
129
130 // Force writing of UA (since time has not changed)
131 UA.write();
132
133 volScalarField error("error", mag(U-UA)/mag(UA));
134
135 Info<<"Writing relative error in U to " << error.objectPath()
OpenFOAM-3.0.1
P-50 Examples of the use of OpenFOAM
potentialFoam executes an iterative loop around the pressure equation which it solves in
order that explicit terms relating to non-orthogonal correction in the Laplacian term may
be updated in successive iterations. The number of iterations around the pressure equation is
controlled by the nNonOrthogonalCorrectors keyword in controlDict. In the first instance
we can set nNonOrthogonalCorrectors to 0 so that no loops are performed, i.e. the pressure
equation is solved once, and there is no non-orthogonal correction. The solution is shown
in Figure 3.3(a) (at t = 1, when the steady-state simulation is complete). We expect
the solution to show smooth streamlines passing across the domain as in the analytical
solution in Figure 3.3(c), yet there is clearly some error in the regions where there is high
non-orthogonality in the mesh, e.g. at the join of blocks 0, 1 and 3. The case can be run a
second time with some non-orthogonal correction by setting nNonOrthogonalCorrectors to
3. The solution shows smooth streamlines with no significant error due to non-orthogonality
as shown in Figure 3.3(b).
OpenFOAM-3.0.1
3.2 Steady turbulent flow over a backward-facing step P-51
OpenFOAM-3.0.1
P-52 Examples of the use of OpenFOAM
y
50.8 33.2
x
OpenFOAM-3.0.1
3.2 Steady turbulent flow over a backward-facing step P-53
Boundary conditions
Transport properties
Turbulence model
• Standard k − ǫ;
• Coefficients: Cµ = 0.09; C1 = 1.44; C2 = 1.92; αk = 1; αǫ = 0.76923.
OpenFOAM-3.0.1
P-54 Examples of the use of OpenFOAM
upperWall
9 15
3
2 7
8 14 12
21
inlet 2 6
1 13 11 20
7 19 10 outlet
1
0 6 4 12 9 18
0 5 5 17
11 8
3 16
4 10
lowerWall
Figure 3.5: Blocks in backward-facing step
14 }
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 convertToMeters 0.001;
18
19 vertices
20 (
21 (-20.6 0 -0.5)
22 (-20.6 3 -0.5)
23 (-20.6 12.7 -0.5)
24 (-20.6 25.4 -0.5)
25 (0 -25.4 -0.5)
26 (0 -5 -0.5)
27 (0 0 -0.5)
28 (0 3 -0.5)
29 (0 12.7 -0.5)
30 (0 25.4 -0.5)
31 (206 -25.4 -0.5)
32 (206 -8.5 -0.5)
33 (206 0 -0.5)
34 (206 6.5 -0.5)
35 (206 17 -0.5)
36 (206 25.4 -0.5)
37 (290 -16.6 -0.5)
38 (290 -6.3 -0.5)
39 (290 0 -0.5)
40 (290 4.5 -0.5)
41 (290 11 -0.5)
42 (290 16.6 -0.5)
43 (-20.6 0 0.5)
44 (-20.6 3 0.5)
45 (-20.6 12.7 0.5)
46 (-20.6 25.4 0.5)
47 (0 -25.4 0.5)
48 (0 -5 0.5)
49 (0 0 0.5)
50 (0 3 0.5)
51 (0 12.7 0.5)
52 (0 25.4 0.5)
53 (206 -25.4 0.5)
54 (206 -8.5 0.5)
55 (206 0 0.5)
56 (206 6.5 0.5)
57 (206 17 0.5)
58 (206 25.4 0.5)
59 (290 -16.6 0.5)
60 (290 -6.3 0.5)
61 (290 0 0.5)
62 (290 4.5 0.5)
63 (290 11 0.5)
64 (290 16.6 0.5)
65 );
66
67 blocks
68 (
OpenFOAM-3.0.1
3.2 Steady turbulent flow over a backward-facing step P-55
OpenFOAM-3.0.1
P-56 Examples of the use of OpenFOAM
A major feature of this problem is the use of the full mesh grading capability of blockMesh
that is described in section 5.3.1 of the User Guide. The user can see that blocks 4,5 and 6
use the full list of 12 expansion ratios. The expansion ratios correspond to each edge of the
block, the first 4 to the edges aligned in the local x1 direction, the second 4 to the edges
in the local x2 direction and the last 4 to the edges in the local x3 direction. In blocks 4,
5, and 6, the ratios are equal for all edges in the local x1 and x3 directions but not for the
edges in the x2 direction that corresponds in all blocks to the global y. If we consider the
ratios used in relation to the block definition in section 5.3.1 of the User Guide, we realize
that different gradings have been prescribed along the left and right edges in blocks 4,5 and
6 in Figure 3.5. The purpose of this differential grading is to generate a fine mesh close to
the most critical region of flow, the corner of the step, and allow it to expand into the rest
of the domain.
The mesh can be generated using blockMesh from the command line or from within
FoamX and viewed as described in previous examples.
OpenFOAM-3.0.1
3.2 Steady turbulent flow over a backward-facing step P-57
If we estimate the turbulent length scale l to be 10% of the width of the inlet then
OpenFOAM-3.0.1
P-58 Examples of the use of OpenFOAM
Run the case and post-process the results. After a few iterations, e.g. 50, a vortex
develops beneath the corner of the step that is the height of the step but narrow in the
x-direction as shown by the vector plot of velocities is shown Figure 3.6(a). Over several
iterations the vortex stretches in the x-direction from the step to the outlet until at 1000
iterations the system reaches a steady-state in which the vortex is fully developed as shown
in Figure 3.6(b-c).
• supersonic flow;
Solution domain The domain is 2 dimensional and consists of a short inlet section fol-
lowed by a forward-facing step of 20% the height of the section as shown in Figure 3.7
1.0
y
0.2
x
0.6 2.4
Dimensions in m
Figure 3.7: Geometry of the forward step geometry
Governing equations
• Mass continuity
∂ρ
+ ∇ • (ρU) = 0 (3.8)
∂t
• Ideal gas
p = ρRT (3.9)
OpenFOAM-3.0.1
3.3 Supersonic flow over a forward-facing step P-59
Boundary conditions
Transport properties
Thermodynamic properties
OpenFOAM-3.0.1
P-60 Examples of the use of OpenFOAM
OpenFOAM-3.0.1
3.4 Decompression of a tank internally pressurised with water P-61
80 faces
81 (
82 (5 13 14 6)
83 (6 14 15 7)
84 );
85 }
86 obstacle
87 {
88 type patch;
89 faces
90 (
91 (1 3 11 9)
92 (3 4 12 11)
93 );
94 }
95 );
96
97 mergePatchPairs
98 (
99 );
100
101 // ************************************************************************* //
3.3.4 Exercise
The user can examine the effect on the solution of increasing the inlet velocity.
OpenFOAM-3.0.1
P-62 Examples of the use of OpenFOAM
x
100
50 50 240
Outlet: p = 0 bar
Dimensions in mm
10 Note: image is rotated through -90◦ from normal
orientation of horizontal x-axis
Figure 3.9: Geometry of a tank with outflow pipe
Governing equations This problem requires a model for compressibility ψ in the fluid
in order to be able to resolve waves propagating at a finite speed. A barotropic
relationship is used to relate density ρ and pressure p are related to ψ.
• Mass continuity
∂ρ
+ ∇ • (ρU) = 0 (3.13)
∂t
• The barotropic relationship
∂ρ ρ
= =ψ (3.14)
∂p K
where K is the bulk modulus
• Equation 3.14 is linearised as
ρ ≈ ρ0 + ψ (p − p0 ) (3.15)
where ρ0 and p0 are the reference density and pressure respectively such that
ρ(p0 ) = ρ0 .
• Momentum equation for Newtonian fluid
∂ρU
+ ∇ • (ρUU) − ∇ • µ∇U = −∇p (3.16)
∂t
Boundary conditions Using FoamX the following physical boundary conditions can be
set:
OpenFOAM-3.0.1
3.4 Decompression of a tank internally pressurised with water P-63
Transport properties
Thermodynamic properties
OpenFOAM-3.0.1
P-64 Examples of the use of OpenFOAM
37 (1 0.6 0.1)
38 (1.5 0.6 0.1)
39 (0 3 0.1)
40 (1 3 0.1)
41 );
42
43 blocks
44 (
45 hex (0 1 3 2 10 11 13 12) (30 20 1) simpleGrading (1 1 1)
46 hex (2 3 6 5 12 13 16 15) (30 5 1) simpleGrading (1 1 1)
47 hex (3 4 7 6 13 14 17 16) (25 5 1) simpleGrading (1 1 1)
48 hex (5 6 9 8 15 16 19 18) (30 95 1) simpleGrading (1 1 1)
49 );
50
51 edges
52 (
53 );
54
55 boundary
56 (
57 outerWall
58 {
59 type wall;
60 faces
61 (
62 (0 1 11 10)
63 (1 3 13 11)
64 (3 4 14 13)
65 (7 6 16 17)
66 (6 9 19 16)
67 (9 8 18 19)
68 );
69 }
70 axis
71 {
72 type symmetryPlane;
73 faces
74 (
75 (0 10 12 2)
76 (2 12 15 5)
77 (5 15 18 8)
78 );
79 }
80 nozzle
81 {
82 type patch;
83 faces
84 (
85 (4 7 17 14)
86 );
87 }
88 back
89 {
90 type empty;
91 faces
92 (
93 (0 2 3 1)
94 (2 5 6 3)
95 (3 6 7 4)
96 (5 8 9 6)
97 );
98 }
99 front
100 {
101 type empty;
102 faces
103 (
104 (10 11 13 12)
105 (12 13 16 15)
106 (13 14 17 16)
107 (15 16 19 18)
108 );
109 }
110 );
111
112 mergePatchPairs
113 (
114 );
115
116 // ************************************************************************* //
OpenFOAM-3.0.1
3.4 Decompression of a tank internally pressurised with water P-65
In order to improve the numerical accuracy, we shall use the reference level of 1 bar for the
pressure field. Note that both the internal field level and the boundary conditions are offset
by the reference level.
For the mesh described above, the characteristic mesh size is approximately 2 mm (note the
scaling factor of 0.1 in the blockMeshDict file). Using
U ∆t
Co = (3.18)
∆x
a reasonable time step is around ∆t = 5 × 10−7 s, giving the Co number of 0.35, based on
the speed of sound. Also, note that the reported Co number by the code (associated with
the convective velocity) will be two orders of magnitude smaller. As we are interested in
the pressure wave propagation, we shall set the simulation time to 0.25 ms. For reference,
the controlDict file is quoted below.
1 /*--------------------------------*- C++ -*----------------------------------*\
2 | ========= | |
3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 | \\ / O peration | Version: 3.0.1 |
5 | \\ / A nd | Web: www.OpenFOAM.org |
6 | \\/ M anipulation | |
7 \*---------------------------------------------------------------------------*/
8 FoamFile
9 {
10 version 2.0;
11 format ascii;
12 class dictionary;
13 location "system";
14 object controlDict;
15 }
16 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
17
18 application sonicLiquidFoam;
19
20 startFrom startTime;
21
22 startTime 0;
23
24 stopAt endTime;
25
26 endTime 0.0001;
27
28 deltaT 5e-07;
29
30 writeControl timeStep;
31
32 writeInterval 20;
33
34 purgeWrite 0;
35
36 writeFormat ascii;
37
38 writePrecision 6;
39
OpenFOAM-3.0.1
P-66 Examples of the use of OpenFOAM
40 writeCompression off;
41
42 timeFormat general;
43
44 timePrecision 6;
45
46 runTimeModifiable true;
47
48
49 // ************************************************************************* //
Pressure, p
(bar)
100
90
80
70
60
50
40
30
20
10
0
The user can run the case and view results in dxFoam. The liquid flows out through
the nozzle causing a wave to move along the nozzle. As it reaches the inlet to the tank,
some of the wave is transmitted into the tank and some of it is reflected. While a wave
is reflected up and down the inlet pipe, the waves transmitted into the tank expand and
propagate through the tank. In Figure 3.10, the pressures are shown as contours so that
the wave fronts are more clearly defined than if plotted as a normal isoline plot.
If the simulation is run for a long enough time for the reflected wave to return to the
pipe, we can see that negative absolute pressure is detected. The modelling permits this and
has some physical basis since liquids can support tension, i.e. negative pressures. In reality,
however, impurities or dissolved gases in liquids act as sites for cavitation, or vapourisa-
tion/boiling, of the liquid due to the low pressure. Therefore in practical situations, we
generally do not observe pressures falling below the vapourisation pressure of the liquid; not
at least for longer than it takes for the cavitation process to occur.
OpenFOAM-3.0.1
3.5 Magnetohydrodynamic flow of a liquid P-67
Pressure, p
(bar)
100
90
80
70
60
50
40
30
20
10
0
OpenFOAM-3.0.1
P-68 Examples of the use of OpenFOAM
20
y
By = 20 T 2
x
∇•U=0 (3.19)
∇•B=0 (3.22)
∂D
∇×H=J+ =J (3.23)
∂t
assuming ∂D/∂t ≪ J. Here, H is the magnetic field strength, J is the current
density and D is the electric flux density.
• Charge continuity
∇•J=0 (3.24)
• Constitutive law
B = µH (3.25)
• Ohm’s law
J = σ (E + U × B) (3.26)
• Combining Equation 3.21, Equation 3.23, Equation 3.26, and taking the curl
∂B
+ ∇ • (UB) − ∇ • (φB U) − ∇ • (ΓB B) = 0 (3.27)
∂t
OpenFOAM-3.0.1
3.5 Magnetohydrodynamic flow of a liquid P-69
Boundary conditions
• inlet is specified the inlet condition with fixed velocity U = (1, 0, 0) m/s;
• outlet is specified as the outlet with with fixed pressure p = 0 Pa;
• upperWall is specified as a wall where B = (0, 20, 0) T.
• lowerWall is specified as a wall where B = (0, 20, 0) T.
• front and back boundaries are specified as empty.
Transport properties
• Kinematic viscosity ν = 1 Pa s
• Density ρ = 1 kg m/s
• Electrical conductivity σ = 1 (Ω m)−1
• Permeability µ = 1 H/m
OpenFOAM-3.0.1
P-70 Examples of the use of OpenFOAM
37 (
38 );
39
40 boundary
41 (
42 inlet
43 {
44 type patch;
45 faces
46 (
47 (0 4 7 3)
48 );
49 }
50 outlet
51 {
52 type patch;
53 faces
54 (
55 (2 6 5 1)
56 );
57 }
58 lowerWall
59 {
60 type patch;
61 faces
62 (
63 (1 5 4 0)
64 );
65 }
66 upperWall
67 {
68 type patch;
69 faces
70 (
71 (3 7 6 2)
72 );
73 }
74 frontAndBack
75 {
76 type empty;
77 faces
78 (
79 (0 3 2 1)
80 (4 5 6 7)
81 );
82 }
83 );
84
85 mergePatchPairs
86 (
87 );
88
89 // ************************************************************************* //
where L is the characteristic length scale. In this case with By = 20 T, M = 20 and the
electromagnetic body forces dominate the viscous forces. Consequently with the flow fairly
steady at t = 2 s the velocity profile is almost planar, viewed at a cross section midway
along the domain x = 10 m. The user can plot a graph of the profile of Ux in dxFoam.
Now the user should reduce the magnetic flux density B to 1 Tand re-run the code and
Ucomponents. In this case, M = 1 and the electromagnetic body forces no longer dominate.
OpenFOAM-3.0.1
3.5 Magnetohydrodynamic flow of a liquid P-71
y (m)
+1.0
By = 1 T
0.0 By = 20 T
-1.0
0.0 0.5 1.0 1.5
Ux (m/s)
Figure 3.13: Velocity profile in the Hartmann problem for By = 1 T and By = 20 T.
The velocity profile consequently takes on the parabolic form, characteristic of Poiseuille
flow as shown in Figure 3.13. To validate the code the analytical solution for the velocity
profile Ux is superimposed in Figure 3.13, given by:
where the characteristic length L is half the width of the domain, i.e. 1 m.
OpenFOAM-3.0.1
P-72 Examples of the use of OpenFOAM
OpenFOAM-3.0.1
Index P-73
Index
Symbols Numbers A B C D E F G H I J K L M N O P Q R S T U V W X Z
OpenFOAM-3.0.1
P-74 Index
B movingWallVelocity, U-139
background outlet, P-69
process, U-24, U-81 outletInlet, U-139
backward partialSlip, U-139
keyword entry, U-122 patch, U-136
Backward differencing, P-37 pressureDirectedInletVelocity, U-139
barotropicCompressibilityModels pressureInletVelocity, U-139
library, U-101 pressureOutlet, P-63
basicMultiComponentMixture model, U-100 pressureTransmissive, U-139
basicSolidThermo processor, U-138
library, U-102 setup, U-20
basicThermophysicalModels slip, U-139
library, U-100 supersonicFreeStream, U-139
binary surfaceNormalFixedValue, U-139
keyword entry, U-114 symmetryPlane, P-63, U-137
BirdCarreau model, U-104 totalPressure, U-139
blended differencing, P-36 turbulentInlet, U-139
block wall, U-41
expansion ratio, U-143 wall, P-63, P-69, U-59, U-137
block keyword, U-141 wedge, U-133, U-137, U-148
blocking zeroGradient, U-138
keyword entry, U-80 boundary conditions, P-41
blockMesh Dirichlet, P-41
library, U-99 inlet, P-42
blockMesh solver, P-45 Neumann, P-41
blockMesh utility, U-38, U-91, U-140 no-slip impermeable wall, P-42
blockMesh executable outlet, P-42
vertex numbering, U-143 physical, P-42
blockMeshDict symmetry plane, P-42
dictionary, U-18, U-20, U-36, U-49, U-140, boundaryField keyword, U-21, U-110
U-149 boundaryFoam solver, U-86
blocks keyword, U-20, U-31, U-142 bounded
boundaries, U-133 keyword entry, U-120, U-121
boundary, U-133 boxToCell keyword, U-60
boundary boxTurb utility, U-90
dictionary, U-132, U-140 breaking of a dam, U-56
boundary keyword, U-145 BSpline
boundary condition keyword entry, U-142
alphaContactAngle, U-59 buoyantBoussinesqPimpleFoam solver, U-88
buoyantPressure, U-139 buoyantBoussinesqSimpleFoam solver, U-88
calculated, U-138 buoyantPimpleFoam solver, U-88
cyclic, U-137, U-146 buoyantPressure
directionMixed, U-138 boundary condition, U-139
empty, P-63, P-69, U-18, U-133, U-137 buoyantSimpleFoam solver, U-88
fixedGradient, U-138 burntProducts keyword, U-193
fixedValue, U-138 button
fluxCorrectedVelocity, U-139 Apply, U-170, U-174
inlet, P-69 Auto Accept, U-174
inletOutlet, U-139 Camera Parallel Projection, U-174
mixed, U-138 Choose Preset, U-173
OpenFOAM-3.0.1
Index P-75
OpenFOAM-3.0.1
P-76 Index
OpenFOAM-3.0.1
Index P-77
OpenFOAM-3.0.1
P-78 Index
OpenFOAM-3.0.1
Index P-79
field flow
U, U-23 free surface, U-56
p, U-23 laminar, U-17
decomposition, U-82 steady, turbulent, P-50
FieldField<Type> template class, P-30 supersonic, P-58
fieldFunctionObjects turbulent, U-17
library, U-98 flow around a cylinder, P-43
fields, P-27 flow over backward step, P-50
mapping, U-165 flowType utility, U-93
fields tools, U-98 fluent3DMeshToFoam utility, U-91
fields keyword, U-185 fluentInterface directory, U-181
Field<Type> template class, P-27 fluentMeshToFoam utility, U-91, U-159
fieldValues keyword, U-60 fluxCorrectedVelocity
file boundary condition, U-139
Make/files, U-75 fluxRequired keyword, U-116
controlDict, P-48 OpenFOAM
files, U-73 cases, U-105
g, U-60 FOAM RUN
options, U-73 environment variable, U-105
snappyHexMeshDict, U-150 foamCalc utility, U-33
transportProperties, U-60 foamCalcFunctions
file format, U-106 library, U-98
fileFormats foamChemistryFile keyword, U-193
library, U-99 foamCorrectVrt script/alias, U-164
fileModificationChecking keyword, U-80 foamDataToFluent utility, U-93, U-181
fileModificationSkew keyword, U-80 foamDebugSwitches utility, U-97
files file, U-73 FoamFile keyword, U-107
filteredLinear2 foamFile
keyword entry, U-119 keyword entry, U-185
finalLayerThickness keyword, U-157 foamFormatConvert utility, U-97
financialFoam solver, U-90 foamHelp utility, U-97
find script/alias, U-179 foamInfoExec utility, U-97
finite volume foamJob script/alias, U-188
discretisation, P-25 foamListTimes utility, U-95
mesh, P-29 foamLog script/alias, U-188
finiteVolume foamMeshToFluent utility, U-91, U-181
library, U-98 foamToEnsight utility, U-93
finiteVolume tools, U-98 foamToEnsightParts utility, U-93
finiteVolumeCalculus class, P-34 foamToGMV utility, U-93
finiteVolumeMethod class, P-34 foamToStarMesh utility, U-91
fireFoam solver, U-88 foamToSurface utility, U-91
firstTime keyword, U-113 foamToTecplot360 utility, U-93
fixed foamToTetDualMesh utility, U-93
keyword entry, U-114 foamToVTK utility, U-93
fixedGradient foamUpgradeCyclics utility, U-90
boundary condition, U-138 foamUpgradeFvSolution utility, U-90
fixedValue foamyHexMeshBackgroundMesh utility, U-91
boundary condition, U-138 foamyHexMeshSurfaceSimplify utility, U-91
flattenMesh utility, U-92 foamyHexMesh utility, U-91
floatTransfer keyword, U-80 foamyQuadMesh utility, U-91
OpenFOAM-3.0.1
P-80 Index
OpenFOAM-3.0.1
Index P-81
OpenFOAM-3.0.1
P-82 Index
OpenFOAM-3.0.1
Index P-83
OpenFOAM-3.0.1
P-84 Index
OpenFOAM-3.0.1
Index P-85
OpenFOAM-3.0.1
P-86 Index
OpenFOAM-3.0.1
Index P-87
OpenFOAM-3.0.1
P-88 Index
OpenFOAM-3.0.1
Index P-89
OpenFOAM-3.0.1
P-90 Index
OpenFOAM-3.0.1
Index P-91
pressureDirectedInletVelocity RASModel
boundary condition, U-139 keyword entry, U-41
pressureInletVelocity RASModel keyword, U-198
boundary condition, U-139 RaviPetersen model, U-101
pressureOutlet raw
boundary condition, P-63 keyword entry, U-115, U-185
pressureTransmissive reactingEulerFoam solver, U-88
boundary condition, U-139 reactingFoam solver, U-88
primitive reactingMixture model, U-100
library, P-21 reactingMixture
primitives tools, U-98 keyword entry, U-193
printCoeffs keyword, U-42, U-198 reactingParcelFilmFoam solver, U-89
processorWeights keyword, U-82 reactingParcelFoam solver, U-89
probeLocations utility, U-95 reactionThermophysicalModels
process library, U-100
background, U-24, U-81 realizableKE model, U-102, U-103
foreground, U-24 reconstruct model, U-100
processor reconstructPar utility, U-85, U-97
boundary condition, U-138 reconstructParMesh utility, U-97
processor redistributePar utility, U-97
keyword entry, U-137 refGradient keyword, U-138
processorN directory, U-83 refineHexMesh utility, U-93
processorWeights keyword, U-83 refinementRegions keyword, U-154
Properties window, U-171, U-172 refinementLevel utility, U-93
Properties window panel, U-25, U-170 refinementRegions keyword, U-152, U-154
psiReactionThermo model, U-100, U-192 refinementSurfaces keyword, U-152, U-153
psiThermo model, U-192 refineMesh utility, U-92
psiuReactionThermo model, U-100, U-192 refineWallLayer utility, U-93
ptot utility, U-95 Refresh Times button, U-25, U-171
ptsotchDecomp model, U-100 regions keyword, U-60
pureMixture model, U-100 relative tolerance, U-124
pureMixture relativeSizes keyword, U-157
keyword entry, U-193 relaxed keyword, U-158
purgeWrite keyword, U-114 relTol keyword, U-53, U-124
PV4FoamReader removeFaces utility, U-93
library, U-169 Render View window, U-174
Q Render View window panel, U-173, U-174
Q utility, U-94 renumberMesh utility, U-92
QUICK Rescale to Data Range button, U-25
keyword entry, U-122 Reset button, U-170
qZeta model, U-102 resolveFeatureAngle keyword, U-152, U-153
restart, U-39
R Reynolds number, U-17, U-21
R utility, U-94 rhoPorousSimpleFoam solver, U-86
radiationModels rhoReactingBuoyantFoam solver, U-88
library, U-100 rhoCentralDyMFoam solver, U-86
randomProcesses rhoCentralFoam solver, U-86
library, U-99 rhoConst model, U-101, U-195
RAS rhoPimpleFoam solver, U-86
keyword entry, U-41, U-197 rhoReactingFoam solver, U-88
OpenFOAM-3.0.1
P-92 Index
OpenFOAM-3.0.1
Index P-93
OpenFOAM-3.0.1
P-94 Index
OpenFOAM-3.0.1
Index P-95
OpenFOAM-3.0.1
P-96 Index
OpenFOAM-3.0.1
Index P-97
OpenFOAM-3.0.1
P-98 Index
OpenFOAM-3.0.1
Index P-99
OpenFOAM-3.0.1
P-100 Index
OpenFOAM-3.0.1