frd2vtu 0.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.
- frd2vtu-0.1.0/LICENSE +21 -0
- frd2vtu-0.1.0/PKG-INFO +21 -0
- frd2vtu-0.1.0/README.md +3 -0
- frd2vtu-0.1.0/frd2vtu/frd2vtu.py +229 -0
- frd2vtu-0.1.0/pyproject.toml +23 -0
frd2vtu-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 wr1
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
frd2vtu-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: frd2vtu
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: converter from calculix frd to vtu
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: wr1
|
|
7
|
+
Author-email: 8971152+wr1@users.noreply.github.com
|
|
8
|
+
Requires-Python: >=3.12,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: fire (>=0.6.0,<0.7.0)
|
|
13
|
+
Requires-Dist: numpy (==1.26.4)
|
|
14
|
+
Requires-Dist: pandas (>=2.2.2,<3.0.0)
|
|
15
|
+
Requires-Dist: pyvista (>=0.44.1,<0.45.0)
|
|
16
|
+
Requires-Dist: vtk (>=9.3.1,<10.0.0)
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# frd converter
|
frd2vtu-0.1.0/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import numpy as np
|
|
3
|
+
import re
|
|
4
|
+
import pyvista as pv
|
|
5
|
+
import vtk
|
|
6
|
+
import fire
|
|
7
|
+
import time
|
|
8
|
+
import pandas as pd
|
|
9
|
+
import multiprocessing
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
e2nn = {
|
|
13
|
+
1: 8,
|
|
14
|
+
2: 6,
|
|
15
|
+
3: 4,
|
|
16
|
+
5: 15,
|
|
17
|
+
6: 10,
|
|
18
|
+
4: 20,
|
|
19
|
+
7: 3,
|
|
20
|
+
8: 6,
|
|
21
|
+
9: 4,
|
|
22
|
+
10: 8,
|
|
23
|
+
12: 3,
|
|
24
|
+
11: 2,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def split_blocks(buf):
|
|
29
|
+
patterns = [
|
|
30
|
+
b" 2C(.*?)3\n",
|
|
31
|
+
b" 3C(.*?)\n",
|
|
32
|
+
b" 1PSTEP(.*?)\n",
|
|
33
|
+
b"1ALL\n",
|
|
34
|
+
b"3 1\n",
|
|
35
|
+
b"0 0\n",
|
|
36
|
+
b" 9999",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
out = [
|
|
40
|
+
[(m.start(), m.end(), m[0]) for m in re.finditer(pattern, buf)]
|
|
41
|
+
for pattern in patterns
|
|
42
|
+
]
|
|
43
|
+
if out[0] == []:
|
|
44
|
+
print(f"frd format not binary")
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
# out = [i for i in out if i != []]
|
|
48
|
+
# out.sort(key=lambda x: x[0][0])
|
|
49
|
+
return out
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def frdbin2vtu(file_path):
|
|
53
|
+
starttime = time.time()
|
|
54
|
+
print(f"Converting {file_path}")
|
|
55
|
+
buf = open(file_path, "rb").read()
|
|
56
|
+
lcs = split_blocks(buf)
|
|
57
|
+
if lcs is None:
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
nodes = pd.DataFrame(
|
|
61
|
+
np.frombuffer(
|
|
62
|
+
buf[lcs[0][0][1] : lcs[1][0][0]],
|
|
63
|
+
dtype=np.dtype([("i", "i4"), ("x", "f8"), ("y", "f8"), ("z", "f8")]),
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# print(nodes)
|
|
68
|
+
|
|
69
|
+
elm = np.frombuffer(
|
|
70
|
+
buf[lcs[1][0][1] : lcs[2][0][0]],
|
|
71
|
+
dtype=np.dtype("i4"),
|
|
72
|
+
)
|
|
73
|
+
nz = np.zeros(nodes["i"].max() + 1, dtype=int)
|
|
74
|
+
|
|
75
|
+
nz[nodes["i"]] = np.arange(len(nodes))
|
|
76
|
+
|
|
77
|
+
els, nn = {}, 0
|
|
78
|
+
eid, emat = [], []
|
|
79
|
+
while True:
|
|
80
|
+
if nn >= len(elm):
|
|
81
|
+
break
|
|
82
|
+
|
|
83
|
+
nid = elm[1 + nn]
|
|
84
|
+
|
|
85
|
+
# print(elm)
|
|
86
|
+
ni = e2nn[nid]
|
|
87
|
+
elmarr = elm[0 + nn : ni + 4 + nn]
|
|
88
|
+
eid.append(elmarr[0])
|
|
89
|
+
emat.append(elmarr[3])
|
|
90
|
+
# deal with 20 node hexahedron
|
|
91
|
+
if nid == 4:
|
|
92
|
+
if vtk.VTK_QUADRATIC_HEXAHEDRON not in els:
|
|
93
|
+
els[vtk.VTK_QUADRATIC_HEXAHEDRON] = []
|
|
94
|
+
e = elmarr[4:].tolist()
|
|
95
|
+
els[vtk.VTK_QUADRATIC_HEXAHEDRON].append(nz[e[:12] + e[16:] + e[12:16]])
|
|
96
|
+
nn += 24
|
|
97
|
+
elif nid == 1:
|
|
98
|
+
if vtk.VTK_HEXAHEDRON not in els:
|
|
99
|
+
els[vtk.VTK_HEXAHEDRON] = []
|
|
100
|
+
e = elmarr[4:].tolist()
|
|
101
|
+
els[vtk.VTK_HEXAHEDRON].append(nz[e[:8]])
|
|
102
|
+
nn += 12
|
|
103
|
+
elif nid == 11:
|
|
104
|
+
if vtk.VTK_LINE not in els:
|
|
105
|
+
els[vtk.VTK_LINE] = []
|
|
106
|
+
e = elmarr[4:].tolist()
|
|
107
|
+
els[vtk.VTK_LINE].append(nz[e[:2]])
|
|
108
|
+
nn += 6
|
|
109
|
+
elif nid == 12:
|
|
110
|
+
if vtk.VTK_QUADRATIC_EDGE not in els:
|
|
111
|
+
els[vtk.VTK_QUADRATIC_EDGE] = []
|
|
112
|
+
e = elmarr[4:].tolist()
|
|
113
|
+
els[vtk.VTK_QUADRATIC_EDGE].append(nz[e[:3]])
|
|
114
|
+
nn += 7
|
|
115
|
+
elif nid == 10:
|
|
116
|
+
if vtk.VTK_QUADRATIC_QUAD not in els:
|
|
117
|
+
els[vtk.VTK_QUADRATIC_QUAD] = []
|
|
118
|
+
e = elmarr[4:].tolist()
|
|
119
|
+
els[vtk.VTK_QUADRATIC_QUAD].append(nz[e[:8]])
|
|
120
|
+
nn += 12
|
|
121
|
+
elif nid == 6:
|
|
122
|
+
if vtk.VTK_QUADRATIC_TETRA not in els:
|
|
123
|
+
els[vtk.VTK_QUADRATIC_TETRA] = []
|
|
124
|
+
e = elmarr[4:].tolist()
|
|
125
|
+
els[vtk.VTK_QUADRATIC_TETRA].append(nz[e[:10]])
|
|
126
|
+
nn += 14
|
|
127
|
+
elif nid == 9:
|
|
128
|
+
if vtk.VTK_QUAD not in els:
|
|
129
|
+
els[vtk.VTK_QUAD] = []
|
|
130
|
+
e = elmarr[4:].tolist()
|
|
131
|
+
els[vtk.VTK_QUAD].append(nz[e[:4]])
|
|
132
|
+
nn += 8
|
|
133
|
+
else:
|
|
134
|
+
print(f"Unknown element type: {nid}")
|
|
135
|
+
break
|
|
136
|
+
|
|
137
|
+
# convert list of lists to numpy arrays
|
|
138
|
+
for i in els:
|
|
139
|
+
els[i] = np.array(els[i])
|
|
140
|
+
|
|
141
|
+
ogrid = pv.UnstructuredGrid(els, nodes[["x", "y", "z"]].values)
|
|
142
|
+
|
|
143
|
+
ogrid.cell_data["ccx_id"] = np.array(eid)
|
|
144
|
+
ogrid.cell_data["ccx_mat"] = np.array(emat)
|
|
145
|
+
|
|
146
|
+
ogrid.point_data["ccx_id"] = nodes["i"]
|
|
147
|
+
|
|
148
|
+
endblocks = lcs[3] + lcs[4] + lcs[5] # if len(lcs) > 4 else lcs[3] + lcs[4]
|
|
149
|
+
|
|
150
|
+
endblocks.sort(key=lambda x: x[0])
|
|
151
|
+
|
|
152
|
+
# print(len(lcs[2]), len(endblocks))
|
|
153
|
+
|
|
154
|
+
headers = [buf[j[0][0] : j[1][1]] for j in zip(lcs[2], endblocks)]
|
|
155
|
+
|
|
156
|
+
# print(headers)
|
|
157
|
+
|
|
158
|
+
for n, bl in enumerate(headers):
|
|
159
|
+
# print(f"Block {bl}", "\n" * 5)
|
|
160
|
+
|
|
161
|
+
lns = bl.decode("ascii").split("\n")
|
|
162
|
+
|
|
163
|
+
if bl.find(b"MODAL") != -1 and bl.find(b"DISP") != -1:
|
|
164
|
+
# fix for modal analysis
|
|
165
|
+
# print("true")
|
|
166
|
+
lns = lns[5:]
|
|
167
|
+
# print(lns)
|
|
168
|
+
|
|
169
|
+
timestamp, nn = lns[1].split()[2:4]
|
|
170
|
+
name = lns[2].split()[1]
|
|
171
|
+
|
|
172
|
+
if name in ["NORM", "SENMISE", "SENPS1", "SDV"]:
|
|
173
|
+
continue
|
|
174
|
+
|
|
175
|
+
ncomp = int(lns[2].split()[2])
|
|
176
|
+
print(f"timestamp: {timestamp}, nn: {nn}, name: {name}")
|
|
177
|
+
|
|
178
|
+
# set the start of the binary block to the end of the ascii block
|
|
179
|
+
startblock = endblocks[n][1]
|
|
180
|
+
|
|
181
|
+
# print(ncomp)
|
|
182
|
+
ncl = {6: 6, 4: 3, 1: 1, 20: 20}
|
|
183
|
+
|
|
184
|
+
nms = [("c_" + str(i), "f4") for i in range(ncl[ncomp])]
|
|
185
|
+
dt = np.dtype([("id", "i4")] + nms)
|
|
186
|
+
|
|
187
|
+
endblock = dt.itemsize * int(nn) + startblock
|
|
188
|
+
|
|
189
|
+
na = pd.DataFrame(np.frombuffer(buf[startblock:endblock], dtype=dt))
|
|
190
|
+
|
|
191
|
+
# print(len(na), len(nodes))
|
|
192
|
+
if len(na) != len(nodes):
|
|
193
|
+
missing_values = nodes[~nodes["i"].isin(na["id"])]["i"]
|
|
194
|
+
padding = pd.DataFrame({"id": missing_values})
|
|
195
|
+
for col in na.columns:
|
|
196
|
+
if col != "id":
|
|
197
|
+
padding[col] = 0
|
|
198
|
+
|
|
199
|
+
na = pd.concat([na, padding], ignore_index=True)
|
|
200
|
+
|
|
201
|
+
arrn = f"{name}_{timestamp}"
|
|
202
|
+
# if name not in ["PE"]:
|
|
203
|
+
ogrid.point_data[arrn] = na[[i[0] for i in nms]].values
|
|
204
|
+
|
|
205
|
+
of = file_path.replace(".frd", ".vtu")
|
|
206
|
+
# ogrid.save(of, binary=False)
|
|
207
|
+
ogrid.save(of)
|
|
208
|
+
print(f"Saved {of}")
|
|
209
|
+
endtime = time.time()
|
|
210
|
+
print(f"Elapsed time: {endtime - starttime} seconds")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def frd2vtu(*frd):
|
|
214
|
+
parr = True
|
|
215
|
+
if parr:
|
|
216
|
+
p = multiprocessing.Pool()
|
|
217
|
+
p.map(frdbin2vtu, frd)
|
|
218
|
+
p.close()
|
|
219
|
+
else:
|
|
220
|
+
for f in frd:
|
|
221
|
+
frdbin2vtu(f)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def main():
|
|
225
|
+
fire.Fire(frd2vtu)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if __name__ == "__main__":
|
|
229
|
+
main()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "frd2vtu"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "converter from calculix frd to vtu"
|
|
5
|
+
authors = ["wr1 <8971152+wr1@users.noreply.github.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "^3.12"
|
|
11
|
+
fire = "^0.6.0"
|
|
12
|
+
pyvista = "^0.44.1"
|
|
13
|
+
vtk = "^9.3.1"
|
|
14
|
+
pandas = "^2.2.2"
|
|
15
|
+
numpy = "1.26.4"
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["poetry-core"]
|
|
19
|
+
build-backend = "poetry.core.masonry.api"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
[tool.poetry.scripts]
|
|
23
|
+
frd2vtu = "frd2vtu.frd2vtu:main"
|