Table of Contents
What is the basic structure of Open Source CFD Solver?
By Dr. Sharad N. Pachpute
Introduction to OpenFOAM
Open FOAM is an opensource CFD software that 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 variables 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 Multi physics CFD solver for complex flows
 Provides numerical solutions for 3D geometries
 Opensource software developed in C++ (objectoriented programming)
 Can be freely downloaded at www.openfoam.com
 Designed as a toolbox that is easily customizable
 Parallel computation is 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 preand postprocessing environments. The interface to the pre and postprocessing are called ads utilities. These things ensure that all variables are in OpenFOAM environments. The overall structure of the opensource CFD solver, OpenFOAM is shown below.
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 codetocode 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
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 preprocessing, solver setting, and monitoring the simulations
 More suitable for the Linux platform
 CFD users must know Unix command lines and C++ programming
Essential Subject for OpenFOAM
To understand the numerical algorithms with programs in Open FOAM. CFD users need to understand the following subjecting details
 Governing equations: various equations for transport of scalar, vector, tenor need understand for fluid mechanics, heat transfer, turbulence, Multiphase flow, combustion, and turbomachinery
 Numerical methods and modeling of various terms
 Programming in C++
 Experience on Linux
 Parallel computing and shell programming
Parts of CFD Simulations in Open FOAM
Preprocessing

 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, StarCCM, 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, electromagnetism, turbulence modelling (DNS, RANS, LES) and solid mechanics, etc.
 Example: icoFoam, rhoSonicFoam etc.

Postprocessing



 After simulation, CFD results can be analzed in ParaView
 The data from OpenFoam can be converted to other data files for other postprocessing tools (FoamToTecplot)


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.
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 pressurevelocity coupling
 Additional files for mesh and postprocessing
 After simulation different directories of iteration of time steps are created which have data of domain for velocity, pressure, temperature, TKE, Dissipation rate etc.
Application Utility
Applications are programmed in OpenFOAM for pre and postprocessing. CFD users need to be familiar with such commands.
Preprocessing: Meshing Utilities
 BlockMesh: convert geometry to mesh
 CheckMesh: To check mesh quality such as skewness and aspect ratio
 fluentMeshToFoam: Converts fluent 2D mesh (in ASCII format) to OpenFOAM format
 snappyHexMesh: Generate Hexdominant automatic mesh
 surfaceTransformPoints: Scale, rotate, translate surface mesh vertices
 fluent3DMeshToFoam: Converts a Fluent 3D mesh to OpenFOAM format
 star4toFoam: Converts the mesh file of PROSTAR v4 to OpenFOAM format
Preprocessing: Application Utilities
 setFields: Modify internal field values using sets
 FunkySetFields: Enhanced setFields with interpreted functions
 mapFields: Parallel mapping of solution fields
Preprocessing: Utilities for Parallel simulation
 decomposePar: Decompose or split the mesh and fields for parallel execution
 reconstructParMesh: Merge decomposed mesh and data (simulated files from parallel processors) into a single set of files
 reconstructPar: Merge decomposed fields (parallel run data) from parallel runs
Postprocessing Utilities
 foamToVTK: Converts OpenFOAM file to VTK format
 foamToTecplot360: Converts OpenFOAM (mesh and data) files to Tecplot 360 format
 foamLog: Create plottable ASCII files from solution logs
 foamCalc: Perform mathematical operations on existing fields
 ptot: Calculate and write the total pressure field
 yPlusRAS: Calculate and write the yPlus field for RANS (Renolds averaged Navier stokes equations) models
 yPlusLES: Calculate and write the yPlus field for large eddy simulation (LES)
 sample: Sample results on points, lines, and surfaces
 vorticity: Calculate and write the vorticity field of velocity
 wallShearStress: Calculate and write the field of wallShearStress over the wall
 wallHeatFlux: Calculate and write the field of convective heat flux over the wall
Solvers in OpenFOAM
 After installation of openfoam libraries, check available source code as per physics of CFD applications like turbulent flow, sonic flow, combustion and multiphase flow etc, $FOAM_APP/solvers or ($FOAM_SOLVERS)\
 Find the source code for the CFD solvers arranged as follows:
 Combustion: example: reactingFoam
 Compressible coupled
 Discrete methods
 Direct Numerical Simulation (DNS)
 Electromagnetics engine
 Incompressible flow: example: icoFoam, simpleFoam
 Heat Transfer
 Lagrangian Flow
 Multiphase Flow: example:interFaom
 Stress Analysis
 surface Tracking
 viscoelastic flow
 Financial Application
 Some examples of CFD solvers are listed below
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 cases
 OpenFOAM provides enough choices to CFD users for the selection of interpolation schemes for different interpolation terms.
