Coreform-Cubit-Mesh-Export 1.0.3__py3-none-any.whl → 1.1.0__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.

cubit_mesh_export.py CHANGED
@@ -1,86 +1,8 @@
1
- ########################################################################
2
- ### FreeFEM mesh format
3
- ########################################################################
4
-
5
- def export_3D_mesh(cubit, FileName):
6
-
7
- block_count = cubit.get_block_count()
8
- block_list = cubit.get_block_id_list()
9
- sideset_count = cubit.get_sideset_count()
10
- sideset_list = cubit.get_sideset_id_list()
11
- nodeset_count = cubit.get_nodeset_count()
12
- nodeset_list = cubit.get_nodeset_id_list()
13
-
14
- node_count = cubit.get_node_count()
15
- volume_count = cubit.get_volume_count()
16
- volume_list = cubit.get_entities("volume")
17
- nodeset_surface_count = 0
18
- nodeset_surface_list = []
19
- sideset_surface_list = []
20
- surface_sideset_id = {}
21
- surface_nodeset_id = {}
22
-
23
- with open(FileName, 'w') as fid:
24
- fid.write("MeshVersionFormatted 2\n")
25
- fid.write("\n")
26
- fid.write("Dimension 3\n")
27
- fid.write("\n")
28
- fid.write("Vertices\n")
29
- fid.write(f'{node_count}\n')
30
-
31
- node_set = set()
32
- for block_id in cubit.get_block_id_list():
33
- volume_list = cubit.get_block_volumes(block_id)
34
- node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ) )
35
- for node_id in node_set:
36
- coord = cubit.get_nodal_coordinates(node_id)
37
- fid.write(f'{coord[0]} {coord[1]} {coord[2]} {0}\n')
38
-
39
- fid.write("\n")
40
- tet_list = []
41
- fid.write("Tetrahedra\n")
42
- for block_id in cubit.get_block_id_list():
43
- volume_list = cubit.get_block_volumes(block_id)
44
- for volume_id in volume_list:
45
- tet_list += cubit.get_volume_tets(volume_id)
46
- fid.write(f'{len(tet_list)}\n')
47
-
48
- for block_id in cubit.get_block_id_list():
49
- volume_list = cubit.get_block_volumes(block_id)
50
- for volume_id in volume_list:
51
- tet_list = cubit.get_volume_tets(volume_id)
52
- if len(tet_list)>0:
53
- for tet_id in tet_list:
54
- node_list = cubit.get_connectivity("tet", tet_id)
55
- fid.write(f'{node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {block_id}\n')
56
-
57
- tri_list = []
58
- fid.write("Triangles\n")
59
- for nodeset_id in nodeset_list:
60
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
61
- for surface_id in surface_list:
62
- tri_list += cubit.get_surface_tris(surface_id)
63
- fid.write(f'{len(tri_list)}\n')
64
- for nodeset_id in nodeset_list:
65
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
66
- for surface_id in surface_list:
67
- nodeset_surface_list.append(surface_id)
68
- tri_list = cubit.get_surface_tris(surface_id)
69
- if len(tri_list)>0:
70
- for tri_id in tri_list:
71
- node_list = cubit.get_connectivity("tri", tri_id)
72
- fid.write(f'{node_list[0]} {node_list[1]} {node_list[2]} {nodeset_id}\n')
73
-
74
- fid.write("\n")
75
- fid.write("End\n")
76
- fid.close()
77
- return cubit
78
-
79
1
  ########################################################################
80
2
  ### Gmsh format version 2
81
3
  ########################################################################
82
4
 
83
- def export_2D_gmsh_ver2(cubit, FileName):
5
+ def export_Gmsh_ver2(cubit, FileName):
84
6
 
85
7
  with open(FileName, 'w') as fid:
86
8
 
@@ -89,548 +11,130 @@ def export_2D_gmsh_ver2(cubit, FileName):
89
11
  fid.write("$EndMeshFormat\n")
90
12
 
91
13
  fid.write("$PhysicalNames\n")
92
- fid.write(f'{cubit.get_nodeset_count() + cubit.get_block_count()}\n')
93
-
94
- for nodeset_id in cubit.get_nodeset_id_list():
95
- name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
96
- fid.write(f'1 {nodeset_id} "{name}"\n')
97
-
14
+ fid.write(f'{cubit.get_block_count()}\n')
98
15
  for block_id in cubit.get_block_id_list():
99
- name = cubit.get_exodus_entity_name("block",block_id)
100
- fid.write(f'2 {block_id} "{name}"\n')
16
+ name = cubit.get_exodus_entity_name("block", block_id)
17
+ if len(cubit.get_block_edges(block_id)) > 0:
18
+ fid.write(f'1 {block_id} "{name}"\n')
19
+ elif len(cubit.get_block_tris(block_id)) + len(cubit.get_block_faces(block_id))> 0:
20
+ fid.write(f'2 {block_id} "{name}"\n')
21
+ else:
22
+ fid.write(f'3 {block_id} "{name}"\n')
101
23
  fid.write('$EndPhysicalNames\n')
102
24
 
103
25
  fid.write("$Nodes\n")
104
-
105
- node_set = set()
106
- for block_id in cubit.get_block_id_list():
107
- surface_list = cubit.get_block_surfaces(block_id)
108
- node_set.update(cubit.parse_cubit_list( 'node', f'in surface {" ".join(map(str, surface_list)) }' ))
109
- fid.write(f'{len(node_set)}\n')
110
- for node_id in node_set:
111
- coord = cubit.get_nodal_coordinates(node_id)
112
- fid.write(f'{node_id} {coord[0]} {coord[1]} {coord[2]}\n')
113
- fid.write('$EndNodes\n')
114
-
115
- edge_list = []
116
- quad_list = []
117
- tri_list = []
118
-
119
- for nodeset_id in cubit.get_nodeset_id_list():
120
- curve_list = cubit.get_nodeset_curves(nodeset_id)
121
- for curve_id in curve_list:
122
- edge_list += cubit.get_curve_edges(curve_id)
123
-
124
- for block_id in cubit.get_block_id_list():
125
- surface_list = cubit.get_block_surfaces(block_id)
126
- for surface_id in surface_list:
127
- quad_list += cubit.get_surface_quads(surface_id)
128
- tri_list += cubit.get_surface_tris(surface_id)
129
-
130
- Elems = 0
131
- fid.write('$Elements\n')
132
- fid.write(f'{len(edge_list) + len(quad_list) + len(tri_list)}\n')
133
-
134
- for nodeset_id in cubit.get_nodeset_id_list():
135
- curve_list = cubit.get_nodeset_curves(nodeset_id)
136
- for curve_id in curve_list:
137
- edge_list = cubit.get_curve_edges(curve_id)
138
- if len(edge_list)>0:
139
- for edge_id in edge_list:
140
- Elems += 1
141
- node_list = cubit.get_connectivity('edge', edge_id)
142
- fid.write(f'{Elems} {1} {2} {nodeset_id} {curve_id} {node_list[0]} {node_list[1]}\n')
143
-
144
- for block_id in cubit.get_block_id_list():
145
- surface_list = cubit.get_block_surfaces(block_id)
146
- for surface_id in surface_list:
147
- tri_list = cubit.get_surface_tris(surface_id)
148
- if len(tri_list)>0:
149
- for tri_id in tri_list:
150
- Elems += 1
151
- node_list = cubit.get_expanded_connectivity("tri", tri_id)
152
- if len(node_list)==3:
153
- fid.write(f'{Elems} {2} {2} {block_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
154
- if len(node_list)==6:
155
- fid.write(f'{Elems} {9} {2} {block_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n')
156
- if len(node_list)==7:
157
- fid.write(f'{Elems} {42} {2} {block_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[5]}\n')
158
-
159
- quad_list = cubit.get_surface_quads(surface_id)
160
- if len(quad_list)>0:
161
- for quad_id in quad_list:
162
- Elems += 1
163
- node_list = cubit.get_expanded_connectivity("quad", quad_id)
164
- if len(node_list)==4:
165
- fid.write(f'{Elems} {3} {2} {block_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
166
- if len(node_list)==8:
167
- fid.write(f'{Elems} {16} {2} {block_id} {surface_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')
168
- if len(node_list)==9:
169
- fid.write(f'{Elems} {10} {2} {block_id} {surface_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')
170
-
171
- fid.write('$EndElements\n')
172
-
173
- fid.close()
174
- return cubit
175
-
176
- ########################################################################
177
- ### Gmsh format version 2
178
- ########################################################################
179
-
180
- def export_3D_gmsh_ver2(cubit, FileName):
181
-
182
- with open(FileName, 'w') as fid:
183
-
184
- fid.write("$MeshFormat\n")
185
- fid.write("2.2 0 8\n")
186
- fid.write("$EndMeshFormat\n")
187
-
188
- fid.write("$PhysicalNames\n")
189
- fid.write(f'{cubit.get_nodeset_count() + cubit.get_block_count()}\n')
190
-
191
- for nodeset_id in cubit.get_nodeset_id_list():
192
- name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
193
- fid.write(f'2 {nodeset_id} "{name}"\n')
194
-
26
+ node_list = set()
195
27
  for block_id in cubit.get_block_id_list():
196
- name = cubit.get_exodus_entity_name("block",block_id)
197
- fid.write(f'3 {block_id} "{name}"\n')
198
- fid.write('$EndPhysicalNames\n')
199
-
200
- fid.write("$Nodes\n")
28
+ elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face", "edge"]
29
+ for elem_type in elem_types:
30
+ if elem_type == "hex":
31
+ func = getattr(cubit, f"get_block_{elem_type}es")
32
+ else:
33
+ func = getattr(cubit, f"get_block_{elem_type}s")
34
+ for element_id in func(block_id):
35
+ node_ids = cubit.get_expanded_connectivity(elem_type, element_id)
36
+ node_list.update(node_ids)
201
37
 
202
- node_set = set()
203
- for block_id in cubit.get_block_id_list():
204
- volume_list = cubit.get_block_volumes(block_id)
205
- node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
206
- fid.write(f'{len(node_set)}\n')
207
- for node_id in node_set:
38
+ fid.write(f'{len(node_list)}\n')
39
+ for node_id in node_list:
208
40
  coord = cubit.get_nodal_coordinates(node_id)
209
41
  fid.write(f'{node_id} {coord[0]} {coord[1]} {coord[2]}\n')
210
42
  fid.write('$EndNodes\n')
211
43
 
212
- hex_list = []
213
- tet_list = []
214
- wedge_list = []
215
- pyramid_list = []
216
- quad_list = []
217
- tri_list = []
44
+ hex_list = set()
45
+ tet_list = set()
46
+ wedge_list = set()
47
+ pyramid_list = set()
48
+ tri_list = set()
49
+ quad_list = set()
50
+ edge_list = set()
218
51
 
219
52
  for block_id in cubit.get_block_id_list():
220
- volume_list = cubit.get_block_volumes(block_id)
221
- for volume_id in volume_list:
222
- hex_list += cubit.get_volume_hexes(volume_id)
223
- tet_list += cubit.get_volume_tets(volume_id)
224
- wedge_list += cubit.get_volume_wedges(volume_id)
225
- pyramid_list += cubit.get_volume_pyramids(volume_id)
226
-
227
- for nodeset_id in cubit.get_nodeset_id_list():
228
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
229
- for surface_id in surface_list:
230
- quad_list += cubit.get_surface_quads(surface_id)
231
- tri_list += cubit.get_surface_tris(surface_id)
232
-
233
- Elems = 0
53
+ tet_list.update(cubit.get_block_tets(block_id))
54
+ hex_list.update(cubit.get_block_hexes(block_id))
55
+ wedge_list.update(cubit.get_block_wedges(block_id))
56
+ pyramid_list.update(cubit.get_block_pyramids(block_id))
57
+ tri_list.update(cubit.get_block_tris(block_id))
58
+ quad_list.update(cubit.get_block_faces(block_id))
59
+ edge_list.update(cubit.get_block_edges(block_id))
60
+
61
+ element_id = 0
234
62
  fid.write('$Elements\n')
235
- fid.write(f'{len(hex_list) + len(tet_list) + len(wedge_list) + len(pyramid_list) + len(quad_list) + len(tri_list)}\n')
236
-
237
- for nodeset_id in cubit.get_nodeset_id_list():
238
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
239
- for surface_id in surface_list:
240
- tri_list = cubit.get_surface_tris(surface_id)
241
- if len(tri_list)>0:
242
- for tri_id in tri_list:
243
- Elems += 1
244
- node_list = cubit.get_expanded_connectivity("tri", tri_id)
245
- if len(node_list)==3:
246
- fid.write(f'{Elems} {2} {2} {nodeset_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
247
- if len(node_list)==6:
248
- fid.write(f'{Elems} {9} {2} {nodeset_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n')
249
- if len(node_list)==7:
250
- fid.write(f'{Elems} {42} {2} {nodeset_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]} {node_list[5]}\n')
251
-
252
- quad_list = cubit.get_surface_quads(surface_id)
253
- if len(quad_list)>0:
254
- for quad_id in quad_list:
255
- Elems += 1
256
- node_list = cubit.get_expanded_connectivity("quad", quad_id)
257
- if len(node_list)==4:
258
- fid.write(f'{Elems} {3} {2} {nodeset_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
259
- if len(node_list)==8:
260
- fid.write(f'{Elems} {16} {2} {nodeset_id} {surface_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')
261
- if len(node_list)==9:
262
- fid.write(f'{Elems} {10} {2} {nodeset_id} {surface_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')
263
-
63
+ fid.write(f'{len(hex_list) + len(tet_list) + len(wedge_list) + len(pyramid_list) + len(tri_list) + len(quad_list) + len(edge_list)}\n')
264
64
 
265
65
  for block_id in cubit.get_block_id_list():
266
- volume_list = cubit.get_block_volumes(block_id)
267
- for volume_id in volume_list:
268
66
 
269
- tet_list = cubit.get_volume_tets(volume_id)
270
- if len(tet_list)>0:
271
- for tet_id in tet_list:
272
- Elems += 1
273
- node_list = cubit.get_expanded_connectivity("tet", tet_id)
274
- if len(node_list)==4:
275
- fid.write(f'{Elems} {4} {2} {block_id} {volume_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
276
- if len(node_list)==10:
277
- fid.write(f'{Elems} {11} {2} {block_id} {volume_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')
278
- if len(node_list)==11:
279
- fid.write(f'{Elems} {35} {2} {block_id} {volume_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[9]} {node_list[10]}\n')
280
-
281
- hex_list = cubit.get_volume_hexes(volume_id)
282
- if len(hex_list)>0:
283
- for hex_id in hex_list:
284
- Elems += 1
285
- node_list = cubit.get_expanded_connectivity("hex", hex_id)
286
- if len(node_list)==8:
287
- fid.write(f'{Elems} {5} {2} {block_id} {volume_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')
288
- if len(node_list)==20:
289
- fid.write(f'{Elems} {17} {2} {block_id} {volume_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[9]} {node_list[10]} {node_list[11]} {node_list[12]} {node_list[13]} {node_list[14]} {node_list[15]} {node_list[16]} {node_list[17]} {node_list[18]} {node_list[19]}\n')
290
-
291
- wedge_list = cubit.get_volume_wedges(volume_id)
292
- if len(wedge_list)>0:
293
- for wedge_id in wedge_list:
294
- Elems += 1
295
- node_list = cubit.get_connectivity("wedge", wedge_id)
296
- if len(node_list)==6:
297
- fid.write(f'{Elems} {6} {2} {block_id} {volume_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n')
298
- if len(node_list)==15:
299
- fid.write(f'{Elems} {18} {2} {block_id} {volume_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[9]} {node_list[10]} {node_list[11]} {node_list[12]} {node_list[13]} {node_list[14]}\n')
300
-
301
- pyramid_list = cubit.get_volume_pyramids(volume_id)
302
- if len(pyramid_list)>0:
303
- for pyramid_id in pyramid_list:
304
- Elems += 1
305
- node_list = cubit.get_connectivity("pyramid", pyramid_id)
306
- if len(node_list)==6:
307
- fid.write(f'{Elems} {7} {2} {block_id} {volume_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]}\n')
308
- if len(node_list)==13:
309
- fid.write(f'{Elems} {19} {2} {block_id} {volume_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[9]} {node_list[10]} {node_list[11]} {node_list[12]} {node_list[13]} {node_list[14]}\n')
310
-
311
- fid.write('$EndElements\n')
312
-
313
- fid.close()
314
- return cubit
315
-
316
- ########################################################################
317
- ### Gmsh format version 4
318
- ########################################################################
319
-
320
- def export_3D_gmsh_ver4(cubit, FileName):
321
-
322
- nodeset_surface_count = 0
323
- for nodeset_id in cubit.get_nodeset_id_list():
324
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
325
- for surface_id in surface_list:
326
- nodeset_surface_count += 1
327
-
328
- block_volume_count = 0
329
- for block_id in cubit.get_block_id_list():
330
- volume_list = cubit.get_block_volumes(block_id)
331
- for volume_id in volume_list:
332
- block_volume_count += 1
333
-
334
- with open(FileName, 'w') as fid:
335
-
336
- fid.write('$MeshFormat\n')
337
- fid.write('4.1 0 8\n')
338
- fid.write('$EndMeshFormat\n')
339
-
340
- fid.write('$PhysicalNames\n')
341
- fid.write(f'{cubit.get_nodeset_count() + cubit.get_block_count()}\n')
342
-
343
- for nodeset_id in cubit.get_nodeset_id_list():
344
- name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
345
- fid.write(f'2 {nodeset_id} "{name}"\n')
346
- for block_id in cubit.get_block_id_list():
347
- name = cubit.get_exodus_entity_name("block",block_id)
348
- fid.write(f'3 {block_id} "{name}"\n')
349
- fid.write('$EndPhysicalNames\n')
350
-
351
- fid.write('$Entities\n')
352
- fid.write(f'{0} {0} {nodeset_surface_count} {block_volume_count}\n')
353
-
354
- # for nodeset_id in cubit.get_nodeset_id_list():
355
- # surface_list = cubit.get_nodeset_surfaces(nodeset_id)
356
- # for surface_id in surface_list:
357
- # vertex_list = cubit.get_relatives("surface", surface_id, "vertex")
358
- # for vertex_id in vertex_list:
359
- # x = cubit.vertex(vertex_id).coordinates()[0]
360
- # y = cubit.vertex(vertex_id).coordinates()[1]
361
- # z = cubit.vertex(vertex_id).coordinates()[2]
362
- # fid.write(f'{vertex_id} {x} {y} {z} {1} {nodeset_id}\n')
363
-
364
- # for nodeset_id in cubit.get_nodeset_id_list():
365
- # surface_list = cubit.get_nodeset_surfaces(nodeset_id)
366
- # for surface_id in surface_list:
367
- # curve_list = cubit.get_relatives("surface", surface_id, "curve")
368
- # for curve_id in curve_list:
369
- # bounding_box = cubit.get_bounding_box("curve", curve_id)
370
- # minx = bounding_box[0]
371
- # maxx = bounding_box[1]
372
- # miny = bounding_box[3]
373
- # maxy = bounding_box[4]
374
- # minz = bounding_box[6]
375
- # maxz = bounding_box[7]
376
- # vertex_list = cubit.get_relatives("curve", curve_id, "vertex")
377
- # fid.write(f'{curve_id} {minx} {miny} {minz} {maxx} {maxy} {maxz} {1} {nodeset_id} {len(vertex_list)}')
378
- # for vertex_id in vertex_list:
379
- # fid.write(f' {vertex_id}')
380
- # fid.write(f'\n')
381
-
382
- for nodeset_id in cubit.get_nodeset_id_list():
383
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
384
- for surface_id in surface_list:
385
- bounding_box = cubit.get_bounding_box("surface", surface_id)
386
- minx = bounding_box[0]
387
- maxx = bounding_box[1]
388
- miny = bounding_box[3]
389
- maxy = bounding_box[4]
390
- minz = bounding_box[6]
391
- maxz = bounding_box[7]
392
- fid.write(f'{surface_id} {minx} {miny} {minz} {maxx} {maxy} {maxz} {1} {nodeset_id} {0}\n')
393
-
394
- for block_id in cubit.get_block_id_list():
395
- for volume_id in cubit.get_block_volumes(block_id):
396
- bounding_box = cubit.get_bounding_box("volume", volume_id)
397
- minx = bounding_box[0]
398
- maxx = bounding_box[1]
399
- miny = bounding_box[3]
400
- maxy = bounding_box[4]
401
- minz = bounding_box[6]
402
- maxz = bounding_box[7]
403
- fid.write(f'{volume_id} {minx} {miny} {minz} {maxx} {maxy} {maxz} {1} {block_id} {nodeset_surface_count}')
404
- for nodeset_id in cubit.get_nodeset_id_list():
405
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
406
- for surface_id in surface_list:
407
- fid.write(f' {surface_id}')
408
- fid.write(f'\n')
409
-
410
- fid.write('$EndEntities\n')
411
-
412
- counts = 0
413
- node_all_set = set()
414
- for nodeset_id in cubit.get_nodeset_id_list():
415
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
416
- for surface_id in surface_list:
417
- node_list = cubit.get_surface_nodes(surface_id)
418
- if len(node_list) > 0:
419
- node_all_set.update(node_list)
420
- counts += 1
421
-
422
- for block_id in cubit.get_block_id_list():
423
- for volume_id in cubit.get_block_volumes(block_id):
424
- node_list = cubit.parse_cubit_list( "node", f"in volume {volume_id}" )
425
- if len(node_list) > 0:
426
- node_all_set.update(node_list)
427
- counts += 1
428
-
429
- fid.write('$Nodes\n')
430
- fid.write(f'{counts} {len(node_all_set)} {min(node_all_set)} {max(node_all_set)}\n')
431
-
432
- node_all_set.clear()
433
-
434
- for nodeset_id in cubit.get_nodeset_id_list():
435
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
436
- for surface_id in surface_list:
437
- node_list = cubit.get_surface_nodes(surface_id)
438
- node_list = set(node_list) - node_all_set
439
- if len(node_list) > 0:
440
- node_all_set.update(node_list)
441
- fid.write(f'2 {surface_id} 0 {len(node_list)}\n')
442
- for node_id in node_list:
443
- fid.write(f'{node_id}\n')
444
- for node_id in node_list:
445
- coord = cubit.get_nodal_coordinates(node_id)
446
- fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
447
-
448
- for block_id in cubit.get_block_id_list():
449
- for volume_id in cubit.get_block_volumes(block_id):
450
- node_list = cubit.parse_cubit_list( "node", f"in volume {volume_id}" )
451
- node_list = set(node_list) - node_all_set
452
- if len(node_list) > 0:
453
- node_all_set.update(node_list)
454
- fid.write(f'3 {volume_id} 0 {len(node_list)}\n')
455
- for node_id in node_list:
456
- fid.write(f'{node_id}\n')
457
- for node_id in node_list:
458
- coord = cubit.get_nodal_coordinates(node_id)
459
- fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
460
-
461
- fid.write('$EndNodes\n')
462
-
463
- tri_all_list = []
464
- quad_all_list = []
465
- tet_all_list = []
466
- hex_all_list = []
467
- wedge_all_list = []
468
-
469
- fid.write('$Elements\n')
470
-
471
- for nodeset_id in cubit.get_nodeset_id_list():
472
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
473
- for surface_id in surface_list:
474
- tri_all_list += cubit.get_surface_tris(surface_id)
475
- quad_all_list += cubit.get_surface_quads(surface_id)
476
-
477
- for block_id in cubit.get_block_id_list():
478
- for volume_id in cubit.get_block_volumes(block_id):
479
- tet_all_list += cubit.get_volume_tets(volume_id)
480
- hex_all_list += cubit.get_volume_hexes(volume_id)
481
- wedge_all_list += cubit.get_volume_wedges(volume_id)
482
-
483
- elementTag = 1
484
-
485
- all_list = quad_all_list + tri_all_list + hex_all_list + tet_all_list + wedge_all_list
486
- if len(all_list) > 0:
487
- fid.write(f'{ nodeset_surface_count + block_volume_count} {len(all_list)} {min(all_list)} {max(all_list)}\n')
488
- else:
489
- fid.write(f'{ nodeset_surface_count + block_volume_count} 0 0 0\n')
490
-
491
- for nodeset_id in cubit.get_nodeset_id_list():
492
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
493
- for surface_id in surface_list:
494
- tri_list = cubit.get_surface_tris(surface_id)
495
- if len(tri_list)>0:
496
- fid.write(f'2 {surface_id} 2 {len(tri_list)}\n')
497
- for tri_id in tri_list:
498
- node_list = cubit.get_connectivity("tri", tri_id)
499
- elementTag +=1
500
- fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]}\n')
501
-
502
- quad_list = cubit.get_surface_quads(surface_id)
503
- if len(quad_list)>0:
504
- fid.write(f'2 {surface_id} 3 {len(quad_list)}\n')
505
- for quad_id in quad_list:
506
- node_list = cubit.get_connectivity("quad", quad_id)
507
- elementTag +=1
508
- fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
509
-
510
- for block_id in cubit.get_block_id_list():
511
- for volume_id in cubit.get_block_volumes(block_id):
512
- tet_list = cubit.get_volume_tets(volume_id)
513
- if len(tet_list)>0:
514
- fid.write(f'3 {volume_id} 4 {len(tet_list)}\n')
515
- for tet_id in tet_list:
516
- node_list = cubit.get_connectivity("tet", tet_id)
517
- elementTag +=1
518
- fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
519
-
520
- hex_list = cubit.get_volume_hexes(volume_id)
521
- if len(hex_list)>0:
522
- fid.write(f'3 {volume_id} 5 {len(hex_list)}\n')
523
- for hex_id in hex_list:
524
- node_list = cubit.get_connectivity("hex", hex_id)
525
- elementTag +=1
526
- fid.write(f'{elementTag} {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')
527
-
528
- wedge_list = cubit.get_volume_wedges(volume_id)
529
- if len(wedge_list)>0:
530
- fid.write(f'3 {volume_id} 6 {len(wedge_list)}\n')
531
- for wedge_id in wedge_list:
532
- node_list = cubit.get_connectivity("wedge", wedge_id)
533
- elementTag +=1
534
- fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} {node_list[5]}\n')
535
-
536
- fid.write('$EndElements\n')
537
- fid.close()
538
- return cubit
539
-
540
- ########################################################################
541
- ### NASTRAN 1D file
542
- ########################################################################
543
-
544
- def export_1D_Nastran(cubit, FileName):
545
- import datetime
546
- formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
67
+ tet_list = cubit.get_block_tets(block_id)
68
+ for tet_id in tet_list:
69
+ element_id += 1
70
+ node_list = cubit.get_expanded_connectivity("tet", tet_id)
71
+ if len(node_list)==4:
72
+ fid.write(f'{element_id} { 4} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
73
+ if len(node_list)==10:
74
+ 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')
75
+ if len(node_list)==11:
76
+ 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')
77
+
78
+ hex_list = cubit.get_block_hexes(block_id)
79
+ for hex_id in hex_list:
80
+ element_id += 1
81
+ node_list = cubit.get_expanded_connectivity("hex", hex_id)
82
+ if len(node_list)==8:
83
+ 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')
84
+ if len(node_list)==20:
85
+ 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')
547
86
 
548
- fid = open(FileName,'w',encoding='UTF-8')
549
- fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
550
- fid.write("$\n")
551
- fid.write("$ CUBIT NX Nastran Translator\n")
552
- fid.write("$\n")
553
- fid.write(f"$ File: {FileName}\n")
554
- fid.write(f"$ Time Stamp: {formatted_date_time}\n")
555
- fid.write("$\n")
556
- fid.write("$\n")
557
- fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
558
- fid.write("$\n")
559
- fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
560
- 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")
561
- fid.write("$\n")
562
- fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
563
- fid.write("$\n")
564
- fid.write("$\n")
565
- fid.write("$ -------------------------\n")
566
- fid.write("$ Executive Control Section\n")
567
- fid.write("$ -------------------------\n")
568
- fid.write("$\n")
569
- fid.write("SOL 101\n")
570
- fid.write("CEND\n")
571
- fid.write("$\n")
572
- fid.write("$\n")
573
- fid.write("$ --------------------\n")
574
- fid.write("$ Case Control Section\n")
575
- fid.write("$ --------------------\n")
576
- fid.write("$\n")
577
- fid.write("ECHO = SORT\n")
578
- fid.write("$\n")
579
- fid.write("$\n")
580
- fid.write("$ Name: Initial\n")
581
- fid.write("$\n")
582
- fid.write("$\n")
583
- fid.write("$ Name: Default Set\n")
584
- fid.write("$\n")
585
- fid.write("SUBCASE = 1\n")
586
- fid.write("$\n")
587
- fid.write("LABEL = Default Set\n")
588
- fid.write("$\n")
589
- fid.write("$ -----------------\n")
590
- fid.write("$ Bulk Data Section\n")
591
- fid.write("$ -----------------\n")
592
- fid.write("$\n")
593
- fid.write("BEGIN BULK\n")
594
- fid.write("$\n")
595
- fid.write("$ Params\n")
596
- fid.write("$\n")
597
- fid.write("$\n")
598
- fid.write("$ Node cards\n")
599
- fid.write("$\n")
87
+ wedge_list = cubit.get_block_wedges(block_id)
88
+ for wedge_id in wedge_list:
89
+ element_id += 1
90
+ node_list = cubit.get_expanded_connectivity("wedge", wedge_id)
91
+ if len(node_list)==6:
92
+ 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')
93
+ if len(node_list)==15:
94
+ 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')
600
95
 
601
- node_set = set()
602
- for block_id in cubit.get_block_id_list():
603
- curve_list = cubit.get_block_curves(block_id)
604
- node_set.update(cubit.parse_cubit_list( 'node', f'in curve {" ".join(map(str, curve_list)) }' ))
605
- for node_id in node_set:
606
- coord = cubit.get_nodal_coordinates(node_id)
607
- fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
96
+ pyramid_list = cubit.get_block_pyramids(block_id)
97
+ for pyramid_id in pyramid_list:
98
+ element_id += 1
99
+ node_list = cubit.get_expanded_connectivity("pyramid", pyramid_id)
100
+ if len(node_list)==6:
101
+ 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')
102
+ if len(node_list)==13:
103
+ 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')
608
104
 
609
- element_id = 0
610
- fid.write("$\n")
611
- fid.write("$ Element cards\n")
612
- fid.write("$\n")
613
- for block_id in cubit.get_block_id_list():
614
- name = cubit.get_exodus_entity_name("block",block_id)
615
- curve_list = cubit.get_block_curves(block_id)
616
- for curve_id in curve_list:
617
- edge_list = cubit.get_curve_edges(curve_id)
105
+ tri_list = cubit.get_block_tris(block_id)
106
+ for tri_id in tri_list:
107
+ element_id += 1
108
+ node_list = cubit.get_expanded_connectivity("tri", tri_id)
109
+ if len(node_list)==3:
110
+ fid.write(f'{element_id} { 2} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
111
+ if len(node_list)==6:
112
+ 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')
113
+ if len(node_list)==7:
114
+ 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')
115
+
116
+ quad_list = cubit.get_block_faces(block_id)
117
+ for quad_id in quad_list:
118
+ element_id += 1
119
+ node_list = cubit.get_expanded_connectivity("quad", quad_id)
120
+ if len(node_list)==4:
121
+ fid.write(f'{element_id} { 3} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
122
+ if len(node_list)==8:
123
+ 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')
124
+ if len(node_list)==9:
125
+ 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')
126
+
127
+ edge_list = cubit.get_block_edges(block_id)
618
128
  for edge_id in edge_list:
619
- node_list = cubit.get_connectivity('edge', edge_id)
620
129
  element_id += 1
621
- fid.write(f"CROD {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}\n")
622
- fid.write("$\n")
623
- fid.write("$ Property cards\n")
624
- fid.write("$\n")
130
+ node_list = cubit.get_expanded_connectivity("edge", edge_id)
131
+ if len(node_list)==2:
132
+ fid.write(f'{element_id} {1} {2} {block_id} {block_id} {node_list[0]} {node_list[1]}\n')
133
+ if len(node_list)==3:
134
+ fid.write(f'{element_id} {8} {2} {block_id} {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
625
135
 
626
- for block_id in cubit.get_block_id_list():
627
- name = cubit.get_exodus_entity_name("block",block_id)
628
- fid.write("$\n")
629
- fid.write(f"$ Name: {name}\n")
630
- fid.write("$\n")
631
- fid.write(f"MAT1 {block_id:< 8}{1:<8}{1:<8}{1:<8}\n")
632
- fid.write("ENDDATA\n")
633
- fid.close()
136
+ fid.write('$EndElements\n')
137
+ fid.close()
634
138
  return cubit
635
139
 
636
140
  ########################################################################
@@ -694,11 +198,15 @@ def export_2D_Nastran(cubit, FileName):
694
198
  fid.write("$ Node cards\n")
695
199
  fid.write("$\n")
696
200
 
697
- node_set = set()
201
+ node_list = set()
698
202
  for block_id in cubit.get_block_id_list():
699
- surface_list = cubit.get_block_surfaces(block_id)
700
- node_set.update(cubit.parse_cubit_list( 'node', f'in surface {" ".join(map(str, surface_list)) }' ))
701
- for node_id in node_set:
203
+ elem_types = ["tri", "face", "edge"]
204
+ for elem_type in elem_types:
205
+ func = getattr(cubit, f"get_block_{elem_type}s")
206
+ for element_id in func(block_id):
207
+ node_ids = cubit.get_connectivity(elem_type, element_id)
208
+ node_list.update(node_ids)
209
+ for node_id in node_list:
702
210
  coord = cubit.get_nodal_coordinates(node_id)
703
211
  fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
704
212
 
@@ -711,25 +219,35 @@ def export_2D_Nastran(cubit, FileName):
711
219
  fid.write("$\n")
712
220
  fid.write(f"$ Name: {name}\n")
713
221
  fid.write("$\n")
714
- surface_list = cubit.get_block_surfaces(block_id)
715
- for surface_id in surface_list:
222
+
223
+ tri_list = cubit.get_block_tris(block_id)
224
+ for tri_id in tri_list:
225
+ element_id += 1
226
+ surface_id = int(cubit.get_geometry_owner("tri", tri_id).split()[1])
716
227
  normal = cubit.get_surface_normal(surface_id)
717
- tri_list = cubit.get_surface_tris(surface_id)
718
- for tri_id in tri_list:
719
- node_list = cubit.get_connectivity('tri',tri_id)
720
- element_id += 1
721
- if normal[2] > 0:
722
- fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}\n")
723
- else:
724
- fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[2]:<8}{node_list[1]:<8}\n")
725
- quad_list = cubit.get_surface_quads(surface_id)
726
- for quad_id in quad_list:
727
- node_list = cubit.get_connectivity('quad',quad_id)
728
- element_id += 1
729
- if normal[2] > 0:
730
- 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")
731
- else:
732
- 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]:<1}\n")
228
+ node_list = cubit.get_connectivity('tri',tri_id)
229
+ if normal[2] > 0:
230
+ fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}\n")
231
+ else:
232
+ fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[2]:<8}{node_list[1]:<8}\n")
233
+
234
+ quad_list = cubit.get_block_faces(block_id)
235
+ for quad_id in quad_list:
236
+ element_id += 1
237
+ surface_id = int(cubit.get_geometry_owner("quad", quad_id).split()[1])
238
+ normal = cubit.get_surface_normal(surface_id)
239
+ node_list = cubit.get_connectivity('quad',quad_id)
240
+ if normal[2] > 0:
241
+ 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")
242
+ else:
243
+ 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]:<1}\n")
244
+
245
+ edge_list = cubit.get_block_edges(block_id)
246
+ for edge_id in edge_list:
247
+ element_id += 1
248
+ node_list = cubit.get_connectivity('edge', edge_id)
249
+ if len(node_list)==2:
250
+ fid.write(f"CROD {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}\n")
733
251
  fid.write("$\n")
734
252
  fid.write("$ Property cards\n")
735
253
  fid.write("$\n")
@@ -748,7 +266,7 @@ def export_2D_Nastran(cubit, FileName):
748
266
  ### 3D Nastran file
749
267
  ########################################################################
750
268
 
751
- def export_3D_Nastran(cubit, FileName, Pyram=True):
269
+ def export_3D_Nastran(cubit, FileName, PYRAM=True):
752
270
 
753
271
  import datetime
754
272
  formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
@@ -805,12 +323,19 @@ def export_3D_Nastran(cubit, FileName, Pyram=True):
805
323
  fid.write("$ Node cards\n")
806
324
  fid.write("$\n")
807
325
 
808
- node_set = set()
326
+ node_list = set()
809
327
  for block_id in cubit.get_block_id_list():
810
- volume_list = cubit.get_block_volumes(block_id)
811
- node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
812
- fid.write(f'{len(node_set)}\n')
813
- for node_id in node_set:
328
+ elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face", "edge"]
329
+ for elem_type in elem_types:
330
+ if elem_type == "hex":
331
+ func = getattr(cubit, f"get_block_{elem_type}es")
332
+ else:
333
+ func = getattr(cubit, f"get_block_{elem_type}s")
334
+ for element_id in func(block_id):
335
+ node_ids = cubit.get_connectivity(elem_type, element_id)
336
+ node_list.update(node_ids)
337
+ fid.write(f'{len(node_list)}\n')
338
+ for node_id in node_list:
814
339
  coord = cubit.get_nodal_coordinates(node_id)
815
340
  fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
816
341
 
@@ -823,42 +348,51 @@ def export_3D_Nastran(cubit, FileName, Pyram=True):
823
348
  fid.write("$\n")
824
349
  fid.write(f"$ Name: {name}\n")
825
350
  fid.write("$\n")
826
- volume_list = cubit.get_block_volumes(block_id)
827
- for volume_id in volume_list:
828
- tet_list = cubit.get_volume_tets(volume_id)
829
- for tet_id in tet_list:
830
- node_list = cubit.get_connectivity('tet',tet_id)
351
+ tet_list = cubit.get_block_tets(block_id)
352
+ for tet_id in tet_list:
353
+ node_list = cubit.get_connectivity('tet',tet_id)
354
+ element_id += 1
355
+ 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")
356
+ hex_list = cubit.get_block_hexes(block_id)
357
+ for hex_id in hex_list:
358
+ node_list = cubit.get_connectivity('hex',hex_id)
359
+ element_id += 1
360
+ 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")
361
+ wedge_list = cubit.get_block_wedges(block_id)
362
+ for wedge_id in wedge_list:
363
+ node_list = cubit.get_connectivity('wedge',wedge_id)
364
+ element_id += 1
365
+ 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")
366
+ pyramid_list = cubit.get_block_pyramids(block_id)
367
+ for pyramid_id in pyramid_list:
368
+ node_list = cubit.get_connectivity('pyramid',pyramid_id)
369
+ if PYRAM:
831
370
  element_id += 1
832
- 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")
833
- hex_list = cubit.get_volume_hexes(volume_id)
834
- for hex_id in hex_list:
835
- node_list = cubit.get_connectivity('hex',hex_id)
371
+ 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")
372
+ else:
836
373
  element_id += 1
837
- 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")
838
- wedge_list = cubit.get_volume_wedges(volume_id)
839
- for wedge_id in wedge_list:
840
- node_list = cubit.get_connectivity('wedge',wedge_id)
374
+ 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")
375
+ tri_list = cubit.get_block_tris(block_id)
376
+ for tri_id in tri_list:
377
+ node_list = cubit.get_connectivity('tri',tri_id)
378
+ element_id += 1
379
+ fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}\n")
380
+ quad_list = cubit.get_block_faces(block_id)
381
+ for quad_id in quad_list:
382
+ node_list = cubit.get_connectivity('quad',quad_id)
383
+ element_id += 1
384
+ 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")
385
+ edge_list = cubit.get_block_edges(block_id)
386
+ if len(edge_list)>0:
387
+ for edge_id in edge_list:
841
388
  element_id += 1
842
- 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")
843
- pyramid_list = cubit.get_volume_pyramids(volume_id)
844
- for pyramid_id in pyramid_list:
845
- node_list = cubit.get_connectivity('pyramid',pyramid_id)
846
- if Pyram:
847
- element_id += 1
848
- 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")
849
- else:
850
- element_id += 1
851
- 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")
389
+ node_list = cubit.get_connectivity('edge', edge_id)
390
+ if len(node_list)==2:
391
+ fid.write(f"CROD {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}\n")
852
392
  fid.write("$\n")
853
393
  fid.write("$ Property cards\n")
854
394
  fid.write("$\n")
855
395
 
856
- for nodeset_id in cubit.get_nodeset_id_list():
857
- name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
858
- fid.write("$\n")
859
- fid.write(f"$ Name: {name}\n")
860
- fid.write("$\n")
861
- fid.write(f"PSHELL {nodeset_id:< 8}{nodeset_id:< 8}{1:<8}{1:<8}{1:<8}\n")
862
396
  for block_id in cubit.get_block_id_list():
863
397
  name = cubit.get_exodus_entity_name("block",block_id)
864
398
  fid.write("$\n")
@@ -870,166 +404,10 @@ def export_3D_Nastran(cubit, FileName, Pyram=True):
870
404
  return cubit
871
405
 
872
406
  ########################################################################
873
- ### 3D CDB file
874
- ########################################################################
875
-
876
- def export_3D_CDB(cubit, FileName):
877
-
878
- fid = open(FileName,'w',encoding='UTF-8')
879
- fid.write(f'/COM,ANSYS RELEASE 15.0\n')
880
- fid.write(f'! Exported from Coreform Cubit 2024.3\n')
881
- fid.write(f'! {datetime.now().strftime("%Y/%m/%d %I:%M:%S %p")}\n')
882
- fid.write(f'/PREP7\n')
883
- fid.write(f'/TITLE,\n')
884
- fid.write(f'*IF,_CDRDOFF,EQ,1,THEN\n')
885
- fid.write(f'_CDRDOFF= \n')
886
- fid.write(f'*ELSE\n')
887
- fid.write(f'NUMOFF,NODE, {node_count:8d}\n')
888
- fid.write(f'NUMOFF,ELEM, {elem_count:8d}\n')
889
- fid.write(f'NUMOFF,TYPE, 1\n')
890
- fid.write(f'*ENDIF\n')
891
- fid.write(f'DOF,DELETE\n')
892
- fid.write(f'ET, 1,185\n')
893
- fid.write(f'NBLOCK,6,SOLID, {node_count:8d}, {node_count:8d}\n')
894
- fid.write(f'(3i9,6e20.13)\n')
895
-
896
- node_set = set()
897
- for block_id in cubit.get_block_id_list():
898
- volume_list = cubit.get_block_volumes(block_id)
899
- node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
900
- fid.write(f'{len(node_set)}\n')
901
- for node_id in node_set:
902
- coord = cubit.get_nodal_coordinates(node_id)
903
- fid.write(f'{node_id:9d}{0:9d}{0:9d}{coord[0]:20.13e}{coord[1]:20.13e}{coord[2]:20.13e}\n')
904
-
905
- fid.write(f'N,R5.3,LOC, -1\n')
906
- elem_count = 0
907
- for block_id in cubit.get_block_id_list():
908
- fid.write(f'EBLOCK, 19, SOLID\n')
909
- fid.write(f'(19i9)\n')
910
- for volume_id in cubit.get_block_volumes(block_id):
911
- hex_list = cubit.get_volume_hexes(volume_id)
912
- if len(hex_list)>0:
913
- for hex_id in hex_list:
914
- elem_count += 1
915
- node_list = cubit.get_connectivity("hex", hex_id)
916
- fid.write(f'{block_id:9d}{1:9d}{1:9d}{1:9d}{0:9d}{0:9d}{0:9d}{0:9d}{8:9d}{0:9d}{elem_count:9d}{node_list[0]:9d}{node_list[1]:9d}{node_list[2]:9d}{node_list[3]:9d}{node_list[4]:9d}{node_list[5]:9d}{node_list[6]:9d}{node_list[7]:9d}\n')
917
- wedge_list = cubit.get_volume_wedges(volume_id)
918
- if len(wedge_list)>0:
919
- for wedge_id in wedge_list:
920
- elem_count += 1
921
- node_list = cubit.get_connectivity("wedge", wedge_id)
922
- fid.write(f'{block_id:9d}{1:9d}{1:9d}{1:9d}{0:9d}{0:9d}{0:9d}{0:9d}{8:9d}{0:9d}{elem_count:9d}{node_list[0]:9d}{node_list[1]:9d}{node_list[2]:9d}{node_list[2]:9d}{node_list[3]:9d}{node_list[4]:9d}{node_list[5]:9d}{node_list[5]:9d}\n')
923
- tet_list = cubit.get_volume_tets(volume_id)
924
- if len(tet_list)>0:
925
- for tet_id in tet_list:
926
- elem_count += 1
927
- node_list = cubit.get_connectivity("tet", tet_id)
928
- fid.write(f'{block_id:9d}{1:9d}{1:9d}{1:9d}{0:9d}{0:9d}{0:9d}{0:9d}{8:9d}{0:9d}{elem_count:9d}{node_list[0]:9d}{node_list[1]:9d}{node_list[2]:9d}{node_list[2]:9d}{node_list[3]:9d}{node_list[3]:9d}{node_list[3]:9d}{node_list[3]:9d}\n')
929
- pyramid_list = cubit.get_volume_pyramids(volume_id)
930
- if len(pyramid_list)>0:
931
- for pyramid_id in pyramid_list:
932
- elem_count += 1
933
- node_list = cubit.get_connectivity("pyramid", pyramid_id)
934
- fid.write(f'{block_id:9d}{1:9d}{1:9d}{1:9d}{0:9d}{0:9d}{0:9d}{0:9d}{8:9d}{0:9d}{elem_count:9d}{node_list[0]:9d}{node_list[1]:9d}{node_list[2]:9d}{node_list[3]:9d}{node_list[4]:9d}{node_list[4]:9d}{node_list[4]:9d}{node_list[4]:9d}\n')
935
- fid.write(f' -1\n')
936
-
937
- for block_id in cubit.get_block_id_list():
938
- name = cubit.get_exodus_entity_name("block",block_id)
939
- elem_list = []
940
- volume_list = cubit.get_block_volumes(block_id)
941
- for volume_id in volume_list:
942
- hex_list = cubit.get_volume_hexes(volume_id)
943
- elem_list.extend(hex_list)
944
- wedge_list = cubit.get_volume_wedges(volume_id)
945
- elem_list.extend(wedge_list)
946
- tet_list = cubit.get_volume_tets(volume_id)
947
- elem_list.extend(tet_list)
948
- pyramid_list = cubit.get_volume_pyramids(volume_id)
949
- elem_list.extend(pyramid_list)
950
- fid.write(f'CMBLOCK,{name:<8},ELEM,{len(elem_list):8d}\n')
951
- fid.write(f'(8i10)\n')
952
- for n in range(0, len(elem_list), 8):
953
- strLine = ""
954
- for m in range(n, min(n+8, len(elem_list))):
955
- strLine += f'{elem_list[m]:10d}'
956
- fid.write(f'{strLine}\n')
957
-
958
- for nodeset_id in cubit.get_nodeset_id_list():
959
- name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
960
-
961
- node_set.clear()
962
- surface_list = cubit.get_nodeset_surfaces(nodeset_id)
963
- for surface_id in surface_list:
964
- quad_list = cubit.get_surface_quads(surface_id)
965
- for quad_id in quad_list:
966
- node_list = cubit.get_connectivity("quad", quad_id)
967
- node_set.update(node_list)
968
- tri_list = cubit.get_surface_tris(surface_id)
969
- for tri_id in tri_list:
970
- node_list = cubit.get_connectivity("tri", tri_id)
971
- node_set.update(node_list)
972
-
973
- fid.write(f'CMBLOCK,{name:<8},NODE,{len(node_set):8d}\n')
974
- fid.write(f'(8i10)\n')
975
- node_list = list(node_set)
976
- for n in range(0, len(node_list), 8):
977
- strLine = ""
978
- for m in range(n, min(n+8, len(node_list))):
979
- strLine += f'{node_list[m]:10d}'
980
- fid.write(f'{strLine}\n')
981
- return cubit
982
-
983
-
984
- ########################################################################
985
- ### ELF 1D file
986
- ########################################################################
987
-
988
- def export_1D_meg(cubit, FileName, Dim='T', MGR2=[] ):
989
-
990
- fid = open(FileName,'w',encoding='UTF-8')
991
- fid.write("BOOK MEP 3.50\n")
992
- fid.write("* ELF/MESH VERSION 7.3.0\n")
993
- fid.write("* SOLVER = ELF/MAGIC\n")
994
- fid.write("MGSC 0.001\n")
995
- fid.write("* NODE\n")
996
-
997
- node_set = set()
998
- for block_id in cubit.get_block_id_list():
999
- curve_list = cubit.get_block_curves(block_id)
1000
- node_set.update(cubit.parse_cubit_list( 'node', f'in curve {" ".join(map(str, curve_list)) }' ))
1001
- for node_id in node_set:
1002
- coord = cubit.get_nodal_coordinates(node_id)
1003
- if Dim=='T':
1004
- fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
1005
- elif Dim=='K':
1006
- fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
1007
- elif Dim=='R':
1008
- fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
1009
-
1010
- element_id = 0
1011
- fid.write("* ELEMENT T\n")
1012
- for block_id in cubit.get_block_id_list():
1013
- name = cubit.get_exodus_entity_name("block",block_id)
1014
- curve_list = cubit.get_block_curves(block_id)
1015
- for curve_id in curve_list:
1016
- edge_list = cubit.get_curve_edges(curve_id)
1017
- for edge_id in edge_list:
1018
- node_list = cubit.get_connectivity('edge', edge_id)
1019
- element_id += 1
1020
- fid.write(f"{name[0:3]}2{Dim} {element_id} 0 {block_id} {node_list[0]} {node_list[1]}\n")
1021
- fid.write("* ELEMENT\n")
1022
- fid.write("BOOK END\n")
1023
- for node_id in range(len(MGR2)):
1024
- fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
1025
- fid.close()
1026
- return cubit
1027
-
1028
- ########################################################################
1029
- ### ELF 2D file
407
+ ### ELF meg file
1030
408
  ########################################################################
1031
409
 
1032
- def export_2D_meg(cubit, FileName, Dim='T', MGR2=[]):
410
+ def export_meg(cubit, FileName, DIM='T', MGR2=[]):
1033
411
 
1034
412
  fid = open(FileName,'w',encoding='UTF-8')
1035
413
  fid.write("BOOK MEP 3.50\n")
@@ -1038,108 +416,72 @@ def export_2D_meg(cubit, FileName, Dim='T', MGR2=[]):
1038
416
  fid.write("MGSC 0.001\n")
1039
417
  fid.write("* NODE\n")
1040
418
 
1041
- node_set = set()
419
+ node_list = set()
1042
420
  for block_id in cubit.get_block_id_list():
1043
- surface_list = cubit.get_block_surfaces(block_id)
1044
- node_set.update(cubit.parse_cubit_list( 'node', f'in surface {" ".join(map(str, surface_list)) }' ))
1045
- for node_id in node_set:
421
+ elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face", "edge"]
422
+ for elem_type in elem_types:
423
+ if elem_type == "hex":
424
+ func = getattr(cubit, f"get_block_{elem_type}es")
425
+ else:
426
+ func = getattr(cubit, f"get_block_{elem_type}s")
427
+ for element_id in func(block_id):
428
+ node_ids = cubit.get_connectivity(elem_type, element_id)
429
+ node_list.update(node_ids)
430
+ for node_id in node_list:
1046
431
  coord = cubit.get_nodal_coordinates(node_id)
1047
- if Dim=='T':
432
+ if DIM=='T':
1048
433
  fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
1049
- if Dim=='K':
434
+ if DIM=='K':
1050
435
  fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
1051
- if Dim=='R':
1052
- fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
1053
-
1054
- element_id = 0
1055
- fid.write("* ELEMENT T\n")
1056
- for block_id in cubit.get_block_id_list():
1057
- name = cubit.get_exodus_entity_name("block",block_id)
1058
- for surface_id in cubit.get_block_surfaces(block_id):
1059
- tri_list = cubit.get_surface_tris(surface_id)
1060
- for tri_id in tri_list:
1061
- node_list = cubit.get_connectivity('tri',tri_id)
1062
- element_id += 1
1063
- fid.write(f"{name[0:3]}3{Dim} {element_d} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n")
1064
-
1065
- quad_list = cubit.get_surface_quads(surface_id)
1066
- for quad_id in quad_list:
1067
- node_list = cubit.get_connectivity('quad',quad_id)
1068
- element_id += 1
1069
- fid.write(f"{name[0:3]}4{Dim} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n")
1070
-
1071
- fid.write("* NODE\n")
1072
- for node_id in range(len(MGR2)):
1073
- fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
1074
- fid.write("BOOK END\n")
1075
- fid.close()
1076
- return cubit
1077
-
1078
- ########################################################################
1079
- ### ELF 3D file
1080
- ########################################################################
1081
-
1082
- def export_3D_meg(cubit, FileName, Dim='T', MGR2=[], Pyram=True):
1083
-
1084
- fid = open(FileName,'w',encoding='UTF-8')
1085
- fid.write("BOOK MEP 3.50\n")
1086
- fid.write("* ELF/MESH VERSION 7.3.0\n")
1087
- fid.write("* SOLVER = ELF/MAGIC\n")
1088
- fid.write("MGSC 0.001\n")
1089
- fid.write("* NODE\n")
1090
-
1091
- node_set = set()
1092
- for block_id in cubit.get_block_id_list():
1093
- volume_list = cubit.get_block_volumes(block_id)
1094
- node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
1095
- for node_id in node_set:
1096
- coord = cubit.get_nodal_coordinates(node_id)
1097
- if Dim=='T':
1098
- fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
1099
- if Dim=='K':
1100
- fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
1101
- if Dim=='R':
436
+ if DIM=='R':
1102
437
  fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
1103
438
 
1104
439
  element_id = 0
1105
440
  fid.write("* ELEMENT K\n")
1106
441
  for block_id in cubit.get_block_id_list():
1107
442
  name = cubit.get_exodus_entity_name("block",block_id)
1108
- for volume_id in cubit.get_block_volumes(block_id):
1109
- tet_list = cubit.get_volume_tets(volume_id)
1110
- if len(tet_list)>0:
1111
- for tet_id in tet_list:
1112
- node_list = cubit.get_connectivity('tet',tet_id)
1113
- node_list = cubit.get_connectivity("tet", tet_id)
1114
- element_id += 1
1115
- fid.write(f"{name[0:3]}4{Dim} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n")
1116
- hex_list = cubit.get_volume_hexes(volume_id)
1117
- if len(hex_list)>0:
1118
- for hex_id in hex_list:
1119
- node_list = cubit.get_connectivity("hex", hex_id)
1120
- element_id += 1
1121
- fid.write(f"{name[0:3]}8{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")
1122
- wedge_list = cubit.get_volume_wedges(volume_id)
1123
- if len(wedge_list)>0:
1124
- for wedge_id in wedge_list:
1125
- node_list = cubit.get_connectivity("wedge", wedge_id)
1126
- element_id += 1
1127
- fid.write(f"{name[0:3]}6{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")
1128
443
 
1129
- pyramid_list = cubit.get_volume_pyramids(volume_id)
1130
- if len(pyramid_list)>0:
1131
- for pyramid_id in pyramid_list:
1132
- node_list = cubit.get_connectivity('pyramid',pyramid_id)
1133
- if Pyram:
1134
- # element_id += 1
1135
- # fid.write(f"{name}5T {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} \n")
1136
- element_id += 1
1137
- fid.write(f"{name[0:3]}4{Dim} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[3]} {node_list[4]} \n")
1138
- element_id += 1
1139
- fid.write(f"{name[0:3]}4{Dim} {element_id} 0 {block_id} {node_list[1]} {node_list[2]} {node_list[3]} {node_list[4]} \n")
1140
- else:
1141
- element_id += 1
1142
- fid.write(f"{name[0:3]}8{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")
444
+ tet_list = cubit.get_block_tets(block_id)
445
+ for tet_id in tet_list:
446
+ node_list = cubit.get_connectivity('tet',tet_id)
447
+ element_id += 1
448
+ 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")
449
+
450
+ hex_list = cubit.get_block_hexes(block_id)
451
+ for hex_id in hex_list:
452
+ node_list = cubit.get_connectivity('hex',hex_id)
453
+ element_id += 1
454
+ 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")
455
+
456
+ wedge_list = cubit.get_block_wedges(block_id)
457
+ for wedge_id in wedge_list:
458
+ node_list = cubit.get_connectivity('wedge',wedge_id)
459
+ element_id += 1
460
+ 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")
461
+
462
+ pyramid_list = cubit.get_block_pyramids(block_id)
463
+ for pyramid_id in pyramid_list:
464
+ node_list = cubit.get_connectivity('pyramid',pyramid_id)
465
+ element_id += 1
466
+ 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")
467
+
468
+ tri_list = cubit.get_block_tris(block_id)
469
+ for tri_id in tri_list:
470
+ node_list = cubit.get_connectivity('tri',tri_id)
471
+ element_id += 1
472
+ fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n")
473
+
474
+ quad_list = cubit.get_block_faces(block_id)
475
+ for quad_id in quad_list:
476
+ node_list = cubit.get_connectivity('quad',quad_id)
477
+ element_id += 1
478
+ 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")
479
+
480
+ edge_list = cubit.get_block_edges(block_id)
481
+ for edge_id in edge_list:
482
+ node_list = cubit.get_connectivity('edge',edge_id)
483
+ element_id += 1
484
+ fid.write(f"{name[0:4]}{DIM} {element_id} 0 {block_id} {node_list[0]} {node_list[1]}\n")
1143
485
 
1144
486
  fid.write("* NODE\n")
1145
487
  for node_id in range(len(MGR2)):
@@ -1152,7 +494,7 @@ def export_3D_meg(cubit, FileName, Dim='T', MGR2=[], Pyram=True):
1152
494
  ### vtk format
1153
495
  ########################################################################
1154
496
 
1155
- def export_3D_vtk(cubit, FileName):
497
+ def export_vtk(cubit, FileName):
1156
498
 
1157
499
  fid = open(FileName,'w')
1158
500
  fid.write('# vtk DataFile Version 3.0\n')
@@ -1166,31 +508,24 @@ def export_3D_vtk(cubit, FileName):
1166
508
  coord = cubit.get_nodal_coordinates(node_id)
1167
509
  fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
1168
510
 
1169
- tet_list = []
1170
- hex_list = []
1171
- wedge_list = []
1172
- pyramid_list = []
1173
- volume_id_list = []
1174
- for block_id in cubit.get_block_id_list():
1175
- for volume_id in cubit.get_block_volumes(block_id):
1176
- tet_list += cubit.get_volume_tets(volume_id)
1177
- volume_id_list += [volume_id]*(len(cubit.get_volume_tets(volume_id)))
1178
-
1179
- for block_id in cubit.get_block_id_list():
1180
- for volume_id in cubit.get_block_volumes(block_id):
1181
- hex_list += cubit.get_volume_hexes(volume_id)
1182
- volume_id_list += [volume_id]*(len(cubit.get_volume_hexes(volume_id)))
511
+ hex_list = set()
512
+ tet_list = set()
513
+ wedge_list = set()
514
+ pyramid_list = set()
515
+ tri_list = set()
516
+ quad_list = set()
517
+ edge_list = set()
1183
518
 
1184
519
  for block_id in cubit.get_block_id_list():
1185
- for volume_id in cubit.get_block_volumes(block_id):
1186
- wedge_list += cubit.get_volume_wedges(volume_id)
1187
- volume_id_list += [volume_id]*(len(cubit.get_volume_wedges(volume_id)))
1188
- for block_id in cubit.get_block_id_list():
1189
- for volume_id in cubit.get_block_volumes(block_id):
1190
- pyramid_list += cubit.get_volume_pyramids(volume_id)
1191
- volume_id_list += [volume_id]*(len(cubit.get_volume_pyramids(volume_id)))
1192
-
1193
- fid.write(f'CELLS {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list)} {5*len(tet_list) + 9*len(hex_list) + 7*len(wedge_list) + 6*len(pyramid_list)}\n' )
520
+ tet_list.update(cubit.get_block_tets(block_id))
521
+ hex_list.update(cubit.get_block_hexes(block_id))
522
+ wedge_list.update(cubit.get_block_wedges(block_id))
523
+ pyramid_list.update(cubit.get_block_pyramids(block_id))
524
+ tri_list.update(cubit.get_block_tris(block_id))
525
+ quad_list.update(cubit.get_block_faces(block_id))
526
+ edge_list.update(cubit.get_block_edges(block_id))
527
+
528
+ 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)} {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)}\n' )
1194
529
  for tet_id in tet_list:
1195
530
  node_list = cubit.get_connectivity("tet", tet_id)
1196
531
  fid.write(f'4 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1}\n')
@@ -1203,8 +538,17 @@ def export_3D_vtk(cubit, FileName):
1203
538
  for pyramid_id in pyramid_list:
1204
539
  node_list = cubit.get_connectivity("pyramid", pyramid_id)
1205
540
  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')
1206
-
1207
- fid.write(f'CELL_TYPES {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list)}\n')
541
+ for tri_id in tri_list:
542
+ node_list = cubit.get_connectivity("tri", tri_id)
543
+ fid.write(f'3 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} \n')
544
+ for quad_id in quad_list:
545
+ node_list = cubit.get_connectivity("quad", quad_id)
546
+ fid.write(f'4 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1} \n')
547
+ for edge_id in edge_list:
548
+ node_list = cubit.get_connectivity("edge", edge_id)
549
+ fid.write(f'2 {node_list[0]-1} {node_list[1]-1} \n')
550
+
551
+ 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)}\n')
1208
552
  for tet_id in tet_list:
1209
553
  fid.write('10\n')
1210
554
  for hex_id in hex_list:
@@ -1213,82 +557,28 @@ def export_3D_vtk(cubit, FileName):
1213
557
  fid.write('13\n')
1214
558
  for pyramid_id in pyramid_list:
1215
559
  fid.write('14\n')
1216
- fid.write(f'CELL_DATA {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list)}\n')
560
+ for tri_id in tri_list:
561
+ fid.write('5\n')
562
+ for quad_id in quad_list:
563
+ fid.write('9\n')
564
+ for edge_id in edge_list:
565
+ fid.write('3\n')
566
+ 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)}\n')
1217
567
  fid.write('SCALARS scalars float\n')
1218
568
  fid.write('LOOKUP_TABLE default\n')
1219
- for volume_id in volume_id_list:
1220
- fid.write(f'{volume_id}\n')
1221
- fid.close()
1222
- return cubit
1223
-
1224
- ########################################################################
1225
- ### Lukas FEM 2D file
1226
- ########################################################################
1227
-
1228
- def export_2D_geo_mesh(cubit, FileName):
1229
-
1230
- import numpy
1231
- import scipy.io
1232
-
1233
- nodes = []
1234
- node_list = []
1235
-
1236
- N = cubit.get_node_count()
1237
- M = cubit.get_tri_count()
1238
-
1239
- node_set = set()
1240
- for block_id in cubit.get_block_id_list():
1241
- volume_list = cubit.get_block_volumes(block_id)
1242
- node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
1243
-
1244
- for node_id in node_set:
1245
- coord = cubit.get_nodal_coordinates(node_id)
1246
- nodes.append([coord[0],coord[1]])
1247
-
1248
- for nodeset_id in cubit.get_nodeset_id_list():
1249
- name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
1250
- curve_list = cubit.get_nodeset_curves(nodeset_id)
1251
- node_list = []
1252
- for curve_id in curve_list:
1253
- node_list += cubit.get_curve_nodes(curve_id)
1254
- nodeset = numpy.array([(name, node_list)], dtype=[('name', 'U20'), ('DBCnodes', 'O')])
1255
- try:
1256
- nodesets = append(nodesets,nodeset)
1257
- except:
1258
- nodesets = nodeset
1259
-
1260
- conn_matrix = numpy.zeros((M,3))
1261
- center_x = numpy.zeros((M))
1262
- center_y = numpy.zeros((M))
1263
- block_count = cubit.get_block_count()
1264
- regions = numpy.rec.array([("", [], [])]*(block_count), dtype=[('name', 'U20'), ('Elements', 'O'), ('Nodes', 'O')])
1265
-
1266
- for block_id in cubit.get_block_id_list():
1267
- Elements = []
1268
- name = cubit.get_exodus_entity_name("block",block_id)
1269
- surface_list = cubit.get_block_surfaces(block_id)
1270
- Nodes = []
1271
- Elements = []
1272
- for surface_id in surface_list:
1273
- tri_list = cubit.get_surface_tris(surface_id)
1274
- Elements += tri_list
1275
- for tri_id in tri_list:
1276
- x = []
1277
- y = []
1278
- node_list = cubit.get_connectivity('tri',tri_id)
1279
- Nodes += node_list
1280
- conn_matrix[tri_id-1,:] = node_list
1281
- for node_id in node_list:
1282
- coord = cubit.get_nodal_coordinates(node_id)
1283
- x.append(coord[0])
1284
- y.append(coord[1])
1285
- center_x[tri_id-1] = numpy.mean(x)
1286
- center_y[tri_id-1] = numpy.mean(y)
1287
- regions[block_id-1][0] = name
1288
- regions[block_id-1][1] = Elements
1289
- regions[block_id-1][2] = Nodes
1290
-
1291
- geo = {'conn_matrix':conn_matrix, 'nodes':nodes, 'M':M, 'N':N, 'nodesets':nodesets , 'center_x':center_x, 'center_y':center_y, 'regions':regions }
1292
- scipy.io.savemat(FileName, {'geo': geo}, format='5', long_field_names=True)
569
+ for tet_id in tet_list:
570
+ fid.write(f'{4}\n')
571
+ for hex_id in hex_list:
572
+ fid.write(f'{8}\n')
573
+ for wedge_id in wedge_list:
574
+ fid.write(f'{6}\n')
575
+ for pyramid_id in pyramid_list:
576
+ fid.write(f'{5}\n')
577
+ for tri_id in tri_list:
578
+ fid.write(f'{3}\n')
579
+ for quad_id in quad_list:
580
+ fid.write(f'{4}\n')
581
+ for edge_id in edge_list:
582
+ fid.write(f'{2}\n')
1293
583
  return cubit
1294
584