When we started working with OpenFOAM, back in 2008, there was very little information available online. Things have changed in the meantime, but we still figured it would be useful for others as well as challenging and interesting for us to write a book about this great code. The book “The OpenFOAM Technology Primer” is a starting point for anyone interested in OpenFOAMand it additionally provides enough information on how to program using the OpenFOAM as a development framework for Computational Fluid Dynamics (CFD). This is what we came up with.
The OpenFOAM Technology Primer comes with example source code and simulation cases. We have tried our best to provide information on both the software design and numerical method background required when programming in OpenFOAM. The example code and simulation cases we have prepared ourselves, which makes the book a standalone source of information, and not a copy or reinterpretation of any other material available online. We hope the book will end up being at least as useful to others as much as it was fun for us to write. If you happen to have comments or complaints, feel free drop us an email, open a thread on the forum or comment on the FAQ page. We will be happy to receive any feedback that makes the book, the accompanying code, or the example cases better.
1. Computational Fluid Dynamics in OpenFOAM
3. Geometry Definition, Meshing and Mesh Conversion
Defining a geometry, mesh generation using blockMesh, generating meshes with snappyHexMesh and cfMesh, converting meshes from external formats. Generating axisymmetric meshes and using mesh modification utilities.
3. OpenFOAM Case Setup
An overview over the general case setup, including all essential dictionary files. Discussion of both boundary- and initial conditions, as well as how they are defined. A brief introduction to discretization schemes and solver control. The chapter closes with a tutorial on how solvers are executed in both serial and parallel.
4. Post-Processing, Visualization and Data Sampling
This chapter provides information on how the simulation data can be visualized, using both command line tools and paraView. In addition the reader is introduced to the usage of runtime sampling, which enables to gather relevant data with a high frequency, without wasting too much harddrive space.
5. Design Overview of the OpenFOAM Library
A structured overview of the OpenFOAM framework is provided in this chapter. A short introduction to Doxygen is given as well, covering the usage of the generated documentation as well as how to generate the documentation in the first place. Furtheron, the design of important building blocks of the library is discussed and illustrated, using hands-on tutorials.
6. Productive Programming in OpenFOAM
This chapter covers the important topics of code organization, debugging and profiling, especially in the context of the OpenFOAM library itself. A very short introduction to the git tool is provided as well, though the reader is referred to literature, specific to that tool for more in-depth information. The chapter concludes with a guide to install OpenFOAM on a HPC system.
7. Turbulence Modelling
It is impossible to cover turbulence modelling in a single chapter. Rather than describing the background, the reader is referred to specific literature. Various turbulence models and their implementations in OpenFOAM are discussed, and the reader’s attention is raised towards different pitfalls.
8. Writing Pre- and Post-Processing Applications
This chapter introduces the reader to the development of novel pre- and postprocessing applications from scratch, including the steps requried to generate an empty application skeleton, that can be compiled straight away.
The examples provided for the preprocessing step include the usage of various shell scripts to automate a parallel computation using mpi as well as how to create a parameter variation using PyFoam.
The chapter closes with a post-processing application that calculates the surface area of a bubble and it’s velocity, using an iso-surface.
9. Solver Customization
Designing a new solver from scratch is explained in this chapter. At the beginning of the chapter, some of the existing solvers of the interFoam-family are inspected closely. After this discussion, a new transport equation is added to interFoam, which includes reading data from a dictionary and creating a new field with the object registry.
10. Boundary Conditions
Boundary conditions and the incorrect usage of them are one of the most prominent source of error in a CFD computation. This chapter deals with boundary conditions in an all-embracing fashion. The numerical background is provided, followed by an thorough discussion of the boundary condition’s design from a programming point of view. The chapter ends with examples of how to change existing boundary conditions and create new ones.
11. Transport Models
Transport models in OpenFOAM provide an easy access to the viscosity during runtime and make them runtime selectable. This means that it is possible to alter the flow model (e.g. newtonian to non-newtonian), without the need to recompile the solvers. The entire design of this part of the OpenFOAM library is covered in this chapter.
12. Function Objects
This chapter provides a starting point to working with OpenFOAM function objects. The design is discussed quite extensively, by drawing parallels to C++ function objects. After the working principles have been outlined, the usage of function objects is shown by using some minimal examples. The chapter closes with the development of a custom function object.
13. Dynamic Mesh
Dynamic meshes are a complex and poorly documented part of the OpenFOAM library. This chapter deals with the basic usage of dynamic meshes of different kinds, such as dynamic mesh refinement and mesh morphing. The working principles with respect to the design are explained and a custom dynamic mesh is developed, that combines dynamic mesh refinement and mesh motion.