Importing mesh created in gmsh

hi,

im trying to import a msh files but once i run it gives me the following error
Traceback (most recent call last):
File “/home/mirialex/PycharmProjects/fibers/31-05-24.py”, line 11, in
tet_data = msh.cell_data_dict[“gmsh:physical”][“tetra”]
KeyError: ‘gmsh:physical’

attaching the file and also the code

import meshio
from fenics import *

mesh_name = "godplease2"

# Read the mesh file
msh = meshio.read(mesh_name + ".msh")

# Write the volume mesh to XDMF
if "tetra" in msh.cells_dict:
    tet_data = msh.cell_data_dict["gmsh:physical"]["tetra"]
    meshio.write(mesh_name + ".xdmf",
        meshio.Mesh(points=msh.points,
            cells=[("tetra", msh.cells_dict["tetra"])],
            cell_data={"dom_marker": [tet_data]}
        )
    )

# Write the surface mesh to XDMF
if "triangle" in msh.cells_dict:
    tri_data = msh.cell_data_dict["gmsh:physical"]["triangle"]
    meshio.write(mesh_name + "_surf.xdmf",
        meshio.Mesh(points=msh.points,
            cells=[("triangle", msh.cells_dict["triangle"])],
            cell_data={"bnd_marker": [tri_data]}
        )
    )

# Read the volume mesh into FEniCS
mesh = Mesh()
with XDMFFile(mesh_name + ".xdmf") as file:
    file.read(mesh)

# If needed, read the surface mesh (example for boundary conditions)
bnd_mesh = Mesh()
with XDMFFile(mesh_name + "_surf.xdmf") as file:
    file.read(bnd_mesh)

since im having a real hard time of create a cylinder inside a box i tried to do it directly in gmsh and then to import it and start analyzing it

so if you have any tips how to continue i would be more that happy to read
well i cant attach the msh file, but hope that what i wrote here would be helpful

Hi.

Would you mind to share your mesh file so we can test the MWE?

https://www.dropbox.com/scl/fi/ymo5o2woy243tn7ma4exn/godplease2.msh?rlkey=1pwyhzykbe9yjeohc1arkjuhu&st=tehu9kc5&dl=0

its not neccerely configured very well cause even the gmsh got stuck for me for a bit

I just tested with another approach for reading mesh and got the same error. There is something happening in the .geo file. Paste it here please.

$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
10 15 9 2
1 0 0 0.2 0
2 0 0 0 0
3 0 0.2 0.2 0
4 0 0.2 0 0
5 1 0 0.2 0
6 1 0 0 0
7 1 0.2 0.2 0
8 1 0.2 0 0
9 1 0.1 0.15 0
10 0 0.1 0.15 0
1 -1e-07 -1e-07 -1.000000000028756e-07 1e-07 1e-07 0.2000001 0 2 2 -1
2 -1e-07 -1.000000000028756e-07 0.1999999 1e-07 0.2000001 0.2000001 0 2 1 -3
3 -1e-07 0.1999999 -1.000000000028756e-07 1e-07 0.2000001 0.2000001 0 2 4 -3
4 -1e-07 -1.000000000028756e-07 -1e-07 1e-07 0.2000001 1e-07 0 2 2 -4
5 0.9999999000000001 -1e-07 -1.000000000028756e-07 1.0000001 1e-07 0.2000001 0 2 6 -5
6 0.9999999000000001 -1.000000000028756e-07 0.1999999 1.0000001 0.2000001 0.2000001 0 2 5 -7
7 0.9999999000000001 0.1999999 -1.000000000028756e-07 1.0000001 0.2000001 0.2000001 0 2 8 -7
8 0.9999999000000001 -1.000000000028756e-07 -1e-07 1.0000001 0.2000001 1e-07 0 2 6 -8
9 -9.999999994736442e-08 -1e-07 -1e-07 1.0000001 1e-07 1e-07 0 2 2 -6
10 -9.999999994736442e-08 -1e-07 0.1999999 1.0000001 1e-07 0.2000001 0 2 1 -5
11 -9.999999994736442e-08 0.1999999 -1e-07 1.0000001 0.2000001 1e-07 0 2 4 -8
12 -9.999999994736442e-08 0.1999999 0.1999999 1.0000001 0.2000001 0.2000001 0 2 3 -7
13 0.9999999000000001 0.0499999 0.0499999 1.0000001 0.1500001 0.1500001 0 2 9 -9
14 -9.999999994736442e-08 0.09999990000000002 0.1499999 1.0000001 0.1000001 0.1500001 0 2 10 -9
15 -1e-07 0.0499999 0.0499999 1e-07 0.1500001 0.1500001 0 2 10 -10
1 -1e-07 -1.000000000028756e-07 -1.000000000028756e-07 1e-07 0.2000001 0.2000001 0 4 1 2 -3 -4
2 0.9999999000000001 -1.000000000028756e-07 -1.000000000028756e-07 1.0000001 0.2000001 0.2000001 0 4 5 6 -7 -8
3 -9.999999994736442e-08 -1e-07 -1.000000000028756e-07 1.0000001 1e-07 0.2000001 0 4 9 5 -10 -1
4 -9.999999994736442e-08 0.1999999 -1.000000000028756e-07 1.0000001 0.2000001 0.2000001 0 4 11 7 -12 -3
5 -9.999999994736442e-08 -1.000000000028756e-07 -1e-07 1.0000001 0.2000001 1e-07 0 4 4 11 -8 -9
6 -9.999999994736442e-08 -1.000000000028756e-07 0.1999999 1.0000001 0.2000001 0.2000001 0 4 2 12 -6 -10
7 -9.999999994736442e-08 0.0499999 0.0499999 1.0000001 0.1500001 0.1500001 0 4 13 -14 15 14
8 0.9999999000000001 0.0499999 0.0499999 1.0000001 0.1500001 0.1500001 0 1 13
9 -1e-07 0.0499999 0.0499999 1e-07 0.1500001 0.1500001 0 1 15
1 -9.999999994736442e-08 -1.000000000028756e-07 -1.000000000028756e-07 1.0000001 0.2000001 0.2000001 0 6 1 2 3 4 5 6
2 -9.999999994736442e-08 0.0499999 0.0499999 1.0000001 0.1500001 0.1500001 0 3 7 8 9
$EndEntities
$Nodes
36 184 1 184
0 1 0 1
1
0 0 0.2
0 2 0 1
2
0 0 0
0 3 0 1
3
0 0.2 0.2
0 4 0 1
4
0 0.2 0
0 5 0 1
5
1 0 0.2
0 6 0 1
6
1 0 0
0 7 0 1
7
1 0.2 0.2
0 8 0 1
8
1 0.2 0
0 9 0 1
9
1 0.1 0.15
0 10 0 1
10
0 0.1 0.15
1 1 0 1
11
0 0 0.1
1 2 0 1
12
0 0.1 0.2
1 3 0 1
13
0 0.2 0.1
1 4 0 1
14
0 0.1 0
1 5 0 1
15
1 0 0.1
1 6 0 1
16
1 0.1 0.2
1 7 0 1
17
1 0.2 0.1
1 8 0 1
18
1 0.1 0
1 9 0 9
19
20
21
22
23
24
25
26
27
0.1000000000000001 0 0
0.2000000000000003 0 0
0.3000000000000003 0 0
0.4000000000000002 0 0
0.5000000000000002 0 0
0.6000000000000002 0 0
0.7000000000000001 0 0
0.8 0 0
0.9 0 0
1 10 0 9
28
29
30
31
32
33
34
35
36
0.1000000000000001 0 0.2
0.2000000000000003 0 0.2
0.3000000000000003 0 0.2
0.4000000000000002 0 0.2
0.5000000000000002 0 0.2
0.6000000000000002 0 0.2
0.7000000000000001 0 0.2
0.8 0 0.2
0.9 0 0.2
1 11 0 9
37
38
39
40
41
42
43
44
45
0.1000000000000001 0.2 0
0.2000000000000003 0.2 0
0.3000000000000003 0.2 0
0.4000000000000002 0.2 0
0.5000000000000002 0.2 0
0.6000000000000002 0.2 0
0.7000000000000001 0.2 0
0.8 0.2 0
0.9 0.2 0
1 12 0 9
46
47
48
49
50
51
52
53
54
0.1000000000000001 0.2 0.2
0.2000000000000003 0.2 0.2
0.3000000000000003 0.2 0.2
0.4000000000000002 0.2 0.2
0.5000000000000002 0.2 0.2
0.6000000000000002 0.2 0.2
0.7000000000000001 0.2 0.2
0.8 0.2 0.2
0.9 0.2 0.2
1 13 0 6
55
56
57
58
59
60
1 0.06090842587659847 0.1311744900929366
1 0.05125360439090887 0.08887395330218409
1 0.07830581304412229 0.05495155660487895
1 0.1216941869558781 0.05495155660487911
1 0.1487463956090912 0.08887395330218441
1 0.1390915741234015 0.1311744900929367
1 14 0 9
61
62
63
64
65
66
67
68
69
0.1000000000000001 0.1 0.15
0.2000000000000003 0.1 0.15
0.3000000000000003 0.1 0.15
0.4000000000000002 0.1 0.15
0.5000000000000002 0.1 0.15
0.6000000000000002 0.1 0.15
0.7000000000000001 0.1 0.15
0.8 0.1 0.15
0.9 0.1 0.15
1 15 0 6
70
71
72
73
74
75
0 0.06090842587659847 0.1311744900929366
0 0.05125360439090887 0.08887395330218409
0 0.07830581304412229 0.05495155660487895
0 0.1216941869558781 0.05495155660487911
0 0.1487463956090912 0.08887395330218441
0 0.1390915741234015 0.1311744900929367
2 1 0 4
76
77
78
79
0 0.05 0.15
0 0.07500000000000002 0.07500000000000001
0 0.1437500000000001 0.05624999999999997
0 0.130859375 0.130859375
2 2 0 4
80
81
82
83
1 0.05 0.15
1 0.07500000000000002 0.07500000000000001
1 0.1437500000000001 0.05624999999999997
1 0.130859375 0.130859375
2 3 0 12
84
85
86
87
88
89
90
91
92
93
94
95
0.5500000000000003 0 0.1045527348213611
0.75 0 0.1013917155348728
0.2500000000000003 0 0.09860828446512715
0.4500000000000002 0 0.09793221167012232
0.6500000000000002 0 0.09778431657591313
0.1500000000000002 0 0.1102317462994015
0.3500000000000002 0 0.09942341602254158
0.8499999999999998 0 0.08976825370059803
0.9344040574809804 0 0.1273210776630609
0.06559594251901953 0 0.07267892233693907
0.05930184415270761 0 0.1405457692304925
0.9406981558472924 0 0.05945423076950745
2 4 0 12
96
97
98
99
100
101
102
103
104
105
106
107
0.5500000000000003 0.2 0.1045527348213611
0.75 0.2 0.1013917155348728
0.2500000000000003 0.2 0.09860828446512715
0.4500000000000002 0.2 0.09793221167012232
0.6500000000000002 0.2 0.09778431657591313
0.1500000000000002 0.2 0.1102317462994015
0.3500000000000002 0.2 0.09942341602254158
0.8499999999999998 0.2 0.08976825370059803
0.9344040574809804 0.2 0.1273210776630609
0.06559594251901953 0.2 0.07267892233693907
0.05930184415270761 0.2 0.1405457692304925
0.9406981558472924 0.2 0.05945423076950745
2 5 0 12
108
109
110
111
112
113
114
115
116
117
118
119
0.5496531297882159 0.1038278456061589 0
0.3498761177815058 0.0955018881917593 0
0.7497571908517509 0.09989293889428419 0
0.1500000000000002 0.08660254037844391 0
0.2499894657977474 0.1050402887746911 0
0.8499999999999998 0.1102317462994021 0
0.4499215412616204 0.0998882889663197 0
0.6499017201066613 0.1006201307500738 0
0.06574516661590253 0.1266317716836685 0
0.9344040574809805 0.07267892233693914 0
0.9406981558472924 0.1405457692304925 0
0.05798121337236102 0.0577982064806853 0
2 6 0 12
120
121
122
123
124
125
126
127
128
129
130
131
0.5500000000000003 0.09544726517863894 0.2
0.3500000000000003 0.09571645848834598 0.2
0.75 0.09860828446512722 0.2
0.1500000000000002 0.08660254037844391 0.2
0.4500000000000002 0.1027759079474666 0.2
0.6500000000000002 0.1022156834240869 0.2
0.2500000000000003 0.1050585345482103 0.2
0.8499999999999998 0.1102317462994021 0.2
0.06574516661590253 0.1266317716836685 0.2
0.9344040574809805 0.07267892233693914 0.2
0.9406981558472924 0.1405457692304925 0.2
0.05798121337236102 0.0577982064806853 0.2
2 7 0 48
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
0.4500000000000002 0.05669872981078012 0.07499999999999646
0.75 0.05669872981069369 0.07500000000014616
0.2500000000000003 0.05669872981081389 0.07499999999993796
0.03864961160049265 0.1397554659399123 0.06967669332179499
0.9528622308122919 0.1388129347171359 0.06847927509330815
0.1500000000000002 0.1433012701892249 0.0750000000000051
0.03930420342317779 0.05849191860964156 0.07212386003602043
0.8338626203971097 0.146050378793142 0.08052276680305606
0.9612181471153711 0.05982961142391618 0.07022853914154642
0.3397010664704267 0.05253972517104338 0.08426715813465648
0.2500811171920695 0.1442374058580496 0.0766965255176357
0.7610288082490322 0.1476545893944515 0.08486592884758939
0.668013515595136 0.1410762473963341 0.07149137148449333
0.5172556777220378 0.05134066711555398 0.08849915988978763
0.5833179627592462 0.1353751825210597 0.06466451554595981
0.1511160446422474 0.05552532515507408 0.07715260852004954
0.8397010664704433 0.05253972517103474 0.08426715813468252
0.6873365527202564 0.05708091609604238 0.07434942034095438
0.3522800086422564 0.1447172119013056 0.07763102685026117
0.4371336242431002 0.1436611296589133 0.07563392200399173
0.794802815786534 0.1006609374735909 0.05000436857428438
0.8731515378528543 0.09326265185874003 0.05045599794098724
0.9024646240730545 0.05004036086618685 0.09799140406772144
0.9644456608780083 0.05514530106036977 0.1220919891144988
0.9052416639802433 0.1392212513163814 0.06898881741730495
0.9361158408801952 0.101257467277876 0.0500158147406095
0.2026827091059967 0.09720216267294357 0.05007834030912705
0.110576822366881 0.1009051430999813 0.05000819351165077
0.0373682469098232 0.1464236595037172 0.1185699714130886
0.08590808773790368 0.1482668920828809 0.08694982265792808
0.9630467905161008 0.1469128762283579 0.1172968796024825
0.09891996507855508 0.05118020601524366 0.1107994312482625
0.03652573470127193 0.09991583517530431 0.05000007083722734
0.03801397912453156 0.05165050656665893 0.112740741137756
0.3001309203478111 0.1026304659670282 0.05006924145582899
0.3796775089488177 0.09102578011591664 0.0508119589994466
0.5067772720537647 0.1001030500030627 0.05000010619314409
0.9719533436323954 0.1000901522378401 0.05000008127432593
0.06957167559563301 0.1202675314046176 0.05429193538594266
0.7401302098100802 0.1072318448036999 0.05052576002872608
0.1509437999809 0.0975916710983312 0.05005803416062413
0.07400848333359721 0.07779943353310612 0.05519894143495015
0.5088546951368127 0.1482513718248925 0.08689255490127967
0.1118283089069722 0.07002828630988187 0.05997880088656032
0.3946651242033256 0.05187590823838512 0.08643269399918795
0.213952073167741 0.05386326068155439 0.1192717743101613
0.1579343820657804 0.06017713661913132 0.1302347408149742
0.5911316083578523 0.07302057736476888 0.05790355413731964
2 8 0 1
180
1 0.1 0.09999999999999999
2 9 0 1
181
0 0.1 0.09999999999999999
3 1 0 3
182
183
184
0.9018489145737005 0.10212926530284 0.10373010969716
0.09794952289097118 0.103833954910569 0.102025420089431
0.699788294243326 0.09460441626152791 0.1054566698716954
3 2 0 0
$EndNodes
$Elements
36 826 1 826
0 1 15 1
1 1
0 2 15 1
2 2
0 3 15 1
3 3
0 4 15 1
4 4
0 5 15 1
5 5
0 6 15 1
6 6
0 7 15 1
7 7
0 8 15 1
8 8
0 9 15 1
9 9
0 10 15 1
10 10
1 1 1 2
11 2 11
12 11 1
1 2 1 2
13 1 12
14 12 3
1 3 1 2
15 4 13
16 13 3
1 4 1 2
17 2 14
18 14 4
1 5 1 2
19 6 15
20 15 5
1 6 1 2
21 5 16
22 16 7
1 7 1 2
23 8 17
24 17 7
1 8 1 2
25 6 18
26 18 8
1 9 1 10
27 2 19
28 19 20
29 20 21
30 21 22
31 22 23
32 23 24
33 24 25
34 25 26
35 26 27
36 27 6
1 10 1 10
37 1 28
38 28 29
39 29 30
40 30 31
41 31 32
42 32 33
43 33 34
44 34 35
45 35 36
46 36 5
1 11 1 10
47 4 37
48 37 38
49 38 39
50 39 40
51 40 41
52 41 42
53 42 43
54 43 44
55 44 45
56 45 8
1 12 1 10
57 3 46
58 46 47
59 47 48
60 48 49
61 49 50
62 50 51
63 51 52
64 52 53
65 53 54
66 54 7
1 13 1 7
67 9 55
68 55 56
69 56 57
70 57 58
71 58 59
72 59 60
73 60 9
1 14 1 10
74 10 61
75 61 62
76 62 63
77 63 64
78 64 65
79 65 66
80 66 67
81 67 68
82 68 69
83 69 9
1 15 1 7
84 10 70
85 70 71
86 71 72
87 72 73
88 73 74
89 74 75
90 75 10
2 1 2 14
91 11 1 76
92 1 12 76
93 2 11 77
94 14 2 77
95 12 3 79
96 3 13 79
97 13 4 78
98 4 14 78
99 11 76 77
100 76 12 79
101 13 78 79
102 14 77 78
103 77 76 79
104 78 77 79
2 2 2 14
105 15 80 5
106 5 80 16
107 6 81 15
108 18 81 6
109 16 83 7
110 7 83 17
111 17 82 8
112 8 82 18
113 15 81 80
114 80 83 16
115 17 83 82
116 18 82 81
117 81 83 80
118 82 83 81
2 3 2 46
119 1 11 94
120 28 1 94
121 11 2 93
122 2 19 93
123 15 5 92
124 5 36 92
125 6 15 95
126 27 6 95
127 11 93 94
128 15 92 95
129 19 20 89
130 19 89 93
131 20 21 86
132 20 86 89
133 21 22 90
134 86 21 90
135 22 23 87
136 22 87 90
137 23 24 84
138 23 84 87
139 24 25 88
140 84 24 88
141 25 26 85
142 25 85 88
143 26 27 91
144 85 26 91
145 91 27 95
146 29 28 89
147 89 28 94
148 30 29 86
149 86 29 89
150 31 30 90
151 30 86 90
152 32 31 87
153 87 31 90
154 33 32 84
155 84 32 87
156 34 33 88
157 33 84 88
158 35 34 85
159 85 34 88
160 36 35 91
161 35 85 91
162 36 91 92
163 93 89 94
164 92 91 95
2 4 2 46
165 3 106 13
166 46 106 3
167 13 105 4
168 4 105 37
169 17 104 7
170 7 104 54
171 8 107 17
172 45 107 8
173 13 106 105
174 17 107 104
175 37 101 38
176 37 105 101
177 38 98 39
178 38 101 98
179 39 102 40
180 98 102 39
181 40 99 41
182 40 102 99
183 41 96 42
184 41 99 96
185 42 100 43
186 96 100 42
187 43 97 44
188 43 100 97
189 44 103 45
190 97 103 44
191 103 107 45
192 47 101 46
193 101 106 46
194 48 98 47
195 98 101 47
196 49 102 48
197 48 102 98
198 50 99 49
199 99 102 49
200 51 96 50
201 96 99 50
202 52 100 51
203 51 100 96
204 53 97 52
205 97 100 52
206 54 103 53
207 53 103 97
208 54 104 103
209 105 106 101
210 104 107 103
2 5 2 46
211 2 14 119
212 19 2 119
213 14 4 116
214 4 37 116
215 18 6 117
216 6 27 117
217 8 18 118
218 45 8 118
219 14 116 119
220 18 117 118
221 20 19 111
222 111 19 119
223 21 20 112
224 20 111 112
225 22 21 109
226 109 21 112
227 23 22 114
228 22 109 114
229 24 23 108
230 108 23 114
231 25 24 115
232 24 108 115
233 26 25 110
234 110 25 115
235 27 26 113
236 26 110 113
237 27 113 117
238 37 38 111
239 37 111 116
240 38 39 112
241 111 38 112
242 39 40 109
243 39 109 112
244 40 41 114
245 109 40 114
246 41 42 108
247 41 108 114
248 42 43 115
249 108 42 115
250 43 44 110
251 43 110 115
252 44 45 113
253 110 44 113
254 113 45 118
255 116 111 119
256 117 113 118
2 6 2 46
257 1 131 12
258 28 131 1
259 12 128 3
260 3 128 46
261 16 129 5
262 5 129 36
263 7 130 16
264 54 130 7
265 12 131 128
266 16 130 129
267 29 123 28
268 123 131 28
269 30 126 29
270 29 126 123
271 31 121 30
272 121 126 30
273 32 124 31
274 31 124 121
275 33 120 32
276 120 124 32
277 34 125 33
278 33 125 120
279 35 122 34
280 122 125 34
281 36 127 35
282 35 127 122
283 36 129 127
284 46 123 47
285 46 128 123
286 47 126 48
287 123 126 47
288 48 121 49
289 48 126 121
290 49 124 50
291 121 124 49
292 50 120 51
293 50 124 120
294 51 125 52
295 120 125 51
296 52 122 53
297 52 125 122
298 53 127 54
299 122 127 53
300 127 130 54
301 128 131 123
302 129 130 127
2 7 2 128
303 9 155 55
304 60 162 9
305 69 155 9
306 9 162 69
307 61 160 10
308 10 165 61
309 70 165 10
310 10 160 75
311 55 155 56
312 56 140 57
313 56 155 140
314 57 169 58
315 140 169 57
316 58 136 59
317 58 169 136
318 59 162 60
319 136 162 59
320 62 137 61
321 61 178 62
322 137 161 61
323 61 161 160
324 61 165 163
325 163 178 61
326 63 142 62
327 62 177 63
328 62 142 137
329 62 178 177
330 63 141 64
331 64 150 63
332 134 141 63
333 63 177 134
334 63 150 142
335 64 132 65
336 65 151 64
337 64 176 132
338 141 176 64
339 64 151 150
340 65 145 66
341 66 174 65
342 132 145 65
343 65 174 151
344 67 144 66
345 66 149 67
346 144 146 66
347 145 179 66
348 146 174 66
349 66 179 149
350 67 133 68
351 68 143 67
352 67 149 133
353 143 144 67
354 69 139 68
355 68 148 69
356 133 148 68
357 139 143 68
358 69 156 139
359 148 154 69
360 154 155 69
361 69 162 156
362 71 165 70
363 72 138 71
364 138 165 71
365 73 164 72
366 72 164 138
367 74 135 73
368 135 164 73
369 75 160 74
370 74 160 135
371 132 168 145
372 132 167 151
373 151 168 132
374 132 176 167
375 133 152 148
376 149 171 133
377 133 171 152
378 134 166 141
379 158 166 134
380 134 177 158
381 160 161 135
382 161 170 135
383 135 170 164
384 136 157 156
385 156 162 136
386 136 169 157
387 142 158 137
388 158 172 137
389 159 161 137
390 137 172 159
391 163 165 138
392 138 173 163
393 164 173 138
394 139 152 143
395 139 153 152
396 139 156 153
397 140 155 154
398 154 157 140
399 157 169 140
400 166 167 141
401 167 176 141
402 150 166 142
403 142 166 158
404 143 171 144
405 152 171 143
406 144 179 146
407 144 171 149
408 149 179 144
409 168 179 145
410 168 174 146
411 146 179 168
412 147 172 158
413 158 177 147
414 163 175 147
415 147 178 163
416 147 175 172
417 177 178 147
418 152 153 148
419 153 154 148
420 151 167 150
421 150 167 166
422 151 174 168
423 153 157 154
424 156 157 153
425 159 170 161
426 159 173 170
427 172 175 159
428 159 175 173
429 173 175 163
430 170 173 164
2 8 2 7
431 55 180 9
432 9 180 60
433 56 180 55
434 57 180 56
435 58 180 57
436 59 180 58
437 60 180 59
2 9 2 7
438 70 10 181
439 10 75 181
440 71 70 181
441 72 71 181
442 73 72 181
443 74 73 181
444 75 74 181
3 1 4 262
445 99 90 102 114
446 99 87 90 114
447 109 90 114 102
448 102 98 90 121
449 98 86 90 121
450 87 114 99 108
451 124 87 99 108
452 86 98 126 121
453 124 84 87 108
454 108 124 96 99
455 96 84 124 108
456 84 96 124 120
457 98 112 86 183
458 98 86 126 183
459 84 108 96 184
460 96 120 84 184
461 115 100 108 184
462 96 108 100 184
463 108 88 115 184
464 108 84 88 184
465 113 97 110 184
466 96 125 120 184
467 112 111 86 183
468 123 126 86 183
469 126 101 98 183
470 125 96 100 184
471 110 85 91 184
472 97 127 122 184
473 123 86 89 183
474 125 88 84 184
475 112 98 101 183
476 113 182 103 184
477 97 113 103 184
478 125 84 120 184
479 111 89 86 183
480 111 112 101 183
481 101 126 123 183
482 35 85 122 91
483 115 108 24 88
484 102 114 40 99
485 87 23 114 108
486 40 109 114 102
487 24 108 84 88
488 23 87 84 108
489 87 90 31 121
490 33 84 125 88
491 124 84 32 87
492 31 124 87 121
493 30 90 86 121
494 127 35 122 91
495 84 120 33 125
496 84 124 32 120
497 86 126 30 121
498 98 38 112 101
499 100 42 115 108
500 112 39 98 102
501 99 114 41 108
502 39 112 109 102
503 51 125 96 100
504 42 100 96 108
505 96 99 41 108
506 50 124 99 96
507 113 97 44 110
508 51 125 120 96
509 50 120 124 96
510 111 112 38 101
511 97 113 44 103
512 91 85 110 26
513 86 126 123 29
514 53 127 122 97
515 110 113 91 26
516 29 123 86 89
517 53 127 97 103
518 111 86 20 112
519 47 101 98 126
520 111 20 86 89
521 45 118 107 182
522 28 94 131 183
523 47 101 126 123
524 97 43 110 184
525 91 95 117 182
526 115 43 100 184
527 95 91 117 27
528 115 110 43 184
529 119 93 111 183
530 89 94 28 183
531 97 100 43 184
532 113 91 117 182
533 113 118 45 182
534 25 85 110 184
535 45 107 103 182
536 131 76 79 183
537 37 111 101 183
538 127 36 91 182
539 82 104 107 182
540 52 97 122 184
541 25 115 88 184
542 125 100 52 184
543 82 83 104 182
544 28 131 123 183
545 82 118 81 182
546 93 89 111 183
547 82 107 118 182
548 92 91 36 182
549 129 92 36 182
550 19 93 111 119
551 91 113 117 27
552 36 35 127 91
553 94 76 131 183
554 37 116 111 183
555 127 129 36 182
556 34 88 125 184
557 94 77 76 183
558 37 111 38 101
559 25 110 115 184
560 116 37 105 183
561 125 34 33 88
562 84 23 108 24
563 87 124 31 32
564 37 101 105 183
565 43 44 97 110
566 97 52 100 184
567 86 126 29 30
568 102 49 48 121
569 104 54 103 182
570 105 78 116 183
571 111 93 19 89
572 109 40 39 102
573 83 80 129 182
574 80 92 129 182
575 128 46 123 183
576 85 34 122 184
577 130 54 104 182
578 105 79 78 183
579 46 128 106 183
580 25 110 85 26
581 128 131 79 183
582 25 88 85 184
583 125 51 52 100
584 23 22 87 114
585 52 122 125 184
586 24 25 115 88
587 80 81 92 182
588 21 20 86 112
589 12 79 131 76
590 113 45 103 182
591 116 78 77 183
592 99 49 124 50
593 43 100 42 115
594 122 52 53 97
595 42 96 41 108
596 41 40 114 99
597 77 94 93 183
598 117 81 118 182
599 89 28 123 183
600 120 50 51 96
601 90 30 31 121
602 90 22 21 109
603 122 34 85 35
604 117 95 81 182
605 77 93 119 183
606 17 82 104 107
607 104 83 82 17
608 127 103 54 182
609 101 123 46 183
610 85 88 34 184
611 34 125 122 184
612 79 76 77 183
613 130 127 54 182
614 105 4 116 78
615 92 81 95 182
616 77 119 116 183
617 46 106 101 183
618 94 77 11 76
619 83 81 80 182
620 79 105 106 183
621 130 83 129 182
622 48 47 98 126
623 104 83 130 182
624 79 106 128 183
625 12 79 128 131
626 120 33 32 84
627 5 80 92 129
628 27 91 113 26
629 127 53 54 103
630 78 105 13 79
631 80 129 16 83
632 101 47 46 123
633 112 39 38 98
634 82 81 83 182
635 89 93 94 183
636 77 78 79 183
637 118 113 117 182
638 91 92 95 182
639 19 20 111 89
640 119 111 116 183
641 11 93 77 94
642 14 77 116 78
643 3 79 106 128
644 92 80 15 81
645 104 7 130 83
646 81 117 6 95
647 77 93 2 119
648 104 103 107 182
649 44 45 103 113
650 128 123 131 183
651 79 105 13 106
652 130 16 129 83
653 106 105 101 183
654 127 130 129 182
655 93 2 11 77
656 6 18 117 81
657 81 15 92 95
658 79 3 12 128
659 83 104 7 17
660 14 77 119 116
661 4 14 116 78
662 105 13 4 78
663 123 29 28 89
664 36 5 92 129
665 15 5 80 92
666 5 80 129 16
667 81 6 15 95
668 4 116 37 105
669 77 2 14 119
670 7 16 130 83
671 79 13 3 106
672 17 8 82 107
673 8 82 118 18
674 8 82 107 118
675 94 11 1 76
676 131 1 12 76
677 7 130 54 104
678 3 106 46 128
679 45 8 107 118
680 95 117 6 27
681 1 131 28 94
682 1 131 94 76
683 93 19 2 119
684 121 98 48 102
685 121 48 98 126
686 121 102 99 90
687 99 87 121 90
688 121 87 99 124
689 102 112 90 98
690 102 90 112 109
691 86 90 112 98
692 114 90 22 87
693 114 22 90 109
694 184 113 91 110
695 184 91 113 182
696 103 184 127 97
697 127 184 103 182
698 184 91 122 85
699 184 127 91 182
700 184 91 127 122
701 118 81 18 82
702 18 81 118 117
703 99 121 49 102
704 49 121 99 124
705 90 112 21 86
706 90 21 112 109
3 2 4 120
707 170 164 138 135
708 135 164 138 181
709 138 170 135 160
710 138 173 164 170
711 138 135 181 160
712 138 173 170 165
713 175 172 159 137
714 178 175 147 163
715 159 173 175 163
716 160 138 170 165
717 173 159 170 161
718 158 172 147 178
719 161 135 170 160
720 173 159 161 163
721 160 181 138 165
722 58 180 136 169
723 172 158 137 178
724 154 157 155 140
725 135 73 164 181
726 180 59 58 136
727 161 159 61 163
728 157 155 69 154
729 155 69 162 157
730 72 164 73 181
731 73 135 74 181
732 164 72 138 181
733 61 137 62 178
734 57 180 169 140
735 141 176 167 64
736 159 61 137 161
737 157 69 156 154
738 10 181 160 165
739 154 69 153 148
740 62 137 158 178
741 180 162 59 136
742 68 67 143 133
743 153 69 139 148
744 180 57 56 140
745 171 143 67 133
746 153 156 69 154
747 178 147 158 177
748 151 167 176 64
749 180 58 57 169
750 69 139 156 153
751 63 141 150 64
752 142 63 62 177
753 63 142 134 177
754 150 141 167 64
755 132 151 64 65
756 162 9 155 180
757 135 74 181 160
758 72 71 138 181
759 153 157 156 154
760 69 68 139 148
761 152 68 133 148
762 142 137 158 62
763 152 68 143 133
764 150 142 166 63
765 144 143 67 171
766 179 66 146 145
767 138 173 165 163
768 158 62 178 177
769 160 61 10 165
770 176 132 151 64
771 151 150 167 64
772 168 146 174 145
773 179 144 66 149
774 146 144 66 179
775 67 66 144 149
776 134 166 142 63
777 152 139 68 148
778 146 168 179 145
779 176 132 167 151
780 56 155 180 140
781 70 181 10 165
782 166 134 141 63
783 174 132 151 168
784 166 141 150 63
785 69 9 155 162
786 74 181 160 75
787 158 142 62 177
788 155 55 56 180
789 143 171 152 133
790 143 139 68 152
791 149 171 67 133
792 171 67 144 149
793 71 181 70 165
794 132 151 65 174
795 59 60 162 180
796 142 158 134 177
797 60 9 162 180
798 160 181 10 75
799 139 152 153 148
800 181 71 138 165
801 155 9 55 180
802 166 141 167 150
803 166 158 134 142
804 160 161 165 170
805 160 165 161 61
806 173 165 161 170
807 157 140 162 155
808 180 162 140 155
809 178 163 137 175
810 178 137 163 61
811 159 137 163 175
812 159 163 137 61
813 162 157 156 136
814 156 157 162 69
815 178 172 175 137
816 178 175 172 147
817 163 161 165 61
818 163 165 161 173
819 66 174 145 65
820 145 174 66 146
821 145 174 132 65
822 145 132 174 168
823 157 169 180 140
824 180 169 157 136
825 180 162 157 140
826 157 162 180 136
$EndElements

