grokkingstuff Home Blog Projects Wiki Calculators About

OpenFOAM Boundary Conditions

#+CATEGORY: openfoam

OpenFOAM Boundary Conditions :: Types, Implementation, and Best Practices

Boundary conditions (BCs) in OpenFOAM are specified as boundaryField entries in each field file within the 0/ directory (or in time directories for restarts). The type of each patch is chosen from OpenFOAM's extensive library of boundary condition types. The correct BC type and parameters are critical. Wrong BCs produce wrong solutions. Always check mesh quality and solver robustness.

OpenFOAM's boundary condition system is a strength. It offers over 100 built-in BC types. You extend it through user-defined BCs. Each BC type inherits from the base fvPatchField class. Each type implements logic to fix values, specify gradients, or compute values from field data.

BC Types by Physical Category

Velocity Boundary Conditions

BC TypeDescriptionUse Case
--------------------------------
fixedValuePrescribed valueInlet velocity
zeroGradientNo normal gradientOutlet (fully developed)
inletOutletfixedValue at inlet, zeroGradient at outletOutlet with possible backflow
outletInletzeroGradient at inlet, fixedValue at outletRarely used
noSlipVelocity = 0 at wallStationary walls
slipZero normal velocity, tangential stress-freeSymmetry planes, inviscid walls
movingWallVelocityWall moving at prescribed velocityRotating walls, moving belts
pressureInletOutletVelocityDepends on flow directionPressure outlets
advectiveConvective outflowLarge-domain outlets
cyclicPeriodic (paired patches)Periodic repeating geometries

Pressure Boundary Conditions

BC TypeDescriptionUse Case
--------------------------------
fixedValuePrescribed pressurePressure inlet/outlet
zeroGradientNo normal pressure gradientOutlet
totalPressureTotal (stagnation) pressureInlet with specified stagnation conditions
staticPressureStatic pressureInlets/outlets
inletOutletDepends on flow directionPressure outlets
cyclicPeriodic (paired patches)Periodic domains
autoMixedAutomatic pressure outlet typeGeneral pressure outlets

Total Pressure BC

The totalPressure BC imposes the total (stagnation) pressure relationship at the boundary:

At the inlet, the relationship is:

If flow reverses (outlet), the BC automatically switches to zeroGradient for static pressure.

Outlet Boundary Conditions

The inletOutlet BC is common for outlets where backflow is possible:

If flow leaves → zeroGradient (outlet behavior) If flow enters (backflow) → inletValue (Dirichlet)

pressureInletOutletVelocity applies similar logic to velocity at pressure outlets:

Wall Functions

Wall functions serve the near-wall region. The mesh is too coarse there to resolve the viscous sublayer:

BC TypeDescriptiony₊ Range
--------------------------------
nutUSpaldingWallFunctionk-omega SST compatible30–300
nutkWallFunctionStandard wall function30–300
fixedValue (nut=0)Low-Re (y₊ ~ 1)~1
zeroGradientScalar at wall (T, etc.)Any

The mesh cannot resolve the viscous sublayer in the near-wall region. Wall functions replace the near-wall turbulence model equations with empirical profiles called the law of the wall. The wall functions provide a boundary condition for turbulent viscosity (nut) and turbulent kinetic energy (k). The boundary condition is based on the local wall shear stress.

Wall Functions for Turbulence

For k-omega SST with wall functions (nutUSpaldingWallFunction):

For low-Re simulation (y₊ ~ 1):

Temperature and Scalar BCs

BC TypeDescriptionUse Case
--------------------------------
fixedValuePrescribed temperatureInlet, heated wall
zeroGradientNo normal gradientAdiabatic wall
mixedBlended Dirichlet/NeumannConvection BC (Newton's law of cooling)

For mixed BC, the temperature is computed as:

Periodic BCs

The cyclic family of BCs couples periodic (or transformed-periodic) patches. For simple periodic flow (no transformation):

For cyclicAMI (non-matching periodic patches), the Arbitrary Mesh Interface (AMI) interpolation maps fields between non-conformal patches:

Derived (Function) BCs

Derived BCs compute values from field data or other BCs:

BC TypePurpose
------------------
groovyBCExpression-based BC (swak4Foam)
codedFixedValueCustom C++ code embedded BC
externalCoupledCoupled to external solver (FSI)
fanVelocityVelocity BC for fans
fanPressurePressure BC for fans/blowers
fanPatchCombined fan velocity/pressure BC
pulsatingUniformFixedValueTime-varying inlet velocity
timeVaryingMappedFixedValueTime-varying mapped inlet from data

The groovyBC type (if swak4Foam is installed) allows specifying BCs using arbitrary mathematical expressions evaluated at runtime:

empty BC

The empty BC is for 2D planar simulations (no variation in the spanning direction):

The empty patch gives the field zero thickness. The field has no normal flux. This reduces the PDE to 2D.

BC Selection Guide

LocationFieldRecommended BC
--------------------------------
InletUfixedValue
InletpzeroGradient / totalPressure
Inletk, omega/epsilonfixedValue (from turbulence intensity/length)
OutletUinletOutlet zeroGradient
OutletpfixedValue (usually atmospheric)
WallUnoSlip (stationary) / movingWallVelocity (moving)
WallpzeroGradient
Wallk, omega, epsilonwallFunction (y₊ > 30) / fixedValue (y₊ ~ 1)
SymmetryAllslip (velocity) / zeroGradient (scalars)
PeriodicAllcyclic / cyclicAMI
Far-fieldAllinletOutlet + fixedValue as appropriate

Summary

1. Specify BCs per-patch per-field in 0/<field> files 2. Match the BC type to the physical reality. Use fixedValue for prescribed values, zeroGradient for fully-developed outlets, and wallFunction for wall treatment 3. Use totalPressure at inlets with specified stagnation conditions 4. Use inletOutlet for outlets where backflow is possible 5. The wallFunction BC types are required when y+ > 30 for high-Re RANS. Use fixedValue with y+ ~ 1 for low-Re RANS or LES 6. The empty BC reduces 3D simulations to 2D

See Also