GithubHelp home page GithubHelp logo

hbcbh1999 / deep_flow_control Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sisl/deep_flow_control

0.0 2.0 0.0 10.22 MB

Source code for "Deep Dynamical Modeling and Control of Unsteady Fluid Flows" from NIPS 2018

Python 100.00%

deep_flow_control's Introduction

Deep Flow Control

Source code for "Deep Dynamical Modeling and Control of Unsteady Fluid Flows" from NIPS 2018. The paper can be found here.

Overview

A description of the individual files is given below.

training Directory

  • koopman_model.py - script for defining architecture of and constructing Deep Koopman models for training.
  • train_koopman.py - training script for Deep Koopman models.
  • bayes_filter.py - script for defining architecture of and constructing Deep Variational Bayes Filter models.
  • train_bayes_filter.py - training script for Deep Variational Bayes Filter models.
  • dataloader.py - script for loading and processing data prior to training.
  • utils.py - contains functions for evaluating trained models.
  • find_matrices.py - script to load a trained neural network model and determine the B-matrix, action normalization parameters, and goal state encoding.
  • find_dynamics.py - script to load a trained neural network model and output the current state encoding and the A-matrix based on the previous sequence of observed states and actions.

mpc_files Directory

  • config.ini - example config file that defines parameters for a PyFR simulation of the 2D cylinder system. Relevant parameters that may need to be modified can be found in the soln-plugin-controller section.
  • controller.patch - patch that can be applied to PyFR to allow for prescribing an angular velocity on the surface of the cylinder and performing model predictive control.
  • mesh.pyfrm - mesh file required to run simulation of 2D cylinder system.
  • cyl-2d-p2-1530.pyfrs - solution file that can be used to initialize simulations of the 2D cylinder system.
  • base.h5 - snapshot of steady base flow that defines the goal state in model predictive control.
  • loc_to_idx.json - JSON file containing a map from spatial locations in full CFD solutions to indices in the arrays used as neural network inputs.

Getting Started

Below we detail the steps required to install the necessary software, generate training data, train a Deep Koopman model, and perform model predictive control.

Software Installation

Python Environment

Deep Flow Control depends on both TensorFlow and PyFR which require python 3.5 to work properly. The training code depends on python 2.7 so it is easiest to manage different python environments using conda. Once conda is installed, you can create the two needed python environments by

conda create -n py27 python=2.7 anaconda
conda create -n py35 python=3.5 anaconda

When installing PyFR or tensorflow start by activating the python 3.5 environment

source activate py35

PyFR Installation

Deep Flow Control requires PyFR v1.7.6. Once downloaded, copy controller.patch into the top-level directory of PyFR and run git apply controller.patch to modify the PyFR code in order to enable simulation with control inputs. This patch will create a file named controller.py in the pyfr/plugins directory that contains the necessary code for defining control laws and performing model predictive control.

After applying the patch, PyFR can be installed by navigating to the PyFR directory and running

python setup.py build
python setup.py install

TensorFlow Installation

Tensorflow can be installed via pip install tensorflow or pip install tensorflow-gpu

Generating Training Data

Once PyFR has been successfully installed, simulations can be run in order to generate training data. Move the files config.ini, mesh.pyfrm, cyl-2d-p2-1530.pyfrs, and loc_to_idx.json to the same directory. Modify config.ini and controller.py as desired. Direct the python path to include the training files by adding the following to your .bashrc or .bash_profile file

export PYTHONPATH=$PYTHONPATH:/path/to/deep_flow_control/training

To generate the training data run the command

pyfr restart -bcuda -p mesh.pyfrm cyl-2d-p2-1530.pyfrs config.ini

to begin a simulation using the CUDA backend (OpenCL and OpenMP are also available as backends). Training data will be saved to the directory save_dir, as defined in config.ini but make sure the directory already exists.

Training a Model

The scripts in the training directory can be used to train a Deep Koopman model. Navigate to the directory containing the scripts

cd path/to/deep_flow_control/training

Before executing the scripts, make sure to switch to python 2.7 with

source activate py27

Examine train_koopman.py to get a sense for the arguments that can be used to define the model architecture. An example command to train a Deep Koopman model is:

python train_koopman.py --num_filters 256 128 64 32 16 --control_input True --data_dir (data_dir)

where (data_dir) is the directory where training data has been stored. By default checkpoints will be written to a directory named ./checkpoints.

Running MPC

Once you have a trained model, modify the arguments in config.ini to perform model predictive control. In particular, you will need to set mpc = 1, change training_path to be the path to the directory where the training scripts are located, modify checkpoint to correspond to the desired model checkpoint, and change base_flow to contain the correct path to the file base.h5. From this point, simulations can be run with the same command used to generate the training data. Make sure to activate python 2.7 before running PyFR with model predictive control.

deep_flow_control's People

Contributors

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