Coder Social home page Coder Social logo

argonne-lcf / tensorflowfoam Goto Github PK

View Code? Open in Web Editor NEW
191.0 191.0 72.0 139.07 MB

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

License: MIT License

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

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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tensorflowfoam's Issues

Error in Step 3 "Compile ML turbulence model"

Hi,
This is really very interesting work, was trying with the OpenFOAM v1906, and was able to complete all the steps till Step 2. In the Step 3, when I am running wclean && wmake libso
it is giving an error which says:

ML_SA_CG.C: In member function ‘virtual void Foam::RASModels::ML_SA_CG<BasicTurbulenceModel>::correct()’:
ML_SA_CG.C:378:64: error: there are no arguments to ‘IFstream’ that depend on a template parameter, so a declaration of ‘IFstream’ must be available [-fpermissive]
   RectangularMatrix<doubleScalar>mean_std_vals(IFstream("means")());
                                                                ^
ML_SA_CG.C:378:64: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
ML_SA_CG.C: In instantiation of ‘void Foam::RASModels::ML_SA_CG<BasicTurbulenceModel>::correct() [with BasicTurbulenceModel = Foam::IncompressibleTurbulenceModel<Foam::transportModel>]’:
maketurbulentTransportModels.C:29:23:   required from here
ML_SA_CG.C:378:56: error: ‘IFstream’ was not declared in this scope
   RectangularMatrix<doubleScalar>mean_std_vals(IFstream("means")());

I think this is the problem related to OpenFOAM version, is it not doable at all with the OpenFOAM v 1906 and had to install/work-with OpenFOAM 5? Thanks in advance :)

Generating Training Data (and OpenFOAM 5)

I'm trying to generate the training data for the backward step case instead of using data provided. I see that you need wall distance, u,v,w velocities and coordinates for cell centres. I have two brief questions:

  1. How did you write out your wall distances in OpenFOAM5 so that it is readable by "training_data_marker.py"? (For cellcentres I just used the inbuilt func)
  2. Could you elaborate on how files need to be setup for the "training_data_maker.py" to create the total array data set for training?

Linking tensorflow to openfoam

I have not installed tensorflow in the default location. So, I modified the OF_model/Make/options file to

EXE_INC =
-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
-I/work/SDDO_lab/jethro/software_installations/tf_1_15/include \

LIB_LIBS =
-lincompressibleTransportModels
-lturbulenceModels
-lfiniteVolume
-lmeshTools
-L/work/SDDO_lab/jethro/software_installations/tf_1_15/lib
-lstdc++

It managed to compile it without any error, however, when I try to run simpleFoam_ML in the Testing folder, I get the following error

simpleFoam_ML: symbol lookup error: /home/jethro/OpenFOAM/jethro-5.x/platforms/linux64IccDPInt32Opt/lib/ML_SST_CG.so: undefined symbol: TF_NewBuffer

I am not sure where I am going wrong.

The issue about "sample" function

Dear Maulik
ThankU for your fantastic contribution, I have a little issue while performing the Testing case.
All of the procedures were done and work really well. Moreover I have tried to performing the functions in the controlDict file:
"functions
{
//#includeFunc "stressComponents"
//#includeFunc "pressureCoefficient"
//#includeFunc "sample"
//#includeFunc "sampleCp"
//#includeFunc "writeCellCentres"
//#includeFunc "wallShearStress"
}"
However, while execution, the OpenFOAM report:
"--> FOAM FATAL ERROR:
Unknown RASModel type ML_SA_CG"
Is there anything wrong about my comprehension?
Thanks a lot!

Installation issue in Ubuntu 20.04.3 LTS

Hello,
I am trying to install this feature in OpenFOAM v 1906 in Ubuntu 20.04.3 LTS, I am facing the following issues:

  1. Using pip install -r requirements.txt, I am getting the following error:
ERROR: spyder 3.3.6 requires pyqt5<5.13; python_version >= "3", which is not installed.
ERROR: spyder 3.3.6 requires pyqtwebengine<5.13; python_version >= "3", which is not installed.
ERROR: astroid 2.3.1 requires typed-ast<1.5,>=1.4.0; implementation_name == "cpython" and python_version < "3.8", which is not installed.
ERROR: astroid 2.3.1 has requirement six==1.12, but you'll have six 1.14.0 which is incompatible.
Installing collected packages: terminado, notebook, opt-einsum, protobuf, pybind11, pydot, pydotplus, qtconsole, scipy, scikit-learn, sklearn, Werkzeug, tensorboard, wrapt, termcolor, tensorflow-estimator, tensorflow
  Found existing installation: terminado 0.8.2
ERROR: Cannot uninstall 'terminado'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Could I use coanda install -r requirements.txt to rectify this issue, I am using Python 3.7.4 while coanda environment on.
2. At the end of step 2, during compiling using: g++ hello_tf.cpp -ltensorflow, getting the error:

/usr/bin/ld: /usr/local/lib/libtensorflow.so: .dynsym local symbol at index 1603 (>= sh_info of 1)
/usr/bin/ld: /usr/local/lib/libtensorflow.so: .dynsym local symbol at index 2710 (>= sh_info of 1)
/usr/bin/ld: /usr/local/lib/libtensorflow.so: .dynsym local symbol at index 2711 (>= sh_info of 1)

But while executing giving me the output: Hello from TensorFlow C library version 1.15.0

  1. In running the step 1 of ML_RANS: python ML_Model.py gives me error:
Traceback (most recent call last):
  File "ML_Model.py", line 5, in <module>
    import tensorflow as tf

Could you please help.

Step height values

In training_data_maker.py, cases 5 and 6 both have step heights of 1.75. Shouldn't they be different?

Installation Instructions

We shouldn't need to install Tensorflow with sudo permissions.
eg. sudo tar -C /usr/local -xzf (downloaded file)

Can we update the installation instructions for a user-defined prefix?

Step height during testing

In the Testing folder, constant/turbulenceProperties has hh_ set to 1.9. However, in system/blockMeshDict, the step height seems to be 1. Am I missing something?

Illegal instruction (core dumped)

Hello

I followed the installation instruction but when I execute the ./a.out , I got this error.
Illegal instruction (core dumped)

My ubuntu version is 18.04.4 LTS. Do you know why I got this error ?

Thanks,

Encountering an error in Step 4 in README.md in ML_RANS

I was in Step 4 in README.md in ML_RANS. I ran wclean && wmake from the simpleFoam_ML directory and I got the following:

Making dependency list for source file simpleFoam_ML.C g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam5/src/TurbulenceModels/turbulenceModels/lnInclude -I/opt/openfoam5/src/TurbulenceModels/incompressible/lnInclude -I/opt/openfoam5/src/transportModels -I/opt/openfoam5/src/transportModels/incompressible/singlePhaseTransportModel -I/opt/openfoam5/src/finiteVolume/lnInclude -I/opt/openfoam5/src/meshTools/lnInclude -I/opt/openfoam5/src/sampling/lnInclude -IlnInclude -I. -I/opt/openfoam5/src/OpenFOAM/lnInclude -I/opt/openfoam5/src/OSspecific/POSIX/lnInclude -fPIC -c simpleFoam_ML.C -o Make/linux64GccDPInt32Opt/simpleFoam_ML.o g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam5/src/TurbulenceModels/turbulenceModels/lnInclude -I/opt/openfoam5/src/TurbulenceModels/incompressible/lnInclude -I/opt/openfoam5/src/transportModels -I/opt/openfoam5/src/transportModels/incompressible/singlePhaseTransportModel -I/opt/openfoam5/src/finiteVolume/lnInclude -I/opt/openfoam5/src/meshTools/lnInclude -I/opt/openfoam5/src/sampling/lnInclude -IlnInclude -I. -I/opt/openfoam5/src/OpenFOAM/lnInclude -I/opt/openfoam5/src/OSspecific/POSIX/lnInclude -fPIC -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/simpleFoam_ML.o -L/opt/openfoam5/platforms/linux64GccDPInt32Opt/lib \ -lturbulenceModels -lincompressibleTurbulenceModels -lincompressibleTransportModels -lfiniteVolume -lmeshTools -lfvOptions -lsampling -lOpenFOAM -ldl \ -lm -o /opt/openfoam5/platforms/linux64GccDPInt32Opt/bin/simpleFoam_ML /usr/bin/ld: cannot open output file /opt/openfoam5/platforms/linux64GccDPInt32Opt/bin/simpleFoam_ML: Permission denied collect2: error: ld returned 1 exit status /opt/openfoam5/wmake/makefiles/general:140: recipe for target '/opt/openfoam5/platforms/linux64GccDPInt32Opt/bin/simpleFoam_ML' failed make: *** [/opt/openfoam5/platforms/linux64GccDPInt32Opt/bin/simpleFoam_ML] Error 1

