0% found this document useful (0 votes)
19 views71 pages

TP Fluide2 SMER S4 Partie1

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

TP Fluide2 SMER S4 Partie1

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

Running my first OpenFOAM® case setup blindfold

Before we start – Always remember the directory structure


case_name
├── 0
├── constant
│ └── polyMesh
├── system
└── time_directories

• To keep everything in order, the case directory is often located in the path
$WM_PROJECT_USER_DIR/run
• This is not compulsory but highly advisable, you can put the case in any directory of your preference.
• The name of the case directory if given by the user (do not use white spaces).
• You run the applications and utilities in the top level of this directory.
• The directory system contains run-time control and solver numerics.
• The directory constant contains physical properties, turbulence modeling properties, advanced physics
and so on.
• The directory constant/polyMesh contains the polyhedral mesh information.
• The directory 0 contains boundary conditions (BC) and initial conditions (IC).
Running my first OpenFOAM® case setup blindfold
Flow in a lid-driven square cavity – Re = 100
Incompressible flow

Physical and numerical side of the


problem:
• The governing equations of the problem are the
incompressible laminar Navier-Stokes equations.
• We are going to work in a 2D domain but the
problem can be extended to 3D easily.
• To find the numerical solution we need to
discretize the domain (mesh generation), set the
boundary and initial conditions, define the flow
properties, setup the numerical scheme and solver
settings, and set runtime parameters (time step,
simulation time, saving frequency and so on).
• For convenience, when dealing with
incompressible flows we will use relative pressure.
• All the dictionaries files have been already preset.
Running my first OpenFOAM® case setup blindfold
Workflow of the case

blockMesh

icoFoam functionObjects

sampling paraview
Running my first OpenFOAM® case setup blindfold
At the end of the day, you should get something like this

Mesh (very coarse and 2D)

Pressure field (relative pressure) Velocity magnitude field


Running my first OpenFOAM® case setup blindfold
At the end of the day, you should get something like this
Y centerline

• And as CFD is not only about pretty colors, we should also


validate the results
X centerline

High-Re Solutions for incompressible flow using the navier-stokes equations and a multigrid method
U. Ghia, K. N. Ghia, C. T. Shin.
Journal of computational physics, 48, 387-411 (1982)
Running my first OpenFOAM® case setup blindfold
What are we going to do?
• We will use the lid-driven square cavity tutorial as a general example to show you how to set up
and run solvers and utilities in OpenFOAM®.
• In this tutorial we are going to generate the mesh using blockMesh.
• After generating the mesh, we will look for topological errors and assess the mesh quality. For
this we use the utility checkMesh. Later on, we are going to talk about what is a good mesh.
• Then, we will find the numerical solution using icoFoam, which is a transient solver for
incompressible, laminar flow of Newtonian fluids. By the way, we hope you did not forget where
to look for this information.
• And we will finish with some quantitative post-processing and qualitative visualization using
paraFoam and OpenFOAM® utilities.
• While we run this case, we are going to see a lot of information on the screen (standard output
stream or stdout), but it will not be saved. This information is mainly related to convergence of
the simulation, we will talk about this later on.
• A final word, we are going to use the solver icoFoam but have in mind that this is a very basic
solver with no modeling capabilities and limited post-processing features.
• Therefore, is better to use pisoFoam or pimpleFoam which are equivalent to icoFoam but
with many more features.
Running my first OpenFOAM® case setup blindfold
Running the case blindfold
• Let us run this case blindfold.
• Later we will study in details each file and directory.
• Remember, the variable $FOAM_RUN is pointing to the path where you unpacked the
tutorials.
• You can create this environment variable or write down the path to the directory.
• In the terminal window type:

1. $> cd $FOAM_RUN/cavity

2. $> ls –l
3. $> blockMesh
4. $> checkMesh
5. $> icoFoam
6. $> paraFoam
Running my first OpenFOAM® case setup blindfold
Running the case blindfold

• In step 1 we go to the case directory. Remember, $FOAM_RUN is pointing to the path where you
unpacked the tutorials.

• In step 2 we just list the directory structure (this step is optional). Does it look familiar to you? In
the directory 0 you will the initial and boundary conditions, in the constant directory you will
find the mesh information and physical properties, and in the directory system you will find the
dictionaries that controls the numerics, runtime parameters and sampling.

• In step 3 we generate the mesh.

• In step 4 we check the mesh quality. We are going to address how to assess mesh quality later
on.

• In step 5 we run the simulation. This will show a lot information on the screen, the standard
output stream will not be saved.

• Finally, in step 6 we visualize the solution using paraFoam. In the next slides we are going to
briefly explore this application.
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam

Menu Bar
Toolbars

Pipeline Browser

Properties panel

Apply button
Press this button to
load the case or to
apply a filter

3D View/Canvas
Advanced Toggle
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Toolbars
• Main Controls

• VCR Controls (animation controls)

• Current Time Controls

• Active Variable Controls

• Representation Toolbar

• Camera Controls (view orientation)

• Center Axes Controls

• Common Filters

• Data Analysis Toolbar


Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Mesh visualization
Select Surface With Edges in the Representation Toolbar Fit to screen Select the -Z view

Select Solid Color in the


Active Variable Controls

Click on the eyeball in


the Pipeline Browser to
hide/unhide the object

Select mesh parts to visualize.


By default it will automatically
select internalMesh

Select the volume fields to


visualize. By default it will select
U and p
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – 3D View and mouse interaction
Select view orientation in the Camera Controls

Mouse interaction in the


3D view

Rotate

Zoom

Pan

Zoom

3D View/Canvas
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Fields visualization
Select Last Frame in the VCR Controls Current Time Controls

Select U in Active Variable Controls

Turn on/off color bar

Select Surface in the


Representation Toolbar

Select Magnitude in the


drop down menu

Select volume fields to visualize.


By default it will select U and p.
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Filters
• Filters are functions that generate, extract or derive features from the input data.
• They are attached to the input data.
• You can access the most commonly used filters from the Common Filters toolbar

• You can access all the filters from the menu Filter.
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Filters

