grokkingstuff Home Blog Projects Wiki Calculators About

OpenFOAM Case Setup — Dictionaries, BCs, and Turbulence Configuration

#+CATEGORY: openfoam # :PROPERTIES: # :ID: uuid-openfoam-case-setup # :END:

OpenFOAM Case Setup :: Complete Configuration Guide

This note documents the complete directory structure and configuration files of an OpenFOAM case. Understanding the case setup is critical: the same solver can produce completely different results depending on how fvSchemes, fvSolution, and boundary conditions are configured. A misconfigured case is the #1 cause of simulation failure — not numerical instability (that's a symptom, not a cause), but incorrect physics through wrong boundary conditions or inappropriate turbulence models.

The case setup maps to the general conservation equation in Conservation Laws, which every solver solves. The solver is the mathematical engine; the case setup determines what physics the engine actually computes.

**Table of Contents**

Case Directory Structure :: Walk-Through of 0/, constant/, system/

An OpenFOAM case directory has three top-level subdirectories:

case/
├── 0/                    # Initial and boundary conditions (field data)
│   ├── U                 # Velocity field
│   ├── p                 # Pressure field
│   ├── alpha.water       # Volume fraction (for multiphase)
│   ├── k                 # Turbulent kinetic energy
│   ├── omega             # Specific dissipation rate
│   ├── T                 # Temperature (for energy equation)
│   └── ...
├── constant/             # Physics and mesh configuration
│   ├── polyMesh/         # Mesh files (points, faces, owner, neighbour, boundary)
│   │   ├── points
│   │   ├── faces
│   │   ├── owner
│   │   ├── neighbour
│   │   ├── internalFaces
│   │   └── boundary
│   ├── turbulenceProperties       # RANS/LES/DES
│   ├── transportProperties        # Dynamic viscosity, density
│   ├── thermophysicalProperties   # Cp, k (thermal conductivity), HRR
│   ├── radiationProperties        # Radiation model (if applicable)
│   ├── chemicalKinetics             # Chemistry (for reacting flow)
│   ├── combustionProperties         # Combustion model (if applicable)
│   └── ...
└── system/               # Numerical configuration
    ├── controlDict            # Time stepping, write intervals
    ├── fvSchemes              # Discretisation schemes
    ├── fvSolution             # Linear solvers, tolerances, algorithms
    ├── snapHexMeshDict        # Mesh generation (for snappyHexMesh)
    ├── blockMeshDict          # Mesh generation (for blockMesh)
    └── ...

controlDict :: Time Control and Execution Parameters

The controlDict file defines the solver type, time stepping, time range, and output frequency. It is analogous to Fluent's Solution Initialization and Run Duration settings, but text-file-based.

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}

application     simpleFoam;    // solver name — must match case name

startFrom       startTime;       // or: latestTime, system/controlDict
startTime       0;               // initial time (ignored if startFrom: latestTime)
stopAt          endTime;         // or: noOutput, runTime, clockTime
endTime         1000;            // final time
deltaT          1;               // timestep (for steady-state: irrelevant, usually set to 1)
writeControl    timeStep;        // or: runTime, adjustableRunTime, clockTime
writeInterval   100;             // write every N time steps
purgeWrite      0;               // keep all writes (0 = infinite)
purgeRemote     0;

writeFormat     binary;          // or: ascii, compressed
writeCompression compressed;
writePrecision  6;               // significant digits for field output
timeFormat      general;
timePrecision   6;

libs            ("libsimpleFoam.so");  // libraries to load

// Function objects — post-processing
functions
{
    // Calculate forces on "wall" patch
    forceCoeffs
    {
        type            forceCoeffs;
        libs            ("libforces.so");
        patchNames      (wall);
        liftDir         (0 1 0);
        dragDir         (1 0 0);
        pName           p;
        UName           U;
        rhoName         rhoInf;     // incompressible: rhoInf (constant)
        rhoInf          1000;       // density for force calculation
        CofR            (0 0 0);    // center of rotation
        pitchAxis       (0 0 0);
        referenceArea   1.0;        // reference area for non-dimensionalisation
    }
}

Function objects in controlDict are OpenFOAM's equivalent of Fluent's Monitors and Reports. They evaluate quantities at each write step and optionally write to postProcessing/ directories. The forceCoeffs function object is the direct analogue of Fluent's Surface Integrals → Force with non-dimensional coefficients.

