OpenFOAM version: OpenFOAM-v2206
Operating System: Ubuntu 20.04 LTS, hosted on Windows 11 machine via Docker
Tutorial Case: Dam Break
Solver: interFoam
If you just started your OpenFOAM journey for your studies (Master/PhD) or for your job, you may find it difficult to learn it at the very beginning because OpenFOAM doesn’t have a default GUI to setup the case and run it. You need to run by command line interface (CLI) and change the solver settings through text files called dictionary files.
Therefore, you may want to understand the file structure of your OpenFOAM case directory. And this tutorial is for you!
For this tutorial, we will use the Dam Break tutorial. It is a default OpenFOAM tutorial for multiphase free surface flow of a breaking dam. We chose this tutorial because it is readily available in every OpenFOAM version and simple enough to run easily and complex enough to study the general OpenFOAM case structure.
First, we enter the directory of the tutorial. It is located inside $FOAM_TUTORIALS/multiphase/interFoam/RAS/damBreak. You can copy it to anywhere you want by the following command.
Where, $destination is the directory you want to copy to. Then you can use “tree” command to see inside the directory. The case directory consists mainly of 3 directories “0”, “constant” and “system”. Sometimes, you can find “0.orig” instead of “0” but you need to copy this 0.orig as 0 to run your simulation properly.
“0” directory (time series directories)
The 0 directory contains field setting files where you can set up the initial and boundary conditions for your CFD simulation. In our example, we have “U”, “p_rgh” files which are the setting files for velocity and pressure boundary conditions. These files are necessary for most of your CFD calculations involving fluid flows. For single phase flows, the pressure boundary conditions are located in “p” file instead of p_rgh which is used particularly for gravity driven free surface flows. As an example, the following is the velocity boundary condition file “U”. Here, the leftWall, rightWall and lowerWall are set to be noSlip walls while the atmosphere is a pressureInletOutletVelocity type. For more details, you can refer to our explanation about boundary conditions here.https://cfdmonkey.com/a-brief-explanation-of-boundary-conditions-in-openfoam/
“constant” directory
This directory mainly contains the mesh, the CAD geometry, physical properties of the material/fluid, turbulence models, advanced models like dynamic meshing settings.
For our example, there are only the mesh and fluid properties as well as turbulence properties. If you use snappyHexMesh to create the mesh for your CFD analysis, you need to put necessary STL CAD files inside constant/triSurface directory. We will show about the details in our snappyHexMesh tutorial.
The mesh is located in the “constant/polyMesh” directory and composed of multiple files.
The most important file among these mesh files is the “boundary” file in which you can check the boundary patches of your mesh like inlets, outlets and walls. You can confirm you have proper patches for your boundary conditions in this file. For instance, if you want to define a non-slip wall on a patch name “leftWall”, you need to confirm the type of your patch “leftWall” to be “wall” as shown in the image below. For the details about boundary conditions, we will explain in later articles.
The other files inside the polyMesh directory contain the actual representation of the mesh such as points, faces, cells, etc. Since these files usually contain large amounts of data, it’s better to check your mesh in other ways like checkMesh and visualization in Paraview than actually looking inside these.
Now we move on to constant/transportProperties file. This file contains fluid properties for our CFD simulation. For single phase cases, we have only one fluid and all we need to setup is the kinematic viscosity “nu”.
For multiphase free surface flows like our dam break tutorial, we need to setup the fluid properties for air and water. Such an example is shown in the following image. As we can see, the kinematic viscosity and density of water and air phases being configured. Also, we can set the surface tension sigma in this file.
“system” directory
This is the core of our CFD analysis settings. It usually contains “blockMeshDict”, “controlDict”, “fvSchemes”, “fvSolutions”, and “decomposeParDict” files. It may contain other files used by various OpenFOAM utilities like “setFieldsDict”, “topoSetDict”, “snappyHexMeshDict” but we will mainly focus on the ones above.
The first one is the blockMeshDict. blockMeshDict is the setting file for blockMesh mesh generator by OpenFOAM. It is used to generate blocked structure meshes which may either be Cartesian or not. The following is the blockMeshDict file. It contains the vertices and the order of these vertices for each block. Also, the patch names and patch types can also be defined here. When you run blockMesh utility, blockMesh will read this file and generate the mesh according to the settings inside it. Therefore, the patch names will appear inside constant/polyMesh/boundary file we mentioned earlier.
The second file you will see is the “controlDict” file. This is the most important file inside any OpenFOAM case directory because all OpenFOAM solvers and utilities will look for this controlDict file. If the solver does not find this file, it will not run at all!
Inside the controlDict file, we have application name which is the solver to be used, the starting and ending times for the simulation, the time step, the output file writing interval, the Courant number if the solver is transient, etc.You can also setup additional functionalities such as calculating for drag and lift coefficients, wall shear stresses, etc. here.
Next file inside the system directory is the “decomposeParDict”. It contains information about the number of processors to be used for the calculation and how to divide the computational domain for parallel processing. The number of processors can be configured in “numberOfSubdomains” and the method can also be changed.
After that, we have fvSchemes and fvSolution files. The fvSchemes file contains the settings for discretization of various terms in the Partial Differential Equations (PDEs) we are solving. For our dam break tutorial, we have unsteady Navier Stokes equations for two fluids with a free surface. The following is a fvSchemes file for the dam break tutorial showing how temporal terms, gradient and divergence terms are disceetized.
On the other hand, the fvSolution file contains the settings for solving the linear systems generated by discretizing the governing equations using those schemes in fvSchemes file. And you have control on how the solving algorithm (SIMPLE, PISO or PIMPLE) should work. For example, you can set the number of maximum iterations for each time step in PIMPLE algorithm or the number of correction steps for non-orthoginality if your mesh has unfavorable non-orthoginality.
Now you have a brief overview of an OpenFOAM case directory structure. For the details, we will create in depth tutorials for each of the important settings. Stay in tune!