Skip to main content

JAX-SPH: Smoothed Particle Hydrodynamics in JAX

Project description

JAX-SPH: A Differentiable Smoothed Particle Hydrodynamics Framework

Paper Docs PyPI - Version Open In Colab Discord

Tests CodeCov License

HT_T.gif

Table of Contents

  1. Installation
  2. Getting Started
  3. Setting up a case
  4. Contributing
  5. Citation
  6. Acknowledgements

Installation

Standalone library

Install the jax-sph library from PyPI as

python3.10 -m venv venv
source venv/bin/activate
pip install jax-sph

By default jax-sph is installed without GPU support. If you have a CUDA-capable GPU, follow the instructions in the GPU support section.

Clone

We recommend using a poetry or python3-venv environment.

Using Poetry

poetry config virtualenvs.in-project true
poetry install
source .venv/bin/activate

Later, you just need to source .venv/bin/activate to activate the environment.

Using python3-venv

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -e . # to install jax_sph in interactive mode

Later, you just need to source venv/bin/activate to activate the environment.

GPU Support

If you want to use a CUDA GPU, you first need a running Nvidia driver. And then just follow the instructions here. The whole process could look like this:

source .venv/bin/activate
pip install -U "jax[cuda12]==0.4.29"

Getting Started

In the following, a quick setup guide for different cases is presented.

Running an SPH Simulation

  • Standard SPH 2D Taylor Green vortex
python main.py config=cases/tgv.yaml solver.name=SPH solver.tvf=0.0
  • Transport velocity SPH 2D Taylor Green vortex
python main.py config=cases/tgv.yaml solver.name=SPH solver.tvf=1.0
  • Riemann SPH 2D Taylor Green vortex
python main.py config=cases/tgv.yaml solver.name=RIE solver.tvf=0.0
  • Thermal diffusion
python main.py config=cases/ht.yaml

Notebooks

We provide various notebooks demonstrating how to use JAX-SPH:

  • tutorial.ipynb Colab, with a general overview of JAX-SPH and an example how to run the channel flow with hot bottom wall.
  • iclr24_grads.ipynb Colab, with a validation of the gradients through the solver.
  • iclr24_inverse.ipynb Colab, solving the inverse problem of finding the initial state of a 100-step-long SPH simulation.
  • iclr24_sitl.ipynb Colab, including training and testing a Solver-in-the-Loop model using the LagrangeBench library.
  • neighbors.ipynb Colab, explaining the difference between the three neighbor search implementations and comparing their performance.
  • kernel_plots.ipynb Colab, visualizing the SPH kernels.

Setting up a Case

To set up a case, just add a my_case.py and a my_case.yaml file to the cases/ directory. Every *.py case should inherit from SimulationSetup in jax_sph/case_setup.py or another case, and every *.yaml config file should either contain a complete set of parameters (see jax_sph/defaults.py) or extend JAX_SPH_DEFAULTS. Running a case in relaxation mode case.mode=rlx overwrites certain parts of the selected case. Passed CLI arguments overwrite any argument.

Contributing

If you wish to contribute, please run

pre-commit install

upon installation to automate the code linting and formatting checks.

Citation

The main reference for this code is the ICLR'24 workshop paper toshev2024jax. If you refer to the code used for dataset generation in LagrangeBench, please cite toshev2024lagrangebench directly.

@article{toshev2024jax,
  title={JAX-SPH: A Differentiable Smoothed Particle Hydrodynamics Framework},
  author={Toshev, Artur P and Ramachandran, Harish and Erbesdobler, Jonas A and Galletti, Gianluca and Brandstetter, Johannes and Adams, Nikolaus A},
  journal={arXiv preprint arXiv:2403.04750},
  year={2024}
}
@article{toshev2024lagrangebench,
  title={Lagrangebench: A lagrangian fluid mechanics benchmarking suite},
  author={Toshev, Artur and Galletti, Gianluca and Fritz, Fabian and Adami, Stefan and Adams, Nikolaus},
  journal={Advances in Neural Information Processing Systems},
  volume={36},
  year={2024}
}

Acknowledgements

The initial idea for JAX-SPH is due to Fabian Fritz and Ludger Paehler, which has led to the first validated JAX implementation of the 3D Taylor-Green vortex simulated with the transport velocity SPH formulation. Since then, Artur Toshev has maintained the codebase and extended it in various ways. The people who have provided useful feedback include, but are not limited to: Stefan Adami, Xiangyu Hu, Fabian Fritz, Christopher Zöller, Fabian Thiery, Johannes Brandstetter, and Ludger Paehler. Special thanks to Nikolaus Adams, who has supervised the project from the beginning.

Contributors

  • Artur Toshev - developed and maintains the codebase; selected the SPH algorithms and validated most of them; designed the simulation cases and ML experiments.
  • Fabian Fritz - provided the first validated transport velocity SPH implementation of the 3D Taylor-Green vortex in JAX.
  • Jonas Erbesdobler - implemented Riemann SPH; improved and added solver validation scripts; contributed to refactoring the codebase.
  • Harish Ramachandran - implemented thermal diffusion and the inverse problem; helped in the initial phase of Solver-in-the-Loop.
  • Gianluca Galletti - validated the gradients through the solver; implemented and tuned Solver-in-the-Loop.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jax_sph-0.0.3.tar.gz (55.8 kB view details)

Uploaded Source

Built Distribution

jax_sph-0.0.3-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

Details for the file jax_sph-0.0.3.tar.gz.

File metadata

  • Download URL: jax_sph-0.0.3.tar.gz
  • Upload date:
  • Size: 55.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1021-azure

File hashes

Hashes for jax_sph-0.0.3.tar.gz
Algorithm Hash digest
SHA256 42448c137b5cc11ec1018925cbfb77468af8b09af0fd14e86a37ef6e8a85326a
MD5 5eafd30d317b8a236a8c19d8511bf2a4
BLAKE2b-256 0f3fee752757b9d0a800e4c2b0cdcbf4b5de1e5025de08449e11c26246ffc2f2

See more details on using hashes here.

File details

Details for the file jax_sph-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jax_sph-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 60.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1021-azure

File hashes

Hashes for jax_sph-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fcd6d2a04b34c84167f05e9bbd86f4eb8c7d04c8de3e1b4efa44eb7a0d6daf27
MD5 488059d75fb76a4d831adf06033da3c6
BLAKE2b-256 e091c0ac7ede8363e83c8572729e141196f489a5a3b5b91a204576809dff7fa9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page