 The purpose of this post is to show how to add a passive scalar to your simulations without modifying a given solver. This feature is, for example, very useful when trying to track the concentration of inert species.

## The tutorial Cavity

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

\$FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity/

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 /system directory:

functions
{
scalar1
{
type            scalarTransport;
functionObjectLibs ("libsolverFunctionObjects.so");
enabled true;
writeControl outputTime; // write scalar field results

field s; //name of scalar field
nCorr 1; //number of corrector loop
D 0.0001; //difussion coefficient
//    schemesField U;  // Name of field to use when looking up schemes from fvSchemes

log yes;
}
};
Scalar Definition

In this case, schemesField U being commented the discretization scheme used for the convection term has to to defined in fvScheme the (if not OpenFOAM® uses that defined for U). We choose to use the second order scheme linearUpwind (grad(s) 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.

div(phi,s)     Gauss linearUpwind grad(s);
Divergence scheme for passive scalar field

Once the fvSchemes file is correctly adapted, the resolution algorithms of the matrix system need to be set in the fvSolution file:

    s
{
solver          PBiCGStab;
preconditioner  DILU;
tolerance       1e-08;
relTol          0;
minIter	     1;
}
Linear-solver for passive scalar s

Finally, it only remains to define the boundary conditions used for the field s by creating a file “s” in the directory /0:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  plus                                  |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
version     2.0;
format      ascii;
class       volScalarField;
object      s;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 0 0 0 0];

internalField   uniform 0;

boundaryField
{
movingWall
{
type            fixedValue;
value           uniform 1.0;
}

fixedWalls
{
}

frontAndBack
{
type            empty;
}
}

// ************************************************************************* //
Boundary condition for passive scalar field

## 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$$

## Conclusions

It is easily possible to add a passive scalar to a simulation under OpenFOAM® by following the steps previously described:

• Define the scalar field in the controlDict file
• Define the discretization schemes in the fvSchemes file
• Set the linear solver in the fvSolution file
• Create a file with the name of the scalar in directory 0 and set the boundary conditions

Note that the procedure can be repeated to add as many passive scalars as required !