How to add a new turbulence model, revisited


In this post, my old tutorial on how to implement a new turbulence model in OpenFOAM-3.0 is revisited. The old post is over two years old and since then a lot of changes in OpenFOAM have been introduced by OpenFOAM foundation. Fortunately, implementing a new model in OpenFOAM-5.0 upwards is much easier now. Therefore, this will be a very short post since all the basics has been covered in the previous post.

komegaSST as an example

Unlike the old post, kOmegaSST is used as an example. It seems that many OpenFOAMers are using kOmegaSST as a base model for their development which is quite understandable due to the popularity of the model in many applications. Also, that has been reflected in OpenFOAM implementation of the model since version-4.0. The model has been reimplemented as base model for all kOmegaSST based models and called kOmegaSSTbase. The model governing equations are implemend in the base class kOmeagaSSTbase [1].

As usual, we need to copy few files from OpenFOAM source to a local directory of your choice, typically OpenFOAM user run is a reasonable option. Open a new terminal and source OpenFOAM-5.0 or OpenFOAM-6.0. Then change directory to any folder where you want to save your code. The follow the commend below to copy and rename the files.

cp -r $FOAM_SRC/TurbulenceModels/turbulenceModels/RAS/kOmegaSST newkOmegaSST
cd newkOmegaSST
mv kOmegaSST.H newkOmegaSST.H
mv kOmegaSST.C newkOmegaSST.C
cp -r $FOAM_SRC/TurbulenceModels/incompressible/Make/ .
cp -r $FOAM_SRC/TurbulenceModels/incompressible/turbulentTransportModels/turbulentTransportModels.C maketurbulentTransportModels.C

It is the time to modify the source code, first edit maketurbulentTransportModels.C. Just keep the include statement in the beginning and remove everything else and add these two lines,

#include "newkOmegaSST.H"

The Make/files should point to maketurbulentTransportModels.C as follows,


LIB = $(FOAM_USER_LIBBIN)/libmyincompressibleTurbulenceModels

The Make/options should links the following libraries as,

    -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \

    -lincompressibleTransportModels \
    -lturbulenceModels \
    -lfiniteVolume \

Now replace every instance of kOmegaSST to newkOmegaSST in both newkOmegaSST.H and newkOmegaSST.H. Please be careful, do not use sed nor replace all functionally in your editior without reviewing the changes. As discussed before, all kOmegaSST based models are inherited from a base class called kOmegaSSTbase. Therefore, do not change these instance where kOmegaSSTbase appears ( line[41] [2]) nor the base type in class declaration ( line[59] [3]) and definition ( line[50] [4]).

Just add the new library to controlDict libs and you are ready to go!!

[1] kOmeagaSSTbase
[2] Line 41 in kOmegaSST.H
[3] Line 59 in kOmegaSST.H
[4] Line 50 in kOmegaSST.C


Comments powered by Disqus