Basics of OpenFOAM : Open source CFD Solver

What is the basic structure of Open Source CFD Solver?

By Dr. Sharad N. Pachpute


1. Introduction to OpenFOAM

OpenFOAM is an open source CFD software which has a C++ library for more than 80 applications of CFD modeling. This solver has a large number of solvers and utilities covering a broad range of problems related to fluid flow. Any equation as a function of  field variable like scalar, vector and tensors can be coded there in the Open FOAM framework . Hence, this solver has been popular in academia and industries.


  • OpenFOAM solve the Partial Differential Equations (PDEs) numerically using the finite volumes method (FVM)
  • Customized Multiphysics CFD solver for complex flows
  • Provides numerical solutions for 3D geometries
  • Open-source software developed in C++ (object-oriented programming)
  • Can be freely downloaded  at
  • Designed as a toolbox which is easily customizable
  • Parallel computation implemented and users can use unlimited cores on HPC
  • Can be installed on windows and Linux operating systems. It needs a C++compiler for running the simulation, hence Linux is preferred

OpenFOAM has pre- and post-processing environments. The interface to the pre- and post-processing are called ads utilities. These things ensure that all variables are in OpenFOAM environments. The overall structure of open source CFD solver, OpenFOAM is shown below.

Parts of CFD Simulations in OpenFOAM

  • Pre-processing:
    • Utilities: these are provided to create or read the mesh model and boundary conditions for simulations and manipulation of input data
    • Meshing platforms: blockMesh, snappyHexMesh
    • Mesh conversion utilities: ANSYS, Salome, ideas, CFX, Star-CCM, Gmsh etc
    • Example: blockMesh, CheckMesh, runTime
  • Solvers:
    • To numerically solve a specific problem based on continuum mechanics for fluid flows
    • Different applications are coded in OpenFOAM for CFD simulations: incompressible or compressible flow , heat transfer, multiphase flow, combustion, electro-magnetism, turbulence modelling (DNS, RANS, LES) and solid mechanics, etc.
    • Example: icoFoam, rhoSonicFoam etc.
  • Post-processing
    • After simulation, CFD results can be analzed  in ParaView
    • The data from OpenFoam can be converted to other data files for other post-processing tools (FoamToTecplot)

1.2 Advantage of OpenFOAM

  • No licensing fees
  • Easy to use CFD solvers on any HPC with unlimited cores for complex problems (LES, DNS)
  • Direct access to source codes to customize CFD solvers
  • additional code-to-code for benchmarks,
  • Users get regular updates
  • More than 80 different solvers and various tutorials
  • Ease to implement and program for any equations in partial differential equations
  • Active academic and professional communities by forum, conference, training schools

1.3 Disadvantage of OpenFOAM

  • Require more time to learn initially
  • Lack of complete user guide or direct CFD support
  • No integrated graphical user interface (GUI) for pre-processing, solver setting and monitoring the simulations
  • More suitable for Linux platform
  • CFD users must know Unix command lines and C++ programming

2. OpenFOAM Directory

After installation of OpenFOAM, we can see many subdirectories like applications, source code (src), tutorials, dictionary files, other supporting installation and compilation file.

3. Case Set up in OpenFOAM

To set a case for CFD simulation, we have to create three subdirectories for numerical simulation

  • 0 :
    • All initial boundary conditions are given with different files created for pressure (P), velocity(U), temperature (T), concentration (C) and turbulent viscosity (nut) as key variables implemented in CFD solver
    • This directory is common for both steady and unsteady problems
  • Constant
    • Mesh files: files for boundary conditions, faces and nodes
    • Transport properties /Material properties
    • Selection of turbulence models like RANS/LES
  • System
    • conrtolDict: Files to control the simulation
    • decomposeParDict: files for parallel simulation on HPC
    • fvSchemes: discretization schemes for both temporal and spatial
    • fvSolution: selection of tolerance, residual and pressure-velocity coupling
  • Additional files for mesh and post-processing
  • After simulation different directories of iteration of time steps are created which have data of domain for velocity, pressure, temperature, TKE, Dissipation rate etc.

4.Discretization schemes in OpenFOAM

  • In OpenFOAM case set up,  there is a fvSchemes dictionary in the system directory to define different numerical schemes for discretization of different terms in governing equations

Different interpolation schemes are used for various terms in equations. However, the linear interpolation is more effective in most of cases

  • OpenFOAM provides enough choices to CFD user for selection of interpolation schemes for different interpolation terms.

4.1 Schemes for Vector fields

For vector fields such as gradient of scalar, various numerical schemes are used in OpenFOAM

4.2 Unsteady Terms

For transient flows, there is an unsteady term (d/dt) governing equation. This is called is the first time derivative. In OpenFoam solver, it is presented as ddtSchemes. The discretisation schemes for each term can be selected from those listed below.

  • Steady State: time derivative is set with zero value
  • Euler Scheme: this time scheme is suitable for unsteady, 1st order implicit and bounded solution
  • Backward scheme: it is suitable for unsteady, 2nd order implicit and potentially unbounded problems
  • Crank Nicolson scheme: it is suitable for unsteady, 2nd order implicit and bounded problems. This scheme requires to set a coefficient of 1 for Crank Nicolson and zero for Euler scheme. For most engineering problems it is set with 0.9 to get stable solutions
  • In openfam it is written as

  • A list of time schemes available in OpenFOAM is given below


4.3 Gradient schemes

a) Gauss linear

  • finite volume method (FVM) discretisation of Gaussian integration which interpolate of values from cell centres to face centres
  • Linear interpolation scheme or central differencing is used
  • Its value can be specified with 1 for boundness and 0 for no boundness
  •  In some cases, cell Limited scheme used to limit the calculated gradient due to extrapolation from faces. It helps to improve boundedness and stability for velocity gradients for poor mesh quality