This is not the .geo file. This is the raw .msh file. If you don’t have the .geo, then maybe you did your mesh directly using the Gmsh python interface. You could also share that to see what is happening.

i used the gmsh that is intall on my ubonto
this is the files that was generated when i saved it
how can i save different file?

Please note that when your are editing your mesh file on GMSH, the changes are saved on a .geo file by default. A .geo file looks like the following:

SetFactory("Built-in");
h=1;
Point(1) = {0, 0, 0, h}; 
Point(2) = {1, 0, 0, h};
Point(3) = {1, 1, 0, h};
Point(4) = {0,1, 0, h};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};

//+
Curve Loop(1) = {1, 2, 3, 4};
//+
Plane Surface(1) = {1};
//+
Physical Surface("10",10) = {1};
//+
Physical Curve("1", 1) = {1};
//+
Physical Curve("2", 2) = {2};
//+
Physical Curve("3", 3) = {3};
//+
Physical Curve("4", 4) = {4};

You can check on that by clicking on edit script
image

I suspect there is something wrong when defining the physical groups of your mesh.

yes it was something with the files, i managed to import it
thanks

Please post the solution here, as it would help others resolve similar problems in the future.

im facing again an issue with the file
with this error “Error: Couldn’t read file box_cylinder.msh as either of ansys, gmsh”

