• CFD, Fluid Flow, FEA, Heat/Mass Transfer
  • +91 987-11-19-383
  • amod.cfd@gmail.com

CFD using Open-Source

OpenFOAM: A Beginner's Diary

Disclaimer:

This content is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OpenFOAM and OpenCFD trademarks.
At the outset, start with few excerpts from User Guide: "OpenFOAM is first and foremost a C++ library, used primarily to create executables, known as applications. The applications fall into two categories: solvers, that are each designed to solve a specific problem in continuum mechanics; and utilities, that are designed to perform tasks that involve data manipulation. One of the strengths of OpenFOAM is that new solvers and utilities can be created by its users with some pre-requisite knowledge of the underlying method, physics and programming techniques involved. OpenFOAM is supplied with pre- and post-processing environments. The interface to the pre- and post-processing are themselves OpenFOAM utilities, thereby ensuring consistent data handling across all environments."
The code is released under GPL GNU Public License), the product is free, powerful but comes with its own 'inconvenience'. Though the authors and programmers try their best to document everything, it still requires additional things to be learnt other than CFD itself, such as:
  • complier and build-platform (such as "Windows XP Professional, Service Pack 2, 64-bit") used to prepare the binaries
  • 'make' utility to compile the source codes, associated intermediate programs like Qt, Cygwin
  • Windows versions of required programs such as "Visual Studio 2008 x86 9.0.30729.1 SP"
  • Jargons like Kubuntu (Ubuntu + KDE) are by no mean kind to those either not familiar with Linux or not up-to-date with this OS!
  • Yet, one can do with it whatever (s)he likes, including unlimited commercial use, serial or parallel computing.
The effort of this page is to provide all resources 'collocated': start (installation) -> finish (getting CFD results), in a concise but complete manner.

Installation:

OpenFOAM, by its design is meant for Linux platform. However, there are few companies which provide installers for Microsof Windows free of cost (other than providing other paid services). Some of them are:

Few key attributes

  • OpenFOAM stands for: Open Field Operations And Manipulation.
  • It is primarily, similar to CFX, a 3D-solver, hence all 2D meshes need to be extruded in third dimension. 2D problems are solved using special patches "empty". Excerpts from user guide: "OpenFOAM always operates in a 3 dimensional Cartesian coordinate system and all geometries are generated in 3 dimensions. OpenFOAM solves the case in 3 dimensions by default but can be instructed to solve in 2 dimensions by specifying a special empty boundary condition on boundaries normal to the (3rd) dimension for which no solution is required."
  • Simulation of axi-symmetric flow problems, patch name 'wedge' is used. The wedge (also called prism mesh in other programs) is created by collapsing a pair of nodes - to convert a cuboid into a wedge - as described in the user manual shipped with OpenFOAM.
  • It is a collection of Utilities, Solvers and Libraries based on programming language C++.
  • Ulities are specific functions needed to be performed in any CFD simulations such as "Mesh Generation and Checking", "Mesh Conversion", Post-processing ...
  • It is primarily a command line based solver, with less emphasis on GUI. It uses ParaView or paraFoam as post-processor.
  • Paraview is a general-purpose post-processing tool to process a vast variety of formats.
  • ParaFoam is a customized-version of Paraview to post-process results produced by OpenFOAM in its native format (i.e. without any interim conversion of data)
  • Unit of variables in OpenFAOM are specified as row vector of size 1x7 comprising of indexes [a b c d e f g] designated as [Massa Lengthb Timec Temperatured Quantitye Currentf Luminous Intensityg] which in SI unit is [kga mb sc Kd kilo-molee Af Cdg]. For example, the unit of dynamic viscosity, kg/m-s or Pa.s can be specified as [1 -1 -1 0 0 0 0].
  • The solvers are named based on certain features and can easily be decoded and remembered after working through once or twice: For example, icoFoam is InCOmpressible Foam (icoFoam), simpleFoam is Semi-Implicit Method for Pressure-Linked Equations Foam...
  • "SanppyHex Mesh" in OpenFOAM is similar to "Cartesian Meshing" in ICEM CFD, "Trim Mesh" in STAR CCM+ and "Cut-cell method" in some other pre-processors.
  • Files have free form, no need to indicate continuation across lines, no constraints on start column and end column
  • // is used to put comment in OpenFOAM dictionary files, inline with C++ programming syntax. Comment encompassing multiple lines need to be enclosed between /* and */ delimiters.
  • The OpenFAOM solver supports polyhedral meshes. It is believed that OpenFOAM had it first than any other program!
  • Pre-processor Harpoon can directly export data in the native format of OpenFOAM (no data conversion required).