b) leastSquares: this is a a second-order scheme and calculates the least squares distance using all neighbour cells.

c) Gauss Cubic: third-order scheme that is suitable for the  direct numerical simulation (dnsFoam) on a regular mesh.

4.4 Divergence schemes for Advection and Diffusion

In governing equation such as momentum, energy or species transport there are advection and  diffusion terms. These terms are treated as divSchemes in Open FOAM. The non-advective terms is generally interpolated with the Gauss integration considering a linear variation 

  • Upwind: This is a first-order bounded scheme
  • Linear: this scheme is based on second order, unbounded.
  • Linear Upwind: second order, upwind-biased, unbounded (but much less so than linear). For this discretization, velocity gradients need to be specified
  • LUST (Linear Upwind Stabilised Transport) : This scheme is combination of both linear (75%) and linear Upwind (25%). For this discretization, velocity gradients need to be specified. This scheme is used for large eddy simulation (LES).
  • Limited Linear: it is a modified linear scheme which limits towards the upwind schemes in the region of a sudden change in gradients. It needs to define with a coefficient of one for upwind and zero for linear.

5. Application source code in OpenFOAM

  • The main code application is included in the *.C file.
  • In OpenFOAM, depending on flow application, the source code is developed in several other files
  • This file is given at the beginning of any piece of code using the class, including the class declaration code itself
  • Any piece of code in ( *.C file) can have a number of classes and which are declared in *.H files
  • The classes in these files may have other classes

  • In OpenFOAM Header files are included in the application code using # include statements: # include “otherHeader.H”
  • It is given for compiling to suspend reading from the current file to read the file specified
  • Any self-contained piece of code or custome code is put into a header file and included at the relevant location in the main code in order to improve code readability
  • For example, in most OpenFOAM applications , the code for creating or reading field of input data is given in a file createFields.H

Structure of Application in OpenFOAM

We scan consider the sonicFoam application as an example of application directory This application can be found at:

The top level source file takes the application name with the .C extension. For any application, classes are defined on *.H files and governing equations are generally coded in *.C files


5.2 Compilation of Application using the wmake command 

For the compilation of a new application, the directory should have a Make subdirectory which contains 2 files: options and files. The wmake command is used to compile a modifies application.

There are several files (*.C and *.H) are given in a particular directory of application. Do required changes as per OpenFOAM framework without any error in compilation

The OpenFoam compiler checks for the included header files in the following order. It is specified with the -I option in wmake:


  •  lnInclude is added as a local  directory for incompressible solver (icoFoam): $WM_PROJECT DIR/src/icoFoam/lnInclude
  • Platform dependent paths are  set in files :  $WM_PROJECT_DIR/wmake/rules/$WM_ARCH/
  • The full paths of directory to locate header files given in “ Make/options” file using the following syntax:

EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude

6. Implementation of Governing Equations in OpenFOAM

6.1 Mass, Momentum and Enrgy Equation in OpenFOAM

  • The turbulent kinetic energy equation is given as below

  • In open Foam, the above governing equations are implemented as equation representation

Here, the first term represents of the left side the unsteady term, the second term is the divergence f mass flux (phi) and K. The four term is diffusion term.

6.2 Implementation of compressible flow solver (rhoSonicFoam)

  • The conservation of equations for compressible flow in OpenFOAM are presented as

7. Pressure and Velocity Coupling in OpenFOAM

a) Semi-Implicit Method for Pressure-Linked Equations (SIMPLE)

    • The details of SIMPLE algorithm it is useful for most simple steady flows
    • You can find on open foam wiki website:
    • The SIMPLE  is used to couple the mass and moemtum (Navier-Stokes)  equations during  iterative procedure, which is given as below
      1. set the domain with boundary conditions
      2. Solve numerically the discretized momentum equation to calculate the intermediate velocities
      3. Calculate the mass fluxes at the cells faces.
      4. Solve the pressure corrected equation and  apply under-relaxation factors
      5. Correct the mass fluxes for all the cell faces.
      6. Correct the velocity fields based on new pressure fields
      7. Update the boundary conditions.
      8. Repeat above steps till convergence

b) PISO: Pressure-Implicit with Splitting of Operators

  • This algorithm is more suitable   to solve the Navier-Stokes equations in unsteady (transient) problems of CFD modeling
  • It can support worst meshes

c) PIMPLE: combination of SIMPLE and PISO

  • This is more suitable to use adaptive steps with a fixed courant number in large eddy simulations (LES)

The PISO loop in OpenFOAM

8.Boundary Conditions in OpenFOAM

  • Most of boundary conditions are defined based on fixed value or fixed gradients
  • It is important to understand these values before CFD modelling
  • For details of boundary conditions: \src\finiteVolume\fields\fvPatchFields\
  • There major types of boundary conditions:
    • Basic: calculated, fixed value, fixed gradient, zero gradient
    • Constraint: symmetry, wedge, cyclic, jump, cyclic AMI
    • Derived: slip, no slip, fan pressure, inlet outlet, outlet inlet, total pressure


  1. Open FOAM downloads and details of solvers:
  2. OpenFOAM discussion forum:
  3. community-driven wiki: 
  4.  Open Foam Blog: Fumiya Nozaki
  5. Customization of CFD solvers: Chalmer University tutorials on OpenFOAM

1 thought on “Basics of OpenFOAM : Open source CFD Solver”

  1. ESI-OpenCFD is pleased to announce the release of OpenFOAM v2006 (20 06) of the OpenFOAM open source CFD toolbox.


Leave a Comment