Meshio does not read Gmsh physical groups

Hi All,

I am trying to use Gmsh .msh file in FEniCS. The environment is FEniCS container with meshio 4.3.12 installed. Gmsh is 4.8.0. and not in the container.

I generated a simple model (a unit box with a cylinder hole in y direction), and defined two surface physical groups 1/2, (top/bottom surface of the box). I export the mesh to box.msh in version 2 format. I used the python codes discussed previously, in which meshio reads the msh file and generates two xdmf files. The first one, mesh.xdmf is tetra cells, which is OK. The second mf.xdmf file is triangle cells, supposedly referring to the two physical surfaces 1/2. However, in paraview mf.xdmf is all surfaces of the box and cylinder hole. mesh_from_file.get_cell_data("gmsh:physical", "triangle") gives an array of all 0 elements. It seems the meshio failed to recognize physical groups.

If the mesh is exported as version 4 msh format, the meshio.read(box.msh) throws an error “ValueError: Incompatible cell data. 33 cell blocks, but ‘gmsh:physical’ has 2 blocks.”

Could anyone help? I followed this thread closely (Gmsh 4.4.1 in FEniCS? Meshio) , and also this one Meshio Changelog - pyup.io (meshio ver 4.0 change mesh.cells from dict to list tuples).

Thank you!

The geo code

// Gmsh project created on Fri Apr 09 22:46:46 2021
SetFactory("OpenCASCADE");
//+
Box(1) = {0, 0, 0, 1, 1, 1};
//+
Cylinder(2) = {0.3, 0, 0.5, 0, 1, 0, 0.1, 2*Pi};
//+
BooleanDifference{ Volume{1}; Delete; }{ Volume{2}; Delete; };
//+
Physical Surface("1", 28) = {10};
//+
Physical Surface("2", 29) = {12};

python code

import meshio
import numpy
mesh_from_file = meshio.read("box.msh")

meshio.write("mesh.xdmf", meshio.Mesh(points=mesh_from_file.points, 
                                      cells={"tetra": mesh_from_file.get_cells_type("tetra")}))

meshio.write("mf.xdmf", meshio.Mesh(points=mesh_from_file.points, cells={"triangle": mesh_from_file.get_cells_type("triangle")}, 
                                    cell_data={"name_to_read": [mesh_from_file.get_cell_data("gmsh:physical", "triangle")]}))

My python code and geo codes are attached

I do not know if this will fix your issue or not, I don’t really have time to test it myself, but are you missing a semicolon at the end of the “BooleanDifference” line?

Thank you @Firemage0520 . I don’t know why it is missing a semicolon, but it works in gmsh. I have just added a semicolon, and it did not change any behaviors that I mentioned in my original post.

I may have missed something in a hurry, but the following could be of some help as a starting point. I save all the physical entities (volume/surface). Note this is pygmsh-6.1.1 since I prefer to use that over the newer releases.

import numpy as np
import meshio, pygmsh, os

geom = pygmsh.opencascade.Geometry()
b1 = geom.add_box([0.0, 0.0, 0.0], [1.0, 1.0, 1.0])
cyl1 = geom.add_cylinder([0.3, 0.0, 0.5], [0.0, 1.0, 0], 0.1, 2 * np.pi)
final = geom.boolean_difference([b1], [cyl1])
geom.add_raw_code("eps=1.E-3;")
geom.add_raw_code(
    "bottom() = Surface In BoundingBox {-eps, -eps, -eps, 1 + eps, eps, 1 + eps};"
)
geom.add_raw_code(
    "top() = Surface In BoundingBox {-eps, 1-eps, -eps, 1 + eps, 1 + eps, 1 + eps};"
)

geom.add_raw_code('Physical Surface("top") = top();')
geom.add_raw_code('Physical Surface("bottom") = bottom();')
geom.add_raw_code('Physical Volume("domain") = bo1[];')

msh = pygmsh.generate_mesh(geom, geo_filename=os.path.join(os.getcwd(), "testmesh.geo"))

tetramesh = meshio.Mesh(msh.points, cells={"tetra": msh.get_cells_type("tetra")})
cellData = msh.get_cell_data("gmsh:physical", "triangle")
trimesh = meshio.Mesh(
    msh.points,
    cells={"triangle": msh.get_cells_type("triangle")},
    cell_data={"bdry": [cellData]},
)
meshio.xdmf.write("testmesh.xdmf", tetramesh)
meshio.xdmf.write("testmesh_tri.xdmf", trimesh)

and the corresponding geo file:

// This code was created by pygmsh vunknown.
SetFactory("OpenCASCADE");
vol0 = newv;
Box(vol0) = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
vol1 = newv;
Cylinder(vol1) = {0.3, 0.0, 0.5, 0.0, 1.0, 0, 0.1, 6.283185307179586};
bo1[] = BooleanDifference{ Volume{vol0}; Delete; } { Volume{vol1}; Delete;};
eps=1.E-3;
bottom() = Surface In BoundingBox {-eps, -eps, -eps, 1 + eps, eps, 1 + eps};
top() = Surface In BoundingBox {-eps, 1-eps, -eps, 1 + eps, 1 + eps, 1 + eps};
Physical Surface("top") = top();
Physical Surface("bottom") = bottom();
Physical Volume("domain") = bo1[];

Please also checkout the meshing tutorials by @dokken https://jsdokken.com/converted_files/tutorial_gmsh.html for a much more comprehensive usage of the gmsh python API and loading the generated meshes into dolfin (or dolfinx), in case if you haven’t.

My understanding of top/bottom corresponds to y=1/y=0, but you can change that according to your definitions.

Thank you @bhaveshshrimali for your detailed response. My ultimate goal is to use gmsh API/pygmsh to generate the mesh, and solve in FEniCS. Since I have little to no knowledge of any of them, I had to divide them and learn step by step.

As to your suggestions

  1. I tried the geo file. Your geo file opens OK in my Gmsh GUI 4.8.0. However I meshed the model, and exported to .msh. The same problems remain when I ran my python code: Meshio.read() can read ver2 msh file, but does not recognize physical groups; ver4 msh file cannot be properly read by Meshio.

  2. I also tried to run your python/pygmsh code. I had to install pygmsh and gmsh to the FEniCS container following this thread (Problem with installation of latest gmsh 4.6.0 via pip - #3 by Nexius). I could import meshio and pygmsh in container’s bash, but not directly in jupyter notebook (Jupyter did not find module of pygmsh). I did the following in Jupyter to be able to import gmsh and pygmsh. However there are errors about opencascade, see below.

import sys
sys.path.append('/usr/local/gmsh-4.6.0-Linux64-sdk/lib')    # have to add path manually to import gmsh
sys.path.append('/usr/local/gmsh-4.6.0-Linux64-sdk/bin')
import meshio
import gmsh
import pygmsh, os
import numpy as np

#geom = pygmsh.opencascade.Geometry()     # pygmsh has no opencascade attribute
geom = pygmsh.geo.Geometry()                      # pygmsh.geo.Geometry() works
b1 = geom.add_box([0.0, 0.0, 0.0], [1.0, 1.0, 1.0])     # error: add_box() missing 4 required positional arguments: 'y0', 'y1', 'z0', and 'z1'

It seems pygmsh (v7.1.8) has no .opencascade, but .geo attribute. ‘add_box’ needs 4 arguments. I have not yet started studying pygmsh/gmsh API but your code provides me a good point to start with.

At this point I will try to stick to 1), i.e. generate a mesh from Gmsh GUI with physical groups, and then use my python code to read (via meshio) and export to separate xdmf files. Any insights?

I am not sure if I follow. pygmsh-6.1.1 in my case does exactly what you are doing (except for the GUI). It writes the geo file, spawns a process on the command line and calls gmsh. If you take the above geo file (say test.geo), and then simply run from the terminal:

gmsh -3 test.geo -o test.msh

and then read your test.msh using the code snippet above, it should work. Also, I think that the default format when saving as .msh is indeed MSH 4.1 and not MSH 2.0. I have checked this just now.

Yes, so you should uninstall the latest pygmsh and instead do

pip3 install pygmsh==6.1.1

if you want to run the above code. I think the link that I posted above also has updated tutorials on using the later versions of pygmsh. pygmsh-7 onwards uses the gmsh python API and hence I directly use that instead.

Dear all.

Just a small note: instead of using pygmsh and opencascade one can also use the built-in functions in gmsh! Here is a small example of how to fragment two cylinders:

# Done with gmsh 4.6.0
import numpy as np
import scipy.constants as const

import gmsh

gmsh.initialize()

cyl1_x    =   0.0
cyl1_y    =   0.0
cyl1_z    =   0.0
cyl1_vx   =   0.0
cyl1_vy   =   0.0
cyl1_vz   =  50.0
cyl1_size = 100.0

cyl2_x    =  0.0
cyl2_y    =  0.0
cyl2_z    = 40.0
cyl2_vx   =  0.0
cyl2_vy   =  0.0
cyl2_vz   = 50.0
cyl2_size = 50.0

cyl1_1 = gmsh.model.occ.addCylinder(cyl1_x,
                                    cyl1_y,
                                    cyl1_z,
                                    cyl1_vx,
                                    cyl1_vy,
                                    cyl1_vz,
                                    cyl1_size,
                                    angle=2.0*const.pi)

cyl2_1 = gmsh.model.occ.addCylinder(cyl2_x,
                                    cyl2_y,
                                    cyl2_z,
                                    cyl2_vx,
                                    cyl2_vy,
                                    cyl2_vz,
                                    cyl2_size,
                                    angle=2.0*const.pi)

gmsh.model.occ.fragment([(3, cyl1_1)], [(3, cyl2_1)],
                                 removeObject=True,
                                 removeTool=False)

gmsh.model.occ.removeAllDuplicates()

gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)
gmsh.write("mesh.msh")

Other objects: gmsh.model.occ.addCylinder, gmsh.model.occ.addCone, gmsh.model.occ.addSphere and so on …

… and, because this might get important: once created a gmsh file, you have an interest for the import of the gmsh mesh into FEniCS. Below you find two definitions, how I import 2D or 3D meshes into FEniCS (this was derived, e.g., from here and so on).

First you use convert_mesh_xdmf and then load_mesh_to_fenics. It is written such that you can use MPI (see, e.g., here).

Greetings … .

import os
import numpy as np
import meshio
from fenics import *


# _________________________________________________________________ Definitions

# Convert the 'gmsh' specific mesh into a XDMF mesh. This is done for MPI
#
# i             => process number (MPI)
# file_mesh     => gmsh file
# dir_data      => directory of the mesh files
# dimension     => either "2D" or "3D"
#
def convert_mesh_xdmf(i, file_mesh, dir_data, dimension):

    mesh = meshio.read(file_mesh)

    string_nr = "{:04d}".format(i)

    tetra_cells    = None # For 3D only
    tetra_data     = None # For 3D only
    triangle_cells = None # For 2D and 3D
    triangle_data  = None # For 2D and 3D
    line_cells     = None # For 2D only
    line_data      = None # For 2D only

    for key in mesh.cell_data_dict["gmsh:physical"].keys():
        if key == "triangle":
            triangle_data = mesh.cell_data_dict["gmsh:physical"][key]
        elif key == "tetra":
            tetra_data = mesh.cell_data_dict["gmsh:physical"][key]
        elif key == "line":
            line_data = mesh.cell_data_dict["gmsh:physical"][key]

    for cell in mesh.cells:
        if cell.type == "tetra":
            if tetra_cells is None:
                tetra_cells = cell.data
            else:
                tetra_cells = np.vstack([tetra_cells, cell.data])
        elif cell.type == "triangle":
            if triangle_cells is None:
                triangle_cells = cell.data
            else:
                triangle_cells = np.vstack([triangle_cells, cell.data])
        elif cell.type == "line":
            if line_cells is None:
                line_cells = cell.data
            else:
                line_cells = np.vstack([line_cells, cell.data])

    line_mesh  = meshio.Mesh(points=mesh.points,
                             cells={"line": line_cells},
                             cell_data={"name_to_read":[line_data]})
    tetra_mesh = meshio.Mesh(points=mesh.points,
                             cells={"tetra": tetra_cells},
                             cell_data={"name_to_read":[tetra_data]})

    triangle_mesh =meshio.Mesh(points=mesh.points,
                               cells=[("triangle", triangle_cells)],
                               cell_data={"name_to_read":[triangle_data]})

    file_msh_subd = os.path.join(dir_data, "Data_"+string_nr+"_msh_subd.xdmf")
    file_bound    = os.path.join(dir_data, "Data_"+string_nr+"_bound.xdmf")

    if dimension == "2D":
        meshio.write(file_msh_subd, triangle_mesh)
        meshio.write(file_bound,    line_mesh)
    if dimension == "3D":
        meshio.write(file_msh_subd, tetra_mesh)
        meshio.write(file_bound,    triangle_mesh)


# Import the mesh, boundaries and subdomains into FEniCS.
#
# i             => process number (MPI)
# dir_data      => directory of the mesh files
#
def load_mesh_to_fenics(i, dir_data):

    string_nr = "{:04d}".format(i)

    file_msh_subd = os.path.join(dir_data, "Data_"+string_nr+"_msh_subd.xdmf")
    file_bound    = os.path.join(dir_data, "Data_"+string_nr+"_bound.xdmf")

    # Open the latter files and obtain the mesh, subdomains, boundaries,
    # dx and ds.
    mesh = Mesh(MPI.comm_self)
    with XDMFFile(MPI.comm_self, file_msh_subd) as infile:
        infile.read(mesh)

    mvc = MeshValueCollection("size_t", mesh, 2)
    with XDMFFile(MPI.comm_self, file_bound) as infile:
        infile.read(mvc, "name_to_read")
    boundaries = cpp.mesh.MeshFunctionSizet(mesh, mvc)

    mvc2 = MeshValueCollection("size_t", mesh, 3)
    with XDMFFile(MPI.comm_self, file_msh_subd) as infile:
        infile.read(mvc2, "name_to_read")
    subdomains = cpp.mesh.MeshFunctionSizet(mesh, mvc2)

    dx = Measure("dx", domain=mesh, subdomain_data=subdomains)
    ds = Measure("ds", domain=mesh, subdomain_data=boundaries)
    dS = Measure("dS", domain=mesh, subdomain_data=boundaries)

    # We note some statistical information into the parameter class
    n_cells     = mesh.num_cells()
    n_facets    = mesh.num_faces()
    n_vertices  = mesh.num_vertices()
    n_edges     = mesh.num_edges()

    # We print out this info on the terminal for the case that we decide to
    # eventually stop the calculations.
    print("Mesh information")
    print("================")
    print("No. of cells   : ", n_cells)
    print("No. of faces   : ", n_facets)
    print("No. of vertices: ", n_vertices)
    print("No. of edges   : ", n_edges)

    return n_cells, n_facets, n_vertices, n_edges, mesh, subdomains, boundaries, dx, ds, dS

@bhaveshshrimali what you have done is absolutely correct, as evident by the plots. @Nexius , thank you for the gmsh build-in codes. They actually ran well on my system. I have not studied gmsh API yet but will do so.

I tend to believe there are some conflicts between Gmsh (in Win10) and FEniCS+Meshio+pygmsh container in my system. I have tried ver 6.1.1 and 7.8 of pygmsh, but both seem not to connect to the gmsh in the docker container. I have also tried Meshio 3.1 and 4.7; again neither of them read Gmsh(Win 10 GUI)'s .msh in ver4 format; while they both can read msh in ver2, they failed to recognize the physical groups (msh.get_cell_data("gmsh:physical", "triangle") gives all 0 array).

At this point my system is a mess. I will remove the fenics docker container completely, and start from scratch. I will also get a linux computer (my old laptop) to run Gmsh in linux to see if I can solve (or reproduce) the problem. Will report here later in few days.

BTW, it would be appreciated if any of you can provide a 3d .msh file with physical surface groups generated from this thread. It would help me narrow down the problem. Thank you so much!

Here you go

$MeshFormat
4.1 0 8
$EndMeshFormat
$PhysicalNames
3
2 1 "top"
2 2 "bottom"
3 3 "domain"
$EndPhysicalNames
$Entities
10 15 7 1
9 0.2999999999999999 1 0.6 0 
10 0.2999999999999999 0 0.6 0 
11 0 0 1 0 
12 0 0 0 0 
13 0 1 1 0 
14 0 1 0 0 
15 1 0 0 0 
16 1 0 1 0 
17 1 1 1 0 
18 1 1 0 0 
13 0.1999999 0.9999999000000001 0.3999999 0.4000001 1.0000001 0.6000000999999999 0 2 9 -9 
14 0.2999998999999999 -9.999999994736442e-08 0.5999999 0.3000000999999999 1.0000001 0.6000000999999999 0 2 10 -9 
15 0.1999999 -1e-07 0.3999999 0.4000001 1e-07 0.6000000999999999 0 2 10 -10 
16 -1e-07 -1e-07 -9.999999994736442e-08 1e-07 1e-07 1.0000001 0 2 12 -11 
17 -1e-07 -9.999999994736442e-08 0.9999999000000001 1e-07 1.0000001 1.0000001 0 2 11 -13 
18 -1e-07 0.9999999000000001 -9.999999994736442e-08 1e-07 1.0000001 1.0000001 0 2 14 -13 
19 -1e-07 -9.999999994736442e-08 -1e-07 1e-07 1.0000001 1e-07 0 2 12 -14 
20 -9.999999994736442e-08 -1e-07 -1e-07 1.0000001 1e-07 1e-07 0 2 12 -15 
21 0.9999999000000001 -1e-07 -9.999999994736442e-08 1.0000001 1e-07 1.0000001 0 2 15 -16 
22 -9.999999994736442e-08 -1e-07 0.9999999000000001 1.0000001 1e-07 1.0000001 0 2 11 -16 
23 -9.999999994736442e-08 0.9999999000000001 0.9999999000000001 1.0000001 1.0000001 1.0000001 0 2 13 -17 
24 0.9999999000000001 -9.999999994736442e-08 0.9999999000000001 1.0000001 1.0000001 1.0000001 0 2 16 -17 
25 -9.999999994736442e-08 0.9999999000000001 -1e-07 1.0000001 1.0000001 1e-07 0 2 14 -18 
26 0.9999999000000001 0.9999999000000001 -9.999999994736442e-08 1.0000001 1.0000001 1.0000001 0 2 18 -17 
27 0.9999999000000001 -9.999999994736442e-08 -1e-07 1.0000001 1.0000001 1e-07 0 2 15 -18 
7 0.1999999 -9.999999994736442e-08 0.3999999 0.4000001 1.0000001 0.6000000999999999 0 4 13 -14 15 14 
8 -1e-07 -9.999999994736442e-08 -9.999999994736442e-08 1e-07 1.0000001 1.0000001 0 4 16 17 -18 -19 
9 -9.999999994736442e-08 -1e-07 -9.999999994736442e-08 1.0000001 1e-07 1.0000001 1 2 5 20 21 -22 -16 15 
10 -9.999999994736442e-08 -9.999999994736442e-08 0.9999999000000001 1.0000001 1.0000001 1.0000001 0 4 17 23 -24 -22 
11 -9.999999994736442e-08 0.9999999000000001 -9.999999994736442e-08 1.0000001 1.0000001 1.0000001 1 1 5 25 26 -23 -18 13 
12 -9.999999994736442e-08 -9.999999994736442e-08 -1e-07 1.0000001 1.0000001 1e-07 0 4 19 25 -27 -20 
13 0.9999999000000001 -9.999999994736442e-08 -9.999999994736442e-08 1.0000001 1.0000001 1.0000001 0 4 21 24 -26 -27 
1 -9.999999994736442e-08 -9.999999994736442e-08 -9.999999994736442e-08 1.0000001 1.0000001 1.0000001 1 3 7 8 9 10 11 12 13 7 
$EndEntities
$Nodes
33 189 1 189
0 9 0 1
1
0.2999999999999999 1 0.6
0 10 0 1
2
0.2999999999999999 0 0.6
0 11 0 1
3
0 0 1
0 12 0 1
4
0 0 0
0 13 0 1
5
0 1 1
0 14 0 1
6
0 1 0
0 15 0 1
7
1 0 0
0 16 0 1
8
1 0 1
0 17 0 1
9
1 1 1
0 18 0 1
10
1 1 0
1 13 0 13
11
12
13
14
15
16
17
18
19
20
21
22
23
0.3433883739117558 1 0.5900968867902419
0.378183148246803 1 0.5623489801858733
0.3974927912181824 1 0.5222520933956314
0.3974927912181824 1 0.4777479066043686
0.378183148246803 1 0.4376510198141266
0.3433883739117558 1 0.4099031132097581
0.3 1 0.4
0.2566116260882442 1 0.4099031132097581
0.221816851753197 1 0.4376510198141266
0.2025072087818176 1 0.4777479066043686
0.2025072087818176 1 0.5222520933956314
0.221816851753197 1 0.5623489801858733
0.2566116260882442 1 0.5900968867902419
1 14 0 3
24
25
26
0.2999999999999999 0.25 0.6
0.2999999999999999 0.5 0.6
0.2999999999999999 0.75 0.6
1 15 0 13
27
28
29
30
31
32
33
34
35
36
37
38
39
0.3433883739117558 0 0.5900968867902419
0.378183148246803 0 0.5623489801858733
0.3974927912181824 0 0.5222520933956314
0.3974927912181824 0 0.4777479066043686
0.378183148246803 0 0.4376510198141266
0.3433883739117558 0 0.4099031132097581
0.3 0 0.4
0.2566116260882442 0 0.4099031132097581
0.221816851753197 0 0.4376510198141266
0.2025072087818176 0 0.4777479066043686
0.2025072087818176 0 0.5222520933956314
0.221816851753197 0 0.5623489801858733
0.2566116260882442 0 0.5900968867902419
1 16 0 1
40
0 0 0.5
1 17 0 1
41
0 0.5 1
1 18 0 1
42
0 1 0.5
1 19 0 1
43
0 0.5 0
1 20 0 1
44
0.5 0 0
1 21 0 1
45
1 0 0.5
1 22 0 1
46
0.5 0 1
1 23 0 1
47
0.5 1 1
1 24 0 1
48
1 0.5 1
1 25 0 1
49
0.5 1 0
1 26 0 1
50
1 1 0.5
1 27 0 1
51
1 0.5 0
2 7 0 72
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
0.2158831334920706 0.3923495142414911 0.4459227148528406
0.2761961584839044 0.9604106880638535 0.4028744259781359
0.3634869330403887 0.03831174889097004 0.422738047312243
0.2386231727844231 0.04358306987508974 0.4210513769534312
0.3570097700799455 0.9643020440273072 0.4178423094565594
0.2099031132097581 0.9615398792819613 0.4566116260882442
0.3998149979341919 0.0402335755485877 0.5060799825161972
0.2006387343456938 0.04463611509859518 0.5112844533573588
0.3998332397898698 0.9498469300850713 0.5057727145311671
0.2077926391976693 0.9320092890222652 0.5387014549321962
0.3623489801858734 0.03846012071803868 0.5781831482468029
0.2427789202035358 0.06551712364413304 0.5820106580081313
0.3623489801858734 0.9615398792819613 0.5781831482468029
0.3797060310694752 0.2602358202569108 0.4396100288859827
0.2182516267225869 0.6183517637617151 0.4424048312226039
0.3796269607326741 0.7406825247823771 0.4395058091675145
0.2064776706496701 0.2286307791811557 0.4645941542554281
0.2108313185116438 0.1099494595663458 0.5452652873803766
0.201397429607044 0.7748268091916823 0.4833406749265718
0.2051589009804572 0.1001367986472977 0.4682956479838291
0.2008376519190208 0.5465566238979098 0.5129162193797846
0.3900968867902419 0.09839785831883457 0.5433883739117558
0.3822365077259767 0.1577804642613315 0.4431039825907351
0.2027766701841026 0.2017121584798905 0.5234013704622023
0.390096886790242 0.8984569796158656 0.5433883739117558
0.3799514369087308 0.8358490561890591 0.4399353037448016
0.3216472360320022 0.03882347299601251 0.4023711253154335
0.3433883739119202 0.07875205048216619 0.4099031132098372
0.2910778962558675 0.0815690198284634 0.4003988149428987
0.3874962805904429 0.4620099659319037 0.4515809863500042
0.394080486520681 0.2060438389358394 0.5338948676945635
0.2929133968342376 0.2128928913420621 0.400251415771596
0.291103317646789 0.2922135565086291 0.4003965410083261
0.375860155356208 0.3622128415630234 0.434844518040828
0.3899273463574454 0.08139540858120281 0.4562613171539419
0.2907395725499942 0.4673544065685912 0.4004297007966574
0.312627570582136 0.1357620560054761 0.4008004815475742
0.248344000447046 0.1419720086764203 0.4143749002325532
0.2772700915578253 0.0403461688819623 0.4026175002261169
0.2884917828741596 0.5604605933944108 0.4006644024602232
0.2995785948747858 0.6594250183883547 0.4000008879153397
0.2318030986395805 0.7120177519093482 0.4268618933466472
0.2003116402700864 0.6868569252154035 0.5078886585906188
0.2765461859248534 0.7774843477448434 0.4027893081737999
0.2190317035358099 0.8561708272736299 0.4413132470851638
0.2043797663491053 0.8731223043031151 0.5292706494042805
0.2895679845615454 0.8681180959763357 0.4005456232542185
0.2397570424217887 0.2538314708391592 0.4201827959508112
0.3222347097361009 0.9567862693574799 0.4025032427054553
0.347421119371265 0.9151160417501456 0.4119588877990729
0.2457957804610708 0.9129620320904189 0.4159648729150984
0.3952643494511181 0.7937802877891522 0.5304089415083008
0.2427081495184184 0.0880874457781316 0.4180387660634852
0.2368937934799485 0.9562815594728733 0.4224267655782704
0.2133153850677278 0.3183353435264286 0.5498575724844651
0.2039263086753709 0.4436934527542419 0.5277460958561719
0.2101344626131351 0.05065286779411843 0.4561344646656401
0.3900968867902419 0.03846012071748597 0.4566116260882441
0.2167741313452046 0.4669211351670507 0.444561251938245
0.3894678350950599 0.9561261735056521 0.4553289077433386
0.389483631011019 0.6298599074942695 0.4553605580110615
0.2000619238457093 0.9415354278625759 0.5035186552231212
0.2470507577240148 0.9021787490567172 0.5848314666995628
0.2753111373246698 0.3808736411652127 0.4030956138257989
0.3936913014168984 0.3189119522255695 0.5349562589361031
0.2075109635163826 0.9201702453734056 0.4619766107463829
0.2088835902394095 0.1721375954053822 0.4587956328486874
0.2309286259135025 0.312325487359276 0.4276871706970117
0.221445578681314 0.5439448267534163 0.4381194465822551
0.3979179184798931 0.8894769322329737 0.479700215750777
0.2981534665770154 0.9187650272505155 0.4000170498819033
0.2382427737370737 0.202155852528299 0.4213485854907255
2 8 0 4
124
125
126
127
0 0.25 0.75
0 0.625 0.625
0 0.71875 0.2812499999999999
0 0.3457031250000001 0.3457031250000001
2 9 0 15
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
0.7328971425872275 0 0.2582937972405249
0.6907672434260151 0 0.5369140294925234
0.5091090617824467 0 0.3767750978479607
0.4360345475541838 0 0.5
0.543119161971223 0 0.657373619024493
0.4684619712449832 0 0.2322029112958924
0.2746116859212392 0 0.3663203074054499
0.3653705742380441 0 0.3535370917297228
0.2614658690224948 0 0.2699587614635988
0.7509925273398023 0 0.7801272949227218
0.4060337130399908 0 0.7859024046796717
0.2697294654279183 0 0.6326238774315993
0.3583539997860928 0 0.7010720924543761
0.250847718572457 0 0.7402781935359314
0.3323617487196485 0 0.6367176082776536
2 10 0 4
143
144
145
146
0.2613884839650146 0.2613884839650146 1
0.625 0.3750000000000001 1
0.3508564139941691 0.6425230806608357 1
0.71875 0.71875 1
2 11 0 15
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
0.7328971425872275 1 0.2582937972405249
0.6907672434260151 1 0.5369140294925234
0.5091090617824467 1 0.3767750978479607
0.4360345475541838 1 0.5
0.543119161971223 1 0.657373619024493
0.4684619712449832 1 0.2322029112958924
0.2746116859212392 1 0.3663203074054499
0.3653705742380441 1 0.3535370917297228
0.2614658690224948 1 0.2699587614635988
0.7509925273398023 1 0.7801272949227218
0.4060337130399908 1 0.7859024046796717
0.2697294654279183 1 0.6326238774315993
0.3583539997860928 1 0.7010720924543761
0.250847718572457 1 0.7402781935359314
0.3323617487196485 1 0.6367176082776536
2 12 0 4
162
163
164
165
0.25 0.75 0
0.625 0.625 0
0.71875 0.2812499999999999 0
0.3457031250000001 0.3457031250000001 0
2 13 0 4
166
167
168
169
1 0.2613884839650146 0.2613884839650146
1 0.625 0.3750000000000001
1 0.3508564139941691 0.6425230806608357
1 0.71875 0.71875
3 1 0 20
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
0.09505330940837238 0.1255412817021685 0.3393395103992923
0.4230499153597994 0.2041244438684116 0.2676740838055393
0.7095392524470649 0.3229036600494383 0.419418110545426
0.6360848554435858 0.5378217607785112 0.6835863399119999
0.3526821675438731 0.8821317376480491 0.2720163719451475
0.4495885571722107 0.4425117333884452 0.2147249602066515
0.6078331627435622 0.8024341283091321 0.4421416375766835
0.1122623556150863 0.8797044936091502 0.2977044874659281
0.2455752509749342 0.9229748568790236 0.3239078196958322
0.5435281627861697 0.1422656499414537 0.4893065429329083
0.2358733790186436 0.07320436502789401 0.3284564920861708
0.5724040484999077 0.2612137665245745 0.7343108268404404
0.2163326185609402 0.2512072926255695 0.1920975231377167
0.4579914133828347 0.6769333060560804 0.2274202113565141
0.202985932023773 0.706259336398978 0.2150023436156553
0.1424384318048363 0.492924377965467 0.2361765447191848
0.09853156897635787 0.5653251222479154 0.4153444960172225
0.5053988727394052 0.7534109754470588 0.7695485179179072
0.08633988727708573 0.3192298270446811 0.4690049154951993
0.130295445201412 0.7989033919464755 0.7729001234402958
$EndNodes
$Elements
3 676 1 676
2 9 2 52
1 2 27 142 
2 39 2 139 
3 139 2 142 
4 3 40 141 
5 46 3 141 
6 40 4 136 
7 4 44 136 
8 44 7 128 
9 7 45 128 
10 45 8 137 
11 8 46 137 
12 27 28 142 
13 28 29 131 
14 28 131 132 
15 28 132 140 
16 28 140 142 
17 29 30 131 
18 30 31 131 
19 31 32 135 
20 32 33 135 
21 33 34 134 
22 34 35 134 
23 35 36 40 
24 36 37 40 
25 40 37 38 
26 40 38 141 
27 38 39 139 
28 38 139 141 
29 35 40 136 
30 44 128 133 
31 44 133 136 
32 128 45 129 
33 129 45 137 
34 46 132 137 
35 132 46 138 
36 138 46 141 
37 31 130 131 
38 130 31 135 
39 33 134 135 
40 134 35 136 
41 128 129 130 
42 128 130 133 
43 130 129 131 
44 131 129 132 
45 132 129 137 
46 133 130 135 
47 132 138 140 
48 133 135 136 
49 135 134 136 
50 140 138 141 
51 139 140 141 
52 140 139 142 
2 11 2 52
53 1 161 11 
54 23 158 1 
55 158 161 1 
56 5 160 42 
57 47 160 5 
58 42 155 6 
59 6 155 49 
60 9 156 47 
61 50 156 9 
62 49 147 10 
63 10 147 50 
64 11 161 12 
65 12 150 13 
66 12 151 150 
67 12 159 151 
68 12 161 159 
69 13 150 14 
70 14 150 15 
71 15 154 16 
72 16 154 17 
73 17 153 18 
74 18 153 19 
75 19 42 20 
76 20 42 21 
77 42 22 21 
78 42 160 22 
79 22 158 23 
80 22 160 158 
81 19 155 42 
82 47 156 151 
83 151 157 47 
84 157 160 47 
85 49 152 147 
86 49 155 152 
87 147 148 50 
88 148 156 50 
89 15 150 149 
90 149 154 15 
91 17 154 153 
92 153 155 19 
93 147 149 148 
94 147 152 149 
95 149 150 148 
96 150 151 148 
97 151 156 148 
98 152 154 149 
99 151 159 157 
100 152 155 154 
101 154 155 153 
102 159 160 157 
103 158 160 159 
104 159 161 158 
3 1 4 572
105 81 112 172 175 
106 96 95 93 184 
107 81 172 112 173 
108 112 176 172 183 
109 65 171 85 172 
110 74 86 79 130 
111 65 85 116 172 
112 112 173 172 176 
113 107 25 124 106 
114 86 54 79 130 
115 142 140 63 139 
116 85 81 116 172 
117 106 25 124 24 
118 101 111 121 149 
119 111 101 56 149 
120 155 42 6 177 
121 112 172 175 183 
122 18 105 19 153 
123 114 161 158 159 
124 114 161 159 26 
125 172 176 167 183 
126 85 84 115 175 
127 2 24 63 142 
128 171 172 65 179 
129 65 172 116 179 
130 123 83 89 180 
131 4 127 40 170 
132 65 84 85 171 
133 95 67 92 183 
134 77 101 121 149 
135 81 116 172 173 
136 54 86 109 130 
137 112 103 173 176 
138 5 41 125 189 
139 95 70 96 93 
140 92 66 93 184 
141 85 81 172 175 
142 140 63 24 142 
143 143 24 25 181 
144 74 171 65 179 
145 135 79 54 130 
146 112 103 26 187 
147 40 71 118 75 
148 92 91 66 184 
149 88 79 80 180 
150 115 119 52 185 
151 74 79 88 171 
152 24 116 25 181 
153 65 116 82 179 
154 70 96 93 177 
155 67 77 176 183 
156 112 67 103 176 
157 81 25 116 173 
158 25 81 112 173 
159 25 112 26 187 
160 25 124 24 143 
161 26 161 159 64 
162 24 62 140 142 
163 163 175 172 183 
164 77 101 149 174 
165 141 140 24 138 
166 77 174 149 176 
167 117 42 96 97 
168 76 103 121 176 
169 112 173 103 187 
170 124 69 75 24 
171 100 101 122 174 
172 172 173 167 176 
173 154 56 101 149 
174 85 172 171 175 
175 63 69 124 24 
176 128 172 171 179 
177 130 128 171 179 
178 82 74 65 179 
179 53 105 18 153 
180 125 25 124 107 
181 25 173 145 181 
182 85 115 87 175 
183 173 176 103 187 
184 19 42 155 177 
185 164 171 128 172 
186 74 130 79 171 
187 86 130 74 179 
188 171 172 164 175 
189 25 173 112 187 
190 174 176 77 183 
191 143 138 24 181 
192 42 70 96 97 
193 91 112 81 175 
194 95 98 77 174 
195 25 145 143 181 
196 65 83 84 171 
197 92 183 91 184 
198 140 24 138 181 
199 77 149 121 176 
200 164 133 128 171 
201 129 172 179 181 
202 163 172 167 183 
203 120 66 91 185 
204 81 87 91 175 
205 166 51 164 172 
206 67 176 112 183 
207 82 73 179 181 
208 25 125 72 107 
209 83 171 88 180 
210 85 171 84 175 
211 77 121 103 176 
212 147 176 152 183 
213 88 83 74 171 
214 163 167 176 183 
215 149 174 152 176 
216 103 67 77 176 
217 169 173 146 187 
218 24 141 138 143 
219 148 50 169 176 
220 25 116 173 181 
221 145 173 25 187 
222 147 163 176 183 
223 92 112 91 183 
224 95 92 93 184 
225 103 76 151 176 
226 83 123 99 182 
227 167 173 169 176 
228 163 164 172 175 
229 152 176 174 183 
230 172 116 179 181 
231 129 168 172 181 
232 156 169 146 187 
233 145 25 26 187 
234 42 160 5 189 
235 151 176 148 187 
236 147 163 167 176 
237 117 57 105 177 
238 124 25 41 143 
239 106 124 75 24 
240 79 130 135 171 
241 107 106 124 188 
242 83 65 74 171 
243 95 183 92 184 
244 163 164 51 172 
245 88 89 83 180 
246 25 125 94 72 
247 26 103 76 187 
248 130 128 133 171 
249 87 175 115 185 
250 42 117 113 97 
251 160 159 26 114 
252 172 173 116 181 
253 116 82 179 181 
254 71 40 69 75 
255 57 42 117 113 
256 2 24 142 62 
257 26 161 64 1 
258 99 123 68 170 
259 115 52 110 185 
260 152 49 147 183 
261 101 100 56 154 
262 115 84 119 182 
263 77 98 101 174 
264 93 94 70 186 
265 160 145 26 187 
266 95 96 98 178 
267 84 99 119 182 
268 105 102 117 177 
269 145 157 160 47 
270 151 103 176 187 
271 74 130 171 179 
272 91 183 175 184 
273 166 167 51 172 
274 157 145 160 187 
275 147 50 148 176 
276 154 149 101 174 
277 25 145 41 143 
278 103 151 76 187 
279 129 137 168 181 
280 85 87 81 175 
281 127 125 124 188 
282 96 93 177 184 
283 67 112 92 183 
284 129 172 128 179 
285 91 175 87 185 
286 87 115 110 185 
287 164 128 166 172 
288 46 138 141 143 
289 63 69 40 124 
290 151 148 156 187 
291 149 152 147 176 
292 101 98 122 174 
293 133 136 171 182 
294 116 24 82 181 
295 115 175 84 182 
296 133 164 44 171 
297 144 168 137 181 
298 61 42 113 97 
299 167 163 51 172 
300 24 124 63 141 
301 127 124 40 188 
302 109 31 54 130 
303 162 175 183 184 
304 10 167 147 163 
305 52 107 110 188 
306 72 110 107 186 
307 66 94 93 186 
308 84 83 99 182 
309 26 145 160 189 
310 40 38 63 141 
311 117 102 96 177 
312 168 173 172 181 
313 40 108 71 59 
314 137 144 8 168 
315 141 24 124 143 
316 128 129 45 172 
317 86 73 58 179 
318 4 40 136 170 
319 112 175 91 183 
320 162 175 184 185 
321 139 140 63 141 
322 146 169 48 173 
323 49 152 174 183 
324 169 50 167 176 
325 167 172 168 173 
326 91 184 175 185 
327 140 24 63 141 
328 40 69 75 124 
329 110 120 87 185 
330 131 31 30 109 
331 71 40 59 69 
332 95 174 183 184 
333 168 45 129 172 
334 147 167 50 176 
335 144 173 168 181 
336 41 125 25 124 
337 138 132 140 181 
338 145 173 144 181 
339 100 154 101 174 
340 155 174 178 184 
341 109 86 58 131 
342 63 38 139 141 
343 128 45 166 172 
344 145 125 25 41 
345 143 46 138 181 
346 145 144 143 181 
347 133 171 44 182 
348 98 174 95 178 
349 105 19 153 178 
350 23 158 22 114 
351 160 114 26 189 
352 74 73 86 179 
353 10 167 163 51 
354 146 173 144 187 
355 118 68 123 170 
356 91 87 120 185 
357 48 169 168 173 
358 66 184 91 185 
359 165 171 164 175 
360 163 162 175 183 
361 8 46 144 137 
362 44 164 133 128 
363 168 144 8 48 
364 147 167 10 50 
365 147 49 10 163 
366 109 86 131 130 
367 130 129 128 179 
368 137 129 168 45 
369 169 148 156 50 
370 114 97 26 189 
371 125 127 186 188 
372 150 15 111 14 
373 169 167 168 173 
374 145 160 5 47 
375 156 146 9 47 
376 162 49 174 183 
377 125 107 124 188 
378 46 141 3 143 
379 120 110 72 186 
380 47 157 151 187 
381 44 7 164 128 
382 159 160 158 114 
383 135 79 78 54 
384 128 7 166 45 
385 124 106 75 188 
386 156 9 169 50 
387 159 151 157 187 
388 152 155 49 174 
389 136 44 4 182 
390 168 8 137 45 
391 102 98 96 178 
392 96 42 117 177 
393 48 168 144 173 
394 126 93 70 186 
395 155 162 174 184 
396 146 9 48 169 
397 19 105 57 177 
398 115 182 119 185 
399 165 43 4 182 
400 49 163 147 183 
401 86 58 131 179 
402 166 51 7 164 
403 132 179 73 181 
404 124 3 40 141 
405 74 82 73 179 
406 7 166 164 128 
407 49 155 162 174 
408 136 40 35 170 
409 160 145 5 189 
410 6 162 49 155 
411 124 40 63 141 
412 70 93 126 177 
413 146 48 144 173 
414 9 146 156 169 
415 127 4 43 182 
416 70 97 42 189 
417 129 179 132 181 
418 96 70 42 177 
419 132 138 46 181 
420 84 175 171 182 
421 165 4 44 182 
422 6 43 162 126 
423 71 40 118 170 
424 166 45 168 172 
425 124 41 3 143 
426 40 38 37 59 
427 145 144 173 187 
428 157 47 145 187 
429 84 171 83 182 
430 95 178 174 184 
431 145 41 5 189 
432 53 17 100 153 
433 21 22 42 61 
434 162 126 43 184 
435 165 44 164 171 
436 162 165 175 185 
437 42 22 160 189 
438 113 21 42 61 
439 133 135 130 171 
440 6 126 162 184 
441 167 166 168 172 
442 35 108 55 170 
443 118 123 89 170 
444 162 183 174 184 
445 70 42 126 125 
446 75 40 124 188 
447 133 44 136 182 
448 134 78 135 180 
449 123 83 180 182 
450 20 42 57 113 
451 125 126 70 186 
452 148 150 149 176 
453 99 127 119 182 
454 120 72 66 186 
455 155 178 177 184 
456 70 126 42 177 
457 100 174 122 178 
458 127 170 4 182 
459 145 146 144 187 
460 148 149 147 176 
461 61 114 22 189 
462 145 125 41 189 
463 141 124 3 143 
464 58 73 131 179 
465 63 38 39 139 
466 107 186 110 188 
467 120 66 185 186 
468 47 156 146 187 
469 119 127 52 185 
470 36 108 40 59 
471 165 163 162 175 
472 175 182 115 185 
473 61 97 114 189 
474 46 144 137 181 
475 104 108 71 170 
476 11 12 161 64 
477 62 27 28 142 
478 129 132 137 181 
479 31 135 54 130 
480 153 154 100 178 
481 43 126 127 185 
482 6 177 126 184 
483 90 33 134 78 
484 94 66 72 186 
485 153 17 100 154 
486 151 150 148 176 
487 135 133 136 171 
488 47 151 156 187 
489 125 70 94 186 
490 127 185 126 186 
491 165 44 171 182 
492 72 107 125 186 
493 159 161 12 64 
494 140 62 28 142 
495 123 170 99 182 
496 19 155 153 178 
497 143 144 46 181 
498 145 47 146 187 
499 162 163 49 183 
500 46 137 132 181 
501 35 134 136 180 
502 102 177 105 178 
503 131 129 130 179 
504 135 134 33 78 
505 161 114 158 1 
506 154 152 149 174 
507 120 185 110 186 
508 78 32 135 54 
509 52 127 110 185 
510 52 110 127 188 
511 184 185 66 186 
512 56 100 16 154 
513 162 43 165 185 
514 163 165 164 175 
515 126 177 93 184 
516 123 89 170 180 
517 71 89 104 170 
518 17 16 100 154 
519 131 130 86 179 
520 118 89 71 170 
521 125 186 107 188 
522 135 171 136 180 
523 88 80 89 180 
524 162 184 43 185 
525 102 96 177 178 
526 171 180 83 182 
527 70 42 125 189 
528 52 127 119 188 
529 142 63 2 139 
530 33 32 135 78 
531 117 42 57 177 
532 53 105 153 178 
533 43 184 126 185 
534 73 132 131 179 
535 35 136 170 180 
536 70 125 94 189 
537 127 182 43 185 
538 4 170 136 182 
539 131 132 129 179 
540 154 174 100 178 
541 53 102 105 178 
542 122 174 98 178 
543 105 177 19 178 
544 40 170 127 188 
545 136 180 171 182 
546 42 97 61 189 
547 89 80 104 180 
548 107 52 106 188 
549 43 182 165 185 
550 12 159 64 151 
551 140 28 62 132 
552 154 16 56 15 
553 108 40 71 170 
554 53 122 102 178 
555 75 106 68 188 
556 119 182 127 185 
557 136 170 180 182 
558 165 171 175 182 
559 165 182 175 185 
560 32 135 54 31 
561 131 31 109 130 
562 42 61 22 189 
563 35 170 55 180 
564 21 42 20 113 
565 122 98 102 178 
566 104 90 55 180 
567 99 170 127 182 
568 15 150 111 149 
569 37 36 40 59 
570 154 155 152 174 
571 68 106 119 188 
572 127 110 185 186 
573 119 106 52 188 
574 110 186 127 188 
575 123 180 170 182 
576 33 134 34 90 
577 18 17 53 153 
578 126 185 184 186 
579 94 72 125 186 
580 90 104 80 180 
581 89 104 170 180 
582 19 177 155 178 
583 23 1 158 114 
584 58 30 109 131 
585 136 134 135 180 
586 111 150 14 60 
587 155 154 153 178 
588 11 161 1 64 
589 2 27 62 142 
590 155 174 154 178 
591 39 2 63 139 
592 60 150 14 13 
593 58 29 30 131 
594 114 161 26 1 
595 42 126 6 177 
596 125 127 126 186 
597 125 42 5 189 
598 73 24 181 82 
599 78 79 180 80 
600 78 180 79 135 
601 151 121 176 76 
602 60 121 151 76 
603 171 79 180 135 
604 171 180 79 88 
605 55 104 170 108 
606 55 170 104 180 
607 159 187 160 26 
608 160 187 159 157 
609 187 148 173 176 
610 169 173 148 176 
611 15 56 149 111 
612 15 149 56 154 
613 70 26 189 94 
614 70 189 26 97 
615 183 77 95 67 
616 183 95 77 174 
617 187 169 148 156 
618 187 148 169 173 
619 132 62 181 73 
620 132 181 62 140 
621 24 181 62 73 
622 24 62 181 140 
623 151 64 187 159 
624 151 187 64 76 
625 26 187 64 159 
626 26 64 187 76 
627 63 40 59 38 
628 63 59 40 69 
629 184 96 178 177 
630 184 178 96 95 
631 68 170 127 99 
632 127 170 68 188 
633 127 119 68 99 
634 68 119 127 188 
635 93 186 184 66 
636 184 186 93 126 
637 180 78 90 134 
638 180 90 78 80 
639 57 19 42 20 
640 57 42 19 177 
641 134 90 55 34 
642 55 90 134 180 
643 55 35 134 34 
644 134 35 55 180 
645 35 108 40 36 
646 35 40 108 170 
647 100 178 53 153 
648 53 178 100 122 
649 184 6 155 162 
650 184 155 6 177 
651 40 170 75 118 
652 40 75 170 188 
653 68 75 170 118 
654 68 170 75 188 
655 64 60 151 76 
656 189 145 25 26 
657 25 145 189 125 
658 25 94 189 26 
659 189 94 25 125 
660 160 114 22 158 
661 160 22 114 189 
662 151 64 150 60 
663 151 150 64 12 
664 13 150 64 60 
665 13 64 150 12 
666 151 60 176 121 
667 176 60 151 150 
668 60 149 176 121 
669 176 149 60 150 
670 60 111 149 121 
671 149 111 60 150 
672 62 132 131 73 
673 131 132 62 28 
674 62 29 131 28 
675 58 62 131 73 
676 58 131 62 29 
$EndElements

