Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio

Hi, thanks a lot for the fast reply.
What I am trying to do is just to import a 3D mesh generated with gmesh that has marked 3D subdomains (representing different materials) and 2D subdomains of the boundary marked to impose different boundary conditions.

Later in the code I will need to do the following three things:

being able to integrate separately on the 3D subdomains (like dx(1))
being able to integrate over 2D subdomains (ds(2) for example)
being able to impose Dirichlet BC on one of the marked subdomain of the boundary.

They seems to be super standard operation but I was not able to find a clean (or just working) way to do them.

Iacopo

@Iactor, the problem with your code is your mesh. It is not a connected mesh, and consists of several bits and pieces. In particular, you add extra surfaces over the surfaces defined in the surface mesh.
I’ve rewritten your code, using boolean fragments in gmsh to generate what I think is the desired mesh. Note that in this mesh, elements align over boundaries, which was not the case in your original code.

// Gmsh project created by Jørgen S. Dokken 2020
SetFactory("OpenCASCADE");
Box(1) = {0, 0, 0, 1, 1, .285};
Box(2) = {0.4, 0.4, 0.285, .2, .2, .03};
Box(3) = {0., 0, 0.315, 1, 1, .01};
Box(4) = {0.0, 0.0, 0.325, 1, 1, 1};
v() = BooleanFragments{ Volume{1}; Delete;}{ Volume{2,3,4}; Delete; };
Physical Volume("air", 33) ={#v()};
Physical Volume("hBN", 32) ={#v()-1};
Physical Volume("cavity", 31) ={#v()-2};
Physical Volume("substrate", 30) ={#v()-3};
Physical Surface("backgate", 34) = {29};
Physical Surface("patterned_gate", 29) = {18, 23};

This mesh and the corresponding volume and facet data loads into FEniCS as they should. On the usage of gmsh i suggest reading through the tutorials.

4 Likes

I still have to check but you probably saved my day.
Thanks a lot!!
Best.
I

@dokken I have a question adapting this method. I seem to get an error and I dont know why.
I have troubles understanding transferring to what was boundaries = FacetFunction("size_t", mesh) to the same now. I noticed the other thread menitoning boundaries = MeshFunction("size_t",mesh,mesh.topology().dim()-1) but I get an error whilst trying to make DirichletBC.

MWE :

import meshio
msh = meshio.read(“cepijp.msh”)
meshio.write(“mesh.xdmf”, meshio.Mesh(points=msh.points, cells={“tetra”: msh.cells[“tetra”]}))
meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]},
cell_data={“triangle”: {“name_to_read”: msh.cell_data[“triangle”][“gmsh:physical”]}}))
meshio.write(“cf.xdmf”, meshio.Mesh(
points=msh.points, cells={“tetra”: msh.cells[“tetra”]},
cell_data={“tetra”: {“name_to_read”:
msh.cell_data[“tetra”][“gmsh:physical”]}}))
from dolfin import *
from fenics import *
mesh = Mesh()
with XDMFFile(“mesh.xdmf”) as infile:
infile.read(mesh)
mvc = MeshValueCollection(“size_t”, mesh, 2)
with XDMFFile(“mf.xdmf”) as infile:
infile.read(mvc, “name_to_read”)
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
mvc = MeshValueCollection(“size_t”, mesh, 3)
with XDMFFile(“cf.xdmf”) as infile:
infile.read(mvc, “name_to_read”)
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
ds = Measure(“ds”, domain=mesh, subdomain_data=mf)
boundaries = MeshFunction(“size_t”,mesh,mesh.topology().dim()-1)
surf_inlet = [1]
surf_wall = [3]
surf_outlet = [2]
eta_true = 3.5e-3 # [Pa s] Unscaled blood dynamic viscosity
rho_true = 1000 # [kg/m3] Unscaled blood density
V = VectorFunctionSpace(mesh, ‘CG’, 2)
Q = FunctionSpace(mesh, ‘CG’, 1)
inflow_profile_x = (‘v_in’)
inflow_profile_y = (‘0’)
v_in=0.3
bc_x = DirichletBC(V, Expression(inflow_profile_x, degree=2, v_in=v_in), boundaries, surf_inlet)
bc_y = DirichletBC(V, Expression(inflow_profile_y, degree=2), boundaries, surf_inlet)
bcp = DirichletBC(Q, 0.0, boundaries, surf_outlet)
bc0_x = DirichletBC(V, Constant(0), boundaries, surf_wall)
bc0_y = DirichletBC(V, Constant(0), boundaries, surf_wall)
bcu = [bc_x, bc0_x,bc_y,bc0_y]
bcp = [bcp]

This gives:

Traceback (most recent call last):
File “3Dsim.py”, line 56, in
bc_x = DirichletBC(V, Expression(inflow_profile_x, degree=2, v_in=v_in), boundaries, surf_inlet)
File “/usr/local/lib/python3.6/dist-packages/dolfin/fem/dirichletbc.py”, line 131, in init
super().init(*args)
TypeError: init(): incompatible constructor arguments. The following argument types are supported:
1. dolfin.cpp.fem.DirichletBC(arg0: dolfin.cpp.fem.DirichletBC)
2. dolfin.cpp.fem.DirichletBC(V: dolfin.cpp.function.FunctionSpace, g: dolfin.cpp.function.GenericFunction, sub_domain: dolfin.cpp.mesh.SubDomain, method: str = ‘topological’, check_midpoint: bool = True)
3. dolfin.cpp.fem.DirichletBC(V: dolfin.cpp.function.FunctionSpace, g: dolfin.cpp.function.GenericFunction, sub_domains: dolfin.cpp.mesh.MeshFunctionSizet, sub_domain: int, method: str = ‘topological’)
Invoked with: <dolfin.cpp.function.FunctionSpace object at 0x7fdb5a5b3360>, <dolfin.cpp.function.Expression object at 0x7fdb5a5b53e8>, <dolfin.cpp.mesh.MeshFunctionSizet object at 0x7fdb627796f8>, [1], ‘topological’

I also got the error when trying to apply Constant BC instead of the expression.
Cheers,
Jack

@jacktat why are you sending in a list (surf_inlet)? This should just be the integer in the list,Which causes the error. You should call this constructor

dolfin.cpp.fem.DirichletBC(V: dolfin.cpp.function.FunctionSpace, g: dolfin.cpp.function.GenericFunction, sub_domains: dolfin.cpp.mesh.MeshFunctionSizet, sub_domain: int, method: str = ‘topological’)
1 Like

Sorry for bumping in this discussion, but I was hoping to get some help on using dolfin-convert to convert an Abaqus mesh with two different subdomains. I believe that meshio does not support cell sets yet see here

So I have a domain like this

I have generated the mesh in Abaqus and want to import it in dolfin. Using dolfin-convert does give me the mesh but is it possible to somehow extract the subdomains, precisely the “red” spheres above. I could hand-pick the sphere centers/radii and instantiate a SubDomain class but I want to avoid having to do it repeatedly for each mesh.

@bhaveshshrimali, Cell_sets Seems to be supporter in the latest version

I can check but from the description it seemed that only 2D cells were supported and no 3D

@dokken, hiya, I first indeed had them as integters, but I dont know if something is wrong with my subdomains. If i change the lists to integers as so:

surf_inlet = 1
surf_wall = 3
surf_outlet = 2

I get the following error:

File “3Dsim.py”, line 56, in
bc_x = DirichletBC(V, Expression(inflow_profile_x, degree=2, v_in=v_in), boundaries, surf_inlet)
File “/usr/local/lib/python3.6/dist-packages/dolfin/fem/dirichletbc.py”, line 131, in init
super().init(*args)
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 create Dirichlet boundary condition.
*** Reason: Expecting a vector-valued boundary value but given function is scalar.
*** Where: This error was encountered inside DirichletBC.cpp.
*** Process: 0
****** DOLFIN version: 2019.1.0
*** Git changeset: 74d7efe1e84d65e9433fd96c50f1d278fa3e3f3f
*** -------------------------------------------------------------------------

You want to apply boundary conditions to a sub space, so you have to use V.sub(0) and V.sub(1) to apply conditions to the x and y component.

1 Like

I dont understand, the only t hing that I’ve done different in this script is loading in the mesh with this new manner. I thought I could replace boundaries = FacetFunction("size_t", mesh) with boundaries = MeshFunction("size_t",mesh,mesh.topology().dim()-1). So somehow Im saving that boundary meshfunction wrong…

@jacktat that is not what the error message says. It says that since V is a vector space it requires the boundary condition u_inlet to be a vector expression of same dimension as V

2 Likes

Hi, I’m trying to convert a mesh file created in GMSH. When I run the code:

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

meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))
meshio.write("mf.xdmf", meshio.Mesh(points=msh.points, cells={"triangle": msh.cells["triangle"]},
                                    cell_data={"triangle": {"name_to_read": msh.cell_data["triangle"]["gmsh:physical"]}}))

from dolfin import * 
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2) 
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
File("dolfinmesh.pvd").write(mesh)
File("dolfincellfunc.pvd").write(mf)

I get the following message:

Traceback (most recent call last):
  File "convert.py", line 4, in <module>
    meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": 
    msh.cells["tetra"]}))
TypeError: list indices must be integers or slices, not str

I will appreciate if someone could help me.

You Need to supply the msh file for me to be able to help you.

Here is my mesh file:

$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
95
1 0 0 0
2 1 0 0
3 0 1 0
4 0 0 1
5 0.2499999999994083 0 0
6 0.4999999999986718 0 0
7 0.7499999999993359 0 0
8 0 0 0.2499999999994083
9 0 0 0.4999999999986718
10 0 0 0.7499999999993359
11 0 0.2499999999994083 0
12 0 0.4999999999986718 0
13 0 0.7499999999993359 0
14 0.195090322472501 0 0.9807852803124523
15 0.3826834331662315 0 0.923879532179443
16 0.5555702342368348 0 0.8314696114892164
17 0.7071067827953921 0 0.707106779577703
18 0.8314696132285331 0 0.5555702316337635
19 0.9238795328354849 0 0.3826834315824063
20 0.9807852804721869 0 0.1950903216694607
21 0 0.195090322472501 0.9807852803124523
22 0 0.3826834331662315 0.923879532179443
23 0 0.5555702342368348 0.8314696114892164
24 0 0.7071067827953921 0.707106779577703
25 0 0.8314696132285331 0.5555702316337635
26 0 0.9238795328354849 0.3826834315824063
27 0 0.9807852804721869 0.1950903216694607
28 0.9807852803124523 0.195090322472501 0
29 0.923879532179443 0.3826834331662315 0
30 0.8314696114892164 0.5555702342368348 0
31 0.707106779577703 0.7071067827953921 0
32 0.5555702316337635 0.8314696132285331 0
33 0.3826834315824063 0.9238795328354849 0
34 0.1950903216694607 0.9807852804721869 0
35 0 0.3535533913976961 0.3535533897888515
36 0 0.1767766956988391 0.1767766948943751
37 0 0.4267766956980765 0.1767766948944119
38 0 0.6387164621165908 0.3681184106856289
39 0 0.7119397664177036 0.1913417157915462
40 0 0.5303300870965439 0.5303300846832772
41 0 0.176776695698916 0.42677669489376
42 0 0.19134171658312 0.7119397660891155
43 0 0.3681184122819638 0.6387164609841474
44 0.3535533913976963 0 0.3535533897888515
45 0.6387164621165906 0 0.3681184106856288
46 0.5303300870965442 0 0.5303300846832774
47 0.7119397664168547 0 0.1913417157912504
48 0.4267766956981823 0 0.1767766948944938
49 0.1767766956987976 0 0.1767766948944168
50 0.1913417165834587 0 0.7119397660896828
51 0.368118412281964 0 0.6387164609841471
52 0.1767766956988142 0 0.4267766948939973
53 0.3535533897888515 0.3535533913976963 0
54 0.1767766948944168 0.1767766956987975 0
55 0.4267766948939424 0.1767766956985926 0
56 0.6387164609841651 0.3681184122819501 0
57 0.7119397660890574 0.1913417165831158 0
58 0.5303300846832772 0.5303300870965441 0
59 0.1767766948944938 0.4267766956981823 0
60 0.1913417157912073 0.7119397664171364 0
61 0.3681184106856289 0.6387164621165906 0
62 0.8165216491971474 0.4081997763863762 0.4082466643470378
63 0.4089087385349484 0.8158353300336605 0.4089087402081611
64 0.4419237808016637 0.4112069128391336 0.797252937777762
65 0.7890367805805403 0.2097309024064934 0.5774373623752228
66 0.89084579822994 0.2090329174119163 0.4033596449997491
67 0.8905963043164519 0.4031799584255262 0.2104379810344812
68 0.9599447951389524 0.1972015566475527 0.1990415442600276
69 0.7886918244914327 0.5773274280524443 0.2113249791168205
70 0.2106795650933204 0.8904318519763815 0.4034169528391198
71 0.2116803286041188 0.7883243681570086 0.5776989951972442
72 0.1988649612168969 0.9596381891903171 0.1988649618402678
73 0.4049913241675203 0.890065096791435 0.209203610921733
74 0.5793739980942608 0.7876507950345313 0.2095996073797425
75 0.205318405039248 0.1980741163968379 0.9584419632746425
76 0.2278350962449054 0.4074743853066978 0.8843391850630635
77 0.4223834081727916 0.2106299512424475 0.8816049456190346
78 0.2358477212435688 0.5814232630554431 0.7786673497471027
79 0.6004509594512709 0.2126828137235622 0.7708596928369498
80 0.6539538094546348 0.4242376736818296 0.626391899156431
81 0.443267064331417 0.6392588625756028 0.6283807892492845
82 0.6425203370671659 0.6378910624135036 0.4245734435266377
83 0.5850375202974218 0.2040998881931881 0.3809000270679447
84 0.39773858609968 0.2056034564195668 0.5754031637833068
85 0.1767766956988482 0.176776695698848 0.3535533897888515
86 0.353553390593274 0.1767766956988482 0.1767766948944258
87 0.1767766948944258 0.3535533913976962 0.1767766948944258
88 0.2209618904008319 0.3823801521184148 0.5754031637833068
89 0.2044543692674742 0.5846943607156783 0.3812310649985063
90 0.5850375194929995 0.3808765838920363 0.2041233321735189
91 0.3812310641618999 0.5846943607156784 0.2044543701040806
92 0.4082608245985737 0.3808765838920362 0.3809000270679447
93 0.1767766956988482 0.1913417165831157 0.6387164609841472
94 0.6387164617885697 0.1913417165831157 0.1767766948944258
95 0.1767766948944258 0.6387164621165906 0.1913417157912031
$EndNodes
$Elements
416
1 2 2 10 1 1 36 11
2 2 2 10 1 36 37 11
3 2 2 10 1 36 35 37
4 2 2 10 1 11 37 12
5 2 2 10 1 35 38 37
6 2 2 10 1 38 39 37
7 2 2 10 1 38 26 39
8 2 2 10 1 37 39 12
9 2 2 10 1 35 40 38
10 2 2 10 1 40 25 38
11 2 2 10 1 40 24 25
12 2 2 10 1 38 25 26
13 2 2 10 1 12 39 13
14 2 2 10 1 39 27 13
15 2 2 10 1 39 26 27
16 2 2 10 1 13 27 3
17 2 2 10 1 1 8 36
18 2 2 10 1 8 41 36
19 2 2 10 1 8 9 41
20 2 2 10 1 36 41 35
21 2 2 10 1 9 42 41
22 2 2 10 1 42 43 41
23 2 2 10 1 42 22 43
24 2 2 10 1 41 43 35
25 2 2 10 1 9 10 42
26 2 2 10 1 10 21 42
27 2 2 10 1 10 4 21
28 2 2 10 1 42 21 22
29 2 2 10 1 35 43 40
30 2 2 10 1 43 23 40
31 2 2 10 1 43 22 23
32 2 2 10 1 40 23 24
33 2 2 20 2 17 18 46
34 2 2 20 2 18 45 46
35 2 2 20 2 18 19 45
36 2 2 20 2 46 45 44
37 2 2 20 2 19 47 45
38 2 2 20 2 47 48 45
39 2 2 20 2 47 6 48
40 2 2 20 2 45 48 44
41 2 2 20 2 19 20 47
42 2 2 20 2 20 7 47
43 2 2 20 2 20 2 7
44 2 2 20 2 47 7 6
45 2 2 20 2 44 48 49
46 2 2 20 2 48 5 49
47 2 2 20 2 48 6 5
48 2 2 20 2 49 5 1
49 2 2 20 2 4 14 10
50 2 2 20 2 14 50 10
51 2 2 20 2 14 15 50
52 2 2 20 2 10 50 9
53 2 2 20 2 15 51 50
54 2 2 20 2 51 52 50
55 2 2 20 2 51 44 52
56 2 2 20 2 50 52 9
57 2 2 20 2 15 16 51
58 2 2 20 2 16 46 51
59 2 2 20 2 16 17 46
60 2 2 20 2 51 46 44
61 2 2 20 2 9 52 8
62 2 2 20 2 52 49 8
63 2 2 20 2 52 44 49
64 2 2 20 2 8 49 1
65 2 2 30 3 1 54 5
66 2 2 30 3 54 55 5
67 2 2 30 3 54 53 55
68 2 2 30 3 5 55 6
69 2 2 30 3 53 56 55
70 2 2 30 3 56 57 55
71 2 2 30 3 56 29 57
72 2 2 30 3 55 57 6
73 2 2 30 3 53 58 56
74 2 2 30 3 58 30 56
75 2 2 30 3 58 31 30
76 2 2 30 3 56 30 29
77 2 2 30 3 6 57 7
78 2 2 30 3 57 28 7
79 2 2 30 3 57 29 28
80 2 2 30 3 7 28 2
81 2 2 30 3 1 11 54
82 2 2 30 3 11 59 54
83 2 2 30 3 11 12 59
84 2 2 30 3 54 59 53
85 2 2 30 3 12 60 59
86 2 2 30 3 60 61 59
87 2 2 30 3 60 33 61
88 2 2 30 3 59 61 53
89 2 2 30 3 12 13 60
90 2 2 30 3 13 34 60
91 2 2 30 3 13 3 34
92 2 2 30 3 60 34 33
93 2 2 30 3 53 61 58
94 2 2 30 3 61 32 58
95 2 2 30 3 61 33 32
96 2 2 30 3 58 32 31
97 2 2 40 4 17 65 18
98 2 2 40 4 65 66 18
99 2 2 40 4 65 62 66
100 2 2 40 4 18 66 19
101 2 2 40 4 62 67 66
102 2 2 40 4 67 68 66
103 2 2 40 4 67 29 68
104 2 2 40 4 66 68 19
105 2 2 40 4 62 69 67
106 2 2 40 4 69 30 67
107 2 2 40 4 69 31 30
108 2 2 40 4 67 30 29
109 2 2 40 4 19 68 20
110 2 2 40 4 68 28 20
111 2 2 40 4 68 29 28
112 2 2 40 4 20 28 2
113 2 2 40 4 24 25 71
114 2 2 40 4 25 70 71
115 2 2 40 4 25 26 70
116 2 2 40 4 71 70 63
117 2 2 40 4 26 72 70
118 2 2 40 4 72 73 70
119 2 2 40 4 72 33 73
120 2 2 40 4 70 73 63
121 2 2 40 4 26 27 72
122 2 2 40 4 27 34 72
123 2 2 40 4 27 3 34
124 2 2 40 4 72 34 33
125 2 2 40 4 63 73 74
126 2 2 40 4 73 32 74
127 2 2 40 4 73 33 32
128 2 2 40 4 74 32 31
129 2 2 40 4 4 21 14
130 2 2 40 4 21 75 14
131 2 2 40 4 21 22 75
132 2 2 40 4 14 75 15
133 2 2 40 4 22 76 75
134 2 2 40 4 76 77 75
135 2 2 40 4 76 64 77
136 2 2 40 4 75 77 15
137 2 2 40 4 22 23 76
138 2 2 40 4 23 78 76
139 2 2 40 4 23 24 78
140 2 2 40 4 76 78 64
141 2 2 40 4 15 77 16
142 2 2 40 4 77 79 16
143 2 2 40 4 77 64 79
144 2 2 40 4 16 79 17
145 2 2 40 4 17 79 65
146 2 2 40 4 79 80 65
147 2 2 40 4 79 64 80
148 2 2 40 4 65 80 62
149 2 2 40 4 64 81 80
150 2 2 40 4 81 82 80
151 2 2 40 4 81 63 82
152 2 2 40 4 80 82 62
153 2 2 40 4 64 78 81
154 2 2 40 4 78 71 81
155 2 2 40 4 78 24 71
156 2 2 40 4 81 71 63
157 2 2 40 4 62 82 69
158 2 2 40 4 82 74 69
159 2 2 40 4 82 63 74
160 2 2 40 4 69 74 31
161 4 2 50 1 46 44 84 83
162 4 2 50 1 46 17 65 79
163 4 2 50 1 65 62 83 80
164 4 2 50 1 84 64 79 80
165 4 2 50 1 65 80 84 79
166 4 2 50 1 65 84 46 79
167 4 2 50 1 84 80 65 83
168 4 2 50 1 46 84 65 83
169 4 2 50 1 49 44 86 85
170 4 2 50 1 49 1 36 54
171 4 2 50 1 36 35 85 87
172 4 2 50 1 86 53 54 87
173 4 2 50 1 36 87 86 54
174 4 2 50 1 36 86 49 54
175 4 2 50 1 86 87 36 85
176 4 2 50 1 49 86 36 85
177 4 2 50 1 40 35 89 88
178 4 2 50 1 40 24 78 71
179 4 2 50 1 78 64 88 81
180 4 2 50 1 89 63 71 81
181 4 2 50 1 78 81 89 71
182 4 2 50 1 78 89 40 71
183 4 2 50 1 89 81 78 88
184 4 2 50 1 40 89 78 88
185 4 2 50 1 69 62 82 90
186 4 2 50 1 69 31 58 74
187 4 2 50 1 58 53 90 91
188 4 2 50 1 82 63 74 91
189 4 2 50 1 58 91 82 74
190 4 2 50 1 58 82 69 74
191 4 2 50 1 82 91 58 90
192 4 2 50 1 69 82 58 90
193 4 2 50 1 89 35 87 92
194 4 2 50 1 89 63 82 91
195 4 2 50 1 82 62 92 90
196 4 2 50 1 87 53 91 90
197 4 2 50 1 82 90 87 91
198 4 2 50 1 82 87 89 91
199 4 2 50 1 87 90 82 92
200 4 2 50 1 89 87 82 92
201 4 2 50 1 92 35 87 85
202 4 2 50 1 92 62 83 90
203 4 2 50 1 83 44 85 86
204 4 2 50 1 87 53 90 86
205 4 2 50 1 83 86 87 90
206 4 2 50 1 83 87 92 90
207 4 2 50 1 87 86 83 85
208 4 2 50 1 92 87 83 85
209 4 2 50 1 82 62 80 92
210 4 2 50 1 82 63 89 81
211 4 2 50 1 89 35 92 88
212 4 2 50 1 80 64 81 88
213 4 2 50 1 89 88 80 81
214 4 2 50 1 89 80 82 81
215 4 2 50 1 80 88 89 92
216 4 2 50 1 82 80 89 92
217 4 2 50 1 83 44 84 85
218 4 2 50 1 83 62 92 80
219 4 2 50 1 92 35 85 88
220 4 2 50 1 84 64 80 88
221 4 2 50 1 92 88 84 80
222 4 2 50 1 92 84 83 80
223 4 2 50 1 84 88 92 85
224 4 2 50 1 83 84 92 85
225 4 2 50 1 36 35 41 85
226 4 2 50 1 36 1 49 8
227 4 2 50 1 49 44 85 52
228 4 2 50 1 41 9 8 52
229 4 2 50 1 49 52 41 8
230 4 2 50 1 49 41 36 8
231 4 2 50 1 41 52 49 85
232 4 2 50 1 36 41 49 85
233 4 2 50 1 40 35 88 43
234 4 2 50 1 40 24 23 78
235 4 2 50 1 23 22 43 76
236 4 2 50 1 88 64 78 76
237 4 2 50 1 23 76 88 78
238 4 2 50 1 23 88 40 78
239 4 2 50 1 88 76 23 43
240 4 2 50 1 40 88 23 43
241 4 2 50 1 21 22 75 42
242 4 2 50 1 21 4 10 14
243 4 2 50 1 10 9 42 50
244 4 2 50 1 75 15 14 50
245 4 2 50 1 10 50 75 14
246 4 2 50 1 10 75 21 14
247 4 2 50 1 75 50 10 42
248 4 2 50 1 21 75 10 42
249 4 2 50 1 46 44 51 84
250 4 2 50 1 46 17 79 16
251 4 2 50 1 79 64 84 77
252 4 2 50 1 51 15 16 77
253 4 2 50 1 79 77 51 16
254 4 2 50 1 79 51 46 16
255 4 2 50 1 51 77 79 84
256 4 2 50 1 46 51 79 84
257 4 2 50 1 75 22 76 93
258 4 2 50 1 75 15 51 77
259 4 2 50 1 51 44 93 84
260 4 2 50 1 76 64 77 84
261 4 2 50 1 51 84 76 77
262 4 2 50 1 51 76 75 77
263 4 2 50 1 76 84 51 93
264 4 2 50 1 75 76 51 93
265 4 2 50 1 93 22 76 43
266 4 2 50 1 93 44 85 84
267 4 2 50 1 85 35 43 88
268 4 2 50 1 76 64 84 88
269 4 2 50 1 85 88 76 84
270 4 2 50 1 85 76 93 84
271 4 2 50 1 76 88 85 43
272 4 2 50 1 93 76 85 43
273 4 2 50 1 51 44 52 93
274 4 2 50 1 51 15 75 50
275 4 2 50 1 75 22 93 42
276 4 2 50 1 52 9 50 42
277 4 2 50 1 75 42 52 50
278 4 2 50 1 75 52 51 50
279 4 2 50 1 52 42 75 93
280 4 2 50 1 51 52 75 93
281 4 2 50 1 85 35 41 43
282 4 2 50 1 85 44 93 52
283 4 2 50 1 93 22 43 42
284 4 2 50 1 41 9 52 42
285 4 2 50 1 93 42 41 52
286 4 2 50 1 93 41 85 52
287 4 2 50 1 41 42 93 43
288 4 2 50 1 85 41 93 43
289 4 2 50 1 69 62 90 67
290 4 2 50 1 69 31 30 58
291 4 2 50 1 30 29 67 56
292 4 2 50 1 90 53 58 56
293 4 2 50 1 30 56 90 58
294 4 2 50 1 30 90 69 58
295 4 2 50 1 90 56 30 67
296 4 2 50 1 69 90 30 67
297 4 2 50 1 65 62 66 83
298 4 2 50 1 65 17 46 18
299 4 2 50 1 46 44 83 45
300 4 2 50 1 66 19 18 45
301 4 2 50 1 46 45 66 18
302 4 2 50 1 46 66 65 18
303 4 2 50 1 66 45 46 83
304 4 2 50 1 65 66 46 83
305 4 2 50 1 49 44 48 86
306 4 2 50 1 49 1 54 5
307 4 2 50 1 54 53 86 55
308 4 2 50 1 48 6 5 55
309 4 2 50 1 54 55 48 5
310 4 2 50 1 54 48 49 5
311 4 2 50 1 48 55 54 86
312 4 2 50 1 49 48 54 86
313 4 2 50 1 28 29 57 68
314 4 2 50 1 28 2 20 7
315 4 2 50 1 20 19 68 47
316 4 2 50 1 57 6 7 47
317 4 2 50 1 20 47 57 7
318 4 2 50 1 20 57 28 7
319 4 2 50 1 57 47 20 68
320 4 2 50 1 28 57 20 68
321 4 2 50 1 48 44 45 94
322 4 2 50 1 48 6 57 47
323 4 2 50 1 57 29 94 68
324 4 2 50 1 45 19 47 68
325 4 2 50 1 57 68 45 47
326 4 2 50 1 57 45 48 47
327 4 2 50 1 45 68 57 94
328 4 2 50 1 48 45 57 94
329 4 2 50 1 94 44 45 83
330 4 2 50 1 94 29 67 68
331 4 2 50 1 67 62 83 66
332 4 2 50 1 45 19 68 66
333 4 2 50 1 67 66 45 68
334 4 2 50 1 67 45 94 68
335 4 2 50 1 45 66 67 83
336 4 2 50 1 94 45 67 83
337 4 2 50 1 57 29 56 94
338 4 2 50 1 57 6 48 55
339 4 2 50 1 48 44 94 86
340 4 2 50 1 56 53 55 86
341 4 2 50 1 48 86 56 55
342 4 2 50 1 48 56 57 55
343 4 2 50 1 56 86 48 94
344 4 2 50 1 57 56 48 94
345 4 2 50 1 67 62 90 83
346 4 2 50 1 67 29 94 56
347 4 2 50 1 94 44 83 86
348 4 2 50 1 90 53 56 86
349 4 2 50 1 94 86 90 56
350 4 2 50 1 94 90 67 56
351 4 2 50 1 90 86 94 83
352 4 2 50 1 67 90 94 83
353 4 2 50 1 11 12 37 59
354 4 2 50 1 11 1 54 36
355 4 2 50 1 54 53 59 87
356 4 2 50 1 37 35 36 87
357 4 2 50 1 54 87 37 36
358 4 2 50 1 54 37 11 36
359 4 2 50 1 37 87 54 59
360 4 2 50 1 11 37 54 59
361 4 2 50 1 13 12 60 39
362 4 2 50 1 13 3 27 34
363 4 2 50 1 27 26 39 72
364 4 2 50 1 60 33 34 72
365 4 2 50 1 27 72 60 34
366 4 2 50 1 27 60 13 34
367 4 2 50 1 60 72 27 39
368 4 2 50 1 13 60 27 39
369 4 2 50 1 25 26 70 38
370 4 2 50 1 25 24 40 71
371 4 2 50 1 40 35 38 89
372 4 2 50 1 70 63 71 89
373 4 2 50 1 40 89 70 71
374 4 2 50 1 40 70 25 71
375 4 2 50 1 70 89 40 38
376 4 2 50 1 25 70 40 38
377 4 2 50 1 58 53 91 61
378 4 2 50 1 58 31 32 74
379 4 2 50 1 32 33 61 73
380 4 2 50 1 91 63 74 73
381 4 2 50 1 32 73 91 74
382 4 2 50 1 32 91 58 74
383 4 2 50 1 91 73 32 61
384 4 2 50 1 58 91 32 61
385 4 2 50 1 70 26 72 95
386 4 2 50 1 70 63 91 73
387 4 2 50 1 91 53 95 61
388 4 2 50 1 72 33 73 61
389 4 2 50 1 91 61 72 73
390 4 2 50 1 91 72 70 73
391 4 2 50 1 72 61 91 95
392 4 2 50 1 70 72 91 95
393 4 2 50 1 95 26 72 39
394 4 2 50 1 95 53 59 61
395 4 2 50 1 59 12 39 60
396 4 2 50 1 72 33 61 60
397 4 2 50 1 59 60 72 61
398 4 2 50 1 59 72 95 61
399 4 2 50 1 72 60 59 39
400 4 2 50 1 95 72 59 39
401 4 2 50 1 91 53 87 95
402 4 2 50 1 91 63 70 89
403 4 2 50 1 70 26 95 38
404 4 2 50 1 87 35 89 38
405 4 2 50 1 70 38 87 89
406 4 2 50 1 70 87 91 89
407 4 2 50 1 87 38 70 95
408 4 2 50 1 91 87 70 95
409 4 2 50 1 59 12 37 39
410 4 2 50 1 59 53 95 87
411 4 2 50 1 95 26 39 38
412 4 2 50 1 37 35 87 38
413 4 2 50 1 95 38 37 87
414 4 2 50 1 95 37 59 87
415 4 2 50 1 37 38 95 39
416 4 2 50 1 59 37 95 39
$EndElements

