OpenFOAM implementation of turbulence models driven by Machine Learning predictions.
These models were used in our papers:
-
"A highly accurate strategy for data-driven turbulence modeling" by Bernardo P. Brener, Matheus A. Cruz, Matheus S. S. Macedo and Roney L. Thompson., published at Computational and Applied Mathematics in January 2024
Available at https://doi.org/10.1007/s40314-023-02547-9 , you can read it for free on this link.
(It was previously cited by other works in its preprint version, still accessible here)
-
"A data-driven turbulence modeling for the Reynolds stress tensor transport equation" by Matheus S. S. Macedo, Matheus A. Cruz, Bernardo P. Brener and Roney L. Thompson, published at the International Journal for Numerical Methods in Fluids in March 2024
Available at https://doi.org/10.1002/fld.5284 , you can read it for free on this link
Information on how to cite both papers are available on their respective links
The models are used to correct RANS simulations by using fields predicted by Machine Learning techniques. They also work with the direct use of high-fidelity fields, such as DNS or LES. In the models of the 1st paper, the corrections are driven by source terms injected into the mean momentum equation, while the model of the 2nd paper injects its source term into a Reynolds stress model (RSM).
- Compatibility
- Folders in the repository
- Models in the repository and their source terms
- Using the models
- References
The models were implemented using the OF ShihQuadraticKE model as a base. Implementation and tests were done in OpenFOAM-4.x, OpenFOAM-7, OpenFOAM-v2306 and OpenFOAM-v2312.
The OpenFOAM foundation versions (openfoam.org) have renamed and moved header files used to compile this library from version 8 onwards. In these versions, compilation won't succeed, unless the code is adapted. For this reason I advise anyone interested in using this library to prefer the ESI versions (openfoam.com)
The folder of-turbulence-models
contains the OpeFOAM implementation of the data-driven turbulence models.
To compile and use the applications and the libraries, you need to do the following:
- Clone the repository, preferably into your $WM_PROJECT_USER_DIR
- Navigate to the repository's directory and execute the scripts
./Allwclean
and./Allwmake
- After compilation, it is necessary to include the line
libs ("libMachineLearningTurbulenceModels.so");
into your simulation's controlDict in order to use the turbulence models - Change the turbulence model in
constant/turbulenceProperties
into one of the 5 models of this library.
The square-duct (SD) and periodic-hills (PH) simulations used in our papers are provided.
The SD folder contains the simulations for Reynolds numbers of 2200, 2400, 2600, 2900, 3200, 3500.
The PH folder contains the simulations for the slopes of 0.5, 0.8, 1.0, 1.2, 1.5.
Each subdirectory in the SD or PH folders contains the subdirectory 0
with the following k-epsilon
fields:
- Urans - velocity
- Rrans - Reynolds stress
- p - pressure
- S - mean strain-rate tensor
- k - turbulent kinetic energy
- epsilon - turbulent dissipation
- nut - eddy-viscosity
And the following DNS fields:
- Udns - velocity
- Rdns - Reynolds stress
The DNS fields for the square-duct were provided by Pinelli et al. (2010) and post-processed by Fonseca et al. (2022).
The DNS fields for the periodic-hills were provided by Xiao et al. (2020)
- RST - Reynolds stress tensor R
- Directly injects the deviatoric part of R into the momentum balance
- evRST - Perpendicular-to S (mean strain-rate tensor) Reynolds Stress Rperp and optimal eddy-viscosity nut
- Based on the paper by Wu et al. (2018)
- Directly injects the deviatoric part of Rperp into the momentum balance, along with the eddy-viscosity nut
- The turbulent viscosity nut can be included in the diffusive term of the momentum equation implicitly, as proposed by Wu et al. (2018), or explicitly, as in Brener et al. (2021)
- You can select between implicit or explicit variations, a constant implicitFactor can be defined as a model coefficient in the
turbulenceProperties
dictionary. If defined, the constant needs to be assigned a value of0.0
(explicit) or1.0
(implicit). - If not defined, the model assigns the default value of
1.0
- RFV - Modified Reynolds force vector t
- Based on the work by Cruz et al. (2019)
- Directly injects the vector t into the momentum balance
- evRFV - nonlinear part of the modified Reynolds force vector tStar and an optimal eddy-viscosity nut
- Based on the papers by Brener et al. (2021) and Brener et al (2024)
- Directly injects the vector tStar into the momentum balance along with the eddy-viscosity nut.
- The scalar nut is included within the diffusive term of the discretized mean momentum balance solved to compute the velocity field U
- Analogous to the
evRST
model, a constant implicitFactor defines if the diffusive term containing nut is calculated implicitly or explicitly. - Default value is also
1.0
(implicit)
- gammaRST - Symmetric source term tensor Gamma
- Based on the paper by Macedo et al. (2024)
- Injects the source term Gamma into the data-driven Reynolds stress model.
- At each iteration, the RST equation is solved for R.
- The deviatoric part of the calculated R is injected into the momentum balance.
- The process is repeated iteratively until numerical convergence.
Inside the data
folder there is a shell script that will calculate and organize the source terms in each simulation.
You can use the DNS fields contained in the data
folder simulations to calculate the source terms of
each turbulence model and employ them as the target of your ML.
The RANS data should be used to calculate the inputs of the ML technique you have selected.
The feature selection of the RANS inputs is itself a topic of discussion and, therefore, varies from work to work. For example, almost each of the referenced works uses a different set of inputs. Because the focus of this repository is the OpenFOAM implementation of the turbulence models, we have decided to only include the baseline RANS fields from where we extracted the features used as our inputs.
There are multiple manners of training ML techniques and predicting the source terms of each of the
5 models.
In our works we have used neural networks and random forests, they were both built using
common Python libraries such as: Keras
, TensorFlow
and Scikit-learn
.
For more details on the implementation and training of the techniques
please check our papers and others in the reference section of this README.
If your main interest is building ML architectures and predicting the fields, you are referred to the
work of McConkey et al (2021), where the authors
have curated an extensive database readily usable in ML algorithms, especially in Python.
The database is composed by DNS, LES and RANS data, and available at the
Kaggle platform on this link.
The data is presented both as OpenFOAM cases and as Numpy
arrays, multiple derived RANS feature
fields usable as ML inputs are also available.
You can also correct the RANS cases of this repository by running the models with the DNS fields included here. This serves as an upper performance estimate for each of the 5 methodologies, since the best possible scenario for ML is to exactly predict its targets.
Instructions for running three of these evaluations are provided below. They must be followed after the models and applications of the repository have been compiled in your OpenFOAM installation!
The first two tutorials with the RST
and evRFV
models should converge quickly, the last tutorial, using the gammaRST
model, takes longer since 6 additional PDEs for the Reynolds stress must be solved.
(To simplify some of the steps in the tutorials you may run the provided
shell script in the data
folder.)
The model solves for U
and p
and requires the source term R
.
-
Navigate to the case folder:
cd data/square-duct/3500/
-
Use the RANS velocity field
Urans
as the initial condition forU
:cp -r 0/Urans 0/U
-
Use the DNS Reynolds stress tensor
Rdns
as the model's source term:cp -r 0/Rdns 0/R
-
Specify
RST
as the turbulence model inconstant/turbulenceProperties
:foamDictionary constant/turbulenceProperties -entry RAS.RASModel -set RST
-
Include the repository's library in
system/cotrolDict
:foamDictionary system/controlDict -entry libs -add "("'"libMachineLearningTurbulenceModels.so"'")"
You only have to do this if you are not using any of the
controlDict
included in thedata
folder -
Run the simulation:
simpleFoam
(you may use any other steady-state solver you prefer)
The model solves for U
and p
and requires the source terms nut
(optimal) and tStar
.
-
Navigate to the case folder:
cd data/periodic-hills/1p0/
-
Calculate the DNS eddy-viscosity
nut
and nonlinear part of the Reynolds force vectortStar
- Rename the baseline RANS eddy-viscosity to avoid overwriting it:
mv -v 0/nut 0/nutRans
- Set
Udns
andRdns
asU
andR
cp -r 0/Udns 0/U
cp -r 0/Rdns 0/R
- Calculate the DNS
nut
:calculateNut
- Calculate the DNS
tStar
:calculateRFVperp
- Reorganize the
0
folder:rm -r 0/U 0/R
- Rename the baseline RANS eddy-viscosity to avoid overwriting it:
-
Use the RANS velocity field
Urans
as the initial condition forU
:cp -r 0/Urans 0/U
-
Specify
evRFV
as the turbulence model inconstant/turbulenceProperties
:foamDictionary constant/turbulenceProperties -entry RAS.RASModel -set evRFV
-
Include the repository's library in
system/cotrolDict
:foamDictionary system/controlDict -entry libs -add "("'"libMachineLearningTurbulenceModels.so"'")"
You only have to do this if you are not using any of the
controlDict
included in thedata
folder -
Run the simulation:
simpleFoam
(you may use any other steady-state solver you prefer)
The model solves for U
, p
and R
and requires the source terms nut
(RANS) and Gamma
.
-
Navigate to the case folder:
cd data/square-duct/2200/
-
Calculate the DNS source term
Gamma
- Set
Udns
andRdns
asU
andR
cp -r 0/Udns 0/U
cp -r 0/Rdns 0/R
- Calculate the DNS
Gamma
:calculateGamma
- Reorganize the
0
folder:rm -r 0/U 0/R
- Set
-
Use the RANS velocity field
Urans
as the initial condition forU
:cp -r 0/Urans 0/U
-
Use the RANS Reynolds stress field
Rrans
as the initial condition forR
:cp -r 0/Rrans 0/R
-
Set the null boundary condition for
R
:foamDictionary 0/R -entry boundaryField.fixedWalls.type -set fixedValue
foamDictionary 0/R -entry boundaryField.fixedWalls.value -set "uniform (0 0 0 0 0 0)"
-
Optional - convergence occurs faster when the initial condition for
R
is null:foamDictionary 0/R -entry internalField -set "uniform (0 0 0 0 0 0)"
-
Specify
gammaRST
as the turbulence model inconstant/turbulenceProperties
:foamDictionary constant/turbulenceProperties -entry RAS.RASModel -set gammaRST
-
Include the repository's library in
system/cotrolDict
:foamDictionary system/controlDict -entry libs -add "("'"libMachineLearningTurbulenceModels.so"'")"
You only have to do this if you are not using any of the
controlDict
included in thedata
folder -
Run the simulation:
simpleFoam
(you may use any other steady-state solver you prefer)
-
Macedo, M. S. S., Cruz, M. A., Brener, B. P. and Thompson, R. L. "A data-driven turbulence modeling for the Reynolds stress tensor transport equation" International Journal for Numerical Methods in Fluids (2024). https://doi.org/10.1002/fld.5284
-
Brener, B. P., Cruz, M. A., Macedo, M. S. S. and Thompson, R. L. "A highly accurate strategy for data-driven turbulence modeling." Computational and Applied Mathematics, 43, 59 (2024). https://doi.org/10.1007/s40314-023-02547-9
-
Brener, B. P., Cruz, M. A., Thompson, R. L. and Anjos, R. P. "Conditioning and accurate solutions of Reynolds average Navier–Stokes equations with data-driven turbulence closures." Journal of Fluid Mechanics, 915, A110 (2021). https://doi.org/doi:10.1017/jfm.2021.148
-
Cruz, M. A., Thompson, R. L., Sampaio, L. E. and Bacchi, R. D. "The use of the Reynolds force vector in a physics informed machine learning approach for predictive turbulence modeling." Computers & Fluids, 192 (2019): 104258. https://doi.org/10.1016/j.compfluid.2019.104258
-
Wu, J.L., Xiao, H., and Paterson, E. "Physics-informed machine learning approach for augmenting turbulence models: A comprehensive framework." Physical Review Fluids, 3.7 (2018): 074602. https://doi.org/10.1103/PhysRevFluids.3.074602
-
Pinelli, A., Uhlmann, M., Sekimoto, A. and Kawahara, G. "Reynolds number dependence of mean flow structure in square duct turbulence." Journal of Fluid Mechanics, 644, 107-122 (2010). https://doi.org/10.1017/S0022112009992242
-
Xiao, H., Wu, J.-L., Laizet, S., Duan, L. "Flows over periodic hills of parameterized geometries: A dataset for data-driven turbulence modeling from direct simulations." Computers and Fluids, 200(104431), 1–26 (2020). https://doi.org/10.1016/j.compfluid.2020.104431
-
Fonseca, E.F., Rangel, V.B., Brener, B.P., Cruz, M. A. and Thompson, R. L. "Pre-processing DNS data to improve statistical convergence and accuracy of mean velocity fields in invariant data-driven turbulence models." Theoretical and Computational Fluid Dynamics, 36, 435–463 (2022). https://doi.org/10.1007/s00162-022-00603-4