@bhaveshshrimali Thank you ! My python code can read (Meshio 4.3.12) your .msh file, and correctly generates xdmf files recognizing the physical surface groups!

Thank you so much!

Now the problem has to be Gmsh, either I did something wrong or it’s not properly installed.
Will post my updates here.

1 Like

Hi @fen
I have the same problem. I have 3d msh file that looks similar but does not read physical groups. Could you summarize your solution ??

Hi, I am trying to create coiled pipe using gmsh. I have the following python script for generating msh file

import gmsh
import math
import os
import sys

gmsh.initialize()

gmsh.model.add("coiled_pipe")

# define a spline curve:
nturns = 5.
npts = 20
r = 1.
h = 1. * nturns
p = []
for i in range(0, npts):
    theta = i * 2 * math.pi * nturns / npts
    gmsh.model.occ.addPoint(r * math.cos(theta), r * math.sin(theta),
                            i * h / npts, 1, 1000 + i)
    p.append(1000 + i)
gmsh.model.occ.addSpline(p, 1000)

# A wire is like a curve loop, but open:
gmsh.model.occ.addWire([1000], 1000)

# We define the shape we would like to extrude along the spline (a disk):
gmsh.model.occ.addDisk(1, 0, 0, 0.2, 0.2, 1000)
gmsh.model.occ.rotate([(2, 1000)], 0, 0, 0, 1, 0, 0, math.pi / 2)

# We extrude the disk along the spline to create a pipe (other sweeping types
# can be specified; try e.g. 'Frenet' instead of 'DiscreteTrihedron'):
gmsh.model.occ.addPipe([(2, 1000)], 1000, 'DiscreteTrihedron')

# We delete the source surface, and increase the number of sub-edges for a
# nicer display of the geometry:
gmsh.model.occ.remove([(2, 1000)])
gmsh.option.setNumber("Geometry.NumSubEdges", 1000)

gmsh.model.occ.synchronize()

# We can activate the calculation of mesh element sizes based on curvature
# (here with a target of 20 elements per 2*Pi radians):
gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 20)

# We can constraint the min and max element sizes to stay within reasonnable
# values (see `t10.py' for more details):
gmsh.option.setNumber("Mesh.MeshSizeMin", 0.001)
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.3)

#  Physical groups
gmsh.model.addPhysicalGroup(dim=2, tags=[1001], tag=1)
gmsh.model.setPhysicalName(dim=2, tag=1, name="inlet")
gmsh.model.addPhysicalGroup(dim=2, tags=[1003], tag=2)
gmsh.model.setPhysicalName(dim=2, tag=2, name="outlet")
gmsh.model.addPhysicalGroup(dim=2, tags=[1002], tag=3)
gmsh.model.setPhysicalName(dim=2, tag=3, name="boundary")
gmsh.model.addPhysicalGroup(dim=3, tags=[1], tag=1)
gmsh.model.setPhysicalName(dim=3, tag=1, name="Volume")

gmsh.model.mesh.generate(3)
gmsh.write("coiled_pipe.msh")

# Launch the GUI to see the results:
if '-nopopup' not in sys.argv:
    gmsh.fltk.run()

gmsh.finalize()

but meshio does not seem to recognize physical groups. I am fairly new to gmsh so I may have problems in my above code, but at least it seems correct when I open the msh file with gmsh GUI.
I used the following code to read msh file and generate xdmf file.

def create_mesh(mesh, cell_type):

    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    points = mesh.points
    # Create output mesh
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells},
                           cell_data={"name_to_read": [cell_data]})
    return out_mesh

mesh3D_from_msh = meshio.read("coiled_pipe.msh")
tetra_mesh = create_mesh(mesh3D_from_msh, "tetra")

meshio.write("coiled_pipe.xdmf", tetra_mesh)

There is no error message when I run them, but xdmf file does not contain any of physical group names (inlet, outlet, volume, boundary), but has “name_to_read” name.
I can not find what is wrong with my code, so I appreciate any help.

Update : This is how my mesh looks like with Gmsh GUI

Best,

Update: I use Gmsh 4.8.0 on linux Mint. It opens @bhaveshshrimali 's geo file OK. Under GUI I export to box_bh.msh in ver4 format (checked the option save all elements). My code in docker is simply as follows:

