Skip to content

ms.write_voxels(mesh=True) fails #32

@RZandomeni

Description

@RZandomeni

Description:

When calling mesh.write_voxels() with mesh=True and a voxelized mesh, the function crashes with:

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'

Steps to reproduce:

  1. Create an RVE using examples/RVE_generation/create_rve.py.
  2. Add mesh=True in ms.write_voxels(mesh=True).

Observed behavior:

The function fails at this line in api.py: "Values": [int(val) for val in self.mesh.voxel_dict.values()],

        if mesh:
            structure['Mesh'] = {
                "Nodes": {
                    "Description": 'Nodal coordinates',
                    "Type": 'float',
                    "Shape": self.mesh.nodes.shape,
                    "Values": [list(val) for val in self.mesh.nodes],
                },
                "Voxels": {
                    "Description": 'Node list per voxel',
                    "Type": 'int',
                    "Shape": (len(self.mesh.voxel_dict.keys()), 8),
                    "Values": [int(val) for val in self.mesh.voxel_dict.values()],
                }
            }

Expected behavior:

write_voxels() should correctly serialize the node connectivity for each voxel in JSON.

Proposed fix:

Replace:
"Values": [int(val) for val in self.mesh.voxel_dict.values()],
with:
"Values": [list(val) for val in self.mesh.voxel_dict.values()],. This ensures the 8-node connectivity of each voxel is preserved in the JSON output.

System

  • Kanapy version: v6.5.3-post1-46-g82139362
  • Python version: 3.10.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions