Skip to content

Integrating the TensorFlow 1.15 C-API into OpenFOAM 5.0 for data-driven CFD algorithm development

License

Notifications You must be signed in to change notification settings

amirtaqi/TensorFlowFoam

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TensorFlowFoam

A turbulence model built using a deep neural network trained in Tensorflow 1.15.

Contents

  1. ML_RANS/: A tutorial for setting up an artificial neural network surrogate for a linear eddy-viscosity RANS model.

  2. ML_LES/: A tutorial for setting up an artificial neural network surrogate for dynamic Smagorinsky coefficient calculation (i.e., bypass test-filtering).

  3. IN_SITU/: A tutorial for setting up a neural network training from within OpenFOAM to avoid disk IO. NOTE: We have observed some training instances to suffer from segfaults due to impromper initial (randomized) choices for weights and biases (be careful).

Installation

The following steps will get you started with a data-driven turbulence model deployed in OpenFOAM 5. I am assuming you have already installed and successfully run OpenFOAM 5 prior to this. Also, this tutorial will be based on Linux (Ubuntu 18.04) at this point of time.

Step 1: Install python environment

We suggest the creation of a new Python 3.6.9 virtual environment (either in conda or venv) and the installation of relevant packages for this tutorial using

pip install -r requirements.txt

Step 2: Download the Tensorflow C API

You can download the TensorFlow C API at https://www.tensorflow.org/install/lang_c. Follow instructions there to install on your machine. This tutorial/model is designed for the Linux CPU only release. Briefly, the instructions to install (if you have root access) are:

  1. sudo tar -C /usr/local -xzf (downloaded file)
  2. sudo ldconfig

and you are good to go. If you do not have root access and need to place the TensorFlow C API at an arbitrary location you may use the following steps:

  1. tar -C /path/to/api -xzf (downloaded file)
  2. export LIBRARY_PATH=$LIBRARY_PATH:/path/to/api/lib
  3. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/api/lib

Note that steps 2 and 3 either need to be added to your .bashrc file or need to be executed each time a new terminal session is started.

Update: The new version of the C API are for TensorFlow 2.4 and have not been tested with the contents of this repository. You may obtain the C API tarball for 1.15 in misc/.

Step 3: Test that C API is running using Test_TF_C code

After Step 2 is complete test that your API is configured correctly by executing the following code (which you can save in hello_tf.cpp

//Working on some tensorflow and c++ implementations

#include <stdio.h>
#include <tensorflow/c/c_api.h>

int main() {
  printf("Hello from TensorFlow C library version %s\n", TF_Version());

  return 0;
}

by using

  1. g++ hello_tf.cpp -ltensorflow
  2. ./a.out to obtain the following output
Hello from TensorFlow C library version 1.15.0

If you face an error here (perhaps due to not linking appropriately in the absence of root priveleges) try using:

g++ -I/path/to/api/include -L/path/to/api/lib hello_tf.cpp -ltensorflow

for step 2.

If you have reached this point - congratulations you are ready to use TensorFlow 1.15 within OpenFOAM 5. You may utilize the individual READMEs from ML_RANS/, ML_LES and IN-SITU (documentation for the latter two are in-progress) to construct a neural network based turbulence model for training/deployment in OpenFOAM.

Points of contact for further assistance - Romit Maulik ([email protected]), Himanshu Sharma ([email protected]), Saumil Patel ([email protected]). This work was performed by using the resources of the Argonne Leadership Computing Facility, a U.S. Department of Energy (Office of Science) user facility at Argonne National Laboratory, Lemont, IL, USA.

If you have found this framework informative and useful for any of your research, please cite us

@inproceedings{maulik2021deploying,
  title={Deploying deep learning in OpenFOAM with TensorFlow},
  author={Maulik, Romit and Sharma, Himanshu and Patel, Saumil and Lusch, Bethany and Jennings, Elise},
  booktitle={AIAA Scitech 2021 Forum},
  pages={1485},
  year={2021}
}

LICENSE

MIT

About

Integrating the TensorFlow 1.15 C-API into OpenFOAM 5.0 for data-driven CFD algorithm development

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.5%
  • Jupyter Notebook 2.7%
  • Other 0.8%