Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GMSH guide #875

Closed
RemDelaporteMathurin opened this issue Aug 12, 2024 · 9 comments · Fixed by #885
Closed

GMSH guide #875

RemDelaporteMathurin opened this issue Aug 12, 2024 · 9 comments · Fixed by #885
Milestone

Comments

@RemDelaporteMathurin
Copy link
Collaborator

Following #739 we would need to add a guide/demo for a GMSH workflow.

@celyn has a working example for a cube mesh with the python API of GMSH.

I don't know if the GUI workflow is needed.

I'm opening this issue to start the discussion

@celyneira
Copy link
Contributor

I haven't had chance to fully test it yet but I think my cube mesh should work - when visualising in Paraview all the markers look to be correct. I'm just having issues getting more complicated meshes to compile. The GUI workflow has issues when it comes to exporting files, but is fairly okay to use to create the base mesh, I think it's to do with what meshio can and can't read and how GMSH exports things when using the actual program.

@RemDelaporteMathurin
Copy link
Collaborator Author

I'm just having issues getting more complicated meshes to compile.

Have you tried importing CAD files into GMSH?

The GUI workflow has issues when it comes to exporting files, but is fairly okay to use to create the base mesh, I think it's to do with what meshio can and can't read and how GMSH exports things when using the actual program.

What you could do is try to mesh the exact same geometry in the GUI and with the python API. They should produce the exact same .msh files.

If the .msh file previously produced by the python API is readable by meshio, then so should the one produced by the GUI.

@celyneira
Copy link
Contributor

Not yet. I'm finding that converting from a .msh to an XDMF that retains all the necessary boundaries and tags isn't as straight forward as I thought. The issue with the GUI vs Python API is the method of exporting is that the GUI has problems with the formatting of the file compared to what meshio can read due to version errors

@RemDelaporteMathurin
Copy link
Collaborator Author

It looks like this answer from @jorgensd works with the latest meshio version for msh-to-xdmf https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/79

Is this what you are using?

@celyneira
Copy link
Contributor

celyneira commented Aug 13, 2024 via email

@RemDelaporteMathurin
Copy link
Collaborator Author

RemDelaporteMathurin commented Aug 13, 2024

@celyneira I managed to get the following to work:

Mesh file (taken from the thread)

$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

Conversion and FESTIM sim

import meshio
import numpy as np
import festim as F

# convert mesh to xdmf

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},
    cell_data={"f": [tetra_data]},
)
triangle_mesh = meshio.Mesh(
    points=msh.points,
    cells=[("triangle", triangle_cells)],
    cell_data={"f": [triangle_data]},
)

print("surface ids ", np.unique(triangle_data))
print("volume ids ", np.unique(tetra_data))

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

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

# FESTIM simulation

my_model = F.Simulation()
my_model.mesh = F.MeshFromXDMF(volume_file="mesh.xdmf", boundary_file="mf.xdmf")


my_model.boundary_conditions = [
    F.DirichletBC(surfaces=[40], value=10, field=0),
    F.DirichletBC(surfaces=[10], value=2, field=0),
    F.DirichletBC(surfaces=[20], value=5, field=0),
]

my_model.materials = F.Material(id=50, D_0=1, E_D=0)

my_model.T = 500

my_model.settings = F.Settings(
    absolute_tolerance=1e-10,
    relative_tolerance=1e-10,
    transient=False,
)
my_model.exports = [F.XDMFExport(field="solute")]

my_model.initialise()
my_model.run()

It produces the following field:

image

@jorgensd
Copy link
Collaborator

Please note that you can use dolfinx.io.gmshio to read msh files (as long as you have the Python API of GMSH installed). Then you do not have to split the Mesh and boundary files into different files.

@RemDelaporteMathurin
Copy link
Collaborator Author

Yep will do that for FESTIM2 but we are still trying to get a workflow for legacy-fenics. But I got it to work!!!

Meshing script:

import gmsh


def main():
    gmsh.initialize()

    # Define the first material cube
    cube1 = gmsh.model.occ.addBox(x=0, y=0, z=0, dx=1, dy=1, dz=1)
    # Define the second material cube
    # Adjust the position to make the cubes touch each other
    cube2 = gmsh.model.occ.addBox(x=1, y=0, z=0, dx=1, dy=1, dz=1)

    gmsh.model.occ.synchronize()

    # Perform a Boolean union to merge the cubes and their shared surfaces
    gmsh.model.occ.fragment([(3, cube1)], [(3, cube2)])
    gmsh.model.occ.synchronize()

    # Create physical groups
    gmsh.model.addPhysicalGroup(3, [cube1], 1)
    gmsh.model.addPhysicalGroup(3, [cube2], 2)

    # Tagging the surfaces
    # Get the surfaces of cube 1 and cube 2
    surfaces_cube1 = gmsh.model.getBoundary(
        [(3, cube1)], oriented=False, recursive=False
    )
    surfaces_cube2 = gmsh.model.getBoundary(
        [(3, cube2)], oriented=False, recursive=False
    )

    # Tag the left surface of cube 1
    left_surface_cube1 = None
    for surface in surfaces_cube1:
        com = gmsh.model.occ.getCenterOfMass(surface[0], surface[1])
        if com[0] == 0:
            left_surface_cube1 = surface[1]
            break

    # Tag the right surface of cube 2
    right_surface_cube2 = None
    for surface in surfaces_cube2:
        com = gmsh.model.occ.getCenterOfMass(surface[0], surface[1])
        if com[0] == 2:
            right_surface_cube2 = surface[1]
            break

    if left_surface_cube1 is not None:
        gmsh.model.addPhysicalGroup(
            2, [left_surface_cube1], 3
        )  # Tag ID 3 for left surface of cube 1
    if right_surface_cube2 is not None:
        gmsh.model.addPhysicalGroup(
            2, [right_surface_cube2], 4
        )  # Tag ID 4 for right surface of cube 2

    # Generate the mesh
    gmsh.model.mesh.generate(3)

    # Save the mesh
    gmsh.write("two_material_cubes_touching.msh")

    # If you want to visualize the mesh
    gmsh.fltk.run()

    gmsh.finalize()


if __name__ == "__main__":
    main()

Conversion and FESTIM:

import meshio
import numpy as np
import festim as F

# Convert mesh to XDMF
filename = "two_material_cubes_touching.msh"
msh = meshio.read(filename)

# Initialize lists to store cells and their corresponding data
triangle_cells_list = []
tetra_cells_list = []
triangle_data_list = []
tetra_data_list = []

# Extract cell data for all types
for cell in msh.cells:
    if cell.type == "triangle":
        triangle_cells_list.append(cell.data)
    elif cell.type == "tetra":
        tetra_cells_list.append(cell.data)

# Extract physical tags
for key, data in msh.cell_data_dict["gmsh:physical"].items():
    if key == "triangle":
        triangle_data_list.append(data)
    elif key == "tetra":
        tetra_data_list.append(data)

# Concatenate all tetrahedral cells and their data
tetra_cells = np.concatenate(tetra_cells_list)
tetra_data = np.concatenate(tetra_data_list)

# Concatenate all triangular cells and their data
triangle_cells = np.concatenate(triangle_cells_list)
triangle_data = np.concatenate(triangle_data_list)

# Create the tetrahedral mesh
tetra_mesh = meshio.Mesh(
    points=msh.points,
    cells=[("tetra", tetra_cells)],
    cell_data={"f": [tetra_data]},
)

# Create the triangular mesh for the surface
triangle_mesh = meshio.Mesh(
    points=msh.points,
    cells=[("triangle", triangle_cells)],
    cell_data={"f": [triangle_data]},
)

# Print unique surface and volume IDs
print("Surface IDs: ", np.unique(triangle_data))
print("Volume IDs: ", np.unique(tetra_data))

# Write the mesh files
meshio.write("mesh.xdmf", tetra_mesh)
meshio.write("mf.xdmf", triangle_mesh)
# FESTIM simulation

my_model = F.Simulation()
my_model.mesh = F.MeshFromXDMF(volume_file="mesh.xdmf", boundary_file="mf.xdmf")


my_model.boundary_conditions = [
    F.DirichletBC(surfaces=[3], value=10, field=0),
    F.DirichletBC(surfaces=[4], value=1, field=0),
]

my_model.materials = [
    F.Material(id=1, D_0=1, E_D=0),
    F.Material(id=2, D_0=4, E_D=0),
]

my_model.T = 500

my_model.settings = F.Settings(
    absolute_tolerance=1e-10,
    relative_tolerance=1e-10,
    transient=False,
)
my_model.exports = [F.XDMFExport(field="solute")]

my_model.initialise()
my_model.run()

It produces this concentration field:
image

@celyneira
Copy link
Contributor

ok yes your second method works for me, I think I had an issue with the first method due to there being two volumes? I haven't had a lot of time today to look at this but I'll continue to mess with things

@RemDelaporteMathurin RemDelaporteMathurin linked a pull request Oct 8, 2024 that will close this issue
10 tasks
@RemDelaporteMathurin RemDelaporteMathurin added this to the 1.4 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants