Uncomplete cell markers when generating GMSH mesh using Meshio

Hi everyone

I have an issue with the markers when generating GMSH from text files using Meshio. Precisely, I have mesh information stored in text files like ‘node1.txt’ storing nodes coordinates, ‘elements1.txt’ storing mesh connectivity and makers. The code below will used for generating GMSH mesh.

Files: node1.txt, elements1.txt

import meshio
import numpy as np

# read data
list_nodes = np.loadtxt('nodes1.txt', delimiter=" ")
list_elements = np.loadtxt('elements1.txt', dtype="i", delimiter=" ")

# define points 
points = list_nodes

# define cells
cells = [ ("triangle", list_elements[:, 0:3]-1) ]

# define cell_data
cell_data_value = []
e1 = list_elements[:, -1][0]
tmp = []

# get maker
for e in list_elements[:, -1]:
    if e == e1:
        tmp.append(e)
    else:
        cell_data_value.append(np.asarray(tmp))
        e1 = e
        tmp = []
        tmp.append(e)

cell_data = {'gmsh:physical': cell_data_value}

# generate gmsh mesh
meshio.write_points_cells(
    "new_machine.msh",
    points,
    cells,
    cell_data=cell_data
    )

The markers are not complete, as shown in picture below.

If you know how to fix this issue, please let me know.

Best regards

Please supply a minimal example including the text file for your mesh (the mesh should not consist of more than 10 cells).

In general, why do you have mesh data stored in a text file? Where does this data originate from?

Hi Dokken,

Thank for your reply.

Here are the files. I will minimize my problem latter. The data comes from another software and sent by a colleague, from my side, I do not other option.

As meshio provides conversion between many mesh formats, including:

Abaqus, ANSYS msh, AVS-UCD, CGNS, DOLFIN XML, Exodus, FLAC3D, H5M, Kratos/MDPA, Medit, MED/Salome, Nastran (bulk data), Neuroglancer precomputed format, Gmsh (format versions 2.2, 4.0, and 4.1), OBJ, OFF, PERMAS, PLY, STL, Tecplot .dat, TetGen .node/.ele, SVG (2D only, output only), UGRID, VTK, VTU, WKT (TIN), XDMF.

you should check with your colleague if he can supply you the mesh in any of these formats.