{"id":21812238,"url":"https://github.com/jolibrain/fluidnet_cxx","last_synced_at":"2026-02-16T20:10:24.730Z","repository":{"id":83660154,"uuid":"129415142","full_name":"jolibrain/fluidnet_cxx","owner":"jolibrain","description":"FluidNet re-written with ATen tensor lib","archived":false,"fork":false,"pushed_at":"2019-06-17T08:36:44.000Z","size":8186,"stargazers_count":52,"open_issues_count":1,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-13T23:14:40.350Z","etag":null,"topics":["aten","deep-learning","fluid-dynamics","pytorch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jolibrain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-04-13T14:42:13.000Z","updated_at":"2025-02-25T08:14:09.000Z","dependencies_parsed_at":"2023-03-12T19:10:32.525Z","dependency_job_id":null,"html_url":"https://github.com/jolibrain/fluidnet_cxx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jolibrain/fluidnet_cxx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jolibrain%2Ffluidnet_cxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jolibrain%2Ffluidnet_cxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jolibrain%2Ffluidnet_cxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jolibrain%2Ffluidnet_cxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jolibrain","download_url":"https://codeload.github.com/jolibrain/fluidnet_cxx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jolibrain%2Ffluidnet_cxx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272187339,"owners_count":24888558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aten","deep-learning","fluid-dynamics","pytorch"],"created_at":"2024-11-27T14:15:14.268Z","updated_at":"2026-02-16T20:10:19.693Z","avatar_url":"https://github.com/jolibrain.png","language":"C++","funding_links":[],"categories":["Paper implementations｜论文实现","Paper implementations"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"readme":"# fluidnet_cxx: Accelerating Fluid Simulation with Convolutional Neural Networks. A PyTorch/ATen Implementation.  \nThis repository is based on the paper, [Accelerating Eulerian Fluid Simulation With Convolutional Networks](http://cims.nyu.edu/~schlacht/CNNFluids.htm) by Jonathan Tompson, Kristofer Schlachter, Pablo Sprechmann, Ken Perlin on the accelation of fluid simulations by embedding a neural network in an existing solver for pressure prediction, replacing an expensive pressure projection linked to a Poisson equation on the pressure, which is usually solved with iterative methods (PCG or Jacobi methods). We implemented our code with PyTorch, effectively replacing all the original Torch/Lua and C++/CUDA implementation of the inviscid, incompressible fluid solver (based on the open-source fluid simulator [Mantaflow](http://mantaflow.com/), aimed at the Computer Graphics community).\nFind the original FluidNet repository [here](https://github.com/google/FluidNet).\n\nWe have retaken the original FluidNet NN architecture and added different features, such as replacing upsampling with deconvolution layers, or directly replacing the complete architecture with a deeper MultiScale net which showed more accurate results at the expense of inference speed.\n\nThis work allows to compare both the code perfomace when run in a single GPU unit and the accuracy of this data-driven method in comparison with tradional mehtods (Jacobi) or other fluid simulation methods like Lattice Boltzmann Methods.\n\n## Results\n\nSimulations of a buoyancy-driven plume flow are performed with different methods for the Poisson equation resolution.\nAn inlet is placed at the bottom of the domain, where a lighter fluid (with density rho0) is injected with velocity v0\ninto a quiescent heavier fluid. Results show that some work is still needed to predict a correct plume growth rate, due\nprobably to a poor modelling of buoyant forces by the trained model.\n\n![Alt text](figures/Animation_rho001.gif?raw=true \"Plume simulation for Richardson number Ri=0.14. Left: CNN-resolved\nPoisson equation. Center: Jacobi method 28 iterations. Right: Jacobi method 100 iterations.\")\n\u003cp align=\"center\"\u003e\n  Resolution with ConvNet |\n  Jacobi Method 28 iter | \n  Jacobi Method 100 iter\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"500\" src=\"figures/GrowthRate.png\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Growth Rate of the plume's head for Ri=0.14\n\u003c/p\u003e\n\n## Functionalities:\n* **NOTE: For the moment, only 2D simulations and training are supported.** 3D needs still some work.\n* Full eulerian (incompressible and inviscid) fluid simulator:\n    * Momentum equation resolution using a splitting algorithm:\n        * Advection of velocity + External forces\n        * Enforcing of non-divergence of velocity constraint through Poisson equation resolution, resulting in a pressure gradient\n          that corrects the velocity from the previous step. Step replaced by a fully convolutional Neural Network with\n          divergence of velocity as input and pressure as output.\n    * Unconditional Stable MacCormack discretization of velocity advection algorithm.\n    * Jacobi method implementation for comparison.\n* Dataset:\n    * Generation with FluidNet own Mantaflow sript.\n    * Random insertion of objects and velocity emitters, as well as gravity forces.\n    * Pre-processed into PyTorch objects\n* Pre-trained models:\n    * An already trained model is available in [trained_models](trained_models)\n* Training:\n    * Several options for loss function: \n        * MSE of pressure \n        * \"Physical\" loss: MSE of velocity divergence (unsupervised)\n        * MSE of velocity divergence after several timesteps.\n    * Short term divergence loss: 8 hours training\n    * Short+Long term divergence loss: ~2 days\n* Inference. Two test cases:\n    * Buoyant plume.\n    * Rayleigh Taylor instability.\n    * Launch your simulation with the available pre-trained model.\n    * Comparison with Jacobi method resolution + LBM with open-sourced C++ library [Palabos](http://www.palabos.org/)\n* Results visualization:\n    * Matplotlib\n    * Paraview post-processing tool (VTK files)\n\n# Models\n\n* Adapted FluidNet architecture\n* Deep MultiScale adapted from [Deep multi-scale video prediction beyond mean square error](https://arxiv.org/abs/1511.05440).\n\n## Requirements\n* Python 3.X \n* C++11\n* Pytorch 0.4 (Including ATen Tensor library, exposing PyTorch library in C++)\n* FluidNet own Mantaflow implementation\n* PyVTK (pip install)\n* (Optional) Paraview\n* (Optional) OpenCV2\n\nATen allows to write generic code that works on both devices.\nMore information in ATen [repo](https://github.com/zdevito/ATen). It can be called from PyTorch, using its new extension-cpp.\n\n## Installation\nTo install this repo:\n\n1. Clone this repo:\n```\nhttps://github.com/jolibrain/fluidnet_cxx.git\n```\n2. Install Pytorch 0.4:\n[Pytorch 0.4](https://pytorch.org/)\n__NOTE: Training is done in GPUs__\n\n3. Install cpp extensions for fluid solver:\nC++ scripts have been written using PyTorch's backend C++ library ATen.\nThese scripts are used for the advection part of the solver.\nFollow these instructions from main directory:\n```\ncd pytorch/lib/fluid/cpp\npython3 setup.py install # if you want to install it on local user, use --user\n```\n## Training\n\n**Dataset**\nWe use the same **2D dataset** as the original FluidNet [Section 1: Generating the data - Generating training data](https://github.com/google/FluidNet#1-generating-the-data) (generated with MantaFlow) for training our ConvNet.\n\n**Running the training**\nTo train the model, go to pytorch folder: \n```\ncd pytorch\n```\nThe dataset file structure should be located in ```\u003cdataDir\u003e``` folder with the following structure: \n```\n.\n└── dataDir\n    └── dataset\n        ├── te\n        └── tr\n\n```\nPrecise the location of the dataset in ```pytorch/config.yaml``` writing the folder location at ```dataDir``` (__use absolute paths__).\nPrecise also ```dataset``` (name of the dataset), and output folder ```modelDir```where the trained model and loss logs will be stored and the model name ```modelFilename```.\n\nRun the training :\n```\npython3 fluid_net_train.py\n```\nFor a given dataset, a **pre-processing** operation must be performed to save it as PyTorch objects, easily loaded when training. This is done automatically if no preprocessing log is detected.\nThis process can take some time but it is necessary only once per dataset.\n\nTraining can be stopped using Ctrl+C and then resumed by running:\n```\npython3 fluid_net_train.py --resume\n```\n\nYou can also monitor the loss during training by running in ```/pytorch```\n\n```\npython3 plot_loss.py \u003cmodelDir\u003e #For total training and validation losses\n#or\npython3 plot_5loss.py \u003cmodelDir\u003e #For each of the losses (e.g: L1(div) and L2(div))\n```\n\nIt is also possible to load the saved model and print its output fields and\ncompare it to targets (Pressure, Velocity, Divergence and Errors):\n```\npython3 print_output.py \u003cmodelDir\u003e \u003cmodelFilename\u003e\n#example:\npython3 print_output.py data/model_pLoss_L2 convModel\n```\n\n### Training options\nYou can set the following options for training from the terminal command line:\n* ```-h``` : displays help message\n* ```--trainingConf``` : YAML config file for training. Default = config.yaml.\n* ```--modelDir``` : Output folder location for trained model. When resuming, reads from this location.\n* ```--modelFilename``` : Model name.\n* ```--dataDir``` : Dataset location.\n* ```--resume``` : Resumes training from checkpoint in ```modelDir```\n* ```--bsz``` : Batch size for training.\n* ```--maxEpochs``` : Maximum number training epochs.\n* ```--noShuffle``` : Remove dataset shuffle when training.\n* ```--lr``` : Learning rate.\n* ```--numWorkers``` : Number of parallel workers for dataset loading.\n* ```--outMode``` : Training debug options. Prints or shows validation dataset.\n        ```save```  = saves plots to disk\n        ```show```  = shows plots in window during training\n        ```none```  = do nothing\n\nThe rest of the training parameters are set in the trainingConf file, by default [config.yaml](pytorch/config.yaml).\n\nParameters in the YAML config file are copied into a python dictionary and saved as two separated dictionaries in ```modelDir```, one conf dictionary for parameters related to training (batch size, maximum number of epochs) and one mconf dictionary for parameters related to the model (inputs, losses, scaling options etc) \n\n## Test\nRun the buoyant plume test case by running:\n```\ncd pytorch\npython3 plume.py --modelDir \u003cmodelDir\u003e --modelFilename \u003cmodelFilename\u003e --outputFolder \u003coutputFolder\u003e\n```\nwith:\n* ``` \u003cmodelDir\u003e``` : folder with trained model.\n* ``` \u003cmodelFilename\u003e``` : Trained model name.\n* ``` \u003coutputFolder\u003e``` : Folder for saving simulation results.\n\nYou can also stop the simulation (Ctrl+C) and restart it afterwards:\n```\npython3 plume.py --restartSim\n```\n\n### Test options\n* ```-h``` : displays help message\n* ```--simConf``` : YAML config file for simulation. Default = plumeConfig.yaml.\n* ```--trainingConf``` : YAML config file for training. Default = config.yaml.\n* ```--modelDir``` : Trained model location.\n* ```--modelFilename``` : Model name.\n* ```--outputFolder``` : Location of output results.\n* ```--restartSim``` : Restart simulation from checkpoint in ```\u003coutputFolder\u003e```.\n\nCheck [plumeConfig.yaml](pytorch/plumeConfig.yaml) to see how the configuation file for the simulation is organized.\n\n## Modifying the NN architecture\n\nIf you want to try your own architecture, you only have to follow these simple rules:\n* Write your model in a separate script and save it inside ```pytorch/lib```.\n* Open ```model.py``` and import your own script as a module. Go to ```class FluidNet```\n  [here](https://github.com/AAlguacil/fluidnet_cxx/blob/d09c192641daeb42668bdf2b70cfc1f415944e98/pytorch/lib/model.py#L42).\n* Ideally, as with the Multi-Scale Net example, you should just have to precise the number of channels from the input,\n  and add your net forward pass as in the multicale example\n  [here](https://github.com/AAlguacil/fluidnet_cxx/blob/d09c192641daeb42668bdf2b70cfc1f415944e98/pytorch/lib/model.py#L175)\n\n## Extending the cpp code:\n\nThe cpp code, written with ATen library, can be compiled, tested and run on its own.\nYou will need [OpenCV2](https://opencv.org/opencv-2-4-8.html) to visualize output of the pressure and velocity fields, as matplotlib is unfortunately not available in cpp!\n\n**Test**\n\nFirst, generate the test data from FluidNet\n[Section 3. Limitations of the current system - Unit Testing](https://github.com/google/FluidNet#3-limitations-of-the-current-system) and write the location of your folder in:\n```\nsolver_cpp/test/test_fluid.cpp\n#define DATA \u003cpath_to_data\u003e\n```\nRun the following commands:\n```\ncd solver_cpp/\nmkdir build_test\ncd build_test\ncmake .. -DFLUID_TEST=ON # Default is OFF\n./test/fluidnet_sim\n```\nThis will test every routine of the solver (advection, divergence calculation, velocity\nupdate, adding of gravity and buoyancy, linear system resolution with Jacobi method).\nThese tests are taken from FluidNet and compare outputs of Manta to ours, except for \nadvection when there is no Manta equivalent. In that case, we compare to the original\nFluidNet advection.\n\n**Run**\n\n```\ncd solver_cpp/\nmkdir build\ncd build\ncmake .. -DFLUID_TEST=OFF # Default is OFF\n./simulate/fluidnet_sim\n```\nOutput images will be written in ```build``` folder, and can be converted into gif using\nImageMagick.\n\n**NOTE: For the moment, only 2D simulations and training are supported, as bugs are still\nfound for the 3D advection.**\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjolibrain%2Ffluidnet_cxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjolibrain%2Ffluidnet_cxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjolibrain%2Ffluidnet_cxx/lists"}