Computational Fluid Dynamics (CFD) simulations rely on the precise definition of boundary and initial conditions to accurately model physical phenomena. In the OpenFOAM environment, these conditions are critical for ensuring that the solver behaves correctly, as ill-posed combinations can lead to physically incorrect predictions or solver failure. The boundary conditions define the behavior of the fluid at the edges of the computational domain, essentially telling the solver how to handle variables like velocity and pressure at the mesh patches. This article provides a comprehensive overview of how to set boundary conditions in OpenFOAM, drawing on established practices and documentation.
Understanding the Role of Boundary Conditions
In the absence of sources and sinks, system behavior is driven by its boundary conditions. These form a critical aspect of case specification where ill-posed combinations will lead to physically incorrect predictions, and in many cases, solver failure. The boundary conditions are specified in field files, such as p (pressure) and U (velocity), within each time directory. The structure of these files includes three key entries: dimensions for the dimensional units, internalField for the initial internal field values, and boundaryField where the boundary conditions are specified for each mesh patch.
The boundaryField is a sub-dictionary containing an entry for every patch in the mesh. Each entry begins with the patch name and configures the boundary condition through entries in a sub-dictionary. A type entry is required for every patch, which specifies the type of boundary condition. For example, common types include zeroGradient and fixedValue for generic patches, as well as constraint types like symmetry and empty that correspond to equivalent patch definitions in the mesh geometry.
The patches themselves are defined in the constant/polyMesh/boundary file, which is a very important file for boundary conditions. This file lists all boundary patches, their types (e.g., wall, inlet, outlet, symmetry, empty), and geometric information such as the number of faces and the starting face index. The physical understanding of the phenomenon being modeled is paramount when selecting and defining these conditions.
Common Boundary Condition Types and Their Applications
OpenFOAM offers a wide range of boundary conditions, grouped according to their function: constraints (e.g., for 2-D or axisymmetric geometries), general conditions, inlet conditions, outlet conditions, wall conditions, and coupled conditions (e.g., cyclic). The selection of a specific condition depends on the physical situation at the boundary. For instance, a moving wall would require a different condition than a fixed, solid wall.
Fixed Value and Zero Gradient
Two of the most fundamental boundary conditions are fixedValue and zeroGradient.
fixedValue: This condition imposes a constant, uniform value for a field at the boundary. It is used when the value at the boundary is known and must be held constant. For example, specifying a constant inlet velocity or a fixed wall temperature.zeroGradient: This condition sets the normal gradient of the field to zero at the boundary. It allows the field value to adjust naturally at the boundary while preventing an abrupt change across it. This is commonly used for outlets where the flow is assumed to be fully developed, or for walls in certain flow scenarios.
Other Important Boundary Condition Types
Beyond these basics, several other conditions serve specific purposes:
slipandnoSlip: These are wall conditions.slipis used for frictionless walls where the tangential velocity component is zero, whilenoSlipis used for solid walls where both tangential and normal velocity components are zero (i.e., the fluid sticks to the wall).pressureInletOutletVelocity: This condition is often used for outlets where pressure is specified, and the velocity is calculated to satisfy the continuity equation.symmetry: Used for symmetry planes, where the field gradient normal to the boundary is zero, and the tangential components are mirrored.empty: Used for 2D simulations where the front and back faces of the mesh are defined as empty patches, meaning no flow occurs in the third direction.
Example Configuration
A typical boundary field configuration for a 2D incompressible flow might look like this:
boundaryField
{
inlet
{
type zeroGradient;
}
outlet
{
type fixedValue;
value uniform 0;
}
up
{
type symmetry;
}
hole
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
In this example, the inlet uses zeroGradient, the outlet is a fixedValue of zero (often for pressure), the up patch is a symmetry plane, and frontAndBack are empty patches for a 2D simulation.
Customizing Boundary and Initial Conditions
While OpenFOAM provides a wide range of native boundary conditions, some applications require customized approaches. For new OpenFOAM users, one of the simple ways to customize boundary conditions and initial conditions is by using the codeStream utility.
codeStream is part of OpenFOAM and is often simpler than high-level programming, which requires more knowledge about OpenFOAM and C++. It allows users to embed C++ code directly into the case configuration to define non-uniform fields or complex boundary behaviors. For initial conditions, the setFields utility can also be used to define non-uniform fields.
Other methods for customization include using external libraries, such as swak4foam, or high-level programming. However, codeStream is frequently the simplest method for implementing user-defined boundary or initial conditions because it is integrated into OpenFOAM and avoids the complexity of external libraries or deep programming knowledge.
Best Practices and Troubleshooting
A successful simulation setup begins with a clear understanding of the physical phenomena. The user must know what is happening at each boundary to select the appropriate condition type. For example, for a case with a moving top wall and fixed solid walls on the left, bottom, and right, the boundary conditions would translate to:
* Top (moving wall): fixedValue with a uniform velocity, e.g., (1, 0, 0).
* Left, bottom, and right walls (fixed, solid walls): noSlip.
If you are unsure about the details of a boundary condition, you can consult the source code. The files are located in $FOAM_SRC/finiteVolume/fields/fvPatchFields/derived. The header file for each boundary condition typically contains a major description and an example. Alternatively, Doxygen documentation generated during OpenFOAM compilation or available online can be consulted.
Troubleshooting is an essential part of the process. Common issues include solver crashes or setup errors, which often stem from incorrect boundary condition combinations. Understanding the ideal use case for each boundary condition type is crucial to prevent these problems and to focus on the simulation goals. Resources like cheat sheets or detailed documentation can save time and frustration during case setup and troubleshooting.
Sources
- Boundary and initial conditions with codeStream in OpenFOAM
- OpenFOAM Documentation: Boundary Conditions
- A Brief Explanation of Boundary Conditions in OpenFOAM
- Still Guessing Which Boundary Condition to Use?
- OpenFOAM User Guide v13: Boundary Conditions
- CFD-Online Forum: How to change/set different boundary condition for particular cell/region