Skip to content

Commit 3cb91e5

Browse files
committed
first commit
0 parents  commit 3cb91e5

28 files changed

+4190
-0
lines changed

.gitignore

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Editors
2+
.vscode/
3+
.idea/
4+
5+
# Outputs
6+
*vti
7+
*vtr
8+
*vtk
9+
*jpg
10+
*zraw
11+
*mhd
12+
*png
13+
# Exclusions
14+
!jax-lbm.png
15+
!airfoil.png
16+
!car.png
17+
# Vagrant
18+
.vagrant/
19+
20+
# Meshes
21+
*.obj
22+
*.stl
23+
*.ply
24+
*.off
25+
26+
# Mac/OSX
27+
.DS_Store
28+
29+
# Windows
30+
Thumbs.db
31+
32+
# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore
33+
# Byte-compiled / optimized / DLL files
34+
__pycache__/
35+
*.py[cod]
36+
*$py.class
37+
38+
# C extensions
39+
*.so
40+
41+
# Distribution / packaging
42+
.Python
43+
build/
44+
develop-eggs/
45+
dist/
46+
downloads/
47+
eggs/
48+
.eggs/
49+
lib/
50+
lib64/
51+
parts/
52+
sdist/
53+
var/
54+
wheels/
55+
*.egg-info/
56+
.installed.cfg
57+
*.egg
58+
MANIFEST
59+
60+
# PyInstaller
61+
# Usually these files are written by a python script from a template
62+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
63+
*.manifest
64+
*.spec
65+
66+
# Installer logs
67+
pip-log.txt
68+
pip-delete-this-directory.txt
69+
70+
# Unit test / coverage reports
71+
htmlcov/
72+
.tox/
73+
.nox/
74+
.coverage
75+
.coverage.*
76+
.cache
77+
nosetests.xml
78+
coverage.xml
79+
*.cover
80+
.hypothesis/
81+
.pytest_cache/
82+
83+
# Translations
84+
*.mo
85+
*.pot
86+
87+
# Django stuff:
88+
*.log
89+
local_settings.py
90+
db.sqlite3
91+
92+
# Flask stuff:
93+
instance/
94+
.webassets-cache
95+
96+
# Scrapy stuff:
97+
.scrapy
98+
99+
# Sphinx documentation
100+
docs/_build/
101+
102+
# PyBuilder
103+
target/
104+
105+
# Jupyter Notebook
106+
.ipynb_checkpoints
107+
108+
# IPython
109+
profile_default/
110+
ipython_config.py
111+
112+
# pyenv
113+
.python-version
114+
115+
# celery beat schedule file
116+
celerybeat-schedule
117+
118+
# SageMath parsed files
119+
*.sage.py
120+
121+
# Environments
122+
.env
123+
.venv
124+
env/
125+
venv/
126+
ENV/
127+
env.bak/
128+
venv.bak/
129+
130+
# Spyder project settings
131+
.spyderproject
132+
.spyproject
133+
134+
# Rope project settings
135+
.ropeproject
136+
137+
# mkdocs documentation
138+
/site
139+
140+
# mypy
141+
.mypy_cache/
142+
.dmypy.json
143+
dmypy.json

AUTHORS

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This is the list of XLB's significant contributors.
2+
# This compilation acknowledges the principal contributors to XLB but does not include every individual who has contributed code.
3+
# Due to the collective efforts of numerous employees from various corporations, some contributors may not be listed here.
4+
# For a comprehensive view of all contributors, please refer to the revision history in the source control.
5+
6+
Mehdi Ataei (Autodesk Inc)
7+
Hesam Saleipour (Autodesk Inc)

CODE_OF_CONDUCT.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a safe, inclusive and harassment-free experience for everyone. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive and healthy community.
6+
7+
## Our Standards
8+
9+
Our Open Source Community works to:
10+
11+
+ Be kind towards other people which enables us to be empathic to each other
12+
+ Be respectful of differing opinions, viewpoints, and experiences
13+
+ Give and gracefully accept constructive feedback
14+
+ Accept responsibility and apologize to those affected by our mistakes, and learning from the experience
15+
+ Focus on what is best not just for us as individuals, but for the overall community
16+
17+
We will not tolerate the following behaviors:
18+
+ Violent threats or language
19+
+ The use of sexualized language or imagery, and sexual attention or advances of any kind
20+
+ Trolling, insulting or derogatory comments, and personal or political attacks
21+
+ Public or private harassment
22+
+ Publishing others’ private information, such as a physical or email address, without their explicit permission
23+
+ Other conduct which could reasonably be considered inappropriate in a professional setting

