As you are using a stp file I do not have access to, I cannot really do much more than showing you a minimal working example.
Here is a minimal geo file (taken from the gmsh tutorial, called tutorial_t1.geo
lc = 1e-1;
Point(1) = {0, 0, 0, lc};
Point(2) = {.1, 0, 0, lc};
Point(3) = {.1, .3, 0, lc};
Point(4) = {0, .3, 0, lc};
Line(1) = {1, 2};
Line(2) = {3, 2};
Line(3) = {3, 4};
Line(4) = {4, 1};
Curve Loop(1) = {4, 1, -2, 3};
Plane Surface(1) = {1};
Physical Curve(666) = {1, 2, 4};
Physical Surface(555) = {1};
using gmsh -2 tutorial_gmsh.geo
and converting it using:
import meshio
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={
cell_type: cells}, cell_data={"name_to_read": [cell_data]})
if prune_z:
out_mesh.prune_z_0()
return out_mesh
mesh_from_file = meshio.read("tutorial_t1.msh")
triangle_mesh = create_mesh(mesh_from_file, "triangle", prune_z=True)
line_mesh = create_mesh(mesh_from_file, "line", prune_z=True)
meshio.write("mesh_2d.xdmf", triangle_mesh)
meshio.write("mesh_1d.xdmf", line_mesh)
You can visualize the corresponding xdmf files in paraview, and observe that the boundary data is written to the files.
Corresponding msh file (observe that the physical marker data is stored inside entities):
$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
4 4 1 0
1 0 0 0 0
2 0.1 0 0 0
3 0.1 0.3 0 0
4 0 0.3 0 0
1 0 0 0 0.1 0 0 1 666 2 1 -2
2 0.1 0 0 0.1 0.3 0 1 666 2 3 -2
3 0 0.3 0 0.1 0.3 0 0 2 3 -4
4 0 0 0 0 0.3 0 1 666 2 4 -1
1 0 0 0 0.1 0.3 0 1 555 4 4 1 -2 3
$EndEntities
$Nodes
8 11 1 11
0 1 0 1
1
0 0 0
0 2 0 1
2
0.1 0 0
0 3 0 1
3
0.1 0.3 0
0 4 0 1
4
0 0.3 0
1 1 0 0
1 2 0 2
5
6
0.1 0.2000000000002564 0
0.1 0.1000000000002544 0
1 4 0 2
7
8
0 0.2000000000002564 0
0 0.1000000000002544 0
2 1 0 3
9
10
11
0.05000000000000001 0.1500000000002553 0
0.05 0.2500000000001282 0
0.05 0.05000000000012717 0
$EndNodes
$Elements
4 19 1 19
1 1 1 1
1 1 2
1 2 1 3
2 3 5
3 5 6
4 6 2
1 4 1 3
5 4 7
6 7 8
7 8 1
2 1 2 12
8 3 4 10
9 8 1 11
10 2 6 11
11 6 5 9
12 7 8 9
13 9 5 10
14 7 9 10
15 8 6 9
16 6 8 11
17 1 2 11
18 5 3 10
19 4 7 10
$EndElements