tecio-python 0.4.0__py3-none-any.whl → 0.4.2__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.
- tecio/__init__.py +46 -2
- tecio/_constants.py +2 -2
- tecio/_dat_read.py +268 -17
- tecio/_dat_write.py +347 -10
- tecio/_elements.py +1311 -0
- tecio/_io.py +108 -31
- tecio/_meta.py +47 -20
- tecio/_plt_legacy.py +9 -1
- tecio/_plt_read.py +285 -89
- tecio/_plt_write.py +286 -9
- tecio/_reader.py +460 -19
- tecio/_szl_read.py +155 -17
- tecio/_szl_write.py +322 -11
- tecio/_utils.py +78 -15
- tecio/_writer.py +963 -102
- tecio/cli/tec2mat.py +69 -30
- tecio/cli/tecaux.py +24 -30
- tecio/cli/tecdump.py +67 -5
- tecio/cli/tecelretyp.py +1096 -0
- tecio/cli/tecextract.py +57 -14
- tecio/cli/tecfix.py +32 -14
- tecio/cli/tecmerge.py +289 -45
- tecio/cli/teconvert.py +29 -16
- tecio/cli/tecscale.py +40 -13
- tecio/cli/tecslice.py +158 -69
- tecio/cli/tecstats.py +6 -2
- tecio/libtecio.py +192 -67
- {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/matlab/tecmat2struct.m +18 -18
- {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/paraview/TecplotTecioReader.py +463 -38
- {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/paraview/TecplotTecioWriter.py +459 -84
- {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/METADATA +33 -17
- tecio_python-0.4.2.dist-info/RECORD +40 -0
- {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/WHEEL +1 -1
- {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/entry_points.txt +1 -0
- tecio_python-0.4.0.dist-info/RECORD +0 -38
- {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/matlab/contourfe.m +0 -0
- {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/licenses/LICENSE +0 -0
- {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/licenses/NOTICE +0 -0
- {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/top_level.txt +0 -0
tecio/_plt_read.py
CHANGED
|
@@ -21,13 +21,14 @@ Notes:
|
|
|
21
21
|
StrandID, SolutionTime, value location, face-neighbor, or aux-data. v107
|
|
22
22
|
(``#!TDV107``) and v111 (``#!TDV111``) are structurally v112 with two deltas each:
|
|
23
23
|
v107 has no file-level FileType field and no per-zone "face neighbors complete"
|
|
24
|
-
flag; v111 has one extra
|
|
25
|
-
purpose. Legacy files are read-only;
|
|
26
|
-
current format.
|
|
24
|
+
flag; v111 has one extra INT32 value right after the zone type (the data-packing
|
|
25
|
+
field, 0 = block) of unidentified purpose. Legacy files are read-only;
|
|
26
|
+
:mod:`._plt_write` only ever writes the current format.
|
|
27
27
|
|
|
28
28
|
Limitations:
|
|
29
|
-
* FEPOLYGON and FEPOLYHEDRON zones are
|
|
30
|
-
|
|
29
|
+
* FEPOLYGON and FEPOLYHEDRON zones are read as
|
|
30
|
+
:class:`~tecio._reader.TecplotPolyZoneReader` (v111 and v112). The v191 face-map
|
|
31
|
+
layout is untested, and v107 files cannot contain poly zones.
|
|
31
32
|
* Bit-packed data (DataType 6) is not supported and raises NotImplementedError.
|
|
32
33
|
* Legacy files have no passive-variable.
|
|
33
34
|
|
|
@@ -59,9 +60,11 @@ from ._constants import (
|
|
|
59
60
|
)
|
|
60
61
|
from ._containers import ZoneList
|
|
61
62
|
from ._reader import (
|
|
63
|
+
PolyArrayKey,
|
|
62
64
|
TecplotAuxDataReader,
|
|
63
65
|
TecplotFEZoneReader,
|
|
64
66
|
TecplotOrderedZoneReader,
|
|
67
|
+
TecplotPolyZoneReader,
|
|
65
68
|
TecplotReader,
|
|
66
69
|
TecplotVariableReader,
|
|
67
70
|
TecplotZoneReader,
|
|
@@ -99,6 +102,11 @@ _NODES_PER_ELEMENT: dict[ZoneType, int] = {
|
|
|
99
102
|
ZoneType.FEBRICK: 8,
|
|
100
103
|
}
|
|
101
104
|
|
|
105
|
+
_POLY_TYPES: frozenset[ZoneType] = frozenset({
|
|
106
|
+
ZoneType.FEPOLYGON,
|
|
107
|
+
ZoneType.FEPOLYHEDRON,
|
|
108
|
+
})
|
|
109
|
+
|
|
102
110
|
# Faces per element
|
|
103
111
|
_FACES_PER_ELEMENT: dict[ZoneType, int] = {
|
|
104
112
|
ZoneType.FELINESEG: 2,
|
|
@@ -153,7 +161,14 @@ class PltReadError(RuntimeError):
|
|
|
153
161
|
|
|
154
162
|
|
|
155
163
|
def _read_int32(fp: io.BufferedIOBase, byte_order: str) -> int:
|
|
156
|
-
"""Read a single INT32 with the given byte-order prefix.
|
|
164
|
+
"""Read a single INT32 with the given byte-order prefix.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
int: Value decoded by byte order.
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
PltReadError: If the file ends before the value.
|
|
171
|
+
"""
|
|
157
172
|
raw = fp.read(4)
|
|
158
173
|
if len(raw) < 4:
|
|
159
174
|
raise PltReadError("Unexpected end of file reading INT32.")
|
|
@@ -162,7 +177,14 @@ def _read_int32(fp: io.BufferedIOBase, byte_order: str) -> int:
|
|
|
162
177
|
|
|
163
178
|
|
|
164
179
|
def _read_int64(fp: io.BufferedIOBase, byte_order: str) -> int:
|
|
165
|
-
"""Read a single INT64 with the given byte-order prefix.
|
|
180
|
+
"""Read a single INT64 with the given byte-order prefix.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
int: Value decoded by byte order.
|
|
184
|
+
|
|
185
|
+
Raises:
|
|
186
|
+
PltReadError: If the file ends before the value.
|
|
187
|
+
"""
|
|
166
188
|
raw = fp.read(8)
|
|
167
189
|
if len(raw) < 8:
|
|
168
190
|
raise PltReadError("Unexpected end of file reading INT64.")
|
|
@@ -171,7 +193,14 @@ def _read_int64(fp: io.BufferedIOBase, byte_order: str) -> int:
|
|
|
171
193
|
|
|
172
194
|
|
|
173
195
|
def _read_float32(fp: io.BufferedIOBase, byte_order: str) -> float:
|
|
174
|
-
"""Read a single FLOAT32 with the given byte-order prefix.
|
|
196
|
+
"""Read a single FLOAT32 with the given byte-order prefix.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
float: Value decoded by byte order.
|
|
200
|
+
|
|
201
|
+
Raises:
|
|
202
|
+
PltReadError: If the file ends before the value.
|
|
203
|
+
"""
|
|
175
204
|
raw = fp.read(4)
|
|
176
205
|
if len(raw) < 4:
|
|
177
206
|
raise PltReadError("Unexpected end of file reading FLOAT32.")
|
|
@@ -180,7 +209,14 @@ def _read_float32(fp: io.BufferedIOBase, byte_order: str) -> float:
|
|
|
180
209
|
|
|
181
210
|
|
|
182
211
|
def _read_float64(fp: io.BufferedIOBase, byte_order: str) -> float:
|
|
183
|
-
"""Read a single FLOAT64 with the given byte-order prefix.
|
|
212
|
+
"""Read a single FLOAT64 with the given byte-order prefix.
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
float: Value decoded by byte order.
|
|
216
|
+
|
|
217
|
+
Raises:
|
|
218
|
+
PltReadError: If the file ends before the value.
|
|
219
|
+
"""
|
|
184
220
|
raw = fp.read(8)
|
|
185
221
|
if len(raw) < 8:
|
|
186
222
|
raise PltReadError("Unexpected end of file reading FLOAT64.")
|
|
@@ -193,6 +229,9 @@ def _read_string(fp: io.BufferedIOBase, byte_order: str) -> str:
|
|
|
193
229
|
|
|
194
230
|
The PLT format stores each character as a 4-byte integer (see Note 1 of the format
|
|
195
231
|
spec). The string is terminated by a zero INT32.
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
str: utf-8 decoded string.
|
|
196
235
|
"""
|
|
197
236
|
chars: list[str] = []
|
|
198
237
|
while True:
|
|
@@ -218,7 +257,11 @@ def _skip_string(fp: io.BufferedIOBase, byte_order: str) -> None:
|
|
|
218
257
|
|
|
219
258
|
|
|
220
259
|
def _peek_float32(fp: io.BufferedIOBase, byte_order: str) -> float:
|
|
221
|
-
"""Peek at the next 4 bytes as a FLOAT32 without advancing the file pointer.
|
|
260
|
+
"""Peek at the next 4 bytes as a FLOAT32 without advancing the file pointer.
|
|
261
|
+
|
|
262
|
+
Returns:
|
|
263
|
+
float: The value of the peeked bytes as float32.
|
|
264
|
+
"""
|
|
222
265
|
pos = fp.tell()
|
|
223
266
|
val = _read_float32(fp, byte_order)
|
|
224
267
|
fp.seek(pos)
|
|
@@ -259,11 +302,17 @@ class _ZoneMeta:
|
|
|
259
302
|
num_nodes: int = 0
|
|
260
303
|
num_elements: int = 0
|
|
261
304
|
|
|
262
|
-
# Poly zone extras
|
|
305
|
+
# Poly zone extras. num_boundary_faces is the public count; the header stores one
|
|
306
|
+
# more when any exist (TecIO reserves entry 0 of the boundary tables), kept as
|
|
307
|
+
# boundary_table_entries since it sizes the on-disk offsets table.
|
|
263
308
|
num_faces: int = 0
|
|
264
309
|
total_face_nodes: int = 0
|
|
265
310
|
num_boundary_faces: int = 0
|
|
311
|
+
boundary_table_entries: int = 0
|
|
266
312
|
num_boundary_connections: int = 0
|
|
313
|
+
# Face-map blocks on disk, {key: (file_offset, count, itemsize)}, empty for zones
|
|
314
|
+
# that share connectivity.
|
|
315
|
+
poly_sections: dict[str, tuple[int, int, int]] = field(default_factory=dict)
|
|
267
316
|
|
|
268
317
|
# Variable metadata (per variable)
|
|
269
318
|
var_data_types: list[DataType] = field(default_factory=list)
|
|
@@ -360,7 +409,11 @@ class _PltParser:
|
|
|
360
409
|
# -- Header section ----------------------------------------------------------------
|
|
361
410
|
|
|
362
411
|
def _parse_header(self, fp: io.BufferedIOBase) -> None:
|
|
363
|
-
"""Parse the PLT header section up to and including EOHMARKER.
|
|
412
|
+
"""Parse the PLT header section up to and including EOHMARKER.
|
|
413
|
+
|
|
414
|
+
Raises:
|
|
415
|
+
PltReadError: If an unexpected header marker is found.
|
|
416
|
+
"""
|
|
364
417
|
self._detect_version_and_endian(fp)
|
|
365
418
|
byte_order = self.byte_order
|
|
366
419
|
|
|
@@ -434,7 +487,12 @@ class _PltParser:
|
|
|
434
487
|
)
|
|
435
488
|
|
|
436
489
|
def _detect_version_and_endian(self, fp: io.BufferedIOBase) -> None:
|
|
437
|
-
"""Read magic bytes and INT32=1 endian probe; set ``self.byte_order``.
|
|
490
|
+
"""Read magic bytes and INT32=1 endian probe; set ``self.byte_order``.
|
|
491
|
+
|
|
492
|
+
Raises:
|
|
493
|
+
PltReadError: If the magic number is unrecognised or the byte-order probe is
|
|
494
|
+
invalid.
|
|
495
|
+
"""
|
|
438
496
|
magic = fp.read(8)
|
|
439
497
|
if magic == _MAGIC_V75:
|
|
440
498
|
self._file_version = "v75"
|
|
@@ -474,7 +532,12 @@ class _PltParser:
|
|
|
474
532
|
)
|
|
475
533
|
|
|
476
534
|
def _parse_zone_header(self, fp: io.BufferedIOBase, *, v191: bool) -> None:
|
|
477
|
-
"""Parse a single zone header record and append to ``self.zones``.
|
|
535
|
+
"""Parse a single zone header record and append to ``self.zones``.
|
|
536
|
+
|
|
537
|
+
Raises:
|
|
538
|
+
PltReadError: If the zone is a poly zone in a v107 file or a v111 POINT
|
|
539
|
+
zone.
|
|
540
|
+
"""
|
|
478
541
|
byte_order = self.byte_order
|
|
479
542
|
num_vars = len(self.var_names)
|
|
480
543
|
|
|
@@ -497,6 +560,16 @@ class _PltParser:
|
|
|
497
560
|
|
|
498
561
|
# ZoneType
|
|
499
562
|
meta.zone_type = ZoneType(_read_int32(fp, byte_order))
|
|
563
|
+
if self._file_version == "v107" and meta.zone_type in _POLY_TYPES:
|
|
564
|
+
raise PltReadError("Poly zones are not supported in v107 files.")
|
|
565
|
+
|
|
566
|
+
# Manual tests with v111 showed one extra INT32 value of 0 here. Its unknown what
|
|
567
|
+
# the purpose is, but possible that data formats different that what was
|
|
568
|
+
# manually tested could cause an unreported error here.
|
|
569
|
+
if self._file_version == "v111" and _read_int32(fp, byte_order) != 0:
|
|
570
|
+
raise PltReadError(
|
|
571
|
+
"v111 zone with a nonzero data-packing field (POINT) is not supported."
|
|
572
|
+
)
|
|
500
573
|
|
|
501
574
|
# Variable locations
|
|
502
575
|
# PLT spec: 0 = Node, 1 = Cell Centered — opposite of the input ValueLocation
|
|
@@ -531,12 +604,6 @@ class _PltParser:
|
|
|
531
604
|
if zt in fe_types and self._file_version != "v107":
|
|
532
605
|
_read_int32(fp, byte_order)
|
|
533
606
|
|
|
534
|
-
# Manual tests with v111 showed one extra INT32 value of 0 here. Its unknown what
|
|
535
|
-
# the purpose is, but possible that data formats different that what was
|
|
536
|
-
# manually tested could cause an unreported error here.
|
|
537
|
-
if self._file_version == "v111":
|
|
538
|
-
_read_int32(fp, byte_order)
|
|
539
|
-
|
|
540
607
|
# Dimensions / element counts
|
|
541
608
|
if meta.zone_type == ZoneType.ORDERED:
|
|
542
609
|
meta.i_max = _read_int32(fp, byte_order)
|
|
@@ -546,13 +613,16 @@ class _PltParser:
|
|
|
546
613
|
meta.num_nodes = _read_int32(fp, byte_order)
|
|
547
614
|
|
|
548
615
|
if meta.zone_type in (ZoneType.FEPOLYGON, ZoneType.FEPOLYHEDRON):
|
|
549
|
-
if v191:
|
|
616
|
+
if v191: # pragma: no cover
|
|
617
|
+
# v191 stores only the two counts, as INT64. It has no boundary
|
|
618
|
+
# counts in the zone header, so no boundary sections are read.
|
|
550
619
|
meta.num_faces = _read_int64(fp, byte_order)
|
|
551
620
|
meta.total_face_nodes = _read_int64(fp, byte_order)
|
|
552
621
|
else:
|
|
553
622
|
meta.num_faces = _read_int32(fp, byte_order)
|
|
554
623
|
meta.total_face_nodes = _read_int32(fp, byte_order)
|
|
555
|
-
meta.
|
|
624
|
+
meta.boundary_table_entries = _read_int32(fp, byte_order)
|
|
625
|
+
meta.num_boundary_faces = max(meta.boundary_table_entries - 1, 0)
|
|
556
626
|
meta.num_boundary_connections = _read_int32(fp, byte_order)
|
|
557
627
|
|
|
558
628
|
meta.num_elements = _read_int32(fp, byte_order)
|
|
@@ -653,6 +723,9 @@ class _PltParser:
|
|
|
653
723
|
The EOHMARKER has already been consumed by :meth:`_parse_header`. We iterate
|
|
654
724
|
over zones in declaration order, matching each data block to the corresponding
|
|
655
725
|
:class:`_ZoneMeta` in ``self.zones``.
|
|
726
|
+
|
|
727
|
+
Raises:
|
|
728
|
+
PltReadError: If a zone marker is not valid.
|
|
656
729
|
"""
|
|
657
730
|
if self._file_version == "v75":
|
|
658
731
|
from ._plt_legacy import parse_v75_data_section
|
|
@@ -790,9 +863,8 @@ class _PltParser:
|
|
|
790
863
|
self._record_face_connections(fp, meta)
|
|
791
864
|
return
|
|
792
865
|
|
|
793
|
-
if zt in
|
|
794
|
-
|
|
795
|
-
self._skip_poly_face_map(fp, meta)
|
|
866
|
+
if zt in _POLY_TYPES:
|
|
867
|
+
self._record_poly_face_map(fp, meta)
|
|
796
868
|
return
|
|
797
869
|
|
|
798
870
|
# Simple FE zones
|
|
@@ -913,41 +985,43 @@ class _PltParser:
|
|
|
913
985
|
meta.num_face_connections = int(elem_idx.size)
|
|
914
986
|
meta.face_connections_eager = triples
|
|
915
987
|
|
|
916
|
-
def
|
|
917
|
-
"""
|
|
918
|
-
zt = meta.zone_type
|
|
988
|
+
def _record_poly_face_map(self, fp: io.BufferedIOBase, meta: _ZoneMeta) -> None:
|
|
989
|
+
"""Record the offsets of the face-map blocks of a poly zone and skip them.
|
|
919
990
|
|
|
991
|
+
Layout (all INT32 unless noted): polyhedra start with the face node offsets
|
|
992
|
+
(``nf + 1``, or per-face counts in v191), then face nodes, left elements, and
|
|
993
|
+
right elements. Polygons omit the first block, every face has 2 nodes. When
|
|
994
|
+
boundary faces exist, the boundary connection offsets (one more entry than the
|
|
995
|
+
stored table size), elements, and zones follow. Zones are INT16 in v111.
|
|
996
|
+
"""
|
|
920
997
|
if meta.connectivity_shared_zone >= 0:
|
|
921
998
|
return
|
|
922
999
|
|
|
923
|
-
v191 = meta.is_v191
|
|
924
1000
|
nf = meta.num_faces
|
|
925
|
-
fn = meta.total_face_nodes
|
|
926
|
-
nbf = meta.num_boundary_faces
|
|
927
1001
|
nbc = meta.num_boundary_connections
|
|
1002
|
+
sections = meta.poly_sections
|
|
928
1003
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
fp.seek(nf * 4, os.SEEK_CUR)
|
|
933
|
-
else:
|
|
934
|
-
# Face node offsets (INT32 * (nf + 1))
|
|
935
|
-
fp.seek((nf + 1) * 4, os.SEEK_CUR)
|
|
936
|
-
|
|
937
|
-
# Face nodes (INT32 * fn)
|
|
938
|
-
fp.seek(fn * 4, os.SEEK_CUR)
|
|
939
|
-
# Left elements (INT32 * nf)
|
|
940
|
-
fp.seek(nf * 4, os.SEEK_CUR)
|
|
941
|
-
# Right elements (INT32 * nf)
|
|
942
|
-
fp.seek(nf * 4, os.SEEK_CUR)
|
|
1004
|
+
def take(key: str, count: int, itemsize: int = 4) -> None:
|
|
1005
|
+
sections[key] = (fp.tell(), count, itemsize)
|
|
1006
|
+
fp.seek(count * itemsize, os.SEEK_CUR)
|
|
943
1007
|
|
|
944
|
-
if
|
|
945
|
-
#
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1008
|
+
if meta.zone_type == ZoneType.FEPOLYHEDRON:
|
|
1009
|
+
if meta.is_v191: # pragma: no cover
|
|
1010
|
+
take("face_node_counts", nf)
|
|
1011
|
+
else:
|
|
1012
|
+
take("face_node_offsets", nf + 1)
|
|
1013
|
+
take("face_nodes", meta.total_face_nodes)
|
|
1014
|
+
take("face_left_elements", nf)
|
|
1015
|
+
take("face_right_elements", nf)
|
|
1016
|
+
|
|
1017
|
+
if meta.boundary_table_entries > 0:
|
|
1018
|
+
take("boundary_offsets", meta.boundary_table_entries + 1)
|
|
1019
|
+
take("boundary_connection_elements", nbc)
|
|
1020
|
+
take(
|
|
1021
|
+
"boundary_connection_zones",
|
|
1022
|
+
nbc,
|
|
1023
|
+
2 if self._file_version == "v111" else 4,
|
|
1024
|
+
)
|
|
951
1025
|
|
|
952
1026
|
|
|
953
1027
|
# ======================================================================================
|
|
@@ -1080,7 +1154,11 @@ class TecplotPltVariableReader(TecplotVariableReader):
|
|
|
1080
1154
|
return self._meta.value_locations[self.var_index]
|
|
1081
1155
|
|
|
1082
1156
|
def is_passive(self) -> bool:
|
|
1083
|
-
"""True if this variable is passive in this zone.
|
|
1157
|
+
"""True if this variable is passive in this zone.
|
|
1158
|
+
|
|
1159
|
+
Returns:
|
|
1160
|
+
bool: ``True`` for a passive variable.
|
|
1161
|
+
"""
|
|
1084
1162
|
return self._meta.is_passive[self.var_index]
|
|
1085
1163
|
|
|
1086
1164
|
@property
|
|
@@ -1218,6 +1296,9 @@ class TecplotPltVariableReader(TecplotVariableReader):
|
|
|
1218
1296
|
rather than once per variable. A copy is always returned, never the cached
|
|
1219
1297
|
array's own view, so a caller mutating the result cannot corrupt the shared
|
|
1220
1298
|
cache or a later re-read of the same variable.
|
|
1299
|
+
|
|
1300
|
+
Returns:
|
|
1301
|
+
NDArray: Copy of the variable values for the requested rows.
|
|
1221
1302
|
"""
|
|
1222
1303
|
field_name = meta.point_field_by_var[self.var_index]
|
|
1223
1304
|
|
|
@@ -1253,7 +1334,11 @@ def _load_plt_variables(
|
|
|
1253
1334
|
byte_order: str,
|
|
1254
1335
|
all_metas: list[_ZoneMeta] | None,
|
|
1255
1336
|
) -> list[TecplotVariableReader]:
|
|
1256
|
-
"""Build this zone's variable readers. Shared by both PLT zone classes.
|
|
1337
|
+
"""Build this zone's variable readers. Shared by both PLT zone classes.
|
|
1338
|
+
|
|
1339
|
+
Returns:
|
|
1340
|
+
list: One reader class per variable of the zone.
|
|
1341
|
+
"""
|
|
1257
1342
|
return [
|
|
1258
1343
|
TecplotPltVariableReader(
|
|
1259
1344
|
file_path=file_path,
|
|
@@ -1268,6 +1353,30 @@ def _load_plt_variables(
|
|
|
1268
1353
|
]
|
|
1269
1354
|
|
|
1270
1355
|
|
|
1356
|
+
def _resolve_connectivity_meta(
|
|
1357
|
+
meta: _ZoneMeta, all_metas: list[_ZoneMeta] | None
|
|
1358
|
+
) -> _ZoneMeta | None:
|
|
1359
|
+
"""Return the :class:`_ZoneMeta` that contains the *meta* connectivity.
|
|
1360
|
+
|
|
1361
|
+
For a zone with its own connectivity this is *meta* itself. For a zone that shares
|
|
1362
|
+
connectivity, the chain of ``connectivity_shared_zone`` references is followed to
|
|
1363
|
+
the owning zone (with a cycle/range guard against malformed files). Returns None
|
|
1364
|
+
when the share cannot be resolved, e.g. when *all_metas* was not supplied.
|
|
1365
|
+
"""
|
|
1366
|
+
if meta.connectivity_shared_zone < 0:
|
|
1367
|
+
return meta
|
|
1368
|
+
if all_metas is None:
|
|
1369
|
+
return None
|
|
1370
|
+
seen: set[int] = set()
|
|
1371
|
+
while meta.connectivity_shared_zone >= 0:
|
|
1372
|
+
src = meta.connectivity_shared_zone # zero-based file value
|
|
1373
|
+
if src in seen or src >= len(all_metas):
|
|
1374
|
+
return None # cycle or out-of-range: malformed file
|
|
1375
|
+
seen.add(src)
|
|
1376
|
+
meta = all_metas[src]
|
|
1377
|
+
return meta
|
|
1378
|
+
|
|
1379
|
+
|
|
1271
1380
|
class TecplotPltOrderedZoneReader(TecplotOrderedZoneReader):
|
|
1272
1381
|
"""Ordered (IJK) zone reader for PLT files.
|
|
1273
1382
|
|
|
@@ -1279,14 +1388,14 @@ class TecplotPltOrderedZoneReader(TecplotOrderedZoneReader):
|
|
|
1279
1388
|
__slots__ = (
|
|
1280
1389
|
"_file_path",
|
|
1281
1390
|
"_meta",
|
|
1282
|
-
"
|
|
1391
|
+
"_num_vars",
|
|
1283
1392
|
"_var_names",
|
|
1284
1393
|
"_byte_order",
|
|
1285
1394
|
"_all_metas",
|
|
1286
1395
|
)
|
|
1287
1396
|
_file_path: str | os.PathLike
|
|
1288
1397
|
_meta: _ZoneMeta
|
|
1289
|
-
|
|
1398
|
+
_num_vars: int
|
|
1290
1399
|
_var_names: list[str]
|
|
1291
1400
|
_byte_order: str
|
|
1292
1401
|
_all_metas: list[_ZoneMeta] | None
|
|
@@ -1315,7 +1424,7 @@ class TecplotPltOrderedZoneReader(TecplotOrderedZoneReader):
|
|
|
1315
1424
|
)
|
|
1316
1425
|
object.__setattr__(self, "_file_path", file_path)
|
|
1317
1426
|
object.__setattr__(self, "_meta", meta)
|
|
1318
|
-
object.__setattr__(self, "
|
|
1427
|
+
object.__setattr__(self, "_num_vars", num_vars)
|
|
1319
1428
|
object.__setattr__(self, "_var_names", var_names)
|
|
1320
1429
|
object.__setattr__(self, "_byte_order", byte_order)
|
|
1321
1430
|
object.__setattr__(self, "_all_metas", all_metas)
|
|
@@ -1325,7 +1434,7 @@ class TecplotPltOrderedZoneReader(TecplotOrderedZoneReader):
|
|
|
1325
1434
|
self._file_path,
|
|
1326
1435
|
self._meta,
|
|
1327
1436
|
self.zone_index,
|
|
1328
|
-
self.
|
|
1437
|
+
self._num_vars,
|
|
1329
1438
|
self._var_names,
|
|
1330
1439
|
self._byte_order,
|
|
1331
1440
|
self._all_metas,
|
|
@@ -1346,14 +1455,14 @@ class TecplotPltFEZoneReader(TecplotFEZoneReader):
|
|
|
1346
1455
|
__slots__ = (
|
|
1347
1456
|
"_file_path",
|
|
1348
1457
|
"_meta",
|
|
1349
|
-
"
|
|
1458
|
+
"_num_vars",
|
|
1350
1459
|
"_var_names",
|
|
1351
1460
|
"_byte_order",
|
|
1352
1461
|
"_all_metas",
|
|
1353
1462
|
)
|
|
1354
1463
|
_file_path: str | os.PathLike
|
|
1355
1464
|
_meta: _ZoneMeta
|
|
1356
|
-
|
|
1465
|
+
_num_vars: int
|
|
1357
1466
|
_var_names: list[str]
|
|
1358
1467
|
_byte_order: str
|
|
1359
1468
|
_all_metas: list[_ZoneMeta] | None
|
|
@@ -1387,7 +1496,7 @@ class TecplotPltFEZoneReader(TecplotFEZoneReader):
|
|
|
1387
1496
|
)
|
|
1388
1497
|
object.__setattr__(self, "_file_path", file_path)
|
|
1389
1498
|
object.__setattr__(self, "_meta", meta)
|
|
1390
|
-
object.__setattr__(self, "
|
|
1499
|
+
object.__setattr__(self, "_num_vars", num_vars)
|
|
1391
1500
|
object.__setattr__(self, "_var_names", var_names)
|
|
1392
1501
|
object.__setattr__(self, "_byte_order", byte_order)
|
|
1393
1502
|
object.__setattr__(self, "_all_metas", all_metas)
|
|
@@ -1397,44 +1506,23 @@ class TecplotPltFEZoneReader(TecplotFEZoneReader):
|
|
|
1397
1506
|
self._file_path,
|
|
1398
1507
|
self._meta,
|
|
1399
1508
|
self.zone_index,
|
|
1400
|
-
self.
|
|
1509
|
+
self._num_vars,
|
|
1401
1510
|
self._var_names,
|
|
1402
1511
|
self._byte_order,
|
|
1403
1512
|
self._all_metas,
|
|
1404
1513
|
)
|
|
1405
1514
|
|
|
1406
1515
|
def _resolve_connectivity_meta(self) -> _ZoneMeta | None:
|
|
1407
|
-
"""Return the :class:`_ZoneMeta` that owns this zone's connectivity.
|
|
1408
|
-
|
|
1409
|
-
For a zone with its own connectivity this is simply ``self._meta``. For a zone
|
|
1410
|
-
that shares connectivity, the chain of ``connectivity_shared_zone`` references
|
|
1411
|
-
is followed to the owning zone (with a cycle/range guard against malformed
|
|
1412
|
-
files). Returns None when the share cannot be resolved, e.g. when ``all_metas``
|
|
1413
|
-
was not supplied at construction.
|
|
1414
|
-
"""
|
|
1415
|
-
meta = self._meta
|
|
1416
|
-
if meta.connectivity_shared_zone < 0:
|
|
1417
|
-
return meta
|
|
1418
|
-
if self._all_metas is None:
|
|
1419
|
-
return None
|
|
1420
|
-
seen: set[int] = set()
|
|
1421
|
-
while meta.connectivity_shared_zone >= 0:
|
|
1422
|
-
src = meta.connectivity_shared_zone # zero-based file value
|
|
1423
|
-
if src in seen or src >= len(self._all_metas):
|
|
1424
|
-
return None # cycle or out-of-range: malformed file
|
|
1425
|
-
seen.add(src)
|
|
1426
|
-
meta = self._all_metas[src]
|
|
1427
|
-
return meta
|
|
1516
|
+
"""Return the :class:`_ZoneMeta` that owns this zone's connectivity."""
|
|
1517
|
+
return _resolve_connectivity_meta(self._meta, self._all_metas)
|
|
1428
1518
|
|
|
1429
1519
|
def _load_node_map(self) -> npt.NDArray[np.int64] | None:
|
|
1430
1520
|
"""Read this zone's node connectivity.
|
|
1431
1521
|
|
|
1432
|
-
Returns
|
|
1433
|
-
|
|
1522
|
+
Returns:
|
|
1523
|
+
NDArray: Zero-based node map, or ``None`` if the zone has no stored
|
|
1524
|
+
connectivity.
|
|
1434
1525
|
"""
|
|
1435
|
-
if self.zone_type in (ZoneType.FEPOLYGON, ZoneType.FEPOLYHEDRON):
|
|
1436
|
-
return None
|
|
1437
|
-
|
|
1438
1526
|
meta = self._resolve_connectivity_meta()
|
|
1439
1527
|
if meta is None or meta.connectivity_offset is None:
|
|
1440
1528
|
return None
|
|
@@ -1494,6 +1582,106 @@ class TecplotPltFEZoneReader(TecplotFEZoneReader):
|
|
|
1494
1582
|
return TecplotPltAuxDataReader(self._meta.auxdata)
|
|
1495
1583
|
|
|
1496
1584
|
|
|
1585
|
+
class TecplotPltPolyZoneReader(TecplotPolyZoneReader):
|
|
1586
|
+
"""Poly (FEPOLYGON / FEPOLYHEDRON) zone reader for PLT files.
|
|
1587
|
+
|
|
1588
|
+
Metadata comes from the pre-parsed :class:`_ZoneMeta`. Each face-map array is read
|
|
1589
|
+
from disk on first access.
|
|
1590
|
+
"""
|
|
1591
|
+
|
|
1592
|
+
__slots__ = (
|
|
1593
|
+
"_file_path",
|
|
1594
|
+
"_meta",
|
|
1595
|
+
"_num_vars",
|
|
1596
|
+
"_var_names",
|
|
1597
|
+
"_byte_order",
|
|
1598
|
+
"_all_metas",
|
|
1599
|
+
)
|
|
1600
|
+
_file_path: str | os.PathLike
|
|
1601
|
+
_meta: _ZoneMeta
|
|
1602
|
+
_num_vars: int
|
|
1603
|
+
_var_names: list[str]
|
|
1604
|
+
_byte_order: str
|
|
1605
|
+
_all_metas: list[_ZoneMeta] | None
|
|
1606
|
+
|
|
1607
|
+
def __init__(
|
|
1608
|
+
self,
|
|
1609
|
+
file_path: str | os.PathLike,
|
|
1610
|
+
meta: _ZoneMeta,
|
|
1611
|
+
zone_index: int,
|
|
1612
|
+
num_vars: int,
|
|
1613
|
+
var_names: list[str],
|
|
1614
|
+
byte_order: str,
|
|
1615
|
+
all_metas: list[_ZoneMeta] | None = None,
|
|
1616
|
+
) -> None:
|
|
1617
|
+
super().__init__(
|
|
1618
|
+
zone_index=zone_index,
|
|
1619
|
+
title=meta.title,
|
|
1620
|
+
zone_type=meta.zone_type,
|
|
1621
|
+
solution_time=meta.solution_time,
|
|
1622
|
+
strand_id=max(meta.strand_id + 1, 0),
|
|
1623
|
+
datapacking=DataPacking.BLOCK,
|
|
1624
|
+
num_nodes=meta.num_nodes,
|
|
1625
|
+
num_elements=meta.num_elements,
|
|
1626
|
+
num_faces=meta.num_faces,
|
|
1627
|
+
num_boundary_faces=meta.num_boundary_faces,
|
|
1628
|
+
num_boundary_connections=meta.num_boundary_connections,
|
|
1629
|
+
shared_connectivity=(
|
|
1630
|
+
meta.connectivity_shared_zone
|
|
1631
|
+
if meta.connectivity_shared_zone >= 0
|
|
1632
|
+
else None
|
|
1633
|
+
),
|
|
1634
|
+
)
|
|
1635
|
+
object.__setattr__(self, "_file_path", file_path)
|
|
1636
|
+
object.__setattr__(self, "_meta", meta)
|
|
1637
|
+
object.__setattr__(self, "_num_vars", num_vars)
|
|
1638
|
+
object.__setattr__(self, "_var_names", var_names)
|
|
1639
|
+
object.__setattr__(self, "_byte_order", byte_order)
|
|
1640
|
+
object.__setattr__(self, "_all_metas", all_metas)
|
|
1641
|
+
|
|
1642
|
+
def _load_variables(self) -> list[TecplotVariableReader]:
|
|
1643
|
+
return _load_plt_variables(
|
|
1644
|
+
self._file_path,
|
|
1645
|
+
self._meta,
|
|
1646
|
+
self.zone_index,
|
|
1647
|
+
self._num_vars,
|
|
1648
|
+
self._var_names,
|
|
1649
|
+
self._byte_order,
|
|
1650
|
+
self._all_metas,
|
|
1651
|
+
)
|
|
1652
|
+
|
|
1653
|
+
def _read_section(self, meta: _ZoneMeta, key: str) -> npt.NDArray[np.int64]:
|
|
1654
|
+
"""Read one recorded face-map block as int64.
|
|
1655
|
+
|
|
1656
|
+
Returns:
|
|
1657
|
+
NDArray: Flat array of node indices for section.
|
|
1658
|
+
"""
|
|
1659
|
+
offset, count, itemsize = meta.poly_sections[key]
|
|
1660
|
+
dt = np.dtype(f"{self._byte_order}i{itemsize}")
|
|
1661
|
+
with open(self._file_path, "rb") as fp:
|
|
1662
|
+
fp.seek(offset)
|
|
1663
|
+
return np.fromfile(fp, dtype=dt, count=count).astype(np.int64)
|
|
1664
|
+
|
|
1665
|
+
def _load_array(self, key: PolyArrayKey) -> npt.NDArray[np.int64]:
|
|
1666
|
+
meta = _resolve_connectivity_meta(self._meta, self._all_metas)
|
|
1667
|
+
if meta is None or not meta.poly_sections:
|
|
1668
|
+
raise PltReadError(
|
|
1669
|
+
f"Zone {self.zone_index}: shared connectivity could not be resolved."
|
|
1670
|
+
)
|
|
1671
|
+
if key == "face_node_counts":
|
|
1672
|
+
if "face_node_counts" in meta.poly_sections: # pragma: no cover
|
|
1673
|
+
return self._read_section(meta, "face_node_counts")
|
|
1674
|
+
return np.diff(self._read_section(meta, "face_node_offsets"))
|
|
1675
|
+
if key == "boundary_connection_counts":
|
|
1676
|
+
return np.diff(self._read_section(meta, "boundary_offsets"))[1:]
|
|
1677
|
+
# The remaining arrays are stored 0-based, with -1 for "none" and -(b + 2)
|
|
1678
|
+
# for boundary face b, matching the public convention directly.
|
|
1679
|
+
return self._read_section(meta, key)
|
|
1680
|
+
|
|
1681
|
+
def _load_auxdata(self) -> TecplotAuxDataReader:
|
|
1682
|
+
return TecplotPltAuxDataReader(self._meta.auxdata)
|
|
1683
|
+
|
|
1684
|
+
|
|
1497
1685
|
def _build_plt_zone(
|
|
1498
1686
|
file_path: str | os.PathLike,
|
|
1499
1687
|
meta: _ZoneMeta,
|
|
@@ -1503,11 +1691,19 @@ def _build_plt_zone(
|
|
|
1503
1691
|
byte_order: str,
|
|
1504
1692
|
all_metas: list[_ZoneMeta] | None,
|
|
1505
1693
|
) -> TecplotZoneReader:
|
|
1506
|
-
"""Construct the right concrete zone reader for one parsed zone.
|
|
1694
|
+
"""Construct the right concrete zone reader for one parsed zone.
|
|
1695
|
+
|
|
1696
|
+
Returns:
|
|
1697
|
+
TecplotZoneReader: The zone reader class that matches the zone type.
|
|
1698
|
+
"""
|
|
1507
1699
|
if meta.zone_type == ZoneType.ORDERED:
|
|
1508
1700
|
return TecplotPltOrderedZoneReader(
|
|
1509
1701
|
file_path, meta, zone_index, num_vars, var_names, byte_order, all_metas
|
|
1510
1702
|
)
|
|
1703
|
+
if meta.zone_type in _POLY_TYPES:
|
|
1704
|
+
return TecplotPltPolyZoneReader(
|
|
1705
|
+
file_path, meta, zone_index, num_vars, var_names, byte_order, all_metas
|
|
1706
|
+
)
|
|
1511
1707
|
return TecplotPltFEZoneReader(
|
|
1512
1708
|
file_path, meta, zone_index, num_vars, var_names, byte_order, all_metas
|
|
1513
1709
|
)
|