Some of the troubleshooting and best practices can be found out at:

  • OpenFOAM: Troubleshooting
  • Few excellent videos on YouTube, by Jozsef Nagy, are: blockMeshDict and OpenFOAM results in ParaView. Many thanks Jozsef!
  • OpenFOAM uses its own makefile 'wmake' which is based on standard 'make' utility. However, the common 'makefile' command 'make' will not work with compilation of OpenFOAM codes.
  • If you know what to look for, it is a great tool. If you don't, you might get lost in the hugeness of the OpenFOAM! The trick is to go through as many tutorials as possible and as many repeats you can make. You will find it worth doing.

One of the complexity a new user faces is the files (with no pre-defined extensions, most of us are so used to now) and folder-structure used by OpenFOAM. A bare minimum requirement for geometry, assuming that the OpenFOAM run in a folder named "BaseDir", then the following items must exist, all with read and write access:
  1. BaseDir/system/controlDict
  2. BaseDir/constant/polyMesh/points or points.gz
  3. BaseDir/constant/polyMesh/faces or faces.gz
  4. BaseDir/constant/polyMesh/owner or owner.gz
  5. BaseDir/constant/polyMesh/neighbour or neighbour.gz
  6. BaseDir/constant/polyMesh/boundary or boundary.gz
  7. BaseDir/0/p
  8. BaseDir/0/U
There are few additional files which is just to make simulations easier:
  1. BaseDir/Allrun: This file describes all the things that need to be executed in order to run a case
  2. BaseDir/Allclean: Keeps file required for future re-use. All other files are deleted.
The content of the files / dictionaries used in OpenFOAM are:
  • controlDict: Excerpts from user guide: "Input data relating to the control of time and reading and writing of the solution data are read in from the controlDict dictionary. The user should view this file; as a case control file, it is located in the system directory."
  • blockMeshDict: the file describing the geometry (and not the mesh, 'blockMesh' is the utility or command that creates the mesh from this geometry). This operation, 'blockmesh' creates the 5 files described below.
  • points or pints.gz: the file containing node numbers and locations (X, Y, Z coordinates)
  • faces or faces.gz: the file containing the face connectivity of the "points" or nodes defined in points file
  • owner or owner.gz: the file containing the collection of faces which make up an 3D element
  • neighbour or neighbour.gz: the file containing connectivity between the faces (each internal faces have an owner and neighbour, apart from boundary faces who have owner only). Note that it uses '..ou..' in neighbour.
  • .../0/p and .../0/U are initialization files. Be careful with the units! In OpenFOAM incompressible solvers, the solved pressure is plocal / ρ. Hence, unit in p dictionary should be m2/s2 i.e. [0 2 -2 0 0 0 0] and not kg/m-s2 i.e. [1 -1 -2 0 0 0 0].
  • system/fvSchemes: This dictionary in the system directory sets the numerical schemes for terms, such as derivatives equations, that appear in applications being run.
  • U / p / T dictionaries : boundary names can be combined using "(boundary-1 | boundary-2 | ...)" E.g.
    "(left | right)"
    {
      type zeroGradient;
    } 
  • There are two different algorithms to solve Navier-Stokes equations. SIMPLE (simpleFoam...) - only steady state solution [pseudo-transient] and PISO (icoFoam, pisoFoam...) - both transient and steady state solution.
A layout of the files is shown below:
File Structure in OpenFOAM
File Hierarchy in OpenFOAM

Some historical facts:

  • FOAM was originally written by Henry Weller et all. at Imperial College of London (interestingly, many CFD applications have genesis associated with this academy), which was initially sold as commercial code by company named Nabla Limited. In 2004, it was renamed to OpenFOAM while releasing under GNU Public License.
  • FoamX was dropped from OpenFOAM V1.5 onwards. FoamX was a GUI that can manage cases on a local machine as well as over a distributed network.
  • Excerpts from: "OpenFOAM for Computational Fluid Dynamics - Goong Chen, Qingang Xiong, Philip J. Morris, Eric G. Paterson, Alexey Sergeev, and Yi-Ching Wang" -- OpenFOAM was born in the strong British tradition of fluid dynamics research, specifically at The Imperial College, London, which has been a center of CFD research since the 1960s. The original development of OpenFOAM was begun by Prof. David Gosman and Dr. Radd Issa, with principal developers Henry Weller and Dr. Hrvoje Jasak. It was based on the finite volume method (FVM) [5], an idea to use C++and object-oriented programming to develop a syntactical model of equation mimicking (see Box 2) and scalar-vectortensor operations.Alarge number of Ph.D. students and their theses have contributed to the project. Weller and Jasak founded the company Nabla Ltd., but it was not successful in marketing its product, FOAM (the predecessor of OpenFOAM), and folded in 2004. Weller founded OpenCFD Ltd. in 2004 and released the GNU general public license of OpenFOAM software. OpenFOAM constitutes a C++ CFD toolbox for customized numerical solvers (over sixty of them) that can perform simulations of basic CFD, combustion, turbulence modeling, electromagnetics, heat transfer, multiphase flow, stress analysis, and even financial mathematics modeled by the Black-Scholes equation. In August 2011, OpenCFD was acquired by Silicon Graphics International (SGI). In September 2012, SGI sold OpenCFD Ltd to the ESI Group. --