those are the files i used Dropbox

with the same code(updated name file)

import meshio
from fenics import *

mesh_name = "box_cylinder"

# Read the mesh file
msh = meshio.read(mesh_name + ".msh")

# Write the volume mesh to XDMF
if "tetra" in msh.cells_dict:
    tet_data = msh.cell_data_dict["gmsh:physical"]["tetra"]
    meshio.write(mesh_name + ".xdmf",
        meshio.Mesh(points=msh.points,
            cells=[("tetra", msh.cells_dict["tetra"])],
            cell_data={"dom_marker": [tet_data]}
        )
    )

# Write the surface mesh to XDMF
if "triangle" in msh.cells_dict:
    tri_data = msh.cell_data_dict["gmsh:physical"]["triangle"]
    meshio.write(mesh_name + "_surf.xdmf",
        meshio.Mesh(points=msh.points,
            cells=[("triangle", msh.cells_dict["triangle"])],
            cell_data={"bnd_marker": [tri_data]}
        )
    )

# Read the volume mesh into FEniCS
mesh = Mesh()
with XDMFFile(mesh_name + ".xdmf") as file:
    file.read(mesh)

# If needed, read the surface mesh (example for boundary conditions)
bnd_mesh = Mesh()
with XDMFFile(mesh_name + "_surf.xdmf") as file:
    file.read(bnd_mesh)

any idea why? is it something about the way im saving the files?

i tried to add the following line to the geo files (new_box_cylinder)

//+
SetFactory("Build-in");

i uploaded the updated files to this link Dropbox

and i managed to get thorough the first steps but then i got the following error
/usr/bin/python3.10 /home/mirialex/PycharmProjects/fibers/31-05-24.py
Traceback (most recent call last):
File “/home/mirialex/PycharmProjects/fibers/31-05-24.py”, line 36, in
file.read(mesh)
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


*** https://fenicsproject.discourse.group/


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to open XDMF file.
*** Reason: XDMF file “new_box_cylinder.xdmf” does not exist.
*** Where: This error was encountered inside XDMFFile.cpp.
*** Process: 0


*** DOLFIN version: 2019.2.0.13.dev0
*** Git changeset: ubuntu
*** -------------------------------------------------------------------------

Process finished with exit code 1

any idea why?

i also tried this (posted by @dokken few years ago

import meshio


msh = meshio.read("new_box_cylinder.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


tetra_mesh = create_mesh(msh, "tetra")
triangle_mesh = create_mesh(msh, "triangle")
meshio.write("mesh.xdmf", tetra_mesh)

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

error
/usr/bin/python3.10 /home/mirialex/PycharmProjects/fibers/1-06-24.py
Traceback (most recent call last):
File “/home/mirialex/PycharmProjects/fibers/1-06-24.py”, line 17, in
tetra_mesh = create_mesh(msh, “tetra”)
File “/home/mirialex/PycharmProjects/fibers/1-06-24.py”, line 9, in create_mesh
cell_data = mesh.get_cell_data(“gmsh:physical”, cell_type)
File “/usr/lib/python3/dist-packages/meshio/_mesh.py”, line 249, in get_cell_data
return np.concatenate(
File “<array_function internals>”, line 5, in concatenate
ValueError: need at least one array to concatenate

Process finished with exit code 1

how can i make sure that my tetra elements are defined as needed?

First you post about box_cylinder and then about new_box_cylinder. Please, try to simplify your debugging as much as possible before posting because we might end up solving a question you have already solved by yourself, or getting lost in the post.

Regarding box_cylinder, you are using Recombine in the extrude, which will produce elements that are not supported in Legacy FEniCS. By removing that, you end up with tetrahedrons, as desired. Also, by extruding your composite mesh, your are creating two volumes: one for the cylinder, and one for the “exterior”. However, you are defining only a physical volume 1 which is the cylinder. I don’t know if that was intentional. The following .geo file stores Volume 1 and 2 as single physical volume:

SetFactory("Built-in");
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {0, 0.2, .2, 1.0};
//+
Point(7) = {0, 0.2, 0, 1.0};
//+
Point(8) = {0, 0, 0.2, 1.0};
//+
Point(10) = {0, 0.1, 0.1, 1.0};
//+
Point(13) = {0, 0.15, 0.1, 1.0};
//+
Point(14) = {0, 0.1, 0.15, 1.0};
//+
Point(15) = {0, 0.1, 0.05, 1.0};
//+
Point(16) = {0, 0.05, 0.1, 1.0};
//+
Circle(1) = {14, 10, 13};
//+
Circle(2) = {13, 10, 15};
//+
Circle(3) = {15, 10, 16};
//+
Circle(4) = {16, 10, 14};
//+
Line(5) = {8, 2};
//+
Line(6) = {2, 7};
//+
Line(7) = {7, 1};
//+
Line(8) = {1, 8};
//+
Curve Loop(1) = {5, 6, 7, 8};
//+
Curve Loop(2) = {4, 1, 2, 3};
//+
Plane Surface(2) = {2};
//+
Plane Surface(3) = {1, 2};

//+
Extrude {1, 0, 0} {Surface{2}; Surface{3}; Layers {10};
}
//+
Physical Surface("top", 110) = {43};
//+
Physical Surface("bottum", 111) = {51};
//+
Physical Surface("left", 112) = {47};
//+
Physical Surface("right", 113) = {55};
//+
Physical Surface("front", 114) = {3};
//+
Physical Surface("back", 115) = {72};
//+
Physical Surface("cylinder_left", 116) = {2};
//+
Physical Surface("cylinder_right", 117) = {30};
//+
Physical Volume("body", 118) = {1,2};

Using the code from @dokken works with no issue in this mesh.

import meshio


msh = meshio.read("box_cylinder.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


tetra_mesh = create_mesh(msh, "tetra")
triangle_mesh = create_mesh(msh, "triangle")
meshio.write("mesh.xdmf", tetra_mesh)

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

hi, i have tried to use what you sent me (the updated code for box_cylinder) in both of the codes and this is the error i got
Error: Couldn’t read file new_box_cylinder_wc.msh as either of ansys, gmsh

i have use the updated file in the dropbox Dropbox called new_box_cylinder_wc
btw, when you are importing my files , are you using new_box_cylinder_wc.msh or new_box_cylinder_ws?

Maybe the .msh is being malformed because I tested your .msh file from Dropbox and got the same error. What version of GMSH are you using?. How are you saving your files?.

You can save your mesh by running the following command from a terminal inside your meshes directory and try to read them again.

gmsh -3 box_cylinder.geo -o box_cylinder.msh

I did not used either. I used box_cylinder.

my version is 4.11.1
im saving it via files->export->
image
or file-> save mesh
and for the geo it just being saved

also, if i do want to create 2 volumes (i want to create two bodies, the cylinder and the box) its possible?

i tried that and it read my file without any issue and exported my exml file so thats great, thank you!

now what i want to ask is how can i create two bodies with the exml (2 volums) i need one body to be the cylinder inside the second body the box.

i tried to do it like this but in paraview i see only the box(with the same code i posted before)

// Gmsh project created on Mon Jun 03 15:42:59 2024
//+
SetFactory("OpenCASCADE");
Box(1) = {0, 0, 0, 1, 0.2, 0.2};
//+
Cylinder(2) = {0, 0.1, 0.1, 1, 0, 0, 0.05, 2*Pi};
//+
Curve Loop(10) = {2, -3, -4, 1};
//+
Plane Surface(10) = {10};
//+
Curve Loop(11) = {2, 12, -6, -10};
//+
Plane Surface(11) = {11};
//+
Curve Loop(12) = {11, -8, -9, 4};
//+
Plane Surface(12) = {12};
//+
Curve Loop(14) = {1, 10, -5, -9};
//+
Plane Surface(13) = {14};
//+
Curve Loop(15) = {8, 7, -6, -5};
//+
Plane Surface(14) = {15};
//+
Curve Loop(16) = {12, -7, -11, 3};
//+
Plane Surface(15) = {16};
//+
Physical Surface("left", 17) = {1};
//+
Physical Surface("right", 18) = {2};
//+
Physical Surface("up", 19) = {4};
//+
Physical Surface("down", 20) = {3};
//+
Physical Surface("front", 21) = {6};
//+
Physical Surface("back", 22) = {5};
//+
Physical Volume("body", 23) = {1};
//+
Physical Volume("body", 24) = {2};

This is a pure gmsh question, which I think is better suited for the GMSH developers.
You can also look into the gmsh tutorials (chapter 2 of: https://gmsh.info/dev/doc/texinfo/gmsh.pdf)

1 Like