 ## Non uniform inlet profil with codedFixedValue

In most commercial codes (CFX, FLUENT, STARCCM + …) it is relatively easy to introduce a non-uniform profile for a boundary condition. For example, in case of a fully developed laminar at pipe entrance. It is possible to perform equivalent modeling with OpenFOAM® using the codedFixedValue boundary condition. The purpose of this article is to illustrate through a concrete example how to set up such a boundary condition.

It should be noted that there are also other possibilities (such as using #codeStream or from writeCellCentre) that will not be discussed here.

## The codedFixedValue boundary condition

The boundary condition code is located in:

\$FOAM_SRC/finiteVolume/fields/fvPatchFields/derived/codedFixedValue

## The structure of the boundary condition

The setting of the boundary condition is done as follows:

    inlet //name of the patch where you want to define a boundary condition
{
type            codedFixedValue; // tell to OF that you want to use codedFixedValue
value           uniform (0 0 0); // initialization

redirectType bc_name; //name of the boundary condition. Do to not use the same name on other patches

code // define the section where the implementation of the BC is done
#{
//my code

#};
General structure of the codedFixedValue BC

## A concrete example !

To illustrate the possibilities offered by the use of codedFixedValue we will study the case of the flow, in laminar regime  ($$R_{e}=500$$), in a bend. In this case study, we want to impose a fully developed velocity profile. The analytical expression of the profile, in laminar regime (obtained after solving the Navier-Stokes equation under simplifying assumptions) is as follows:

#### $$U(r) = U_{max}(1-\frac{r}{R})^2$$

The pipe radius $$R$$ is 24 mm and the bulk velocity $$U_{max}$$ is 0.0105 m/s. The figures below show the geometry of the elbow and the mesh composed of 430,000 cells generated with snappyHexMesh (volume refinement at the elbow area, refinement with a distance mode for the wall patch and insertion of 5 boundary layer elements ).

Bend geometry (left) and mesh (right)

The circular input patch (in red) in the figure is centered in x = 0, y = 0.1344 m and z = 0. This offset must be taken into account in the calculation of the radius. The implementation of the codedFixedValue boundary condition and its visualization under Paraview are shown in the figure below:

CodedFixedValue (left) and code visualization under paraview (right)

The calculation is performed (4 cores) with the simpleFoam incompressible solver and converges in 500 iterations. The converged velocity field is shown in the following figure:

## Conclusion

The OpenFOAM® codedFixedValue condition makes it easy to define custom boundary conditions with relatively little effort like commercial codes. The method can of course apply to other variables without advanced knowledge in C ++. Note also that it is possible to include the variable “time” to achieve, for example ramp-like conditions, parabolic etc …