fvSchemes :: Discretisation Scheme Specification

The fvSchemes file is the most important file for numerical accuracy. Every discretisation scheme is specified here, and each scheme choice directly affects accuracy, stability, and computational cost. This maps to Numerical Schemes theory.

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvSchemes;
}

// Time discretisation
ddtSchemes
{
    default         Euler;           // or: CrankNicolson 0.9 (second-order, with blending)
    // for steady-state: none
}

// Gradient schemes
gradSchemes
{
    default         Gauss linear;    // cellCenter gradient from cell-centered interpolation
    // for non-orthogonal meshes: corrected
    grad(p)         Gauss linear corrected;
    grad(U)         Gauss linear corrected;
}

// Divergence (convection) schemes — CRITICAL
divSchemes
{
    default         none;
    div(phi,U)      bounded Gauss linearUpwind Grad U;  // 2nd-order for momentum
    div(phi,k)      bounded Gauss upwind;                 // 1st-order for k (more stable)
    div(phi,omega)  bounded Gauss upwind;                 // 1st-order for omega (more stable)
    div(phi,alpha)  MULES interfIsoAdvector;              // VOF with MULES boundedness
    div(nuTilda)    bounded Gauss upwind;
    div((nuEff*dev2(T(grad(U)))))  Gauss linear;  // viscous stress
}

// Laplacian (diffusion) schemes
laplacianSchemes
{
    default         none;
    laplacian(nu,U)         Gauss linear corrected;      // laminar viscosity
    laplacian(nuEff,U)      Gauss linear corrected;      // turbulent + laminar viscosity
    laplacian(1,rho,p)      Gauss linear corrected;
    laplacian(Dt,T)         Gauss linear corrected;
}

// Interpolation schemes (for face values)
interpolationSchemes
{
    default         linear;
    interpolation(p)        linear;
    interpolation(U)        linear;
}

// Surface normal gradient schemes (for non-orthogonal diffusion correction)
snGradSchemes
{
    default         corrected;           // or: uncorrected (0th order), corrected (1st order)
}

// Flux correction schemes (for non-orthogonal correction)
fluxCorrectionSchemes
{
    default         none;
}

// Evaluation schemes (for derived fields like Q-criterion)
evaluationSchemes
{
    default         cellCell;
}

Key principles:

. Convective terms — momentum should be at least 2nd-order (linearUpwind) for accurate prediction of separation and drag. Passive scalars (k, omega) can be 1st-order upwind for stability, but this degrades accuracy significantly — linear or TVD is preferred for production runs. VOF (alpha) must use MULES for boundedness — without MULES, alpha will oscillate (overshoot > 1, undershoot < 0), causing instability.

. Diffusive terms — linear corrected is standard for non-orthogonal meshes. The "corrected" option applies a non-orthogonal correction (two-stage: orthogonal first, then correction for non-orthogonal face vectors). This is essential for mesh quality > 0.7 orthogonality (where 0.7 = |H·S| / |H| × |S|, with H the vector between cell centers and S the face area vector). For hexahedral meshes with orthogonality > 0.9, "uncorrected" is often adequate, but "corrected" is safer.

. Gradient schemes — linear corrected for p and U is standard. For non-orthogonal meshes, the "corrected" option is critical because it applies the non-orthogonal correction to the face gradient.

The fvSchemes file is OpenFOAM's way of implementing the theory in Numerical Schemes. Fluent achieves the same effect through the Solution Methods panel — selecting the same schemes (First-order upwind, Second-order upwind, Central differencing) but through a GUI.

fvSolution :: Linear Solver Specification and Algorithm Parameters

The fvSolution file defines: the linear algebra solvers (for each field), convergence tolerances, under-relaxation factors (SIMPLE/PISO), and PIMPLE parameters. This maps to Pressure-Velocity Coupling theory.

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvSolution;
}

solvers
{
    // Pressure equation (the most important solver)
    p_rgh
    {
        solver          GAMG;
        tolerance       1e-7;
        relTol          0.01;
        smoother        gaussSeidel;
        nPreSweeps      0;
        nPostSweeps     2;
        cacheAgglomeration true;
        agglomerator    faceAreaPair;
        nCellsInCoarsestLevel 10;
        mergeLevels     1;
    }

    // Momentum equation
    U
    {
        solver          smoothSolver;
        smoother        symGaussSeidel;
        tolerance       1e-8;
        relTol          0.1;
        maxIter         100;
    }

    // Turbulent kinetic energy
    k
    {
        solver          GAMG;
        tolerance       1e-8;
        relTol          0.1;
    }

    // Specific dissipation rate
    omega
    {
        solver          GAMG;
        tolerance       1e-8;
        relTol          0.1;
    }
}

