Introduction
Modeling with OpenFOAM involves multiple steps. These include pre-processing (geometry/part creation and meshing), simulation, and post-processing. Simple geometries can be created and meshed within OpenFOAM (see the lid-driven cavity flow example below). However, it is more convenient to use a CAD software package for creating more complex geometries and use a separate software for meshing. In the following sections, we will briefly take you through the modeling steps with a simple example.
Basics of pre-processing, simulation and post-processing in OpenFOAM
The example of lid-driven cavity flow introduces you to OpenFOAM by taking you through all the steps (geometry creation, meshing, simulation and post-processing) for a simple geometry. All steps are carried out in OpenFOAM via command-line interface (CLI). Please familiarize yourself with this model (and the OpenFOAM directory structure) before proceeding further. These steps can be carried out using the singularity container on odyssey.
https://cfd.direct/openfoam/user-guide/v8-cavity/
OpenFOAM with geometry and meshing using other software
In this example, we consider laminar flow in a pipe (radius 10 mm, length 1000 mm). The kinematic viscosity of the fluid is 0.00047 m^2/s and the density is 850 kg.m^3 (corresponding to some kind of oil). Flow in the tube is maintained by applying a pressure of 5000 Pascals above the atmospheric pressure at one end while the other end is exposed to the atmosphere.
Geometry preparation with freecad and meshing with gmsh
The following pdf shows how to construct the tube geometry and export it in the STEP format suitable for import into gmsh for meshing.
01_Openfoam_freecad_tube_geometry_v2021.pdf
While tetrahedral meshes can be generated easily with gmsh, they are not ideal for CFD applications. The following pdf shows mesh generation with hexahedra.
02_Openfoam_gmsh_hexahedral_meshing_v2021.pdf
Note that the geometry creation step can also be performed with commercial software (eg. Solidworks, Onshape, Autodesk, etc.) and exported in STEP format to meshing software. Geometry creation and meshing can also be carried out with other open source packages such as salome (or salome_meca).
Simulation
We set up the simulation of laminar pipe flow by copying a pre-existing incompressible flow simulation directory structure from the directory $FOAM_TUTORIALS. Before beginning this part, make yourself familiar with the OpenFOAM directory structure:
https://cfd.direct/openfoam/user-guide/v8-case-file-structure/
For the current simulation, we need the mesh generated with gmsh along with the initial and boundary conditions and fluid transport properties. The mesh file should be converted to the OpenFOAM format with the gmshToFoam utility and the units (which are in mm) need to be converted to SI units (the native units of OpenFOAM) with the transformPoints utility function. We setup the simulation by copying the folder $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily folder and modifying the appropriate files. The following pdf file illustrates the steps:
03_OpenFOAM_laminar_flow_simulation_v2021.pdf
The zip file tube_laminar_flow.zip includes the directory structure with all the necessary files set up for laminar pipe flow. Unzip the file in a suitable directory, change into it and run singularity from there. The file also includes a mesh file from gmsh. You can import it into openfoam and run openfoam from the tube_laminar_flow directory as follows:
singularity shell /n/seas_computing/scientific_software/freecad-OpenFoam-2021.simg #Once you are in the container source /opt/openfoam8/etc/bashrc gmshToFoam tube_laminar_flow.msh checkMesh #As the geometry is in mm, we need to convert it to meters, the native unit in OpenFoam transformPoints -scale '(0.001 0.001 0.001)' #run the solver simpleFoam simpleFoam
Simulation via batch
You can run an OpenFoam job via singularity in the batch mode. For this, create two scripts. The first script (say openfoam_tube_laminar):
source /opt/openfoam8/etc/bashrc gmshToFoam tube_laminar_flow.msh checkMesh #As the geometry is in mm, we need to convert it to meters, the native unit in OpenFoam transformPoints -scale '(0.001 0.001 0.001)' #run the solver simpleFoam simpleFoam
The second script (say runscript_openfoam_tube_laminar) is as follows. You can submit this script to slurm:
#!/bin/bash #SBATCH -n 1 #Number of cores #SBATCH -t 60 #Runtime in minutes #SBATCH -p shared #Partition to submit to #SBATCH --mem-per-cpu=500 #Memory per cpu in MB (see also --mem) echo "singularity invoked" echo " " singularity exec /n/seas_computing/scientific_software/freecad-OpenFoam-2021.simg ./test_scr # Report some useful info /bin/uname -a date exit
Post-processing
Post-processing of results is done with the paraFoam program that is also available on the freecad-openfoam singularity image. The following pdf shows how to plot the velocity across the outlet of the pipe. Note that the maximum velocity at the center of the tube at the outlet (~ 0.29 m/s) smaller than the theoretical maximum (~ 0.31 m/s). This is perhaps due to resolution and the kind of mesh (unstructured mesh). Structured mesh with greater resolution at the boundary is likely to yield better results (see the OpenFOAM results with the Freecad CFD workbench below).
Openfoam_laminar_pipe_flow_postprocessing.pdf
References
OpenFOAM Documentation
https://cfd.direct/openfoam/user-guide/
For specific documentation, search the web (google, bing, etc.) or youtube. For example, to find out about OpenFOAM solvers, search on youtube "OpenFOAM solvers". As of this writing, this will lead you to a nice video by Jozsef Nagy titled "How to find the most suitable solver for OpenFOAM simulations".
Freecad – CFD/Finite Element Analysis workbenches
http://www.opensim.co.za/training.html