Summary of OpenFOAM Programs and Utilities

Most of the applications in OpenFOAM requires instruction from a plain text file called dictionaries. These are equivalent command line operation to the GUI features available in commercial softwares. Though, most of the dictionaries are commented well, the learning curve might still be steep for most of the beginners.
Summary OpenFOAM
Example 'blockMeshDict' files and mesh generated in OpenFOAM.
  • The mesh generated by blockMeshDict file available with OpenFOAM distribution.
    Block Mesh for Cylinder

    The blockMeshDict file is here .
  • The mesh generated with simple biasing over cylinder body is shown below.
    Block Mesh for Cylinder

    The blockMeshDict file is here.
  • The mesh generated for a pipe flow, pipe diameter of 50 [mm] and length of 1000 [mm] is shown below.
    Block Mesh for Pipe Flow

    The blockMeshDict file is here.
  • A recommended blocking for a quater-symmetric cylindrical domain is shown below.
    Block Mesh for Pipe Flow

Variables or Parametric blockMeshDict

It is possible to use variables or parameters to define meshing features in blockMeshDict. If #calc function is used, blockMesh creates a runtime folder dynamicCode (first run of blockMesh) in the case folder. Refer to the screen-shots for sample use of variables in blockMeshDict and what works and what does not [tested in Version: v1606+ on Microsoft Windows 10].
parametric blockMeshDict


parametric blockMeshDict


parametric using include file

Convective Boundary Conditions

Following setting can be applied in 'T' file.
wallConvective    {
    type        externalWallHeatFluxTemperature;
    Ta          uniform 300.0;    // Reference temperature q''= h*(T-Ta)
    h           uniform 10.0;     // HTC value [W/m^2]
    value       uniform 300.0;    // Boundary Initialization Temperature 
    kappa       solidThermo;      // -kappa x dT/dx = h *(T - Ta)
                //fluidThermo,solidThermo,lookup,directionalSolidThermo
    kappaName 	none;
    }	
	


Volumetric Heat Source

Following setting can be applied in 'fvOption' file in the folder containing mesh data and 'fvSchemes' and 'fvSolution' files.
volumeHeatSource   {
    type        scalarSemiImplicitSource;
    active      true;
    scalarSemiImplicitSourceCoeffs     {
        selectionMode   cellZone;  
                        //cellZone, cellSet, points, all 
                        //Domain where the source is applied 
        cellZone        solidDomain;
        volumeMode      specific;  //specific | absolute
        injectionRateSuSp    {
          h (100000 0);  
             /* S(T) = Su + Sp * T  ->  Su = q, Sp = 0   
             q''' = 'specific' volumetric generation [W/m^3] = 100,000
             q = 'absolute' volumetric generation [W]                      */
	    }
	}
}	
	


Contact Resistance

Following setting can be applied to the boundary field in 'T' file.
    solidZone_to_waterDomain    {
        //type          calculated;
        type            compressible::turbulentTemperatureCoupledBaffleMixed;
        value           uniform 300;
        //"value" entry is only ans 'initialization' value at the interface. 

        Tnbr            T;
        kappa           solidThermo;
        kappaName       none;
		
        /*define thermal contact resistance between regions by giving the 
          thickness and the conductivity of the inter-region layers.           */
        thicknessLayers (1e-3);    // value in [m] - Rk = [K/W] = [m] / [W/m.K]
        kappaLayers 	(5e-4);    // Value in [W/m.K]
    }
	
A summary of OpenFOAM tutorials can be found on this page. This is being continuously revised and updated with additional information. The summary of tutorials on Multi-Phase flow are here.

OpenFOAM by design is a Finite Volume solver (even structural problems which are dominated by Finite Element technique can be solved using OpenFOAM) and can handle any type of mesh (including the polyhedral). Following info-graphics provide a concise difference between the three numerical techniques known so far.
FDM, FEM, FVM


Disclaimer:

This content is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OpenFOAM and OpenCFD trademarks.
Contact us
Disclaimers and Policies

The content on CFDyna.com is being constantly refined and improvised with on-the-job experience, testing, and training. Examples might be simplified to improve insight into the physics and basic understanding. Linked pages, articles, references, and examples are constantly reviewed to reduce errors, but we cannot warrant full correctness of all content.