Coreform-Cubit-Mesh-Export 1.0.4__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of Coreform-Cubit-Mesh-Export might be problematic. Click here for more details.
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/Coreform_Cubit_Mesh_Export.egg-info/PKG-INFO +1 -1
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/Coreform_Cubit_Mesh_Export.egg-info/SOURCES.txt +5 -1
- coreform_cubit_mesh_export-1.1.0/Coreform_Cubit_Mesh_Export.egg-info/top_level.txt +4 -0
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/PKG-INFO +1 -1
- coreform_cubit_mesh_export-1.1.0/cubit_mesh_export.py +584 -0
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/pyproject.toml +1 -1
- coreform_cubit_mesh_export-1.1.0/sample_script/cubit_mesh_export_2d_geo_lukas_format.py +77 -0
- coreform_cubit_mesh_export-1.1.0/sample_script/cubit_mesh_export_3d_cdb.py +115 -0
- coreform_cubit_mesh_export-1.1.0/sample_script/cubit_mesh_export_3d_freefem_mesh.py +59 -0
- coreform_cubit_mesh_export-1.1.0/sample_script/cubit_mesh_export_3d_gmesh_v4.py +191 -0
- coreform_cubit_mesh_export-1.0.4/Coreform_Cubit_Mesh_Export.egg-info/top_level.txt +0 -3
- coreform_cubit_mesh_export-1.0.4/cubit_mesh_export.py +0 -1352
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/Coreform_Cubit_Mesh_Export.egg-info/dependency_links.txt +0 -0
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/Coreform_Cubit_Mesh_Export.egg-info/requires.txt +0 -0
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/README.md +0 -0
- {coreform_cubit_mesh_export-1.0.4 → coreform_cubit_mesh_export-1.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Coreform_Cubit_Mesh_Export
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Cubit mesh export to various formats including Gmsh, Nastran, and VTK
|
|
5
5
|
Author-email: Kengo Sugahara <ksugahar@gmail.com>
|
|
6
6
|
Maintainer-email: Kengo Sugahara <ksugahar@gmail.com>
|
|
@@ -5,4 +5,8 @@ Coreform_Cubit_Mesh_Export.egg-info/PKG-INFO
|
|
|
5
5
|
Coreform_Cubit_Mesh_Export.egg-info/SOURCES.txt
|
|
6
6
|
Coreform_Cubit_Mesh_Export.egg-info/dependency_links.txt
|
|
7
7
|
Coreform_Cubit_Mesh_Export.egg-info/requires.txt
|
|
8
|
-
Coreform_Cubit_Mesh_Export.egg-info/top_level.txt
|
|
8
|
+
Coreform_Cubit_Mesh_Export.egg-info/top_level.txt
|
|
9
|
+
sample_script/cubit_mesh_export_2d_geo_lukas_format.py
|
|
10
|
+
sample_script/cubit_mesh_export_3d_cdb.py
|
|
11
|
+
sample_script/cubit_mesh_export_3d_freefem_mesh.py
|
|
12
|
+
sample_script/cubit_mesh_export_3d_gmesh_v4.py
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Coreform_Cubit_Mesh_Export
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Cubit mesh export to various formats including Gmsh, Nastran, and VTK
|
|
5
5
|
Author-email: Kengo Sugahara <ksugahar@gmail.com>
|
|
6
6
|
Maintainer-email: Kengo Sugahara <ksugahar@gmail.com>
|
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
########################################################################
|
|
2
|
+
### Gmsh format version 2
|
|
3
|
+
########################################################################
|
|
4
|
+
|
|
5
|
+
def export_Gmsh_ver2(cubit, FileName):
|
|
6
|
+
|
|
7
|
+
with open(FileName, 'w') as fid:
|
|
8
|
+
|
|
9
|
+
fid.write("$MeshFormat\n")
|
|
10
|
+
fid.write("2.2 0 8\n")
|
|
11
|
+
fid.write("$EndMeshFormat\n")
|
|
12
|
+
|
|
13
|
+
fid.write("$PhysicalNames\n")
|
|
14
|
+
fid.write(f'{cubit.get_block_count()}\n')
|
|
15
|
+
for block_id in cubit.get_block_id_list():
|
|
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')
|
|
23
|
+
fid.write('$EndPhysicalNames\n')
|
|
24
|
+
|
|
25
|
+
fid.write("$Nodes\n")
|
|
26
|
+
node_list = set()
|
|
27
|
+
for block_id in cubit.get_block_id_list():
|
|
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)
|
|
37
|
+
|
|
38
|
+
fid.write(f'{len(node_list)}\n')
|
|
39
|
+
for node_id in node_list:
|
|
40
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
41
|
+
fid.write(f'{node_id} {coord[0]} {coord[1]} {coord[2]}\n')
|
|
42
|
+
fid.write('$EndNodes\n')
|
|
43
|
+
|
|
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()
|
|
51
|
+
|
|
52
|
+
for block_id in cubit.get_block_id_list():
|
|
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
|
|
62
|
+
fid.write('$Elements\n')
|
|
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')
|
|
64
|
+
|
|
65
|
+
for block_id in cubit.get_block_id_list():
|
|
66
|
+
|
|
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')
|
|
86
|
+
|
|
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')
|
|
95
|
+
|
|
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')
|
|
104
|
+
|
|
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)
|
|
128
|
+
for edge_id in edge_list:
|
|
129
|
+
element_id += 1
|
|
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')
|
|
135
|
+
|
|
136
|
+
fid.write('$EndElements\n')
|
|
137
|
+
fid.close()
|
|
138
|
+
return cubit
|
|
139
|
+
|
|
140
|
+
########################################################################
|
|
141
|
+
### NASTRAN 2D file
|
|
142
|
+
########################################################################
|
|
143
|
+
|
|
144
|
+
def export_2D_Nastran(cubit, FileName):
|
|
145
|
+
import datetime
|
|
146
|
+
formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
|
|
147
|
+
|
|
148
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
149
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
150
|
+
fid.write("$\n")
|
|
151
|
+
fid.write("$ CUBIT NX Nastran Translator\n")
|
|
152
|
+
fid.write("$\n")
|
|
153
|
+
fid.write(f"$ File: {FileName}\n")
|
|
154
|
+
fid.write(f"$ Time Stamp: {formatted_date_time}\n")
|
|
155
|
+
fid.write("$\n")
|
|
156
|
+
fid.write("$\n")
|
|
157
|
+
fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
|
|
158
|
+
fid.write("$\n")
|
|
159
|
+
fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
|
|
160
|
+
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")
|
|
161
|
+
fid.write("$\n")
|
|
162
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
163
|
+
fid.write("$\n")
|
|
164
|
+
fid.write("$\n")
|
|
165
|
+
fid.write("$ -------------------------\n")
|
|
166
|
+
fid.write("$ Executive Control Section\n")
|
|
167
|
+
fid.write("$ -------------------------\n")
|
|
168
|
+
fid.write("$\n")
|
|
169
|
+
fid.write("SOL 101\n")
|
|
170
|
+
fid.write("CEND\n")
|
|
171
|
+
fid.write("$\n")
|
|
172
|
+
fid.write("$\n")
|
|
173
|
+
fid.write("$ --------------------\n")
|
|
174
|
+
fid.write("$ Case Control Section\n")
|
|
175
|
+
fid.write("$ --------------------\n")
|
|
176
|
+
fid.write("$\n")
|
|
177
|
+
fid.write("ECHO = SORT\n")
|
|
178
|
+
fid.write("$\n")
|
|
179
|
+
fid.write("$\n")
|
|
180
|
+
fid.write("$ Name: Initial\n")
|
|
181
|
+
fid.write("$\n")
|
|
182
|
+
fid.write("$\n")
|
|
183
|
+
fid.write("$ Name: Default Set\n")
|
|
184
|
+
fid.write("$\n")
|
|
185
|
+
fid.write("SUBCASE = 1\n")
|
|
186
|
+
fid.write("$\n")
|
|
187
|
+
fid.write("LABEL = Default Set\n")
|
|
188
|
+
fid.write("$\n")
|
|
189
|
+
fid.write("$ -----------------\n")
|
|
190
|
+
fid.write("$ Bulk Data Section\n")
|
|
191
|
+
fid.write("$ -----------------\n")
|
|
192
|
+
fid.write("$\n")
|
|
193
|
+
fid.write("BEGIN BULK\n")
|
|
194
|
+
fid.write("$\n")
|
|
195
|
+
fid.write("$ Params\n")
|
|
196
|
+
fid.write("$\n")
|
|
197
|
+
fid.write("$\n")
|
|
198
|
+
fid.write("$ Node cards\n")
|
|
199
|
+
fid.write("$\n")
|
|
200
|
+
|
|
201
|
+
node_list = set()
|
|
202
|
+
for block_id in cubit.get_block_id_list():
|
|
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:
|
|
210
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
211
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
|
|
212
|
+
|
|
213
|
+
element_id = 0
|
|
214
|
+
fid.write("$\n")
|
|
215
|
+
fid.write("$ Element cards\n")
|
|
216
|
+
fid.write("$\n")
|
|
217
|
+
for block_id in cubit.get_block_id_list():
|
|
218
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
219
|
+
fid.write("$\n")
|
|
220
|
+
fid.write(f"$ Name: {name}\n")
|
|
221
|
+
fid.write("$\n")
|
|
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])
|
|
227
|
+
normal = cubit.get_surface_normal(surface_id)
|
|
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")
|
|
251
|
+
fid.write("$\n")
|
|
252
|
+
fid.write("$ Property cards\n")
|
|
253
|
+
fid.write("$\n")
|
|
254
|
+
|
|
255
|
+
for block_id in cubit.get_block_id_list():
|
|
256
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
257
|
+
fid.write("$\n")
|
|
258
|
+
fid.write(f"$ Name: {name}\n")
|
|
259
|
+
fid.write("$\n")
|
|
260
|
+
fid.write(f"MAT1 {block_id:< 8}{1:<8}{1:<8}{1:<8}\n")
|
|
261
|
+
fid.write("ENDDATA\n")
|
|
262
|
+
fid.close()
|
|
263
|
+
return cubit
|
|
264
|
+
|
|
265
|
+
########################################################################
|
|
266
|
+
### 3D Nastran file
|
|
267
|
+
########################################################################
|
|
268
|
+
|
|
269
|
+
def export_3D_Nastran(cubit, FileName, PYRAM=True):
|
|
270
|
+
|
|
271
|
+
import datetime
|
|
272
|
+
formatted_date_time = datetime.datetime.now().strftime("%d-%b-%y at %H:%M:%S")
|
|
273
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
274
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
275
|
+
fid.write("$\n")
|
|
276
|
+
fid.write("$ CUBIT NX Nastran Translator\n")
|
|
277
|
+
fid.write("$\n")
|
|
278
|
+
fid.write(f"$ File: {FileName}\n")
|
|
279
|
+
fid.write(f"$ Time Stamp: {formatted_date_time}\n")
|
|
280
|
+
fid.write("$\n")
|
|
281
|
+
fid.write("$\n")
|
|
282
|
+
fid.write("$ PLEASE CHECK YOUR MODEL FOR UNITS CONSISTENCY.\n")
|
|
283
|
+
fid.write("$\n")
|
|
284
|
+
fid.write("$ It should be noted that load ID's from CUBIT may NOT correspond to Nastran SID's\n")
|
|
285
|
+
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")
|
|
286
|
+
fid.write("$\n")
|
|
287
|
+
fid.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n")
|
|
288
|
+
fid.write("$\n")
|
|
289
|
+
fid.write("$\n")
|
|
290
|
+
fid.write("$ -------------------------\n")
|
|
291
|
+
fid.write("$ Executive Control Section\n")
|
|
292
|
+
fid.write("$ -------------------------\n")
|
|
293
|
+
fid.write("$\n")
|
|
294
|
+
fid.write("SOL 101\n")
|
|
295
|
+
fid.write("CEND\n")
|
|
296
|
+
fid.write("$\n")
|
|
297
|
+
fid.write("$\n")
|
|
298
|
+
fid.write("$ --------------------\n")
|
|
299
|
+
fid.write("$ Case Control Section\n")
|
|
300
|
+
fid.write("$ --------------------\n")
|
|
301
|
+
fid.write("$\n")
|
|
302
|
+
fid.write("ECHO = SORT\n")
|
|
303
|
+
fid.write("$\n")
|
|
304
|
+
fid.write("$\n")
|
|
305
|
+
fid.write("$ Name: Initial\n")
|
|
306
|
+
fid.write("$\n")
|
|
307
|
+
fid.write("$\n")
|
|
308
|
+
fid.write("$ Name: Default Set\n")
|
|
309
|
+
fid.write("$\n")
|
|
310
|
+
fid.write("SUBCASE = 1\n")
|
|
311
|
+
fid.write("$\n")
|
|
312
|
+
fid.write("LABEL = Default Set\n")
|
|
313
|
+
fid.write("$\n")
|
|
314
|
+
fid.write("$ -----------------\n")
|
|
315
|
+
fid.write("$ Bulk Data Section\n")
|
|
316
|
+
fid.write("$ -----------------\n")
|
|
317
|
+
fid.write("$\n")
|
|
318
|
+
fid.write("BEGIN BULK\n")
|
|
319
|
+
fid.write("$\n")
|
|
320
|
+
fid.write("$ Params\n")
|
|
321
|
+
fid.write("$\n")
|
|
322
|
+
fid.write("$\n")
|
|
323
|
+
fid.write("$ Node cards\n")
|
|
324
|
+
fid.write("$\n")
|
|
325
|
+
|
|
326
|
+
node_list = set()
|
|
327
|
+
for block_id in cubit.get_block_id_list():
|
|
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:
|
|
339
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
340
|
+
fid.write(f"GRID* {node_id:>16}{0:>16}{coord[0]:>16.5f}{coord[1]:>16.5f}\n* {coord[2]:>16.5f}\n")
|
|
341
|
+
|
|
342
|
+
element_id = 0
|
|
343
|
+
fid.write("$\n")
|
|
344
|
+
fid.write("$ Element cards\n")
|
|
345
|
+
fid.write("$\n")
|
|
346
|
+
for block_id in cubit.get_block_id_list():
|
|
347
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
348
|
+
fid.write("$\n")
|
|
349
|
+
fid.write(f"$ Name: {name}\n")
|
|
350
|
+
fid.write("$\n")
|
|
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:
|
|
370
|
+
element_id += 1
|
|
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:
|
|
373
|
+
element_id += 1
|
|
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:
|
|
388
|
+
element_id += 1
|
|
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")
|
|
392
|
+
fid.write("$\n")
|
|
393
|
+
fid.write("$ Property cards\n")
|
|
394
|
+
fid.write("$\n")
|
|
395
|
+
|
|
396
|
+
for block_id in cubit.get_block_id_list():
|
|
397
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
398
|
+
fid.write("$\n")
|
|
399
|
+
fid.write(f"$ Name: {name}\n")
|
|
400
|
+
fid.write("$\n")
|
|
401
|
+
fid.write(f"MAT1 {block_id:< 8}{1:<8}{1:<8}{1:<8}\n")
|
|
402
|
+
fid.write("ENDDATA\n")
|
|
403
|
+
fid.close()
|
|
404
|
+
return cubit
|
|
405
|
+
|
|
406
|
+
########################################################################
|
|
407
|
+
### ELF meg file
|
|
408
|
+
########################################################################
|
|
409
|
+
|
|
410
|
+
def export_meg(cubit, FileName, DIM='T', MGR2=[]):
|
|
411
|
+
|
|
412
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
413
|
+
fid.write("BOOK MEP 3.50\n")
|
|
414
|
+
fid.write("* ELF/MESH VERSION 7.3.0\n")
|
|
415
|
+
fid.write("* SOLVER = ELF/MAGIC\n")
|
|
416
|
+
fid.write("MGSC 0.001\n")
|
|
417
|
+
fid.write("* NODE\n")
|
|
418
|
+
|
|
419
|
+
node_list = set()
|
|
420
|
+
for block_id in cubit.get_block_id_list():
|
|
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:
|
|
431
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
432
|
+
if DIM=='T':
|
|
433
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {coord[2]}\n")
|
|
434
|
+
if DIM=='K':
|
|
435
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {coord[1]} {0}\n")
|
|
436
|
+
if DIM=='R':
|
|
437
|
+
fid.write(f"MGR1 {node_id} 0 {coord[0]} {0} {coord[2]}\n")
|
|
438
|
+
|
|
439
|
+
element_id = 0
|
|
440
|
+
fid.write("* ELEMENT K\n")
|
|
441
|
+
for block_id in cubit.get_block_id_list():
|
|
442
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
443
|
+
|
|
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")
|
|
485
|
+
|
|
486
|
+
fid.write("* NODE\n")
|
|
487
|
+
for node_id in range(len(MGR2)):
|
|
488
|
+
fid.write(f"MGR2 {node_id+1} 0 {MGR2[node_id][0]} {MGR2[node_id][1]} {MGR2[node_id][2]}\n")
|
|
489
|
+
fid.write("BOOK END\n")
|
|
490
|
+
fid.close()
|
|
491
|
+
return cubit
|
|
492
|
+
|
|
493
|
+
########################################################################
|
|
494
|
+
### vtk format
|
|
495
|
+
########################################################################
|
|
496
|
+
|
|
497
|
+
def export_vtk(cubit, FileName):
|
|
498
|
+
|
|
499
|
+
fid = open(FileName,'w')
|
|
500
|
+
fid.write('# vtk DataFile Version 3.0\n')
|
|
501
|
+
fid.write(f'Unstructured Grid {FileName}\n')
|
|
502
|
+
fid.write('ASCII\n')
|
|
503
|
+
fid.write('DATASET UNSTRUCTURED_GRID\n')
|
|
504
|
+
fid.write(f'POINTS {cubit.get_node_count()} float\n')
|
|
505
|
+
|
|
506
|
+
for node_id in range(cubit.get_node_count()+1):
|
|
507
|
+
if cubit.get_node_exists(node_id):
|
|
508
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
509
|
+
fid.write(f'{coord[0]} {coord[1]} {coord[2]}\n')
|
|
510
|
+
|
|
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()
|
|
518
|
+
|
|
519
|
+
for block_id in cubit.get_block_id_list():
|
|
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' )
|
|
529
|
+
for tet_id in tet_list:
|
|
530
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
531
|
+
fid.write(f'4 {node_list[0]-1} {node_list[1]-1} {node_list[2]-1} {node_list[3]-1}\n')
|
|
532
|
+
for hex_id in hex_list:
|
|
533
|
+
node_list = cubit.get_connectivity("hex", hex_id)
|
|
534
|
+
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')
|
|
535
|
+
for wedge_id in wedge_list:
|
|
536
|
+
node_list = cubit.get_connectivity("wedge", wedge_id)
|
|
537
|
+
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')
|
|
538
|
+
for pyramid_id in pyramid_list:
|
|
539
|
+
node_list = cubit.get_connectivity("pyramid", pyramid_id)
|
|
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')
|
|
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')
|
|
552
|
+
for tet_id in tet_list:
|
|
553
|
+
fid.write('10\n')
|
|
554
|
+
for hex_id in hex_list:
|
|
555
|
+
fid.write('12\n')
|
|
556
|
+
for wedge_id in wedge_list:
|
|
557
|
+
fid.write('13\n')
|
|
558
|
+
for pyramid_id in pyramid_list:
|
|
559
|
+
fid.write('14\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')
|
|
567
|
+
fid.write('SCALARS scalars float\n')
|
|
568
|
+
fid.write('LOOKUP_TABLE default\n')
|
|
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')
|
|
583
|
+
return cubit
|
|
584
|
+
|