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 Type | Description | Use Case |
| --------- | ------------- | ---------- |
| fixedValue | Prescribed value | Inlet velocity |
| zeroGradient | No normal gradient | Outlet (fully developed) |
| inletOutlet | fixedValue at inlet, zeroGradient at outlet | Outlet with possible backflow |
| outletInlet | zeroGradient at inlet, fixedValue at outlet | Rarely used |
| noSlip | Velocity = 0 at wall | Stationary walls |
| slip | Zero normal velocity, tangential stress-free | Symmetry planes, inviscid walls |
| movingWallVelocity | Wall moving at prescribed velocity | Rotating walls, moving belts |
| pressureInletOutletVelocity | Depends on flow direction | Pressure outlets |
| advective | Convective outflow | Large-domain outlets |
| cyclic | Periodic (paired patches) | Periodic repeating geometries |
Pressure Boundary Conditions
| BC Type | Description | Use Case |
| --------- | ------------- | ---------- |
| fixedValue | Prescribed pressure | Pressure inlet/outlet |
| zeroGradient | No normal pressure gradient | Outlet |
| totalPressure | Total (stagnation) pressure | Inlet with specified stagnation conditions |
| staticPressure | Static pressure | Inlets/outlets |
| inletOutlet | Depends on flow direction | Pressure outlets |
| cyclic | Periodic (paired patches) | Periodic domains |
| autoMixed | Automatic pressure outlet type | General 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:
- Flow out: zeroGradient
- Flow in: zeroVelocity (or fixedValue if specified)
Wall Functions
Wall functions serve the near-wall region. The mesh is too coarse there to resolve the viscous sublayer:
| BC Type | Description | y₊ Range |
| --------- | ------------- | ---------- |
| nutUSpaldingWallFunction | k-omega SST compatible | 30–300 |
| nutkWallFunction | Standard wall function | 30–300 |
| fixedValue (nut=0) | Low-Re (y₊ ~ 1) | ~1 |
| zeroGradient | Scalar 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 Type | Description | Use Case |
| --------- | ------------- | ---------- |
| fixedValue | Prescribed temperature | Inlet, heated wall |
| zeroGradient | No normal gradient | Adiabatic wall |
| mixed | Blended Dirichlet/Neumann | Convection 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 Type | Purpose |
| --------- | --------- |
| groovyBC | Expression-based BC (swak4Foam) |
| codedFixedValue | Custom C++ code embedded BC |
| externalCoupled | Coupled to external solver (FSI) |
| fanVelocity | Velocity BC for fans |
| fanPressure | Pressure BC for fans/blowers |
| fanPatch | Combined fan velocity/pressure BC |
| pulsatingUniformFixedValue | Time-varying inlet velocity |
| timeVaryingMappedFixedValue | Time-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
| Location | Field | Recommended BC |
| ---------- | ------- | --------------- |
| Inlet | U | fixedValue |
| Inlet | p | zeroGradient / totalPressure |
| Inlet | k, omega/epsilon | fixedValue (from turbulence intensity/length) |
| Outlet | U | inletOutlet zeroGradient |
| Outlet | p | fixedValue (usually atmospheric) |
| Wall | U | noSlip (stationary) / movingWallVelocity (moving) |
| Wall | p | zeroGradient |
| Wall | k, omega, epsilon | wallFunction (y₊ > 30) / fixedValue (y₊ ~ 1) |
| Symmetry | All | slip (velocity) / zeroGradient (scalars) |
| Periodic | All | cyclic / cyclicAMI |
| Far-field | All | inletOutlet + 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