Filters are attached


to the input data

• Even if the case is 2D, it will be


visualized as if it were a 3D case.
• Notice that there is only one cell in
the Z direction.
• Let us use the slice filter. This filter
will create a cut plane.
• Let us create a slice normal to the
Z direction.
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Slice filter

1. Select the Slice filter

If you want to erase a filter,


right click on it and select
Delete

4. Press Apply

3. Optional - Turn off the


option Show Plane

2. Select the direction Z Normal.


Additionally you can choose the
origin of the plane (by default is the
mid section)
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Glyph filter
4. Color the colors using Solid Color
1. Select the Glyph filter. This
filter will be applied on the
Slice1 filter

Notice that the filter


Glyph was applied on
the Slice1 filter.

3. Press Apply

2. Filter options

Notice that the vectors are plotted in the


cell vertices. To plot the vectors at the
cell centers, use the filter cell
centers and replot the vectors.
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Plot Over Line filter
1.a. Select the Plot Over Line
filter.

1.b. Alternative, you can select Plot


Over Line filter from the Data
Analysis Toolbar

(0.5, 1, 1)

Notice that we are using the filter in


a clean Pipeline

3. Press Apply

(0.5, 0, 1)
2. Enter the coordinates of the line

Line
Running my first OpenFOAM® case setup blindfold
Crash introduction to paraFoam – Filters
4. Optional – Use the VCR Control to change the frame.
The line chart view will be updated automatically

3. Optional - To save the


sampled data in CSV
format, click on the filter.
Then click on the File
menu and select the
option Save Data

2. Select the variables to


plot in the line chart view

1. Click on the line chart view (the blue frame indicates that it is the active view)
Running my first OpenFOAM® case setup blindfold
Running the case blindfold with log files
• In the previous case, we ran the simulation but we did not save the standard output
stream (stdout) in a log file.

• We just saw the information on-the-fly.

• Our advice is to always save the standard output stream (stdout) in a log file.

• It is of interest to always save the log as if something goes wrong and you would like
to do troubleshooting, you will need this information.

• Also, if you are interested in plotting the residuals you will need the log file.

• By the way, if at any point you ask us what went wrong with your simulation, it is likely
that we will ask you for this file.

• We might also ask for the standard error stream (stderr).


Running my first OpenFOAM® case setup blindfold
Running the case blindfold with log files
• There are many ways to save the log files.
• From now on, we will use the Linux tee command to save log files.
• To save a log file of the simulation or the output of any utility, you can proceed as
follows:

1. $> foamCleanTutorials
2. $> blockMesh | tee log.blockMesh
3. $> checkMesh | tee log.checkMesh
4. $> icoFoam | tee log.icoFoam

The vertical bar or pipelining operator is used to concatenate commands

• You can use your favorite text editor to read the log file (e.g., gedit, vi, emacs).
Running my first OpenFOAM® case setup blindfold
Running the case blindfold with log files

• In step 1 we erase the mesh and all the folders, except for 0, constant and system. This
script comes with your OpenFOAM® installation.

• In step 2, we generate the mesh using the meshing tool blockMesh. We also redirect the
standard output to an ascii file with the name log.blockMesh (it can be any name). The tee
command will redirect the screen output to the file log.blockMesh and at the same time will
show you the information on the screen.

• In step 3 we check the mesh quality. We also redirect the standard output to an ascii file with the
name log.checkMesh (it can be any name).

• In step 4 we run the simulation. We also redirect the standard output to an ascii file with the
name log.icoFoam (it can be any name). Remember, the tee command will redirect the
screen output to the file log.icoFoam and at the same time will show you the information on
the screen.
Running my first OpenFOAM® case setup blindfold
Stopping the simulation
• Your simulation will automatically stop at the time value you set using the keyword endTime in
the controlDict dictionary.
endTime 50;
• If for any reason you want to stop your simulation before reaching the value set by the keyword
endTime, you can change this value to a number lower than the current simulation time (you
can use 0 for instance). This will stop your simulation, but it will not save your last time-step or
iteration, so be careful.
1 /*--------------------------------*- C++ -*----------------------------------*\
2 | ========= | |
3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 | \\ / O peration | Version: 6.x |
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 object controlDict;
14 }
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 application icoFoam;
18
19 startFrom startTime;
20
21 startTime 0;
22
23 stopAt endTime;
24
25 endTime 50;
Running my first OpenFOAM® case setup blindfold
Stopping the simulation
• If you want to stop the simulation and save the solution, in the controlDict dictionary made
the following modification,
stopAt writeNow;
This will stop your simulation and will save the current time-step or iteration.

1 /*--------------------------------*- C++ -*----------------------------------*\


2 | ========= | |
3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 | \\ / O peration | Version: 6.x |
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 object controlDict;
14 }
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17 application icoFoam;
18
19 startFrom startTime;
20
21 startTime 0;
22
23 stopAt writeNow;
24
25 endTime 50;
Running my first OpenFOAM® case setup blindfold
Stopping the simulation
• The previous modifications can be done on-the-fly, but you will need to set the
keyword runTimeModifiable to true in the controlDict dictionary.
• By setting the keyword runTimeModifiable to true, you will be able to modify most of
the dictionaries on-the-fly.

1 /*--------------------------------*- C++ -*----------------------------------*\


2 | ========= | |
3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 | \\ / O peration | Version: 6.x |
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 object controlDict;
14 }

44
45 runTimeModifiable true;
46
Running my first OpenFOAM® case setup blindfold
Stopping the simulation
• You can also kill the process. For instance, if you did not launch the solver in background, go to its terminal
window and press ctrl-c. This will stop your simulation, but it will not save your last time-step or iteration, so
be careful.
Running my first OpenFOAM® case setup blindfold
Stopping the simulation
• When working locally, we usually proceed in this way:

• $> icoFoam | tee log.icofoam

This will run the solver icoFoam (by the way, this works for any solver or utility), it will save the
standard output stream in the file log.icofoam and will show the solver output on the fly.

• If at any moment we want to stop the simulation, and we are not interested in saving the last
time-step, we press ctrl-c.

• If we are interested in saving the last time step, we modify the controlDict dictionary and
add the following keyword
stopAt writeNow;

• Remember, this modification can be done on the fly. However, you will need to set the keyword
runTimeModifiable to yes in the controlDict dictionary.
Running my first OpenFOAM® case setup blindfold
Cleaning the case folder
• If you want to erase the mesh and the solution in the current case folder, you can type in the
terminal,
$> foamCleanTutorials

If you are running in parallel, this will also erase the processorN directories. We will talk about
running in parallel later.

• If you are looking to only erase the mesh, you can type in the terminal,
$> foamCleanPolyMesh

• If you are only interested in erasing the saved solutions, in the terminal type,
$> foamListTimes -rm

• If you are running in parallel and you want to erase the solution saved in the processorN
directories, type in the terminal,
$> foamListTimes –rm -processor
A deeper view to my first OpenFOAM® case setup
• We will take a close look at what we did by looking at the case files.
• The case directory originally contains the following sub-directories: 0, constant, and
system. After running icoFoam it also contains the time step directories 1, 2, 3,
..., 48, 49, 50, the post-processing directory postProcessing, and the
log.icoFoam file (if you chose to redirect the standard output stream).

• The time step directories contain the values of all the variables at those time
steps (the solution). The 0 directory is thus the initial condition and boundary
conditions.
• The constant directory contains the mesh and dictionaries for thermophysical,
turbulence models and advanced physical models.
• The system directory contains settings for the run, discretization schemes and
solution procedures.

• The icoFoam solver reads these files and runs the case according to those
settings.
A deeper view to my first OpenFOAM® case setup
• Before continuing, we want to point out the following:
• Each dictionary file in the case directory has a header.
• Lines 1-7 are commented.
• You should always keep lines 8 to 14, if not, OpenFOAM® will complain.
• According to the dictionary you are using, the class keyword (line 12)
will be different. We are going to talk about this later on.
• From now on and unless it is strictly necessary, we will not show the
header when listing the dictionaries files.

1 /*--------------------------------*- C++ -*----------------------------------*\


2 | ========= | |
3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 | \\ / O peration | Version: 6.x |
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 object controlDict;
14 }
A deeper view to my first OpenFOAM® case setup

Let us explore the case directory


A deeper view to my first OpenFOAM® case setup
The constant directory
(and by the way, open each file and go thru its content)

• In this directory you will find the sub-directory polyMesh and the dictionary file
transportProperties.
• The transportProperties file is a dictionary for the dimensioned scalar nu, or the
kinematic viscosity.

17 nu nu [ 0 2 -1 0 0 0 0 ] 0.01; //Re 100


18 //nu nu [ 0 2 -1 0 0 0 0 ] 0.001; //Re 1000

• Notice that line 18 is commented.


• The values between square bracket are the units.
• OpenFOAM® is fully dimensional. You need to define the dimensions for
each field dictionary and physical properties defined.
• Your dimensions shall be consistent.
A deeper view to my first OpenFOAM® case setup

Dimensions in OpenFOAM® (metric system)

No. Property Unit Symbol

1 Mass Kilogram kg

2 Length meters m

3 Time second s

4 Temperature Kelvin K

5 Quantity moles mol

6 Current ampere A

7 Luminuous intensity candela cd

[ 1 (kg), 2 (m), 3 (s), 4 (K), 5 (mol), 6 (A), 7 (cd)]


A deeper view to my first OpenFOAM® case setup
The constant directory
(and by the way, open each file and go thru its content)

• Therefore, the dimensioned scalar nu or the kinematic viscosity,

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

has the following units

[ 0 m^2 s^-1 0 0 0 0 ]

Which is equivalent to
A deeper view to my first OpenFOAM® case setup
The constant directory
(and by the way, open each file and go thru its content)

• In this case, as we are working with an incompressible flow, we only need to define
the kinematic viscosity.

• Later on, we will ask you to change the Reynolds number, to do so you can change
the value of nu. Remember,

• You can also change the free stream velocity U or the reference length L.
A deeper view to my first OpenFOAM® case setup
The constant directory
(and by the way, open each file and go thru its content)

• Depending on the physics involved and models used, you will need to define more
variables in the dictionary transportProperties.
• For instance, for a multiphase case you will need to define the density rho and
kinematic viscosity nu for each single phase. You will also need to define the surface
tension .
• Also, depending of your physical model, you will find more dictionaries in the constant
directory.
• For example, if you need to set gravity, you will need to create the dictionary g.
• If you work with compressible flows you will need to define the dynamic viscosity mu,
and many other physical properties in the dictionary thermophysicalProperties.
• As we are not dealing with compressible flows (for the moment), we are not going into
details.
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh directory
(and by the way, open each file and go thru its content)

• In this case, the polyMesh directory is initially empty. After generating the mesh, it
will contain the mesh in OpenFOAM® format.
• To generate the mesh in this case, we use the utility blockMesh. This utility reads
the dictionary blockMeshDict located in the system folder.
• We will briefly address a few important inputs of the blockMeshDict dictionary.
• Do not worry, we are going to revisit this dictionary during the meshing session.
• However, have in mind that rarely you will use this utility to generate a mesh for
complex geometries.
• Go to the directory system and open blockMeshDict dictionary with your favorite
text editor, we will use gedit.
A deeper view to my first OpenFOAM® case setup
The system/blockMeshDict dictionary
• The blockMeshDict dictionary first defines a list with a number of vertices:
• The keyword convertToMeters (line 17), is a scaling factor. In this case
17 convertToMeters 1;
18
we do not scale the dimensions.
19 xmin 0;
20 xmax 1; • In the section vertices (lines 37-58), we define the vertices coordinates of
21 ymin 0; the geometry. In this case, there are eight vertices defining the geometry.
22 ymax 1;
23 zmin 0;
OpenFOAM® always uses 3D meshes, even if the simulation is 2D.
24 zmax 1;
25 • We can directly define the vertex coordinates in the section vertices
26 xcells 20; (commented lines 49-56), or we can use macro syntax.
27 ycells 20;
28 zcells 1; • Using macro syntax we first define a variable and its value (lines 19-24),
29
37 vertices and then we can use them by adding the symbol $ to the variable name
38 ( (lines 39-46).
39 ($xmin $ymin $zmin) //vertex 0
40 ($xmax $ymin $zmin) //vertex 1 • In lines 26-28, we define a set of variables that will be used at a later time.
41 ($xmax $ymax $zmin) //vertex 2
42 ($xmin $ymax $zmin) //vertex 3 These variables are related to the number of cells in each direction.
43 ($xmin $ymin $zmax) //vertex 4
44 ($xmax $ymin $zmax) //vertex 5 • Finally, notice that the vertex numbering starts from 0 (as the counters in
45 ($xmax $ymax $zmax) //vertex 6 c++). This numbering applies for blocks as well.
46 ($xmin $ymax $zmax) //vertex 7
47
48 /*
49 (0 0 0)
50 (1 0 0)
51 (1 1 0)
52 (0 1 0)
53 (0 0 0.1)
54 (1 0 0.1)
55 (1 1 0.1)
56 (0 1 0.1)
57 */
58 );
A deeper view to my first OpenFOAM® case setup
The system/blockMeshDict dictionary
• The blockMeshDict dictionary also defines the boundary patches:

• In the section boundary, we define all the surface


71 boundary
72 (
patches where we want to apply boundary conditions.
73 movingWall Name
74 { • This step is of paramount importance, because if we do
75 type wall; Type
76 faces not define the surface patches we will not be able to
77 (
Connectivity
apply the boundary conditions.
78 (3 7 6 2)
79 );
80 } • For example:
81 fixedWalls
82 { • In line 73 we define the patch name movingWall
83 type wall;
84 faces (the name is given by the user).
85 (
86 (0 4 7 3) • In line 75 we give a base type to the surface patch.
87 (2 6 5 1)
88 (1 5 4 0) In this case wall (do not worry we are going to talk
89 );
90 }
about this later on).
91 frontAndBack
92 { • In line 78 we give the connectivity list of the
93 type empty;
94 faces
vertices that made up the surface patch or face,
95 ( that is, (3 7 6 2). Have in mind that the vertices
96 (0 3 2 1)
97 (4 5 6 7) need to be neighbors and it does not matter if the
98 );
99 }
ordering is clockwise or counter clockwise.
100 );
• Remember, faces are defined by a list of 4 vertex
numbers, e.g., (3 7 6 2).
A deeper view to my first OpenFOAM® case setup
The system/blockMeshDict dictionary

• To sum up, the blockMeshDict dictionary generates in this case a single block with:
• X/Y/Z dimensions: 1.0/1.0/1.0
• Cells in the X, Y and Z directions: 20 x 20 x 1 cells.
• One single hex block with straight lines.
• Patch type wall and patch name fixedWalls at three sides.
• Patch type wall and patch name movingWall at one side.
• Patch type empty and patch name frontAndBack patch at two sides.

• If you are interested in visualizing the actual block topology, you can use paraFoam
as follows,
• $> paraFoam –block
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• First of all, this file is automatically generated after you create the mesh
using blockMesh or snappyHexMesh, or when you convert the mesh from
a third-party format.
• In this file, the geometrical information related to the base type patch of
each boundary (or surface patch) of the domain is specified.
• The base type boundary condition is the actual surface patch where we are
going to apply a numerical type boundary condition (or numerical boundary
condition).
• The numerical type boundary condition assign a field value to the surface
patch (base type).
• We define the numerical type patch (or the value of the boundary
condition), in the directory 0 or time directories.
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• In this case, the file boundary is divided as follows

18 3 Number of surface patches


19 (
20 movingWall
In the list bellow there must be 3 patches
21 { definition.
22 type wall;
23 inGroups 1(wall); movingWall
24 nFaces 20;
25 startFace 760;
26 } frontAndBack
27 fixedWalls
28 {
29 type wall;
30 inGroups 1(wall);
31 nFaces 60;
32 startFace 780;
33 }

fixedWall
fixedWall
34 frontAndBack
35 {
36 type empty;
37 inGroups 1(empty);
38 nFaces 800;
39 startFace 840;
40 }
41 )
frontAndBack

fixedWall
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• In this case, the file boundary is divided as follows

18 3
19 ( Name and type of the surface patches
20 movingWall Name
21 {
22 type wall; Type • The name and type of the patch is given by
23 inGroups 1(wall);
24 nFaces 20; the user.
25 startFace 760;
26 } • In this case the name and type was assigned
27 fixedWalls in the dictionary blockMeshDict.
28 {
29 type wall; • You can change the name if you do not like it.
30 inGroups 1(wall);
31 nFaces 60; Do not use strange symbols or white spaces.
32 startFace 780;
33 } • You can also change the base type. For
34 frontAndBack instance, you can change the type of the
35 {
36 type empty;
patch movingWall from wall to patch.
37 inGroups 1(empty);
38 nFaces 800;
• When converting the mesh from a third party
39 startFace 840; format, OpenFOAM® will try to recover the
40 } information from the original format. But it
41 )
might happen that it does not recognizes the
base type and name of the original file. In this
case you will need to modify this file manually.
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• In this case, the file boundary is divided as follows

18 3 inGroups keyword
19 ( • This keyword is optional. You can erase this information safely.
20 movingWall
21 { • It is used to group patches during visualization in
22 type wall; ParaView/paraFoam. If you open this mesh in paraFoam you will
23 inGroups 1(wall); see that there are two groups, namely: wall and empty.
24 nFaces 20;
25 startFace 760; • As usual, you can change the name.
26 } • If you want to put a surface patch in two groups, you can proceed
27 fixedWalls
as follows:
28 {
29 type wall; 2(wall wall1)
30 inGroups 1(wall);
31 nFaces 60;
In this case the surface patch belongs to the groups wall and
32 startFace 780; wall1.
33 } • Groups can have more than one patch.
34 frontAndBack
35 {
36 type empty; nFaces and startFace keywords
37 inGroups 1(empty);
38 nFaces 800; • Unless you know what you are doing, you do not need to
39 startFace 840; modify this information.
40 }
41 ) • This information is related to the starting face and ending face of
the boundary patch in the mesh data structure.
• This information is created automatically when generating the
mesh or converting the mesh.
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary
• There are a few base type patches that are constrained or paired. This means that the type
should be the same in the boundary file and in the numerical boundary condition defined in the
field files, e.g., the files 0/U and 0/p.
• In this case, the base type of the patch frontAndBack (defined in the file boundary), is
consistent with the numerical type patch defined in the field files 0/U and 0/p. They are of
the type empty.
• Also, the base type of the patches movingWall and fixedWalls (defined in the file boundary),
is consistent with the numerical type patch defined in the field files 0/U and 0/p.
• This is extremely important, especially if you are converting meshes as not always the type of
the patches is set as you would like.
• Hence, it is highly advisable to do a sanity check and verify that the base type of the patches
(the type defined in the file boundary), is consistent with the numerical type of the patches
(the patch type defined in the field files contained in the directory 0 (or whatever time directory
you defined the boundary and initial conditions).
• If the base type and numerical type boundary conditions are not consistent, OpenFOAM® will
complain.
• Do not worry, we are going to address boundary conditions later on.
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• The following base type boundary conditions are constrained or paired.


That is, the type needs to be same in the boundary dictionary and field
variables dictionaries (e.g. U, p).

constant/polyMesh/boundary 0/U - 0/p (IC/BC)

symmetry symmetry
symmetryPlane symmetryPlane
empty empty
wedge wedge
cyclic cyclic
processor processor
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• The base type patch can be any of the numerical or derived type
boundary conditions available in OpenFOAM®. Mathematically speaking;
they can be Dirichlet, Neumann or Robin boundary conditions.

constant/polyMesh/boundary 0/U - 0/p (IC/BC)

fixedValue
zeroGradient
inletOutlet
slip
patch
totalPressure
supersonicFreeStream
and so on …
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• The wall base type boundary condition is defined as follows:

constant/polyMesh/boundary 0/U (IC/BC) 0/p (IC/BC)

type fixedValue;
wall zeroGradient
value uniform (U V W);

• This boundary condition is not contained in the patch base type boundary
condition group, because specialize modeling options can be used on this
boundary condition.
• An example is turbulence modeling, where turbulence can be generated or
dissipated at the walls.
A deeper view to my first OpenFOAM® case setup
The constant/polyMesh/boundary dictionary

• The name of the base type boundary condition and the name of the
numerical type boundary condition needs to be the same, if not,
OpenFOAM® will complain.
• Pay attention to this, specially if you are converting the mesh from another
format.

constant/polyMesh/boundary 0/U (IC/BC) 0/p (IC/BC)

movingWall movingWall movingWall


fixedWalls fixedWalls fixedWalls
frontAndBack frontAndBack frontAndBack

• As you can see, all the names are the same across all the dictionary files.
A deeper view to my first OpenFOAM® case setup
The system directory
(and by the way, open each file and go thru its content)

• The system directory consists of the following compulsory dictionary files:


• controlDict
• fvSchemes
• fvSolution
• controlDict contains general instructions on how to run the case.
• fvSchemes contains instructions for the discretization schemes that will be used for the
different terms in the equations.
• fvSolution contains instructions on how to solve each discretized linear equation system.
• Do not worry, we are going to study in details the most important entries of each dictionary (the
compulsory entries).
• If you forget a compulsory keyword or give a wrong entry to the keyword, OpenFOAM® will
complain and it will let you what are you missing. This applies for all the dictionaries in the
hierarchy of the case directory.
• There are many optional parameters, to know all of them refer to the doxygen documentation or
the source code. Hereafter we will try to introduce a few of them.
• OpenFOAM® will not complain if you are not using optional parameters, after all, they are
optional. However, if the entry you use for the optional parameter is wrong OpenFOAM® will let
you know.
A deeper view to my first OpenFOAM® case setup
The controlDict dictionary
• The controlDict dictionary contains runtime simulation controls, such
as, start time, end time, time step, saving frequency and so on.
17 application icoFoam; • Most of the entries are self-explanatory.
18
19 startFrom startTime; • This case starts from time 0 (keyword startFrom – line 19 – and
20
21 startTime 0; keyword startTime – line 21 –). If you have the initial solution in a
22 different time directory, just enter the number in line 21.
23 stopAt endTime;
24
25 endTime 50;
• The case will stop when it reaches the desired time set using the keyword
26 stopAt (line 23).
27 deltaT 0.01;
28 • It will run up to 50 seconds (keyword endTime – line 25 –).
29 writeControl runTime;
30
31 writeInterval 1; • The time step of the simulation is 0.01 seconds (keyword deltaT
32 – line 27 –).
33 purgeWrite 0;
34
35 writeFormat ascii;
• It will write the solution every second (keyword writeInterval – line 31 –)
36 of simulation time (keyword runTime – line 29 –).
37 writePrecision 8;
38 • It will keep all the solution directories (keyword purgeWrite – line 33 –).
39 writeCompression off;
40 If you want to keep only the last 5 solutions just change the value to 5.
41 timeFormat general;
42 • It will save the solution in ascii format (keyword writeFormat – line 35 –)
43 timePrecision 6;
44
with a precision of 8 digits (keyword writePrecision – line 37 –).
45 runTimeModifiable true;
• And as the option runTimeModifiable (line 45) is on (true), we can
modify all these entries while we are running the simulation.
• FYI, you can modify the entries on-the-fly for most of the dictionaries files.
A deeper view to my first OpenFOAM® case setup
The 0 directory
(and by the way, open each file and go thru its content)

• The 0 directory contains the initial and boundary conditions for all primitive variables,
in this case p and U. The U file contains the following information (velocity vector):

17 dimensions [0 1 -1 0 0 0 0]; Dimensions of the field


18
19 internalField uniform (0 0 0);
20
21 boundaryField
22 {
23 movingWall
24 { Uniform initial conditions.
25 type fixedValue;
26 value uniform (1 0 0); The velocity field is initialize to (0 0 0) in all
27 }
28
the domain
29 fixedWalls
Remember velocity is a vector with three
30 {
31 type fixedValue; components, therefore the notation (0 0 0).
32 value uniform (0 0 0);
33 }
34
35 frontAndBack Note:
If you take some time and compare the files 0/U and
36 {
constant/polyMesh/boundary, you will see that the name and type of each
37 type empty;
numerical type patch (the patch defined in 0/U), is consistent with the base
38 } type patch (the patch defined in the file constant/polyMesh/boundary).
39 }
A deeper view to my first OpenFOAM® case setup
The 0 directory
(and by the way, open each file and go thru its content)

• The 0 directory contains the initial and boundary conditions for all primitive variables,
in this case p and U. The U file contains the following information (velocity):

17 dimensions [0 1 -1 0 0 0 0]; Dimensions of the field


18
19 internalField uniform (0 0 0);
20
21 boundaryField
22 {
23 movingWall
24 {
25 type fixedValue; Numerical boundary condition for the patch
26 value uniform (1 0 0); movingWall
27 }
28
29 fixedWalls
30 {
31 type fixedValue; Numerical boundary condition for the patch
32 value uniform (0 0 0); fixedWalls
33 }
34
35 frontAndBack
36 {
37 type empty;
Numerical boundary condition for the patch
38 } frontAndBack (this is a constrained boundary
39 } condition).
A deeper view to my first OpenFOAM® case setup
The 0 directory
(and by the way, open each file and go thru its content)

• The 0 directory contains the initial and boundary conditions for all primitive variables,
in this case p and U. The p file contains the following information (modified pressure):

17 dimensions [0 2 -2 0 0 0 0]; Dimensions of the field


18
19 internalField uniform 0;
20
21 boundaryField
22 {
23 movingWall
24 { Uniform initial conditions.
25 type zeroGradient;
26 } The modified pressure field is initialize to 0
27
28 fixedWalls
in all the domain. This is relative
29 { pressure.
30 type zeroGradient;
31 }
32
33 frontAndBack
34 {
35 type empty; Note:
If you take some time and compare the files 0/p and
36 }
constant/polyMesh/boundary, you will see that the name and type of each
37 }
numerical type patch (the patch defined in 0/p), is consistent with the base
38 type patch (the patch defined in the file constant/polyMesh/boundary).
A deeper view to my first OpenFOAM® case setup
The 0 directory
(and by the way, open each file and go thru its content)

• The 0 directory contains the initial and boundary conditions for all primitive variables,
in this case p and U. The p file contains the following information (modified pressure):

17 dimensions [0 2 -2 0 0 0 0]; Dimensions of the field


18
19 internalField uniform 0;
20
21 boundaryField
22 {
23 movingWall
24 {
25 type zeroGradient;
Numerical boundary condition for the patch
26 } movingWall
27
28 fixedWalls
29 {
30 type zeroGradient;
Numerical boundary condition for the patch
31 } fixedWalls
32
33 frontAndBack
34 {
35 type empty;
Numerical boundary condition for the patch
36 } frontAndBack (this is a constrained boundary
37 } condition).
38
A deeper view to my first OpenFOAM® case setup

A very important remark on the pressure field

• We just used icoFoam which is an incompressible solver.


• Let us be really loud on this. All the incompressible solvers implemented in OpenFOAM®
(icoFoam, simpleFoam, pisoFoam, and pimpleFoam), use the modified pressure, that is,

with units

• Or in OpenFOAM® jargon: dimensions [0 2 -2 0 0 0 0]


• So when visualizing or post processing the results do not forget to multiply the pressure by
the density in order to get the right units of the physical pressure, that is,

• Or in OpenFOAM® jargon: dimensions [1 -1 -2 0 0 0 0]


A deeper view to my first OpenFOAM® case setup
• Coming back to the headers, and specifically the headers related to the field variable
dictionaries (e.g. U, p, gradU, and so on).
• In the header of the field variables, the class type should be consistent with the type
of field variable you are using.
• Be careful with this, specially if you are copying and pasting files.
• If the field variable is a scalar, the class should be volScalarField.

/*--------------------------------*- C++ -*----------------------------------*\


| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 6.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
A deeper view to my first OpenFOAM® case setup
• If the field variable is a vector, the class should be volVectorField.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 6.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}

• If the field variable is a tensor (e.g. the velocity gradient tensor), the class should be
volTensorField.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 6.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volTensorField;
object gradU;
}
A deeper view to my first OpenFOAM® case setup
The output screen
• Finally, let us talk about the output screen, which shows a lot of information.

Velocity residuals
Simulation time
Courant number
Pressure residuals
No orthogonal corrections
Only one PISO correction
Execution time (wall time)

Continuity errors

Additional information
End of the simulation Minimum and maximum values of each field
A deeper view to my first OpenFOAM® case setup
The output screen
• Another very important output information is the CFL or Courant number.
• The Courant number imposes the CFL number condition, which is the maximum allowable
CFL number a numerical scheme can use. For the n - dimensional case, the CFL number
condition becomes,

• In OpenFOAM®, most of the solvers are implicit, which means they are unconditionally
stable. In other words, they are not constrained to the CFL number condition.
• However, the fact that you are using a numerical method that is unconditionally stable, does
not mean that you can choose a time step of any size.
• The time-step must be chosen in such a way that it resolves the time-dependent features, and it
maintains the solver stability.
• For the moment and for the sake of simplicity, let us try to keep the CFL number below 5.0 and
preferably close to 1.0 (for good accuracy).
• Other properties of the numerical method that you should observe are: conservationess,
boundedness, transportiveness, and accuracy. We are going to address these properties and
the CFL number when we deal with the FVM theory.
A deeper view to my first OpenFOAM® case setup
The output screen
• To control the CFL number you can change the time step or you can change the mesh.
• The easiest way is by changing the time step.
• For a time step of 0.01 seconds, this is the output you should get for this case,

Time = 49.99
CFL number at
Courant Number mean: 0.044365026 max: 0.16800273
time step n - 1
smoothSolver: Solving for Ux, Initial residual = 1.1174405e-09, Final residual = 1.1174405e-09, No Iterations 0
smoothSolver: Solving for Uy, Initial residual = 1.4904251e-09, Final residual = 1.4904251e-09, No Iterations 0
DICPCG: Solving for p, Initial residual = 6.7291723e-07, Final residual = 6.7291723e-07, No Iterations 0
time step continuity errors : sum local = 2.5096865e-10, global = -1.7872395e-19, cumulative = 2.6884327e-18
ExecutionTime = 4.47 s ClockTime = 5 s

fieldMinMax minmaxdomain output:


min(p) = -0.37208362 at location (0.025 0.975 0.5)
max(p) = 0.77640927 at location (0.975 0.975 0.5)
min(U) = (0.00028445255 -0.00028138799 0) at location (0.025 0.025 0.5)
max(U) = (0.00028445255 -0.00028138799 0) at location (0.025 0.025 0.5)

Time = 50
CFL number at
Courant Number mean: 0.044365026 max: 0.16800273
smoothSolver: Solving for Ux, Initial residual = 1.0907508e-09, Final residual = 1.0907508e-09, No Iterations 0 time step n
smoothSolver: Solving for Uy, Initial residual = 1.4677462e-09, Final residual = 1.4677462e-09, No Iterations 0
DICPCG: Solving for p, Initial residual = 1.0020944e-06, Final residual = 1.0746895e-07, No Iterations 1
time step continuity errors : sum local = 4.0107145e-11, global = -5.0601748e-20, cumulative = 2.637831e-18
ExecutionTime = 4.47 s ClockTime = 5 s

fieldMinMax minmaxdomain output:


min(p) = -0.37208345 at location (0.025 0.975 0.5)
max(p) = 0.77640927 at location (0.975 0.975 0.5)
min(U) = (0.00028445255 -0.00028138799 0) at location (0.025 0.025 0.5)
max(U) = (0.00028445255 -0.00028138799 0) at location (0.025 0.025 0.5)
A deeper view to my first OpenFOAM® case setup
The output screen
• To control the CFL number you can change the time step or you can change the mesh.
• The easiest way is by changing the time step.
• For a time step of 0.1 seconds, this is the output you should get for this case,

Time = 49.9
CFL number at
Courant Number mean: 0.4441161 max: 1.6798756
time step n - 1
smoothSolver: Solving for Ux, Initial residual = 0.00016535808, Final residual = 2.7960145e-09, No Iterations 5
smoothSolver: Solving for Uy, Initial residual = 0.00015920267, Final residual = 2.7704949e-09, No Iterations 5
DICPCG: Solving for p, Initial residual = 0.0015842846, Final residual = 5.2788554e-07, No Iterations 26
time step continuity errors : sum local = 8.6128916e-09, global = 3.5439859e-19, cumulative = 2.4940081e-17
ExecutionTime = 0.81 s ClockTime = 1 s

fieldMinMax minmaxdomain output:


min(p) = -0.34322821 at location (0.025 0.975 0.5)
max(p) = 0.73453489 at location (0.975 0.975 0.5)
min(U) = (0.0002505779 -0.00025371425 0) at location (0.025 0.025 0.5)
max(U) = (0.0002505779 -0.00025371425 0) at location (0.025 0.025 0.5)

Time = 50
CFL number at
Courant Number mean: 0.44411473 max: 1.6798833
smoothSolver: Solving for Ux, Initial residual = 0.00016378098, Final residual = 2.7690608e-09, No Iterations 5 time step n
smoothSolver: Solving for Uy, Initial residual = 0.00015720331, Final residual = 2.7354499e-09, No Iterations 5
DICPCG: Solving for p, Initial residual = 0.0015662416, Final residual = 5.2290439e-07, No Iterations 26
time step continuity errors : sum local = 8.5379223e-09, global = -3.6676527e-19, cumulative = 2.4573316e-17
ExecutionTime = 0.81 s ClockTime = 1 s

fieldMinMax minmaxdomain output:


min(p) = -0.34244269 at location (0.025 0.975 0.5)
max(p) = 0.73656831 at location (0.975 0.975 0.5)
min(U) = (0.00025028679 -0.00025338014 0) at location (0.025 0.025 0.5)
max(U) = (0.00025028679 -0.00025338014 0) at location (0.025 0.025 0.5)
A deeper view to my first OpenFOAM® case setup
The output screen
• To control the CFL number you can change the time step or you can change the mesh.
• The easiest way is by changing the time step.
• For a time step of 0.5 seconds, this is the output you should get for this case,

Time = 2
CFL number at
Courant Number mean: 1.6828931 max: 5.6061178
time step n - 1
smoothSolver: Solving for Ux, Initial residual = 0.96587058, Final residual = 4.9900041e-09, No Iterations 27
smoothSolver: Solving for Uy, Initial residual = 0.88080685, Final residual = 9.7837781e-09, No Iterations 25
DICPCG: Solving for p, Initial residual = 0.95568243, Final residual = 7.9266324e-07, No Iterations 33
time step continuity errors : sum local = 6.3955627e-06, global = 1.3227253e-17, cumulative = 1.4125109e-17
ExecutionTime = 0.04 s ClockTime = 0 s

fieldMinMax minmaxdomain output:


min(p) = -83.486425 at location (0.975 0.875 0.5)
max(p) = 33.078468 at location (0.025 0.925 0.5)
min(U) = (0.1309243 -0.13648118 0) at location (0.025 0.025 0.5)
max(U) = (0.1309243 -0.13648118 0) at location (0.025 0.025 0.5)

Time = 2.5

Courant Number mean: 8.838997 max: 43.078153


CFL number at
#0 Foam::error::printStack(Foam::Ostream&) at ??:? time step n (way
#1 Foam::sigFpe::sigHandler(int) at ??:? too high)
#2 ? in "/lib64/libc.so.6"
#3 Foam::symGaussSeidelSmoother::smooth(Foam::word const&, Foam::Field<double>&, Foam::lduMatrix const&, Foam::Field<double> const&,
Foam::FieldField<Foam::Field, double> const&, Foam::UPtrList<Foam::lduInterfaceField const> const&, unsigned char, int) at ??:?
#4 Foam::symGaussSeidelSmoother::smooth(Foam::Field<double>&, Foam::Field<double> const&, unsigned char, int) const at ??:?
#5 Foam::smoothSolver::solve(Foam::Field<double>&, Foam::Field<double> const&, unsigned char) const at ??:?
#6 ? at ??:?

The solver crashed.


The offender? Time step too large.
A deeper view to my first OpenFOAM® case setup
The output screen
• Another output you should monitor are the continuity errors.
• These numbers should be small (it does not matter if they are negative or positive).
• If these values increase in time (about the order of 1e-2), you better control the case setup because
something is wrong.
• The continuity errors are defined in the following file
$WM_PROJECT_DIR/src/finiteVolume/cfdTools/incompressible/continuityErrs.H

Time = 50

Courant Number mean: 0.44411473 max: 1.6798833


smoothSolver: Solving for Ux, Initial residual = 0.00016378098, Final residual = 2.7690608e-09, No Iterations 5
smoothSolver: Solving for Uy, Initial residual = 0.00015720331, Final residual = 2.7354499e-09, No Iterations 5
DICPCG: Solving for p, Initial residual = 0.0015662416, Final residual = 5.2290439e-07, No Iterations 26
time step continuity errors : sum local = 8.5379223e-09, global = -3.6676527e-19, cumulative = 2.4573316e-17
ExecutionTime = 0.81 s ClockTime = 1 s

fieldMinMax minmaxdomain output:


min(p) = -0.34244269 at location (0.025 0.975 0.5)
max(p) = 0.73656831 at location (0.975 0.975 0.5)
min(U) = (0.00025028679 -0.00025338014 0) at location (0.025 0.025 0.5)
max(U) = (0.00025028679 -0.00025338014 0) at location (0.025 0.025 0.5) Continuity errors
A deeper view to my first OpenFOAM® case setup
Dictionary files general features

• OpenFOAM® follows same general syntax rules as in C++.


• Commenting in OpenFOAM® (same as in C++):

/*
// This is a line comment This is a block comment
*/

• As in C++, you can use the #include directive in your dictionaries (do not forget to create the respective include file):
#include “ n t C nd t n ”

• Scalars, vectors, lists and dictionaries.


• Scalars in OpenFOAM® are represented by a single value, e.g.,
3.14159
• Vectors in OpenFOAM® are represented as a list with three components, e.g.,
(1.0 0.0 0.0)
• A second order tensor in OpenFOAM® is represented as a list with nine components, e.g.,
(
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
)
A deeper view to my first OpenFOAM® case setup
Dictionary files general features

• Scalars, vectors, lists and dictionaries.


• List entries are contained within parentheses ( ). A list can contain scalars, vectors, tensors, words, and so on.
• A list of scalars is represented as follows:
name_of_the_list
(
0
1
2
);

• A list of vectors is represented as follows:


name_of_the_list
(
(0 0 0)
(1 0 0)
(2 0 0)
);

• A list of words is represented as follows


name_of_the_list
(
“ rd1”
“ rd2”
“ rd3”
);
A deeper view to my first OpenFOAM® case setup
Dictionary files general features
• OpenFOAM® uses dictionaries to specify data in an input file (dictionary file).
• A dictionary in OpenFOAM® can contain multiple data entries and at the same time dictionaries can contain
sub-dictionaries.
• To specify a dictionary entry, the name is followed by the keyword entries in curly braces:

solvers Dictionary solvers


{
p Sub-dictionary p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0;
}

U Sub-dictionary U
{
solver PBiCGStab;
preconditioner DILU;
tolerance 1e-06;
relTol 0;
}



}
A deeper view to my first OpenFOAM® case setup
Dictionary files general features

