How are boundary conditions applied in CFD?

CFD Direct's OpenFOAM Training fully covers boundary conditions in OpenFOAM

See Training

6.3 Introduction to boundary conditions

Boundary conditions are specified in field files, e.g. p, U, in time directories. The structure of these files is introduced in sections 2.1.4 and 4.2.9 , with the keyword entries dimensions, internalField, boundaryField, and, optionally sources. The boundaryField sub-dictionary is the place where boundary conditions are specified. An entry for each patch in the mesh, which are specified in the boundary file; below is a sample file from a 2D incompressibleFluid example in OpenFOAM.


5
(
    outlet
    {
        type            patch;
        nFaces          320;
        startFace       198740;
    }
    up
    {
        type            symmetry;
        inGroups        List<word> 1(symmetry);
        nFaces          760;
        startFace       199060;
    }
    hole
    {
        type            wall;
        inGroups        List<word> 1(wall);
        nFaces          1120;
        startFace       199820;
    }
    frontAndBack
    {
        type            empty;
        inGroups        List<word> 1(empty);
        nFaces          200000;
        startFace       200940;
    }
    inlet
    {
        type            patch;
        nFaces          320;
        startFace       400940;
    }
)
The corresponding pressure field file, p, is shown below.

16

17dimensions      [kinematicPressure];

18

19internalField   uniform 0;

20

21boundaryField

22{

23    inlet

24    {

25       type             zeroGradient;

26    }

27    outlet

28    {

29        type            fixedValue;

30        value           uniform 0;

31    }

32    up

33    {

34        type            symmetry;

35    }

36    hole

37    {

38        type            zeroGradient;

39    }

40    frontAndBack

41    {

42        type            empty;

43    }

44}

45

46// ************************************************************************* //
   

Each entry in the boundaryField sub-dictionary must include a type entry which specifies the type of boundary condition. The examples above include zeroGradient and fixedValue conditions corresponding to generic patches defined in the boundary file. They also include symmetry and empty types corresponding to equivalent constraint patches, e.g. the up patch is defined as symmetry in the mesh and uses a symmetry condition in the field file.

For details about the main boundary conditions used in OpenFOAM, refer to Chapter 4 of Notes on Computational Fluid Dynamics: General Principles.

6.3.1 Patch selection in field files

There are three different ways an entry can be specified for a patch in the boundaryField of a field file: 1) by patch name; 2) by group name; 3) matching a patch name with a regular expression. They are listed here in order of precedence which is obeyed if multiple entries are valid of a particular patch. The different specifications can be illustrated by imagining a mesh with the following patches.

  • inlet: a generic patch.

  • lowerWall and upperWall: two wall patches.

  • outletSmall, outletMedium and outletLarge: three outlet patches of generic type, all in a patch group named outlet.

Then imagine the following boundaryField for a field, e.g. p, corresponding to the patches above.


boundaryField
{
    inlet
    {
       type             zeroGradient;
    }
    ".*Wall"
    {
        type            zeroGradient;
    }
    outletSmall
    {
        type            fixedValue;
        value           uniform 1;
    }
    outlet
    {
        type            fixedValue;
        value           uniform 0;
    }
}
In this example, the inlet field entry is read for the inlet patch, following rule 1 above (matching patch name). Similarly, the outletSmall entry will be read for the patch of the same name.

The outletMedium and outletLarge patches do not have matching entries in the field file, so they instead the outlet entry will be applied (rule 2), since it matches the group name to which the patches belong. Note that the outletSmall patch does not use the outlet entry because a matching patch entry takes precedence over a matching group entry.

Finally, the lowerWall and upperWall match the regular expression ".*Wall". Regular expressions are described in section 4.2.13 ; they must be included in double quotations "". The ".*" component matches any expression (including nothing), so matches the wall patch names here. The regular expression could use word grouping to provide a more precise match to the patch names, e.g.


    "(lower|upper)Wall"
    {
        type            zeroGradient;
    }
Alternatively a patch entry could cover the wall patches taking advantage of the fact that every non-generic patch is automatically placed in a group of the same name as its type, as discussed in section 5.3.6 . In this case, all wall patches are placed in a group named wall, so the following entry would be read for both patches.


    wall
    {
        type            zeroGradient;
    }

6.3.2 Geometric constraints

Section 5.3 describes the mesh boundary, which is split into patches and written in the mesh boundary file. Each patch includes a type entry which can be specified as a generic patch, a wall or a geometric constraint, e.g. empty, symmetry, cyclic etc.

For each geometric constraint type for a patch in the mesh, there is an equivalent boundary condition type that must be applied to the same patch in the boundaryField of a field file. The type names in the mesh and boundaryField are the same, e.g. the symmetry boundary condition must be applied to a symmetry patch.

To simplify the configuration of field files, OpenFOAM includes a file named setConstraintTypes in the $FOAM_ETC/caseDicts of the installation. The setConstraintTypes file contains the following entries.

9cyclic

10{

11    type  cyclic;

12}

13

14cyclicSlip

15{

16    type  cyclicSlip;

17}

18

19nonConformalCyclic

20{

21    type  nonConformalCyclic;

22}

23

24nonConformalError

25{

26    type  nonConformalError;

27}

28

29empty

30{

31    type  empty;

32}

33

34processor

35{

36    type  processor;

37}

38

39processorCyclic

40{

41    type  processorCyclic;

42}

43

44nonConformalProcessorCyclic

45{

46    type  nonConformalProcessorCyclic;

47}

48

49symmetryPlane

50{

51    type  symmetryPlane;

52}

53

54symmetry

55{

56    type  symmetry;

57}

58

59wedge

60{

61    type  wedge;

62}

63

64internal

65{

66    type  internal;

67}

68

69

70// ************************************************************************* //
   

The file exploits the fact that a patch which is a geometric constraint is automatically included in a group of the constraint name, e.g. a symmetry patch is in a group named symmetry. The entries therefore set a boundary type for each constraint group (to the name of the group). All constraint conditions are covered by an entry for each condition.

The user can then include this file inside the boundaryField of their field files. Since the file is in the $FOAM_ETC directory it can be included using the special #includeEtc directive, e.g. in the boundaryField entry below.


boundaryField
{
    inlet
    {
        type            zeroGradient;
    }

    outlet
    {
        type            fixedValue;
        value           uniform 0;
    }

    wall
    {
        type            zeroGradient;
    }

    #includeEtc "caseDicts/setConstraintTypes"
}
With the setContraintTypes file included in the field files, the only patches that generally need to be configured are: the generic patches, corresponding to open boundaries; and, wall patches.

6.3.3 Basic boundary conditions

The main basic boundary condition types available in OpenFOAM are summarised below using a patch field named eqn. This is not a complete list; for all types see $FOAM_SRC/finiteVolume/fields/fvPatchFields/basic.

  • fixedValue: value of eqn is specified by value.

  • fixedGradient: normal gradient of eqn (eqn) is specified by gradient.

  • zeroGradient: normal gradient of eqn is zero.

  • calculated: patch field eqn calculated from other patch fields.

  • mixed: mixed fixedValue/ fixedGradient condition depending on valueFraction eqn where

     {1 corresponds to Ψ = refValue, valueFraction = 0 corresponds to ∂Ψ ∕∂n = refGradient. \relax \special {t4ht=
    (6.2)
  • directionMixed: mixed condition with tensorial valueFraction, to allow different conditions in normal and tangential directions of a vector patch field, e.g. fixedValue in the tangential direction, zeroGradient in the normal direction.

OpenFOAM v14 User Guide - 6.3 Introduction to boundary conditions
OpenFOAM User Guide