Coder Social home page Coder Social logo

caijt961117 / tensorflowfoam Goto Github PK

View Code? Open in Web Editor NEW

This project forked from argonne-lcf/tensorflowfoam

0.0 0.0 0.0 139.06 MB

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

License: MIT License

C++ 96.49% Python 0.27% C 0.57% Jupyter Notebook 2.67%

tensorflowfoam's Introduction

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

tensorflowfoam's People

Contributors

romit-maulik avatar himscipy avatar sinanh avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.