Tutorial Guide
Tutorial Guide
Tutorial Guide
Version v2212
21st December 2022
T-2
Typeset in LATEX.
Open∇FOAM-v2212
T-3
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 PROHIBITED.
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
LICENSE 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
cinematographic adaptations or any other form in which the Work may be recast, trans-
formed, 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 (“synch-
ing”) 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 arrangement 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 collective 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, individ-
uals, entity or entities who created the Work or if no individual or entity can be identified,
the 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
Open∇FOAM-v2212
T-4
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 individually 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
exercise the rights in the Work as stated below:
a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Re-
produce the Work as incorporated in the Collections; and,
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:
Open∇FOAM-v2212
T-5
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
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.
Open∇FOAM-v2212
T-6
iii. Voluntary License Schemes. The Licensor reserves the right to collect royalties,
whether individually or, in the event that the Licensor is a member of a collecting
society that administers voluntary licensing schemes, via that society, from any exercise
by You of the rights granted under this License that is for a purpose or use which is
otherwise than noncommercial as permitted under Section 4(b).
6. Limitation on Liability
EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL
LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCI-
DENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT
OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN AD-
VISED 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
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
Open∇FOAM-v2212
T-7
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. This License may not be modified without the
mutual written agreement of the Licensor and You.
e. 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 Artis-
tic 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 appli-
cable 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.
Open∇FOAM-v2212
T-8
Trademarks
Open∇FOAM-v2212
Contents
Trademarks T-8
Contents T-9
1 Introduction T-13
1.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T-13
1.1.1 Note for Windows Users . . . . . . . . . . . . . . . . . . . . T-14
Open∇FOAM-v2212
Contents T-11
Index T-101
Open∇FOAM-v2212
T-12 Contents
Open∇FOAM-v2212
Chapter 1
Introduction
This guide details the process of setup, simulation and post-processing for some Open-
FOAM test cases, with the principal aim of introducing a user to the basic procedures
of running OpenFOAM. The $FOAM TUTORIALS directory contains many more cases
that demonstrate the use of all the solvers and many utilities supplied with OpenFOAM.
Before attempting to run the tutorials, the user must first make sure that they have
installed OpenFOAM correctly.
The tutorial cases describe the use of the blockMesh pre-processing tool, case setup
and running OpenFOAM solvers and post-processing using paraFoam. Those users with
access to third-party post-processing tools supported in OpenFOAM have an option:
either they can follow the tutorials using paraFoam; or refer to the User Guide for details
on post-processing with external applications.
Copies of all tutorials are available from the tutorials directory of the OpenFOAM
installation. The tutorials are organised into a set of directories according to the type
of flow and then subdirectories according to solver. For example, all the icoFoam cases
are stored within a subdirectory incompressible/icoFoam, where incompressible indicates
the type of flow. If the user wishes to run a range of example cases, it is recommended
that the user copy the tutorials directory into their local run directory. They can be easily
copied by typing:
experienced users. Many editors are available for both Linux and Windows environments,
e.g. on Ubuntu the default GUI-based editor is gedit, and default terminal editor is nano.
Other popular text editors include vim, emacs, kate, and atom.
Open∇FOAM-v2212
Chapter 2
Incompressible flow
T-16 Incompressible flow
Ux = 1 m/s
d = 0.1 m
2.1.1 Pre-processing
In preparation of editing case files and running the first cavity case, the user should change
to the case directory
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity/cavity
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-17
3 2
7 6
y
x 1
0
z
4 5
Figure 2.2: Block structure of the mesh for the cavity.
Open∇FOAM-v2212
T-18 Incompressible flow
58 );
59 }
60 frontAndBack
61 {
62 type empty;
63 faces
64 (
65 (0 3 2 1)
66 (4 5 6 7)
67 );
68 }
69 );
70
71
72 // ************************************************************************* //
The file first contains header information in the form of a banner (lines 1-7), then file
information contained in a FoamFile sub-dictionary, delimited by curly braces ({...}).
scale 0.1;
The next section defines the blocks (here, only 1) using the vertex indices, i.e. index 0
for vertex 0, index 1 for vertex 1, and so on, and the number of cells within it in each of
the 3 co-ordinate directions, and the cell spacing. The final section defines the boundary
patches. Please refer to the User Guide section 4.3 to understand the meaning of the
entries in the blockMeshDict file.
The mesh is generated by running blockMesh on this blockMeshDict file. From within
the case directory, this is done, simply by typing in the terminal:
blockMesh
The running status of blockMesh is reported in the terminal window. Any mistakes in
the blockMeshDict file are picked up by blockMesh and the resulting error message directs
the user to the line in the file where the problem occurred. There should be no error
messages at this stage.
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-19
27
28 fixedWalls
29 {
30 type zeroGradient;
31 }
32
33 frontAndBack
34 {
35 type empty;
36 }
37 }
38
39
40 // ************************************************************************* //
dimensions specifies the dimensions of the field, here kinematic pressure, i.e. m2 s−2 (see
User Guide section 2.2.6 for more information);
internalField the internal field data which can be uniform, described by a single value;
or nonuniform, where all the values of the field must be specified (see User Guide
section 2.2.8 for more information);
boundaryField the boundary field data that includes boundary conditions and data for
all the boundary patches (see User Guide section 2.2.8 for more information).
For this case cavity, the boundary consists of walls only, split into 2 patches named: (1)
fixedWalls for the fixed sides and base of the cavity; (2) movingWall for the moving top
of the cavity. As walls, both are given a zeroGradient boundary condition for p, meaning
“the normal gradient of pressure is zero”. The frontAndBack patch represents the front
and back planes of the 2D case and therefore must be set as empty.
In this case, as in most we encounter, the initial fields are set to be uniform. Here the
pressure is kinematic, and as an incompressible case, its absolute value is not relevant, so
is set to uniform 0 for convenience.
The user can similarly examine the velocity field in the 0/U file. The dimensions are
those expected for velocity, the internal field is initialised as uniform zero, which in the
case of velocity must be expressed by 3 vector components, i.e.uniform (0 0 0) (see
User Guide section 2.2.5 for more information).
The boundary field for velocity requires the same boundary condition for the front-
AndBack patch. The other patches are walls: a no-slip condition is assumed on the
fixedWalls, hence a fixedValue condition with a value of uniform (0 0 0). The top
surface moves at a speed of 1 m/s in the x-direction so requires a fixedValue condition
also but with uniform (1 0 0).
d|U|
Re = (2.1)
ν
Open∇FOAM-v2212
T-20 Incompressible flow
where d and |U| are the characteristic length and velocity respectively and ν is the
kinematic viscosity. Here d = 0.1 m, |U| = 1 m s−1 , so that for Re = 10, ν = 0.01 m2 s−1 .
The correct file entry for kinematic viscosity is thus specified below:
17 nu 0.01;
18
19
20 // ************************************************************************* //
2.1.1.4 Control
Input data relating to the control of time and reading and writing of the solution data are
read in from the controlDict dictionary. The user should view this file; as a case control
file, it is located in the system directory.
The start/stop times and the time step for the run must be set. OpenFOAM offers
great flexibility with time control which is described in full in the User Guide section 6.1.
In this tutorial we wish to start the run at time t = 0 which means that OpenFOAM
needs to read field data from a directory named 0 — see User Guide section 2.1 for
more information of the case file structure. Therefore we set the startFrom keyword to
startTime and then specify the startTime keyword to be 0.
For the end time, we wish to reach the steady state solution where the flow is circu-
lating around the cavity. As a general rule, the fluid should pass through the domain 10
times to reach steady state in laminar flow. In this case the flow does not pass through
this domain as there is no inlet or outlet, so instead the end time can be set to the time
taken for the lid to travel ten times across the cavity, i.e. 1 s; in fact, with hindsight, we
discover that 0.5 s is sufficient so we shall adopt this value. To specify this end time, we
must specify the stopAt keyword as endTime and then set the endTime keyword to 0.5.
Now we need to set the time step, represented by the keyword deltaT. To achieve
temporal accuracy and numerical stability when running icoFoam, a Courant number of
less than 1 is required. The Courant number is defined for one cell as:
δt|U|
Co = (2.2)
δx
where δt is the time step, |U| is the magnitude of the velocity through that cell and δx
is the cell size in the direction of the velocity. The flow velocity varies across the domain
and we must ensure Co < 1 everywhere. We therefore choose δt based on the worst case:
the maximum Co corresponding to the combined effect of a large flow velocity and small
cell size. Here, the cell size is fixed across the domain so the maximum Co will occur next
to the lid where the velocity approaches 1 m s−1 . The cell size is:
d 0.1
δx = = = 0.005 m (2.3)
n 20
Therefore to achieve a Courant number less than or equal to 1 throughout the domain
the time step deltaT must be set to less than or equal to:
Co δx 1 × 0.005
δt = = = 0.005 s (2.4)
|U| 1
As the simulation progresses we wish to write results at certain intervals of time that
we can later view with a post-processing package. The writeControl keyword presents
several options for setting the time at which the results are written; here we select the
timeStep option which specifies that results are written every nth time step where the
value n is specified under the writeInterval keyword. Let us decide that we wish to
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-21
write our results at times 0.1, 0.2,. . . , 0.5 s. With a time step of 0.005 s, we therefore
need to output results at every 20th time time step and so we set writeInterval to 20.
OpenFOAM creates a new directory named after the current time, e.g. 0.1 s, on each
occasion that it writes a set of data, as discussed in full in User Guide section 2.1. In the
icoFoam solver, it writes out the results for each field, U and p, into the time directories.
For this case, the entries in the controlDict are shown below:
17 application icoFoam;
18
19 startFrom startTime;
20
21 startTime 0;
22
23 stopAt endTime;
24
25 endTime 0.5;
26
27 deltaT 0.005;
28
29 writeControl timeStep;
30
31 writeInterval 20;
32
33 purgeWrite 0;
34
35 writeFormat ascii;
36
37 writePrecision 6;
38
39 writeCompression off;
40
41 timeFormat general;
42
43 timePrecision 6;
44
45 runTimeModifiable true;
46
47
48 // ************************************************************************* //
paraFoam
Open∇FOAM-v2212
T-22 Incompressible flow
This launches the ParaView window as shown in Figure ??. In the Pipeline Browser, the
user can see that ParaView has opened cavity.OpenFOAM, the module for the cavity case.
Before clicking the Apply button, the user needs to select some geometry from the
Mesh Parts panel. Because the case is small, it is easiest to select all the data by checking
the box adjacent to the Mesh Parts panel title, which automatically checks all individual
components within the respective panel. The user should then click the Apply button to
load the geometry into ParaView. Some general settings are applied as described in User
Guide section 7.1.7.1. Please consult this section about these settings.
The user should then open the Properties panel that controls the visual representation
of the selected module. Within the Display panel the user should do the following as shown
in Figure 2.3: (1) set Color By Solid Color; (2) click Edit and select an appropriate
colour e.g. black (for a white background); (3) select Wireframe from the Representation
menu. The background colour can be set by selecting Settings... from Edit in the top
menu panel.
Especially the first time the user starts ParaView, it is recommended that they
manipulate the view as described in User Guide section 7.1.7. In particular, since this is
a 2D case, it is recommended that Camera Parallel Projection is selected. To do so, click
on the Toggle Advanced Properties to show the option towards the bottom on the panel.
The Orientation Axes can be toggled on and off in the Annotation window or moved by
drag and drop with the mouse.
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-23
icoFoam
at the command prompt, or with the optional -case argument giving the case directory,
e.g.
The progress of the job is written to the terminal window. It tells the user the current
time, maximum Courant number, initial and final residuals for all fields.
2.1.4 Post-processing
As soon as results are written to time directories, they can be viewed using paraFoam.
Return to the paraFoam window and select the Properties panel for the cavity.OpenFOAM
case module. If the correct window panels for the case module do not seem to be present
at any time, please ensure that: cavity.OpenFOAM is highlighted in blue; eye button
alongside it is switched on to show the graphics are enabled;
To prepare paraFoam to display the data of interest, we must first load the data at
the required run time of 0.5 s. If the case was run while ParaView was open, the output
data in time directories will not be automatically loaded within ParaView. To load the
data the user should click Refresh Times in the Properties window. The time data will be
loaded into ParaView.
Open∇FOAM-v2212
T-24 Incompressible flow
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-25
of attributes of the colour bar, such as text size, font selection and numbering format for
the scale. The colour bar can be located in the image window by drag and drop with the
mouse.
New versions of ParaView default to using a colour scale of blue to white to red rather
than the more common blue to green to red (rainbow). Therefore the first time that the
user executes ParaView, they may wish to change the colour scale. This can be done by
selecting Choose Preset in the Color Scale Editor and selecting Blue to Red Rainbow. After
clicking the OK confirmation button, the user can click the Make Default button so that
ParaView will always adopt this type of colour bar.
If the user rotates the image, they can see that they have now coloured the complete
geometry surface by the pressure. In order to produce a genuine contour plot the user
should first create a cutting plane, or ‘slice’, through the geometry using the Slice
filter as described in User Guide section 7.1.8.1. The cutting plane should be centred at
(0.05, 0.05, 0.005) and its normal should be set to (0, 0, 1) (click the Z Normal button).
Having generated the cutting plane, the contours can be created using by the Contour
filter described in User Guide section 7.1.8.
Open∇FOAM-v2212
T-26 Incompressible flow
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-27
Open∇FOAM-v2212
T-28 Incompressible flow
With the cavity.OpenFOAM module highlighted in the Pipeline Browser, the user
should then select Stream Tracer from the Filter menu and then click Apply. The
Properties window panel should appear as shown in Figure 2.8. The Seed points should
be specified along a Line Source running vertically through the centre of the geometry,
i.e. from (0.05, 0, 0.005) to (0.05, 0.1, 0.005). For the image in this guide we used: a point
Resolution of 21; Max Propagation by Length 0.5; Initial Step Length by Cell Length 0.01;
and, Integration Direction BOTH. The Runge-Kutta 2 IntegratorType was used with
default parameters.
On clicking Apply the tracer is generated. The user should then select Tube from the
Filter menu to produce high quality streamline images. For the image in this report, we
used: Num. sides 6; Radius 0.0003; and, Radius factor 10. The streamtubes are coloured
by velocity magnitude. On clicking Apply the image in Figure 2.9 should be produced.
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity
mkdir cavityFine
The user should then copy the base directories from the cavity case into cavityFine, and
then enter the cavityFine case.
cp -r cavity/constant cavityFine
cp -r cavity/system cavityFine
cd cavityFine
2.1.5.3 Mapping the coarse mesh results onto the fine mesh
The mapFields utility maps one or more fields relating to a given geometry onto the cor-
responding fields for another geometry. In our example, the fields are deemed ‘consistent’
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-29
because the geometry and the boundary types, or conditions, of both source and tar-
get fields are identical. We use the -consistent command line option when executing
mapFields in this example.
The field data that mapFields maps is read from the time directory specified by
startFrom/startTime in the controlDict of the target case, i.e. those into which the
results are being mapped. In this example, we wish to map the final results of the coarser
mesh from case cavity onto the finer mesh of case cavityFine. Therefore, since these re-
sults are stored in the 0.5 directory of cavity, the startTime should be set to 0.5 s in the
controlDict dictionary and startFrom should be set to startTime.
The case is ready to run mapFields. Typing mapFields -help quickly shows that map-
Fields requires the source case directory as an argument. We are using the -consistent
option, so the utility is executed from within the cavityFine directory by
Open∇FOAM-v2212
T-30 Incompressible flow
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity
touch cavityFine/cavityFine.OpenFOAM
Now the cavityFine case can be loaded into ParaView by selecting Open from the File
menu, and having navigated the directory tree, selecting cavityFine.OpenFOAM. The user
can now make a vector plot of the results from the refined mesh in ParaView. The plot can
be compared with the cavity case by enabling glyph images for both case simultaneously.
postProcess -list
CourantNo
Lambda2
MachNo
PecletNo
Q
R
XiReactionRate
add
boundaryCloud
cellMax
cellMin
components
div
enstrophy
faceMax
faceMin
flowRatePatch
flowType
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-31
forceCoeffsCompressible
forceCoeffsIncompressible
forcesCompressible
forcesIncompressible
grad
internalCloud
mag
magSqr
minMaxComponents
minMaxMagnitude
patchAverage
patchIntegrate
pressureDifferencePatch
pressureDifferenceSurface
probes
randomise
residuals
scalarTransport
singleGraph
staticPressure
streamFunction
streamlines
subtract
surfaces
totalPressureCompressible
totalPressureIncompressible
turbulenceFields
volFlowRateSurface
vorticity
wallHeatFlux
wallShearStress
writeCellCentres
writeCellVolumes
writeObjects
yPlus
The components and mag functions provide useful scalar measures of velocity.
When the components function is run on a case, say cavity, it reads the velocity vector
field from each time directory and, in the corresponding time directories, writes scalar
fields Ux, Uy and Uz representing the x, y and z components of velocity. Similarly the
mag function writes a scalar field magU to each time directory representing the magnitude
of velocity.
The user can run both functions simultaneously, e.g. for the cavity case the user
should go into the cavity directory and execute postProcess as follows:
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity/cavity
postProcess -funcs '(components(U) mag(U))'
Open∇FOAM-v2212
T-32 Incompressible flow
prefer to write raw data and plot it with a dedicated graphing tool, such as gnuplot or
Grace/xmgr. To do this, see section 5.1.4.
Before commencing plotting, the user needs to load the newly generated Ux, Uy and
Uz fields into ParaView. To do this, the user should click the Refresh button at the top
of the Properties panel for the cavity.OpenFOAM module which will cause the new fields
to be loaded into ParaView and appear in the Volume Fields window. Ensure the new
fields are selected and the changes are applied, i.e. click Apply again if necessary. Also,
data is interpolated incorrectly at boundaries if the boundary regions are selected in the
Mesh Parts panel. Therefore the user should deselect the patches in the Mesh Parts panel,
i.e.movingWall, fixedWall and frontAndBack, and apply the changes.
Now, in order to display a graph in ParaView the user should select the module of inter-
est, e.g.cavity.OpenFOAM and apply the Plot Over Line filter from the Filter->Data
Analysis menu. This opens up a new XY Plot window below or beside the existing 3D
View window. A PlotOverLine module is created in which the user can specify the end
points of the line in the Properties panel. In this example, the user should position the
line vertically up the centre of the domain, i.e. from (0.05, 0, 0.005) to (0.05, 0.1, 0.005),
in the Point1 and Point2 text boxes. The Resolution can be set to 100.
On clicking Apply, a graph is generated in the XY Plot window. In the Display panel,
the Attribute Mode is set to Point Data by default. The Use Data Array option can
be selected for the X Axis Data, taking the arc length option so that the x-axis of the
graph represents distance from the base of the cavity.
The user can choose the fields to be displayed in the Line Series panel of the Display
window. From the list of scalar fields to be displayed, it can be seen that the magnitude
and components of vector fields are available by default, e.g. displayed as U:X, so that it
was not necessary to create Ux using postProcess. Nevertheless, the user should deselect
all series except Ux (or U:x). A square colour box in the adjacent column to the selected
series indicates the line colour. The user can edit this most easily by a double click of the
mouse over that selection.
In order to format the graph, the user should modify the settings below the Line Series
panel, namely Line Color, Line Thickness, Line Style, Marker Style and Chart
Axes.
Also the user can click one of the buttons above the top left corner of the XY Plot.
The third button, for example, allows the user to control View Settings in which the user
can set title and legend for each axis, for example. Also, the user can set font, colour and
alignment of the axes titles, and has several options for axis range and labels in linear or
logarithmic scales.
Figure 2.11 is a graph produced using ParaView. The user can produce a graph
however he/she wishes. For information, the graph in Figure 2.11 was produced with the
options for axes of: Standard type of Notation; Specify Axis Range selected; titles in Sans
Serif 12 font. The graph is displayed as a set of points rather than a line by activating
the Enable Line Series button in the Display window. Note: if this button appears to be
inactive by being “greyed out”, it can be made active by selecting and deselecting the
sets of variables in the Line Series panel. Once the Enable Line Series button is selected,
the Line Style and Marker Style can be adjusted to the user’s preference.
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-33
in regions where the true solution deviates greatest from linear form, i.e. where the change
in gradient is largest. Error decreases with cell size.
It is useful to have an intuitive appreciation of the form of the solution before setting
up any problem. It is then possible to anticipate where the errors will be largest and
to grade the mesh so that the smallest cells are in these regions. In the cavity case the
large variations in velocity can be expected near a wall and so in this part of the tutorial
the mesh will be graded to be smaller in this region. By using the same number of cells,
greater accuracy can be achieved without a significant increase in computational cost.
A mesh of 20×20 cells with grading towards the walls will be created for the lid-driven
cavity problem and the results from the finer mesh of section 2.1.5.2 will then be mapped
onto the graded mesh to use as an initial condition. The results from the graded mesh will
be compared with those from the previous meshes. Since the changes to the blockMeshDict
dictionary are fairly substantial, the case used for this part of the tutorial, cavityGrade, is
supplied in the $FOAM RUN/tutorials/incompressible/icoFoam/cavity directory.
Open∇FOAM-v2212
T-34 Incompressible flow
63 }
64 fixedWalls
65 {
66 type wall;
67 faces
68 (
69 (3 12 15 6)
70 (0 9 12 3)
71 (0 1 10 9)
72 (1 2 11 10)
73 (2 5 14 11)
74 (5 8 17 14)
75 );
76 }
77 frontAndBack
78 {
79 type empty;
80 faces
81 (
82 (0 3 4 1)
83 (1 4 5 2)
84 (3 6 7 4)
85 (4 7 8 5)
86 (9 10 13 12)
87 (10 11 14 13)
88 (12 13 16 15)
89 (13 14 17 16)
90 );
91 }
92 );
93
94
95 // ************************************************************************* //
Once familiar with the blockMeshDict file for this case, the user can execute blockMesh
from the command line. The graded mesh can be viewed as before using paraFoam as
described in section 2.1.2.
and
(
R for R > 1,
α= (2.7)
1 − r−n + r−1 for R < 1.
For the cavityGrade case the number of cells in each direction in a block is 10, the ratio
between largest and smallest cells is 2 and the block height and width is 0.05 m. Therefore
the smallest cell length is 3.45 mm. From Equation 2.2, the time step should be less than
3.45 ms to maintain a Courant of less than 1. To ensure that results are written out
at convenient time intervals, the time step deltaT should be reduced to 2.5 ms and the
writeInterval set to 40 so that results are written out every 0.1 s. These settings can
be viewed in the cavityGrade/system/controlDict file.
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-35
The startTime needs to be set to that of the final conditions of the case cavityFine,
i.e.0.7. Since cavity and cavityFine converged well within the prescribed run time, we can
set the run time for case cavityGrade to 0.1 s, i.e. the endTime should be 0.8.
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity/cavityGrade
mapFields ../cavityFine -consistent
Now run icoFoam from the case directory and monitor the run time information. View
the converged results for this case and compare with other results using post-processing
tools described previously in section 2.1.5.6 and section 2.1.5.7.
cd $FOAM_RUN/tutorials/incompressible/icoFoam/cavity
cp -r cavity cavityHighRe
2.1.7.1 Pre-processing
Enter the cavityHighRe case and edit the transportProperties dictionary. Since the Reynolds
number is required to be increased by a factor of 10, decrease the kinematic viscosity by
a factor of 10, i.e. to 1 × 10−3 m2 s−1 . We can now run this case by restarting from the
solution at the end of the cavity case run. To do this we can use the option of setting the
startFrom keyword to latestTime so that icoFoam takes as its initial data the values
stored in the directory corresponding to the most recent time, i.e. 0.5. The endTime
should be set to 2 s.
nohup enables a command to keep running after the user who issues the command has
logged out;
nice changes the priority of the job in the kernel’s scheduler; a niceness of -20 is the
highest priority and 19 is the lowest priority.
This is useful, for example, if a user wishes to set a case running on a remote machine
and does not wish to monitor it heavily, in which case they may wish to give it low
priority on the machine. In that case the nohup command allows the user to log out of a
Open∇FOAM-v2212
T-36 Incompressible flow
remote machine he/she is running on and the job continues running, while nice can set
the priority to 19. For our case of interest, we can execute the command in this manner
as follows:
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity/cavityHighRe
nohup nice -n 19 icoFoam > log &
cat log
In previous runs you may have noticed that icoFoam stops solving for velocity U quite
quickly but continues solving for pressure p for a lot longer or until the end of the run.
In practice, once icoFoam stops solving for U and the initial residual of p is less than
the tolerance set in the fvSolution dictionary (typically 10−6 ), the run has effectively
converged and can be stopped once the field data has been written out to a time directory.
For example, at convergence a sample of the log file from the run on the cavityHighRe
case appears as follows in which the velocity has already converged after 1.62 s and
initial pressure residuals are small; No Iterations 0 indicates that the solution of U has
stopped:
1
2 Time = 1.63
3
4 Courant Number mean: 0.221985 max: 0.839923
5 smoothSolver: Solving for Ux, Initial residual = 3.64032e-06, Final residual = 3.64032e-06, No Iterations 0
6 smoothSolver: Solving for Uy, Initial residual = 4.20677e-06, Final residual = 4.20677e-06, No Iterations 0
7 DICPCG: Solving for p, Initial residual = 2.11678e-06, Final residual = 7.25303e-07, No Iterations 3
8 time step continuity errors : sum local = 7.25166e-09, global = 4.96308e-19, cumulative = -1.28342e-17
9 DICPCG: Solving for p, Initial residual = 1.36075e-06, Final residual = 7.94478e-07, No Iterations 1
10 time step continuity errors : sum local = 7.77548e-09, global = -4.78772e-19, cumulative = -1.3313e-17
11 ExecutionTime = 0.38 s ClockTime = 0 s
12
13 Time = 1.635
14
15 Courant Number mean: 0.221986 max: 0.839923
16 smoothSolver: Solving for Ux, Initial residual = 3.56036e-06, Final residual = 3.56036e-06, No Iterations 0
17 smoothSolver: Solving for Uy, Initial residual = 4.11726e-06, Final residual = 4.11726e-06, No Iterations 0
18 DICPCG: Solving for p, Initial residual = 2.03881e-06, Final residual = 8.18692e-07, No Iterations 3
19 time step continuity errors : sum local = 8.38471e-09, global = -6.27334e-19, cumulative = -1.39403e-17
20 DICPCG: Solving for p, Initial residual = 1.36655e-06, Final residual = 7.94623e-07, No Iterations 1
21 time step continuity errors : sum local = 8.25673e-09, global = 5.87298e-20, cumulative = -1.38816e-17
22 ExecutionTime = 0.38 s ClockTime = 0 s
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-37
2.1.8.1 Pre-processing
17 dimensions [0 2 -1 0 0 0 0];
18
19 internalField uniform 0;
20
21 boundaryField
22 {
23 "(movingWall|fixedWalls)"
24 {
25 type nutkWallFunction;
26 value uniform 0;
27 }
28
29 frontAndBack
30 {
31 type empty;
32 }
33 }
34
35
36 // ************************************************************************* //
This case uses standard wall functions, specified by the nutWallFunction keyword entry
on the movingWall and fixedWalls patches. Other wall function models include the
rough wall functions, specified though the nutRoughWallFunction keyword.
The user should now open the field files for k and ε (0/k and 0/epsilon) and examine
their boundary conditions. For a wall boundary condition wall, ε is assigned a epsilon-
WallFunction boundary condition and a kqRwallFunction boundary condition is assigned
to k. The latter is a generic boundary condition that can be applied to any field that are
of a turbulent kinetic energy type, e.g. k, q or Reynolds Stress R. The initial values for
k and ε are set using an estimated fluctuating component of velocity U′ and a turbulent
length scale, l. k and ε are defined in terms of these parameters as follows:
1
k = U′ • U′ (2.8)
2
Cµ0.75 k 1.5
ε= (2.9)
l
1
k = (Ux′ 2 + Uy′ 2 + Uz′ 2 ) (2.10)
2
where Ux′ 2 , Uy′ 2 and Uz′ 2 are the fluctuating components of velocity in the x, y and z
directions respectively. Let us assume the initial turbulence is isotropic, i.e. Ux′ 2 = Uy′ 2 =
Uz′ 2 , and equal to 5% of the lid velocity and that l, is equal to 20% of the box width, 0.1
Open∇FOAM-v2212
T-38 Incompressible flow
The options for simulationType are laminar, RAS and LES. More informaton on turbu-
lence models can be found in the Extended Code Guide With RAS selected in this case,
the choice of RAS modelling is specified in a turbulenceProperties subdictionary, also in
the constant directory. The turbulence model is selected by the RASModel entry from a
long list of available models that are listed in User Guide Table A.5. The kEpsilon model
should be selected which is is the standard k − ε model; the user should also ensure that
turbulence calculation is switched on.
The coefficients for each turbulence model are stored within the respective code with
a set of default values. Setting the optional switch called printCoeffs to on will make
the default values be printed to standard output, i.e. the terminal, when the model is
called at run time. The coefficients are printed out as a sub-dictionary whose name
is that of the model name with the word Coeffs appended, e.g. kEpsilonCoeffs in
the case of the kEpsilon model. The coefficients of the model, e.g. kEpsilon, can be
modified by optionally including (copying and pasting) that sub-dictionary within the
turbulenceProperties file and adjusting values accordingly.
The user should next set the laminar kinematic viscosity in the transportProperties
dictionary. To achieve a Reynolds number of 104 , a kinematic viscosity of 10−5 m is
required based on the Reynolds number definition given in Equation 2.1.
Finally the user should set the startTime, stopTime, deltaT and the writeInterval
in the controlDict. Set deltaT to 0.005 s to satisfy the Courant number restriction and
the endTime to 10 s.
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-39
centres are much less than the lid velocity. In fact, after ≈ 100 time steps it becomes
apparent that the velocity in the cells adjacent to the lid reaches an upper limit of around
0.2 m s−1 hence the maximum Courant number does not rise much above 0.2. It is sensible
to increase the solution time by increasing the time step to a level where the Courant
number is much closer to 1. Therefore reset deltaT to 0.02 s and, on this occasion, set
startFrom to latestTime. This instructs pisoFoam to read the start data from the latest
time directory, i.e.10.0. The endTime should be set to 20 s since the run converges a lot
slower than the laminar case. Restart the run as before and monitor the convergence of
the solution. View the results at consecutive time steps as the solution progresses to see
if the solution converges to a steady-state or perhaps reaches some periodically oscillating
state. In the latter case, convergence may never occur but this does not mean the results
are inaccurate.
Open∇FOAM-v2212
T-40 Incompressible flow
63 {
64 type wall;
65 faces
66 (
67 (0 8 10 2)
68 (2 10 13 5)
69 (7 15 12 4)
70 (4 12 11 3)
71 (3 11 9 1)
72 (1 9 8 0)
73 );
74 }
75 frontAndBack
76 {
77 type empty;
78 faces
79 (
80 (0 2 3 1)
81 (2 5 6 3)
82 (3 6 7 4)
83 (8 9 11 10)
84 (10 11 14 13)
85 (11 12 15 14)
86 );
87 }
88 );
89
90
91 // ************************************************************************* //
Generate the mesh with blockMesh. The patches are set as according to the previous
cavity cases. For the sake of clarity in describing the field mapping process, the upper
wall patch is renamed lid, previously the movingWall patch of the original cavity.
In an inconsistent mapping, there is no guarantee that all the field data can be mapped
from the source case. The remaining data must come from field files in the target case
itself. Therefore field data must exist in the time directory of the target case before
mapping takes place. In the cavityClipped case the mapping is set to occur at time 0.5 s,
since the startTime is set to 0.5 s in the controlDict. Therefore the user needs to copy
initial field data to that directory, e.g. from time 0:
cd $FOAM RUN/tutorials/incompressible/icoFoam/cavity/cavityClipped
cp -r 0 0.5
Before mapping the data, the user should view the geometry and fields at 0.5 s.
Now we wish to map the velocity and pressure fields from cavity onto the new fields
of cavityClipped. Since the mapping is inconsistent, we need to edit the mapFieldsDict
dictionary, located in the system directory. The dictionary contains 2 keyword entries:
patchMap and cuttingPatches. The patchMap list contains a mapping of patches from
the source fields to the target fields. It is used if the user wishes a patch in the target
field to inherit values from a corresponding patch in the source field. In cavityClipped, we
wish to inherit the boundary values on the lid patch from movingWall in cavity so we
must set the patchMap as:
patchMap
(
lid movingWall
);
The cuttingPatches list contains names of target patches whose values are to be
mapped from the source internal field through which the target patch cuts. In this case
we will include the fixedWalls to demonstrate the interpolation process.
cuttingPatches
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-41
(
fixedWalls
);
Now the user should run mapFields, from within the cavityClipped directory:
mapFields ../cavity
The user can view the mapped field as shown in Figure 2.13. The boundary patches
have inherited values from the source case as we expected. Having demonstrated this,
however, we actually wish to reset the velocity on the fixedWalls patch to (0, 0, 0). Edit
the U field, go to the fixedWalls patch and change the field from nonuniform to uniform
(0, 0, 0). The nonuniform field is a list of values that requires deleting in its entirety. Now
run the case with icoFoam.
Open∇FOAM-v2212
T-42 Incompressible flow
Open∇FOAM-v2212
2.1 Lid-driven cavity flow T-43
6 7 8
15 16 17
2 3
3 4 5
12 13 14
0 1
y
x 1 2
0
z 11
9 10
Figure 2.12: Block structure of the graded mesh for the cavity (block numbers encircled).
Open∇FOAM-v2212
T-44 Incompressible flow
Open∇FOAM-v2212
2.2 Flow around a cylinder T-45
symmetry
4.0 m
0 x
0.5 m
4.0 m
Figure 2.15: Geometry of flow round a cylinder
Governing equations
• Mass continuity for an incompressible fluid
∇•U = 0 (2.14)
∇2 p = 0 (2.15)
Open∇FOAM-v2212
T-46 Incompressible flow
Boundary conditions
Solver name potentialFoam: a potential flow code, i.e. assumes the flow is incompress-
ible, steady, irrotational, inviscid and it ignores gravity.
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
Open∇FOAM-v2212
2.2 Flow around a cylinder T-47
problem, we must describe a 3 dimensional mesh that is only one cell thick in the third
direction that is not solved. In Figure 2.16 we show only the back plane of the geometry,
along z = −0.5, in which the vertex numbers are numbered 0-18. The other 19 vertices
in the front plane, z = +0.5, are numbered in the same order as the back plane, as shown
in the mesh description file below:
1 /*--------------------------------*- C++ -*----------------------------------*\
2 | ========= | |
3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 | \\ / O peration | Version: v2212 |
5 | \\ / A nd | Website: www.openfoam.com |
6 | \\/ M anipulation | |
7 \*---------------------------------------------------------------------------*/
8 FoamFile
9 {
10 version 2.0;
11 format ascii;
12 class dictionary;
13 object blockMeshDict;
14 }
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 scale 1;
18
19 // Geometric parameters
20 rInner 0.5;
21 rOuter 1;
22 xmax 2;
23 ymax 2;
24
25 zmin -0.5; // Back/front locations
26 zmax 0.5;
27
28 // Divisions: Radial, quarter circumference, outer region and z-directions.
29 nRadial 10;
30 nQuarter 10;
31 nxOuter 20;
32 nyOuter 20;
33 nz 1;
34
35 // ----------------
36
37 // Derived quantities
38 rInner45 ${{ $rInner * sqrt(0.5) }};
39 rOuter45 ${{ $rOuter * sqrt(0.5) }};
40
41 vertices #codeStream
42 {
43 codeInclude
44 #{
45 #include "pointField.H"
46 #};
47
48 code
49 #{
50 pointField points
51 ({
52 /* 0*/ { $rInner, 0, $zmin },
53 /* 1*/ { $rOuter, 0, $zmin },
54 /* 2*/ { $xmax, 0, $zmin },
55 /* 3*/ { $xmax, $rOuter45, $zmin },
56 /* 4*/ { $rOuter45, $rOuter45, $zmin },
57 /* 5*/ { $rInner45, $rInner45, $zmin },
58 /* 6*/ { $xmax, $ymax, $zmin },
59 /* 7*/ { $rOuter45, $ymax, $zmin },
60 /* 8*/ { 0, $ymax, $zmin },
61 /* 9*/ { 0, $rOuter, $zmin },
62 /*10*/ { 0, $rInner, $zmin },
63 /*11*/ { -$rInner, 0, $zmin },
64 /*12*/ { -$rOuter, 0, $zmin },
65 /*13*/ { -$xmax, 0, $zmin },
66 /*14*/ { -$xmax, $rOuter45, $zmin },
67 /*15*/ { -$rOuter45, $rOuter45, $zmin },
68 /*16*/ { -$rInner45, $rInner45, $zmin },
69 /*17*/ { -$xmax, $ymax, $zmin },
70 /*18*/ { -$rOuter45, $ymax, $zmin }
71 });
72
73 // Duplicate z points for zmax
74 const label sz = points.size();
75 points.resize(2*sz);
Open∇FOAM-v2212
T-48 Incompressible flow
Open∇FOAM-v2212
2.2 Flow around a cylinder T-49
Open∇FOAM-v2212
T-50 Incompressible flow
21 startTime 0;
22
23 stopAt nextWrite;
24
25 endTime 1;
26
27 deltaT 1;
28
29 writeControl timeStep;
30
31 writeInterval 1;
32
33 purgeWrite 0;
34
35 writeFormat ascii;
36
37 writePrecision 6;
38
39 writeCompression off;
40
41 timeFormat general;
42
43 timePrecision 6;
44
45 runTimeModifiable true;
46
47 functions
48 {
49 error
50 {
51 name error;
52 type coded;
53 libs (utilityFunctionObjects);
54
55 codeEnd
56 #{
57 // Lookup U
58 Info<< "Looking up field U\n" << endl;
59 const volVectorField& U = mesh().lookupObject<volVectorField>("U");
60
61 Info<< "Reading inlet velocity uInfX\n" << endl;
62
63 scalar ULeft = 0.0;
64 label leftI = mesh().boundaryMesh().findPatchID("left");
65 const fvPatchVectorField& fvp = U.boundaryField()[leftI];
66 if (fvp.size())
67 {
68 ULeft = fvp[0].x();
69 }
70 reduce(ULeft, maxOp<scalar>());
71
72 dimensionedScalar uInfX("uInfx", dimVelocity, ULeft);
73
74 Info<< "U at inlet = " << uInfX.value() << " m/s" << endl;
75
76
77 scalar magCylinder = 0.0;
78 label cylI = mesh().boundaryMesh().findPatchID("cylinder");
79 const fvPatchVectorField& cylFvp = mesh().C().boundaryField()[cylI];
80 if (cylFvp.size())
81 {
82 magCylinder = mag(cylFvp[0]);
83 }
84 reduce(magCylinder, maxOp<scalar>());
85
86 dimensionedScalar radius("radius", dimLength, magCylinder);
87
88 Info<< "Cylinder radius = " << radius.value() << " m" << endl;
89
90 volVectorField UA
91 (
92 IOobject
93 (
94 "UA",
95 mesh().time().timeName(),
96 U.mesh(),
97 IOobject::NO_READ,
98 IOobject::AUTO_WRITE
99 ),
100 U
101 );
102
103 Info<< "\nEvaluating analytical solution" << endl;
104
Open∇FOAM-v2212
2.2 Flow around a cylinder T-51
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 the fvSolution dic-
tionary. 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 2.17(a) (at t = 1, when the steady-state sim-
ulation is complete). We expect the solution to show smooth streamlines passing across
the domain as in the analytical solution in Figure 2.17(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 2.17(b).
Open∇FOAM-v2212
T-52 Incompressible flow
Open∇FOAM-v2212
2.3 Magnetohydrodynamic flow of a liquid T-53
20
y
By = 20 T 2
x
Governing equations
∇•U = 0 (2.16)
∇•B = 0 (2.19)
∂D
∇×H=J+ =J (2.20)
∂t
assuming ∂D/∂t ≪ J. Here, H is the magnetic field strength, J is the current
density and D is the electric flux density.
Open∇FOAM-v2212
T-54 Incompressible flow
• Charge continuity
∇•J = 0 (2.21)
• Constitutive law
B = µH (2.22)
• Ohm’s law
J = σ (E + U × B) (2.23)
• Combining Equation 2.18, Equation 2.20, Equation 2.23, and taking the curl
∂B
+ ∇ • (UB) − ∇ • (φB U) − ∇ • (ΓB B) = 0 (2.24)
∂t
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
Open∇FOAM-v2212
2.3 Magnetohydrodynamic flow of a liquid T-55
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 scale 1;
18
19 vertices
20 (
21 (0 -1 0)
22 (20 -1 0)
23 (20 1 0)
24 (0 1 0)
25 (0 -1 0.1)
26 (20 -1 0.1)
27 (20 1 0.1)
28 (0 1 0.1)
29 );
30
31 blocks
32 (
33 hex (0 1 2 3 4 5 6 7) (100 40 1) simpleGrading (1 1 1)
34 );
35
36 boundary
37 (
38 inlet
39 {
40 type patch;
41 faces
42 (
43 (0 4 7 3)
44 );
45 }
46 outlet
47 {
48 type patch;
49 faces
50 (
51 (2 6 5 1)
52 );
53 }
54 lowerWall
55 {
56 type patch;
57 faces
58 (
59 (1 5 4 0)
60 );
61 }
62 upperWall
63 {
64 type patch;
65 faces
66 (
67 (3 7 6 2)
68 );
69 }
70 frontAndBack
71 {
72 type empty;
73 faces
74 (
75 (0 3 2 1)
76 (4 5 6 7)
77 );
78 }
79 );
80
81
82 // ************************************************************************* //
σ
r
M = BL (2.25)
ρν
Open∇FOAM-v2212
T-56 Incompressible flow
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 2.19: Velocity profile in the Hartmann problem for By = 1 T and By = 20 T.
code and Ucomponents. In this case, M = 1 and the electromagnetic body forces no longer
dominate. The velocity profile consequently takes on the parabolic form, characteristic
of Poiseuille flow as shown in Figure 2.19. To validate the code the analytical solution
for the velocity profile Ux is superimposed in Figure 2.19, given by:
where the characteristic length L is half the width of the domain, i.e. 1 m.
Open∇FOAM-v2212
Chapter 3
Compressible flow
T-58 Compressible flow
• $FOAM TUTORIALS/incompressible/simpleFoam/pitzDaily
In this example we shall investigate steady turbulent flow over a backward-facing step.
The problem description is taken from one used by Pitz and Daily in an experimental
investigation [**] against which the computed solution can be compared. This example
introduces the following OpenFOAM features for the first time:
y
50.8 33.2
x
Governing equations
∇•U = 0 (3.1)
Boundary conditions
Open∇FOAM-v2212
3.1 Steady turbulent flow over a backward-facing step T-59
Transport properties
Turbulence model
• Standard k − ǫ;
• Coefficients: Cµ = 0.09; C1 = 1.44; C2 = 1.92; αk = 1; αǫ = 0.76923.
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.2: Blocks in backward-facing step
Open∇FOAM-v2212
T-60 Compressible flow
Open∇FOAM-v2212
3.1 Steady turbulent flow over a backward-facing step T-61
A major feature of this problem is the use of the full mesh grading capability of
blockMesh that is described in section 4.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 4.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.2. The purpose of this differential grading
Open∇FOAM-v2212
T-62 Compressible flow
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 and viewed as
described in previous examples.
Open∇FOAM-v2212
3.1 Steady turbulent flow over a backward-facing step T-63
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.3(b-c).
Open∇FOAM-v2212
T-64 Compressible flow
1.0
y
0.2
x
0.6 2.4
Dimensions in m
Figure 3.4: Geometry of the forward step geometry
Governing equations
• Mass continuity
∂ρ
+ ∇ • (ρU) = 0 (3.6)
∂t
• Ideal gas
p = ρRT (3.7)
Open∇FOAM-v2212
3.2 Supersonic flow over a forward-facing step T-65
Boundary conditions
Transport properties
Thermodynamic properties
Open∇FOAM-v2212
T-66 Compressible flow
18
19 vertices
20 (
21 (0 0 -0.05)
22 (0.6 0 -0.05)
23 (0 0.2 -0.05)
24 (0.6 0.2 -0.05)
25 (3 0.2 -0.05)
26 (0 1 -0.05)
27 (0.6 1 -0.05)
28 (3 1 -0.05)
29 (0 0 0.05)
30 (0.6 0 0.05)
31 (0 0.2 0.05)
32 (0.6 0.2 0.05)
33 (3 0.2 0.05)
34 (0 1 0.05)
35 (0.6 1 0.05)
36 (3 1 0.05)
37 );
38
39 blocks
40 (
41 hex (0 1 3 2 8 9 11 10) (25 10 1) simpleGrading (1 1 1)
42 hex (2 3 6 5 10 11 14 13) (25 40 1) simpleGrading (1 1 1)
43 hex (3 4 7 6 11 12 15 14) (100 40 1) simpleGrading (1 1 1)
44 );
45
46 edges
47 (
48 );
49
50 boundary
51 (
52 inlet
53 {
54 type patch;
55 faces
56 (
57 (0 8 10 2)
58 (2 10 13 5)
59 );
60 }
61 outlet
62 {
63 type patch;
64 faces
65 (
66 (4 7 15 12)
67 );
68 }
69 bottom
70 {
71 type symmetryPlane;
72 faces
73 (
74 (0 1 9 8)
75 );
76 }
77 top
78 {
79 type symmetryPlane;
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
102 // ************************************************************************* //
Open∇FOAM-v2212
3.2 Supersonic flow over a forward-facing step T-67
3.2.4 Exercise
The user can examine the effect on the solution of increasing the inlet velocity.
Open∇FOAM-v2212
T-68 Compressible flow
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.6: 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.11)
∂t
• The barotropic relationship
∂ρ ρ
= =ψ (3.12)
∂p K
where K is the bulk modulus
• Equation 3.12 is linearised as
ρ ≈ ρ0 + ψ (p − p0 ) (3.13)
where ρ0 and p0 are the reference density and pressure respectively such that
ρ(p0 ) = ρ0 .
Open∇FOAM-v2212
3.3 Decompression of a tank internally pressurised with water T-69
Transport properties
Thermodynamic properties
Solver name sonicLiquidFoam: a solver for compressible sonic laminar liquid flow.
Open∇FOAM-v2212
T-70 Compressible flow
32 (1 0 0.1)
33 (0 0.5 0.1)
34 (1 0.5 0.1)
35 (1.5 0.5 0.1)
36 (0 0.6 0.1)
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
Open∇FOAM-v2212
3.3 Decompression of a tank internally pressurised with water T-71
117 // ************************************************************************* //
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.16)
∆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: v2212 |
5 | \\ / A nd | Website: www.openfoam.com |
6 | \\/ M anipulation | |
7 \*---------------------------------------------------------------------------*/
8 FoamFile
9 {
10 version 2.0;
11 format ascii;
12 class dictionary;
13 object controlDict;
14 }
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 application sonicLiquidFoam;
18
19 startFrom startTime;
20
21 startTime 0;
22
23 stopAt endTime;
24
25 endTime 0.0001;
26
27 deltaT 5e-07;
28
29 writeControl timeStep;
30
31 writeInterval 20;
32
33 purgeWrite 0;
34
35 writeFormat ascii;
36
37 writePrecision 6;
38
39 writeCompression off;
40
41 timeFormat general;
Open∇FOAM-v2212
T-72 Compressible flow
42
43 timePrecision 6;
44
45 runTimeModifiable true;
46
47
48 // ************************************************************************* //
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.7, 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 vapourisation/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.
Open∇FOAM-v2212
3.3 Decompression of a tank internally pressurised with water T-73
Pressure, p
(bar)
100
90
80
70
60
50
40
30
20
10
0
edit the blockMeshDict and increase the number of cells by a factor of 4 in the x and y
directions, i.e. block 0 becomes (120 80 1) from (30 20 1) and so on. Run blockMesh
on this file. In addition, in order to maintain a Courant number below 1, the time step
must be reduced accordingly to ∆t = 10−7 s. The second simulation gives considerably
better resolution of the pressure waves as shown in Figure 3.8.
Open∇FOAM-v2212
T-74 Compressible flow
Open∇FOAM-v2212
Chapter 4
Multiphase flow
T-76 Multiphase flow
• $FOAM TUTORIALS/multiphase/interFoam/laminar/damBreak/damBreak
This example introduces the following OpenFOAM features for the first time:
Open∇FOAM-v2212
4.1 Breaking of a dam T-77
0.584 m
water column
0.584 m
0.292 m
0.048 m
40 (4 0.32876 0.1)
41 (0 4 0.1)
42 (2 4 0.1)
43 (2.16438 4 0.1)
44 (4 4 0.1)
45 );
46
47 blocks
48 (
49 hex (0 1 5 4 12 13 17 16) (23 8 1) simpleGrading (1 1 1)
50 hex (2 3 7 6 14 15 19 18) (19 8 1) simpleGrading (1 1 1)
51 hex (4 5 9 8 16 17 21 20) (23 42 1) simpleGrading (1 1 1)
52 hex (5 6 10 9 17 18 22 21) (4 42 1) simpleGrading (1 1 1)
53 hex (6 7 11 10 18 19 23 22) (19 42 1) simpleGrading (1 1 1)
54 );
55
56 edges
57 (
58 );
59
60 boundary
61 (
62 leftWall
63 {
64 type wall;
65 faces
66 (
67 (0 12 16 4)
68 (4 16 20 8)
69 );
70 }
71 rightWall
72 {
73 type wall;
74 faces
75 (
76 (7 19 15 3)
77 (11 23 19 7)
78 );
79 }
80 lowerWall
81 {
82 type wall;
83 faces
84 (
85 (0 1 13 12)
86 (1 5 17 13)
87 (5 6 18 17)
Open∇FOAM-v2212
T-78 Multiphase flow
88 (2 14 18 6)
89 (2 3 15 14)
90 );
91 }
92 atmosphere
93 {
94 type patch;
95 faces
96 (
97 (8 20 21 9)
98 (9 21 22 10)
99 (10 22 23 11)
100 );
101 }
102 );
103
104 mergePatchPairs
105 (
106 );
107
108
109 // ************************************************************************* //
Open∇FOAM-v2212
4.1 Breaking of a dam T-79
At all wall boundaries, the fixedFluxPressure boundary condition is applied to the pressure
field, which calculates the normal gradient from the local density gradient.
The defaultFaces patch representing the front and back planes of the 2D problem,
is, as usual, an empty type.
The defaultFieldValues sets the default value of the fields, i.e. the value the field
takes unless specified otherwise in the regions sub-dictionary. That sub-dictionary con-
tains a list of subdictionaries containing fieldValues that override the defaults in a
specified region. The region is expressed in terms of a topoSetSource that creates a set
of points, cells or faces based on some topological constraint. Here, boxToCell creates
a bounding box within a vector minimum and maximum to define the set of cells of the
liquid region. The phase fraction α is defined as 1 in this region.
The setFields utility reads fields from file and, after re-calculating those fields, will
write them back to file. Because the files are then overridden, it is recommended that a
backup is made before setFields is executed. In the damBreak tutorial, the alpha.water
field is initially stored as a backup only, named alpha.water.orig. Before running
setFields, the user first needs to copy alpha.water.orig to alpha.water, e.g. by typing:
cp 0/alpha.water.orig 0/alpha.water
The user should then execute setFields as any other utility is executed. Using paraFoam,
check that the initial alpha.water field corresponds to the desired distribution as in Fig-
ure 4.2.
Open∇FOAM-v2212
T-80 Multiphase flow
Phase fraction, α1
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
and phase2. The transport model for each phase is selected by the transportModel
keyword. The user should select Newtonian in which case the kinematic viscosity is sin-
gle valued and specified under the keyword nu. The viscosity parameters for the other
models, e.g.CrossPowerLaw, are specified within subdictionaries with the generic name
<model>Coeffs, i.e.CrossPowerLawCoeffs in this example. The density is specified under
the keyword rho.
The surface tension between the two phases is specified under the keyword sigma.
The values used in this tutorial are listed in Table 4.1.
phase1 properties
Kinematic viscosity m2 s−1 nu 1.0 × 10−6
Density kg m−3 rho 1.0 × 103
phase2 properties
Kinematic viscosity m2 s−1 nu 1.48 × 10−5
Density kg m−3 rho 1.0
Gravitational acceleration is uniform across the domain and is specified in a file named
g in the constant directory. Unlike a normal field file, e.g. U and p, g is a uniformDimen-
sionedVectorField and so simply contains a set of dimensions and a value that represents
(0, 9.81, 0) m s−2 for this tutorial:
17 dimensions [0 1 -2 0 0 0 0];
18 value (0 -9.81 0);
19
20
21 // ************************************************************************* //
Open∇FOAM-v2212
4.1 Breaking of a dam T-81
Open∇FOAM-v2212
T-82 Multiphase flow
54
55 functions
56 {
57 #sinclude "sampling"
58 }
59
60
61 // ************************************************************************* //
Open∇FOAM-v2212
4.1 Breaking of a dam T-83
equation; sub-cycles are additional solutions to an equation within a given time step. It
is used to enable the solution to be stable without reducing the time step and vastly
increasing the solution time. Here we specify 2 sub-cycles, which means that the α
equation is solved in 2× half length time steps within each actual time step.
The cAlpha keyword is a factor that controls the compression of the interface where: 0
corresponds to no compression; 1 corresponds to conservative compression; and, anything
larger than 1, relates to enhanced compression of the interface. We generally recommend
a value of 1.0 which is employed in this example.
cd $FOAM RUN/tutorials/multiphase/interFoam/laminar/damBreak/damBreak
interFoam | tee log
The code will now be run interactively, with a copy of output stored in the log file.
4.1.11 Post-processing
Post-processing of the results can now be done in the usual way. The user can monitor
the development of the phase fraction alpha.water in time, e.g. see Figure 4.3.
cd $FOAM RUN/tutorials/multiphase/interFoam/laminar/damBreak
mkdir damBreakFine
cp -r damBreak/0 damBreakFine
cp -r damBreak/system damBreakFine
cp -r damBreak/constant damBreakFine
Enter the new case directory and change the blocks description in the blockMeshDict
dictionary to
blocks
(
hex (0 1 5 4 12 13 17 16) (46 10 1) simpleGrading (1 1 1)
hex (2 3 7 6 14 15 19 18) (40 10 1) simpleGrading (1 1 1)
hex (4 5 9 8 16 17 21 20) (46 76 1) simpleGrading (1 2 1)
hex (5 6 10 9 17 18 22 21) (4 76 1) simpleGrading (1 2 1)
hex (6 7 11 10 18 19 23 22) (40 76 1) simpleGrading (1 2 1)
);
Open∇FOAM-v2212
T-84 Multiphase flow
Phase fraction, α1
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
(a) At t = 0.25 s.
Phase fraction, α1
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
(b) At t = 0.50 s.
Open∇FOAM-v2212
4.1 Breaking of a dam T-85
Here, the entry is presented as printed from the blockMeshDict file; in short the user must
change the mesh densities, e.g. the 46 10 1 entry, and some of the mesh grading entries
to 1 2 1. Once the dictionary is correct, generate the mesh.
As the mesh has now changed from the damBreak example, the user must re-initialise
the phase field alpha.water in the 0 time directory since it contains a number of elements
that is inconsistent with the new mesh. Note that there is no need to change the U and
p rgh fields since they are specified as uniform which is independent of the number of
elements in the field. We wish to initialise the field with a sharp interface, i.e. it elements
would have α = 1 or α = 0. Updating the field with mapFields may produce interpolated
values 0 < α < 1 at the interface, so it is better to rerun the setFields utility. There is a
backup copy of the initial uniform α field named 0/alpha.water.org that the user should
copy to 0/alpha.water before running setFields:
cd $FOAM RUN/tutorials/multiphase/interFoam/laminar/damBreak/damBreakFine
cp -r 0/alpha.water.org 0/alpha.water
setFields
The user may run on more nodes over a network by creating a file that lists the
host names of the machines on which the case is to be run as described in User Guide
Open∇FOAM-v2212
T-86 Multiphase flow
section 3.2.2. The case should run in the background and the user can follow its progress
by monitoring the log file as usual.
then processor1 will appear as a case module in ParaView. Figure 4.4 shows the mesh
from processor 1 following the decomposition of the domain using the simple method.
Open∇FOAM-v2212
4.1 Breaking of a dam T-87
Phase fraction, α1
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
(a) At t = 0.25 s.
Phase fraction, α1
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
(b) At t = 0.50 s.
Open∇FOAM-v2212
T-88 Multiphase flow
Open∇FOAM-v2212
Chapter 5
Stress analysis
T-90 Stress analysis
• $FOAM TUTORIALS/stressAnalysis/solidDisplacementFoam/plateHole
This tutorial describes how to pre-process, run and post-process a case involving linear-
elastic, steady-state stress analysis on a square plate with a circular hole at its centre.
The plate dimensions are: side length 4 m and radius R = 0.5 m. It is loaded with a
uniform traction of σ = 10 kPa over its left and right faces as shown in Figure 5.1. Two
symmetry planes can be identified for this geometry and therefore the solution domain
need only cover a quarter of the geometry, shown by the shaded area in Figure 5.1.
y
σ = 10 kPa σ = 10 kPa
symmetry plane x
R = 0.5 m
symmetry plane
4.0 m
Figure 5.1: Geometry of the plate with a hole.
Open∇FOAM-v2212
5.1 Stress analysis of a plate with a hole T-91
An analytical solution exists for loading of an infinitely large, thin plate with a circular
hole. The solution for the stress normal to the vertical plane of symmetry is
µ 2 4
¶
σ 1 + R + 3R for |y| ≥ R
(σxx )x=0 = 2y 2 2y 4 (5.1)
0 for |y| < R
Results from the simulation will be compared with this solution. At the end of the
tutorial, the user can: investigate the sensitivity of the solution to mesh resolution and
mesh grading; and, increase the size of the plate in comparison to the hole to try to
estimate the error in comparing the analytical solution for an infinite plate to the solution
of this problem of a finite plate.
8 up 7 up 6
left
4 3 right
x2
9
x1 x2
left 0 4 x1 3
10 x2
x1 right
2
5 1
hole
y x2 x2
x 0 x1 1 x1 down 2
down
Figure 5.2: Block structure of the mesh for the plate with a hole.
The user should change into the plateHole case in the $FOAM RUN/tutorials/stress-
Analysis/solidDisplacementFoam directory and open the system/blockMeshDict file in an
editor, as listed below
Open∇FOAM-v2212
T-92 Stress analysis
17 scale 1;
18
19 vertices
20 (
21 (0.5 0 0)
22 (1 0 0)
23 (2 0 0)
24 (2 0.707107 0)
25 (0.707107 0.707107 0)
26 (0.353553 0.353553 0)
27 (2 2 0)
28 (0.707107 2 0)
29 (0 2 0)
30 (0 1 0)
31 (0 0.5 0)
32 (0.5 0 0.5)
33 (1 0 0.5)
34 (2 0 0.5)
35 (2 0.707107 0.5)
36 (0.707107 0.707107 0.5)
37 (0.353553 0.353553 0.5)
38 (2 2 0.5)
39 (0.707107 2 0.5)
40 (0 2 0.5)
41 (0 1 0.5)
42 (0 0.5 0.5)
43 );
44
45 blocks
46 (
47 hex (5 4 9 10 16 15 20 21) (10 10 1) simpleGrading (1 1 1)
48 hex (0 1 4 5 11 12 15 16) (10 10 1) simpleGrading (1 1 1)
49 hex (1 2 3 4 12 13 14 15) (20 10 1) simpleGrading (1 1 1)
50 hex (4 3 6 7 15 14 17 18) (20 20 1) simpleGrading (1 1 1)
51 hex (9 4 7 8 20 15 18 19) (10 20 1) simpleGrading (1 1 1)
52 );
53
54 edges
55 (
56 arc 0 5 origin (0 0 0)
57 arc 5 10 origin (0 0 0)
58 arc 1 4 origin (0 0 0)
59 arc 4 9 origin (0 0 0)
60 arc 11 16 origin (0 0 0.5)
61 arc 16 21 origin (0 0 0.5)
62 arc 12 15 origin (0 0 0.5)
63 arc 15 20 origin (0 0 0.5)
64 );
65
66 boundary
67 (
68 left
69 {
70 type symmetryPlane;
71 faces
72 (
73 (8 9 20 19)
74 (9 10 21 20)
75 );
76 }
77 right
78 {
79 type patch;
80 faces
81 (
82 (2 3 14 13)
83 (3 6 17 14)
84 );
85 }
86 down
87 {
88 type symmetryPlane;
89 faces
90 (
91 (0 1 12 11)
92 (1 2 13 12)
93 );
94 }
95 up
96 {
97 type patch;
98 faces
99 (
Open∇FOAM-v2212
5.1 Stress analysis of a plate with a hole T-93
100 (7 8 19 18)
101 (6 7 18 17)
102 );
103 }
104 hole
105 {
106 type patch;
107 faces
108 (
109 (10 5 16 21)
110 (5 0 11 16)
111 );
112 }
113 frontAndBack
114 {
115 type empty;
116 faces
117 (
118 (10 9 4 5)
119 (5 4 1 0)
120 (1 4 3 2)
121 (4 7 6 3)
122 (4 9 8 7)
123 (21 16 15 20)
124 (16 11 12 15)
125 (12 13 14 15)
126 (15 14 17 18)
127 (15 18 19 20)
128 );
129 }
130 );
131
132
133 // ************************************************************************* //
Until now, we have only specified straight edges in the geometries of previous tutorials
but here we need to specify curved edges. These are specified under the edges keyword
entry which is a list of non-straight edges. The syntax of each list entry begins with the
type of curve, including arc, simpleSpline, polyLine etc., described further in User
Guide section 4.3.1. In this example, all the edges are circular and so can be specified by
the arc keyword entry. The following entries are the labels of the start and end vertices
of the arc and a point vector through which the circular arc passes.
The blocks in this blockMeshDict do not all have the same orientation. As can be
seen in Figure 5.2 the x2 direction of block 0 is equivalent to the −x1 direction for block
4. This means care must be taken when defining the number and distribution of cells in
each block so that the cells match up at the block faces.
6 patches are defined: one for each side of the plate, one for the hole and one for the
front and back planes. The left and down patches are both a symmetry plane. Since this
is a geometric constraint, it is included in the definition of the mesh, rather than being
purely a specification on the boundary condition of the fields. Therefore they are defined
as such using a special symmetryPlane type as shown in the blockMeshDict.
The frontAndBack patch represents the plane which is ignored in a 2D case. Again
this is a geometric constraint so is defined within the mesh, using the empty type as shown
in the blockMeshDict. For further details of boundary types and geometric constraints,
the user should refer to User Guide section 4.2.1.
The remaining patches are of the regular patch type. The mesh should be generated
using blockMesh and can be viewed in paraFoam as described in section 2.1.2. It should
appear as in Figure 5.3.
Open∇FOAM-v2212
T-94 Stress analysis
Firstly, it can be seen that the displacement initial conditions are set to (0, 0, 0) m. The
left and down patches must be both of symmetryPlane type since they are specified
as such in the mesh description in the constant/polyMesh/boundary file. Similarly the
frontAndBack patch is declared empty.
The other patches are traction boundary conditions, set by a specialist traction bound-
Open∇FOAM-v2212
5.1 Stress analysis of a plate with a hole T-95
ary type. The traction boundary conditions are specified by a linear combination of: (1)
a boundary traction vector under keyword traction; (2) a pressure that produces a trac-
tion normal to the boundary surface that is defined as negative when pointing out of
the surface, under keyword pressure. The up and hole patches are zero traction so the
boundary traction and pressure are set to zero. For the right patch the traction should
be (1e4, 0, 0) Pa and the pressure should be 0 Pa.
In this case we do not want to solve for the thermal equation. Therefore we must set
the thermalStress keyword entry to no in the thermalProperties dictionary.
5.1.2.4 Control
As before, the information relating to the control of the solution procedure are read in
from the controlDict dictionary. For this case, the startTime is 0 s. The time step is
not important since this is a steady state case; in this situation it is best to set the time
step deltaT to 1 so it simply acts as an iteration counter for the steady-state case. The
endTime, set to 100, then acts as a limit on the number of iterations. The writeInterval
can be set to 20.
The controlDict entries are as follows:
Open∇FOAM-v2212
T-96 Stress analysis
17 application solidDisplacementFoam;
18
19 startFrom startTime;
20
21 startTime 0;
22
23 stopAt endTime;
24
25 endTime 100;
26
27 deltaT 1;
28
29 writeControl timeStep;
30
31 writeInterval 20;
32
33 purgeWrite 0;
34
35 writeFormat ascii;
36
37 writePrecision 6;
38
39 writeCompression off;
40
41 timeFormat general;
42
43 timePrecision 6;
44
45 graphFormat raw;
46
47 runTimeModifiable true;
48
49
50 // ************************************************************************* //
Open∇FOAM-v2212
5.1 Stress analysis of a plate with a hole T-97
39
40 laplacianSchemes
41 {
42 default none;
43 laplacian(DD,D) Gauss linear corrected;
44 laplacian(DT,T) Gauss linear corrected;
45 }
46
47 interpolationSchemes
48 {
49 default linear;
50 }
51
52 snGradSchemes
53 {
54 default none;
55 }
56
57
58 // ************************************************************************* //
The fvSolution dictionary in the system directory controls the linear equation solvers and
algorithms used in the solution. The user should first look at the solvers sub-dictionary
and notice that the choice of solver for D is GAMG. The solver tolerance should be set to
10−6 for this problem. The solver relative tolerance, denoted by relTol, sets the required
reduction in the residuals within each iteration. It is uneconomical to set a tight (low)
relative tolerance within each iteration since a lot of terms in each equation are explicit
and are updated as part of the segregated iterative procedure. Therefore a reasonable
value for the relative tolerance is 0.01, or possibly even higher, say 0.1, or in some cases
even 0.9 (as in this case).
17 solvers
18 {
19 "(D|T)"
20 {
21 solver GAMG;
22 tolerance 1e-06;
23 relTol 0.9;
24 smoother GaussSeidel;
25 nCellsInCoarsestLevel 20;
26 }
27 }
28
29 stressAnalysis
30 {
31 compactNormalStress yes;
32 nCorrectors 1;
33 D 1e-06;
34 }
35
36
37 // ************************************************************************* //
The fvSolution dictionary contains a sub-dictionary, stressAnalysis that contains some con-
trol parameters specific to the application solver. Firstly there is nCorrectors which
specifies the number of outer loops around the complete system of equations, including
traction boundary conditions within each time step. Since this problem is steady-state,
we are performing a set of iterations towards a converged solution with the ’time step’
acting as an iteration counter. We can therefore set nCorrectors to 1.
The D keyword specifies a convergence tolerance for the outer iteration loop, i.e. sets
a level of initial residual below which solving will cease. It should be set to the desired
solver tolerance specified earlier, 10−6 for this problem.
Open∇FOAM-v2212
T-98 Stress analysis
cd $FOAM RUN/tutorials/stressAnalysis/solidDisplacementFoam/plateHole
solidDisplacementFoam > log &
The user should check the convergence information by viewing the generated log file which
shows the number of iterations and the initial and final residuals of the displacement in
each direction being solved. The final residual should always be less than 0.9 times the
initial residual as this iteration tolerance set. Once both initial residuals have dropped
below the convergence tolerance of 10−6 the run has converged and can be stopped by
killing the batch job.
5.1.4 Post-processing
Post processing can be performed as in section 2.1.4. The solidDisplacementFoam solver
outputs the stress field σ as a symmetric tensor field sigma. This is consistent with the
way variables are usually represented in OpenFOAM solvers by the mathematical symbol
by which they are represented; in the case of Greek symbols, the variable is named
phonetically.
For post-processing individual scalar field components, σxx , σxy etc., can be generated
by running the postProcess utility as before in section 2.1.5.7, this time on sigma:
Components named sigmaxx, sigmaxy etc. are written to time directories of the case.
The σxx stresses can be viewed in paraFoam as shown in Figure 5.4.
30
25
σxx (kPa)
20
15
10
We would like to compare the analytical solution of Equation 5.1 to our solution. We
therefore must output a set of data of σxx along the left edge symmetry plane of our
domain. The user may generate the required graph data using the postProcess utility,
using a sets function object. The utility can be driven from a user-supplied file located in
the system directory, whose entries are summarised in User Guide Table 7.3. The sample
line specified in sets is set between (0.0, 0.5, 0.25) and (0.0, 2.0, 0.25), and the fields are
specified in the fields list:
Open∇FOAM-v2212
5.1 Stress analysis of a plate with a hole T-99
35
30
8
9 singleGraph
10 {
11 start (0 0.5 0.25);
12 end (0 2 0.25);
13 fields (sigmaxx);
14
15 #includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg"
16
17 setConfig
18 {
19 axis y;
20 }
21
22 // Must be last entry
23 #includeEtc "caseDicts/postProcessing/graphs/graph.cfg"
24 }
25
26
27 // ************************************************************************* //
The writeFormat is raw 2 column format. The data is written into files within time
subdirectories of a sets directory, e.g. the data at t = 100 s is found within the file
sets/100/leftPatch sigmaxx.xy. In an application such as GnuPlot, one could type the
following at the command prompt would be sufficient to plot both the numerical data
and analytical solution:
5.1.5 Exercises
The user may wish to experiment with solidDisplacementFoam by trying the following
exercises:
Open∇FOAM-v2212
T-100 Stress analysis
Open∇FOAM-v2212
Index T-101
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
Open∇FOAM-v2212
T-102 Index
Open∇FOAM-v2212
Index T-103
Open∇FOAM-v2212
T-104 Index
Open∇FOAM-v2212