• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

compressing physics with neural networks

Lat-Net: Compressing Lattice Boltzmann Flow Simulations using Deep Neural Networks

Introduction

This repository contains the code to reproduce results seen in Lat-Net: Compressing Lattice Boltzmann Flow Simulations using Deep Neural Networks. The premise is to compress Lattice Boltzmann Fluid Flow simulations onto small computationally efficient neural networks that can be evaluated.

Related Work

Similar works can be found in "Accelerating Eulerian Fluid Simulation With Convolutional Networks" and "Convolutional Neural Networks for steady Flow Approximation".

Network Details

alt tag

The network learns a encoding, compression, and decoding piece. The encoding piece learns to compress the state of the physics simulation. The compression piece learns the dynamics of the simulation on this compressed piece. The decoding piece learns to decode the compressed representation. The network is kept all convolutional allowing it to be trained and evaluated on any size simulation. This means that once the model is trained on a small simulation (say 256 by 256 grid) it can then attempt to simulate the dynamics of a larger simulation (say 1024 by 1024 grid). We show that the model can still produce accurate results even with larger simulations then seen during training.

Lattice Boltzmann Fluid Flow

Using the Mechsys library we generated 2D and 3D fluid simulations to train our model. For the 2D case we simulate a variety of random objects interacting with a steady flow and periodic boundary conditions. The simulation is a 256 by 256 grid. Using the trained model we evaluate on grid size 256 by 256, 512 by 512, and 1024 by 1024. Here are examples of generated simulations.

IMAGE ALT TEXT HERE

IMAGE ALT TEXT HERE

IMAGE ALT TEXT HERE

We can look at various properties of the true versus generated simulations such as mean squared error, divergence of the velocity vector field, drag, and flux. Averaging over several test simulations we see the that the generated simulation produces realistic values. The following graphs show this for 256, 512, and 1024 sized simulations.

alt tag alt tag alt tag

A few more snap shots of simulations

alt tag alt tag alt tag

Now we can apply it to other datasets. Here is a simulation around a car cross section. This demonstrates that our method generalizes to vastly different geometries.

alt tag IMAGE ALT TEXT HERE

Here are some 3D simulations.

IMAGE ALT TEXT HERE

IMAGE ALT TEXT HERE

Here are the plots for the 3D simulations.

alt tag alt tag alt tag alt tag

Lattice Boltzmann Electromagnetic Waves

Well the Lattice Boltzmann method is actually a general partial differential equation solver (of a particular form) so why stop at fluid flow! Here are some fun electromagnetic simulations that the model learns. These simulations are of a wave hitting randomly placed objects with different dielectric constants. You can see fun effects such as reflection and refraction when the wave interacts with the surface.

IMAGE ALT TEXT HERE

IMAGE ALT TEXT HERE

Here are the plots for EM simulations

alt tag alt tag alt tag alt tag

How to run

Running the 2d simulations requires around 100 Gb of hard drive memory, a good gpu (currently using GTX 1080s), and 1 and a half days. The 3d simulations can take substantially longer.

Generating Data

The test and train sets are generated using the Mechsys library. Follow the installation guild found here. Once the directory is unpacked run ccmake . followed by c. Then scroll to the flag that says A_USE_OCL and hit enter to raise the flag. Press c again to configure followed by g to generate (I found ccmake to be confusing at first). Quit the prompt and run make. Now copy the contents of Phy-Net/systems/mechsys_fluid_flow to the directory mechsys/tflbm as well as replace mechsys/lib/flbm/Domain.h with the one found in this directory. Now enter mechsys/tflbm and run make followed by

./generate_data.

This will generate the required train and test set for the 2D simulations and save them to /data/ (this can be changed in the run_bunch_2d script. 3D simulation is commented out for now. Generating the 2D simulation data will require about 12 hours.

Generating the data to train on is by far the most complicated piece of this work. It requires several external packages and considerable memory. I recently wrote a library to generate Lattice Boltzmann simulations entirely in Tensorflow here. In the future I would like to integrate this library with the train code allowing the data generation to be streamlined.

Train Model

To train the model enter the Phy-Net/train directory and run

python compress_train.py

This will first generate tfrecords for the generated training data and then begin training. Multi GPU training is supported with the flag --nr_gpu=n for n gpus. The important flags for training and model configurations are

  • --nr_residual=2 Number of residual blocks in each downsample chunk of the encoder and decoder
  • --nr_downsamples=4 Number of downsamples in the encoder and decoder
  • --filter_size=8 Number of filters for the first encoder layer. The filters double after each downsample.
  • --nr_residual_compression=3 Number of residual blocks in compression piece.
  • --filter_size_compression=64 filter size of residual blocks in compression piece.
  • --unroll_length=5 Number of steps in the future the network is unrolled.

All flags and their uses can be found in Phy-Net/model/ring_net.py.

Test Model

There are several different tests that can be run in the test directory. For the 2D simulations, running these scripts will generate the figures and videos above.

  • 2d_error_test.txt Generates the error plots seen above
  • 2d_image_test.txt Generates the images seen above
  • 2d_video_test.txt Generates the videos seen above

Contact

For any questions regarding the project please email me at [email protected].

More Repositories

1

Convolutional-LSTM-in-Tensorflow

An implementation of convolutional lstms in tensorflow. The code is written in the same style as the basiclstmcell function in tensorflow
Python
420
star
2

Computational-Fluid-Dynamics-Machine-Learning-Examples

This repo contains some tutorial type programs showing some basic ways machine learning can be applied to CFD.
Python
271
star
3

Steady-State-Flow-With-Neural-Nets

A Tensorflow re-implementation of the paper Convolutional Neural Networks for Steady Flow Approximation
Python
156
star
4

Computational-Physics-and-Machine-Learning-Reading-List

A list of papers relating Computational Physics and Machine Learning
131
star
5

Lattice-Boltzmann-fluid-flow-in-Tensorflow

A Lattice Boltzmann fluid flow simulation written in Tensorflow.
Python
122
star
6

Early-Visual-Concept-Learning-Recreation-of-Some-Results

Here is an implementation of some of a few results seen in Early Visual Concept Learning with Unsupervised Deep Learning
Python
28
star
7

latnet

Neural Network Based Lattice Boltzmann solver
Python
26
star
8

All-Convnet-Autoencoder-Example

Just a simple use example of the conv2d_transpose function in TensorFlow. Its run on MNIST.
Python
22
star
9

Variational-autoencoder-tricks-and-tips

just a few trouble shooting tips I have found for training variational autoencoders. All code in tensorflow
Python
22
star
10

MinDat-Mineral-Image-Dataset

A dataset of +500,000 mineral images with labels taken from mindat.org.
Python
21
star
11

Crystal-Gems

A dataset of mineral images and labels for machine learning purposes. http://www.minerals.net/
Python
18
star
12

PhantomGaze

Simple GPU rendering of scientific data with Pytorch, Jax, CuPy, and Warp backends.
Python
15
star
13

Deep-Learning-Papers

A list of deep learning papers and notes on them
12
star
14

dynamic_rnn_conv_lstm

just a quick example of using the conv lstm in tensorflow as per https://github.com/tensorflow/tensorflow/pull/8891
Python
9
star
15

Deep-Learning-Experiment-Manager

A simple python program to queue up deep learning experiments on gpus
Python
5
star
16

DeepDesign

Automated Design Library using Deep Neural Networks
Python
5
star
17

ultrasound-nerve-segmentation-in-tensorflow

Jumping in really late to the kaggle ultrasound nerve segmentation competition. Hopefully save peoples time in writing boring data loading scripts.
Python
5
star
18

Compressing-Dynamical-Systems-Atari

This is both an implementation of the paper "Action-Conditional Video Prediction using Deep Networks in Atari Games" and an extension of some of their results
Python
4
star
19

dynamical-systems-for-machine-learning

Simple dynamical systems to test machine learning algorithms. Written with TensorFlow in mind
Python
4
star
20

Mindat

A dataset of mineral images created from mindat.org
Python
3
star
21

Flow-Sculpter

Neural Networks learning to create objects with desired flow properties.
Python
3
star
22

Quantum-Walk-Simulator

A c++ simulator for Continuous-Time Quantum Walk.
C
2
star
23

Compressing-Dynamical-Systems

A tool to compressing video based dynamical systems on to small low dimensional LSTMs or fully connected networks. This also doubles as a video generative model as seen bellow.
Python
2
star
24

Cd.jl

A simple Restricted Boltzmann machine. For use in Neural Networks and other learning needs.
Julia
2
star
25

Memory-Efficient-Autoencoder

A repo looking at autoencoders that can be applied to extremely large 2D and 3D tensors.
Python
2
star
26

resume

my resume yaya
1
star
27

The-Wedding-Project

1
star
28

All-Convnet-TensorFlow-MNIST-Tutorial

A look at using conv nets all the way through for TensorFlows MNIST Tutorial
Python
1
star
29

Ring_Net

A Neural Network for compressing dynamical systems into Markov Chains and the like
Python
1
star
30

PumpkinPulse

Dense Plasma Focus Fusion Reactor
Python
1
star