• Macro expansion.
• We first declare a variable (x = 10) and then we use it through the $ macro substitution ($x).

vectorField (20 0 0); //Declare variable

internalField uniform $vectorField; //Use declared variable

scalarField 101328; //Declare variable

type fixedValue;
value uniform $scalarField; //Use declared variable

• You can use macro expansion to duplicate and access variables in dictionaries

p // Declare/create the dictionary p


{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0;
}

$p; //To create a copy of the dictionary p


$p.solver; //To access the variable solver in the dictionary p
A deeper view to my first OpenFOAM® case setup
Dictionary files general features

• In tead of writing t e poor an’ way :

leftWall rightWall topWall


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

• You can write (the lazy way):

“( eft|r ght|t )W ”
{
type fixedValue;
value uniform (0 0 0);
}

• You could also try (even lazier):

“.*W ”
{
type fixedValue;
value uniform (0 0 0);
}

• OpenFOAM® understands the syntax of regular expressions (regex or regeaxp).


A deeper view to my first OpenFOAM® case setup
Dictionary files general features

• Inline calculations.
• You can use the directive #calc to do inline calculations, the syntax is as follows:
X = 10.0; //Declare variable
Y = 3.0; //Declare variable

Z #c c “$ *$ – 12.0”; //Do inline calculation. The result is saved in the variable Z

• With inline calculations you can access all the mathematical functions available in C++.
• Macro expansions and inline calculations are very useful to parametrize dictionaries and avoid repetitive tasks.
• Switches: they are used to enable or disable a function or a feature in the dictionaries.
• Switches are logical values. You can use the following values:

Switches
false true
off on
no yes
n y
f t
none true

• You can find all the valid switches in the following file:
OpenFOAM-6/src/OpenFOAM/primitives/bools/Switch/Switch.C
A deeper view to my first OpenFOAM® case setup
Solvers and utilities help

• If you need help about a solver or utility, you can use the option –help. For
instance:

• $> icoFoam –help

will print some basic help and usage information about icoFoam

• Remember, you have the source code there so you can always
check the original source.

You might also like