| name | openfoam-cfd |
| description | Set up turbulent flow simulations in OpenFOAM with automated case generation |
| category | integrations |
| domain | fluids |
| complexity | advanced |
| dependencies | [] |
OpenFOAM CFD Integration
Overview
OpenFOAM (Open Field Operation and Manipulation) is a free, open-source CFD software package that provides a comprehensive suite of tools for solving complex fluid dynamics problems. It uses the finite volume method to discretize and solve partial differential equations describing fluid flow, heat transfer, turbulence, and chemical reactions.
Key Features
- Open Source: Licensed under GPLv3, completely free to use and modify
- Extensive Physics: Handles incompressible/compressible flows, multiphase, combustion, heat transfer
- Parallel Computing: Built-in support for MPI-based parallel processing
- Customizable: Written in C++, highly extensible for custom physics and solvers
- Industry Standard: Used in academia and industry for research and commercial applications
Architecture
OpenFOAM uses a case-based structure where each simulation is a self-contained directory with:
- Initial and boundary conditions
- Physical properties
- Numerical schemes
- Solver settings
- Mesh data
Installation
Ubuntu/Debian Installation
Option 1: Official Ubuntu Repository (Latest)
sudo sh -c "wget -O - https://dl.openfoam.org/gpg.key | apt-key add -"
sudo add-apt-repository http://dl.openfoam.org/ubuntu
sudo apt-get update
sudo apt-get install openfoam11
echo "source /opt/openfoam11/etc/bashrc" >> ~/.bashrc
source ~/.bashrc
Option 2: ESI-OpenCFD Version
sudo sh -c "wget -O - https://dl.openfoam.com/add-debian-repo.sh | bash"
sudo apt-get install openfoam2312-default
echo "source /usr/lib/openfoam/openfoam2312/etc/bashrc" >> ~/.bashrc
source ~/.bashrc
Option 3: Build from Source
sudo apt-get install build-essential cmake git ca-certificates \
flex libfl-dev bison zlib1g-dev libboost-system-dev \
libboost-thread-dev libopenmpi-dev openmpi-bin \
gnuplot libreadline-dev libncurses-dev libxt-dev \
qt5-default libqt5x11extras5-dev libqt5help5 qttools5-dev \
qtxmlpatterns5-dev-tools libqt5opengl5-dev freeglut3-dev \
libscotch-dev libcgal-dev
git clone https://github.com/OpenFOAM/OpenFOAM-11.git
cd OpenFOAM-11
source etc/bashrc
./Allwmake -j
Verify Installation
which simpleFoam
foamInstallationTest
mkdir -p $FOAM_RUN
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily $FOAM_RUN/
cd $FOAM_RUN/pitzDaily
blockMesh
simpleFoam
Install ParaView for Post-Processing
sudo apt-get install paraview
paraFoam
Case Directory Structure
Every OpenFOAM case follows a standardized directory structure:
caseDirectory/
├── 0/ # Initial and boundary conditions
│ ├── U # Velocity field
│ ├── p # Pressure field
│ ├── T # Temperature field (if applicable)
│ ├── k # Turbulent kinetic energy
│ ├── epsilon # Turbulent dissipation rate
│ ├── omega # Specific dissipation rate
│ └── nut # Turbulent viscosity
├── constant/ # Physical properties and mesh
│ ├── polyMesh/ # Mesh data
│ │ ├── points # Vertex coordinates
│ │ ├── faces # Face definitions
│ │ ├── owner # Cell ownership
│ │ ├── neighbour # Cell neighbors
│ │ └── boundary # Boundary patches
│ ├── transportProperties # Fluid properties
│ ├── turbulenceProperties # Turbulence model selection
│ ├── g # Gravity vector
│ └── regionProperties # Multi-region properties
├── system/ # Numerical settings
│ ├── controlDict # Simulation control
│ ├── fvSchemes # Discretization schemes
│ ├── fvSolution # Solver settings
│ ├── blockMeshDict # Mesh generation
│ ├── snappyHexMeshDict # Advanced meshing
│ ├── decomposeParDict # Parallel decomposition
│ └── sampleDict # Sampling/probing
└── [time directories]/ # Results at each time step
├── U
├── p
└── ...
Key Dictionaries
controlDict (system/controlDict)
Controls simulation execution and output:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
application simpleFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 1000;
deltaT 1;
writeControl timeStep;
writeInterval 100;
purgeWrite 2;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
forceCoeffs
{
type forceCoeffs;
libs ("libforces.so");
writeControl timeStep;
writeInterval 1;
patches (wall);
rho rhoInf;
rhoInf 1.225;
CofR (0 0 0);
liftDir (0 1 0);
dragDir (1 0 0);
pitchAxis (0 0 1);
magUInf 10;
lRef 1;
Aref 1;
}
probes
{
type probes;
libs ("libsampling.so");
writeControl timeStep;
writeInterval 1;
fields (p U);
probeLocations
(
(0.5 0.5 0.5)
(1.0 0.5 0.5)
);
}
}
fvSchemes (system/fvSchemes)
Defines discretization schemes:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSchemes;
}
ddtSchemes
{
default steadyState;
}
gradSchemes
{
default Gauss linear;
grad(p) Gauss linear;
grad(U) cellLimited Gauss linear 1;
}
divSchemes
{
default none;
div(phi,U) bounded Gauss linearUpwind grad(U);
div(phi,k) bounded Gauss upwind;
div(phi,epsilon) bounded Gauss upwind;
div(phi,omega) bounded Gauss upwind;
div((nuEff*dev2(T(grad(U))))) Gauss linear;
}
laplacianSchemes
{
default Gauss linear corrected;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default corrected;
}
wallDist
{
method meshWave;
}
fvSolution (system/fvSolution)
Solver algorithms and tolerances:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSolution;
}
solvers
{
p
{
solver GAMG;
tolerance 1e-6;
relTol 0.01;
smoother GaussSeidel;
nPreSweeps 0;
nPostSweeps 2;
cacheAgglomeration on;
agglomerator faceAreaPair;
nCellsInCoarsestLevel 10;
mergeLevels 1;
}
U
{
solver smoothSolver;
smoother GaussSeidel;
tolerance 1e-7;
relTol 0.1;
nSweeps 1;
}
"(k|epsilon|omega)"
{
solver smoothSolver;
smoother GaussSeidel;
tolerance 1e-8;
relTol 0.1;
nSweeps 1;
}
}
SIMPLE
{
nNonOrthogonalCorrectors 0;
consistent yes;
residualControl
{
p 1e-5;
U 1e-5;
"(k|epsilon|omega)" 1e-5;
}
}
PIMPLE
{
nOuterCorrectors 50;
nCorrectors 2;
nNonOrthogonalCorrectors 1;
residualControl
{
U 1e-5;
p 1e-5;
}
}
relaxationFactors
{
fields
{
p 0.3;
}
equations
{
U 0.7;
k 0.7;
epsilon 0.7;
omega 0.7;
}
}
transportProperties (constant/transportProperties)
Physical properties of fluids:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object transportProperties;
}
transportModel Newtonian;
nu [0 2 -1 0 0 0 0] 1e-05;
phases (water air);
water
{
transportModel Newtonian;
nu [0 2 -1 0 0 0 0] 1e-06;
rho [1 -3 0 0 0 0 0] 1000;
}
air
{
transportModel Newtonian;
nu [0 2 -1 0 0 0 0] 1.48e-05;
rho [1 -3 0 0 0 0 0] 1;
}
sigma [1 0 -2 0 0 0 0] 0.07;
turbulenceProperties (constant/turbulenceProperties)
Turbulence model selection:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object turbulenceProperties;
}
simulationType RAS;
RAS
{
RASModel kEpsilon;
turbulence on;
printCoeffs on;
}
LES
{
LESModel Smagorinsky;
turbulence on;
printCoeffs on;
delta cubeRootVol;
cubeRootVolCoeffs
{
deltaCoeff 1;
}
}
Boundary Conditions
Common Boundary Types
Velocity (U)
Fixed Value (Inlet)
inlet
{
type fixedValue;
value uniform (1 0 0);
}
Zero Gradient (Outlet)
outlet
{
type zeroGradient;
}
No Slip Wall
wall
{
type noSlip;
}
Slip Wall
symmetry
{
type slip;
}
Inlet with Profile
inlet
{
type codedFixedValue;
value uniform (0 0 0);
name parabolicVelocity;
code
#{
const fvPatch& boundaryPatch = patch();
const vectorField& Cf = boundaryPatch.Cf();
vectorField& field = *this;
forAll(Cf, faceI)
{
scalar y = Cf[faceI].y();
scalar H = 0.1;
scalar Umax = 1.5;
field[faceI] = vector(Umax * 4 * y * (H - y) / (H * H), 0, 0);
}
#};
}
Pressure (p)
Fixed Value (Outlet)
outlet
{
type fixedValue;
value uniform 0;
}
Zero Gradient (Inlet)
inlet
{
type zeroGradient;
}
Wall
wall
{
type zeroGradient;
}
Total Pressure (Inlet)
inlet
{
type totalPressure;
p0 uniform 101325;
U U;
phi phi;
rho none;
psi none;
gamma 1;
value uniform 101325;
}
Turbulence (k, epsilon, omega)
Inlet - Fixed Value
k_inlet
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.05;
value uniform 0.375;
}
epsilon_inlet
{
type turbulentMixingLengthDissipationRateInlet;
mixingLength 0.005;
value uniform 14.855;
}
omega_inlet
{
type turbulentMixingLengthFrequencyInlet;
mixingLength 0.005;
value uniform 440;
}
Wall Functions
k_wall
{
type kqRWallFunction;
value uniform 0.375;
}
epsilon_wall
{
type epsilonWallFunction;
value uniform 14.855;
}
omega_wall
{
type omegaWallFunction;
value uniform 440;
}
nut_wall
{
type nutkWallFunction;
value uniform 0;
}
Outlet
k_outlet
{
type zeroGradient;
}
epsilon_outlet
{
type zeroGradient;
}
omega_outlet
{
type zeroGradient;
}
Calculating Turbulence Parameters
For inlet conditions:
Turbulent intensity: I = u'/U = 0.16 * Re^(-1/8)
Turbulent kinetic energy: k = 3/2 * (U * I)²
Turbulent dissipation: ε = C_μ^(3/4) * k^(3/2) / L
Specific dissipation: ω = k^(1/2) / (C_μ^(1/4) * L)
Where:
- U = mean velocity
- Re = Reynolds number
- L = turbulent length scale ≈ 0.07 * characteristic_length
- C_μ = 0.09
Solver Selection
Incompressible Solvers
simpleFoam - Steady-state, incompressible, turbulent
- Applications: External aerodynamics, HVAC, industrial flows
- Algorithm: SIMPLE
- Speed: Fast convergence for steady problems
pimpleFoam - Transient, incompressible, turbulent
- Applications: Vortex shedding, transient flows, LES
- Algorithm: PIMPLE (merged PISO-SIMPLE)
- Speed: Good stability, handles large time steps
icoFoam - Transient, incompressible, laminar
- Applications: Low Reynolds number, educational
- Algorithm: PISO
- Speed: Fast for laminar flows
pisoFoam - Transient, incompressible, turbulent
- Applications: LES, DNS
- Algorithm: PISO
- Speed: Small time steps required
Multiphase Solvers
interFoam - VOF method, two immiscible fluids
- Applications: Free surface flows, sloshing, wave breaking
- Tracks interface between fluids
multiphaseInterFoam - VOF for multiple fluids
- Applications: More than two phases
twoPhaseEulerFoam - Eulerian-Eulerian multiphase
- Applications: Fluidized beds, bubbly flows
Compressible Solvers
rhoSimpleFoam - Steady-state, compressible, turbulent
- Applications: High-speed flows, compressible effects
rhoPimpleFoam - Transient, compressible, turbulent
- Applications: Transient compressible flows
sonicFoam - Transient, compressible, supersonic
- Applications: Supersonic flows, shock waves
Heat Transfer Solvers
buoyantSimpleFoam - Steady, buoyancy-driven
- Applications: Natural convection
buoyantPimpleFoam - Transient, buoyancy-driven
- Applications: Transient natural convection
chtMultiRegionFoam - Conjugate heat transfer
- Applications: Solid-fluid heat transfer
Mesh Generation
blockMesh - Structured Hex Meshes
Basic block mesh for rectangular domain:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
convertToMeters 1;
vertices
(
(0 0 0)
(1 0 0)
(1 1 0)
(0 1 0)
(0 0 0.1)
(1 0 0.1)
(1 1 0.1)
(0 1 0.1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
);
}
outlet
{
type patch;
faces
(
(1 2 6 5)
);
}
walls
{
type wall;
faces
(
(0 1 5 4)
(3 7 6 2)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);
mergePatchPairs
(
);
Execute: blockMesh
snappyHexMesh - Unstructured Hex-Dominant
For complex geometries from STL files:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object snappyHexMeshDict;
}
castellatedMesh true;
snap true;
addLayers true;
geometry
{
geometry.stl
{
type triSurfaceMesh;
name geometry;
}
}
castellatedMeshControls
{
maxLocalCells 100000;
maxGlobalCells 2000000;
minRefinementCells 0;
nCellsBetweenLevels 3;
features
(
{
file "geometry.eMesh";
level 2;
}
);
refinementSurfaces
{
geometry
{
level (2 2);
}
}
resolveFeatureAngle 30;
refinementRegions
{
}
locationInMesh (0.01 0.01 0.01);
allowFreeStandingZoneFaces true;
}
snapControls
{
nSmoothPatch 3;
tolerance 2.0;
nSolveIter 30;
nRelaxIter 5;
}
addLayersControls
{
relativeSizes true;
layers
{
geometry
{
nSurfaceLayers 3;
}
}
expansionRatio 1.2;
finalLayerThickness 0.3;
minThickness 0.1;
nGrow 0;
featureAngle 30;
nRelaxIter 3;
nSmoothSurfaceNormals 1;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.3;
minMedianAxisAngle 90;
nBufferCellsNoExtrude 0;
nLayerIter 50;
}
meshQualityControls
{
maxNonOrtho 65;
maxBoundarySkewness 20;
maxInternalSkewness 4;
maxConcave 80;
minVol 1e-13;
minTetQuality 1e-30;
minArea -1;
minTwist 0.02;
minDeterminant 0.001;
minFaceWeight 0.02;
minVolRatio 0.01;
minTriangleTwist -1;
nSmoothScale 4;
errorReduction 0.75;
}
debug 0;
mergeTolerance 1e-6;
Execute: snappyHexMesh -overwrite
Post-Processing with ParaView
Using paraFoam
paraFoam
paraFoam -builtin
touch case.foam
paraview case.foam
Common Visualization Tasks
-
Velocity Magnitude
- Filters → Calculator
- Result Array Name: UMag
- Formula:
mag(U)
-
Streamlines
- Filters → Stream Tracer
- Seed Type: Point Source or Line Source
- Vectors: U
-
Slice/Plane
- Filters → Slice
- Plane Parameters: Origin and Normal
-
Iso-surfaces
- Filters → Contour
- Select variable and values
-
Wall Shear Stress
- Filters → Calculator
- Formula:
nu * mag(wallShearStress)
Sampling and Data Extraction
Create system/sampleDict:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object sampleDict;
}
interpolationScheme cellPoint;
setFormat raw;
sets
(
centerline
{
type uniform;
axis distance;
start (0 0.5 0.05);
end (10 0.5 0.05);
nPoints 100;
}
);
surfaces
(
plane
{
type cuttingPlane;
planeType pointAndNormal;
pointAndNormalDict
{
point (0 0 0);
normal (0 0 1);
}
interpolate true;
}
);
fields (p U k epsilon);
Execute: postProcess -func sampleDict
Parallel Processing
Decompose Case
Create system/decomposeParDict:
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object decomposeParDict;
}
numberOfSubdomains 4;
method scotch;
simpleCoeffs
{
n (2 2 1);
delta 0.001;
}
hierarchicalCoeffs
{
n (2 2 1);
delta 0.001;
order xyz;
}
Run Parallel
decomposePar
mpirun -np 4 simpleFoam -parallel
reconstructPar
reconstructPar -latestTime
Workflow Summary
mkdir -p myCase/{0,constant,system}
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily/* myCase/
cd myCase
blockMesh
checkMesh
simpleFoam > log.simpleFoam 2>&1
foamMonitor -l postProcessing/residuals/0/residuals.dat
paraFoam
decomposePar
mpirun -np 4 simpleFoam -parallel
reconstructPar
Best Practices
- Mesh Quality: Always run
checkMesh before simulation
- Residuals: Monitor convergence (< 1e-4 for engineering accuracy)
- Courant Number: Keep Co < 1 for stability (transient cases)
- Y+ Values: 30-300 for wall functions, < 1 for resolved boundary layers
- Grid Independence: Perform mesh refinement studies
- Initialization: Use
potentialFoam for better initial velocity field
- Backup: Version control your case files with git
Troubleshooting
Common Issues
Mesh Check Fails
checkMesh
Divergence
- Reduce relaxation factors
- Improve initial conditions
- Refine mesh
- Reduce time step (transient)
Slow Convergence
- Check boundary conditions
- Adjust solver tolerances
- Use better preconditioners (GAMG for pressure)
Parallel Issues
decomposePar -cellDist
mpirun -np 2 hostname
Resources
See Also
examples/pipe-flow/ - Complete turbulent pipe flow case
examples/pump-impeller/ - Rotating machinery simulation
examples/scripts/ - Python case generation utilities
reference.md - Detailed dictionary and solver reference