CONTRIBUTING.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# XLB's Community and How to Contribute
2+
3+
The XLB team is deeply committed to the ethos of open-source. We are always open to, and greatly value, contributions from our community, which can take the form of suggesting new features, reporting issues, and contributing code. This document will guide you through the various processes you can follow to contribute to our project.
4+
5+
## Providing Suggestions
6+
7+
We believe that XLB should continually evolve in response to community feedback. As such, we highly value your suggestions on how to enhance the design or functionality of our platform. Please use the enhancement tag when submitting issues that are specifically suggestions, as this will help us categorize and respond appropriately.
8+
9+
## Filing Bugs
10+
11+
Despite our best efforts, like any software, XLB may occasionally have bugs. If you encounter any, please report them as regular issues on our GitHub page. We are continuously monitoring these issues, and we will prioritize and schedule fixes accordingly.
12+
13+
The most effective bug reports provide a detailed method for reliably reproducing the issue and, if possible, a working example demonstrating the problem.
14+
15+
## Contributing Code
16+
17+
Contributing your code to our project involves three main steps: signing a Contributor License Agreement, discussing your goals with the community, adhering to XLB's coding standards when writing your code, and finally, submitting a pull request.
18+
19+
20+
### Contributor License Agreement (CLA)
21+
22+
Before you can contribute any code to this project, we kindly request you to sign a Contributor License Agreement (CLA). We are unable to accept any pull request without a signed CLA.
23+
24+
- If you are contributing as an individual, the process of signing the CLA is integrated into the pull request procedure.
25+
26+
- If you are contributing on behalf of your employer, please sign our [**Corporate Contributor License Agreement**](https://github.com/Autodesk/autodesk.github.io/releases/download/1.0/ADSK.Form.Corp.Contrib.Agmt.for.Open.Source.docx). The document includes instructions on where to send the completed forms to. Once a signed form has been received, we can happily review and accept your pull requests.
27+
28+
### Coordinate With the Community
29+
30+
We strongly advise that you initiate your contribution process by opening an issue on GitHub to outline your objectives prior to beginning any coding. This proactive approach facilitates early feedback from the community and helps prevent potential overlaps in contributions.
31+
32+
### Git Workflow
33+
34+
We follow the [GitFlow](http://nvie.com/posts/a-successful-git-branching-model/) development model.
35+
If you would like to contribute your code to XLB, you should:
36+
- Include your work in a feature branch created from the XLB `main` branch. The `main` branch contains the latest work in XLB.
37+
- Then, create a pull request against the `main` branch.
38+
39+
40+
When you submit your code, please include relevant tests as part of the pull request, and ensure that your comments and coding style align with the rest of the project. You can refer to the existing code for examples of the testing and style practices that the project follows.

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2023 Autodesk Inc
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<p align="center">
2+
<img src="assets/logo-transparent.png" alt="" width="700">
3+
</p>
4+
5+
# XLB: Hardware-Accelerated, Scalable, and Differentiable Lattice Boltzmann Simulation Framework based on JAX
6+
7+
XLB (Accelerated LB) is a hardware-accelerated fully differentiable 2D/3D Lattice Boltzmann Method solver based on the JAX library. It is designed to solve fluid dynamics problems in a computationally efficient and differentiable manner.
8+
9+
## Documentation
10+
Coming soon
11+
## Showcase
12+
13+
The following examples showcase the capabilities of XLB:
14+
15+
<p align="center">
16+
<img src="assets/cavity.gif" alt="" width="500">
17+
</p>
18+
<p align="center">
19+
Lid-driven Cavity flow at Re=100,000 (~25 million voxels)
20+
</p>
21+
22+
<p align="center">
23+
<img src="assets/car.png" alt="" width="500">
24+
</p>
25+
<p align="center">
26+
Q-criterion over a DrivAer model
27+
</p>
28+
29+
<p align="center">
30+
<img src="assets/airfoil.png" width="500">
31+
</p>
32+
<p align="center">
33+
Q-criterion over a NACA airfoil
34+
</p>
35+
36+
## Capabilities
37+
38+
### LBM
39+
- BGK collision model (Standard LBM collision model)
40+
- KBC collision model (unconditionally stable for flows with high Reynolds number)
41+
42+
### Lattice Models
43+
- D2Q9
44+
- D3Q19
45+
- D3Q27 (Must be used for KBC simulation runs)
46+
47+
### Output
48+
- Binary VTK output
49+
- ASCII VTK output
50+
- Image Output (2D and 3D slice)
51+
- 3D mesh voxelizer using trimesh
52+
53+
### Boundary conditions
54+
- 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.
55+
56+
- 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.
57+
58+
- 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.
59+
60+
- Do Nothing BC: In this boundary condition, the fluid populations are allowed to pass through the boundary without any reflection or modification.
61+
62+
- Zouhe BC: This boundary condition is used to impose a prescribed velocity or pressure profile at the boundary.
63+
- 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.
64+
- Extrapolation Outflow BC: A type of outflow boundary condition that uses extrapolation to avoid strong wave reflections.
65+
66+
### Compute Capabilities
67+
- Distributed Multi-GPU support
68+
- JAX shard-map and JAX Array support
69+
- Mixed-Precision support (store vs compute)
70+
71+
## Installation Guide
72+
73+
To install XLB, you can run the following commands:
74+
75+
```bash
76+
pip install --upgrade pip
77+
78+
# For CPU run
79+
pip install --upgrade "jax[cpu]"
80+
81+
# For GPU run
82+
83+
# CUDA 12 and cuDNN 8.8 or newer.
84+
pip install --upgrade "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
85+
86+
# CUDA 11 and cuDNN 8.6 or newer.
87+
pip install --upgrade "jax[cuda11_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
88+
89+
# Please refer to https://github.com/google/jax for the latest installation documentation
90+
91+
# Run dependencies
92+
pip install jmp pyvista numpy matplotlib Rtree trimesh jmp
93+
```
94+
## Citing XLB
95+
Accompanying publication coming soon:
96+
97+
**M. Ataei, H. Salehipour**. XLB: Hardware-Accelerated, Scalable, and Differentiable Lattice Boltzmann Simulation Framework based on JAX. TBA

assets/airfoil.png

3.98 MB
Loading

assets/car.png

6.35 MB
Loading

assets/cavity.gif

9.26 MB
Loading

examples/MLUPS2d.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import os
2+
3+
from src.models import BGKSim
4+
from src.lattice import LatticeD2Q9
5+
6+
#os.environ["XLA_FLAGS"] = '--xla_force_host_platform_device_count=8'
7+
import jax.numpy as jnp
8+
import numpy as np
9+
from src.utils import *
10+
from jax.config import config
11+
from time import time
12+
import argparse
13+
from src.boundary_conditions import *
14+
15+
#config.update('jax_disable_jit', True)
16+
# Use 8 CPU devices
17+
18+
precision = 'f32/f32'
19+
20+
21+
class Cavity(BGKSim):
22+
23+
def set_boundary_conditions(self):
24+
# concatenate the indices of the left, right, and bottom walls
25+
walls = np.concatenate((self.boundingBoxIndices['left'], self.boundingBoxIndices['right'], self.boundingBoxIndices['bottom']))
26+
# apply bounce back boundary condition to the walls
27+
self.BCs.append(BounceBack(tuple(walls.T), self.grid_info, self.precision_policy))
28+
29+
# apply inlet equilibrium boundary condition to the top wall
30+
moving_wall = self.boundingBoxIndices['top']
31+
32+
rho_wall = np.ones(moving_wall.shape[0], dtype=self.precision_policy.compute_dtype)
33+
vel_wall = np.zeros(moving_wall.shape, dtype=self.precision_policy.compute_dtype)
34+
vel_wall[:, 0] = u_wall
35+
self.BCs.append(EquilibriumBC(tuple(moving_wall.T), self.grid_info, self.precision_policy, rho_wall, vel_wall))
36+
37+
38+
if __name__ == '__main__':
39+
40+
lattice = LatticeD2Q9(precision)
41+
42+
parser = argparse.ArgumentParser("simple_example")
43+
parser.add_argument("N", help="The total number of voxels will be NxN", type=int)
44+
parser.add_argument("timestep", help="Number of timesteps", type=int)
45+
args = parser.parse_args()
46+
47+
N = args.N
48+
max_iter = args.timestep
49+
Re = 100.0
50+
u_wall = 0.1
51+
clength = N - 1
52+
53+
visc = u_wall * clength / Re
54+
omega = 1.0 / (3. * visc + 0.5)
55+
print('omega = ', omega)
56+
assert omega < 2.0, "omega must be less than 2.0"
57+
os.system('rm -rf ./*.vtk && rm -rf ./*.png')
58+
sim = Cavity(lattice, omega, N, N, precision=precision)
59+
sim.run(max_iter, MLUPS=True)

0 commit comments

Comments
 (0)