taichi-dev / meshtaichi

MeshTaichi: A Compiler for Efficient Mesh-based Operations (SIGGRAPH Asia 2022)
214 stars 11 forks source link

[Func] global index based get for a Member field #11

Closed Eydcao closed 1 year ago

Eydcao commented 1 year ago

Dear Chang,

I am writing to request your assistance in addressing an issue. Specifically, I am trying to use global indices to access a certain element. Unfortunately, currently, the mesh object does not currently support global access to a MemberField by an index.

One example is that I would like to use an integer to indicate in which tetrahedron a particle lies inside. Then, once I have identified the tetrahedron, I can use its relationship with vertices to perform additional operations. Here is an example code:

for p in particle_pos:
    # find which tetra this p lies in, and re-use this index intensively later to avoid re-search
    tetra_id = 1000  # 1000 is just an example
    tetra = mesh.cells[tetra_id]  # this currently triggers an AttributeError: 'MeshElementField' object has no attribute '__getitem__'
    for v in tetra.verts:
        # perform some other operation

I am wondering if it is difficult to implement global access to a MemberField by an index, or if this feature is simply obsolete. If it is obsolete, I would greatly appreciate any advice you can offer on how to work around this issue.

Thank you for your time and assistance.

Sincerely, Yadi

g1n0st commented 1 year ago

Hi Yadi,

Sorry for the late reply due to my vacation. Currently ti.Mesh doesn't support accessing mesh relations directly by a global index (mesh attribute is ok using syntax like mesh.verts.x[g_idx]) since these accesses will not enjoy acceleration from the MeshTaichi framework.

However, we refer users to export the relations they want to directly access as common Taichi fields and then access them using a global index, like:

https://github.com/taichi-dev/meshtaichi/blob/3074198f817994832446cd9f06ff083f4a5eac85/mass_spring/ms.py#L72-L82

Hope this is helpful! Feel free to contact me if you have further questions.

Sincerely, Chang Yu

Eydcao commented 1 year ago

Thanks Chang!

Please let me know when (if possible) you like to add this function. I can do some help. Currently we can close this issue.

Best, Yadi