## How to add a passive scalar to your OpenFOAM® simulations

## The tutorial Cavity

The Cavity tutorial is part of the * icoFoam *solver tutorials. The tutorial is located here

The Cavity tutorial presents the modeling of the flow driven by a moving lid in a square cavity (lid-driven cavity flow). This fluid mechanics problem is a typical validation test case for CFD codes. The problem is considered 2D and the boundary conditions are shown in the figure below. The temporal evolution of the velocity field is also represented.

## Reminder about the icoFoam solver

The icoFoam solver of OpenFOAM is an unsteady, incompressible, one phase solver adapted to laminar flows. The solver is based on the PISO loop (and therefore necessarily unsteady). The solver algorithm is described in detail here.

## Changing the cavity tutorial - Adding a passive scalar

In order to illustrate the possibility of adding a passive scalar to an OpenFOAM simulation, it is assumed that there is an inert chemical species (called s, for example a rare gas) and modeled by a scalar field whose evolution is governed by the convection / diffusion equation

#### \(\frac{\partial s}{\partial t} + \overrightarrow{U}\overrightarrow{\nabla s} = \nabla^2 (D s)\)

The concentration of the species is assumed to be zero in the cavity at t = 0 sec and set at 1 on the upper boundary condition representing the moving lid.

The definition of the scalar field is done in the * controlDict* file located in the

*directory:*

**/system**In this case,* schemesField U* being commented the discretization scheme used for the convection term has to to defined in

*the (if not OpenFOAM® uses that defined for U). We choose to use the second order scheme*

**fvScheme***(*

**linearUpwind***being calculated with the scheme defined in the section gradSchemes, ie a centered scheme). Note also that the scheme used here is not as stable as possible and more complex cases would require an upwind scheme (1st order) for stability reason.*

**grad(s)**Once the * fvSchemes* file is correctly adapted, the resolution algorithms of the matrix system need to be set in the

*file:*

**fvSolution**Finally, it only remains to define the boundary conditions used for the field * s* by creating a file “

*” in the directory*

**s***:*

**/0**## Results

The two images below show the passive scalar evolution for the modified cavity tutorial of OpenFOAM. Two different values of diffusion coefficients are tested:

\(D = 0.0001 m^2/s\) and \( D = 0.0005 m^2/s\)