How do I set a non-uniform inlet condition in OpenFOAM?

Our Training fully explains the functional fixed value boundary condition

See Training

6.5 Field functions in boundary conditions

Field functions are described in section 6.1 , where their use is demonstrated in initialising non-uniform internalFields within field files in a time directory, and in initialising fields within an fvModel configuration. Field functions can also be used to set non-uniform fields on boundary patches, i.e. to set different values on different faces of a patch. Field functions are used in boundary conditions firstly through the functionalFixedValue boundary condition which uses a field function to specify a non-uniform fixed value across a patch, see section 6.5.1 . They are specify particular parameters in a small number of boundary conditions described in section 6.5.2 and 6.6 .

6.5.1 The functionalFixedValue boundary condition

The functionalFixedValue boundary condition accompanies field functions, described in section 6.1 . Field functions allow the user to initialise non-uniform fields. While they are typically applied to the internalField, functionalFixedValue is a fixed value boundary condition where the values are specified with a field function.

The coded field function from section 6.1.3 provides a good example to illustrate the functionalFixedValue condition. Recall that the example initialises swirl flow according to Equation 6.1 , by the following configuration in the 0/U file.


    internalField
    {
        type        coded;

        evaluate
        #{
            field = velocity(1, 0, 0) + (C ^ rate(2, 0, 0));
        #};
    }
The case specifically requires the same velocity distribution at the inlet patch. The functionalFixedValue enables this, with a value entry that is a field function. Since internalField is the same field function, the value entry can be specified using a macro expansion of internalField as follows.


    boundaryField
    {
        inlet
        {
            type    functionalFixedValue;

            value
            {
                $internalField;
            }
        }
        
This will initialise the boundary condition according to the function specified above in the “evaluate #{…#};” block. The boundary values can also vary in time by specifying a function in an optional “update #{…#};” block. Recall that field functions include a reference named ‘t’ to the current time, which can be incorporated into a coded field function to make it a direct function of time.

6.5.2 Parameters as field functions

A small number of general boundary conditions have parameters which are implemented as field functions. The following foamFind command locates them.


    foamFind -dir $FOAM_SRC/finiteVolume/fields/fvPatchFields \
        -search UFunctional
One of the conditions is the pressureInletOutletVelocity condition, discussed in section 6.4.2 , where the tangentialVelocity parameter is a field function. Another is the freeStream condition where the freeStreamVelocity is a field function. The latter is used in the $FOAM_TUTORIALS/fluid/stackPlume example case to initialise the freeStreamVelocity in the far field with the atmosphericBoundaryLayerVelocity field function.
OpenFOAM v14 User Guide - 6.5 Field functions in boundary conditions
OpenFOAM User Guide