Coreform-Cubit-Mesh-Export 1.11.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coreform_cubit_mesh_export-1.11.0.dist-info/METADATA +292 -0
- coreform_cubit_mesh_export-1.11.0.dist-info/RECORD +9 -0
- coreform_cubit_mesh_export-1.11.0.dist-info/WHEEL +5 -0
- coreform_cubit_mesh_export-1.11.0.dist-info/licenses/LICENSE +504 -0
- coreform_cubit_mesh_export-1.11.0.dist-info/top_level.txt +2 -0
- cubit_mesh_export.py +2738 -0
- other_formats/cubit_mesh_export_2d_geo_lukas_format.py +77 -0
- other_formats/cubit_mesh_export_3d_cdb.py +142 -0
- other_formats/cubit_mesh_export_3d_freefem_mesh.py +59 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
########################################################################
|
|
2
|
+
### Lukas FEM 2D file
|
|
3
|
+
########################################################################
|
|
4
|
+
|
|
5
|
+
def export_2D_geo_mesh(cubit, FileName):
|
|
6
|
+
|
|
7
|
+
import numpy
|
|
8
|
+
import scipy.io
|
|
9
|
+
|
|
10
|
+
nodes = []
|
|
11
|
+
node_list = []
|
|
12
|
+
|
|
13
|
+
N = cubit.get_node_count()
|
|
14
|
+
M = cubit.get_tri_count()
|
|
15
|
+
|
|
16
|
+
node_list = set()
|
|
17
|
+
for block_id in cubit.get_block_id_list():
|
|
18
|
+
elem_types = ["hex", "tet", "wedge", "pyramid"]
|
|
19
|
+
for elem_type in elem_types:
|
|
20
|
+
if elem_type == "hex":
|
|
21
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
22
|
+
else:
|
|
23
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
24
|
+
for element_id in func(block_id):
|
|
25
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
26
|
+
node_list.update(node_ids)
|
|
27
|
+
for node_id in node_list:
|
|
28
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
29
|
+
nodes.append([coord[0],coord[1]])
|
|
30
|
+
|
|
31
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
32
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
33
|
+
curve_list = cubit.get_nodeset_curves(nodeset_id)
|
|
34
|
+
node_list = []
|
|
35
|
+
for curve_id in curve_list:
|
|
36
|
+
node_list += cubit.get_curve_nodes(curve_id)
|
|
37
|
+
nodeset = numpy.array([(name, node_list)], dtype=[('name', 'U20'), ('DBCnodes', 'O')])
|
|
38
|
+
try:
|
|
39
|
+
nodesets = append(nodesets,nodeset)
|
|
40
|
+
except:
|
|
41
|
+
nodesets = nodeset
|
|
42
|
+
|
|
43
|
+
conn_matrix = numpy.zeros((M,3))
|
|
44
|
+
center_x = numpy.zeros((M))
|
|
45
|
+
center_y = numpy.zeros((M))
|
|
46
|
+
block_count = cubit.get_block_count()
|
|
47
|
+
regions = numpy.rec.array([("", [], [])]*(block_count), dtype=[('name', 'U20'), ('Elements', 'O'), ('Nodes', 'O')])
|
|
48
|
+
|
|
49
|
+
for block_id in cubit.get_block_id_list():
|
|
50
|
+
Elements = []
|
|
51
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
52
|
+
surface_list = cubit.get_block_surfaces(block_id)
|
|
53
|
+
Nodes = []
|
|
54
|
+
Elements = []
|
|
55
|
+
for surface_id in surface_list:
|
|
56
|
+
tri_list = cubit.get_surface_tris(surface_id)
|
|
57
|
+
Elements += tri_list
|
|
58
|
+
for tri_id in tri_list:
|
|
59
|
+
x = []
|
|
60
|
+
y = []
|
|
61
|
+
node_list = cubit.get_connectivity('tri',tri_id)
|
|
62
|
+
Nodes += node_list
|
|
63
|
+
conn_matrix[tri_id-1,:] = node_list
|
|
64
|
+
for node_id in node_list:
|
|
65
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
66
|
+
x.append(coord[0])
|
|
67
|
+
y.append(coord[1])
|
|
68
|
+
center_x[tri_id-1] = numpy.mean(x)
|
|
69
|
+
center_y[tri_id-1] = numpy.mean(y)
|
|
70
|
+
regions[block_id-1][0] = name
|
|
71
|
+
regions[block_id-1][1] = Elements
|
|
72
|
+
regions[block_id-1][2] = Nodes
|
|
73
|
+
|
|
74
|
+
geo = {'conn_matrix':conn_matrix, 'nodes':nodes, 'M':M, 'N':N, 'nodesets':nodesets , 'center_x':center_x, 'center_y':center_y, 'regions':regions }
|
|
75
|
+
scipy.io.savemat(FileName, {'geo': geo}, format='5', long_field_names=True)
|
|
76
|
+
return cubit
|
|
77
|
+
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
########################################################################
|
|
2
|
+
### 3D CDB file (ANSYS format)
|
|
3
|
+
### Status: Experimental - may have issues
|
|
4
|
+
########################################################################
|
|
5
|
+
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
|
|
8
|
+
def export_3D_CDB(cubit, FileName):
|
|
9
|
+
"""Export mesh to ANSYS CDB format.
|
|
10
|
+
|
|
11
|
+
Note: This is experimental code in other_formats/.
|
|
12
|
+
"""
|
|
13
|
+
# First pass: count nodes and elements
|
|
14
|
+
node_set = set()
|
|
15
|
+
elem_count = 0
|
|
16
|
+
for block_id in cubit.get_block_id_list():
|
|
17
|
+
elem_types = ["hex", "tet", "wedge", "pyramid"]
|
|
18
|
+
for elem_type in elem_types:
|
|
19
|
+
if elem_type == "hex":
|
|
20
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
21
|
+
else:
|
|
22
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
23
|
+
for element_id in func(block_id):
|
|
24
|
+
elem_count += 1
|
|
25
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
26
|
+
node_set.update(node_ids)
|
|
27
|
+
node_count = len(node_set)
|
|
28
|
+
|
|
29
|
+
# Write file
|
|
30
|
+
fid = open(FileName,'w',encoding='UTF-8')
|
|
31
|
+
fid.write(f'/COM,ANSYS RELEASE 15.0\n')
|
|
32
|
+
fid.write(f'! Exported from Coreform Cubit 2024.3\n')
|
|
33
|
+
fid.write(f'! {datetime.now().strftime("%Y/%m/%d %I:%M:%S %p")}\n')
|
|
34
|
+
fid.write(f'/PREP7\n')
|
|
35
|
+
fid.write(f'/TITLE,\n')
|
|
36
|
+
fid.write(f'*IF,_CDRDOFF,EQ,1,THEN\n')
|
|
37
|
+
fid.write(f'_CDRDOFF= \n')
|
|
38
|
+
fid.write(f'*ELSE\n')
|
|
39
|
+
fid.write(f'NUMOFF,NODE, {node_count:8d}\n')
|
|
40
|
+
fid.write(f'NUMOFF,ELEM, {elem_count:8d}\n')
|
|
41
|
+
fid.write(f'NUMOFF,TYPE, 1\n')
|
|
42
|
+
fid.write(f'*ENDIF\n')
|
|
43
|
+
fid.write(f'DOF,DELETE\n')
|
|
44
|
+
fid.write(f'ET, 1,185\n')
|
|
45
|
+
fid.write(f'NBLOCK,6,SOLID, {node_count:8d}, {node_count:8d}\n')
|
|
46
|
+
fid.write(f'(3i9,6e20.13)\n')
|
|
47
|
+
|
|
48
|
+
# Write nodes
|
|
49
|
+
node_list = set()
|
|
50
|
+
for block_id in cubit.get_block_id_list():
|
|
51
|
+
elem_types = ["hex", "tet", "wedge", "pyramid"]
|
|
52
|
+
for elem_type in elem_types:
|
|
53
|
+
if elem_type == "hex":
|
|
54
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
55
|
+
else:
|
|
56
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
57
|
+
for element_id in func(block_id):
|
|
58
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
59
|
+
node_list.update(node_ids)
|
|
60
|
+
fid.write(f'{len(node_list)}\n')
|
|
61
|
+
for node_id in node_list:
|
|
62
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
63
|
+
fid.write(f'{node_id:9d}{0:9d}{0:9d}{coord[0]:20.13e}{coord[1]:20.13e}{coord[2]:20.13e}\n')
|
|
64
|
+
|
|
65
|
+
fid.write(f'N,R5.3,LOC, -1\n')
|
|
66
|
+
|
|
67
|
+
# Write elements
|
|
68
|
+
elem_count = 0
|
|
69
|
+
for block_id in cubit.get_block_id_list():
|
|
70
|
+
fid.write(f'EBLOCK, 19, SOLID\n')
|
|
71
|
+
fid.write(f'(19i9)\n')
|
|
72
|
+
for volume_id in cubit.get_block_volumes(block_id):
|
|
73
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
74
|
+
if len(hex_list)>0:
|
|
75
|
+
for hex_id in hex_list:
|
|
76
|
+
elem_count += 1
|
|
77
|
+
node_list = cubit.get_connectivity("hex", hex_id)
|
|
78
|
+
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')
|
|
79
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
80
|
+
if len(wedge_list)>0:
|
|
81
|
+
for wedge_id in wedge_list:
|
|
82
|
+
elem_count += 1
|
|
83
|
+
node_list = cubit.get_connectivity("wedge", wedge_id)
|
|
84
|
+
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')
|
|
85
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
86
|
+
if len(tet_list)>0:
|
|
87
|
+
for tet_id in tet_list:
|
|
88
|
+
elem_count += 1
|
|
89
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
90
|
+
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')
|
|
91
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
92
|
+
if len(pyramid_list)>0:
|
|
93
|
+
for pyramid_id in pyramid_list:
|
|
94
|
+
elem_count += 1
|
|
95
|
+
node_list = cubit.get_connectivity("pyramid", pyramid_id)
|
|
96
|
+
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')
|
|
97
|
+
fid.write(f' -1\n')
|
|
98
|
+
|
|
99
|
+
for block_id in cubit.get_block_id_list():
|
|
100
|
+
name = cubit.get_exodus_entity_name("block",block_id)
|
|
101
|
+
elem_list = []
|
|
102
|
+
volume_list = cubit.get_block_volumes(block_id)
|
|
103
|
+
for volume_id in volume_list:
|
|
104
|
+
hex_list = cubit.get_volume_hexes(volume_id)
|
|
105
|
+
elem_list.extend(hex_list)
|
|
106
|
+
wedge_list = cubit.get_volume_wedges(volume_id)
|
|
107
|
+
elem_list.extend(wedge_list)
|
|
108
|
+
tet_list = cubit.get_volume_tets(volume_id)
|
|
109
|
+
elem_list.extend(tet_list)
|
|
110
|
+
pyramid_list = cubit.get_volume_pyramids(volume_id)
|
|
111
|
+
elem_list.extend(pyramid_list)
|
|
112
|
+
fid.write(f'CMBLOCK,{name:<8},ELEM,{len(elem_list):8d}\n')
|
|
113
|
+
fid.write(f'(8i10)\n')
|
|
114
|
+
for n in range(0, len(elem_list), 8):
|
|
115
|
+
strLine = ""
|
|
116
|
+
for m in range(n, min(n+8, len(elem_list))):
|
|
117
|
+
strLine += f'{elem_list[m]:10d}'
|
|
118
|
+
fid.write(f'{strLine}\n')
|
|
119
|
+
|
|
120
|
+
for nodeset_id in cubit.get_nodeset_id_list():
|
|
121
|
+
name = cubit.get_exodus_entity_name("nodeset",nodeset_id)
|
|
122
|
+
|
|
123
|
+
node_list = set()
|
|
124
|
+
for block_id in cubit.get_block_id_list():
|
|
125
|
+
elem_types = ["tri", "quad"]
|
|
126
|
+
for elem_type in elem_types:
|
|
127
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
128
|
+
for element_id in func(block_id):
|
|
129
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
130
|
+
node_list.update(node_ids)
|
|
131
|
+
|
|
132
|
+
fid.write(f'CMBLOCK,{name:<8},NODE,{len(node_list):8d}\n')
|
|
133
|
+
fid.write(f'(8i10)\n')
|
|
134
|
+
node_list = list(node_list)
|
|
135
|
+
for n in range(0, len(node_list), 8):
|
|
136
|
+
strLine = ""
|
|
137
|
+
for m in range(n, min(n+8, len(node_list))):
|
|
138
|
+
strLine += f'{node_list[m]:10d}'
|
|
139
|
+
fid.write(f'{strLine}\n')
|
|
140
|
+
|
|
141
|
+
fid.close()
|
|
142
|
+
return cubit
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
node_count = cubit.get_node_count()
|
|
10
|
+
|
|
11
|
+
with open(FileName, 'w') as fid:
|
|
12
|
+
fid.write("MeshVersionFormatted 2\n")
|
|
13
|
+
fid.write("\n")
|
|
14
|
+
fid.write("Dimension 3\n")
|
|
15
|
+
fid.write("\n")
|
|
16
|
+
fid.write("Vertices\n")
|
|
17
|
+
fid.write(f'{node_count}\n')
|
|
18
|
+
node_list = set()
|
|
19
|
+
for block_id in cubit.get_block_id_list():
|
|
20
|
+
elem_types = ["hex", "tet", "wedge", "pyramid", "tri", "face"]
|
|
21
|
+
for elem_type in elem_types:
|
|
22
|
+
if elem_type == "hex":
|
|
23
|
+
func = getattr(cubit, f"get_block_{elem_type}es")
|
|
24
|
+
else:
|
|
25
|
+
func = getattr(cubit, f"get_block_{elem_type}s")
|
|
26
|
+
for element_id in func(block_id):
|
|
27
|
+
node_ids = cubit.get_connectivity(elem_type, element_id)
|
|
28
|
+
node_list.update(node_ids)
|
|
29
|
+
for node_id in node_list:
|
|
30
|
+
coord = cubit.get_nodal_coordinates(node_id)
|
|
31
|
+
fid.write(f'{coord[0]} {coord[1]} {coord[2]} {0}\n')
|
|
32
|
+
fid.write("\n")
|
|
33
|
+
fid.write("Tetrahedra\n")
|
|
34
|
+
tet_list = set()
|
|
35
|
+
for block_id in cubit.get_block_id_list():
|
|
36
|
+
tet_list.update(cubit.get_block_tets(block_id))
|
|
37
|
+
fid.write(f'{len(tet_list)}\n')
|
|
38
|
+
for block_id in cubit.get_block_id_list():
|
|
39
|
+
tet_list = cubit.get_block_tets(block_id)
|
|
40
|
+
if len(tet_list)>0:
|
|
41
|
+
for tet_id in tet_list:
|
|
42
|
+
node_list = cubit.get_connectivity("tet", tet_id)
|
|
43
|
+
fid.write(f'{node_list[0]} {node_list[1]} {node_list[2]} {node_list[3]} {block_id}\n')
|
|
44
|
+
|
|
45
|
+
fid.write("Triangles\n")
|
|
46
|
+
tri_list = set()
|
|
47
|
+
for block_id in cubit.get_block_id_list():
|
|
48
|
+
tri_list.update(cubit.get_block_tris(block_id))
|
|
49
|
+
fid.write(f'{len(tri_list)}\n')
|
|
50
|
+
for block_id in cubit.get_block_id_list():
|
|
51
|
+
tet_list = cubit.get_block_tets(block_id)
|
|
52
|
+
if len(tri_list)>0:
|
|
53
|
+
for tri_id in tri_list:
|
|
54
|
+
node_list = cubit.get_connectivity("tri", tri_id)
|
|
55
|
+
fid.write(f'{node_list[0]} {node_list[1]} {node_list[2]} {block_id}\n')
|
|
56
|
+
fid.write("\n")
|
|
57
|
+
fid.write("End\n")
|
|
58
|
+
fid.close()
|
|
59
|
+
return cubit
|