# How dose mesh affects calcualtion speed?

Hi, everyone. I’m recently solving my equations by Picard iteraion in two different meshes. Mesh 1 is generated by using and rotating (about 2°) the fenics built-in 2D rectangle mesh, while mesh 2 is transformedTransitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio from msh file generated with gmsh by extruding a 1D line to a parallelogram, as the picture shows (mesh1 for the left and mesh2 for the right). The problem is that, while the two meshes has similar numbers of nodes and elements, and even approaching element shapes, the iteration speed for the built-in mesh1 is much more faster then mesh 2 (at least two times faster). Even when I have tried coarsed the mesh 2 and make its elemt numbers become only half of that for mesh 1,the iteration speed using mesh 2 is still obvious slower than using mesh 1. Then what could be the reason for the significant different calculation speed when using the two similar meshes?

Hi, I now can conclude that it’s the interpolation of Expression containing another Function leading to the difference. See the following example:

from dolfin import *
import time

#generate mesh1 and mesh2
mesh1=RectangleMesh(
Point(0,-1),Point(400,0),
40,100)
mesh1.rotate(1.43,2,Point(0,0))
print('mesh1 cells:'+str(mesh1.num_cells()))

mesh2=Mesh()
with XDMFFile('mesh.xdmf') as infile:
print('mesh2 cells:'+str(mesh2.num_cells()))

#define FunctionSpace and Functions
V1=FunctionSpace(mesh1,'CG',1)
V2=FunctionSpace(mesh2,'CG',1)
f1=Function(V1)
f2=Function(V2)
h1=interpolate(Expression('-1',degree=0),V1)
h2=interpolate(Expression('-1',degree=0),V2)

#define the expression
ex1=Expression('h',degree=1,h=h1)
ex2=Expression('h',degree=1,h=h2)
#ex1=Expression('-1',degree=1)
#ex2=Expression('-1',degree=1)

#assign
t0=time.process_time()
f1.assign(interpolate(ex1,V1))
t1=time.process_time()
f2.assign(interpolate(ex2,V2))
t2=time.process_time()
print('assign time for fenics built-in mesh:'+str(t1-t0))
print('assign time for gmsh:'+str(t2-t1))

and the results:

mesh1 cells:8000
mesh2 cells:8000
assign time for fenics built-in mesh:0.016637910000000034
assign time for gmsh:0.11017641499999997

The time difference occurs when I define the Expression with h=h1 or h=h2. But as I directly define the Expression with a number, or define h1 and h2 as Expresseions, this difference disappears:

mesh1 cells:8000
mesh2 cells:8000
assign time for fenics built-in mesh:0.001077723000000086
assign time for gmsh:0.0010484170000000237

What can I do to speed up the code to normal levels with the remaining of the interpolation of an Expression containing another Function?

Could you attach your Gmsh script (or preferably the corresponding msh file)?

Hi, I don’t know how to attach a file here, can I send an e-mail to you?

If it is the msh file, simply copy paste its content in a post here encapsulated by ```

The original msh text is too long to upload. So I have changed the scale of the gmsh:

\$MeshFormat
4.1 0 8
\$EndMeshFormat
\$Entities
4 4 1 0
1 0 0 0 0
2 49.98442826423031 1.24777045084967 0 0
3 0 -1 0 0
4 49.98442826423031 0.2477704508496696 0 0
1 -1.000000011686097e-07 -9.999999994736442e-08 -1e-07 49.98442836423032 1.24777055084967 1e-07 0 2 1 -2
2 -1e-07 -1.0000001 -1e-07 1e-07 9.999999994736442e-08 1e-07 0 2 1 -3
3 49.98442816423031 0.2477703508496696 -1e-07 49.98442836423031 1.24777055084967 1e-07 0 2 2 -4
4 -1.000000011686097e-07 -1.0000001 -1e-07 49.98442836423032 0.2477705508496698 1e-07 0 2 3 -4
1 -1.000000011686097e-07 -1.0000001 -1e-07 49.98442836423032 1.24777055084967 1e-07 0 4 2 4 -3 -1
\$EndEntities
\$Nodes
9 306 1 306
0 1 0 1
1
0 0 0
0 2 0 1
2
49.98442826423031 1.24777045084967 0
0 3 0 1
3
0 -1 0
0 4 0 1
4
49.98442826423031 0.2477704508496696 0
1 1 0 4
5
6
7
8
9.996885652846064 0.249554090169934 0
19.99377130569213 0.4991081803398679 0
29.99065695853819 0.7486622705098019 0
39.98754261138426 0.9982163606797358 0
1 2 0 49
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0 -0.02 0
0 -0.04 0
0 -0.06 0
0 -0.08 0
0 -0.1 0
0 -0.12 0
0 -0.14 0
0 -0.16 0
0 -0.18 0
0 -0.2 0
0 -0.22 0
0 -0.24 0
0 -0.26 0
0 -0.28 0
0 -0.3 0
0 -0.32 0
0 -0.34 0
0 -0.36 0
0 -0.38 0
0 -0.4 0
0 -0.42 0
0 -0.44 0
0 -0.46 0
0 -0.48 0
0 -0.5 0
0 -0.52 0
0 -0.54 0
0 -0.5600000000000001 0
0 -0.58 0
0 -0.6 0
0 -0.62 0
0 -0.64 0
0 -0.66 0
0 -0.68 0
0 -0.7 0
0 -0.72 0
0 -0.74 0
0 -0.76 0
0 -0.78 0
0 -0.8 0
0 -0.82 0
0 -0.84 0
0 -0.86 0
0 -0.88 0
0 -0.9 0
0 -0.92 0
0 -0.9399999999999999 0
0 -0.96 0
0 -0.98 0
1 3 0 49
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
49.98442826423031 1.22777045084967 0
49.98442826423031 1.20777045084967 0
49.98442826423031 1.18777045084967 0
49.98442826423031 1.16777045084967 0
49.98442826423031 1.14777045084967 0
49.98442826423031 1.12777045084967 0
49.98442826423031 1.10777045084967 0
49.98442826423031 1.08777045084967 0
49.98442826423031 1.06777045084967 0
49.98442826423031 1.04777045084967 0
49.98442826423031 1.02777045084967 0
49.98442826423031 1.00777045084967 0
49.98442826423031 0.9877704508496696 0
49.98442826423031 0.9677704508496696 0
49.98442826423031 0.9477704508496696 0
49.98442826423031 0.9277704508496696 0
49.98442826423031 0.9077704508496696 0
49.98442826423031 0.8877704508496697 0
49.98442826423031 0.8677704508496696 0
49.98442826423031 0.8477704508496696 0
49.98442826423031 0.8277704508496697 0
49.98442826423031 0.8077704508496697 0
49.98442826423031 0.7877704508496697 0
49.98442826423031 0.7677704508496697 0
49.98442826423031 0.7477704508496696 0
49.98442826423031 0.7277704508496696 0
49.98442826423031 0.7077704508496696 0
49.98442826423031 0.6877704508496696 0
49.98442826423031 0.6677704508496697 0
49.98442826423031 0.6477704508496697 0
49.98442826423031 0.6277704508496696 0
49.98442826423031 0.6077704508496696 0
49.98442826423031 0.5877704508496696 0
49.98442826423031 0.5677704508496696 0
49.98442826423031 0.5477704508496697 0
49.98442826423031 0.5277704508496697 0
49.98442826423031 0.5077704508496697 0
49.98442826423031 0.4877704508496696 0
49.98442826423031 0.4677704508496696 0
49.98442826423031 0.4477704508496696 0
49.98442826423031 0.4277704508496697 0
49.98442826423031 0.4077704508496697 0
49.98442826423031 0.3877704508496697 0
49.98442826423031 0.3677704508496696 0
49.98442826423031 0.3477704508496696 0
49.98442826423031 0.3277704508496696 0
49.98442826423031 0.3077704508496697 0
49.98442826423031 0.2877704508496697 0
49.98442826423031 0.2677704508496697 0
1 4 0 4
107
108
109
110
9.996885652846064 -0.750445909830066 0
19.99377130569213 -0.5008918196601321 0
29.99065695853819 -0.2513377294901981 0
39.98754261138426 -0.001783639320264152 0
2 1 0 196
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
9.996885652846064 0.229554090169934 0
9.996885652846064 0.209554090169934 0
9.996885652846064 0.189554090169934 0
9.996885652846064 0.1695540901699339 0
9.996885652846064 0.149554090169934 0
9.996885652846064 0.129554090169934 0
9.996885652846064 0.1095540901699339 0
9.996885652846064 0.08955409016993396 0
9.996885652846064 0.06955409016993397 0
9.996885652846064 0.04955409016993395 0
9.996885652846064 0.02955409016993396 0
9.996885652846064 0.009554090169933971 0
9.996885652846064 -0.01044590983006605 0
9.996885652846064 -0.03044590983006606 0
9.996885652846064 -0.05044590983006603 0
9.996885652846064 -0.07044590983006604 0
9.996885652846064 -0.09044590983006606 0
9.996885652846064 -0.110445909830066 0
9.996885652846064 -0.130445909830066 0
9.996885652846064 -0.1504459098300661 0
9.996885652846064 -0.170445909830066 0
9.996885652846064 -0.190445909830066 0
9.996885652846064 -0.2104459098300661 0
9.996885652846064 -0.230445909830066 0
9.996885652846064 -0.250445909830066 0
9.996885652846064 -0.2704459098300661 0
9.996885652846064 -0.2904459098300661 0
9.996885652846064 -0.3104459098300661 0
9.996885652846064 -0.330445909830066 0
9.996885652846064 -0.350445909830066 0
9.996885652846064 -0.370445909830066 0
9.996885652846064 -0.3904459098300661 0
9.996885652846064 -0.4104459098300661 0
9.996885652846064 -0.4304459098300661 0
9.996885652846064 -0.450445909830066 0
9.996885652846064 -0.470445909830066 0
9.996885652846064 -0.490445909830066 0
9.996885652846064 -0.510445909830066 0
9.996885652846064 -0.530445909830066 0
9.996885652846064 -0.550445909830066 0
9.996885652846064 -0.570445909830066 0
9.996885652846064 -0.5904459098300661 0
9.996885652846064 -0.6104459098300661 0
9.996885652846064 -0.6304459098300661 0
9.996885652846064 -0.6504459098300661 0
9.996885652846064 -0.6704459098300661 0
9.996885652846064 -0.6904459098300659 0
9.996885652846064 -0.7104459098300659 0
9.996885652846064 -0.730445909830066 0
19.99377130569213 0.4791081803398679 0
19.99377130569213 0.4591081803398679 0
19.99377130569213 0.4391081803398679 0
19.99377130569213 0.4191081803398679 0
19.99377130569213 0.3991081803398679 0
19.99377130569213 0.3791081803398679 0
19.99377130569213 0.3591081803398679 0
19.99377130569213 0.3391081803398679 0
19.99377130569213 0.3191081803398679 0
19.99377130569213 0.2991081803398679 0
19.99377130569213 0.279108180339868 0
19.99377130569213 0.2591081803398679 0
19.99377130569213 0.2391081803398679 0
19.99377130569213 0.2191081803398679 0
19.99377130569213 0.1991081803398679 0
19.99377130569213 0.1791081803398679 0
19.99377130569213 0.1591081803398679 0
19.99377130569213 0.1391081803398679 0
19.99377130569213 0.1191081803398679 0
19.99377130569213 0.0991081803398679 0
19.99377130569213 0.07910818033986794 0
19.99377130569213 0.05910818033986792 0
19.99377130569213 0.0391081803398679 0
19.99377130569213 0.01910818033986794 0
19.99377130569213 -0.000891819660132076 0
19.99377130569213 -0.02089181966013209 0
19.99377130569213 -0.04089181966013211 0
19.99377130569213 -0.06089181966013213 0
19.99377130569213 -0.08089181966013204 0
19.99377130569213 -0.1008918196601321 0
19.99377130569213 -0.1208918196601321 0
19.99377130569213 -0.1408918196601321 0
19.99377130569213 -0.1608918196601321 0
19.99377130569213 -0.1808918196601321 0
19.99377130569213 -0.200891819660132 0
19.99377130569213 -0.220891819660132 0
19.99377130569213 -0.2408918196601321 0
19.99377130569213 -0.2608918196601321 0
19.99377130569213 -0.2808918196601321 0
19.99377130569213 -0.3008918196601321 0
19.99377130569213 -0.320891819660132 0
19.99377130569213 -0.340891819660132 0
19.99377130569213 -0.3608918196601321 0
19.99377130569213 -0.3808918196601321 0
19.99377130569213 -0.4008918196601321 0
19.99377130569213 -0.4208918196601321 0
19.99377130569213 -0.440891819660132 0
19.99377130569213 -0.460891819660132 0
19.99377130569213 -0.4808918196601321 0
29.99065695853819 0.7286622705098019 0
29.99065695853819 0.7086622705098019 0
29.99065695853819 0.688662270509802 0
29.99065695853819 0.668662270509802 0
29.99065695853819 0.648662270509802 0
29.99065695853819 0.6286622705098019 0
29.99065695853819 0.6086622705098019 0
29.99065695853819 0.5886622705098019 0
29.99065695853819 0.5686622705098019 0
29.99065695853819 0.5486622705098019 0
29.99065695853819 0.528662270509802 0
29.99065695853819 0.508662270509802 0
29.99065695853819 0.4886622705098019 0
29.99065695853819 0.4686622705098019 0
29.99065695853819 0.448662270509802 0
29.99065695853819 0.4286622705098019 0
29.99065695853819 0.4086622705098019 0
29.99065695853819 0.388662270509802 0
29.99065695853819 0.3686622705098019 0
29.99065695853819 0.3486622705098019 0
29.99065695853819 0.328662270509802 0
29.99065695853819 0.3086622705098019 0
29.99065695853819 0.2886622705098019 0
29.99065695853819 0.268662270509802 0
29.99065695853819 0.2486622705098019 0
29.99065695853819 0.2286622705098019 0
29.99065695853819 0.2086622705098019 0
29.99065695853819 0.1886622705098019 0
29.99065695853819 0.168662270509802 0
29.99065695853819 0.148662270509802 0
29.99065695853819 0.1286622705098019 0
29.99065695853819 0.1086622705098019 0
29.99065695853819 0.08866227050980191 0
29.99065695853819 0.06866227050980189 0
29.99065695853819 0.04866227050980199 0
29.99065695853819 0.02866227050980197 0
29.99065695853819 0.00866227050980195 0
29.99065695853819 -0.01133772949019807 0
29.99065695853819 -0.03133772949019809 0
29.99065695853819 -0.0513377294901981 0
29.99065695853819 -0.07133772949019801 0
29.99065695853819 -0.09133772949019803 0
29.99065695853819 -0.111337729490198 0
29.99065695853819 -0.1313377294901981 0
29.99065695853819 -0.1513377294901981 0
29.99065695853819 -0.1713377294901981 0
29.99065695853819 -0.191337729490198 0
29.99065695853819 -0.211337729490198 0
29.99065695853819 -0.231337729490198 0
39.98754261138426 0.9782163606797358 0
39.98754261138426 0.9582163606797358 0
39.98754261138426 0.9382163606797358 0
39.98754261138426 0.9182163606797359 0
39.98754261138426 0.8982163606797359 0
39.98754261138426 0.8782163606797359 0
39.98754261138426 0.8582163606797358 0
39.98754261138426 0.8382163606797358 0
39.98754261138426 0.8182163606797359 0
39.98754261138426 0.7982163606797359 0
39.98754261138426 0.7782163606797359 0
39.98754261138426 0.7582163606797359 0
39.98754261138426 0.7382163606797358 0
39.98754261138426 0.7182163606797358 0
39.98754261138426 0.6982163606797358 0
39.98754261138426 0.6782163606797358 0
39.98754261138426 0.6582163606797358 0
39.98754261138426 0.6382163606797359 0
39.98754261138426 0.6182163606797358 0
39.98754261138426 0.5982163606797358 0
39.98754261138426 0.5782163606797359 0
39.98754261138426 0.5582163606797359 0
39.98754261138426 0.5382163606797359 0
39.98754261138426 0.5182163606797359 0
39.98754261138426 0.4982163606797358 0
39.98754261138426 0.4782163606797358 0
39.98754261138426 0.4582163606797358 0
39.98754261138426 0.4382163606797358 0
39.98754261138426 0.4182163606797359 0
39.98754261138426 0.3982163606797359 0
39.98754261138426 0.3782163606797359 0
39.98754261138426 0.3582163606797358 0
39.98754261138426 0.3382163606797358 0
39.98754261138426 0.3182163606797358 0
39.98754261138426 0.2982163606797359 0
39.98754261138426 0.2782163606797359 0
39.98754261138426 0.2582163606797359 0
39.98754261138426 0.2382163606797358 0
39.98754261138426 0.2182163606797358 0
39.98754261138426 0.1982163606797358 0
39.98754261138426 0.1782163606797359 0
39.98754261138426 0.1582163606797359 0
39.98754261138426 0.1382163606797359 0
39.98754261138426 0.1182163606797358 0
39.98754261138426 0.09821636067973583 0
39.98754261138426 0.07821636067973581 0
39.98754261138426 0.0582163606797359 0
39.98754261138426 0.03821636067973588 0
39.98754261138426 0.01821636067973587 0
\$EndNodes
\$Elements
9 614 1 614
0 1 15 1
1 1
0 2 15 1
2 2
0 3 15 1
3 3
0 4 15 1
4 4
1 1 1 5
5 1 5
6 5 6
7 6 7
8 7 8
9 8 2
1 2 1 50
10 1 9
11 9 10
12 10 11
13 11 12
14 12 13
15 13 14
16 14 15
17 15 16
18 16 17
19 17 18
20 18 19
21 19 20
22 20 21
23 21 22
24 22 23
25 23 24
26 24 25
27 25 26
28 26 27
29 27 28
30 28 29
31 29 30
32 30 31
33 31 32
34 32 33
35 33 34
36 34 35
37 35 36
38 36 37
39 37 38
40 38 39
41 39 40
42 40 41
43 41 42
44 42 43
45 43 44
46 44 45
47 45 46
48 46 47
49 47 48
50 48 49
51 49 50
52 50 51
53 51 52
54 52 53
55 53 54
56 54 55
57 55 56
58 56 57
59 57 3
1 3 1 50
60 2 58
61 58 59
62 59 60
63 60 61
64 61 62
65 62 63
66 63 64
67 64 65
68 65 66
69 66 67
70 67 68
71 68 69
72 69 70
73 70 71
74 71 72
75 72 73
76 73 74
77 74 75
78 75 76
79 76 77
80 77 78
81 78 79
82 79 80
83 80 81
84 81 82
85 82 83
86 83 84
87 84 85
88 85 86
89 86 87
90 87 88
91 88 89
92 89 90
93 90 91
94 91 92
95 92 93
96 93 94
97 94 95
98 95 96
99 96 97
100 97 98
101 98 99
102 99 100
103 100 101
104 101 102
105 102 103
106 103 104
107 104 105
108 105 106
109 106 4
1 4 1 5
110 3 107
111 107 108
112 108 109
113 109 110
114 110 4
2 1 2 500
115 1 111 5
116 1 9 111
117 9 112 111
118 9 10 112
119 10 113 112
120 10 11 113
121 11 114 113
122 11 12 114
123 12 115 114
124 12 13 115
125 13 116 115
126 13 14 116
127 14 117 116
128 14 15 117
129 15 118 117
130 15 16 118
131 16 119 118
132 16 17 119
133 17 120 119
134 17 18 120
135 18 121 120
136 18 19 121
137 19 122 121
138 19 20 122
139 20 123 122
140 20 21 123
141 21 124 123
142 21 22 124
143 22 125 124
144 22 23 125
145 23 126 125
146 23 24 126
147 24 127 126
148 24 25 127
149 25 128 127
150 25 26 128
151 26 129 128
152 26 27 129
153 27 130 129
154 27 28 130
155 28 131 130
156 28 29 131
157 29 132 131
158 29 30 132
159 30 133 132
160 30 31 133
161 31 134 133
162 31 32 134
163 32 135 134
164 32 33 135
165 33 136 135
166 33 34 136
167 34 137 136
168 34 35 137
169 35 138 137
170 35 36 138
171 36 139 138
172 36 37 139
173 37 140 139
174 37 38 140
175 38 141 140
176 38 39 141
177 39 142 141
178 39 40 142
179 40 143 142
180 40 41 143
181 41 144 143
182 41 42 144
183 42 145 144
184 42 43 145
185 43 146 145
186 43 44 146
187 44 147 146
188 44 45 147
189 45 148 147
190 45 46 148
191 46 149 148
192 46 47 149
193 47 150 149
194 47 48 150
195 48 151 150
196 48 49 151
197 49 152 151
198 49 50 152
199 50 153 152
200 50 51 153
201 51 154 153
202 51 52 154
203 52 155 154
204 52 53 155
205 53 156 155
206 53 54 156
207 54 157 156
208 54 55 157
209 55 158 157
210 55 56 158
211 56 159 158
212 56 57 159
213 57 107 159
214 57 3 107
215 5 160 6
216 5 111 160
217 111 161 160
218 111 112 161
219 112 162 161
220 112 113 162
221 113 163 162
222 113 114 163
223 114 164 163
224 114 115 164
225 115 165 164
226 115 116 165
227 116 166 165
228 116 117 166
229 117 167 166
230 117 118 167
231 118 168 167
232 118 119 168
233 119 169 168
234 119 120 169
235 120 170 169
236 120 121 170
237 121 171 170
238 121 122 171
239 122 172 171
240 122 123 172
241 123 173 172
242 123 124 173
243 124 174 173
244 124 125 174
245 125 175 174
246 125 126 175
247 126 176 175
248 126 127 176
249 127 177 176
250 127 128 177
251 128 178 177
252 128 129 178
253 129 179 178
254 129 130 179
255 130 180 179
256 130 131 180
257 131 181 180
258 131 132 181
259 132 182 181
260 132 133 182
261 133 183 182
262 133 134 183
263 134 184 183
264 134 135 184
265 135 185 184
266 135 136 185
267 136 186 185
268 136 137 186
269 137 187 186
270 137 138 187
271 138 188 187
272 138 139 188
273 139 189 188
274 139 140 189
275 140 190 189
276 140 141 190
277 141 191 190
278 141 142 191
279 142 192 191
280 142 143 192
281 143 193 192
282 143 144 193
283 144 194 193
284 144 145 194
285 145 195 194
286 145 146 195
287 146 196 195
288 146 147 196
289 147 197 196
290 147 148 197
291 148 198 197
292 148 149 198
293 149 199 198
294 149 150 199
295 150 200 199
296 150 151 200
297 151 201 200
298 151 152 201
299 152 202 201
300 152 153 202
301 153 203 202
302 153 154 203
303 154 204 203
304 154 155 204
305 155 205 204
306 155 156 205
307 156 206 205
308 156 157 206
309 157 207 206
310 157 158 207
311 158 208 207
312 158 159 208
313 159 108 208
314 159 107 108
315 6 209 7
316 6 160 209
317 160 210 209
318 160 161 210
319 161 211 210
320 161 162 211
321 162 212 211
322 162 163 212
323 163 213 212
324 163 164 213
325 164 214 213
326 164 165 214
327 165 215 214
328 165 166 215
329 166 216 215
330 166 167 216
331 167 217 216
332 167 168 217
333 168 218 217
334 168 169 218
335 169 219 218
336 169 170 219
337 170 220 219
338 170 171 220
339 171 221 220
340 171 172 221
341 172 222 221
342 172 173 222
343 173 223 222
344 173 174 223
345 174 224 223
346 174 175 224
347 175 225 224
348 175 176 225
349 176 226 225
350 176 177 226
351 177 227 226
352 177 178 227
353 178 228 227
354 178 179 228
355 179 229 228
356 179 180 229
357 180 230 229
358 180 181 230
359 181 231 230
360 181 182 231
361 182 232 231
362 182 183 232
363 183 233 232
364 183 184 233
365 184 234 233
366 184 185 234
367 185 235 234
368 185 186 235
369 186 236 235
370 186 187 236
371 187 237 236
372 187 188 237
373 188 238 237
374 188 189 238
375 189 239 238
376 189 190 239
377 190 240 239
378 190 191 240
379 191 241 240
380 191 192 241
381 192 242 241
382 192 193 242
383 193 243 242
384 193 194 243
385 194 244 243
386 194 195 244
387 195 245 244
388 195 196 245
389 196 246 245
390 196 197 246
391 197 247 246
392 197 198 247
393 198 248 247
394 198 199 248
395 199 249 248
396 199 200 249
397 200 250 249
398 200 201 250
399 201 251 250
400 201 202 251
401 202 252 251
402 202 203 252
403 203 253 252
404 203 204 253
405 204 254 253
406 204 205 254
407 205 255 254
408 205 206 255
409 206 256 255
410 206 207 256
411 207 257 256
412 207 208 257
413 208 109 257
414 208 108 109
415 7 258 8
416 7 209 258
417 209 259 258
418 209 210 259
419 210 260 259
420 210 211 260
421 211 261 260
422 211 212 261
423 212 262 261
424 212 213 262
425 213 263 262
426 213 214 263
427 214 264 263
428 214 215 264
429 215 265 264
430 215 216 265
431 216 266 265
432 216 217 266
433 217 267 266
434 217 218 267
435 218 268 267
436 218 219 268
437 219 269 268
438 219 220 269
439 220 270 269
440 220 221 270
441 221 271 270
442 221 222 271
443 222 272 271
444 222 223 272
445 223 273 272
446 223 224 273
447 224 274 273
448 224 225 274
449 225 275 274
450 225 226 275
451 226 276 275
452 226 227 276
453 227 277 276
454 227 228 277
455 228 278 277
456 228 229 278
457 229 279 278
458 229 230 279
459 230 280 279
460 230 231 280
461 231 281 280
462 231 232 281
463 232 282 281
464 232 233 282
465 233 283 282
466 233 234 283
467 234 284 283
468 234 235 284
469 235 285 284
470 235 236 285
471 236 286 285
472 236 237 286
473 237 287 286
474 237 238 287
475 238 288 287
476 238 239 288
477 239 289 288
478 239 240 289
479 240 290 289
480 240 241 290
481 241 291 290
482 241 242 291
483 242 292 291
484 242 243 292
485 243 293 292
486 243 244 293
487 244 294 293
488 244 245 294
489 245 295 294
490 245 246 295
491 246 296 295
492 246 247 296
493 247 297 296
494 247 248 297
495 248 298 297
496 248 249 298
497 249 299 298
498 249 250 299
499 250 300 299
500 250 251 300
501 251 301 300
502 251 252 301
503 252 302 301
504 252 253 302
505 253 303 302
506 253 254 303
507 254 304 303
508 254 255 304
509 255 305 304
510 255 256 305
511 256 306 305
512 256 257 306
513 257 110 306
514 257 109 110
515 8 58 2
516 8 258 58
517 258 59 58
518 258 259 59
519 259 60 59
520 259 260 60
521 260 61 60
522 260 261 61
523 261 62 61
524 261 262 62
525 262 63 62
526 262 263 63
527 263 64 63
528 263 264 64
529 264 65 64
530 264 265 65
531 265 66 65
532 265 266 66
533 266 67 66
534 266 267 67
535 267 68 67
536 267 268 68
537 268 69 68
538 268 269 69
539 269 70 69
540 269 270 70
541 270 71 70
542 270 271 71
543 271 72 71
544 271 272 72
545 272 73 72
546 272 273 73
547 273 74 73
548 273 274 74
549 274 75 74
550 274 275 75
551 275 76 75
552 275 276 76
553 276 77 76
554 276 277 77
555 277 78 77
556 277 278 78
557 278 79 78
558 278 279 79
559 279 80 79
560 279 280 80
561 280 81 80
562 280 281 81
563 281 82 81
564 281 282 82
565 282 83 82
566 282 283 83
567 283 84 83
568 283 284 84
569 284 85 84
570 284 285 85
571 285 86 85
572 285 286 86
573 286 87 86
574 286 287 87
575 287 88 87
576 287 288 88
577 288 89 88
578 288 289 89
579 289 90 89
580 289 290 90
581 290 91 90
582 290 291 91
583 291 92 91
584 291 292 92
585 292 93 92
586 292 293 93
587 293 94 93
588 293 294 94
589 294 95 94
590 294 295 95
591 295 96 95
592 295 296 96
593 296 97 96
594 296 297 97
595 297 98 97
596 297 298 98
597 298 99 98
598 298 299 99
599 299 100 99
600 299 300 100
601 300 101 100
602 300 301 101
603 301 102 101
604 301 302 102
605 302 103 102
606 302 303 103
607 303 104 103
608 303 304 104
609 304 105 104
610 304 305 105
611 305 106 105
612 305 306 106
613 306 4 106
614 306 110 4
\$EndElements

and the corresponding built-in mesh becomes:

mesh1=RectangleMesh(
Point(0,-1),Point(50,0),
5,50)
mesh1.rotate(1.43,2,Point(0,0))

It would be best if you could try to make the problem as simple as possible. Using your msh file, I’ve made simple timings for the gmsh mesh and the built in mesh, and you observe that they have quite a variability:

mesh_name = "rect_mesh"

# import meshio
# import numpy
# def create_mesh(mesh, cell_type, prune_z=False):
#     cells = mesh.get_cells_type(cell_type)
#     out_mesh = meshio.Mesh(points=mesh.points, cells={cell_type: cells})
#     if prune_z:
#         out_mesh.prune_z_0()
#     return out_mesh

# msh = meshio.read(mesh_name + ".msh")
# meshio_mesh = create_mesh(msh, "triangle", prune_z=True)
# meshio.write(mesh_name + ".xdmf", meshio_mesh)

from dolfin import *

#generate mesh1 and mesh2
mesh1=RectangleMesh(Point(0,-1),Point(50,0), 5,50)
mesh1.rotate(1.43,2,Point(0,0))
print('mesh1 cells:'+str(mesh1.num_cells()))

mesh2=Mesh()
with XDMFFile(mesh_name + ".xdmf") as infile:
print('mesh2 cells:'+str(mesh2.num_cells()))

#define FunctionSpace and Functions
V1 = FunctionSpace(mesh1,'CG',1)
V2 = FunctionSpace(mesh2,'CG',1)

expr = Expression("-1", degree=1)

# Timing for simple expression
for i in range(10):
with Timer("Gmsh mesh") as t:
h1 = interpolate(expr, V2)
with Timer("Built-in mesh") as t:
h2 = interpolate(expr,V1)

built_in_timing = timing("Built-in mesh", TimingClear.clear)[1]
external_timing = timing("Gmsh mesh", TimingClear.clear)[1]
print("Built-in {0:.2e}, Gmsh {1:.2e}, Built-in/Gmsh {2:.2f}".format(built_in_timing, external_timing, built_in_timing/external_timing))
print("----")
Built-in 1.12e-04, Gmsh 3.36e-04, Built-in/Gmsh 0.33
----
Built-in 1.35e-04, Gmsh 1.81e-04, Built-in/Gmsh 0.75
----
Built-in 9.60e-05, Gmsh 1.44e-04, Built-in/Gmsh 0.67
----
Built-in 1.10e-04, Gmsh 1.35e-04, Built-in/Gmsh 0.82
----
Built-in 1.23e-04, Gmsh 1.15e-04, Built-in/Gmsh 1.07
----
Built-in 1.23e-04, Gmsh 1.56e-04, Built-in/Gmsh 0.79
----
Built-in 1.21e-04, Gmsh 2.05e-04, Built-in/Gmsh 0.59
----
Built-in 1.10e-04, Gmsh 1.72e-04, Built-in/Gmsh 0.64
----
Built-in 9.33e-05, Gmsh 1.50e-04, Built-in/Gmsh 0.62
----
Built-in 9.51e-05, Gmsh 1.43e-04, Built-in/Gmsh 0.66
----

With your current problems, and relatively small meshes, it might be that data locality is affecting the timings.

I would suggest trying to use my code above with a bigger mesh (as 8000 cells is quite a small mesh), and see how the timings are affected.

1 Like