Child pages
  • OpenFOAM - Modeling Basics
Skip to end of metadata
Go to start of metadata

Introduction

Modeling with OpenFOAM involves multiple steps. These include pre-processing (geometry/part creation (perhaps with a CAD package) 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 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/v6-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 about 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. The procedure is similar to that followed in https://www.youtube.com/results?search_query=freecad+gmsh+openfoam.

01_Openfoam_freecad_tube_geometry.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.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/v6-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.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.simg
#Once you are in the container
source /opt/openfoam6/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

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

OpenFOAM via Freecad CFD workbench (new and experimental)

Newer versions of Freecad (0.17 onwards) allow for simple incompressible fluid simulations to be carried out via the Freecad GUI Interface. The freecad-openfoam singularity image on Odyssey allows this method of using Freecad. It requires a few set-up steps and these are detailed in the following pdf file.

Laminar_pipe_simulation_freecad_cfd_workbench.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

https://www.freecadweb.org/

Freecad – CFD/Finite Element Analysis workbenches

http://www.opensim.co.za/training.html 

Gmsh

http://gmsh.info/

  • No labels