Introduction to OpenFOAM
Theory: case structure, time step and mesh choices
Overview
I want to start OpenFOAM but hear there's no GUI. Where should I begin?
By running one official tutorial unchanged. OpenFOAM represents an analysis as a folder called a case containing three folders: 0/ holds initial values and boundary conditions for each variable (velocity U, pressure p); constant/ holds properties (such as viscosity) and the mesh; system/ holds run time and output (controlDict), discretisation (fvSchemes), linear solvers (fvSolution) and mesh generation (blockMeshDict). Start by copying the cavity case (a square box whose lid alone moves), build the mesh with blockMesh, solve with icoFoam and view in ParaView. Once that runs, change one setting at a time and watch the results. Without a GUI, every setting stays as text, which makes comparison and automation easy.
Reynolds number, Courant number and cost
U is the reference speed (lid speed), L the reference length (cavity side), ν kinematic viscosity, Δt time step, Δx cell size and N divisions per side. icoFoam is a transient incompressible laminar solver that couples pressure and velocity with the PISO algorithm.
From a London lab to the world
OpenFOAM's forerunner FOAM was developed at Imperial College London in the 1990s as a C++ library for writing partial differential equations much as they look on paper. After its open-source release in 2004, use spread rapidly through industry and academia. Solver code that reads almost like the governing equations is why researchers find it easy to add their own models.
Worked examples
Example 1: viscosity and Reynolds number (1 m/s lid, 0.1 m side)
| Viscosity ν | Reynolds number | Viscous diffusion time L²/ν |
|---|---|---|
| 0.01 m²/s | 10 | 1 s |
| 0.001 m²/s | 100 | 10 s |
| 0.0001 m²/s | 1,000 | 100 s |
The tutorial uses ν = 0.01 (Re = 10) with an end time of 0.5 s.
Example 2: mesh density and cost (Co = 1, to 0.5 s)
| Mesh | Cell size | Time step | Steps | Cells | Cost (20×20 = 1) |
|---|---|---|---|---|---|
| 20×20 | 0.0050 m | 0.0050 s | 100 | 400 | 1 |
| 40×40 | 0.0025 m | 0.0025 s | 200 | 1,600 | 8 |
| 80×80 | 0.00125 m | 0.00125 s | 400 | 6,400 | 64 |
To get Re = 1000, can I just change viscosity to 0.0001?
Not enough on its own. Higher Re brings small corner eddies and steep near-wall gradients that 20×20 cannot capture; refine to at least about 80×80 and shrink the time step to keep the Courant number below 1. The flow also takes longer to settle: the rough time for viscosity to spread momentum across the box, L²/ν, is 1 s at Re = 10 but 100 s at Re = 1000, so stopping at 0.5 s shows only a transient state. Extend endTime and use results only after the centreline velocity profile stops changing. At Re = 1000 always check mesh convergence too. The cavity has detailed reference data (the tables of Ghia et al.), the ideal first verification.
Getting started
- Copy the tutorial cavity case to a working folder.
- Build the mesh with blockMesh and check quality with checkMesh.
- Solve with icoFoam and check residuals and Courant number in the log.
- View velocity and pressure in ParaView (paraFoam or foamToVTK).
- Change one setting at a time and verify against reference data.
“A first modification that diverged at once”
A common next step after the tutorial runs is to refine the mesh and run again. One student went to 40×40 and the run diverged immediately; the log showed a Courant number near 2, because the cell size had halved while the time step stayed at 0.005 s. Halving the time step to 0.0025 s fixed it. OpenFOAM can also adjust the time step automatically via adjustTimeStep and a maximum Courant number in controlDict.
Common mistakes
Mistakes and fixes
| Mistake | Effect | Fix |
|---|---|---|
| Refining mesh only | Divergence from high Courant number | Reduce time step too |
| Higher Re, same end time | Viewing a transient | Confirm steady state |
| Mismatched patch names | Error at start-up | Match names in 0/ and mesh |
| Skipping checkMesh | Divergence from bad cells | Check quality |
| No reference comparison | Errors unnoticed | Verify on benchmarks |
I'd like to learn related topics.
Related pages include OpenFOAM meshing, OpenFOAM parallel computing, lid-driven cavity, PISO algorithm and SU2 CFD solver.
Related Topics
Experience the theory firsthand with the interactive simulator for this field
All Simulators