Schemes for Vector fields
For vector fields such as the gradient of scalar, various numerical schemes are used in OpenFOAM
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 discretization 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, 1^{st} order implicit and bounded solution
 Backward scheme: it is suitable for unsteady, 2^{nd} order implicit and potentially unbounded problems
 Crank Nicolson scheme: it is suitable for unsteady, 2^{nd} 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
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 secondorder scheme and calculates the leastsquares distance using all neighbor cells.
c) Gauss Cubic: thirdorder scheme that is suitable for the direct numerical simulation (dnsFoam) on a regular mesh.
Divergence schemes for Advection and Diffusion
In governing equations such as momentum, energy or species transport there are advection and diffusion terms. These terms are treated as divSchemes in Open FOAM. The nonadvective terms is generally interpolated with the Gauss integration considering a linear variation
 Upwind: This is a firstorder bounded scheme
 Linear: this scheme is based on secondorder, unbounded.
 Linear Upwind: secondorder, upwindbiased, unbounded (but much less so than linear). For this discretization, velocity gradients need to be specified
 LUST (Linear Upwind Stabilised Transport) : This scheme is a 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 that 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.
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 selfcontained piece of code or custom 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 the field of input data is given in a file createFields.H
Structure of Application in OpenFOAM
We can consider the sonicFoam application as an example of application directory This application can be found at:
The toplevel 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
Compilation of Application using the wmake command
For the compilation of a new application, the directory should have a Make subdirectory that contains 2 files: options and files. The wmake command is used to compile a modified application.
There are several files (*.C and *.H) that are given in a particular directory of applications. 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 are given in the folder: “ Make/options” file using the following syntax:
EXE_INC = \ I$(LIB_SRC)/finiteVolume/lnInclude
Implementation of Governing Equations in OpenFOAM
Mass, Momentum, and Energy Equation in OpenFOAM
 The conservation of mass, momentum, and energy equations are presented in OpenFOAM as follows
 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.
Implementation of Compressible Flow solver (rhoSonicFoam)
 The conservation of equations for compressible flow in OpenFOAM are presented as
Pressure and Velocity Coupling in OpenFOAM
SemiImplicit Method for PressureLinked 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 (NavierStokes) equations during iterative procedure, which is given as below
 set the domain with boundary conditions
 Solve numerically the discretized momentum equation to calculate the intermediate velocities
 Calculate the mass fluxes at the cells faces.
 Solve the pressure corrected equation and apply underrelaxation factors
 Correct the mass fluxes for all the cell faces.
 Correct the velocity fields based on new pressure fields
 Update the boundary conditions.
 Repeat above steps till convergence
PISO: PressureImplicit with Splitting of Operators
 This algorithm is more suitable to solve the NavierStokes equations in unsteady (transient) problems of CFD modeling
 It can support the worst mesh model
PIMPLE: a combination of SIMPLE and PISO
 This is more suitable to use adaptive steps with a fixed courant number in largeeddy simulations (LES)
 We can fix the courant number during the transient simulation
The PISO loop in OpenFOAM
Boundary Conditions in OpenFOAM
 Most the boundary conditions are defined based on a fixed value or fixed gradients
 It is important to understand these values before CFD modeling
 For details of boundary conditions: \src\finiteVolume\fields\fvPatchFields\
 There are major types of boundary conditions:
 Basic: calculated, fixed value, fixed gradient, zero gradient
 Constraint: symmetry, wedge, cyclic, jump, cyclic AMI
 Derived: slip, noslip, fan pressure, inletoutlet, outlet inlet, total pressure
Summary
 OpenFOAM is a finite volume method (FVM) based CFD solver. Its source code is freely available.
 Libraries of OpenFOAM are in C++ language and can be installed in Linux or windows where compiler
 OpenFOAM simulation comprises three parts: preprocessing, simulation using the CFD solver (application utilities), postprocessing
 This solver is easy to customize but it takes more time for new users
 Most CFD simulations can be carried in OpenFOAM
Reference
 Open FOAM downloads and details of solvers: www.openfoam.org
 OpenFOAM discussion forum: www.cfdonline.com/Forums/openfoam/)
 communitydriven wiki: www.openfoamwiki.net
 Open Foam Blog by Fumiaya Nozaki: Fumiya Nozaki
 Customization of CFD solvers: Chalmer University tutorials on OpenFOAM
ESIOpenCFD is pleased to announce the release of OpenFOAM v2006 (20 06) of the OpenFOAM open source CFD toolbox.