Supplement Postprocessing Sampling
Supplement Postprocessing Sampling
Supplement Postprocessing Sampling
More on sampling
1
Sampling on point clouds, lines
and surfaces
2
Supplement – More on sampling
• OpenFOAM® provides the postProcess utility to sample field data for plotting.
• The sampling locations are specified in the dictionary sampleDict located in the case
system directory.
• You can give any name to the input dictionary, hereafter we are going to name it sampleDict.
• During the sampling, inside the case directory, a new directory named postProcessing will
be created. In this directory, the sampled values are stored.
• This utility can sample points, lines, and surfaces.
• Data can be written in many formats, including well-known plotting packages such as:
grace/xmgr, gnuplot and jPlot.
• The sampling can be executed by running the utility postProcess in the case directory and
according to the application syntax.
• A final word, this utility does not do the sampling while the solver is running. It does the
sampling after you finish the simulation.
3
Supplement – More on sampling
$PTOFC/advanced_postprocessing/pipe/
• In the case directory, you will find the README.FIRST file. In this file, you will find the general instructions of
how to run the case. In this file, you might also find some additional comments.
• You will also find a few additional files (or scripts) with the extension .sh, namely, run_all.sh,
run_mesh.sh, run_sampling.sh, run_solver.sh, and so on. These files can be used to run the case
automatically by typing in the terminal, for example, sh run_solver.
• We highly recommend to open the README.FIRST file and type the commands in the terminal, in this way
you will get used with the command line interface and OpenFOAM® commands.
• If you are already comfortable with OpenFOAM®, use the automatic scripts to run the cases.
4
Supplement – More on sampling
Laminar flow in a straight pipe – Re = 600
6
Supplement – More on sampling
Laminar flow in a straight pipe – Re = 600
7
Supplement – More on sampling
Laminar flow in a straight pipe – Re = 600
8
Supplement – More on sampling
Laminar flow in a straight pipe – Re = 600
9
Supplement – More on sampling
What are we going to do?
• We will simulate a laminar flow in a straight pipe (Re = 600).
• We will use this case to introduce the sampling utility postProcess.
• We will introduce the utility topoSet used to do topological modifications on the mesh.
• We will use this utility to run functionObjects a-posteriori.
• We will compare the numerical solution with the analytical solution.
• To find the numerical solution we will use the solver pisoFoam.
• After finding the numerical solution we will do some sampling.
• At the end, we will do some plotting (using gnuplot or Python) and scientific visualization.
10
Supplement – More on sampling
Running the case
• Let us run the simulation and do some sampling. In the terminal type:
1. $> foamCleanTutorials
2. $> blockMesh
3. $> checkMesh
4. $> topoSet
5. $> pisoFoam | tee log.solver
6. $> postProcess -func sampleDict1 -latestTime
7. $> postProcess -func sampleDict2 -latestTime
8. $> gnuplot gnuplot/gnuplot_script
9. $> paraFoam
• Do not erase the solution, we are going to use it in the next sections.
11
Supplement – More on sampling
Running the case
• In step 4 we use the utility topoSet to do mesh topological manipulation. This utility will read
the dictionary topoSetDict located in the system directory. Later on, we will talk about what
are we doing in this step.
• In step 5 we run the simulation and save the log file.
• In step 6 we use the postProcess utility. By using the option –func we specify to do the
sampling according to the dictionary system/sampleDict1. We sample the latest saved
solution.
• In step 7 we use the postProcess utility. By using the option –func we specify to do the
sampling according to the read dictionary system/sampleDict2. We sample the latest saved
solution.
• In step 8 we use the gnuplot script gnuplot/gnuplot_script to plot the sampled fields.
Feel free to take a look at the script and to reuse it.
• Finally, in step 9 we visualize the solution.
12
Supplement – More on sampling
The sampleDict dictionary
• Let us visit the sampleDict dictionaries.
• This dictionary is located in the directory system.
• The sampleDict file contains several entries to be set according to the user needs.
• You can set the following entries,
• The choice of the interpolationScheme.
• The format of the line data output.
• The format of the surface data output.
• The fields to be sample.
• The sub-dictionaries that controls each sampling operation.
• In these sub-dictionaries you can set the name, type and geometrical information of
the sampling operation.
• In this case, in the dictionary sampleDict1 we are sampling points and lines, and in the
dictionary sampleDict2 we are sampling surfaces.
13
Supplement – More on sampling
The sampleDict1 dictionary
17 type sets; Sample sets (points and lines).
Format of the output file, raw format is a generic format that can be
19 setFormat raw;
read by many applications. The file is human readable (ascii
format).
30 sets
31 (
33 s1 Name of the output file
34 {
35 type lineCellFace; Sample method from the solution to the line.
40 axis z;
41 start (0 0 0); Location of the sample line. We define start and end point, and the
42 end (0 0 0.22);
43 }
axis of the sampling.
44
45 s2 Name of the output file
46 {
47 type lineCellFace; Sample method from the solution to the line.
49 axis x;
50 start (-0.002 -0.002 0.2);
51 end ( 0.002 0.002 0.2);
Location of the sample line. We define start and end point, and the
52 } axis of the sampling.
53
Note:
Use the banana method to know all the options
available. 14
Supplement – More on sampling
The sampleDict1 dictionary
54
55 somePoints Name of the output file
56 {
57 type points; Sample a cloud of points
58 ordered true;
59 axis xyz;
57
58 surf3 Name of the object and output file
59 {
60 type triSurfaceMesh; Surface sampling method. In this case we are using a STL
61 surface surface2.stl;
62 source cells; file, the file is always located in the directory
63 constant/triSurface.
64 interpolate true;
65 }
66
67 surf4 Name of the object and output file
68 {
69 type triSurfaceMesh; Surface sampling method. In this case we are using a STL
70 surface surface3.stl;
71 source insideCells; file, the file is always located in the directory
72 constant/triSurface.
73 interpolate false;
74 }
75 ); The sampled information is always saved in the directory
postProcessing/sampleDict2
As we are sampling the latest solution (0.1), the sampled data
will be located in the directory:
postProcessing/sampleDict2/0.1
The files p_surf1.raw, p_surf2.raw, p_surf3.raw,
p_surf4.raw, U_surf1.raw, U_surf2.raw,
U_surf3.raw, and U_surf4.raw, located in the directory
postProcessing/sampleDict2/0.1 contain the sampled
data. Feel free to open the output files using your favorite text
editor.
17
Supplement – More on sampling
The output files
• The output format of the point sampling (cloud) is as follows:
Scalars
#POINT_COORDINATES (X Y Z) SCALAR_VALUE
0 0 0.05 13.310995
0 0 0.1 19.293817
…
Vectors
#POINT_COORDINATES (X Y Z) VECTOR_COMPONENTS (X Y Z)
0 0 0.05 0 0 2.807395
0 0 0.1 0 0 2.826176
…
18
Supplement – More on sampling
The output files
• The output format of the line sampling is as follows:
Scalars
#AXIS_COORDINATE SCALAR_VALUE
0 18.594038
0.0015 18.249091
…
Vectors
#AXIS_COORDINATE VECTOR_COMPONENTS (X Y Z)
0 0 0 1.6152966
0.0015 0 0 1.8067536
…
19
Supplement – More on sampling
The output files
• The output format of the surface sampling is as follows:
Scalars
#POINT_COORDINATES (X Y Z) SCALAR_VALUE
0 0 0.05 13.310995
0 0 0.1 19.293817
…
Vectors
#POINT_COORDINATES (X Y Z) VECTOR_COMPONENTS (X Y Z)
0 0 0.05 0 0 2.807395
0 0 0.1 0 0 2.826176
…
20
Supplement – More on sampling
• To plot the sampled data using gnuplot we can proceed as follows:
21
Supplement – More on sampling
• To plot the sampled data using gnuplot we can proceed as follows:
1. gnuplot> set title 'Velocity profile at plane located at z = 0.1 - Time 0.1 s'
22
Supplement – More on sampling
Creating faceSet and zoneSet
• To create sets and zones we use the utility topoSet.
• This utility reads the dictionary topoSetDict located in the system directory.
• faceSet/cellSet and faceZone/cellZone can be used to do modifications to the mesh or to
apply source terms.
• We can only do sampling operations on zoneSets made of a set of faces and/or cells,
therefore, if we have a faceSet/cellSet we need to convert it to a faceZone/cellZone.
• Creating an internal faceZone is particularly important if we are interested in computing the
mass flow in an internal surface, as sampledSurface does not work with surfaceScalarFields;
therefore, we need to use a faceZone.
• Alternatively, we can compute the mass flow in paraFoam/paraView or we can use the
areaNormaIntegrate operation on the sampleSurface.
• Let us create an internal faceZone and a cellZone and let us compute the mass flow and do
some sampling on these sets.
23
Supplement – More on sampling
The topoSetDict dictionary
17 actions
18 (
19
20 { • In this step we are creating a new faceSet from a boxToFace
21 action new; source.
22 name internalfaces;
23 type faceSet; • The name of the new faceSet is internalFaces.
24 • The box source encloses the faces we want to tag.
25 source boxToFace;
26 sourceInfo
• We can visualize this set in paraFoam.
27 { • Remember, we can not sample on a faceSet, we need to
28 box (-1 -1 0.098) (1 1 0.1); convert it to a faceZone.
29 }
30 }
31
32 {
33 action new;
34 name internalfacepatch;
35 type faceZoneSet; • In this step we convert the faceSet internalFaces, to a
36 faceZone.
37 source setToFaceZone;
38 sourceInfo
• The name of new faceZone is internalfacepatch.
39 { • At this point, we can use this faceZone to do sampling.
40 faceSet internalfaces; • We can visualize this zone in paraFoam.
41 }
42 }
43
Note:
Use the banana method to know all the options
available.
24
Supplement – More on sampling
The topoSetDict dictionary
44 {
45 action new; • In this step we are creating a new cellSet from a boxToCell
46 name internalcells; source.
47 type cellSet;
48 • The name of the new cellSet is internalCells.
49 source boxToCell; • The box source encloses the cells we want to tag.
50 sourceInfo
51 {
• We can visualize this set in paraFoam.
52 box (-1 -1 0.096) (1 1 0.1); • Remember, we can not sample on a cellSet, we need to
53 } convert it to a cellZone.
54 }
55
56 {
57 action new;
58 name internalcells;
59 type cellZoneSet;
60 • In this step we convert the cellSet internalcells, to a cellZone.
61 source setToCellZone;
62 sourceInfo • The name of new cellZone is internalcells.
63 { • At this point, we can use this cellZone to do sampling.
64 set internalcells;
65 }
• We can visualize this set in paraFoam.
66 }
67
68 );
Note:
Use the banana method to know all the options
available.
25
Supplement – More on sampling
• Let us create an internal faceZone and a cellZone and let us compute the mass flow and do
some sampling on these sets.
1. $> topoSet
2. $> pisoFoam -postProcess -dict system/functionobject3 –latestTime
• In step 1 we use the utility topoSet to create the new faceZone and cellZone.
• In step 2 we run a functionObject a-posteriori. In this functionObject we compute:
• Mass flow in a sampledSurface.
• Mass flow in a faceZone.
• In step 3 we run a functionObject a-posteriori. In this functionObject we compute:
• Volume integral in a cellZone.
26
Supplement – More on sampling
Visualizing the newly created sets and zones
faceZone - In red
28
Supplement – More on sampling
The functionobject3 dictionary
64 surface2_massflow
65 {
66 type surfaceRegion;
67 functionObjectLibs ("libfieldFunctionObjects.so");
68 enabled true;
69
70 writeControl timeStep;
71 writeInterval 1;
72
73 log true;
74 writeFields false;
75
76 regionType faceZone;
77 name internalfacepatch;
78
79 operation sum;
80 fields
81 (
82 phi
83 );
84
85 }
29
Supplement – More on sampling
The functionobject3 dictionary
90 surface3_massflow
91 {
92 type surfaceRegion;
93 functionObjectLibs ("libfieldFunctionObjects.so");
94 enabled true;
95
96 writeControl timeStep;
97 writeInterval 1;
98
99 log true;
100 writeFields false;
101
102 regionType sampledSurface;
103 name dummy;
104
105 sampledSurfaceDict
106 {
107 type sampledTriSurfaceMesh;
108 surface surface2.stl;
109 source cells;
110 interpolate true;
In this case we are using a finer surface therefore we
111 } enable the option interpolate.
112
113 operation areaNormalIntegrate;
114 fields
115
116
(
U
Compute mass flow using areaNormalIntegrate
117 ); operation with the field U.
118
119 }
30
Supplement – More on sampling
The functionobject3 dictionary
123 surface4_massflow
124 {
125 type surfaceRegion;
126 functionObjectLibs ("libfieldFunctionObjects.so");
127 enabled true;
128
129 writeControl timeStep;
130 writeInterval 1;
131
132 log true;
133 writeFields false;
134
135 regionType sampledSurface;
136 name dummy;
137
138 sampledSurfaceDict
139 {
140 type sampledTriSurfaceMesh;
141 surface surface3.stl;
142 source insideCells;
143 interpolate true;
144 }
145
146 operation areaNormalIntegrate;
147 fields
148 (
149 U Compute mass flow using areaNormalIntegrate
150
151
);
operation with the field U.
152 }
31
Supplement – More on sampling
The functionobject3 dictionary
156 plane1_massflow
157 {
158 type surfaceRegion;
159 functionObjectLibs ("libfieldFunctionObjects.so");
160 enabled true;
161
163 writeControl timeStep;
164 writeInterval 1;
165
166 log true;
167 writeFields false;
168
169 regionType sampledSurface;
170 name dummy;
171
172 sampledSurfaceDict
173 {
174 type plane;
175
176
planeType pointAndNormal;
pointAndNormalDict
We sample in a plane.
177 {
178 basePoint (0 0 0.1);
179 normalVector (0 0 1);
180 }
181 }
182
184 operation areaNormalIntegrate; Compute mass flow using areaNormalIntegrate
185
186
fields
(
operation with the field U.
187 //phi
188 U
189 );
190 }
191
193 }
32
Supplement – More on sampling
The functionobject4 dictionary
17 functions
18 {
19
22 cells_fo1
23 {
24 type volRegion;
25 functionObjectLibs ("libfieldFunctionObjects.so");
26 enabled true;
27
28 writeControl timeStep;
29 writeInterval 1;
30
31 log true;
32
33 writeFields false;
34
35 regionType cellZone;
36 name internalcells;
37
38 operation volIntegrate;
39
40 fields
41 (
42 U Compute volIntegrate of the field U.
43 );
44
45 }
97
98 }
99
33
Supplement – More on sampling
Exercises
• Where is located the source code of the utility postProcess?
• Try to do the sampling in parallel? Does it run? What about the output file? Is it the same?
• How many options are there available to do sampling in a line?
• How many options are there available to do sampling in a surface?
• Compute the mass flow at the inlet and outlet patches using the operation sum and areaNormalIntegrate. Do
you get the same output?
• Compute the mass flow at the inlet and outlet patches using paraFoam/ParaView and compare with the output
of the postProcess utility. Do you get the same results?
• Do point, line, and surface sampling using paraFoam/ParaView and compare with the output of the
postProcess utility. Do you get the same results?
34
Sampling on points (probing)
35
Supplement – More on sampling
• OpenFOAM® provides the postProcess utility to probe field data for plotting.
• The probing locations are specified in the dictionary probesDict located in the case system
directory.
• You can give any name to the input dictionary, hereafter we are going to name it probesDict.
• During the probing, inside the case directory a new directory named postProcessing, will be
created. In this directory, the sampled values are stored.
• This utility can sample only points.
• Data can be written in many formats, including well-known plotting packages such as:
grace/xmgr, gnuplot and jPlot.
• The probing can be executed by running the utility postProcess in the case directory and
according to the application syntax.
• A final word, this utility does not do the sampling while the solver is running. It does the
sampling after you finish the simulation.
36
Supplement – More on sampling
Laminar flow in a straight pipe – Re = 600
Probes location
37
Supplement – More on sampling
• We hope you did not erase the previous solution because we will use it to play around with the
probeLocations. In the terminal type:
• This will probe all the saved solutions at the specified locations. It will save time vs. quantity of
interest.
• The sampled information is always saved in the directory (same name as the input file),
• postProcessing/probesDict
• As we started to sample from time 0, the sample data is saved in the directory
• postProcessing/probesDict/0
38
Supplement – More on sampling
The probesDict dictionary
17 type probes;
18
20 fields
21 (
22 p
23 U Fields to sample. The output files will have the name of the fields.
24 );
25
27 probeLocations
28 (
29 (0 0 0.025)
30 (0 0 0.050)
31 (0 0 0.075)
32 (0 0 0.10) Probe locations.
33 (0 0 0.125)
34 (0 0 0.150)
35 (0 0 0.175)
36 (0 0 0.20)
37 );
39
Supplement – More on sampling
The output files
• The output format of the probing is as follows:
Scalars
# Probe 0 (0 0 0.025)
# Probe 1 (0 0 0.05)
# Probe 2 (0 0 0.075)
# Probe 3 (0 0 0.1)
# Probe 0 1 2 3
# Time
0 0 0 0 0
0.005 19.1928 16.9497 14.2011 11.7580
0.01 16.6152 14.5294 12.1733 10.0789
…
…
…
40
Supplement – More on sampling
The output files
• The output format of the probing is as follows:
Vectors
# Probe 0 (0 0 0.025)
# Probe 1 (0 0 0.05)
# Probe 2 (0 0 0.075)
# Probe 3 (0 0 0.1)
# Probe 0 1 2 3
# Time
0 (0 0 0) (0 0 0) (0 0 0) (0 0 0)
0.005 (0 0 2.1927) (0 0 2.1927) (0 0 2.1927) (0 0 2.1927)
0.01 (0 0 2.5334) (0 0 2.5334) (0 0 2.5334) (0 0 2.5334)
…
…
…
41
Supplement – More on sampling
Exercises
• Try to do the sampling in parallel? Does it run? What about the output file? Is it the same?
• Do the same sampling using paraFoam/paraview and compare with the output of the postProcess utility. Do
you get the same results?
• Compute the descriptive statistics of each column of the output files using gnuplot. Be careful with the
parentheses of the vector files.
(Hint: you can use sed within gnuplot)
42
On-the-fly postprocessing
functionObjects and the
postProcess utility
43
Supplement – More on sampling
• It is possible to perform data extraction/manipulation operations while the simulation is running
by using the functionObjects.
• functionObjects are small pieces of code executed at a regular interval without explicitly being
linked to the application.
• When using functionObjects, files of sampled data can be written for plotting and post
processing.
• functionObjects are specified in the controlDict dictionary and executed every time step or
pre-defined intervals.
• All functionObjects are runtime modifiable.
• All the information related to the functionObject is saved in the directory postProcessing or in
the solution directory.
• It is also possible to execute functionObject after simulation is over, we will call this running
functionObject a-posteriori.
44
Supplement – More on sampling
$PTOFC/advanced_postprocessing/pipe
• In the case directory, you will find the README.FIRST file. In this file, you will find the general instructions of
how to run the case. In this file, you might also find some additional comments.
• You will also find a few additional files (or scripts) with the extension .sh, namely, run_all.sh,
run_mesh.sh, run_sampling.sh, run_solver.sh, and so on. These files can be used to run the case
automatically by typing in the terminal, for example, sh run_solver.
• We highly recommend to open the README.FIRST file and type the commands in the terminal, in this way
you will get used with the command line interface and OpenFOAM® commands.
• If you are already comfortable with OpenFOAM®, use the automatic scripts to run the cases.
45
Supplement – More on sampling
46
Supplement – More on sampling
What are we going to do?
47
Supplement – More on sampling
Running the case
• Let us run the simulation. In the terminal type:
1. $> foamCleanTutorials
2. $> blockMesh
3. $> checkMesh
4. $> topoSet
5. $> pisoFoam | tee log.solver
7. $> paraFoam
• In step 4 we use the utility topoSet to do mesh topological manipulation. This utility will read
the dictionary topoSetDict located in the system directory. Later on, we will talk about what
are we doing in this step.
• In step 5 we run the simulation and save the log file. In step 6 we use
pyFoamPlotWatcher.py to plot the residuals on-the-fly. As the job is running in background,
we can launch this utility in the same terminal tab.
• Finally, in step 7 we visualize the solution.
48
Supplement – More on sampling
• Let us explore the case directory.
• You will notice that we now have a new directory named postProcessing.
• Inside this directory, you will find many subdirectories pointing to the functionObject used.
• By the way, we are saving a large amount of information.
• This is typical of unsteady simulations, and sometimes it can be too daunting to post-process
and analyze the data.
• To ease the pain of doing data analytics and post-processing, you can use shell scripting or
Python scripting.
• Hereafter, we are going to address how to use shell scripting.
49
Supplement – More on sampling
• Inside the directory postProcessing, you will find the following sub-directories:
• cells_fo1 • pressureDrop
• cells_fo2 • pressureDrop.region1
• field_fo4 • pressureDrop.region2
• field_fo4.region1 • probesDict
• field_fo4.region2 • probes_fo1
• forces_object • probes_online
• inlet_average • sampleDict1
• inlet_massflow • sampleDict2
• inlet_massflow_posteriori • sets_fo2
• innerpatch_massflow • sets_online
• minmaxdomain • surface1_massflow
• outlet_areaNormalIntegrate • surface2_massflow
• outlet_massflow • surface3_massflow
• outlet_massflow_posteriori • surface4_massflow
• outlet_max • surfaces_fo3
• plane1_massflow
• Inside each sub-directory you will find the time directory 0, this is the time directory from which
we started to sample using functionObject. Inside this directory you will find the sampled
data.
• If you start to sample from time 50, you will find the time directory 50.
• If you stop the simulation and restart it, let us say from time 10, you will find the time directories
0 and 10.
• For line and surface sampling, you will find all the time directories corresponding to the saving
frequency. Inside each directory you will find the sampled data.
• Let us take a look at the general organization of a functionObject.
50
Supplement – More on sampling
• The functionObject entry in the controlDict dictionary, contains at least
the following information:
writeControl outputTime;
timeStart 0; Output frequency
timeEnd 20;
51
Supplement – More on sampling
• There are many functionObjects implemented in OpenFOAM®, and sometimes is not very
straightforward how to use a specific functionObject.
• Also, functionObjects can have many options and some limitations.
• Our best advice is to read the doxygen documentation or the source code to learn how to use
functionObjects.
• The source code of the functionObjects is located in the directory:
$WM_PROJECT_DIR/src/postProcessing/functionObjects
52
Supplement – More on sampling
The controlDict dictionary
53
Supplement – More on sampling
The controlDict dictionary
Note:
Use the banana method to know all the options available
for each entry.
54
Supplement – More on sampling
The controlDict dictionary
Note:
Use the banana method to know all the options available
for each entry.
55
Supplement – More on sampling
The functionObject0 dictionary
Note:
Use the banana method to know all the options available
for each entry.
56
Supplement – More on sampling
The functionObject0 dictionary
Note:
Use the banana method to know all the options available
for each entry.
57
Supplement – More on sampling
The functionObject0 dictionary
Note:
Use the banana method to know all the options available
for each entry.
58
Supplement – More on sampling
The functionObject0 dictionary
131 pressureDrop
132 { • fieldValueDelta functionObject
133 type fieldValueDelta;
134 functionObjectLibs ("libfieldFunctionObjects.so"); • This functionObject is used to compute the
135 enabled true;
136 difference/average/min/max of two field values.
137 region1
138 { • We are using the operation sum with the field phi.
139 writeFields off;
140 type surfaceRegion; This is equivalent to compute the mass flow.
141 regionType patch;
142 name inlet; • We are using the operation subtract between the
143
144 operation sum; two field values.
145
146 fields • The output of this functionObject is saved in
147 (
148 phi ascii format in the file fieldValueDelta.dat
149
150 }
);
located in the directory
151
152 region2 postProcessing/pressureDrop/0
153 {
154 writeFields off;
155 type surfaceRegion;
156 regionType patch;
157 name outlet; • Remember, the name of the directory where the output
158
159 operation sum;
data is saved is the same as the name of the
160 functionObject (line 131).
161 fields
162 (
163 phi
164 );
165 } Note:
166 Use the banana method to know all the options available
167 operation subtract;
168 } for each entry.
59
Supplement – More on sampling
The functionObject0 dictionary
Note:
Use the banana method to know all the options available
for each entry.
60
Supplement – More on sampling
The functionObject0 dictionary
Note:
Use the banana method to know all the options available
for each entry.
61
Supplement – More on sampling
The functionObject0 dictionary
Note:
Use the banana method to know all the options available
for each entry.
62
Supplement – More on sampling
Running functionObjects a-posteriori
• Sometimes, it can happen that you forget to use a functionObject or you want to execute a
functionObject a-posteriori (when the simulation is over).
• The solution to this problem is to use the solver with the option -postProcess.
• This will only compute the functionObject, it will not rerun the simulation.
• For instance, let us say that you forgot to use a given functionObject.
• Open the dictionary controlDict, add the new functionObject, and type in the terminal,
• By proceeding in this way you do not need to rerun the simulation, you just compute the new
functionObject.
63
Supplement – More on sampling
• In the directory system, you will find the following functionObjects dictionaries:
functionObject1 , functionObject2 , functionObject3 , functionObject4,
functionObject5 , functionObject6.
• Try to figure out what we are doing in every functionObject dictionary.
• At this point, let us run each the functionObject a-posteriori. In the terminal type:
64
Supplement – More on sampling
• In this step 1, we are reading the dictionary functionObject1 located in the directory
system (the dictionary file can be located anywhere), and we are doing the computation for all
the saved solutions. Notice that we are redirecting the output to a log file ( | tee log_fo1).
• In this step 2, we are reading the dictionary functionObject2 and we are doing the
computation for all saved solutions.
• In this step 3, we are reading the dictionary functionObject3 and we are doing the
computation for the time range 0.05 to 0.1 (–time 0.05:0.1).
• In this step 4, we are reading the dictionary functionObject4 and we are doing the
computation for all the saved solutions, except time zero (–noZero).
• In this step 5, we are reading the dictionary functionObject5 and we are doing the
computation only for he latest save solution (–latestTime).
• In this step 6, we are reading the dictionary functionObject6 and we are doing the
computation only for he latest save solution (–latestTime).
65
Supplement – More on sampling
Some shell and awk scripting
• Let us do some shell and awk scripting on the sampled data.
• Let us go to the directory postprocesssing/minmaxdomain/0
• To erase the parentheses in the file fieldMinMax.dat and save the output in the file
out.txt, type in the terminal:
• $> cat fieldMinMax.dat | tr -d "()" > out.txt
• To extract the velocity from the file out.txt, and save the output in the file vel_minmax.txt,
type in the terminal:
• $> awk '0 == NR % 2' out.txt > vel_minmax.txt
• To extract the pressure from the file out.txt, and save the output in the file
pre_minmax.txt, type in the terminal:
• $> awk '1 == NR % 2' out.txt > pre_minmax.txt
66
Supplement – More on sampling
Some shell and awk scripting
• To erase the header of the file pre_minmax.txt, type in the terminal:
• $> awk '{if (NR!=1) {print}}' pre_minmax.txt > tmp
• $> mv tmp pre_minmax.txt
• To erase the header of the file vel_minmax.txt, type in the terminal:
• $> awk '{if (NR!=1) {print}}' vel_minmax.txt > tmp
• $> mv tmp vel_minmax.txt
• To compute the mean value of the seventh column of the file pre_minmax.txt (maximum
pressure in this case), type in the terminal:
• $> awk 'NR>=50 && NR { total += $7; count++} END { print
“Mean_value ” total/count}' pre_minmax.txt
We are computing the mean value of column 7 starting from row 50
• To compute the mean value of the seventh column of the file vel_minmax.txt (minimum Z
velocity component in this case), type in the terminal:
• $> awk 'NR>=50 && NR { total += $5; count++} END { print
“Mean_value ” total/count}' vel_minmax.txt
We are computing the mean value of column 7 starting from row 50
67
Supplement – More on sampling
Some shell and awk scripting
• In the directory scripts (located in the top level case directory) you will find the following
scripts that will do some data processing automatically,
• script_cleanfile
• script_cleanforce
• script_extractfields
• script_force_coe
• script_forces
• script_meanvalues
• script_minmax
• script_probes
• To run the scripts you need to be inside the scripts directory. In the terminal type,
• cd scripts
• sh script_name
• Feel free to reuse them and adapt these scripts according to your needs. 68
Supplement – More on sampling
Some shell and awk scripting
• The script script_force_coe will compute the mean value and standard deviation of the lift
and drag coefficients (in this case they are not computed).
• The script script_forces will extract the force components and saved in a clean file.
• The script script_minmax will extract the minimum and maximum values of the field
variables.
• The script script_probes will extract the information of the probes.
We just showed how to compute the average and standard deviation and do some manipulation of
the information saved in the output files, but you can do many things in an automatic way.
69
Supplement – More on sampling
Plotting in gnuplot
• Let us do some plotting using gnuplot. Type in the terminal (you must be inside the scripts
directory):
1. $> sh script_minmax
2. $> gnuplot
70
Supplement – More on sampling
Plotting in gnuplot
• Let us do some plotting using gnuplot. Type in the terminal (you must be inside the scripts
directory):
• In this step we are using sed inside gnuplot to clean the parentheses. If you do not erase the
parentheses in the input file, gnuplot will complain.
71
Supplement – More on sampling
Exercises
• Where is located the source code of the functionObjects?
• Try to run in parallel? Do all functionObjects work properly?
• Try to run functionObjects a-posteriori in parallel? Does it work? Do all functionObjects work properly?
• Compute the Courant number using functionObjects.
• Compute the total pressure and velocity gradient using functionObjects (on-the-fly and a-posteriori).
• Sample data (points, lines and surfaces) using functionObjects (a-posteriori).
• Is it possible to do system calls using functionObjects? If so what functionObjects will you use and how do
you use it? Setup a sample case.
• Is it possible to update dictionaries using functionObjects? If so what functionObjects will you use and how
do you use it? Setup a sample case.
• What are the compulsory entries of the functionObjects.
72