In the earlier spillway and swak4Foam tutorials Paraview were used a lot for postprocessing. This works rather well on small and moderate cases, but when it comes to really large cases with tenths of millions of cells, this might not be practical. In such cases you should consider what you need, and configure OpenFOAM to give you those data during the simulation (and not try to extract it with Paraview later). Then the data will be extracted from the analysis while it is run in parallel. Most of the common prostprocessing tasks can be done this way. The surface elevation probe in the swak4Foam tutorial is one example of such run-time postprocessing, the forces and lift coefficient calculation in the airfoil is another.
The purpose of this tutorial is to:
- Show how you can use programs such as GNU Octave to create meshes with nonregular shapes by using blockMesh only
- Show a few of the possible run-time postprocessing features of OpenFoam and swak4Foam
The case we will use as an example is the emptying of a bottle mostly filled with a liquid held with the bottom up. The interesting questions are:
- What is the filling level at a certain time?
- At what rate does the liquid flow out?
- How does the liquid-air interface look in the bottle's neck?
- And how does the liquid surface look like?
Before you start on this tutorial, please make sure that you have
- A decent laptop or workstation
- A working OpenFOAM 2.x.x installation
- GNU Octave (Matlab will probably also work with minor modifications, although not tested)
- Done the basic cavity and damBreak tutorials that is distributed together with OpenFOAM and described in the documentation
- Done the spillway and swak4Foam tutorials provided here (or in any other way installed and familiarized yourself with swak4Foam)
1: Setup of initial case
The infamous damBreak tutorial will be used as a base case. You might choose yourself weather you want to use turbulence modelling or not. In the rest of this guide it is assumed that the simple laminar base case is used. Copy the tutorial into a folder of your choise, and possibly rename the folder to something else, such as
You should also switch the direction of gravity from the negative y-direction to the negative z-direction as we have done earlier, i.e. the acceleration field should be (0 0 -9.81) m^2/s.
2: Mesh generation and boundary conditions
The domain will for computational reasons be 2D, and the dimensions are as shown in the figure above. As this might be a bit difficult to implement by hand, we have prepared a small script meshgen.m that writes a
constant/polyMesh/blockMeshDict file. This is an extremely fast and efficient way do generate simple meshes compared to the method previous used with snappyHexMesh and extrudeMesh. Please look at the script and the
blockMeshDict it produces, and make sure you understand. If in doubt about the syntax of the
blockMeshDict-file, please consult the OpenFOAM documentation. The mesh is very easily generated by the commands:
You should set the boundary conditions yourself (hint: the inletOutlet patch should be defined with a
inletOutlet boundary condition).
3: Defining output data
As previously stated we are interested in some general output variables. Some of this can be extracted by using native OpenFOAM tools, and some output is easiest generated by swak4Foam. Brefore proceeding you should add some libraries to
system/controlDict and include some files:
Now create the files
You can of course also just put everything in one file, or even in
ciontrolDict itself, but some prefer to put postprocessing configuration in separate files (like done here).
Total filling level
The total liquid filling is easiest calculated as the volume integral of the phase fraction. This is done by a native OpenFOAM
volumeIntegrate function. Add the following to the
Cut plane and surface profile
Since we are interested in the air-liquid interface in the bottle's neck, we must define a cut plane through the section we are interested in. For the liquid surface we must calculate an isosurface with alpha1=0.5. Both operations is some by the native OpenFOAM functions cuttingPlane and isoSurface. Add the following to
Unless any modifications are done to the mesh, the cutting plane is not intersecting any internal faces in the mesh. This is done intentionally to show that you can define completely arbitrary planes without concern about the location of the internal faces. It would be quite a lot of work if all of the sample planes were to be relocated each time you changed the mesh resolution (for example in a convergence study).
Interpolation and integration
You should be aware that both integration and interpolation at run-time is costly operations (especially integrating over interpolated planes), and you should carefully consider your needs. If you are careless in your definitions you could end up using more CPU time on postprocessing than the analysis itself (however this might of course actually be what you want).
Rate of flow out of domain
The rate of flow out of the domain is easiest calculated using a
swakExpression. Append the following lines to your
4: Running the simulation
Now you have to configure your decomposition the way you want it (done in
system/decomposeParDict), decompose the domain and execute the simulation:
5: Results and postprocessing
Your output planes, surfaces and variables should show up in folders created in the root directory of the case. If you for example want to plot the filling level together with the flow rate of liquid out of the domain, you can do this in gnuplot with the following commands:
The resulting plot will look like:
Try to look at the other results you get, the volume flow and the isosurfaces.
You can of course still open the case in Paraview. Here is two stills form the discharge process:
6: Further work
If you want to test yourself's
blockMeshDict-skills, you can try to make a full 3D grid. This should not be too difficult...