Skip to content

Parse mesh from elements and points file

Full example code: examples/parser/opencarp_mesh.py

The mesh of an OpenCARP simulation consists of vertices and a list of elements to connect these vertices. For a surface mesh, these elements often consist of triangles. The .pts file contains the index and coordinates of all the vertices (points). The .elem file contains a list of elements, connecting vertices using their points id.

from dgmr.parser import OpencarpReader

pts_file = "path_to_your_points_file"
elem_file = "path_to_your_elements_file"
vertices, elements = OpencarpReader.load_mesh(pts_file, elem_file)

print(vertices[:5])
print(elements[:5])

Output: pandas DataFrame for both vertices and elements.

      x     y     z
0  20.0   0.0   0.0
1 -20.0   0.0   0.0
2   0.0  20.0   0.0
3   0.0 -20.0   0.0
4   0.0   0.0  20.0

   vertex_0  vertex_1  vertex_2  Tags
0     11867     12924     12515     3
1     16044     20163     11912     0
2     12150     15774      2279     3
3     16789     20206     16572     3
4     11688     19615     12367     3