import meshio
mesh_from_file = meshio.read("box_bh.msh")

This generates an error of ValueError: Incompatible cell data. 33 cell blocks, but 'gmsh:physical' has 3 blocks.

Instead I use command gmsh -3 box.geo -o box_bh_com.msh to generate msh file. And this file can be correctly read by the same python code.

It appears Gmsh GUI exports a msh file that is incompatible with Meshio. The command line is fine.

@Kei_Yamamoto I am not sure if I know the solution yet, but I can summarize my problem as above. FYI, originally I used Gmsh 4.8.0. GUI on native Win10 and got the same problem.

It appears to be a Gmsh question rather than a FEniCS question now.

@fen Thank you for the update. I do not use Gmsh GUI to generate geo file, but used the python API for creating msh file direclty. I just used Gmsh GUI for checking if the physical groups are actually embedded. However, I might try using geo file and use the gmsh -3 box.geo -o box_bh_com.msh as you mentioned. Thank you for your help. Other comments or help are very much welcomed.

Hi @Nexius , thank you for your contribution to reading XDMF in parallel! Without any knowledge of MPI, I dared to try it just now for fun. My system is FEniCS docker on WIN10, on an I-7 4core system with 16GB (docker can use 4-core 8GB). Could you please address how to save results to XDMF file(s) in parallel computing. Following your example I added the following line to save the results.

file_results = fn.XDMFFile(MPI.COMM_SELF, "test_mpi.xdmf")
file_results.parameters['flush_output'] = True
file_results.parameters['functions_share_mesh'] = True
...
file_results.write(u, t)            #write u(displacement) at time-step t

I must have been wrong, and notice the following issues and successes:

  1. I have to use MPI.COMM_SELF instead of MPI.comm_self, otherwise it raises no attribute 'comm_self'. Out of curiosity, is it a version issue of mpi4py?
  2. With export HDF5_USE_FILE_LOCKING=FALSE, I run mpirun -np 4 python3 test.py. The code DOES run the FEA analysis MANY times (as I can see it prints the ‘u’ results many times). But in the end it halts and raises many blocks of errors as follows.
HDF5-DIAG: Error detected in HDF5 (1.10.0-patch1) MPI-process 1:
  #000: ../../../src/H5F.c line 579 in H5Fopen(): unable to open file
    major: File accessibilty
    minor: Unable to open file
  #001: ../../../src/H5Fint.c line 1168 in H5F_open(): unable to lock the file or initialize file structure
    major: File accessibilty
    minor: Unable to open file
  #002: ../../../src/H5FD.c line 1821 in H5FD_lock(): driver lock request failed
    major: Virtual File Layer
    minor: Can't update object
  #003: ../../../src/H5FDsec2.c line 939 in H5FD_sec2_lock(): unable to flock file, errno = 11, error message = 'Resource temporarily unavailable'
    major: File accessibilty
    minor: Bad file ID accessed
  1. with export HDF5_USE_FILE_LOCKING=TRUE, it raises error without performing any FEA analysis.
Traceback (most recent call last):
  File "test.py", line 66, in <module>
    infile.read(mvc, "name_to_read")
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to find entity in map.
*** Reason:  Error reading MeshValueCollection.
*** Where:   This error was encountered inside HDF5File.cpp.
*** Process: 2
***
*** DOLFIN version: 2019.1.0
*** Git changeset:  74d7efe1e84d65e9433fd96c50f1d278fa3e3f3f
*** -------------------------------------------------------------------------

Do you have any insights? I can clean up my codes to provide a minimal working code if needed. Thank you!

Hello !
If that’s of any relevance to people reading this topic, I had the same error which led me here.
The root cause was the saveAll gmsh parameter that I used for debugging purposes with the python API. It saves unused nodes, etc. to the mesh so meshio is confused. Solved it like this :slight_smile:
gmsh.option.setNumber("Mesh.SaveAll", 0)

Hello.
I am also little confused about how to properly retrieve physical names from GMSH mesh to XDMF format for use with FEniCS. I followed the same script as https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/172?u=nareniitr provided earlier for a simple 2D rectangular geometry. I convert .msh file to two xdmf files. When I tried to integrate over area dx and boundary ds, I get correct values. However, when I tried to integrate on just one boundary (e.g. Inlet), the integral value is zero. It appears that subdomain_id is not being recognized. Below is a minimum working example.

import meshio
msh = meshio.read("Rectangle.msh")

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

line_mesh = create_mesh(msh, "line", prune_z=True)
meshio.write("mf2D.xdmf", line_mesh)

triangle_mesh = create_mesh(msh, "triangle", prune_z=True)
meshio.write("mesh2D.xdmf", triangle_mesh)
# fenics imported later to avoid compatibilty issue with h5
from fenics import *
mesh = Mesh()
with XDMFFile("mesh2D.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)

with XDMFFile("mf2D.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

print('num_cells   :', mesh.num_cells())
print('num_vertices:', mesh.num_vertices())
print('cell_type   :', mesh.ufl_cell())

dx=Measure("dx", domain=mesh, subdomain_data=mf)
print(assemble(1*dx))

ds=Measure("ds", domain=mesh, subdomain_data=mf)
print(assemble(1*ds))

ds_1=Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=5)
print(assemble(1*ds_1))

I have also attached geo file I got from GMSH attached here.

//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {1, 0, 0, 1.0};
//+
Point(3) = {1, 1, 0, 1.0};
//+
Point(4) = {0, 1, 0, 1.0};
//+
Line(1) = {1, 2};
//+
Line(2) = {2, 3};
//+
Line(3) = {4, 1};
//+
Line(4) = {3, 4};
//+
Curve Loop(1) = {4, 3, 1, 2};
//+
Plane Surface(1) = {1};
//+
Physical Curve("Inlet", 5) = {3};
//+
Physical Curve("Outlet", 6) = {2};
//+
Physical Curve("Top", 7) = {4};
//+
Physical Curve("Bottom", 8) = {1};

//+
MeshSize {1, 2, 3, 4} = 0.05;

Can you please help me understand what is the problem here?

You need to define the surface as a physical surface as well:

Physical Surface("Area", 10) = {1};

with this addition I get:

num_cells   : 944
num_vertices: 513
cell_type   : triangle
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
1.0000000000000007
Calling FFC just-in-time (JIT) compiler, this may take some time.
4.000000000000001
Calling FFC just-in-time (JIT) compiler, this may take some time.
0.9999999999999999
1 Like

Thank you @dokken . That resolved my issue. Just wanted to add for reference that I saved my mesh with Version 4 ASCII format with Save all elements unchecked if anyone else faces the same issue.