Repository: Genesis-Embodied-AI/Genesis
File: tests/test_deformable_physics.py (Python)

Code before:
            E=3.0e4,
            nu=0.45,
            rho=1000.0,
            model="stable_neohookean",
        ),
    )
    scene.build(n_envs=2)

    mpm_cube_pos = mpm_cube.get_particles_pos()
    cloth_pos = cloth.get_particles_pos()
    water_pos = water.get_particles_pos()

    mpm_cube_active = mpm_cube.get_particles_active()
    cloth_active = cloth.get_particles_active()
    water_active = water.get_particles_active()

    mpm_cube_vel = mpm_cube.get_particles_vel()
    cloth_vel = cloth.get_particles_vel()
    water_vel = water.get_particles_vel()

    assert mpm_cube_pos.shape == mpm_cube_vel.shape
    assert mpm_cube_pos.shape == (mpm_cube_active.shape[0], mpm_cube.n_particles, 3)
    assert cloth_pos.shape == cloth_vel.shape
    assert cloth_pos.shape == (cloth_active.shape[0], cloth.n_particles, 3)
    assert water_pos.shape == water_vel.shape
    assert water_pos.shape == (water_active.shape[0], water.n_particles, 3)

    scene.get_state()
    for i in range(1500):
        scene.step()

    assert_allclose(cloth.get_particles_vel(), 0.0, atol=1e-5)
    assert_allclose(mpm_cube.get_particles_vel(), 0.0, atol=1e-4)
    assert_allclose(entity_fem._solver.get_state(0).vel, 0, atol=1e-3)
    assert_allclose(water.get_particles_vel(), 0.0, atol=5e-2)


@pytest.mark.required
def test_sf_solver(show_viewer):
    import gstaichi as ti

    res = 384
    orbit_tau = 0.2
    orbit_radius = 0.3
    orbit_radius_vel = 0.0

    jet_radius = 0.02

    sub_orbit_radius = 0.03
    sub_orbit_tau = 3.0


Review comment (suggestion):
It is not checking much, just that the API is available. Not really useful. The optional arguments are not tested and the returned value is completely ignored. It would be nice to check that the value is correct, and if too complicated, at least checking that it makes sense (i.e. non-zero and in valid range). You should also check that the value is changing over time. I think you should know the initial and final position and velocity, it could be possible to assert that.

Code after:
    )
    scene.build(n_envs=2)

    init_mpm_cube_pos = mpm_cube.get_particles_pos()
    init_cloth_pos = cloth.get_particles_pos()
    init_water_pos = water.get_particles_pos()

    scene.get_state()
    for i in range(1500):
        scene.step()

    final_mpm_cube_pos = mpm_cube.get_particles_pos()
    final_cloth_pos = cloth.get_particles_pos()
    final_water_pos = water.get_particles_pos()

    # check if the positions are changed
    assert (init_mpm_cube_pos - final_mpm_cube_pos).abs().sum() > 0.1
    assert (init_cloth_pos - final_cloth_pos).abs().sum() > 0.1
    assert (init_water_pos - final_water_pos).abs().sum() > 0.1

    # check if the particles are above the ground
    assert final_mpm_cube_pos[..., 2].min() > -1e-5
    assert final_cloth_pos[..., 2].min() > -1e-5
    assert final_water_pos[..., 2].min() > -1e-5

    assert_allclose(cloth.get_particles_vel(), 0.0, atol=1e-5)
    assert_allclose(mpm_cube.get_particles_vel(), 0.0, atol=1e-4)
    assert_allclose(entity_fem._solver.get_state(0).vel, 0, atol=1e-3)
    assert_allclose(water.get_particles_vel(), 0.0, atol=5e-2)


def test_sf_solver(show_viewer):
    import gstaichi as ti

    res = 384
    orbit_tau = 0.2
    orbit_radius = 0.3
    orbit_radius_vel = 0.0

    jet_radius = 0.02

    sub_orbit_radius = 0.03
    sub_orbit_tau = 3.0

    scene = gs.Scene(
        sim_options=gs.options.SimOptions(
            dt=1e-2,
        ),
        sf_options=gs.options.SFOptions(
            res=res,
            solver_iters=200,