-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[BUG FIX] Fix missing buoyancy on rigid bodies submerged in SPH fluid. #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
duburcqa
merged 7 commits into
Genesis-Embodied-AI:main
from
yeezhouyi:feature/sph-buoyancy-fix
Jul 20, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3fab3b9
[BUG FIX] Add pressure-based buoyancy force transfer in SPH-rigid cou…
yeezhouyi fab33a9
[BUG FIX] Extract implicit pressure from DFSPH density solve for buoy…
yeezhouyi e5b4c06
[BUG FIX] Fix function name syntax error in _kernel_compute_dfsph_pre…
yeezhouyi 2b9d812
[BUG FIX] Add analytical integration tests for SPH-rigid pressure buo…
yeezhouyi 690edc3
Calibrate the fluid pressure force on rigid geoms via the kernel plan…
duburcqa 69f7ea6
Validate buoyancy with analytical flotation and column-weight pressur…
duburcqa 16ab62a
Wake hibernated links receiving coupling forces from other solvers.
duburcqa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import pytest | ||
|
|
||
| import genesis as gs | ||
| from genesis.utils.misc import qd_to_numpy | ||
|
|
||
|
|
||
| @pytest.mark.required | ||
| @pytest.mark.parametrize("n_envs", [0, 2]) | ||
| @pytest.mark.parametrize("pressure_solver", ["WCSPH", "DFSPH"]) | ||
| def test_rigid_flotation_follows_density_ratio(n_envs, pressure_solver, show_viewer): | ||
| scene = gs.Scene( | ||
| sim_options=gs.options.SimOptions( | ||
| dt=1e-2, | ||
| substeps=10, | ||
| gravity=(0.0, 0.0, -9.81), | ||
| ), | ||
| sph_options=gs.options.SPHOptions( | ||
| lower_bound=(-0.25, -0.25, 0.0), | ||
| upper_bound=(0.25, 0.25, 1.0), | ||
| particle_size=0.02, | ||
| pressure_solver=pressure_solver, | ||
| ), | ||
| viewer_options=gs.options.ViewerOptions( | ||
| camera_pos=(1.2, 0.0, 0.7), | ||
| camera_lookat=(0.0, 0.0, 0.3), | ||
| camera_fov=40, | ||
| ), | ||
| show_viewer=show_viewer, | ||
| ) | ||
| scene.add_entity( | ||
| morph=gs.morphs.Plane(), | ||
| ) | ||
| scene.add_entity( | ||
| morph=gs.morphs.Box( | ||
| pos=(0.0, 0.0, 0.25), | ||
| size=(0.5, 0.5, 0.5), | ||
| ), | ||
| material=gs.materials.SPH.Liquid( | ||
| sampler="regular", | ||
| ), | ||
| ) | ||
| light_ball = scene.add_entity( | ||
| morph=gs.morphs.Sphere( | ||
| pos=(-0.12, 0.0, 0.25), | ||
| radius=0.06, | ||
| ), | ||
| material=gs.materials.Rigid( | ||
| rho=200.0, | ||
| ), | ||
| ) | ||
| heavy_ball = scene.add_entity( | ||
| morph=gs.morphs.Sphere( | ||
| pos=(0.12, 0.0, 0.25), | ||
| radius=0.06, | ||
| ), | ||
| material=gs.materials.Rigid( | ||
| rho=1500.0, | ||
| ), | ||
| ) | ||
| scene.build(n_envs=n_envs) | ||
|
|
||
| for _ in range(50): | ||
| scene.step() | ||
|
|
||
| # The static fluid pressure must push the light ball (rho well below the fluid rest density) up toward the | ||
| # surface, while the heavy ball (rho well above) must keep sinking: flotation discriminates on the density | ||
| # ratio, which is Archimedes' principle. | ||
| light_z = light_ball.get_pos()[..., 2] | ||
| heavy_z = heavy_ball.get_pos()[..., 2] | ||
| assert (light_z > 0.28).all(), f"Light ball must rise under buoyancy, got z={light_z}" | ||
| assert (heavy_z < 0.22).all(), f"Heavy ball must sink, got z={heavy_z}" | ||
|
|
||
|
|
||
| @pytest.mark.required | ||
| @pytest.mark.parametrize("n_envs", [0, 2]) | ||
| def test_coupling_force_wakes_hibernated_link(n_envs, show_viewer): | ||
| scene = gs.Scene( | ||
| sim_options=gs.options.SimOptions( | ||
| dt=1e-2, | ||
| substeps=10, | ||
| gravity=(0.0, 0.0, -9.81), | ||
| ), | ||
| rigid_options=gs.options.RigidOptions( | ||
| use_hibernation=True, | ||
| ), | ||
| sph_options=gs.options.SPHOptions( | ||
| lower_bound=(-0.55, -0.25, 0.0), | ||
| upper_bound=(0.55, 0.25, 1.0), | ||
| particle_size=0.02, | ||
| ), | ||
| viewer_options=gs.options.ViewerOptions( | ||
| camera_pos=(2.0, -1.5, 1.0), | ||
| camera_lookat=(0.0, 0.0, 0.2), | ||
| camera_fov=40, | ||
| ), | ||
| show_viewer=show_viewer, | ||
| ) | ||
| scene.add_entity( | ||
| morph=gs.morphs.Plane(), | ||
| ) | ||
| liquid = scene.add_entity( | ||
| morph=gs.morphs.Box( | ||
| pos=(-0.35, 0.0, 0.15), | ||
| size=(0.3, 0.4, 0.3), | ||
| ), | ||
| material=gs.materials.SPH.Liquid( | ||
| sampler="regular", | ||
| ), | ||
| ) | ||
| ball = scene.add_entity( | ||
| morph=gs.morphs.Sphere( | ||
| pos=(0.35, 0.0, 0.06), | ||
| radius=0.06, | ||
| ), | ||
| material=gs.materials.Rigid( | ||
| rho=200.0, | ||
| ), | ||
| ) | ||
| # The island partition, which hibernation builds on, only engages when the scene holds at least two free | ||
| # bodies; this bystander rests dry on the floor for the whole scenario. | ||
| scene.add_entity( | ||
| morph=gs.morphs.Sphere( | ||
| pos=(0.0, 0.0, 0.06), | ||
| radius=0.06, | ||
| ), | ||
| material=gs.materials.Rigid( | ||
| rho=2000.0, | ||
| ), | ||
| ) | ||
| scene.build(n_envs=n_envs) | ||
|
|
||
| for _ in range(15): | ||
| scene.step() | ||
|
|
||
| # The dry resting ball must have hibernated, otherwise the scenario would validate flotation instead of the | ||
| # wake-up on coupling forces. | ||
| is_ball_hibernated = qd_to_numpy(scene.rigid_solver.dyn_state.links.is_hibernated, transpose=True) | ||
| assert is_ball_hibernated[..., ball.links[0].idx].all() | ||
|
|
||
| # Teleporting the fluid over the hibernated ball must wake it through the coupling forces alone: there is no | ||
| # awake body around to collide with, so with the ball left asleep the fluid pressure would be silently | ||
| # discarded and the ball would stay frozen on the floor instead of floating up. | ||
| liquid.set_position((0.35, 0.0, 0.15)) | ||
| for _ in range(40): | ||
| scene.step() | ||
| ball_z = ball.get_pos()[..., 2] | ||
| assert (ball_z > 0.15).all(), f"Submerged ball must wake up and float, got z={ball_z}" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.