Boundary conditions are the single most error-prone part of any OpenFOAM setup. Wrong patch names, mismatched types, or physically inconsistent combinations cause divergence, non-convergence, and subtly wrong results that are hard to detect. This guide covers every essential BC type with real dictionary examples and explains the most common mistakes.
Every OpenFOAM boundary condition is either a Dirichlet (value prescribed) or a Neumann (gradient prescribed) condition, or a combination. The framework expresses these through the type keyword in each patch entry of your field files (0/U, 0/p, etc.).
fixedValue prescribes an exact value at the boundary. Use it for velocity at inlets (when you know the inlet velocity), and for pressure at outlets.
// 0/U — inlet patch
inlet
{
type fixedValue;
value uniform (10 0 0); // 10 m/s in x-direction
}
For pressure, fixedValue 0 at the outlet is standard for incompressible flows — pressure is gauge, and the outlet is the reference point.
zeroGradient sets the normal gradient to zero, meaning the field is extrapolated from the interior. Use it at outlets for velocity (the flow develops naturally) and at inlets for pressure (no pressure gradient imposed at the inlet face).
// 0/p — inlet patch
inlet
{
type zeroGradient;
}
// 0/U — outlet patch
outlet
{
type zeroGradient;
}
noSlip is shorthand for fixedValue uniform (0 0 0) for velocity. Use it on all solid walls. It sets U = 0 at the wall surface (no-slip condition).
// 0/U — wall patch
walls
{
type noSlip;
}
The most common divergence trigger is using fixedValue for pressure at both inlet and outlet simultaneously, while also fixing velocity at the inlet. This over-constrains the system. The correct pairings are:
If you want to drive the flow with a pressure difference instead of a velocity, flip this: set fixedValue for pressure at inlet, fixedValue at outlet (different values), and zeroGradient for velocity at both.
inletOutlet is a mixed condition that behaves as zeroGradient when flow is leaving the domain (normal outflow) and as fixedValue when flow reverses (backflow). It prevents unphysical backflow from destabilising the solution.
// 0/U — outlet with possible recirculation
outlet
{
type inletOutlet;
inletValue uniform (0 0 0);
value uniform (0 0 0);
}
Use inletOutlet for U whenever your outlet is close to a recirculation zone or the flow direction is uncertain.
totalPressure specifies the total (stagnation) pressure at a boundary. It is appropriate for inlets where you know the upstream total pressure rather than the velocity magnitude — common in fan or compressor inlet modelling.
// 0/p — pressure-driven inlet
inlet
{
type totalPressure;
p0 uniform 101325; // total pressure in Pa
value uniform 101325;
}
// Paired U condition at the same inlet
inlet
{
type pressureInletOutletVelocity;
value uniform (0 0 0);
}
pressureInletOutletVelocity must be used for U when totalPressure is used for p — it derives the velocity from the computed pressure field.
For external aerodynamics and wind engineering, the atmospheric boundary layer (ABL) inlet gives a logarithmic wind profile consistent with the turbulence model. Available in OpenFOAM v2006+.
// 0/U — ABL inlet
inlet
{
type atmBoundaryLayer;
flowDir (1 0 0);
zDir (0 0 1);
Uref 10; // reference speed at Zref height
Zref 10; // reference height in metres
z0 uniform 0.01; // roughness length
d uniform 0; // displacement height
value uniform (10 0 0);
}
The same BC type is used for k and epsilon at the ABL inlet — atmBoundaryLayerInletK and atmBoundaryLayerInletEpsilon — to keep the turbulence profile consistent with the velocity profile.
When using high-Reynolds-number turbulence models (kEpsilon, kOmegaSST with coarse near-wall mesh), the near-wall region is modelled rather than resolved. Wall function BCs replace the standard no-slip approach for turbulence quantities on wall patches.
// 0/k — wall patch
walls
{
type kqRWallFunction;
value uniform 0.0;
}
// 0/epsilon — wall patch
walls
{
type epsilonWallFunction;
value uniform 0.0;
}
// 0/omega — wall patch
walls
{
type omegaWallFunction;
value uniform 1.0;
}
// 0/nut — wall patch (high-Re)
walls
{
type nutkWallFunction;
value uniform 0.0;
}
// 0/nut — wall patch (low-Re, resolved boundary layer, y+ ~ 1)
walls
{
type nutLowReWallFunction;
value uniform 0.0;
}
The rule: if your first cell centre is at y+ > 30 use wall functions (nutkWallFunction, kqRWallFunction, epsilonWallFunction). If y+ ≈ 1 and the boundary layer is resolved, use nutLowReWallFunction and set k and omega/epsilon to zero at the wall.
A common source of solver warnings and wrong results is using a wildcard default of zero for k or epsilon at inlet patches. Use physically consistent values based on a turbulence intensity estimate:
// Turbulence intensity I = 0.05 (5%), length scale L = 0.01 m
// U_ref = 10 m/s
// k = 1.5 * (U_ref * I)^2 = 1.5 * (10 * 0.05)^2 = 0.375
// epsilon = C_mu^0.75 * k^1.5 / L = 0.09^0.75 * 0.375^1.5 / 0.01 = ~14.9
// omega = k^0.5 / (C_mu^0.25 * L) = ~65
// 0/k — inlet
inlet
{
type fixedValue;
value uniform 0.375;
}
// 0/epsilon — inlet
inlet
{
type fixedValue;
value uniform 14.9;
}
While zeroGradient is commonly used for pressure at wall patches, the technically correct BC is fixedFluxPressure. It adjusts the pressure gradient normal to the patch so that it is consistent with the prescribed velocity flux — which is zero at a no-slip wall, but non-zero at a moving wall or a rotating boundary.
// 0/p — wall patch (recommended in OpenFOAM v2012+)
walls
{
type fixedFluxPressure;
value uniform 0;
}
The practical difference between fixedFluxPressure and zeroGradient is small for most incompressible cases, but fixedFluxPressure is more robust with non-orthogonal meshes and rotating boundaries where the flux is not trivially zero.
Periodic boundary conditions require cyclic patches defined in pairs in the mesh. The two patches must have the same number of faces and be geometrically matched. For non-conformal periodic interfaces (different mesh densities, or when the two patches are not co-planar), use cyclicAMI (Arbitrary Mesh Interface).
// constant/polyMesh/boundary — cyclic pair definition
periodicLeft
{
type cyclic;
nFaces 1000;
startFace 500000;
matchTolerance 0.0001;
neighbourPatch periodicRight;
}
periodicRight
{
type cyclic;
nFaces 1000;
startFace 501000;
matchTolerance 0.0001;
neighbourPatch periodicLeft;
}
// 0/U — cyclic patches require "cyclic" type in field files
periodicLeft
{
type cyclic;
}
periodicRight
{
type cyclic;
}
For cyclicAMI interfaces (rotating machinery, sliding meshes), replace the type in both the boundary file and the field files with cyclicAMI. The transformType keyword must match the geometry transformation (rotational or translational).
mappedFixed (or mappedFixedValue) samples the field values at one patch and maps them onto another patch at the same time step. The classic use case is the recycling inlet technique for turbulent channel flow: map the outlet velocity profile back to the inlet to generate a fully developed turbulent inflow without running a separate precursor simulation.
// 0/U — recycling inlet (maps outlet profile to inlet)
inlet
{
type mappedFixedValue;
fieldName U;
setAverage true;
average (10 0 0); // rescale to maintain bulk velocity
value uniform (10 0 0);
}
The corresponding patch in constant/polyMesh/boundary must be of type mappedPatch and specify the offset vector and sample mode. This avoids the computational cost of a separate turbulent inflow generator.
Patch names in your field files (0/U, 0/p, etc.) must exactly match the patch names in your mesh (constant/polyMesh/boundary). OpenFOAM will silently apply the defaultFaces condition to unrecognised patches, which is almost always wrong. Always run checkMesh and compare patch names carefully — case matters.
If a patch exists in the mesh but is missing from a field file, OpenFOAM uses the defaultFaces entry. For internal patches (processor boundaries) this is fine, but for physical boundaries it is a bug. Make every physical patch explicit in every field file.
Setting fixedValue pressure at the inlet (e.g. 101325 Pa) and fixedValue pressure at the outlet (e.g. 0 Pa) while also prescribing a velocity at the inlet over-constrains the problem. This leads to large pressure residuals that never converge. Choose: either prescribe U at inlet (and use zeroGradient for p at inlet), or prescribe p at inlet (and use pressureInletOutletVelocity for U at inlet).
2D cases require patches to be of type empty in the mesh and field files. If the mesh has an empty patch but the field file uses zeroGradient, OpenFOAM will crash immediately. Similarly, cyclic patches require matching patch pairs defined in the mesh.
Many BC types require an initial value keyword even if the type computes the value internally (e.g. calculated, inletOutlet, omegaWallFunction). Omitting it produces a runtime error like "Entry 'value' not found". Always include a reasonable initial value entry even when it will be overwritten at runtime.
Upload your 0/ folder and CFDpilot flags type mismatches, missing patches, and physically inconsistent values.
Check my BCs →At a velocity-driven inlet, set U to fixedValue and p to zeroGradient. At a pressure-driven inlet, set p to totalPressure and U to pressureInletOutletVelocity. Never prescribe fixedValue for both U and p at the same patch — this over-constrains the system and causes divergence.
Use inletOutlet whenever your outlet is close to a recirculation zone or the flow direction is uncertain. zeroGradient applies a zero normal gradient regardless of flow direction; inletOutlet switches to fixedValue (typically zero velocity) when backflow is detected, preventing unphysical values from entering the domain.
Use nutkWallFunction when your first cell y+ is between 30 and 300 (high-Re wall treatment). Use nutLowReWallFunction when y+ is approximately 1 and you are resolving the boundary layer. kOmegaSST's omegaWallFunction handles both regimes internally for omega.
Use turbulence intensity I and a length scale L. For k: k = 1.5 * (U_ref * I)^2. For epsilon: epsilon = C_mu^0.75 * k^1.5 / L, where C_mu = 0.09. For omega: omega = k^0.5 / (C_mu^0.25 * L). A turbulence intensity of 5% is typical for most industrial flows.
Patch names in field files must exactly match names in constant/polyMesh/boundary. OpenFOAM silently falls back to the defaultFaces condition for unrecognised patch names. Always run checkMesh, ensure patch names are case-sensitive matches, and verify every physical patch is explicitly listed in each field file.
fixedFluxPressure is the technically correct pressure BC at walls. It adjusts the pressure gradient to be consistent with the velocity flux through the patch (zero at a no-slip wall). Using zeroGradient for pressure at walls is common but less accurate. fixedFluxPressure is recommended in recent OpenFOAM versions, especially on non-orthogonal meshes.