Code Monkey home page Code Monkey logo

computational-fluid-dynamics-machine-learning-examples's Introduction

Computational-Fluid-Dynamics-Machine-Learning-Examples

This repo contains tutorial type programs showing some basic ways Neural Networks can be applied to CFD. The purpose of this is to give those who are familiar with CFD but not Neural Networks a few very simple examples of applications. In particular, there is an example for predicting drag from the boundary conditions as well as predicting the velocity and pressure field from the boundary conditions.

The Neural Network code is written with the popular and easy to use Keras library. OpenLB is used to generate the simulation data needed for training.

Here are figures of the two networks to train.

alt tag

alt tag

Needed Install Stuff

You will need the following packages to run all the code. Mpi stuff for OpenLB and Keras for the Neural Networks. Starting from a fresh image of Ubuntu 16.04 the following should meet all dependencies.

sudo apt-get update
sudo apt-get install g++ openmpi-bin openmpi-doc libopenmpi-dev make python-vtk python-tk
sudo pip install tqdm keras tensorflow matplotlib

Note, if you want the gpu version of Tensorflow you need to install tensorflow-gpu and follow the instructions here. Also, depending how python vtk is install it can cause problems. If the above instructions are followed without a prior install of vtk then there should be no problem.

How To Generate Train Data

This repo uses OpenLB to generate the train and test set of simulation data. To setup the library run

./setup_olb.sh

This will download and compile the simulator. Now to generate the train and test set run

python make_dataset.py

This program will generate 2,000 examples of steady state flow around a cylinder at various positions and radii (simple as possible). On a i7 processor it takes about 1 hour and 2 hours on an i5. Keep in mind that it is multithreaded and runs several simulations at the same time. If you notice your machines cpu is not maxed out you can adjust the num_que parameter to make it go faster. You can also change num_runs to change how many simulations to run.

How To Train Networks

To train a network in predicting the steady state flow velocity vector field and pressure field run

keras_steady_flow_predictor.py

For the drag predicting network run

keras_drag_predictor.py

Check these scripts and the above images for more info and explanation of what is happening.

Results

Running the steady state flow predictor produces images like these.

alt tag alt tag alt tag alt tag

Once trained, the drag predicting network has an average mean squared error of 0.72. Given the boundary it is able to reasonable predict the drag. Here are 3 predictions for examples.

alt tag

true drag is : [ 10.7171] predicted drag is: [ 10.45950699]

alt tag

true drag is : [ 7.64211] predicted drag is: [ 6.81015682]

alt tag

true drag is : [ 6.08601] predicted drag is: [ 5.85990286]

Discussion

While there has been relatively little work applying Neural Networks to Computational Fluid Dynamics, there are many interesting applications. If you found these examples helpful you can check out https://github.com/loliverhennigh/Steady-State-Flow-With-Neural-Nets or https://github.com/loliverhennigh/Phy-Net for other applications. I also am compiling a comprehensive list of papers on the subject here.

computational-fluid-dynamics-machine-learning-examples's People

Contributors

loliverhennigh avatar

Watchers

 avatar  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.