Coreform-Cubit-Mesh-Export 1.3__py3-none-any.whl → 1.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of Coreform-Cubit-Mesh-Export might be problematic. Click here for more details.
- coreform_cubit_mesh_export-1.4.1.dist-info/METADATA +124 -0
- coreform_cubit_mesh_export-1.4.1.dist-info/RECORD +10 -0
- coreform_cubit_mesh_export-1.4.1.dist-info/licenses/LICENSE +504 -0
- cubit_mesh_export.py +632 -558
- coreform_cubit_mesh_export-1.3.dist-info/METADATA +0 -156
- coreform_cubit_mesh_export-1.3.dist-info/RECORD +0 -9
- {coreform_cubit_mesh_export-1.3.dist-info → coreform_cubit_mesh_export-1.4.1.dist-info}/WHEEL +0 -0
- {coreform_cubit_mesh_export-1.3.dist-info → coreform_cubit_mesh_export-1.4.1.dist-info}/top_level.txt +0 -0
cubit_mesh_export.py
CHANGED
|
@@ -1,558 +1,632 @@
|
|
|
1
|
-
########################################################################
|
|
2
|
-
### Gmsh format version 2
|
|
3
|
-
########################################################################
|
|
4
|
-
|
|
5
|
-
def export_Gmsh_ver2(cubit, FileName):
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fid.write(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
fid.write(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
tet_list
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if len(node_list)==
|
|
129
|
-
fid.write(f'{element_id} {
|
|
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
|
-
fid.write("
|
|
235
|
-
fid.write(
|
|
236
|
-
fid.write("
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
for
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
fid.write(f
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
fid.write('
|
|
528
|
-
|
|
529
|
-
fid.write('
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
1
|
+
########################################################################
|
|
2
|
+
### Gmsh format version 2
|
|
3
|
+
########################################################################
|
|
4
|
+
|
|
5
|
+
def export_Gmsh_ver2(cubit, FileName: str):
|
|
6
|
+
"""Export mesh to Gmsh format version 2.2.
|
|
7
|
+
|
|
8
|
+
Exports 1D, 2D, and 3D mesh elements from Cubit to Gmsh v2.2 format.
|
|
9
|
+
Supports both first-order and second-order elements.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
cubit: Cubit Python interface object
|
|
13
|
+
FileName: Output file path for the .msh file
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
cubit: The cubit object (for method chaining)
|
|
17
|
+
|
|
18
|
+
Supported elements:
|
|
19
|
+
- 1st order: Point, Line, Triangle, Quad, Tetrahedron, Hexahedron, Wedge, Pyramid
|
|
20
|
+
- 2nd order: Line3, Triangle6, Quad8/9, Tetrahedron10/11, Hexahedron20, Wedge15, Pyramid13
|
|
21
|
+
"""
|
|
22
|
+
with open(FileName, 'w') as fid:
|
|
23
|
+
|
|
24
|
+
fid.write("$MeshFormat\n")
|
|
25
|
+
fid.write("2.2 0 8\n")
|
|
26
|
+
fid.write("$EndMeshFormat\n")
|
|
27
|
+
|
|
28
|
+
fid.write("$PhysicalNames\n")
|
|
29
|
+
fid.write(f'{cubit.get_block_count()}\n')
|
|
30
|
+
for block_id in cubit.get_block_id_list():
|
|
31
|
+
name = cubit.get_exodus_entity_name("block", block_id)
|
|
32
|
+
if len(cubit.get_block_nodes(block_id)) > 0:
|
|
33
|
+
fid.write(f'0 {block_id} "{name}"\n')
|
|
34
|
+
elif len(cubit.get_block_edges(block_id)) > 0:
|
|
35
|
+
fid.write(f'1 {block_id} "{name}"\n')
|
|
36
|
+
elif len(cubit.get_block_tris(block_id)) + len(cubit.get_block_faces(block_id)) > 0:
|
|
37
|
+
fid.write(f'2 {block_id} "{name}"\n')
|
|
38
|
+
else:
|
|
39
|
+
fid.write(f'3 {block_id} "{name}"\n')
|
|
40
|
+
fid.write('$EndPhysicalNames\n')
|
|
41
|
+
|
|
42
|
+
fid.write("$Nodes\n")
|
|
43
|
+
node_list = set()
|
|
44
|
+
for block_id in cubit.get_block_id_list():
|
|
45
|
+
elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face", "edge", "node"]
|
|
46
|
+
for elem_type in elem_types:
|
|
47
|
+
if elem_type == "hex":
|
|
48
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
49
|
+
else:
|
|
50
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
51
|
+
for element_id in func(block_id):
|
|
52
|
+
node_ids = cubit.get_expanded_connectivity(elem_type, element_id)
|
|
53
|
+
node_list.update(node_ids)
|
|
54
|
+
|
|
55
|
+
fid.write(f'{len(node_list)}\n')
|
|
56
|
+
for node_id in node_list:
|
|
57
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
58
|
+
fid.write(f'{node_id} {coord[0]} {coord[1]} {coord[2]}\n')
|
|
59
|
+
fid.write('$EndNodes\n')
|
|
60
|
+
|
|
61
|
+
hex_list = set()
|
|
62
|
+
tet_list = set()
|
|
63
|
+
wedge_list = set()
|
|
64
|
+
pyramid_list = set()
|
|
65
|
+
tri_list = set()
|
|
66
|
+
quad_list = set()
|
|
67
|
+
edge_list = set()
|
|
68
|
+
node_list = set()
|
|
69
|
+
|
|
70
|
+
for block_id in cubit.get_block_id_list():
|
|
71
|
+
tet_list.update(cubit.get_block_tets(block_id))
|
|
72
|
+
hex_list.update(cubit.get_block_hexes(block_id))
|
|
73
|
+
wedge_list.update(cubit.get_block_wedges(block_id))
|
|
74
|
+
pyramid_list.update(cubit.get_block_pyramids(block_id))
|
|
75
|
+
tri_list.update(cubit.get_block_tris(block_id))
|
|
76
|
+
quad_list.update(cubit.get_block_faces(block_id))
|
|
77
|
+
edge_list.update(cubit.get_block_edges(block_id))
|
|
78
|
+
node_list.update(cubit.get_block_nodes(block_id))
|
|
79
|
+
|
|
80
|
+
element_id = 0
|
|
81
|
+
fid.write('$Elements\n')
|
|
82
|
+
fid.write(f'{len(hex_list) + len(tet_list) + len(wedge_list) + len(pyramid_list) + len(tri_list) + len(quad_list) + len(edge_list) + len(node_list)}\n')
|
|
83
|
+
|
|
84
|
+
for block_id in cubit.get_block_id_list():
|
|
85
|
+
|
|
86
|
+
tet_list = cubit.get_block_tets(block_id)
|
|
87
|
+
for tet_id in tet_list:
|
|
88
|
+
element_id += 1
|
|
89
|
+
node_list = cubit.get_expanded_connectivity("tet", tet_id)
|
|
90
|
+
if len(node_list)==4:
|
|
91
|
+
fid.write(f'{element_id} { 4} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
92
|
+
elif len(node_list)==10:
|
|
93
|
+
fid.write(f'{element_id} {11} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]} {node_list[9]} {node_list[8]}\n')
|
|
94
|
+
elif len(node_list)==11:
|
|
95
|
+
fid.write(f'{element_id} {35} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]} {node_list[9]} {node_list[8]} {node_list[10]}\n')
|
|
96
|
+
|
|
97
|
+
hex_list = cubit.get_block_hexes(block_id)
|
|
98
|
+
for hex_id in hex_list:
|
|
99
|
+
element_id += 1
|
|
100
|
+
node_list = cubit.get_expanded_connectivity("hex", hex_id)
|
|
101
|
+
if len(node_list)==8:
|
|
102
|
+
fid.write(f'{element_id} { 5} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]}\n')
|
|
103
|
+
elif len(node_list)==20:
|
|
104
|
+
fid.write(f'{element_id} {17} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]} {node_list[8]} {node_list[11]} {node_list[12]} {node_list[9]} {node_list[13]} {node_list[10]} {node_list[14]} {node_list[15]} {node_list[16]} {node_list[19]} {node_list[17]} {node_list[18]}\n')
|
|
105
|
+
|
|
106
|
+
wedge_list = cubit.get_block_wedges(block_id)
|
|
107
|
+
for wedge_id in wedge_list:
|
|
108
|
+
element_id += 1
|
|
109
|
+
node_list = cubit.get_expanded_connectivity("wedge", wedge_id)
|
|
110
|
+
if len(node_list)==6:
|
|
111
|
+
fid.write(f'{element_id} { 6} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n')
|
|
112
|
+
elif len(node_list)==15:
|
|
113
|
+
fid.write(f'{element_id} {18} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[8]} {node_list[9]} {node_list[7]} {node_list[10]} {node_list[11]} {node_list[12]} {node_list[14]} {node_list[13]}\n')
|
|
114
|
+
|
|
115
|
+
pyramid_list = cubit.get_block_pyramids(block_id)
|
|
116
|
+
for pyramid_id in pyramid_list:
|
|
117
|
+
element_id += 1
|
|
118
|
+
node_list = cubit.get_expanded_connectivity("pyramid", pyramid_id)
|
|
119
|
+
if len(node_list)==5:
|
|
120
|
+
fid.write(f'{element_id} { 7} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]}\n')
|
|
121
|
+
elif len(node_list)==13:
|
|
122
|
+
fid.write(f'{element_id} {19} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[8]} {node_list[9]} {node_list[6]} {node_list[10]} {node_list[7]} {node_list[11]} {node_list[12]} \n')
|
|
123
|
+
|
|
124
|
+
tri_list = cubit.get_block_tris(block_id)
|
|
125
|
+
for tri_id in tri_list:
|
|
126
|
+
element_id += 1
|
|
127
|
+
node_list = cubit.get_expanded_connectivity("tri", tri_id)
|
|
128
|
+
if len(node_list)==3:
|
|
129
|
+
fid.write(f'{element_id} { 2} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
|
|
130
|
+
elif len(node_list)==6:
|
|
131
|
+
fid.write(f'{element_id} { 9} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n')
|
|
132
|
+
elif len(node_list)==7:
|
|
133
|
+
fid.write(f'{element_id} {42} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]}\n')
|
|
134
|
+
|
|
135
|
+
quad_list = cubit.get_block_faces(block_id)
|
|
136
|
+
for quad_id in quad_list:
|
|
137
|
+
element_id += 1
|
|
138
|
+
node_list = cubit.get_expanded_connectivity("quad", quad_id)
|
|
139
|
+
if len(node_list)==4:
|
|
140
|
+
fid.write(f'{element_id} { 3} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
141
|
+
elif len(node_list)==8:
|
|
142
|
+
fid.write(f'{element_id} {16} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]}\n')
|
|
143
|
+
elif len(node_list)==9:
|
|
144
|
+
fid.write(f'{element_id} {10} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]} {node_list[8]}\n')
|
|
145
|
+
|
|
146
|
+
edge_list = cubit.get_block_edges(block_id)
|
|
147
|
+
for edge_id in edge_list:
|
|
148
|
+
element_id += 1
|
|
149
|
+
node_list = cubit.get_expanded_connectivity("edge", edge_id)
|
|
150
|
+
if len(node_list)==2:
|
|
151
|
+
fid.write(f'{element_id} {1} {2} {block_id} {block_id} {node_list[0]} {node_list[1]}\n')
|
|
152
|
+
elif len(node_list)==3:
|
|
153
|
+
fid.write(f'{element_id} {8} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
|
|
154
|
+
|
|
155
|
+
node_list = cubit.get_block_nodes(block_id)
|
|
156
|
+
for node_id in node_list:
|
|
157
|
+
element_id += 1
|
|
158
|
+
fid.write(f'{element_id} {15} {2} {block_id} {block_id} {node_id}\n')
|
|
159
|
+
|
|
160
|
+
fid.write('$EndElements\n')
|
|
161
|
+
return cubit
|
|
162
|
+
|
|
163
|
+
########################################################################
|
|
164
|
+
### Nastran file
|
|
165
|
+
########################################################################
|
|
166
|
+
|
|
167
|
+
def export_Nastran(cubit, FileName: str, DIM: str = "3D", PYRAM: bool = True):
|
|
168
|
+
"""Export mesh to Nastran format.
|
|
169
|
+
|
|
170
|
+
Exports mesh elements from Cubit to NX Nastran bulk data format.
|
|
171
|
+
Supports 2D and 3D meshes with first-order elements only.
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
cubit: Cubit Python interface object
|
|
175
|
+
FileName: Output file path for the .nas or .bdf file
|
|
176
|
+
DIM: Dimension mode - "2D" for 2D meshes, "3D" for 3D meshes (default: "3D")
|
|
177
|
+
PYRAM: If True, export pyramids as CPYRAM; if False, convert to degenerate hex (default: True)
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
cubit: The cubit object (for method chaining)
|
|
181
|
+
|
|
182
|
+
Supported elements:
|
|
183
|
+
- 3D: CTETRA (tet4), CHEXA (hex8), CPENTA (wedge6), CPYRAM (pyramid5)
|
|
184
|
+
- 2D: CTRIA3 (tri3), CQUAD4 (quad4)
|
|
185
|
+
- 1D: CROD (edge/bar)
|
|
186
|
+
- 0D: CMASS (point mass)
|
|
187
|
+
|
|
188
|
+
Note:
|
|
189
|
+
Only first-order elements are supported. Second-order elements are not exported.
|
|
190
|
+
"""
|
|
191
|
+
import datetime
|
|
192
|
+
formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
|
|
193
|
+
with open(FileName,'w',encoding='UTF-8') as fid:
|
|
194
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
195
|
+
fid.write("$\n")
|
|
196
|
+
fid.write("$ CUBIT NX Nastran Translator\n")
|
|
197
|
+
fid.write("$\n")
|
|
198
|
+
fid.write(f"$ File: {FileName}\n")
|
|
199
|
+
fid.write(f"$ Time Stamp: {formatted_date_time}\n")
|
|
200
|
+
fid.write("$\n")
|
|
201
|
+
fid.write("$\n")
|
|
202
|
+
fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
|
|
203
|
+
fid.write("$\n")
|
|
204
|
+
fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
|
|
205
|
+
fid.write("$ The SID's for the load and restraint sets start at one and increment by one:i.e.,1,2,3,4...\n")
|
|
206
|
+
fid.write("$\n")
|
|
207
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
208
|
+
fid.write("$\n")
|
|
209
|
+
fid.write("$\n")
|
|
210
|
+
fid.write("$ -------------------------\n")
|
|
211
|
+
fid.write("$ Executive Control Section\n")
|
|
212
|
+
fid.write("$ -------------------------\n")
|
|
213
|
+
fid.write("$\n")
|
|
214
|
+
fid.write("SOL 101\n")
|
|
215
|
+
fid.write("CEND\n")
|
|
216
|
+
fid.write("$\n")
|
|
217
|
+
fid.write("$\n")
|
|
218
|
+
fid.write("$ --------------------\n")
|
|
219
|
+
fid.write("$ Case Control Section\n")
|
|
220
|
+
fid.write("$ --------------------\n")
|
|
221
|
+
fid.write("$\n")
|
|
222
|
+
fid.write("ECHO = SORT\n")
|
|
223
|
+
fid.write("$\n")
|
|
224
|
+
fid.write("$\n")
|
|
225
|
+
fid.write("$ Name: Initial\n")
|
|
226
|
+
fid.write("$\n")
|
|
227
|
+
fid.write("$\n")
|
|
228
|
+
fid.write("$ Name: Default Set\n")
|
|
229
|
+
fid.write("$\n")
|
|
230
|
+
fid.write("SUBCASE = 1\n")
|
|
231
|
+
fid.write("$\n")
|
|
232
|
+
fid.write("LABEL = Default Set\n")
|
|
233
|
+
fid.write("$\n")
|
|
234
|
+
fid.write("$ -----------------\n")
|
|
235
|
+
fid.write("$ Bulk Data Section\n")
|
|
236
|
+
fid.write("$ -----------------\n")
|
|
237
|
+
fid.write("$\n")
|
|
238
|
+
fid.write("BEGIN BULK\n")
|
|
239
|
+
fid.write("$\n")
|
|
240
|
+
fid.write("$ Params\n")
|
|
241
|
+
fid.write("$\n")
|
|
242
|
+
fid.write("$\n")
|
|
243
|
+
fid.write("$ Node cards\n")
|
|
244
|
+
fid.write("$\n")
|
|
245
|
+
|
|
246
|
+
node_list = set()
|
|
247
|
+
for block_id in cubit.get_block_id_list():
|
|
248
|
+
elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face", "edge", "node"]
|
|
249
|
+
for elem_type in elem_types:
|
|
250
|
+
if elem_type == "hex":
|
|
251
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
252
|
+
else:
|
|
253
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
254
|
+
for element_id in func(block_id):
|
|
255
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
256
|
+
node_list.update(node_ids)
|
|
257
|
+
for node_id in node_list:
|
|
258
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
259
|
+
if DIM == "3D":
|
|
260
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
|
|
261
|
+
else:
|
|
262
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {0}\n")
|
|
263
|
+
|
|
264
|
+
element_id = 0
|
|
265
|
+
fid.write("$\n")
|
|
266
|
+
fid.write("$ Element cards\n")
|
|
267
|
+
fid.write("$\n")
|
|
268
|
+
for block_id in cubit.get_block_id_list():
|
|
269
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
270
|
+
fid.write("$\n")
|
|
271
|
+
fid.write(f"$ Name: {name}\n")
|
|
272
|
+
fid.write("$\n")
|
|
273
|
+
tet_list = cubit.get_block_tets(block_id)
|
|
274
|
+
|
|
275
|
+
if DIM=="3D":
|
|
276
|
+
for tet_id in tet_list:
|
|
277
|
+
node_list = cubit.get_connectivity('tet',tet_id)
|
|
278
|
+
element_id += 1
|
|
279
|
+
fid.write(f"CTETRA {element_id:>8}{block_id:>8}{node_list[0]:>8}{node_list[1]:>8}{node_list[2]:>8}{node_list[3]:>8}\n")
|
|
280
|
+
hex_list = cubit.get_block_hexes(block_id)
|
|
281
|
+
for hex_id in hex_list:
|
|
282
|
+
node_list = cubit.get_connectivity('hex',hex_id)
|
|
283
|
+
element_id += 1
|
|
284
|
+
fid.write(f"CHEXA {element_id:>8}{block_id:>8}{node_list[0]:>8}{node_list[1]:>8}{node_list[2]:>8}{node_list[3]:>8}{node_list[4]:>8}{node_list[5]:>8}+\n+ {node_list[6]:>8}{node_list[7]:>8}\n")
|
|
285
|
+
wedge_list = cubit.get_block_wedges(block_id)
|
|
286
|
+
for wedge_id in wedge_list:
|
|
287
|
+
node_list = cubit.get_connectivity('wedge',wedge_id)
|
|
288
|
+
element_id += 1
|
|
289
|
+
fid.write(f"CPENTA {element_id:>8}{block_id:>8}{node_list[0]:>8}{node_list[1]:>8}{node_list[2]:>8}{node_list[3]:>8}{node_list[4]:>8}{node_list[5]:>8}\n")
|
|
290
|
+
pyramid_list = cubit.get_block_pyramids(block_id)
|
|
291
|
+
for pyramid_id in pyramid_list:
|
|
292
|
+
node_list = cubit.get_connectivity('pyramid',pyramid_id)
|
|
293
|
+
if PYRAM:
|
|
294
|
+
element_id += 1
|
|
295
|
+
fid.write(f"CPYRAM {element_id:>8}{block_id:>8}{node_list[0]:>8}{node_list[1]:>8}{node_list[2]:>8}{node_list[3]:>8}{node_list[4]:>8}\n")
|
|
296
|
+
else:
|
|
297
|
+
element_id += 1
|
|
298
|
+
fid.write(f"CHEXA {element_id:>8}{block_id:>8}{node_list[0]:>8}{node_list[1]:>8}{node_list[2]:>8}{node_list[3]:>8}{node_list[4]:>8}{node_list[4]:>8}+\n+ {node_list[4]:>8}{node_list[4]:>8}\n")
|
|
299
|
+
|
|
300
|
+
tri_list = cubit.get_block_tris(block_id)
|
|
301
|
+
for tri_id in tri_list:
|
|
302
|
+
node_list = cubit.get_connectivity('tri',tri_id)
|
|
303
|
+
element_id += 1
|
|
304
|
+
if DIM=="3D":
|
|
305
|
+
fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}\n")
|
|
306
|
+
else:
|
|
307
|
+
surface_id = int(cubit.get_geometry_owner("tri", tri_id).split()[1])
|
|
308
|
+
normal = cubit.get_surface_normal(surface_id)
|
|
309
|
+
if normal[2] > 0:
|
|
310
|
+
fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}\n")
|
|
311
|
+
else:
|
|
312
|
+
fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[2]:<8}{node_list[1]:<8}\n")
|
|
313
|
+
quad_list = cubit.get_block_faces(block_id)
|
|
314
|
+
for quad_id in quad_list:
|
|
315
|
+
node_list = cubit.get_connectivity('quad',quad_id)
|
|
316
|
+
element_id += 1
|
|
317
|
+
if DIM=="3D":
|
|
318
|
+
fid.write(f"CQUAD4 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}{node_list[3]:<8}\n")
|
|
319
|
+
else:
|
|
320
|
+
surface_id = int(cubit.get_geometry_owner("quad", quad_id).split()[1])
|
|
321
|
+
normal = cubit.get_surface_normal(surface_id)
|
|
322
|
+
node_list = cubit.get_connectivity('quad',quad_id)
|
|
323
|
+
if normal[2] > 0:
|
|
324
|
+
fid.write(f"CQUAD4 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}{node_list[3]:<8}\n")
|
|
325
|
+
else:
|
|
326
|
+
fid.write(f"CQUAD4 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[3]:<8}{node_list[2]:<8}{node_list[1]:<8}\n")
|
|
327
|
+
edge_list = cubit.get_block_edges(block_id)
|
|
328
|
+
for edge_id in edge_list:
|
|
329
|
+
element_id += 1
|
|
330
|
+
node_list = cubit.get_connectivity('edge', edge_id)
|
|
331
|
+
fid.write(f"CROD {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}\n")
|
|
332
|
+
node_list = cubit.get_block_nodes(block_id)
|
|
333
|
+
for node_id in node_list:
|
|
334
|
+
element_id += 1
|
|
335
|
+
fid.write(f"CMASS {element_id:<8}{block_id:<8}{node_id:<8}\n")
|
|
336
|
+
fid.write("$\n")
|
|
337
|
+
fid.write("$ Property cards\n")
|
|
338
|
+
fid.write("$\n")
|
|
339
|
+
|
|
340
|
+
for block_id in cubit.get_block_id_list():
|
|
341
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
342
|
+
fid.write("$\n")
|
|
343
|
+
fid.write(f"$ Name: {name}\n")
|
|
344
|
+
if len(cubit.get_block_nodes(block_id)) > 0:
|
|
345
|
+
fid.write(f"PMASS {block_id:< 8}{block_id:< 8}\n")
|
|
346
|
+
elif len(cubit.get_block_edges(block_id)) > 0:
|
|
347
|
+
fid.write(f"PROD {block_id:< 8}{block_id:< 8}\n")
|
|
348
|
+
elif len(cubit.get_block_tris(block_id)) + len(cubit.get_block_faces(block_id)) > 0:
|
|
349
|
+
fid.write(f"PSHELL {block_id:< 8}{block_id:< 8}\n")
|
|
350
|
+
else:
|
|
351
|
+
fid.write(f"PSOLID {block_id:< 8}{block_id:< 8}\n")
|
|
352
|
+
fid.write("$\n")
|
|
353
|
+
|
|
354
|
+
fid.write("ENDDATA\n")
|
|
355
|
+
return cubit
|
|
356
|
+
|
|
357
|
+
########################################################################
|
|
358
|
+
### ELF meg file
|
|
359
|
+
########################################################################
|
|
360
|
+
|
|
361
|
+
def export_meg(cubit, FileName: str, DIM: str = 'T', MGR2=None):
|
|
362
|
+
"""Export mesh to ELF/MESH MEG format.
|
|
363
|
+
|
|
364
|
+
Exports mesh elements from Cubit to ELF/MAGIC MEG format for finite element analysis.
|
|
365
|
+
|
|
366
|
+
Args:
|
|
367
|
+
cubit: Cubit Python interface object
|
|
368
|
+
FileName: Output file path for the .meg file
|
|
369
|
+
DIM: Dimension mode - 'T' for 3D, 'R' for axisymmetric, 'K' for 2D (default: 'T')
|
|
370
|
+
MGR2: Optional list of spatial nodes [[x1,y1,z1], [x2,y2,z2], ...] (default: None)
|
|
371
|
+
|
|
372
|
+
Returns:
|
|
373
|
+
cubit: The cubit object (for method chaining)
|
|
374
|
+
|
|
375
|
+
Supported elements:
|
|
376
|
+
- 3D: Tetrahedron, Hexahedron, Wedge, Pyramid
|
|
377
|
+
- 2D: Triangle, Quadrilateral
|
|
378
|
+
- 1D: Edge
|
|
379
|
+
- 0D: Node
|
|
380
|
+
"""
|
|
381
|
+
if MGR2 is None:
|
|
382
|
+
MGR2 = []
|
|
383
|
+
|
|
384
|
+
with open(FileName,'w',encoding='UTF-8') as fid:
|
|
385
|
+
fid.write("BOOK MEP 3.50\n")
|
|
386
|
+
fid.write("* ELF/MESH VERSION 7.3.0\n")
|
|
387
|
+
fid.write("* SOLVER = ELF/MAGIC\n")
|
|
388
|
+
fid.write("MGSC 0.001\n")
|
|
389
|
+
fid.write("* NODE\n")
|
|
390
|
+
|
|
391
|
+
node_list = set()
|
|
392
|
+
for block_id in cubit.get_block_id_list():
|
|
393
|
+
elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face", "edge"]
|
|
394
|
+
for elem_type in elem_types:
|
|
395
|
+
if elem_type == "hex":
|
|
396
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
397
|
+
else:
|
|
398
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
399
|
+
for element_id in func(block_id):
|
|
400
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
401
|
+
node_list.update(node_ids)
|
|
402
|
+
for node_id in node_list:
|
|
403
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
404
|
+
if DIM=='T':
|
|
405
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
|
|
406
|
+
if DIM=='K':
|
|
407
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
|
|
408
|
+
if DIM=='R':
|
|
409
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
|
|
410
|
+
|
|
411
|
+
element_id = 0
|
|
412
|
+
fid.write("* ELEMENT K\n")
|
|
413
|
+
for block_id in cubit.get_block_id_list():
|
|
414
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
415
|
+
|
|
416
|
+
if DIM=='T':
|
|
417
|
+
tet_list = cubit.get_block_tets(block_id)
|
|
418
|
+
for tet_id in tet_list:
|
|
419
|
+
node_list = cubit.get_connectivity('tet',tet_id)
|
|
420
|
+
element_id += 1
|
|
421
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n")
|
|
422
|
+
|
|
423
|
+
hex_list = cubit.get_block_hexes(block_id)
|
|
424
|
+
for hex_id in hex_list:
|
|
425
|
+
node_list = cubit.get_connectivity('hex',hex_id)
|
|
426
|
+
element_id += 1
|
|
427
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[6]} {node_list[7]}\n")
|
|
428
|
+
|
|
429
|
+
wedge_list = cubit.get_block_wedges(block_id)
|
|
430
|
+
for wedge_id in wedge_list:
|
|
431
|
+
node_list = cubit.get_connectivity('wedge',wedge_id)
|
|
432
|
+
element_id += 1
|
|
433
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n")
|
|
434
|
+
|
|
435
|
+
pyramid_list = cubit.get_block_pyramids(block_id)
|
|
436
|
+
for pyramid_id in pyramid_list:
|
|
437
|
+
node_list = cubit.get_connectivity('pyramid',pyramid_id)
|
|
438
|
+
element_id += 1
|
|
439
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[4]} {node_list[4]} {node_list[4]}\n")
|
|
440
|
+
|
|
441
|
+
tri_list = cubit.get_block_tris(block_id)
|
|
442
|
+
for tri_id in tri_list:
|
|
443
|
+
node_list = cubit.get_connectivity('tri',tri_id)
|
|
444
|
+
element_id += 1
|
|
445
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n")
|
|
446
|
+
|
|
447
|
+
quad_list = cubit.get_block_faces(block_id)
|
|
448
|
+
for quad_id in quad_list:
|
|
449
|
+
node_list = cubit.get_connectivity('quad',quad_id)
|
|
450
|
+
element_id += 1
|
|
451
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n")
|
|
452
|
+
|
|
453
|
+
edge_list = cubit.get_block_edges(block_id)
|
|
454
|
+
for edge_id in edge_list:
|
|
455
|
+
node_list = cubit.get_connectivity('edge',edge_id)
|
|
456
|
+
element_id += 1
|
|
457
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]}\n")
|
|
458
|
+
|
|
459
|
+
node_list = cubit.get_block_nodes(block_id)
|
|
460
|
+
for node_id in node_list:
|
|
461
|
+
element_id += 1
|
|
462
|
+
fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_id}\n")
|
|
463
|
+
|
|
464
|
+
fid.write("* NODE\n")
|
|
465
|
+
for node_id in range(len(MGR2)):
|
|
466
|
+
fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
|
|
467
|
+
fid.write("BOOK END\n")
|
|
468
|
+
return cubit
|
|
469
|
+
|
|
470
|
+
########################################################################
|
|
471
|
+
### vtk format
|
|
472
|
+
########################################################################
|
|
473
|
+
|
|
474
|
+
def export_vtk(cubit, FileName: str, ORDER: str = "2nd"):
|
|
475
|
+
"""Export mesh to Legacy VTK format.
|
|
476
|
+
|
|
477
|
+
Exports mesh elements from Cubit to VTK (Visualization Toolkit) Legacy format.
|
|
478
|
+
Supports both first-order and second-order elements.
|
|
479
|
+
|
|
480
|
+
Args:
|
|
481
|
+
cubit: Cubit Python interface object
|
|
482
|
+
FileName: Output file path for the .vtk file
|
|
483
|
+
ORDER: Element order - "2nd" for second-order elements, "1st" for first-order (default: "2nd")
|
|
484
|
+
|
|
485
|
+
Returns:
|
|
486
|
+
cubit: The cubit object (for method chaining)
|
|
487
|
+
|
|
488
|
+
Supported elements:
|
|
489
|
+
- 1st order: Tet4, Hex8, Wedge6, Pyramid5, Triangle3, Quad4, Line2, Point
|
|
490
|
+
- 2nd order: Tet10, Hex20, Wedge15, Pyramid13, Triangle6, Quad8, Line3
|
|
491
|
+
|
|
492
|
+
Note:
|
|
493
|
+
VTK cell data includes scalar values to distinguish element types.
|
|
494
|
+
"""
|
|
495
|
+
with open(FileName,'w') as fid:
|
|
496
|
+
fid.write('# vtk DataFile Version 3.0\n')
|
|
497
|
+
fid.write(f'Unstructured Grid {FileName}\n')
|
|
498
|
+
fid.write('ASCII\n')
|
|
499
|
+
fid.write('DATASET UNSTRUCTURED_GRID\n')
|
|
500
|
+
fid.write(f'POINTS {cubit.get_node_count()} float\n')
|
|
501
|
+
|
|
502
|
+
for node_id in range(cubit.get_node_count()+1):
|
|
503
|
+
if cubit.get_node_exists(node_id):
|
|
504
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
505
|
+
fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
|
|
506
|
+
|
|
507
|
+
hex_list = set()
|
|
508
|
+
tet_list = set()
|
|
509
|
+
wedge_list = set()
|
|
510
|
+
pyramid_list = set()
|
|
511
|
+
tri_list = set()
|
|
512
|
+
quad_list = set()
|
|
513
|
+
edge_list = set()
|
|
514
|
+
nodes_list = set()
|
|
515
|
+
|
|
516
|
+
for block_id in cubit.get_block_id_list():
|
|
517
|
+
tet_list.update(cubit.get_block_tets(block_id))
|
|
518
|
+
hex_list.update(cubit.get_block_hexes(block_id))
|
|
519
|
+
wedge_list.update(cubit.get_block_wedges(block_id))
|
|
520
|
+
pyramid_list.update(cubit.get_block_pyramids(block_id))
|
|
521
|
+
tri_list.update(cubit.get_block_tris(block_id))
|
|
522
|
+
quad_list.update(cubit.get_block_faces(block_id))
|
|
523
|
+
edge_list.update(cubit.get_block_edges(block_id))
|
|
524
|
+
nodes_list.update(cubit.get_block_nodes(block_id))
|
|
525
|
+
|
|
526
|
+
if ORDER=="2nd":
|
|
527
|
+
fid.write(f'CELLS {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list) + len(tri_list) + len(quad_list) + len(edge_list) + len(nodes_list)} {11*len(tet_list) + 21*len(hex_list) + 16*len(wedge_list) + 14*len(pyramid_list) + 7*len(tri_list) + 9*len(quad_list) + 4*len(edge_list) + 2*len(nodes_list)}\n' )
|
|
528
|
+
else:
|
|
529
|
+
fid.write(f'CELLS {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list) + len(tri_list) + len(quad_list) + len(edge_list) + len(nodes_list)} { 5*len(tet_list) + 9*len(hex_list) + 7*len(wedge_list) + 6*len(pyramid_list) + 4*len(tri_list) + 5*len(quad_list) + 3*len(edge_list) + 2*len(nodes_list)}\n' )
|
|
530
|
+
|
|
531
|
+
for tet_id in tet_list:
|
|
532
|
+
node_list = cubit.get_expanded_connectivity("tet", tet_id)
|
|
533
|
+
if len(node_list)==4:
|
|
534
|
+
fid.write(f'4 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1}\n')
|
|
535
|
+
elif len(node_list)==10:
|
|
536
|
+
fid.write(f'10 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} {node_list[6]-1} {node_list[7]-1} {node_list[8]-1} {node_list[9]-1}\n')
|
|
537
|
+
for hex_id in hex_list:
|
|
538
|
+
node_list = cubit.get_expanded_connectivity("hex", hex_id)
|
|
539
|
+
if len(node_list)==8:
|
|
540
|
+
fid.write(f'8 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} {node_list[6]-1} {node_list[7]-1}\n')
|
|
541
|
+
elif len(node_list)==20:
|
|
542
|
+
fid.write(f'20 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} {node_list[6]-1} {node_list[7]-1} {node_list[8]-1} {node_list[9]-1} {node_list[10]-1} {node_list[11]-1} {node_list[16]-1} {node_list[17]-1} {node_list[18]-1} {node_list[19]-1} {node_list[12]-1} {node_list[13]-1} {node_list[14]-1} {node_list[15]-1}\n')
|
|
543
|
+
for wedge_id in wedge_list:
|
|
544
|
+
node_list = cubit.get_expanded_connectivity("wedge", wedge_id)
|
|
545
|
+
if len(node_list)==6:
|
|
546
|
+
fid.write(f'6 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} \n')
|
|
547
|
+
elif len(node_list)==15:
|
|
548
|
+
fid.write(f'15 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} {node_list[6]-1} {node_list[7]-1} {node_list[8]-1} {node_list[12]-1} {node_list[13]-1} {node_list[14]-1} {node_list[9]-1} {node_list[10]-1} {node_list[11]-1} \n')
|
|
549
|
+
|
|
550
|
+
for pyramid_id in pyramid_list:
|
|
551
|
+
node_list = cubit.get_expanded_connectivity("pyramid", pyramid_id)
|
|
552
|
+
if len(node_list)==5:
|
|
553
|
+
fid.write(f'5 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} \n')
|
|
554
|
+
elif len(node_list)==13:
|
|
555
|
+
fid.write(f'13 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} {node_list[6]-1} {node_list[7]-1} {node_list[8]-1} {node_list[9]-1} {node_list[10]-1} {node_list[11]-1} {node_list[12]-1} \n')
|
|
556
|
+
for tri_id in tri_list:
|
|
557
|
+
node_list = cubit.get_expanded_connectivity("tri", tri_id)
|
|
558
|
+
if len(node_list)==3:
|
|
559
|
+
fid.write(f'3 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} \n')
|
|
560
|
+
elif len(node_list)==6:
|
|
561
|
+
fid.write(f'6 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} \n')
|
|
562
|
+
for quad_id in quad_list:
|
|
563
|
+
node_list = cubit.get_expanded_connectivity("quad", quad_id)
|
|
564
|
+
if len(node_list)==4:
|
|
565
|
+
fid.write(f'4 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} \n')
|
|
566
|
+
elif len(node_list)==8:
|
|
567
|
+
fid.write(f'8 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} {node_list[4]-1} {node_list[5]-1} {node_list[6]-1} {node_list[7]-1}\n')
|
|
568
|
+
for edge_id in edge_list:
|
|
569
|
+
node_list = cubit.get_expanded_connectivity("edge", edge_id)
|
|
570
|
+
if len(node_list)==2:
|
|
571
|
+
fid.write(f'2 {node_list[0]-1} {node_list[1]-1} \n')
|
|
572
|
+
elif len(node_list)==3:
|
|
573
|
+
fid.write(f'3 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} \n')
|
|
574
|
+
for node_id in nodes_list:
|
|
575
|
+
fid.write(f'1 {node_id-1} \n')
|
|
576
|
+
|
|
577
|
+
fid.write(f'CELL_TYPES {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list) + len(tri_list) + len(quad_list) + len(edge_list) + len(nodes_list)}\n')
|
|
578
|
+
if ORDER=="2nd":
|
|
579
|
+
for tet_id in tet_list:
|
|
580
|
+
fid.write('24\n')
|
|
581
|
+
for hex_id in hex_list:
|
|
582
|
+
fid.write('25\n')
|
|
583
|
+
for wedge_id in wedge_list:
|
|
584
|
+
fid.write('26\n')
|
|
585
|
+
for pyramid_id in pyramid_list:
|
|
586
|
+
fid.write('27\n')
|
|
587
|
+
for tri_id in tri_list:
|
|
588
|
+
fid.write('22\n')
|
|
589
|
+
for quad_id in quad_list:
|
|
590
|
+
fid.write('23\n')
|
|
591
|
+
for edge_id in edge_list:
|
|
592
|
+
fid.write('21\n')
|
|
593
|
+
for node_id in nodes_list:
|
|
594
|
+
fid.write('1\n')
|
|
595
|
+
else:
|
|
596
|
+
for tet_id in tet_list:
|
|
597
|
+
fid.write('10\n')
|
|
598
|
+
for hex_id in hex_list:
|
|
599
|
+
fid.write('12\n')
|
|
600
|
+
for wedge_id in wedge_list:
|
|
601
|
+
fid.write('13\n')
|
|
602
|
+
for pyramid_id in pyramid_list:
|
|
603
|
+
fid.write('14\n')
|
|
604
|
+
for tri_id in tri_list:
|
|
605
|
+
fid.write('5\n')
|
|
606
|
+
for quad_id in quad_list:
|
|
607
|
+
fid.write('9\n')
|
|
608
|
+
for edge_id in edge_list:
|
|
609
|
+
fid.write('3\n')
|
|
610
|
+
for node_id in nodes_list:
|
|
611
|
+
fid.write('1\n')
|
|
612
|
+
fid.write(f'CELL_DATA {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list) + len(tri_list) + len(quad_list) + len(edge_list) + len(nodes_list)}\n')
|
|
613
|
+
fid.write('SCALARS scalars float\n')
|
|
614
|
+
fid.write('LOOKUP_TABLE default\n')
|
|
615
|
+
for tet_id in tet_list:
|
|
616
|
+
fid.write('1\n')
|
|
617
|
+
for hex_id in hex_list:
|
|
618
|
+
fid.write('2\n')
|
|
619
|
+
for wedge_id in wedge_list:
|
|
620
|
+
fid.write('3\n')
|
|
621
|
+
for pyramid_id in pyramid_list:
|
|
622
|
+
fid.write('4\n')
|
|
623
|
+
for tri_id in tri_list:
|
|
624
|
+
fid.write('5\n')
|
|
625
|
+
for quad_id in quad_list:
|
|
626
|
+
fid.write('6\n')
|
|
627
|
+
for edge_id in edge_list:
|
|
628
|
+
fid.write('0\n')
|
|
629
|
+
for node_id in nodes_list:
|
|
630
|
+
fid.write('-1\n')
|
|
631
|
+
return cubit
|
|
632
|
+
|