Traceback (most recent call last):
File “/Users/mlavrent/meshio/msh2xdmf-festim.py”, line 27, in
tetra_cells = np.concatenate(tetra_cells_list)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “<array_function internals>”, line 200, in concatenate
ValueError: need at least one array to concatenate
Does this mean the script only works with 3D .xdmf?
Yes I think this script in the documentation will only work with 3D geometries, you may have to swap all the mentions of “triangle” for “line” and “tetra”’ for “triangle”
As @jhdark said this script can be applied for a 2D .msh file with a few changes:
Consider this:
import meshio
import numpy as np
msh = meshio.read("my_mesh.msh")
# Initialize lists to store cells and their corresponding data
triangle_cells_list = []
line_cells_list = []
triangle_data_list = []
line_data_list = []
# Extract cell data for all types
for cell in msh.cells:
if cell.type == "triangle":
triangle_cells_list.append(cell.data)
elif cell.type == "line":
line_cells_list.append(cell.data)
# Extract physical tags
for key, data in msh.cell_data_dict["gmsh:physical"].items():
if key == "triangle":
triangle_data_list.append(data)
elif key == "line":
line_data_list.append(data)
# Concatenate all linehedral cells and their data
line_cells = np.concatenate(line_cells_list)
line_data = np.concatenate(line_data_list)
# Concatenate all triangular cells and their data
triangle_cells = np.concatenate(triangle_cells_list)
triangle_data = np.concatenate(triangle_data_list)
# Create the linehedral mesh
line_mesh = meshio.Mesh(
points=msh.points,
cells=[("line", line_cells)],
cell_data={"f": [line_data]},
)
# Create the triangular mesh for the surface
triangle_mesh = meshio.Mesh(
points=msh.points,
cells=[("triangle", triangle_cells)],
cell_data={"f": [triangle_data]},
)
# Write the mesh files
meshio.write("volume_mesh.xdmf", triangle_mesh)
meshio.write("surface_mesh.xdmf", line_mesh)