I create a simpleFOAM_ML and provide permissions to it. It works.

Pip install requirements error

I've created a new conda environment on Ubuntu 18.04.5 LTS and tried to the use the command:

pip install -r requirements.txt

I get the following error:
ERROR: Could not find a version that satisfies the requirement ipykernel==5.2.1 (from -r requirements.txt (line 18)) (from versions: 4.0.1, 4.0.2, 4.0.3, 4.1.0, 4.1.1, 4.2.0, 4.2.1, 4.2.2, 4.3.0, 4.3.1, 4.4.0, 4.4.1, 4.5.0, 4.5.1, 4.5.2, 4.6.0, 4.6.1, 4.7.0, 4.8.0, 4.8.1, 4.8.2, 4.9.0, 4.10.0, 4.10.1) ERROR: No matching distribution found for ipykernel==5.2.1 (from -r requirements.txt (line 18))
I'm not sure what I'm missing.

pip --version gives:
pip 20.1.1 from /locationtoanaconda/anaconda/lib/python3.8/site-packages/pip (python 3.8)

Comparison vs two-eq turbulence models

Hello,

This is more of a question than an issue, really. But it might be of interest to more people. Do you plan om making an extension to two-eq RAS turbulence models? Such as k-Epsilon.

In the abstract of your paper I saw only a reference to 1-eq models.

Seems really cool work in any case though

Joris

Implementing the SST kw model

Hi,

In your paper you have implemented the SST kw model as well. I was wondering if it was possible for you to upload the equivalent ML_SA_CG.C file. I was hoping to implement this turbulence model.

The error when occur when I run commend "simplefoam"

--> FOAM FATAL IO ERROR:
size 131374 is not equal to the given value of 20540

file: /home/xdz/desktop/TensorFlowFoam-master/ML_RANS/Testing/1646/p from line 18 to line 131433.

From function Foam::Field<Type>::Field(const Foam::word&, const Foam::dictionary&, Foam::label) [with Type = double; Foam::label = int]
in file /home/xdz/OpenFOAM/OpenFOAM-5.x/src/OpenFOAM/lnInclude/Field.C at line 302.

FOAM exiting

I check the folder 0, and I found the size of Phi also different from other variables.

About the Two Equation Model

Hi Romit,
I’m more interested in the work about k-epsilon model and k-omega model, could you send me the code?
Thanks and regards

Issues about Testing phase in the RANS case

Hi Romit,

I have a minor question about the Testing phase in the RANS case

Your previous paper (https://doi.org/10.1016/j.compfluid.2020.104777) can realize "Deploy the previously trained framework to predict an approximation for the steady-state turbulent eddy viscosity and fix this quantity permanently."

I have read your code row by row but I am not sure how the quantity could be fixed permanently.

I guess this row in ML_SA_CG
"nut_ml_ = MyFilter_(nut_ml_)"

Could you kindly give me some clues?

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.