A JAX-based differentiable Lattice Boltzmann library for single and multiphase flow simulations on CPUs, GPUs and TPUs
Project description
JAX-LaB: A Python-based, Accelerated, Differentiable Massively Parallel Lattice Boltzmann Library for Modeling Multiphase and Multiphysics Flows & Physics-Based Machine Learning
JAX-LaB is a fully differentiable, accelerated multiphysics and multiphase 2D/3D Lattice Boltzmann Method (LBM) Python library written in JAX and it provides a unified workflow for forward and inverse modeling of multiphase flows. JAX-LaB is an extension of XLB and adds support multiphase and multiphysics flows to the original library.
Accompanying Paper
The accompanying paper, published in Journal of Advances in Modeling Earth Systems (JAMES), is available here.
Showcase
Contact angle hysteresis: Left: droplet impinging on inclined surface (MRT collision model). Right: Droplet undergoing evaporation (Cascaded collision model). Simulated using Peng-Robinson EOS, geometric wetting.
Time evolution of liquid distribution in a Fontainebleau sandstone during evaporation simulated using the Cascaded (central-moment) collision model.
On GPU in-situ rendering using PhantomGaze library (no I/O). Droplet impact on dry surface using MRT collision model with ~16 million cells. (single component, multiphase simulation, density ratio: 350, fluid modeled using Peng-Robinson EOS).
In-situ GPU rendering of drainage in a porous geometry. BGK collision model, 110 million cells.
Temporal evolution of the density field determined using neural network for the inverse multiphase flow control problem of forming a droplet at t = 900. The MLP output is used as the initial condition for LBM and the backpropagation step during training leverages the auto-differentiation capabilities of JAX-LaB (see paper for details).
Key Features
- Integration with JAX Ecosystem: The library can be easily integrated with JAX's robust ecosystem of machine learning libraries such as Equinox Flax, Haiku, Optax, and many more.
- Differentiable LBM Kernels: JAX-LaB provides differentiable LBM kernels that can be used in differentiable physics and deep learning applications.
- Scalability: JAX-LaB is capable of scaling on distributed multi-GPU systems, enabling the execution of large-scale simulations on hundreds of GPUs with billions of cells.
- Support for Various LBM Boundary Conditions and Kernels: JAX-LaB supports several LBM boundary conditions and collision kernels.
- Support for Multiphase, Multiphysics and Multicomponent flows: JAX-LaB can accurately model multiphysics and multiphase flows using Shan-Chen method, simulating complex interface dynamics without tracking any interface.
- User-Friendly Interface: Written entirely in Python, JAX-LaB emphasizes a highly accessible interface that allows users to extend the library with ease and quickly set up and run new simulations.
- Leverages JAX Array and Shardmap: The library incorporates the new JAX array unified array type and JAX shardmap, providing users with a numpy-like interface. This allows users to focus solely on the semantics, leaving performance optimizations to the compiler.
- Platform Versatility: The same JAX-LaB code can be executed on a variety of platforms including multi-core CPUs, single or multi-GPU systems, TPUs, and it also supports distributed runs on multi-GPU systems or TPU Pod slices.
- Visualization: JAX-LaB provides a variety of visualization options including in-situ on GPU rendering using PhantomGaze.
Capabilities
Multiphase Flow Modeling
Shan-Chen pseudopotential method with various modifications:
- Support for high density ratio flows (tested for density ratios > 108) using improved forcing scheme.
- Incorporates Equation of State (EOS) to model multiphase flows. Currently implemented EOS include Carnahan-Starling, Peng-Robinson, Redlich-Kwong, Redlich-Kwong-Soave and VanderWaals.
- Density ratio independent surface tension control by directly modifying pressure tensor.
- Improved wetting scheme to handle large range of contact angles without large spurious current or thick layers near solid surface.
Multicomponent Flow Support
JAX-LaB takes advantage of pytrees for computation hence, it can model any number of components (each with their own equation of state, initial condition and boundary conditions) without any user modification.
Wetting model
- Wetting behavior of fluids can be modeled using the geometric wetting scheme and the improved virtual density scheme which avoids the need to include separate fluid-solid interaction forces commonly seen in Shan-Chen method by directly updating the near-wall densities.
- Wetting parameters can be passed by the user while defining the wall boundary conditions. By default, if no wetting parameters are specified, the boundary conditions are used as is without application of wetting behavior.
Collision Models
- BGK
- Multi-Relaxation Time (MRT)
- Cascaded Model
- KBC
Lattice
- D2Q9
- D3Q19
- D3Q27
Machine Learning
- Easy integration with JAX's ecosystem of machine learning libraries
- Differentiable LBM kernels both for single and multiphase flows
- Differentiable boundary conditions
Compute Capabilities
- Distributed Multi-GPU support
- Mixed-Precision support (store vs compute)
Output
- Binary and ASCII VTK output (based on PyVista library)
- HDF5 output (based on h5py) to maximize I/O speed and minimize storage requirement
- In-situ rendering using PhantomGaze library
- Orbax-based distributed asynchronous checkpointing
- Image Output
- 3D mesh voxelizer using trimesh
Boundary conditions
-
Equilibrium BC: In this boundary condition, the fluid populations are assumed to be in at equilibrium. Can be used to set prescribed velocity or pressure.
-
Full-Way Bounceback BC: In this boundary condition, the velocity of the fluid populations is reflected back to the fluid side of the boundary, resulting in zero fluid velocity at the boundary.
-
Half-Way Bounceback BC: Similar to the Full-Way Bounceback BC, in this boundary condition, the velocity of the fluid populations is partially reflected back to the fluid side of the boundary, resulting in a non-zero fluid velocity at the boundary.
-
Do Nothing BC: In this boundary condition, the fluid populations are allowed to pass through the boundary without any reflection or modification.
-
Zouhe BC: This boundary condition is used to impose a prescribed velocity or pressure profile at the boundary.
-
Regularized BC: This boundary condition is used to impose a prescribed velocity or pressure profile at the boundary. This BC is more stable than ZouHe BC, but computationally more expensive.
-
Extrapolation Outflow BC: A type of outflow boundary condition that uses extrapolation to avoid strong wave reflections.
-
Interpolated Bounceback BC: Interpolated bounce-back boundary condition due to Bouzidi for a lattice Boltzmann method simulation.
-
Convective Outflow BC: Convective outflow boundary condition, useful for porous media flows.
Installation Guide
To use JAX-LaB, please install JAX by following the lastest installation instructions described here. The core dependencies can be installed using pip:
pip install numpy orbax-checkpoint termcolor
Optional dependencies
The I/O and visualization utilities load their dependencies lazily (at call time, not at import time), so the core solver runs without them. The following packages are only needed if you call the corresponding functions:
| Package | Required by |
|---|---|
| PyVista | save_fields_vtk, save_BCs_vtk, live_volume_randering |
| h5py | save_fields_hdf5_xdmf |
| matplotlib | save_image, live_volume_randering |
| trimesh + Rtree | voxelize_stl |
Calling one of these functions without its dependency installed raises an ImportError naming the missing package. To install all optional dependencies at once (recommended for running the examples, most of which write VTK or image output):
pip install pyvista matplotlib Rtree trimesh h5py
Note: We encountered challenges when executing JAX-LaB on Apple GPUs due to the lack of support for certain operations in the Metal backend. We advise using the CPU backend on Mac OS. We will be testing JAX-LaB on Apple's GPUs in the future and will update this section accordingly.
Run an example:
git clone https://github.com/piyush-ppradhan/JAX-LaB
cd JAX-LaB
export PYTHONPATH=.
python3 examples/singlephase/cavity2d.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jax_lab-0.1.0.tar.gz.
File metadata
- Download URL: jax_lab-0.1.0.tar.gz
- Upload date:
- Size: 85.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92dcc1fb74bd57c49950246cf0e6532ab29ef87d88a965b5aeafb34e3d54b910
|
|
| MD5 |
fb57651826a322299a2333b30404ef9a
|
|
| BLAKE2b-256 |
bccb4b4a7d6e532284816c37dc6bb44e2591522e534c1ad0fab26fad7b6c499e
|
Provenance
The following attestation bundles were made for jax_lab-0.1.0.tar.gz:
Publisher:
release.yml on piyush-ppradhan/JAX-LaB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jax_lab-0.1.0.tar.gz -
Subject digest:
92dcc1fb74bd57c49950246cf0e6532ab29ef87d88a965b5aeafb34e3d54b910 - Sigstore transparency entry: 2146414451
- Sigstore integration time:
-
Permalink:
piyush-ppradhan/JAX-LaB@07cc09519897cdf0a6d509331351c66912d87733 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/piyush-ppradhan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@07cc09519897cdf0a6d509331351c66912d87733 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jax_lab-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jax_lab-0.1.0-py3-none-any.whl
- Upload date:
- Size: 81.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61f34f05d5f5923d1697cc776193d96756c6c030d4e8b59d160581b08e72b1b5
|
|
| MD5 |
57f1ec7c06949f87e563139cbcb32289
|
|
| BLAKE2b-256 |
534481c9896f13e3e11a5233a41be4844632c1f9b2d6960b8486d348e357506b
|
Provenance
The following attestation bundles were made for jax_lab-0.1.0-py3-none-any.whl:
Publisher:
release.yml on piyush-ppradhan/JAX-LaB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jax_lab-0.1.0-py3-none-any.whl -
Subject digest:
61f34f05d5f5923d1697cc776193d96756c6c030d4e8b59d160581b08e72b1b5 - Sigstore transparency entry: 2146414459
- Sigstore integration time:
-
Permalink:
piyush-ppradhan/JAX-LaB@07cc09519897cdf0a6d509331351c66912d87733 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/piyush-ppradhan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@07cc09519897cdf0a6d509331351c66912d87733 -
Trigger Event:
push
-
Statement type: