Genesis icon indicating copy to clipboard operation
Genesis copied to clipboard

[Bug]: Obtaining resultant force from FEMEntity

Open bahadir14 opened this issue 5 months ago • 0 comments

Bug Description

Hi, I am squeezing FEMEntity cube to get resultant force during process. I got error message of "[Genesis] [09:02:33] [ERROR] AttributeError: 'FEMEntity' object has no attribute 'get_dofs_force'"

Is there any way to obtain these results?

Steps to Reproduce

import argparse

import numpy as np import os import torch

from dask.order import order from mpmath import euler from pygel3d.hmesh import minimize_dihedral_angle from os import path os.environ['PYOPENGL_PLATFORM'] = 'glx' import genesis as gs

def main(): parser = argparse.ArgumentParser() parser.add_argument("-v", "--vis", action="store_true", default=False) args = parser.parse_args()

########################## init ##########################
gs.init(seed=0, precision="32", logging_level="debug")

########################## create a scene ##########################

scene = gs.Scene(
    sim_options=gs.options.SimOptions(
        dt=4e-3,
        substeps=2,
    ),
    fem_options=gs.options.FEMOptions(
        use_implicit_solver=True,
        damping_alpha=0.3,
    ),
    viewer_options=gs.options.ViewerOptions(
        camera_pos=(9.6, 4.8, 14.0),
        camera_lookat=(0.0, 0.0, 0.0),
        camera_fov=35,
        max_FPS=30,
    ),
    show_viewer=True,
    vis_options=gs.options.VisOptions(
        #visualize_mpm_boundary=True,
    ),
)
gs.engine.force_fields.Point(strength=1000,position=(0,0,0),falloff_pow=0.1,flow=1)
cam = scene.add_camera(
    res=(1280, 800),
    pos=(5.5, 6.5, 3.2),
    lookat=(0.5, 1.5, 1.5),
    fov=30,
    GUI=True,
)

plane = scene.add_entity(
    material=gs.materials.Rigid(),
    morph=gs.morphs.URDF(file="urdf/plane/plane.urdf", fixed=True),
)
E, nu = 1.e7,0.3
rho = 2700.0

obj1 = scene.add_entity(
    material=gs.materials.FEM.Elastic(
        E=E,
        nu=nu,
        rho=rho,
        model="linear",
    ),
    morph=gs.morphs.Box(
        pos=(0.0, 0.0, 0.25),
        size=(0.5,0.5,0.5),
    ),
    surface=gs.surfaces.Metal(
        color=(0.6, 1.0, 0.8, 1.0),
        vis_mode="visual",
    ),
)

scene.build()
cam.start_recording()

obj1_force_resultant = []

horizon = 1000
for i in range(horizon):
        if i < 400:
            obj1.set_velocity([0.0, 0.0, -5.0])
            #obj1.set_vertex_constraints(verts_idx=0)

        print(obj1.get_dofs_force())
        tensor_gpu = torch.tensor(obj1.get_dofs_force(), device='cuda')
        numpy_array = tensor_gpu.cpu().numpy()
        obj1_force_resultant.append(numpy_array)

        scene.step()
        cam.render()
cam.stop_recording(save_to_filename="fem_rigid_entities.mp4", fps=60)
np.savetxt("obj1_force_output.txt", obj1_force_resultant, fmt='%3f\t%3f\t%3f\t%3f\t%3f\t%3f\t')

if name == "main": main()

Expected Behavior

Obtaining reaction forces

Screenshots/Videos

No response

Relevant log output

Traceback (most recent call last):
  File "/home/bahadir/Desktop/genesis/genesis/part_1/modelling/fem_entity/cekme_test_simple/fem_cekme.py", line 99, in <module>
    main()
  File "/home/bahadir/Desktop/genesis/genesis/part_1/modelling/fem_entity/cekme_test_simple/fem_cekme.py", line 89, in main
    print(obj1.get_dofs_force())
          ^^^^^^^^^^^^^^^^^^^
  File "/home/bahadir/anaconda3/lib/python3.12/site-packages/gstaichi/lang/kernel_impl.py", line 1317, in _getattr
    x = super(cls, self).__getattribute__(item)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bahadir/anaconda3/lib/python3.12/site-packages/gstaichi/lang/kernel_impl.py", line 1317, in _getattr
    x = super(cls, self).__getattribute__(item)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'FEMEntity' object has no attribute 'get_dofs_force'

[Genesis] [09:02:33] [ERROR] AttributeError: 'FEMEntity' object has no attribute 'get_dofs_force'
[Genesis] [09:02:33] [INFO] 💤 Exiting Genesis and caching compiled kernels...

Process finished with exit code 1

Environment

  • OS: [e.g. Ubuntu 24.04]
  • GPU/CPU [RTX 4000]

Release version or Commit ID

0.3.3

Additional Context

No response

bahadir14 avatar Sep 05 '25 06:09 bahadir14