Deep Learning-Enhanced CFD Solvers for Accelerated Fluid Flow Simulations
- Introduction
- Surrogate Model Overview
- What This Repository Enables
- Key Features
- Publications
- Repository Structure
- Getting Started
- Available CFD Solvers
- Legacy Solvers
- Citation
- Contact
- Acknowledgments
This repository contains machine learning-enhanced OpenFOAM solvers that accelerate computational fluid dynamics (CFD) simulations by replacing the computationally expensive pressure Poisson equation solver with a deep learning surrogate model.
DLpisoFoam and DLbuoyantPimpleFoam are based on OpenFOAM v8 and implement the PISO/PIMPLE algorithms with integrated neural network surrogate models for improved pressure-velocity coupling.
This is an all-in-one repository containing both surrogate models and CFD solvers, building upon the work from Solving-Poisson's-Equation-through-DL-for-CFD-applications.
UPCOMING: AUTO-trainable ML-enhanced CFD Solvers (surrogate train and simulation in a single command)
This repository provides a complete workflow for accelerating CFD simulations with machine learning:
- Generate Training Data: Run CFD simulations to create comprehensive datasets from various flow scenarios (examples in
gen_datasets/) - Train Surrogate Models: Develop neural network models that learn to predict pressure corrections in unsteady CFD simulations (examples in
train_SM/) - Deploy in Production: Integrate trained models with custom OpenFOAM-based solvers for accelerated simulations (examples in
tutorials/)
- 🚀 Accelerated simulations: Up to 40% less iterations required to convergence when compared to standard OpenFOAM solvers
- 🧠 ML-powered: Machine Learning surrogate models enhance pressure Poisson solver
- 🌡️ Multiple physics: Supports isothermal and thermal flows
- 🔧 OpenFOAM compatible: Drop-in replacement for
pisoFoamandbuoyantPimpleFoam - 🐳 Docker ready: Pre-built containers for easy deployment
- 📊 2D & 3D: Surrogate models available for both 2D and 3D simulation cases
Application of machine learning to model the pressure Poisson equation for fluid flow on generic geometries
Neural Computing and Applications (2024)
- Detailed description of the ML surrogate model architecture and training
Enhancing CFD solver with Machine Learning techniques
Computer Methods in Applied Mechanics and Engineering (2024)
- Performance benchmarks and validation of DLpisoFoam solver
- Enhanced pressure surrogate model and integration methodology
- Extension to 3D surrogate models and complex geometries
DLpisoFoam/
├── source/ # Solver source code
│ ├── DLpisoFoam/ # Incompressible isothermal solver
│ └── DLbuoyantPimpleFoam/ # Thermal flow solver
├── pressure_SM/ # Surrogate models
│ ├── 2D/ # 2D models
│ │ ├── train_and_eval/ # Training & evaluation scripts
│ │ └── CFD_usable/ # Interface for integration with CFD solver
│ └── 3D/ # 3D models
│ ├── train_and_eval/ # Training & evaluation scripts
│ │ └── CFD_usable/ # Interface for integration with CFD solver
├── tutorials/ # Example test cases
├── gen_datasets/ # Dataset generation scripts
├── other_solvers/ # Legacy solver versions
├── Dockerfile # Docker build configuration
└── env_311.yml # Python environment specification
This guide will walk you through:
- Setting up your environment (Docker or local)
- Training a surrogate model (SM) from scratch
- Running CFD simulations with the trained model
- For Docker: Docker installed (Get Docker)
- For local install:
- OpenFOAM v8
- Conda or Miniconda
- Python 3.11
Easiest method with automated setup and guaranteed reproducibility.
docker pull pauloacs/dlpisofoam:latestdocker build -t dlpisofoam .docker run -it -v $(pwd):/home/repo --rm pauloacs/dlpisofoam bashThis mounts your current directory inside the container at /home/repo.
conda env create -f env_311.yml
conda activate python311_solverpython -m pip install -e .source /opt/openfoam8/etc/bashrc # Adjust path to your OpenFOAM installation
./prep_env311.sh # Set Python/NumPy pathsNote: You may need to modify prep_env311.sh with paths to your conda environment:
export PYTHON_INCLUDE_PATH=$CONDA_PREFIX/include/python3.11
export NUMPY_INCLUDE_PATH=$CONDA_PREFIX/lib/python3.11/site-packages/numpy/core/include
export PYTHON_LIB_PATH=$CONDA_PREFIX/lib
export PYTHON_LIB_NAME=lpython3.11For DLpisoFoam:
cd source/DLpisoFoam
wclean
wmakeFor DLbuoyantPimpleFoam:
cd source/DLbuoyantPimpleFoam
wclean
wmakeVerify installations:
which DLpisoFoam
DLpisoFoam -helpwhich DLbuoyantPimpleFoam
DLbuoyantPimpleFoam -helpUse the scripts in gen_datasets/ to generate training datasets from various flow scenarios:
- Confined flows over chip arrays: Electronics cooling simulations
- Flow around squared cylinders: Bluff body aerodynamics
- Flow over inclined plates: Boundary layer studies
All configurations support both isothermal and thermal conditions to match your application requirements.
Modified versions of pisoFoam and buoyantPimpleFoam are included to extract the necessary flow field data for training. Depending on the simulation type, generation can be fully or semi-automatic.
Navigate to train_SM/ and use the run_train.sh scripts to train your model:
cd train_SM/
# Edit run_train.sh to set your datasetPath
./run_train.shKey Configuration:
- Required: Set
datasetPathto your training dataset location - Optional: Adjust hyperparameters (learning rate, batch size, dropout, etc.)
Training Outputs:
- Model file: HDF5 format TensorFlow model (e.g.,
model_MLP_small-std-drop0.1-lr0.0005-regNone-batch1024.h5) - Compression artifacts: Tucker factors (3D cases) or PCA vectors (2D cases) (required for CFD deployment)
These files are ready to use with the CFD solvers - the model weights/biases load automatically via TensorFlow.
# Navigate to test case
cd tutorials/DLpisoFoam/
# Run mesh generation (if needed)
./genMesh.sh
# Run the solver
DLpisoFoam# Open in ParaView
paraFoam
# Or use built-in post-processing
postProcess -func 'mag(U)'- Copy the example test case:
cp -r tutorials/DLpisoFoam/array_of_cyks tutorials/DLpisoFoam/my_custom_test
cd tutorials/DLpisoFoam/my_custom_test- Copy your trained surrogate model files:
# Copy your TensorFlow model
cp /path/to/your/model.h5 .
# Copy compression artifacts (Tucker factors (3D cases) or PCA vectors (2D cases))
cp /path/to/your/tucker_factors.pkl .
# Copy normalization files
cp /path/to/maxs .
cp /path/to/mean_std.npz .For incompressible, isothermal flows
- Based on OpenFOAM's
pisoFoam - Uses pressure surrogate model to accelerate PISO algorithm
- Ideal for: laminar/turbulent flows, external aerodynamics, internal flows
Example applications:
- Flow over cylinders
- Channel flows
For thermal flows with buoyancy
- Based on OpenFOAM's
buoyantPimpleFoam - Handles natural/mixed convection
- Supports both incompressible and weakly-compressible flows
Example applications:
- Electronics cooling
- HVAC simulations
Previous versions are maintained in other_solvers/:
- DLpisoFoam-alg1: Original algorithm from initial publication
- DLpisoFoam-alg2: Intermediate version with U→p surrogate model
These use the older u_to_p surrogate models and are kept for reproducibility of earlier papers.
If you use this work in your research, you can cite the papers that introduced it:
@article{firstPressureSM2024,
author = {Sousa, Paulo and Afonso, Alexandre and Veiga Rodrigues, Carlos},
year = {2024},
month = {05},
pages = {1-26},
title = {Application of machine learning to model the pressure poisson equation for fluid flow on generic geometries},
volume = {36},
journal = {Neural Computing and Applications},
doi = {10.1007/s00521-024-09935-0}
}@article{dlpisofoam2024,
title = {Enhancing CFD solver with Machine Learning techniques},
author = {Sousa, Paulo and Rodrigues, Carlos Veiga and Afonso, Alexandre},
journal = {Computer Methods in Applied Mechanics and Engineering},
volume = {429},
pages = {117133},
year = {2024},
issn = {0045-7825},
doi = {10.1016/j.cma.2024.117133},
url = {https://www.sciencedirect.com/science/article/pii/S004578252400389X},
keywords = {CFD, Machine Learning, Incompressible flows, PISO, OpenFOAM}
}@unpublished{surrogateBasedPressureVelocity2024,
title = {Surrogate-Based Pressure–Velocity Coupling: Accelerating Incompressible CFD Flow Solvers with Machine Learning},
author = {Sousa, Paulo Araújo da Cunha and Afonso, Alexandre M. and Veiga Rodrigues, Carlos},
year = {2024},
note = {Preprint},
doi = {10.2139/ssrn.5364744},
url = {https://ssrn.com/abstract=5364744}
}- Issues: GitHub Issues
- Email: [pauloacunhasousa@hotmail.com]
- ResearchGate: (https://www.researchgate.net/profile/Paulo-Sousa-74?ev=hdr_xprf)
This work builds upon:

