Coreform-Cubit-Mesh-Export 0.9.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.
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Coreform_Cubit_Mesh_Export
|
|
3
|
+
Version: 0.9.1
|
|
4
|
+
Summary: Cubit_Mesh_Export: Cubit mesh export to Gmsh format
|
|
5
|
+
Home-page: https://github.com/ksugahar/Coreform_Cubit_Mesh_Export
|
|
6
|
+
Download-URL: https://github.com/ksugahar/Coreform_Cubit_Mesh_Export
|
|
7
|
+
Author: Kengo Sugahara
|
|
8
|
+
Author-email: Kengo Sugahara <ksugahar@gmail.com>
|
|
9
|
+
Maintainer: Kengo Sugahara
|
|
10
|
+
Maintainer-email: ksugahar@gmail.com
|
|
11
|
+
Project-URL: Homepage, https://github.com/ksugahar/Coreform_Cubit_Mesh_Export
|
|
12
|
+
Project-URL: Repository, https://github.com/ksugahar/Coreform_Cubit_Mesh_Export
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Requires-Python: >=3.7
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Requires-Dist: numpy>=1.20.3
|
|
25
|
+
Requires-Dist: scipy>=1.6.3
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: download-url
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: maintainer
|
|
30
|
+
Dynamic: maintainer-email
|
|
31
|
+
Dynamic: requires-python
|
|
32
|
+
|
|
33
|
+
# インストール方法
|
|
34
|
+
|
|
35
|
+
## PyPIから直接インストール(推奨)
|
|
36
|
+
```
|
|
37
|
+
pip install --upgrade Coreform_Cubit_Mesh_Export
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Cubit内蔵Pythonの場合:
|
|
41
|
+
```
|
|
42
|
+
cd "C:\Program Files\Coreform Cubit 2025.3\bin\python3\"
|
|
43
|
+
python.exe -m pip install --upgrade Coreform_Cubit_Mesh_Export
|
|
44
|
+
```
|
|
45
|
+
----
|
|
46
|
+
# サポートしているファイル
|
|
47
|
+
- gmshファイル ver.2
|
|
48
|
+
- gmshファイル ver.4 (不完全)
|
|
49
|
+
- Nastranファイル (2D)
|
|
50
|
+
- Nastranファイル (3D)
|
|
51
|
+
- ELF用ファイル (2D)
|
|
52
|
+
- ELF用ファイル (3D)
|
|
53
|
+
- vtkファイル (メッシュのみ)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
# 使い方
|
|
57
|
+
Cubitでメッシュ生成後にpythonを実行するコマンドを入力。
|
|
58
|
+
play "Pythonスクリプト名.py"
|
|
59
|
+
を実行する。
|
|
60
|
+
"Pythonスクリプト名.py" の中身は例えば、
|
|
61
|
+
```
|
|
62
|
+
FileName = 'O:/test.nas'
|
|
63
|
+
import cubit_mesh_export
|
|
64
|
+
cubit_mesh_export.export_3D_Nastran(cubit, FileName)
|
|
65
|
+
```
|
|
66
|
+
---
|
|
67
|
+
# 関数一覧
|
|
68
|
+
- export_3D_gmsh_ver2
|
|
69
|
+
- export_3D_gmsh_ver4
|
|
70
|
+
- export_2D_Nastran
|
|
71
|
+
- export_3D_Nastran
|
|
72
|
+
- export_2D_meg
|
|
73
|
+
- export_3D_meg
|
|
74
|
+
- export_3D_vtk
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
cubit_mesh_export.py,sha256=cfsC-LKFBalsgt-H0dRkkn5cjxBlrFUplA4u0fUUj7I,51363
|
|
2
|
+
coreform_cubit_mesh_export-0.9.1.dist-info/METADATA,sha256=QD9zjDbnEPtHwo9eniZgv8fu9GOPXSx96KkNqEWaB4E,2265
|
|
3
|
+
coreform_cubit_mesh_export-0.9.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
+
coreform_cubit_mesh_export-0.9.1.dist-info/top_level.txt,sha256=-K1cfrL0sGC26lWxEpEVcVu6kQQc0YQWy-noAn3rMRk,18
|
|
5
|
+
coreform_cubit_mesh_export-0.9.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cubit_mesh_export
|
cubit_mesh_export.py
ADDED
|
@@ -0,0 +1,1290 @@
|
|
|
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
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
68
|
+
if len(tri_list)>0:
|
|
69
|
+
for tri_id in tri_list:
|
|
70
|
+
node_list = cubit.get_connectivity("tri", tri_id)
|
|
71
|
+
fid.write(f'{node_list[0]} {node_list[1]} {node_list[2]} {nodeset_id}\n')
|
|
72
|
+
for surface_id in nodeset_surface_list:
|
|
73
|
+
quad_list += cubit.get_surface_quads(surface_id)
|
|
74
|
+
tri_list += cubit.get_surface_tris(surface_id)
|
|
75
|
+
|
|
76
|
+
fid.write("\n")
|
|
77
|
+
fid.write("End\n")
|
|
78
|
+
fid.close()
|
|
79
|
+
return cubit
|
|
80
|
+
|
|
81
|
+
########################################################################
|
|
82
|
+
### Gmsh format version 2
|
|
83
|
+
########################################################################
|
|
84
|
+
|
|
85
|
+
def export_2D_gmsh_ver2(cubit, FileName):
|
|
86
|
+
|
|
87
|
+
with open(FileName, 'w') as fid:
|
|
88
|
+
|
|
89
|
+
fid.write("$MeshFormat\n")
|
|
90
|
+
fid.write("2.2 0 8\n")
|
|
91
|
+
fid.write("$EndMeshFormat\n")
|
|
92
|
+
|
|
93
|
+
fid.write("$PhysicalNames\n")
|
|
94
|
+
fid.write(f'{cubit.get_nodeset_count() + cubit.get_block_count()}\n')
|
|
95
|
+
|
|
96
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
97
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
98
|
+
fid.write(f'1 {nodeset_id} "{name}"\n')
|
|
99
|
+
|
|
100
|
+
for block_id in cubit.get_block_id_list():
|
|
101
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
102
|
+
fid.write(f'2 {block_id} "{name}"\n')
|
|
103
|
+
fid.write('$EndPhysicalNames\n')
|
|
104
|
+
|
|
105
|
+
fid.write("$Nodes\n")
|
|
106
|
+
|
|
107
|
+
node_set = set()
|
|
108
|
+
for block_id in cubit.get_block_id_list():
|
|
109
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
110
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in surface {" ".join(map(str, surface_list)) }' ))
|
|
111
|
+
fid.write(f'{len(node_set)}\n')
|
|
112
|
+
for node_id in node_set:
|
|
113
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
114
|
+
fid.write(f'{node_id} {coord[0]} {coord[1]} {coord[2]}\n')
|
|
115
|
+
fid.write('$EndNodes\n')
|
|
116
|
+
|
|
117
|
+
edge_list = []
|
|
118
|
+
quad_list = []
|
|
119
|
+
tri_list = []
|
|
120
|
+
|
|
121
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
122
|
+
curve_list = cubit.get_nodeset_curves(nodeset_id)
|
|
123
|
+
for curve_id in curve_list:
|
|
124
|
+
edge_list += cubit.get_curve_edges(curve_id)
|
|
125
|
+
|
|
126
|
+
for block_id in cubit.get_block_id_list():
|
|
127
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
128
|
+
for surface_id in surface_list:
|
|
129
|
+
quad_list += cubit.get_surface_quads(surface_id)
|
|
130
|
+
tri_list += cubit.get_surface_tris(surface_id)
|
|
131
|
+
|
|
132
|
+
Elems = 0
|
|
133
|
+
fid.write('$Elements\n')
|
|
134
|
+
fid.write(f'{len(edge_list) + len(quad_list) + len(tri_list)}\n')
|
|
135
|
+
|
|
136
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
137
|
+
curve_list = cubit.get_nodeset_curves(nodeset_id)
|
|
138
|
+
for curve_id in curve_list:
|
|
139
|
+
edge_list = cubit.get_curve_edges(curve_id)
|
|
140
|
+
if len(edge_list)>0:
|
|
141
|
+
for edge_id in edge_list:
|
|
142
|
+
Elems += 1
|
|
143
|
+
node_list = cubit.get_connectivity('edge', edge_id)
|
|
144
|
+
fid.write(f'{Elems} {1} {2} {nodeset_id} {curve_id} {node_list[0]} {node_list[1]}\n')
|
|
145
|
+
|
|
146
|
+
for block_id in cubit.get_block_id_list():
|
|
147
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
148
|
+
for surface_id in surface_list:
|
|
149
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
150
|
+
if len(tri_list)>0:
|
|
151
|
+
for tri_id in tri_list:
|
|
152
|
+
Elems += 1
|
|
153
|
+
node_list = cubit.get_expanded_connectivity("tri", tri_id)
|
|
154
|
+
if len(node_list)==3:
|
|
155
|
+
fid.write(f'{Elems} {2} {2} {block_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
|
|
156
|
+
if len(node_list)==6:
|
|
157
|
+
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')
|
|
158
|
+
if len(node_list)==7:
|
|
159
|
+
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')
|
|
160
|
+
|
|
161
|
+
quad_list = cubit.get_surface_quads(surface_id)
|
|
162
|
+
if len(quad_list)>0:
|
|
163
|
+
for quad_id in quad_list:
|
|
164
|
+
Elems += 1
|
|
165
|
+
node_list = cubit.get_expanded_connectivity("quad", quad_id)
|
|
166
|
+
if len(node_list)==4:
|
|
167
|
+
fid.write(f'{Elems} {3} {2} {block_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
168
|
+
if len(node_list)==8:
|
|
169
|
+
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')
|
|
170
|
+
if len(node_list)==9:
|
|
171
|
+
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')
|
|
172
|
+
|
|
173
|
+
fid.write('$EndElements\n')
|
|
174
|
+
|
|
175
|
+
fid.close()
|
|
176
|
+
return cubit
|
|
177
|
+
|
|
178
|
+
########################################################################
|
|
179
|
+
### Gmsh format version 2
|
|
180
|
+
########################################################################
|
|
181
|
+
|
|
182
|
+
def export_3D_gmsh_ver2(cubit, FileName):
|
|
183
|
+
|
|
184
|
+
with open(FileName, 'w') as fid:
|
|
185
|
+
|
|
186
|
+
fid.write("$MeshFormat\n")
|
|
187
|
+
fid.write("2.2 0 8\n")
|
|
188
|
+
fid.write("$EndMeshFormat\n")
|
|
189
|
+
|
|
190
|
+
fid.write("$PhysicalNames\n")
|
|
191
|
+
fid.write(f'{cubit.get_nodeset_count() + cubit.get_block_count()}\n')
|
|
192
|
+
|
|
193
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
194
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
195
|
+
fid.write(f'2 {nodeset_id} "{name}"\n')
|
|
196
|
+
|
|
197
|
+
for block_id in cubit.get_block_id_list():
|
|
198
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
199
|
+
fid.write(f'3 {block_id} "{name}"\n')
|
|
200
|
+
fid.write('$EndPhysicalNames\n')
|
|
201
|
+
|
|
202
|
+
fid.write("$Nodes\n")
|
|
203
|
+
|
|
204
|
+
node_set = set()
|
|
205
|
+
for block_id in cubit.get_block_id_list():
|
|
206
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
207
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
|
|
208
|
+
fid.write(f'{len(node_set)}\n')
|
|
209
|
+
for node_id in node_set:
|
|
210
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
211
|
+
fid.write(f'{node_id} {coord[0]} {coord[1]} {coord[2]}\n')
|
|
212
|
+
fid.write('$EndNodes\n')
|
|
213
|
+
|
|
214
|
+
hex_list = []
|
|
215
|
+
tet_list = []
|
|
216
|
+
wedge_list = []
|
|
217
|
+
pyramid_list = []
|
|
218
|
+
quad_list = []
|
|
219
|
+
tri_list = []
|
|
220
|
+
|
|
221
|
+
for block_id in cubit.get_block_id_list():
|
|
222
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
223
|
+
for volume_id in volume_list:
|
|
224
|
+
hex_list += cubit.get_volume_hexes(volume_id)
|
|
225
|
+
tet_list += cubit.get_volume_tets(volume_id)
|
|
226
|
+
wedge_list += cubit.get_volume_wedges(volume_id)
|
|
227
|
+
pyramid_list += cubit.get_volume_pyramids(volume_id)
|
|
228
|
+
|
|
229
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
230
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
231
|
+
for surface_id in surface_list:
|
|
232
|
+
quad_list += cubit.get_surface_quads(surface_id)
|
|
233
|
+
tri_list += cubit.get_surface_tris(surface_id)
|
|
234
|
+
|
|
235
|
+
Elems = 0
|
|
236
|
+
fid.write('$Elements\n')
|
|
237
|
+
fid.write(f'{len(hex_list) + len(tet_list) + len(wedge_list) + len(pyramid_list) + len(quad_list) + len(tri_list)}\n')
|
|
238
|
+
|
|
239
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
240
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
241
|
+
for surface_id in surface_list:
|
|
242
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
243
|
+
if len(tri_list)>0:
|
|
244
|
+
for tri_id in tri_list:
|
|
245
|
+
Elems += 1
|
|
246
|
+
node_list = cubit.get_expanded_connectivity("tri", tri_id)
|
|
247
|
+
if len(node_list)==3:
|
|
248
|
+
fid.write(f'{Elems} {2} {2} {nodeset_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]}\n')
|
|
249
|
+
if len(node_list)==6:
|
|
250
|
+
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')
|
|
251
|
+
if len(node_list)==7:
|
|
252
|
+
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')
|
|
253
|
+
|
|
254
|
+
quad_list = cubit.get_surface_quads(surface_id)
|
|
255
|
+
if len(quad_list)>0:
|
|
256
|
+
for quad_id in quad_list:
|
|
257
|
+
Elems += 1
|
|
258
|
+
node_list = cubit.get_expanded_connectivity("quad", quad_id)
|
|
259
|
+
if len(node_list)==4:
|
|
260
|
+
fid.write(f'{Elems} {3} {2} {nodeset_id} {surface_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
261
|
+
if len(node_list)==8:
|
|
262
|
+
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')
|
|
263
|
+
if len(node_list)==9:
|
|
264
|
+
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')
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
for block_id in cubit.get_block_id_list():
|
|
268
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
269
|
+
for volume_id in volume_list:
|
|
270
|
+
|
|
271
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
272
|
+
if len(tet_list)>0:
|
|
273
|
+
for tet_id in tet_list:
|
|
274
|
+
Elems += 1
|
|
275
|
+
node_list = cubit.get_expanded_connectivity("tet", tet_id)
|
|
276
|
+
if len(node_list)==4:
|
|
277
|
+
fid.write(f'{Elems} {4} {2} {block_id} {volume_id} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
278
|
+
if len(node_list)==10:
|
|
279
|
+
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[8]} {node_list[9]}\n')
|
|
280
|
+
if len(node_list)==11:
|
|
281
|
+
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')
|
|
282
|
+
|
|
283
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
284
|
+
if len(hex_list)>0:
|
|
285
|
+
for hex_id in hex_list:
|
|
286
|
+
Elems += 1
|
|
287
|
+
node_list = cubit.get_expanded_connectivity("hex", hex_id)
|
|
288
|
+
if len(node_list)==8:
|
|
289
|
+
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')
|
|
290
|
+
if len(node_list)==20:
|
|
291
|
+
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')
|
|
292
|
+
|
|
293
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
294
|
+
if len(wedge_list)>0:
|
|
295
|
+
for wedge_id in wedge_list:
|
|
296
|
+
Elems += 1
|
|
297
|
+
node_list = cubit.get_connectivity("wedge", wedge_id)
|
|
298
|
+
if len(node_list)==6:
|
|
299
|
+
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')
|
|
300
|
+
if len(node_list)==15:
|
|
301
|
+
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')
|
|
302
|
+
|
|
303
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
304
|
+
if len(pyramid_list)>0:
|
|
305
|
+
for pyramid_id in pyramid_list:
|
|
306
|
+
Elems += 1
|
|
307
|
+
node_list = cubit.get_connectivity("pyramid", pyramid_id)
|
|
308
|
+
if len(node_list)==6:
|
|
309
|
+
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')
|
|
310
|
+
if len(node_list)==13:
|
|
311
|
+
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')
|
|
312
|
+
|
|
313
|
+
fid.write('$EndElements\n')
|
|
314
|
+
|
|
315
|
+
fid.close()
|
|
316
|
+
return cubit
|
|
317
|
+
|
|
318
|
+
########################################################################
|
|
319
|
+
### Gmsh format version 4
|
|
320
|
+
########################################################################
|
|
321
|
+
|
|
322
|
+
def export_3D_gmsh_ver4(cubit, FileName):
|
|
323
|
+
|
|
324
|
+
nodeset_surface_count = 0
|
|
325
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
326
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
327
|
+
for surface_id in surface_list:
|
|
328
|
+
nodeset_surface_count += 1
|
|
329
|
+
|
|
330
|
+
block_volume_count = 0
|
|
331
|
+
for block_id in cubit.get_block_id_list():
|
|
332
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
333
|
+
for volume_id in volume_list:
|
|
334
|
+
block_volume_count += 1
|
|
335
|
+
|
|
336
|
+
with open(FileName, 'w') as fid:
|
|
337
|
+
|
|
338
|
+
fid.write('$MeshFormat\n')
|
|
339
|
+
fid.write('4.1 0 8\n')
|
|
340
|
+
fid.write('$EndMeshFormat\n')
|
|
341
|
+
|
|
342
|
+
fid.write('$PhysicalNames\n')
|
|
343
|
+
fid.write(f'{cubit.get_nodeset_count() + cubit.get_block_count()}\n')
|
|
344
|
+
|
|
345
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
346
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
347
|
+
fid.write(f'2 {nodeset_id} "{name}"\n')
|
|
348
|
+
for block_id in cubit.get_block_id_list():
|
|
349
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
350
|
+
fid.write(f'3 {block_id} "{name}"\n')
|
|
351
|
+
fid.write('$EndPhysicalNames\n')
|
|
352
|
+
|
|
353
|
+
fid.write('$Entities\n')
|
|
354
|
+
fid.write(f'{0} {0} {nodeset_surface_count} {block_volume_count}\n')
|
|
355
|
+
|
|
356
|
+
# for nodeset_id in cubit.get_nodeset_id_list():
|
|
357
|
+
# surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
358
|
+
# for surface_id in surface_list:
|
|
359
|
+
# vertex_list = cubit.get_relatives("surface", surface_id, "vertex")
|
|
360
|
+
# for vertex_id in vertex_list:
|
|
361
|
+
# x = cubit.vertex(vertex_id).coordinates()[0]
|
|
362
|
+
# y = cubit.vertex(vertex_id).coordinates()[1]
|
|
363
|
+
# z = cubit.vertex(vertex_id).coordinates()[2]
|
|
364
|
+
# fid.write(f'{vertex_id} {x} {y} {z} {1} {nodeset_id}\n')
|
|
365
|
+
|
|
366
|
+
# for nodeset_id in cubit.get_nodeset_id_list():
|
|
367
|
+
# surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
368
|
+
# for surface_id in surface_list:
|
|
369
|
+
# curve_list = cubit.get_relatives("surface", surface_id, "curve")
|
|
370
|
+
# for curve_id in curve_list:
|
|
371
|
+
# bounding_box = cubit.get_bounding_box("curve", curve_id)
|
|
372
|
+
# minx = bounding_box[0]
|
|
373
|
+
# maxx = bounding_box[1]
|
|
374
|
+
# miny = bounding_box[3]
|
|
375
|
+
# maxy = bounding_box[4]
|
|
376
|
+
# minz = bounding_box[6]
|
|
377
|
+
# maxz = bounding_box[7]
|
|
378
|
+
# vertex_list = cubit.get_relatives("curve", curve_id, "vertex")
|
|
379
|
+
# fid.write(f'{curve_id} {minx} {miny} {minz} {maxx} {maxy} {maxz} {1} {nodeset_id} {len(vertex_list)}')
|
|
380
|
+
# for vertex_id in vertex_list:
|
|
381
|
+
# fid.write(f' {vertex_id}')
|
|
382
|
+
# fid.write(f'\n')
|
|
383
|
+
|
|
384
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
385
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
386
|
+
for surface_id in surface_list:
|
|
387
|
+
bounding_box = cubit.get_bounding_box("surface", surface_id)
|
|
388
|
+
minx = bounding_box[0]
|
|
389
|
+
maxx = bounding_box[1]
|
|
390
|
+
miny = bounding_box[3]
|
|
391
|
+
maxy = bounding_box[4]
|
|
392
|
+
minz = bounding_box[6]
|
|
393
|
+
maxz = bounding_box[7]
|
|
394
|
+
fid.write(f'{surface_id} {minx} {miny} {minz} {maxx} {maxy} {maxz} {1} {nodeset_id} {0}\n')
|
|
395
|
+
|
|
396
|
+
for block_id in cubit.get_block_id_list():
|
|
397
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
398
|
+
bounding_box = cubit.get_bounding_box("volume", volume_id)
|
|
399
|
+
minx = bounding_box[0]
|
|
400
|
+
maxx = bounding_box[1]
|
|
401
|
+
miny = bounding_box[3]
|
|
402
|
+
maxy = bounding_box[4]
|
|
403
|
+
minz = bounding_box[6]
|
|
404
|
+
maxz = bounding_box[7]
|
|
405
|
+
fid.write(f'{volume_id} {minx} {miny} {minz} {maxx} {maxy} {maxz} {1} {block_id} {nodeset_surface_count}')
|
|
406
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
407
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
408
|
+
for surface_id in surface_list:
|
|
409
|
+
fid.write(f' {surface_id}')
|
|
410
|
+
fid.write(f'\n')
|
|
411
|
+
|
|
412
|
+
fid.write('$EndEntities\n')
|
|
413
|
+
|
|
414
|
+
counts = 0
|
|
415
|
+
node_all_set = set()
|
|
416
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
417
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
418
|
+
for surface_id in surface_list:
|
|
419
|
+
node_list = cubit.get_surface_nodes(surface_id)
|
|
420
|
+
if len(node_list) > 0:
|
|
421
|
+
node_all_set.update(node_list)
|
|
422
|
+
counts += 1
|
|
423
|
+
|
|
424
|
+
for block_id in cubit.get_block_id_list():
|
|
425
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
426
|
+
node_list = cubit.parse_cubit_list( "node", f"in volume {volume_id}" )
|
|
427
|
+
if len(node_list) > 0:
|
|
428
|
+
node_all_set.update(node_list)
|
|
429
|
+
counts += 1
|
|
430
|
+
|
|
431
|
+
fid.write('$Nodes\n')
|
|
432
|
+
fid.write(f'{counts} {len(node_all_set)} {min(node_all_set)} {max(node_all_set)}\n')
|
|
433
|
+
|
|
434
|
+
node_all_set.clear()
|
|
435
|
+
|
|
436
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
437
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
438
|
+
for surface_id in surface_list:
|
|
439
|
+
node_list = cubit.get_surface_nodes(surface_id)
|
|
440
|
+
node_list = set(node_list) - node_all_set
|
|
441
|
+
if len(node_list) > 0:
|
|
442
|
+
node_all_set.update(node_list)
|
|
443
|
+
fid.write(f'2 {surface_id} 0 {len(node_list)}\n')
|
|
444
|
+
for node_id in node_list:
|
|
445
|
+
fid.write(f'{node_id}\n')
|
|
446
|
+
for node_id in node_list:
|
|
447
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
448
|
+
fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
|
|
449
|
+
|
|
450
|
+
for block_id in cubit.get_block_id_list():
|
|
451
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
452
|
+
node_list = cubit.parse_cubit_list( "node", f"in volume {volume_id}" )
|
|
453
|
+
node_list = set(node_list) - node_all_set
|
|
454
|
+
if len(node_list) > 0:
|
|
455
|
+
node_all_set.update(node_list)
|
|
456
|
+
fid.write(f'3 {volume_id} 0 {len(node_list)}\n')
|
|
457
|
+
for node_id in node_list:
|
|
458
|
+
fid.write(f'{node_id}\n')
|
|
459
|
+
for node_id in node_list:
|
|
460
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
461
|
+
fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
|
|
462
|
+
|
|
463
|
+
fid.write('$EndNodes\n')
|
|
464
|
+
|
|
465
|
+
tri_all_list = []
|
|
466
|
+
quad_all_list = []
|
|
467
|
+
tet_all_list = []
|
|
468
|
+
hex_all_list = []
|
|
469
|
+
wedge_all_list = []
|
|
470
|
+
|
|
471
|
+
fid.write('$Elements\n')
|
|
472
|
+
|
|
473
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
474
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
475
|
+
for surface_id in surface_list:
|
|
476
|
+
tri_all_list += cubit.get_surface_tris(surface_id)
|
|
477
|
+
quad_all_list += cubit.get_surface_quads(surface_id)
|
|
478
|
+
|
|
479
|
+
for block_id in cubit.get_block_id_list():
|
|
480
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
481
|
+
tet_all_list += cubit.get_volume_tets(volume_id)
|
|
482
|
+
hex_all_list += cubit.get_volume_hexes(volume_id)
|
|
483
|
+
wedge_all_list += cubit.get_volume_wedges(volume_id)
|
|
484
|
+
|
|
485
|
+
elementTag = 0
|
|
486
|
+
|
|
487
|
+
all_list = quad_all_list + tri_all_list + hex_all_list + tet_all_list + wedge_all_list
|
|
488
|
+
fid.write(f'{ nodeset_surface_count + block_volume_count} {len(all_list)} {min(all_list)} {max(all_list)}\n')
|
|
489
|
+
|
|
490
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
491
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
492
|
+
for surface_id in surface_list:
|
|
493
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
494
|
+
if len(tri_list)>0:
|
|
495
|
+
fid.write(f'2 {surface_id} 2 {len(tri_list)}\n')
|
|
496
|
+
for tri_id in tri_list:
|
|
497
|
+
node_list = cubit.get_connectivity("tri", tri_id)
|
|
498
|
+
elementTag +=1
|
|
499
|
+
fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]}\n')
|
|
500
|
+
|
|
501
|
+
quad_list = cubit.get_surface_quads(surface_id)
|
|
502
|
+
if len(quad_list)>0:
|
|
503
|
+
fid.write(f'2 {surface_id} 3 {len(quad_list)}\n')
|
|
504
|
+
for quad_id in quad_list:
|
|
505
|
+
node_list = cubit.get_connectivity("quad", quad_id)
|
|
506
|
+
elementTag +=1
|
|
507
|
+
fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
508
|
+
|
|
509
|
+
for block_id in cubit.get_block_id_list():
|
|
510
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
511
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
512
|
+
if len(tet_list)>0:
|
|
513
|
+
fid.write(f'3 {volume_id} 4 {len(tet_list)}\n')
|
|
514
|
+
for tet_id in tet_list:
|
|
515
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
516
|
+
elementTag +=1
|
|
517
|
+
fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
518
|
+
|
|
519
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
520
|
+
if len(hex_list)>0:
|
|
521
|
+
fid.write(f'3 {volume_id} 5 {len(hex_list)}\n')
|
|
522
|
+
for hex_id in hex_list:
|
|
523
|
+
node_list = cubit.get_connectivity("hex", hex_id)
|
|
524
|
+
elementTag +=1
|
|
525
|
+
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')
|
|
526
|
+
|
|
527
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
528
|
+
if len(wedge_list)>0:
|
|
529
|
+
fid.write(f'3 {volume_id} 6 {len(wedge_list)}\n')
|
|
530
|
+
for wedge_id in wedge_list:
|
|
531
|
+
node_list = cubit.get_connectivity("wedge", wedge_id)
|
|
532
|
+
elementTag +=1
|
|
533
|
+
fid.write(f'{elementTag} {node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]}\n')
|
|
534
|
+
|
|
535
|
+
fid.write('$EndElements\n')
|
|
536
|
+
fid.close()
|
|
537
|
+
return cubit
|
|
538
|
+
|
|
539
|
+
########################################################################
|
|
540
|
+
### NASTRAN 1D file
|
|
541
|
+
########################################################################
|
|
542
|
+
|
|
543
|
+
def export_1D_Nastran(cubit, FileName):
|
|
544
|
+
import datetime
|
|
545
|
+
formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
|
|
546
|
+
|
|
547
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
548
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
549
|
+
fid.write("$\n")
|
|
550
|
+
fid.write("$ CUBIT NX Nastran Translator\n")
|
|
551
|
+
fid.write("$\n")
|
|
552
|
+
fid.write("f$ File: {FileName}\n")
|
|
553
|
+
fid.write(f"$ Time Stamp: {formatted_date_time}\n")
|
|
554
|
+
fid.write("$\n")
|
|
555
|
+
fid.write("$\n")
|
|
556
|
+
fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
|
|
557
|
+
fid.write("$\n")
|
|
558
|
+
fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
|
|
559
|
+
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")
|
|
560
|
+
fid.write("$\n")
|
|
561
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
562
|
+
fid.write("$\n")
|
|
563
|
+
fid.write("$\n")
|
|
564
|
+
fid.write("$ -------------------------\n")
|
|
565
|
+
fid.write("$ Executive Control Section\n")
|
|
566
|
+
fid.write("$ -------------------------\n")
|
|
567
|
+
fid.write("$\n")
|
|
568
|
+
fid.write("SOL 101\n")
|
|
569
|
+
fid.write("CEND\n")
|
|
570
|
+
fid.write("$\n")
|
|
571
|
+
fid.write("$\n")
|
|
572
|
+
fid.write("$ --------------------\n")
|
|
573
|
+
fid.write("$ Case Control Section\n")
|
|
574
|
+
fid.write("$ --------------------\n")
|
|
575
|
+
fid.write("$\n")
|
|
576
|
+
fid.write("ECHO = SORT\n")
|
|
577
|
+
fid.write("$\n")
|
|
578
|
+
fid.write("$\n")
|
|
579
|
+
fid.write("$ Name: Initial\n")
|
|
580
|
+
fid.write("$\n")
|
|
581
|
+
fid.write("$\n")
|
|
582
|
+
fid.write("$ Name: Default Set\n")
|
|
583
|
+
fid.write("$\n")
|
|
584
|
+
fid.write("SUBCASE = 1\n")
|
|
585
|
+
fid.write("$\n")
|
|
586
|
+
fid.write("LABEL = Default Set\n")
|
|
587
|
+
fid.write("$\n")
|
|
588
|
+
fid.write("$ -----------------\n")
|
|
589
|
+
fid.write("$ Bulk Data Section\n")
|
|
590
|
+
fid.write("$ -----------------\n")
|
|
591
|
+
fid.write("$\n")
|
|
592
|
+
fid.write("BEGIN BULK\n")
|
|
593
|
+
fid.write("$\n")
|
|
594
|
+
fid.write("$ Params\n")
|
|
595
|
+
fid.write("$\n")
|
|
596
|
+
fid.write("$\n")
|
|
597
|
+
fid.write("$ Node cards\n")
|
|
598
|
+
fid.write("$\n")
|
|
599
|
+
|
|
600
|
+
node_set = set()
|
|
601
|
+
for block_id in cubit.get_block_id_list():
|
|
602
|
+
curve_list = cubit.get_block_curves(block_id)
|
|
603
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in curve {" ".join(map(str, curve_list)) }' ))
|
|
604
|
+
for node_id in node_set:
|
|
605
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
606
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
|
|
607
|
+
|
|
608
|
+
element_id = 0
|
|
609
|
+
fid.write("$\n")
|
|
610
|
+
fid.write("$ Element cards\n")
|
|
611
|
+
fid.write("$\n")
|
|
612
|
+
for block_id in cubit.get_block_id_list():
|
|
613
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
614
|
+
curve_list = cubit.get_block_curves(block_id)
|
|
615
|
+
for curve_id in curve_list:
|
|
616
|
+
edge_list = cubit.get_curve_edges(curve_id)
|
|
617
|
+
for edge_id in edge_list:
|
|
618
|
+
node_list = cubit.get_connectivity('edge', edge_id)
|
|
619
|
+
element_id += 1
|
|
620
|
+
fid.write(f"CROD {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}\n")
|
|
621
|
+
fid.write("$\n")
|
|
622
|
+
fid.write("$ Property cards\n")
|
|
623
|
+
fid.write("$\n")
|
|
624
|
+
|
|
625
|
+
for block_id in cubit.get_block_id_list():
|
|
626
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
627
|
+
fid.write("$\n")
|
|
628
|
+
fid.write(f"$ Name: {name}\n")
|
|
629
|
+
fid.write("$\n")
|
|
630
|
+
fid.write(f"MAT1 {block_id:< 8}{1:<8}{1:<8}{1:<8}\n")
|
|
631
|
+
fid.write("ENDDATA\n")
|
|
632
|
+
fid.close()
|
|
633
|
+
return cubit
|
|
634
|
+
|
|
635
|
+
########################################################################
|
|
636
|
+
### NASTRAN 2D file
|
|
637
|
+
########################################################################
|
|
638
|
+
|
|
639
|
+
def export_2D_Nastran(cubit, FileName):
|
|
640
|
+
import datetime
|
|
641
|
+
formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
|
|
642
|
+
|
|
643
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
644
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
645
|
+
fid.write("$\n")
|
|
646
|
+
fid.write("$ CUBIT NX Nastran Translator\n")
|
|
647
|
+
fid.write("$\n")
|
|
648
|
+
fid.write("f$ File: {FileName}\n")
|
|
649
|
+
fid.write(f"$ Time Stamp: {formatted_date_time}\n")
|
|
650
|
+
fid.write("$\n")
|
|
651
|
+
fid.write("$\n")
|
|
652
|
+
fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
|
|
653
|
+
fid.write("$\n")
|
|
654
|
+
fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
|
|
655
|
+
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")
|
|
656
|
+
fid.write("$\n")
|
|
657
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
658
|
+
fid.write("$\n")
|
|
659
|
+
fid.write("$\n")
|
|
660
|
+
fid.write("$ -------------------------\n")
|
|
661
|
+
fid.write("$ Executive Control Section\n")
|
|
662
|
+
fid.write("$ -------------------------\n")
|
|
663
|
+
fid.write("$\n")
|
|
664
|
+
fid.write("SOL 101\n")
|
|
665
|
+
fid.write("CEND\n")
|
|
666
|
+
fid.write("$\n")
|
|
667
|
+
fid.write("$\n")
|
|
668
|
+
fid.write("$ --------------------\n")
|
|
669
|
+
fid.write("$ Case Control Section\n")
|
|
670
|
+
fid.write("$ --------------------\n")
|
|
671
|
+
fid.write("$\n")
|
|
672
|
+
fid.write("ECHO = SORT\n")
|
|
673
|
+
fid.write("$\n")
|
|
674
|
+
fid.write("$\n")
|
|
675
|
+
fid.write("$ Name: Initial\n")
|
|
676
|
+
fid.write("$\n")
|
|
677
|
+
fid.write("$\n")
|
|
678
|
+
fid.write("$ Name: Default Set\n")
|
|
679
|
+
fid.write("$\n")
|
|
680
|
+
fid.write("SUBCASE = 1\n")
|
|
681
|
+
fid.write("$\n")
|
|
682
|
+
fid.write("LABEL = Default Set\n")
|
|
683
|
+
fid.write("$\n")
|
|
684
|
+
fid.write("$ -----------------\n")
|
|
685
|
+
fid.write("$ Bulk Data Section\n")
|
|
686
|
+
fid.write("$ -----------------\n")
|
|
687
|
+
fid.write("$\n")
|
|
688
|
+
fid.write("BEGIN BULK\n")
|
|
689
|
+
fid.write("$\n")
|
|
690
|
+
fid.write("$ Params\n")
|
|
691
|
+
fid.write("$\n")
|
|
692
|
+
fid.write("$\n")
|
|
693
|
+
fid.write("$ Node cards\n")
|
|
694
|
+
fid.write("$\n")
|
|
695
|
+
|
|
696
|
+
node_set = set()
|
|
697
|
+
for block_id in cubit.get_block_id_list():
|
|
698
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
699
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in surface {" ".join(map(str, surface_list)) }' ))
|
|
700
|
+
for node_id in node_set:
|
|
701
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
702
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
|
|
703
|
+
|
|
704
|
+
element_id = 0
|
|
705
|
+
fid.write("$\n")
|
|
706
|
+
fid.write("$ Element cards\n")
|
|
707
|
+
fid.write("$\n")
|
|
708
|
+
for block_id in cubit.get_block_id_list():
|
|
709
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
710
|
+
fid.write("$\n")
|
|
711
|
+
fid.write(f"$ Name: {name}\n")
|
|
712
|
+
fid.write("$\n")
|
|
713
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
714
|
+
for surface_id in surface_list:
|
|
715
|
+
normal = cubit.get_surface_normal(surface_id)
|
|
716
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
717
|
+
for tri_id in tri_list:
|
|
718
|
+
node_list = cubit.get_connectivity('tri',tri_id)
|
|
719
|
+
element_id += 1
|
|
720
|
+
if normal[2] > 0:
|
|
721
|
+
fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[1]:<8}{node_list[2]:<8}\n")
|
|
722
|
+
else:
|
|
723
|
+
fid.write(f"CTRIA3 {element_id:<8}{block_id:<8}{node_list[0]:<8}{node_list[2]:<8}{node_list[1]:<8}\n")
|
|
724
|
+
quad_list = cubit.get_surface_quads(surface_id)
|
|
725
|
+
for quad_id in quad_list:
|
|
726
|
+
node_list = cubit.get_connectivity('quad',quad_id)
|
|
727
|
+
element_id += 1
|
|
728
|
+
if normal[2] > 0:
|
|
729
|
+
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")
|
|
730
|
+
else:
|
|
731
|
+
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")
|
|
732
|
+
fid.write("$\n")
|
|
733
|
+
fid.write("$ Property cards\n")
|
|
734
|
+
fid.write("$\n")
|
|
735
|
+
|
|
736
|
+
for block_id in cubit.get_block_id_list():
|
|
737
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
738
|
+
fid.write("$\n")
|
|
739
|
+
fid.write(f"$ Name: {name}\n")
|
|
740
|
+
fid.write("$\n")
|
|
741
|
+
fid.write(f"MAT1 {block_id:< 8}{1:<8}{1:<8}{1:<8}\n")
|
|
742
|
+
fid.write("ENDDATA\n")
|
|
743
|
+
fid.close()
|
|
744
|
+
return cubit
|
|
745
|
+
|
|
746
|
+
########################################################################
|
|
747
|
+
### 3D Nastran file
|
|
748
|
+
########################################################################
|
|
749
|
+
|
|
750
|
+
def export_3D_Nastran(cubit, FileName, Pyram=True):
|
|
751
|
+
|
|
752
|
+
import datetime
|
|
753
|
+
formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
|
|
754
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
755
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
756
|
+
fid.write("$\n")
|
|
757
|
+
fid.write("$ CUBIT NX Nastran Translator\n")
|
|
758
|
+
fid.write("$\n")
|
|
759
|
+
fid.write("f$ File: {FileName}\n")
|
|
760
|
+
fid.write(f"$ Time Stamp: {formatted_date_time}\n")
|
|
761
|
+
fid.write("$\n")
|
|
762
|
+
fid.write("$\n")
|
|
763
|
+
fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
|
|
764
|
+
fid.write("$\n")
|
|
765
|
+
fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
|
|
766
|
+
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")
|
|
767
|
+
fid.write("$\n")
|
|
768
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
769
|
+
fid.write("$\n")
|
|
770
|
+
fid.write("$\n")
|
|
771
|
+
fid.write("$ -------------------------\n")
|
|
772
|
+
fid.write("$ Executive Control Section\n")
|
|
773
|
+
fid.write("$ -------------------------\n")
|
|
774
|
+
fid.write("$\n")
|
|
775
|
+
fid.write("SOL 101\n")
|
|
776
|
+
fid.write("CEND\n")
|
|
777
|
+
fid.write("$\n")
|
|
778
|
+
fid.write("$\n")
|
|
779
|
+
fid.write("$ --------------------\n")
|
|
780
|
+
fid.write("$ Case Control Section\n")
|
|
781
|
+
fid.write("$ --------------------\n")
|
|
782
|
+
fid.write("$\n")
|
|
783
|
+
fid.write("ECHO = SORT\n")
|
|
784
|
+
fid.write("$\n")
|
|
785
|
+
fid.write("$\n")
|
|
786
|
+
fid.write("$ Name: Initial\n")
|
|
787
|
+
fid.write("$\n")
|
|
788
|
+
fid.write("$\n")
|
|
789
|
+
fid.write("$ Name: Default Set\n")
|
|
790
|
+
fid.write("$\n")
|
|
791
|
+
fid.write("SUBCASE = 1\n")
|
|
792
|
+
fid.write("$\n")
|
|
793
|
+
fid.write("LABEL = Default Set\n")
|
|
794
|
+
fid.write("$\n")
|
|
795
|
+
fid.write("$ -----------------\n")
|
|
796
|
+
fid.write("$ Bulk Data Section\n")
|
|
797
|
+
fid.write("$ -----------------\n")
|
|
798
|
+
fid.write("$\n")
|
|
799
|
+
fid.write("BEGIN BULK\n")
|
|
800
|
+
fid.write("$\n")
|
|
801
|
+
fid.write("$ Params\n")
|
|
802
|
+
fid.write("$\n")
|
|
803
|
+
fid.write("$\n")
|
|
804
|
+
fid.write("$ Node cards\n")
|
|
805
|
+
fid.write("$\n")
|
|
806
|
+
|
|
807
|
+
node_set = set()
|
|
808
|
+
for block_id in cubit.get_block_id_list():
|
|
809
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
810
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
|
|
811
|
+
fid.write(f'{len(node_set)}\n')
|
|
812
|
+
for node_id in node_set:
|
|
813
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
814
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
|
|
815
|
+
|
|
816
|
+
element_id = 0
|
|
817
|
+
fid.write("$\n")
|
|
818
|
+
fid.write("$ Element cards\n")
|
|
819
|
+
fid.write("$\n")
|
|
820
|
+
for block_id in cubit.get_block_id_list():
|
|
821
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
822
|
+
fid.write("$\n")
|
|
823
|
+
fid.write(f"$ Name: {name}\n")
|
|
824
|
+
fid.write("$\n")
|
|
825
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
826
|
+
for volume_id in volume_list:
|
|
827
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
828
|
+
for tet_id in tet_list:
|
|
829
|
+
node_list = cubit.get_connectivity('tet',tet_id)
|
|
830
|
+
element_id += 1
|
|
831
|
+
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")
|
|
832
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
833
|
+
for hex_id in hex_list:
|
|
834
|
+
node_list = cubit.get_connectivity('hex',hex_id)
|
|
835
|
+
element_id += 1
|
|
836
|
+
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")
|
|
837
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
838
|
+
for wedge_id in wedge_list:
|
|
839
|
+
node_list = cubit.get_connectivity('wedge',wedge_id)
|
|
840
|
+
element_id += 1
|
|
841
|
+
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")
|
|
842
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
843
|
+
for pyramid_id in pyramid_list:
|
|
844
|
+
node_list = cubit.get_connectivity('pyramid',pyramid_id)
|
|
845
|
+
if Pyram:
|
|
846
|
+
element_id += 1
|
|
847
|
+
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")
|
|
848
|
+
else:
|
|
849
|
+
element_id += 1
|
|
850
|
+
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")
|
|
851
|
+
fid.write("$\n")
|
|
852
|
+
fid.write("$ Property cards\n")
|
|
853
|
+
fid.write("$\n")
|
|
854
|
+
|
|
855
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
856
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
857
|
+
fid.write("$\n")
|
|
858
|
+
fid.write(f"$ Name: {name}\n")
|
|
859
|
+
fid.write("$\n")
|
|
860
|
+
fid.write(f"PSHELL {nodeset_id:< 8}{nodeset_id:< 8}{1:<8}{1:<8}{1:<8}\n")
|
|
861
|
+
for block_id in cubit.get_block_id_list():
|
|
862
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
863
|
+
fid.write("$\n")
|
|
864
|
+
fid.write(f"$ Name: {name}\n")
|
|
865
|
+
fid.write("$\n")
|
|
866
|
+
fid.write(f"MAT1 {block_id:< 8}{1:<8}{1:<8}{1:<8}\n")
|
|
867
|
+
fid.write("ENDDATA\n")
|
|
868
|
+
fid.close()
|
|
869
|
+
return cubit
|
|
870
|
+
|
|
871
|
+
########################################################################
|
|
872
|
+
### 3D CDB file
|
|
873
|
+
########################################################################
|
|
874
|
+
|
|
875
|
+
def export_3D_CDB(cubit, FileName):
|
|
876
|
+
|
|
877
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
878
|
+
fid.write(f'/COM,ANSYS RELEASE 15.0\n')
|
|
879
|
+
fid.write(f'! Exported from Coreform Cubit 2024.3\n')
|
|
880
|
+
fid.write(f'! {datetime.now().strftime("%Y/%m/%d %I:%M:%S %p")}\n')
|
|
881
|
+
fid.write(f'/PREP7\n')
|
|
882
|
+
fid.write(f'/TITLE,\n')
|
|
883
|
+
fid.write(f'*IF,_CDRDOFF,EQ,1,THEN\n')
|
|
884
|
+
fid.write(f'_CDRDOFF= \n')
|
|
885
|
+
fid.write(f'*ELSE\n')
|
|
886
|
+
fid.write(f'NUMOFF,NODE, {node_count:8d}\n')
|
|
887
|
+
fid.write(f'NUMOFF,ELEM, {elem_count:8d}\n')
|
|
888
|
+
fid.write(f'NUMOFF,TYPE, 1\n')
|
|
889
|
+
fid.write(f'*ENDIF\n')
|
|
890
|
+
fid.write(f'DOF,DELETE\n')
|
|
891
|
+
fid.write(f'ET, 1,185\n')
|
|
892
|
+
fid.write(f'NBLOCK,6,SOLID, {node_count:8d}, {node_count:8d}\n')
|
|
893
|
+
fid.write(f'(3i9,6e20.13)\n')
|
|
894
|
+
|
|
895
|
+
node_set = set()
|
|
896
|
+
for block_id in cubit.get_block_id_list():
|
|
897
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
898
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
|
|
899
|
+
fid.write(f'{len(node_set)}\n')
|
|
900
|
+
for node_id in node_set:
|
|
901
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
902
|
+
fid.write(f'{node_id:9d}{0:9d}{0:9d}{coord[0]:20.13e}{coord[1]:20.13e}{coord[2]:20.13e}\n')
|
|
903
|
+
|
|
904
|
+
fid.write(f'N,R5.3,LOC, -1\n')
|
|
905
|
+
elem_count = 0
|
|
906
|
+
for block_id in cubit.get_block_id_list():
|
|
907
|
+
fid.write(f'EBLOCK, 19, SOLID\n')
|
|
908
|
+
fid.write(f'(19i9)\n')
|
|
909
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
910
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
911
|
+
if len(hex_list)>0:
|
|
912
|
+
for hex_id in hex_list:
|
|
913
|
+
elem_count += 1
|
|
914
|
+
node_list = cubit.get_connectivity("hex", hex_id)
|
|
915
|
+
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')
|
|
916
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
917
|
+
if len(wedge_list)>0:
|
|
918
|
+
for wedge_id in wedge_list:
|
|
919
|
+
elem_count += 1
|
|
920
|
+
node_list = cubit.get_connectivity("wedge", wedge_id)
|
|
921
|
+
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')
|
|
922
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
923
|
+
if len(tet_list)>0:
|
|
924
|
+
for tet_id in tet_list:
|
|
925
|
+
elem_count += 1
|
|
926
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
927
|
+
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')
|
|
928
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
929
|
+
if len(pyramid_list)>0:
|
|
930
|
+
for pyramid_id in pyramid_list:
|
|
931
|
+
elem_count += 1
|
|
932
|
+
node_list = cubit.get_connectivity("pyramid", pyramid_id)
|
|
933
|
+
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')
|
|
934
|
+
fid.write(f' -1\n')
|
|
935
|
+
|
|
936
|
+
for block_id in cubit.get_block_id_list():
|
|
937
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
938
|
+
elem_list = []
|
|
939
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
940
|
+
for volume_id in volume_list:
|
|
941
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
942
|
+
elem_list.extend(hex_list)
|
|
943
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
944
|
+
elem_list.extend(wedge_list)
|
|
945
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
946
|
+
elem_list.extend(tet_list)
|
|
947
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
948
|
+
elem_list.extend(pyramid_list)
|
|
949
|
+
fid.write(f'CMBLOCK,{name:<8},ELEM,{len(elem_list):8d}\n')
|
|
950
|
+
fid.write(f'(8i10)\n')
|
|
951
|
+
for n in range(0, len(elem_list), 8):
|
|
952
|
+
strLine = ""
|
|
953
|
+
for m in range(n, min(n+8, len(elem_list))):
|
|
954
|
+
strLine += f'{elem_list[m]:10d}'
|
|
955
|
+
fid.write(f'{strLine}\n')
|
|
956
|
+
|
|
957
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
958
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
959
|
+
|
|
960
|
+
node_set.clear()
|
|
961
|
+
surface_list = cubit.get_nodeset_surfaces(nodeset_id)
|
|
962
|
+
for surface_id in surface_list:
|
|
963
|
+
quad_list = cubit.get_surface_quads(surface_id)
|
|
964
|
+
for quad_id in quad_list:
|
|
965
|
+
node_list = cubit.get_connectivity("quad", quad_id)
|
|
966
|
+
node_set.update(node_list)
|
|
967
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
968
|
+
for tri_id in tri_list:
|
|
969
|
+
node_list = cubit.get_connectivity("tri", tri_id)
|
|
970
|
+
node_set.update(node_list)
|
|
971
|
+
|
|
972
|
+
fid.write(f'CMBLOCK,{name:<8},NODE,{len(node_set):8d}\n')
|
|
973
|
+
fid.write(f'(8i10)\n')
|
|
974
|
+
node_list = list(node_set)
|
|
975
|
+
for n in range(0, len(node_list), 8):
|
|
976
|
+
strLine = ""
|
|
977
|
+
for m in range(n, min(n+8, len(node_list))):
|
|
978
|
+
strLine += f'{node_list[m]:10d}'
|
|
979
|
+
fid.write(f'{strLine}\n')
|
|
980
|
+
return cubit
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
########################################################################
|
|
984
|
+
### ELF 1D file
|
|
985
|
+
########################################################################
|
|
986
|
+
|
|
987
|
+
def export_1D_meg(cubit, FileName, Dim='T', MGR2=[] ):
|
|
988
|
+
|
|
989
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
990
|
+
fid.write("BOOK MEP 3.50\n")
|
|
991
|
+
fid.write("* ELF/MESH VERSION 7.3.0\n")
|
|
992
|
+
fid.write("* SOLVER = ELF/MAGIC\n")
|
|
993
|
+
fid.write("MGSC 0.001\n")
|
|
994
|
+
fid.write("* NODE\n")
|
|
995
|
+
|
|
996
|
+
node_set = set()
|
|
997
|
+
for block_id in cubit.get_block_id_list():
|
|
998
|
+
curve_list = cubit.get_block_curves(block_id)
|
|
999
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in curve {" ".join(map(str, curve_list)) }' ))
|
|
1000
|
+
for node_id in node_set:
|
|
1001
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
1002
|
+
if Dim=='T':
|
|
1003
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
|
|
1004
|
+
elif Dim=='K':
|
|
1005
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
|
|
1006
|
+
elif Dim=='R':
|
|
1007
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
|
|
1008
|
+
|
|
1009
|
+
element_id = 0
|
|
1010
|
+
fid.write("* ELEMENT T\n")
|
|
1011
|
+
for block_id in cubit.get_block_id_list():
|
|
1012
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
1013
|
+
curve_list = cubit.get_block_curves(block_id)
|
|
1014
|
+
for curve_id in curve_list:
|
|
1015
|
+
edge_list = cubit.get_curve_edges(curve_id)
|
|
1016
|
+
for edge_id in edge_list:
|
|
1017
|
+
node_list = cubit.get_connectivity('edge', edge_id)
|
|
1018
|
+
element_id += 1
|
|
1019
|
+
fid.write(f"{name[0:3]}2{Dim} {element_id} 0 {block_id} {node_list[0]} {node_list[1]}\n")
|
|
1020
|
+
fid.write("* ELEMENT\n")
|
|
1021
|
+
fid.write("BOOK END\n")
|
|
1022
|
+
for node_id in range(len(MGR2)):
|
|
1023
|
+
fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
|
|
1024
|
+
fid.close()
|
|
1025
|
+
return cubit
|
|
1026
|
+
|
|
1027
|
+
########################################################################
|
|
1028
|
+
### ELF 2D file
|
|
1029
|
+
########################################################################
|
|
1030
|
+
|
|
1031
|
+
def export_2D_meg(cubit, FileName, Dim='T', MGR2=[]):
|
|
1032
|
+
|
|
1033
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
1034
|
+
fid.write("BOOK MEP 3.50\n")
|
|
1035
|
+
fid.write("* ELF/MESH VERSION 7.3.0\n")
|
|
1036
|
+
fid.write("* SOLVER = ELF/MAGIC\n")
|
|
1037
|
+
fid.write("MGSC 0.001\n")
|
|
1038
|
+
fid.write("* NODE\n")
|
|
1039
|
+
|
|
1040
|
+
node_set = set()
|
|
1041
|
+
for block_id in cubit.get_block_id_list():
|
|
1042
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
1043
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in surface {" ".join(map(str, surface_list)) }' ))
|
|
1044
|
+
for node_id in node_set:
|
|
1045
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
1046
|
+
if Dim=='T':
|
|
1047
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
|
|
1048
|
+
if Dim=='K':
|
|
1049
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
|
|
1050
|
+
if Dim=='R':
|
|
1051
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
|
|
1052
|
+
|
|
1053
|
+
element_id = 0
|
|
1054
|
+
fid.write("* ELEMENT T\n")
|
|
1055
|
+
for block_id in cubit.get_block_id_list():
|
|
1056
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
1057
|
+
for surface_id in cubit.get_block_surfaces(block_id):
|
|
1058
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
1059
|
+
for tri_id in tri_list:
|
|
1060
|
+
node_list = cubit.get_connectivity('tri',tri_id)
|
|
1061
|
+
element_id += 1
|
|
1062
|
+
fid.write(f"{name[0:3]}3{Dim} {element_d} 0 {block_id} {node_list[0]} {node_list[1]} {node_list[2]}\n")
|
|
1063
|
+
|
|
1064
|
+
quad_list = cubit.get_surface_quads(surface_id)
|
|
1065
|
+
for quad_id in quad_list:
|
|
1066
|
+
node_list = cubit.get_connectivity('quad',quad_id)
|
|
1067
|
+
element_id += 1
|
|
1068
|
+
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")
|
|
1069
|
+
|
|
1070
|
+
fid.write("* NODE\n")
|
|
1071
|
+
for node_id in range(len(MGR2)):
|
|
1072
|
+
fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
|
|
1073
|
+
fid.write("BOOK END\n")
|
|
1074
|
+
fid.close()
|
|
1075
|
+
return cubit
|
|
1076
|
+
|
|
1077
|
+
########################################################################
|
|
1078
|
+
### ELF 3D file
|
|
1079
|
+
########################################################################
|
|
1080
|
+
|
|
1081
|
+
def export_3D_meg(cubit, FileName, Dim='T', MGR2=[], Pyram=True):
|
|
1082
|
+
|
|
1083
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
1084
|
+
fid.write("BOOK MEP 3.50\n")
|
|
1085
|
+
fid.write("* ELF/MESH VERSION 7.3.0\n")
|
|
1086
|
+
fid.write("* SOLVER = ELF/MAGIC\n")
|
|
1087
|
+
fid.write("MGSC 0.001\n")
|
|
1088
|
+
fid.write("* NODE\n")
|
|
1089
|
+
|
|
1090
|
+
node_set = set()
|
|
1091
|
+
for block_id in cubit.get_block_id_list():
|
|
1092
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
1093
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
|
|
1094
|
+
for node_id in node_set:
|
|
1095
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
1096
|
+
if Dim=='T':
|
|
1097
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
|
|
1098
|
+
if Dim=='K':
|
|
1099
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
|
|
1100
|
+
if Dim=='R':
|
|
1101
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
|
|
1102
|
+
|
|
1103
|
+
element_id = 0
|
|
1104
|
+
fid.write("* ELEMENT K\n")
|
|
1105
|
+
for block_id in cubit.get_block_id_list():
|
|
1106
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
1107
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
1108
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
1109
|
+
if len(tet_list)>0:
|
|
1110
|
+
for tet_id in tet_list:
|
|
1111
|
+
node_list = cubit.get_connectivity('tet',tet_id)
|
|
1112
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
1113
|
+
element_id += 1
|
|
1114
|
+
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")
|
|
1115
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
1116
|
+
if len(hex_list)>0:
|
|
1117
|
+
for hex_id in hex_list:
|
|
1118
|
+
node_list = cubit.get_connectivity("hex", hex_id)
|
|
1119
|
+
element_id += 1
|
|
1120
|
+
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")
|
|
1121
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
1122
|
+
if len(wedge_list)>0:
|
|
1123
|
+
for wedge_id in wedge_list:
|
|
1124
|
+
node_list = cubit.get_connectivity("wedge", wedge_id)
|
|
1125
|
+
element_id += 1
|
|
1126
|
+
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")
|
|
1127
|
+
|
|
1128
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
1129
|
+
if len(pyramid_list)>0:
|
|
1130
|
+
for pyramid_id in pyramid_list:
|
|
1131
|
+
node_list = cubit.get_connectivity('pyramid',pyramid_id)
|
|
1132
|
+
if Pyram:
|
|
1133
|
+
# element_id += 1
|
|
1134
|
+
# 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")
|
|
1135
|
+
element_id += 1
|
|
1136
|
+
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")
|
|
1137
|
+
element_id += 1
|
|
1138
|
+
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")
|
|
1139
|
+
else:
|
|
1140
|
+
element_id += 1
|
|
1141
|
+
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")
|
|
1142
|
+
|
|
1143
|
+
fid.write("* NODE\n")
|
|
1144
|
+
for node_id in range(len(MGR2)):
|
|
1145
|
+
fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
|
|
1146
|
+
fid.write("BOOK END\n")
|
|
1147
|
+
fid.close()
|
|
1148
|
+
return cubit
|
|
1149
|
+
|
|
1150
|
+
########################################################################
|
|
1151
|
+
### vtk format
|
|
1152
|
+
########################################################################
|
|
1153
|
+
|
|
1154
|
+
def export_3D_vtk(cubit, FileName):
|
|
1155
|
+
|
|
1156
|
+
fid = open(FileName,'w')
|
|
1157
|
+
fid.write('# vtk DataFile Version 3.0\n')
|
|
1158
|
+
fid.write(f'Unstructured Grid {FileName}\n')
|
|
1159
|
+
fid.write('ASCII\n')
|
|
1160
|
+
fid.write('DATASET UNSTRUCTURED_GRID\n')
|
|
1161
|
+
fid.write(f'POINTS {cubit.get_node_count()} float\n')
|
|
1162
|
+
|
|
1163
|
+
for node_id in range(cubit.get_node_count()+1):
|
|
1164
|
+
if cubit.get_node_exists(node_id):
|
|
1165
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
1166
|
+
fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
|
|
1167
|
+
|
|
1168
|
+
tet_list = []
|
|
1169
|
+
hex_list = []
|
|
1170
|
+
wedge_list = []
|
|
1171
|
+
pyramid_list = []
|
|
1172
|
+
volume_id_list = []
|
|
1173
|
+
for block_id in cubit.get_block_id_list():
|
|
1174
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
1175
|
+
tet_list += cubit.get_volume_tets(volume_id)
|
|
1176
|
+
volume_id_list += [volume_id]*(len(cubit.get_volume_tets(volume_id)))
|
|
1177
|
+
|
|
1178
|
+
for block_id in cubit.get_block_id_list():
|
|
1179
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
1180
|
+
hex_list += cubit.get_volume_hexes(volume_id)
|
|
1181
|
+
volume_id_list += [volume_id]*(len(cubit.get_volume_hexes(volume_id)))
|
|
1182
|
+
|
|
1183
|
+
for block_id in cubit.get_block_id_list():
|
|
1184
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
1185
|
+
wedge_list += cubit.get_volume_wedges(volume_id)
|
|
1186
|
+
volume_id_list += [volume_id]*(len(cubit.get_volume_wedges(volume_id)))
|
|
1187
|
+
for block_id in cubit.get_block_id_list():
|
|
1188
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
1189
|
+
pyramid_list += cubit.get_volume_pyramids(volume_id)
|
|
1190
|
+
volume_id_list += [volume_id]*(len(cubit.get_volume_pyramids(volume_id)))
|
|
1191
|
+
|
|
1192
|
+
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' )
|
|
1193
|
+
for tet_id in tet_list:
|
|
1194
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
1195
|
+
fid.write(f'4 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1}\n')
|
|
1196
|
+
for hex_id in hex_list:
|
|
1197
|
+
node_list = cubit.get_connectivity("hex", hex_id)
|
|
1198
|
+
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')
|
|
1199
|
+
for wedge_id in wedge_list:
|
|
1200
|
+
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')
|
|
1201
|
+
for pyramid_id in pyramid_list:
|
|
1202
|
+
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')
|
|
1203
|
+
|
|
1204
|
+
fid.write(f'CELL_TYPES {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list)}\n')
|
|
1205
|
+
for tet_id in tet_list:
|
|
1206
|
+
fid.write('10\n')
|
|
1207
|
+
for hex_id in hex_list:
|
|
1208
|
+
fid.write('12\n')
|
|
1209
|
+
for wedge_id in wedge_list:
|
|
1210
|
+
fid.write('13\n')
|
|
1211
|
+
for pyramid_id in pyramid_list:
|
|
1212
|
+
fid.write('14\n')
|
|
1213
|
+
fid.write(f'CELL_DATA {len(tet_list) + len(hex_list) + len(wedge_list) + len(pyramid_list)}\n')
|
|
1214
|
+
fid.write('SCALARS scalars float\n')
|
|
1215
|
+
fid.write('LOOKUP_TABLE default\n')
|
|
1216
|
+
for volume_id in volume_id_list:
|
|
1217
|
+
fid.write(f'{volume_id}\n')
|
|
1218
|
+
fid.close()
|
|
1219
|
+
return cubit
|
|
1220
|
+
|
|
1221
|
+
########################################################################
|
|
1222
|
+
### Lukas FEM 2D file
|
|
1223
|
+
########################################################################
|
|
1224
|
+
|
|
1225
|
+
def export_2D_geo_mesh(cubit, FileName):
|
|
1226
|
+
|
|
1227
|
+
import numpy
|
|
1228
|
+
import scipy.io
|
|
1229
|
+
|
|
1230
|
+
node_list = []
|
|
1231
|
+
|
|
1232
|
+
N = cubit.get_node_count()
|
|
1233
|
+
M = cubit.get_tri_count()
|
|
1234
|
+
|
|
1235
|
+
node_set = set()
|
|
1236
|
+
for block_id in cubit.get_block_id_list():
|
|
1237
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
1238
|
+
node_set.update(cubit.parse_cubit_list( 'node', f'in volume {" ".join(map(str, volume_list)) }' ))
|
|
1239
|
+
|
|
1240
|
+
for node_id in node_set:
|
|
1241
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
1242
|
+
nodes.append([coord[0],coord[1]])
|
|
1243
|
+
|
|
1244
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
1245
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
1246
|
+
curve_list = cubit.get_nodeset_curves(nodeset_id)
|
|
1247
|
+
node_list = []
|
|
1248
|
+
for curve_id in curve_list:
|
|
1249
|
+
node_list += cubit.get_curve_nodes(curve_id)
|
|
1250
|
+
nodeset = numpy.array([(name, node_list)], dtype=[('name', 'U20'), ('DBCnodes', 'O')])
|
|
1251
|
+
try:
|
|
1252
|
+
nodesets = append(nodesets,nodeset)
|
|
1253
|
+
except:
|
|
1254
|
+
nodesets = nodeset
|
|
1255
|
+
|
|
1256
|
+
conn_matrix = numpy.zeros((M,3))
|
|
1257
|
+
center_x = numpy.zeros((M))
|
|
1258
|
+
center_y = numpy.zeros((M))
|
|
1259
|
+
block_count = cubit.get_block_count()
|
|
1260
|
+
regions = numpy.rec.array([("", [], [])]*(block_count), dtype=[('name', 'U20'), ('Elements', 'O'), ('Nodes', 'O')])
|
|
1261
|
+
|
|
1262
|
+
for block_id in cubit.get_block_id_list():
|
|
1263
|
+
Elements = []
|
|
1264
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
1265
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
1266
|
+
Nodes = []
|
|
1267
|
+
Elements = []
|
|
1268
|
+
for surface_id in surface_list:
|
|
1269
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
1270
|
+
Elements += tri_list
|
|
1271
|
+
for tri_id in tri_list:
|
|
1272
|
+
x = []
|
|
1273
|
+
y = []
|
|
1274
|
+
node_list = cubit.get_connectivity('tri',tri_id)
|
|
1275
|
+
Nodes += node_list
|
|
1276
|
+
conn_matrix[tri_id-1,:] = node_list
|
|
1277
|
+
for node_id in node_list:
|
|
1278
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
1279
|
+
x.append(coord[0])
|
|
1280
|
+
y.append(coord[1])
|
|
1281
|
+
center_x[tri_id-1] = numpy.mean(x)
|
|
1282
|
+
center_y[tri_id-1] = numpy.mean(y)
|
|
1283
|
+
regions[block_id-1][0] = name
|
|
1284
|
+
regions[block_id-1][1] = Elements
|
|
1285
|
+
regions[block_id-1][2] = Nodes
|
|
1286
|
+
|
|
1287
|
+
geo = {'conn_matrix':conn_matrix, 'nodes':nodes, 'M':M, 'N':N, 'nodesets':nodesets , 'center_x':center_x, 'center_y':center_y, 'regions':regions }
|
|
1288
|
+
scipy.io.savemat(FileName, {'geo': geo}, format='5', long_field_names=True)
|
|
1289
|
+
return cubit
|
|
1290
|
+
|