Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/zhehaoli1999/DiffFR
05 April 2024, 06:41:38 UTC
  • Code
  • Branches (2)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • refs/heads/website
    No releases to show
  • b5032a7
  • /
  • README.md
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:f3af55b678df8457edcf4d4416677c801874d70d
origin badgedirectory badge Iframe embedding
swh:1:dir:b5032a73be4d08344c1555b58895052bb2f8352f
origin badgerevision badge
swh:1:rev:f7dc063b7f3c0330f345c5d52454c52c1f6f1f26
origin badgesnapshot badge
swh:1:snp:4a544d8c785923c8ae8c1fe32f1445745a948b05

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: f7dc063b7f3c0330f345c5d52454c52c1f6f1f26 authored by Li Zhehao on 31 March 2024, 14:19:09 UTC
update readme to fix typo
Tip revision: f7dc063
README.md
# DiffFR: Differentiable SPH-based Fluid-Rigid Coupling for Rigid Body Control

![](./images/teaser.jpg)

## 1. Introduction
This is the code base for our SIGGRAPH Asia 2023 paper. 
We develop our method based on the open-source library [SPlisHSPlasH](https://github.com/InteractiveComputerGraphics/SPlisHSPlasH) and we sincerely thank the effort of its authors. 

## 2. Installation
We have built and tested the code on Ubuntu22.04. 

### 2.1 Prerequisite

Required infrastructures can be installed via: 

```
sudo apt install git cmake xorg-dev freeglut3-dev build-essential libomp-dev
```

Required python packages can be directly installed by `pip install -r requirements.txt`. 


### 2.2 How to build 
First shallow clone this repo with git:
```
git clone --depth=5 git@github.com:zhehaoli1999/DiffFR.git 
```
Then we recommend to create a new conda environment (such as "diffFR") and
activate it:
```
conda create --name diffFR python=3.7
conda activate diffFR
```
Then find `build.sh` under the root dir of the project, and  use commands like `bash build.sh` to execuate this shell (please ensure your
shell has already execuated `conda init`). It will use cmake to configure the
project and then compile it with your compiler. 

## 3. Experiments in paper
**You can find all raw data records and the scripts for figure plotting of our experiments in the `experiments` folder.**

The simulation scene settings are described as json files, and the initial setting of velocities and positions of fluid and rigid particles are stored as bgeo and binary files. 

To run each task, you need to input a scene json file, as well as an optional binary file of the initial settings of the fluid environment (without specification, all fluid particles will have the positions described in the json file with zero velocities. )

### 3.1. Rigid body trajectory optimization


#### Data
| Task                      | Scene json file                | state file                  | taskType         | design variables | notes                                           |
|---------------------------|--------------------------------|-----------------------------|------------------|------------------|-------------------------------------------------|
| water rafting             | diff-water-rafting-bunny.json  | water_rafting/state_130.bin | 'water-rafting'  | vx, vz omega     | load-fluid-pos-and-vel                          |
| high diving               | diff-high-diving-duck.json     | high_diving/state_98.bin    | 'high-diving'    | omega            | load-fluid-pos                                  |
| stone skipping            | diff-stone-skipping.json       | stone_skipping/state_18.bin | 'stone-skipping' | v, omega         | load-fluid-pos                                  |
| bottle flipping (stage 1) | diff-bottle-model.json         | bottle_flip/state_54.bin    | 'bottle-flip'    | v, omega         | load-fluid-pos                                  |
| bottle flipping (stage 2) | diff-bottle-model-collide.json | bottle_flip/state_54.bin    | 'bottle-flip'    | v, omega         | load-fluid-pos                                  |
| on-water billiards        | billiards-on-water-2balls.json | billiards/state_17.bin      | -                | v, omega         | use `diff-rigid-contact-multi.py`, load-fluid-pos |


#### Commands to run

First, `cd ./experiments/rigid_body_trajectory_optimization/python`.

For gradient-based optimization (ours), use `gradient-based-optimize.py`. For gradient-free optimization (CMA-ES & 1+1 ES), use `opt-ng.py`.

+ bottle flipping
```
python gradient-based-optimize.py --scene=../scene/diff-bottle-model.json --state=../state/bottle_flip/state_54.bin  --load-fluid-pos --taskType=bottle-flip
```
+ stone skipping
```
python gradient-based-optimize.py --scene=../scene/diff-stone-skipping.json --state=../state/stone_skipping/state_18.bin  --load-fluid-pos --taskType=stone-skipping
```

+ water rafting
```
python gradient-based-optimize.py --scene=../scene/diff-water-rafting-bunny.json --state=../state/water_rafting/state_130  --load-fluid-pos-and-vel --taskType=water-rafting 
```

+ high diving
```
python gradient-based-optimize.py --scene=../scene/diff-high-diving-duck.json --state=../state/high_diving/state_98.bin   --load-fluid-pos --taskType=high-diving
```

+ on-water billiards
```
python diff-rigid-contact-multi.py --scene=../scene/billiards-on-water-2balls.json --state=../state/billiards/state_17.bin  --load-fluid-pos
```

### 4.2. Self-supervised bottle flipping control policy 

#### Commands to run
First, `cd ./experiments/bottle_flip_robot/python`
```
python bottle-flip-robot.py --scene=../scene/diff-bottle-model-360degree.json --state=../state/state_1.365999.bin --load-fluid-pos
```

### 4.3. On-water inverted pendulum robot controller

#### Commands to run 
First, `cd ./experiments/on_water_inverted_pendulum/python`

Train:
```
python cartpole-diff-controller.py --scene=../scene/cartpole-diff-controller.json --state=../state/state_0.879992.bin --load-fluid-pos
```
Test: 
```
python cartpole-diff-controller.py --scene=../scene/cartpole-diff-controller.json --state=../state/state_0.879992.bin --load-fluid-pos --test=../saved_models/success8s-2023-01-14-23-07-05-cartpole-epoch6.pth
```
### 4.4. Other comparison & ablation experiments 

Please see the content of `./experiments/others` for code and raw data. 

## 5. Postprocess & Rendering 

For postprocess we use Houdini to reconstruct the fluid surface mesh from particles, and use Blender Cycles for rendering. 

## 6. Contact & citation 
If you have any question, please feel free to open an issue or email `zhehaoli@mail.ustc.edu.cn`. 

To cite our paper, here is the bibtex:
```
@article{10.1145/3618318,
author = {Li, Zhehao and Xu, Qingyu and Ye, Xiaohan and Ren, Bo and Liu, Ligang},
title = {DiffFR: Differentiable SPH-Based Fluid-Rigid Coupling for Rigid Body Control},
year = {2023},
issue_date = {December 2023},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
volume = {42},
number = {6},
issn = {0730-0301},
url = {https://doi.org/10.1145/3618318},
doi = {10.1145/3618318},
journal = {ACM Trans. Graph.},
articleno = {179},
numpages = {17}
}
```
## 7. License
MIT License

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API