PIMPLE
{
    nNonOrthogonalCorrectors  0;
    consistent                yes;

    // For steady-state (simpleFoam):
    pRefCell                  0;
    pRefValue                 0;

    // For transient (pimpleFoam):
    // nCorrectors             2;
    // nNonOrthogonalCorrectors 0;
    // momentumPredictor       yes;
}

relaxationFactors
{
    fields
    {
        p               0.3;     // Pressure under-relaxation (SIMPLE)
    }
    equations
    {
        U               0.7;     // Momentum under-relaxation
        k               0.5;
        omega           0.5;
        "(turbulent.*|muEff)" 0.7;  // turbulent properties
    }
}

Critical points:

. The pressure solver — GAMG (Geometric Multigrid) is the default and recommended solver for pressure in almost all OpenFOAM cases. GAMG convergence is typically faster than PBiCG or BiCGStab for the pressure Poisson equation on unstructured meshes. The tolerance 1e-7 is standard; relaxation factor 0.3 is necessary for SIMPLE.

. /Under-relaxation factors — the SIMPLE algorithm fails without them. The values p: 0.3, U: 0.7 are the standard starting point. If the simulation diverges, reduce p to 0.2 and U to 0.5. If convergence is too slow, increase U to 0.8 (but pressure should never exceed 0.4 for steady-state). This maps to Fluent's Solution Controls → Under-Relaxation Factors — same philosophy, GUI-driven instead of text-driven.

Boundary Conditions in 0/ :: BC Types and Selection

Each field in the 0/ directory has a boundary condition defined for each patch. BC selection directly controls physical behaviour — wrong BCs produce wrong results regardless of mesh quality or solver accuracy. See Boundary Conditions for theory.

/* 0/U */
dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);     // or: calculated; (from file)

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (10 0 0);  // velocity at inlet
    }

    outlet
    {
        type            inletOutlet;
        inletValue      uniform (0 0 0);
        value           uniform (0 0 0);    // zeroGradient for outflow
    }

    walls
    {
        type            noSlip;         // equivalent to fixedValue (0 0 0)
        // or: type fixedValue; value uniform (0 0 0);
    }

    frontAndBack
    {
        type            empty;          // for 2D simulations
    }
}
BC TypeOpenFOAMFluent EquivalentApplication
---------------------------------------------------
Dirichlet (value specified)fixedValuevelocity-inlet, pressure-inletInlet velocity, wall noSlip
Neumann (gradient specified)zeroGradientoutflow (zeroGradient), pressure-outlet (backflow)Outflow, symmetry
MixedinletOutletpressure-outlet (advective BC)Outlet with backflow protection
Fixed fluxfixedFluxPressurepressure-outletPressure BC for incompressible flow
Wall functionnutUSpaldingWallFunctionwall function (near-wall)RANS near-wall turbulence
SymmetrysymmetrysymmetryNo-slip across plane
Coupled (conformer)cyclicAMIperiodic, coupledAMI for rotating interfaces

The inletOutlet BC is particularly important: it is a zeroGradient (advection of outflow) when \vec{v} \cdot \hat{n} > 0 (flow out of the domain) and fixedValue (zero in the standard case) when \vec{v} \cdot \hat{n} < 0 (backflow into the domain). This is physically correct: you cannot impose a Dirichlet BC (fixed inflow profile) at an outlet — you impose it only when backflow occurs.

In Fluent, this is the pressure-outlet BC, which applies the same logic: zeroGradient for outflow, specified backflow values for backflow.

turbulenceProperties :: RANS/LES/DES Selection

The turbulenceProperties file defines the turbulence modelling approach:

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      turbulenceProperties;
}

simulationType  RAS;   // or: LES, DES, DDES, IDDES, LRR

RAS
{
    RASModel        kOmegaSST;  // Spalart-Allmaras, kEpsilon, kOmegaSST, ReynoldsStress
    turbulence      on;          // or: off (laminar)
    printCoeffs     on;          // print coefficients at startup
}
simulationTypeRASModelApplication
--------------------------------------
RASkOmegaSSTDefault for wall-bounded RANS
RASSpalartAllmarasExternal aerodynamics, aerospace
RASkEpsilonGeneral industrial flows, less wall-resolved
RASReynoldsStressStrong rotation/curvature, anisotropic turbulence
LESSmagorinskyHigh-Re separation, transitional flow
LESdynamicKEqnDynamic subgrid-scale
LESWALEWall-adapting local eddy-viscosity
DESIDDESDetached eddy simulation (hybrid RANS/LES)

The choice of turbulence model is the single most important physics decision in the simulation. kOmegaSST is recommended for 90% of engineering RANS simulations because it:

1. Integrates through the viscous sublayer (no wall function needed), with y+ ~ 1 at the first cell. If y+ > 30, switch to the wall-function variant. See Turbulence Models for detailed y+ discipline. 2. Captures adverse pressure gradient separation correctly (the SST correction limits the turbulent shear stress). 3. Blends k-omega (near walls) with k-epsilon (in free stream), avoiding the k-omega sensitivity to free-stream omega values at wall boundaries.

transportProperties :: Laminar Fluid Definition

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      transportProperties;
}

transportModel  Newtonian;

nu              nu [0 2 -1 0 0 0 0] 1e-05;     // kinematic viscosity (m²/s)

// For non-Newtonian (Power-Law):
// transportModel  powerLaw;
// nuCoeffs { K 0.01 n 0.7; }   // K = consistency index, n = power-law index

The dimensions = [0 2 -1 0 0 0 0] /m²/s/ for kinematic viscosity. For dynamic viscosity (\mu = \rho \times \nu), OpenFOAM uses muEff = \mu + \mu_t (laminar + turbulent viscosity), which is computed automatically when a turbulence model is active.

thermophysicalProperties :: Compressible Flow Thermodynamics

For compressible flow solvers (rhoSimpleFoam, rhoPimpleFoam, sonicFoam), the thermophysicalProperties file is mandatory. It defines the equation of state, specific heats, and thermal conductivity. The format is version-specific — the thermophysical model is part of OpenFOAM's multi-package architecture.

A typical perfect-gas compressible flow setup:

thermoType
{
    type            heRhoThermo;      // enthalpy-based, variable density
    mixture         singleComponent;  // single fluid (air, water, etc.)
    package         basicThermo;      // thermodynamic package
    equationOfState perfectGas;        // p = rho R T
    specie          specie;
    energy          enthalpy;
    equationOfState Hconst;              // constant Cp
    transport       const;                // constant thermal conductivity
    thermodynamics  hConst;              // constant Cp
    diffusion       constant;             // constant diffusivity
}
ParameterTypical value (air)Units
---------------------------------------
R (gas constant)287.05J/(kg·K)
Cp (specific heat)1005J/(kg·K)
Cv (specific heat)718J/(kg·K)
gamma (Cp/Cv)1.4dimensionless
mu (viscosity, Sutherland)1.716e-05 at 273KPa·s
k (thermal conductivity)0.02424W/(m·K)

The ideal gas law =\rho = p / (R T)/ couples density to pressure and temperature, which closes the system of governing equations for compressible flow. See Compressible Flow.

See Also :: Related Notes

. Conservation Laws — the equations every solver solves . Numerical Schemes — discretisation scheme theory . Pressure-Velocity Coupling — SIMPLE, PISO, PIMPLE . Boundary Conditions — BC types and selection . Turbulence Models — model selection, y+ discipline . Numerical Schemes in OpenFOAM — fvSchemes, ddtSchemes, divSchemes details . OpenFOAM Solver Selection — solver-to-physics mapping . OpenFOAM Multiphase Flows — VOF, alphaEqn, MULES . ANSYS Fluent Overview — Fluent GUI-based case setup comparison

References

. OpenFOAM User Guide. ESI OpenCFD. (fvSchemes/fvSolution reference.) . Weller, H.G. et al. (1998). "A tensorial approach to computational continuum mechanics." Comp. Phys.. (OpenFOAM API documentation.) . Versteeg, H.K. & Malalasekera, W. (2007). An Introduction to CFD. Chapter 8 (Turbulence modelling), Chapter 5 (Pressure-velocity coupling). . ANSYS Fluent Theory Guide. ANSYS Inc. (Fluent case setup comparison.)