Newest version of meshio seems to have changed the interface, and have several bugs. I would suggest to downgrade to an older version.
I was able to make the meshio mesh with the following command:

import meshio
msh = meshio.read("mesh.msh")
for cell in msh.cells:
    if cell.type == "triangle":
        triangle_cells = cell.data
    elif  cell.type == "tetra":
        tetra_cells = cell.data
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells})

However, seems like meshio has removed xdmf support as the following fails:

meshio.write("mesh.xdmf", tetra_mesh, file_format='xdmf')

with

KeyError: "Unknown format 'xdmf'. Pick one of ['abaqus', 'ansys', 'ansys-ascii', 'ansys-binary', 'avsucd', 'dolfin-xml', 'flac3d', 'gmsh', 'gmsh2-ascii', 'gmsh2-binary', 'gmsh4-ascii', 'gmsh4-binary', 'mdpa', 'medit', 'nastran', 'neuroglancer', 'obj', 'off', 'permas', 'ply', 'ply-ascii', 'ply-binary', 'stl', 'stl-ascii', 'stl-binary', 'svg', 'tecplot', 'tetgen', 'ugrid', 'vtk', 'vtk-ascii', 'vtk-binary', 'vtu', 'vtu-ascii', 'vtu-binary', 'wkt']"

which suggests xdmf has been removed from meshio. Maybe @nschloe can explain what has happened.

I understand, for now I will follow your suggestion and try to use an older version of meshio. Thank you for the help!

@fforteneto, After some help from @nschloe, the following code will work with the newest meshio:

import meshio
msh = meshio.read("mesh.msh")
for cell in msh.cells:
    if cell.type == "triangle":
        triangle_cells = cell.data
    elif  cell.type == "tetra":
        tetra_cells = cell.data

for key in msh.cell_data_dict["gmsh:physical"].keys():
    if key == "triangle":
        triangle_data = msh.cell_data_dict["gmsh:physical"][key]
    elif key == "tetra":
        tetra_data = msh.cell_data_dict["gmsh:physical"][key]
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells})
triangle_mesh =meshio.Mesh(points=msh.points,
                           cells=[("triangle", triangle_cells)],
                           cell_data={"name_to_read":[triangle_data]})
meshio.write("mesh.xdmf", tetra_mesh)

meshio.write("mf.xdmf", triangle_mesh)

6 Likes

It’s working, thanks a lot!

Hi,
Now I am able to prepare my mesh with gmsh and import it alongside with volume and boundary markers.
What should I do to Mark and import also internal boundary?
To be more clear I need to have an internal facet measure dS(i) to integrate on selected internal facets.
Best.
Iacopo