Skip to content

[BUG] Can't create an ElementAssembler on a mixed type mesh imported from meshio #13

Description

@MechEngrLorenzoFiore

Description

LinearElasticityElementAssembler.from_mesh(mixed_types_mesh) fails when mixed_types_mesh is a mesh imported from ".inp" format, but only if the number of elements of different types mismatches.

Minimal reproducing example

"""
** single_part_mixed_types_inp_file.inp
*Node
1, 0.0, 0.0, 0
2, 0.0, 1.0, 0
3, 1.0, 0.0, 0
4, 1.0, 1.0, 0
5, 0.5, 1.5, 0
6, 0.0, 2.0, 0
*ELEMENT, TYPE=S4
1, 1, 2, 4, 3
*ELEMENT, TYPE=S3
2, 2, 5, 4
3, 2, 6, 5 
"""

import tensormesh as tm

mixed_types_mesh = tm.Mesh.read("single_part_mixed_types_inp_file.inp", reorder=True)

print(mixed_types_mesh)

mixed_types_mesh.save("single_part_mixed_types_inp_file.vtk")

mixed_types_mesh_form = tm.LinearElasticityElementAssembler.from_mesh(mixed_types_mesh, E=21e9, nu=0.2)

Full traceback / error output

Mesh(
    points: torch.Size([6, 2])
    cells: quad:torch.Size([1, 4]),triangle:torch.Size([2, 3])
    point_data:
    cell_data:
    field_data:
)
Traceback (most recent call last):
  File "/home/user/Simulations/tensormesh_dev/tensormesh_import_from_inp_MWE.py", line 9, in <module>
    mixed_types_mesh_form = tm.LinearElasticityElementAssembler.from_mesh(mixed_types_mesh, E=21e9, nu=0.2)
  File "/home/user/miniconda3/envs/tensormesh/lib/python3.14/site-packages/tensormesh/assemble/element_assembler.py", line 819, in from_mesh
    elem_u, elem_v = torch.stack(elem_u, -1).flatten(), torch.stack(elem_v, -1).flatten() # [num_elements * num_basis * num_basis]
                     ~~~~~~~~~~~^^^^^^^^^^^^
RuntimeError: stack expects each tensor to be equal size, but got [1] at entry 0 and [2] at entry 16

Expected behavior

I would expect the mesh to be imported and the form to be created without any issue even if the mesh has mixed element types.

Environment

torch:       2.12.0+cu130
torch_sla:   0.2.1
tensormesh:  0.1.1
python:      3.14.4
os:          Linux-6.18.33.1-microsoft-standard-WSL2-x86_64-with-glibc2.39
cuda:        n/a

Pre-flight checks

  • I searched existing issues and did not find a duplicate.
  • I confirmed this is a bug, not a usage question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions