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/_reader.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Every format's reader (SZL, PLT, DAT) exposes the same interface: :class:`TecplotReader`
|
|
4
4
|
(the open file/dataset), :class:`TecplotZoneReader` (one zone, split into
|
|
5
|
-
:class:`TecplotOrderedZoneReader
|
|
5
|
+
:class:`TecplotOrderedZoneReader`, :class:`TecplotFEZoneReader`,
|
|
6
|
+
:class:`TecplotFEMixedZoneReader`, and :class:`TecplotPolyZoneReader` since the
|
|
6
7
|
topologies don't share properties like dimensions or connectivity),
|
|
7
8
|
:class:`TecplotVariableReader` (one variable within a zone, not split by value location
|
|
8
9
|
or zone topology, neither changes which properties exist, only the shape
|
|
@@ -40,9 +41,10 @@ Design notes:
|
|
|
40
41
|
|
|
41
42
|
from __future__ import annotations
|
|
42
43
|
|
|
44
|
+
import hashlib
|
|
43
45
|
from abc import ABC, abstractmethod
|
|
44
46
|
from collections.abc import ItemsView, Iterator, KeysView, Mapping, ValuesView
|
|
45
|
-
from typing import Any, overload
|
|
47
|
+
from typing import Any, Final, Literal, TypeAlias, overload
|
|
46
48
|
|
|
47
49
|
import numpy as np
|
|
48
50
|
import numpy.typing as npt
|
|
@@ -51,11 +53,14 @@ from ._constants import (
|
|
|
51
53
|
DataPacking,
|
|
52
54
|
DataType,
|
|
53
55
|
FaceNeighborMode,
|
|
56
|
+
FeCellShape,
|
|
54
57
|
FileType,
|
|
55
58
|
ValueLocation,
|
|
56
59
|
ZoneType,
|
|
57
60
|
)
|
|
58
61
|
from ._containers import VariableList, ZoneList, select_variable_arrays
|
|
62
|
+
from ._elements import faces_by_element, nodes_by_element
|
|
63
|
+
from ._utils import public_dir
|
|
59
64
|
|
|
60
65
|
# Nodes per element for the standard finite-element zone types. ORDERED zones are
|
|
61
66
|
# computed from active dimensions instead, see TecplotZoneReader.nodes_per_cell.
|
|
@@ -164,12 +169,20 @@ def convert_face_connections_to_zero_based(
|
|
|
164
169
|
|
|
165
170
|
|
|
166
171
|
def _immutable_setattr(instance: object, name: str, value: object) -> None:
|
|
167
|
-
"""Raise, used as every reader class's ``__setattr__``.
|
|
172
|
+
"""Raise, used as every reader class's ``__setattr__``.
|
|
173
|
+
|
|
174
|
+
Raises:
|
|
175
|
+
AttributeError: Always raised when called to prevent user-added or modified attributes.
|
|
176
|
+
"""
|
|
168
177
|
raise AttributeError(f"{type(instance).__name__} instances are immutable")
|
|
169
178
|
|
|
170
179
|
|
|
171
180
|
def _immutable_delattr(instance: object, name: str) -> None:
|
|
172
|
-
"""Raise, used as every reader class's ``__delattr__``.
|
|
181
|
+
"""Raise, used as every reader class's ``__delattr__``.
|
|
182
|
+
|
|
183
|
+
Raises:
|
|
184
|
+
AttributeError: Always raised when called to prevent user-removed attributes.
|
|
185
|
+
"""
|
|
173
186
|
raise AttributeError(f"{type(instance).__name__} instances are immutable")
|
|
174
187
|
|
|
175
188
|
|
|
@@ -373,6 +386,9 @@ class TecplotVariableReader(ABC):
|
|
|
373
386
|
|
|
374
387
|
SZL overrides this with the dataset-level enabled flag it actually
|
|
375
388
|
stores; PLT and DAT have no such flag and use this default.
|
|
389
|
+
|
|
390
|
+
Returns:
|
|
391
|
+
bool: ``True`` for an active variable.
|
|
376
392
|
"""
|
|
377
393
|
return not self.is_passive()
|
|
378
394
|
|
|
@@ -458,6 +474,14 @@ class TecplotZoneReader(ABC):
|
|
|
458
474
|
__setattr__ = _immutable_setattr
|
|
459
475
|
__delattr__ = _immutable_delattr
|
|
460
476
|
|
|
477
|
+
def __dir__(self) -> list[str]: # pragma: no cover
|
|
478
|
+
"""List only the public attributes and methods.
|
|
479
|
+
|
|
480
|
+
Returns:
|
|
481
|
+
list[str]: Names of the public attributes and methods, and the dunder names.
|
|
482
|
+
"""
|
|
483
|
+
return public_dir(self)
|
|
484
|
+
|
|
461
485
|
def __repr__(self) -> str: # pragma: no cover
|
|
462
486
|
title = self.title
|
|
463
487
|
if len(title) > 30:
|
|
@@ -506,6 +530,10 @@ class TecplotZoneReader(ABC):
|
|
|
506
530
|
"""True unless the zone reports itself disabled.
|
|
507
531
|
|
|
508
532
|
Only SZL can report False here; PLT and DAT have no such flag.
|
|
533
|
+
|
|
534
|
+
Returns:
|
|
535
|
+
bool: ``True`` whenever called in the base class. SZL may report ``False``,
|
|
536
|
+
but all other file formats will report ``True``.
|
|
509
537
|
"""
|
|
510
538
|
return True
|
|
511
539
|
|
|
@@ -664,17 +692,8 @@ class TecplotOrderedZoneReader(TecplotZoneReader):
|
|
|
664
692
|
class TecplotFEZoneReader(TecplotZoneReader):
|
|
665
693
|
"""Read-only handle to one finite-element zone.
|
|
666
694
|
|
|
667
|
-
Covers
|
|
668
|
-
|
|
669
|
-
meaningful for all of them today. :attr:`nodes_per_cell` only has a fixed answer for
|
|
670
|
-
the classic types (FELINESEG through FEBRICK) and raises for the rest, and
|
|
671
|
-
:attr:`node_map` may legitimately be None for a zone type whose connectivity a
|
|
672
|
-
format can't yet resolve (e.g. PLT's FEPOLYGON/FEPOLYHEDRON, face-map reading isn't
|
|
673
|
-
implemented there), the same contract this class already had before the Ordered/FE
|
|
674
|
-
split. A dedicated poly reader with real face-map support (a `facemap` property,
|
|
675
|
-
variable-length per-face connectivity) is a reasonable future split once some format
|
|
676
|
-
actually implements it, informed by a real implementation rather than a guess, not
|
|
677
|
-
before.
|
|
695
|
+
Covers the classic element zone types (FELINESEG through FEBRICK). Face-based
|
|
696
|
+
FEPOLYGON and FEPOLYHEDRON zones are read by :class:`TecplotPolyZoneReader`.
|
|
678
697
|
|
|
679
698
|
Args:
|
|
680
699
|
zone_index: 0-based zone index within the dataset.
|
|
@@ -779,10 +798,8 @@ class TecplotFEZoneReader(TecplotZoneReader):
|
|
|
779
798
|
def node_map(self) -> npt.NDArray[np.int64] | None:
|
|
780
799
|
"""Node connectivity array ``(num_elements, nodes_per_cell)``.
|
|
781
800
|
|
|
782
|
-
None only if a format cannot
|
|
783
|
-
|
|
784
|
-
such zones would need a future, dedicated poly reader, not this class, once
|
|
785
|
-
that's built).
|
|
801
|
+
None only if a format cannot resolve connectivity for this zone, e.g. when a
|
|
802
|
+
shared-connectivity source zone is missing.
|
|
786
803
|
"""
|
|
787
804
|
if not self._node_map_loaded:
|
|
788
805
|
node_map = self._load_node_map()
|
|
@@ -861,6 +878,10 @@ class TecplotFEZoneReader(TecplotZoneReader):
|
|
|
861
878
|
connections themselves. Default: None (not implemented for this
|
|
862
879
|
format). A format that overrides this to return real data must
|
|
863
880
|
also override :meth:`_load_face_connections`.
|
|
881
|
+
|
|
882
|
+
Returns:
|
|
883
|
+
tuple: Tuple of the neighbor mode, number of connections and completeness
|
|
884
|
+
flag, or ``None`` if the format does not store them.
|
|
864
885
|
"""
|
|
865
886
|
return None
|
|
866
887
|
|
|
@@ -940,6 +961,426 @@ class TecplotFEZoneReader(TecplotZoneReader):
|
|
|
940
961
|
)
|
|
941
962
|
|
|
942
963
|
|
|
964
|
+
# ======================================================================================
|
|
965
|
+
# TecplotFEMixedZoneReader
|
|
966
|
+
# ======================================================================================
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
class TecplotFEMixedZoneReader(TecplotZoneReader):
|
|
970
|
+
"""Read-only handle to one FEMIXED (mixed finite-element) zone.
|
|
971
|
+
|
|
972
|
+
A FEMIXED zone holds 1 to 16 sections. Every cell in a section has the same shape,
|
|
973
|
+
and all sections share one spatial dimension (all line, all surface or all volume
|
|
974
|
+
cells). Cell numbering runs through the sections in order, so cell-centered
|
|
975
|
+
variables hold ``num_elements`` values, the cells of section 0 first. All indices
|
|
976
|
+
are 0-based.
|
|
977
|
+
|
|
978
|
+
Args:
|
|
979
|
+
zone_index: 0-based zone index within the dataset.
|
|
980
|
+
title: Zone title.
|
|
981
|
+
solution_time: Solution time, 0.0 for static data.
|
|
982
|
+
strand_id: Strand ID, 0 for static data.
|
|
983
|
+
datapacking: On-disk value layout.
|
|
984
|
+
num_nodes: Number of nodes/points.
|
|
985
|
+
section_shapes: Cell shape of each section.
|
|
986
|
+
section_num_elements: Number of cells in each section.
|
|
987
|
+
shared_connectivity: 0-based source zone index if this zone's
|
|
988
|
+
connectivity is shared, else None.
|
|
989
|
+
"""
|
|
990
|
+
|
|
991
|
+
__slots__ = (
|
|
992
|
+
"_num_nodes",
|
|
993
|
+
"_section_shapes",
|
|
994
|
+
"_section_num_elements",
|
|
995
|
+
"_shared_connectivity",
|
|
996
|
+
"_node_maps_cache",
|
|
997
|
+
)
|
|
998
|
+
_num_nodes: int
|
|
999
|
+
_section_shapes: tuple[FeCellShape, ...]
|
|
1000
|
+
_section_num_elements: tuple[int, ...]
|
|
1001
|
+
_shared_connectivity: int | None
|
|
1002
|
+
_node_maps_cache: tuple[npt.NDArray[np.int64], ...] | None
|
|
1003
|
+
|
|
1004
|
+
def __init__(
|
|
1005
|
+
self,
|
|
1006
|
+
zone_index: int,
|
|
1007
|
+
title: str,
|
|
1008
|
+
solution_time: float,
|
|
1009
|
+
strand_id: int,
|
|
1010
|
+
datapacking: DataPacking,
|
|
1011
|
+
num_nodes: int,
|
|
1012
|
+
section_shapes: tuple[FeCellShape, ...],
|
|
1013
|
+
section_num_elements: tuple[int, ...],
|
|
1014
|
+
shared_connectivity: int | None,
|
|
1015
|
+
) -> None:
|
|
1016
|
+
super().__init__(
|
|
1017
|
+
zone_index=zone_index,
|
|
1018
|
+
title=title,
|
|
1019
|
+
zone_type=ZoneType.FEMIXED,
|
|
1020
|
+
solution_time=solution_time,
|
|
1021
|
+
strand_id=strand_id,
|
|
1022
|
+
datapacking=datapacking,
|
|
1023
|
+
)
|
|
1024
|
+
object.__setattr__(self, "_num_nodes", num_nodes)
|
|
1025
|
+
object.__setattr__(self, "_section_shapes", section_shapes)
|
|
1026
|
+
object.__setattr__(self, "_section_num_elements", section_num_elements)
|
|
1027
|
+
object.__setattr__(self, "_shared_connectivity", shared_connectivity)
|
|
1028
|
+
object.__setattr__(self, "_node_maps_cache", None)
|
|
1029
|
+
|
|
1030
|
+
def _repr_size(self) -> str:
|
|
1031
|
+
return (
|
|
1032
|
+
f"N={self._num_nodes}, E={self.num_elements}, S={len(self._section_shapes)}"
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
@property
|
|
1036
|
+
def num_nodes(self) -> int:
|
|
1037
|
+
"""Number of nodes/points."""
|
|
1038
|
+
return self._num_nodes
|
|
1039
|
+
|
|
1040
|
+
@property
|
|
1041
|
+
def num_elements(self) -> int:
|
|
1042
|
+
"""Total number of elements/cells over all sections."""
|
|
1043
|
+
return sum(self._section_num_elements)
|
|
1044
|
+
|
|
1045
|
+
@property
|
|
1046
|
+
def num_sections(self) -> int:
|
|
1047
|
+
"""Number of sections, 1 to 16."""
|
|
1048
|
+
return len(self._section_shapes)
|
|
1049
|
+
|
|
1050
|
+
@property
|
|
1051
|
+
def section_shapes(self) -> tuple[FeCellShape, ...]:
|
|
1052
|
+
"""Cell shape of each section."""
|
|
1053
|
+
return self._section_shapes
|
|
1054
|
+
|
|
1055
|
+
@property
|
|
1056
|
+
def section_num_elements(self) -> tuple[int, ...]:
|
|
1057
|
+
"""Number of cells in each section."""
|
|
1058
|
+
return self._section_num_elements
|
|
1059
|
+
|
|
1060
|
+
@property
|
|
1061
|
+
def shared_connectivity(self) -> int | None:
|
|
1062
|
+
"""0-based source zone index if connectivity is shared, else None."""
|
|
1063
|
+
return self._shared_connectivity
|
|
1064
|
+
|
|
1065
|
+
@property
|
|
1066
|
+
def node_maps(self) -> tuple[npt.NDArray[np.int64], ...]:
|
|
1067
|
+
"""Node connectivity of each section, ``(section_num_elements, nodes)`` arrays.
|
|
1068
|
+
|
|
1069
|
+
The arrays are views of one allocation, loaded on first access. Node indices are
|
|
1070
|
+
0-based. Passing :attr:`section_shapes` and :attr:`node_maps` to
|
|
1071
|
+
:meth:`~tecio.TecplotSzlWriter.write_femixed_zone` writes the zone back.
|
|
1072
|
+
"""
|
|
1073
|
+
node_maps = self._node_maps_cache
|
|
1074
|
+
if node_maps is None:
|
|
1075
|
+
node_maps = self._load_node_maps()
|
|
1076
|
+
object.__setattr__(self, "_node_maps_cache", node_maps)
|
|
1077
|
+
return node_maps
|
|
1078
|
+
|
|
1079
|
+
@abstractmethod
|
|
1080
|
+
def _load_node_maps(self) -> tuple[npt.NDArray[np.int64], ...]:
|
|
1081
|
+
"""Read this zone's per-section connectivity. Called at most once, lazily."""
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
# ======================================================================================
|
|
1085
|
+
# TecplotPolyZoneReader
|
|
1086
|
+
# ======================================================================================
|
|
1087
|
+
|
|
1088
|
+
PolyArrayKey: TypeAlias = Literal[
|
|
1089
|
+
"face_node_counts",
|
|
1090
|
+
"face_nodes",
|
|
1091
|
+
"face_left_elements",
|
|
1092
|
+
"face_right_elements",
|
|
1093
|
+
"boundary_connection_counts",
|
|
1094
|
+
"boundary_connection_elements",
|
|
1095
|
+
"boundary_connection_zones",
|
|
1096
|
+
]
|
|
1097
|
+
|
|
1098
|
+
# Reference value for "no element" in ``face_left_elements`` and
|
|
1099
|
+
# ``face_right_elements``. Values at or below ``BOUNDARY_REF_BASE`` reference boundary
|
|
1100
|
+
# face ``BOUNDARY_REF_BASE - value``.
|
|
1101
|
+
NO_ELEMENT: Final = -1
|
|
1102
|
+
BOUNDARY_REF_BASE: Final = -2
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
def counts_to_offsets(counts: npt.NDArray[np.int64]) -> npt.NDArray[np.int64]:
|
|
1106
|
+
"""Return the ``len(counts) + 1`` running offsets for per-item *counts*."""
|
|
1107
|
+
offsets = np.zeros(counts.size + 1, dtype=np.int64)
|
|
1108
|
+
np.cumsum(counts, out=offsets[1:])
|
|
1109
|
+
return offsets
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
class TecplotPolyZoneReader(TecplotZoneReader):
|
|
1113
|
+
"""Read-only handle to one FEPOLYGON or FEPOLYHEDRON (face-based) zone.
|
|
1114
|
+
|
|
1115
|
+
A poly zone stores faces instead of per-element node lists. Every face lists its
|
|
1116
|
+
nodes and the elements on its left and right. All indices are 0-based. The face
|
|
1117
|
+
arrays are flat and are returned as stored in the file, never split per element.
|
|
1118
|
+
|
|
1119
|
+
``face_left_elements`` and ``face_right_elements`` hold, for each face:
|
|
1120
|
+
|
|
1121
|
+
* ``>= 0``: the 0-based element index.
|
|
1122
|
+
* ``-1`` (:data:`NO_ELEMENT`): no element on that side (a domain boundary).
|
|
1123
|
+
* ``<= -2``: a boundary face, an entry in the boundary connection arrays, used
|
|
1124
|
+
for neighbors in other zones or faces with several neighbors. The boundary
|
|
1125
|
+
face index is ``-2 - value`` (:data:`BOUNDARY_REF_BASE`).
|
|
1126
|
+
|
|
1127
|
+
Boundary face ``b`` owns ``boundary_connection_counts[b]`` consecutive entries of
|
|
1128
|
+
``boundary_connection_elements`` and ``boundary_connection_zones``, which hold the
|
|
1129
|
+
0-based neighbor element and the 0-based zone containing it.
|
|
1130
|
+
|
|
1131
|
+
Face-neighbor connections (:class:`~tecio.FaceNeighborMode`) do not apply to poly
|
|
1132
|
+
zones, the left and right elements play that role.
|
|
1133
|
+
|
|
1134
|
+
For a FEPOLYGON zone each face is an edge with exactly 2 nodes. Its
|
|
1135
|
+
``face_node_counts`` is synthesized (all 2) and ``face_nodes`` has
|
|
1136
|
+
``2 * num_faces`` entries.
|
|
1137
|
+
|
|
1138
|
+
Args:
|
|
1139
|
+
zone_index: 0-based zone index within the dataset.
|
|
1140
|
+
title: Zone title.
|
|
1141
|
+
zone_type: FEPOLYGON or FEPOLYHEDRON.
|
|
1142
|
+
solution_time: Solution time, 0.0 for static data.
|
|
1143
|
+
strand_id: Strand ID, 0 for static data.
|
|
1144
|
+
datapacking: On-disk value layout.
|
|
1145
|
+
num_nodes: Number of nodes/points.
|
|
1146
|
+
num_elements: Number of elements/cells.
|
|
1147
|
+
num_faces: Number of faces.
|
|
1148
|
+
num_boundary_faces: Number of boundary faces.
|
|
1149
|
+
num_boundary_connections: Total number of boundary connections.
|
|
1150
|
+
shared_connectivity: 0-based source zone index if this zone's connectivity
|
|
1151
|
+
is shared, else None.
|
|
1152
|
+
"""
|
|
1153
|
+
|
|
1154
|
+
__slots__ = (
|
|
1155
|
+
"_num_nodes",
|
|
1156
|
+
"_num_elements",
|
|
1157
|
+
"_num_faces",
|
|
1158
|
+
"_num_boundary_faces",
|
|
1159
|
+
"_num_boundary_connections",
|
|
1160
|
+
"_shared_connectivity",
|
|
1161
|
+
"_array_cache",
|
|
1162
|
+
)
|
|
1163
|
+
_num_nodes: int
|
|
1164
|
+
_num_elements: int
|
|
1165
|
+
_num_faces: int
|
|
1166
|
+
_num_boundary_faces: int
|
|
1167
|
+
_num_boundary_connections: int
|
|
1168
|
+
_shared_connectivity: int | None
|
|
1169
|
+
_array_cache: dict[str, npt.NDArray[np.int64]]
|
|
1170
|
+
|
|
1171
|
+
def __init__(
|
|
1172
|
+
self,
|
|
1173
|
+
zone_index: int,
|
|
1174
|
+
title: str,
|
|
1175
|
+
zone_type: ZoneType,
|
|
1176
|
+
solution_time: float,
|
|
1177
|
+
strand_id: int,
|
|
1178
|
+
datapacking: DataPacking,
|
|
1179
|
+
num_nodes: int,
|
|
1180
|
+
num_elements: int,
|
|
1181
|
+
num_faces: int,
|
|
1182
|
+
num_boundary_faces: int,
|
|
1183
|
+
num_boundary_connections: int,
|
|
1184
|
+
shared_connectivity: int | None,
|
|
1185
|
+
) -> None:
|
|
1186
|
+
if zone_type not in (ZoneType.FEPOLYGON, ZoneType.FEPOLYHEDRON):
|
|
1187
|
+
raise ValueError(f"Not a poly zone type: {zone_type!r}")
|
|
1188
|
+
super().__init__(
|
|
1189
|
+
zone_index=zone_index,
|
|
1190
|
+
title=title,
|
|
1191
|
+
zone_type=zone_type,
|
|
1192
|
+
solution_time=solution_time,
|
|
1193
|
+
strand_id=strand_id,
|
|
1194
|
+
datapacking=datapacking,
|
|
1195
|
+
)
|
|
1196
|
+
object.__setattr__(self, "_num_nodes", num_nodes)
|
|
1197
|
+
object.__setattr__(self, "_num_elements", num_elements)
|
|
1198
|
+
object.__setattr__(self, "_num_faces", num_faces)
|
|
1199
|
+
object.__setattr__(self, "_num_boundary_faces", num_boundary_faces)
|
|
1200
|
+
object.__setattr__(self, "_num_boundary_connections", num_boundary_connections)
|
|
1201
|
+
object.__setattr__(self, "_shared_connectivity", shared_connectivity)
|
|
1202
|
+
object.__setattr__(self, "_array_cache", {})
|
|
1203
|
+
|
|
1204
|
+
def _repr_size(self) -> str:
|
|
1205
|
+
return f"N={self._num_nodes}, F={self._num_faces}, E={self._num_elements}"
|
|
1206
|
+
|
|
1207
|
+
@property
|
|
1208
|
+
def num_nodes(self) -> int:
|
|
1209
|
+
"""Number of nodes/points."""
|
|
1210
|
+
return self._num_nodes
|
|
1211
|
+
|
|
1212
|
+
@property
|
|
1213
|
+
def num_elements(self) -> int:
|
|
1214
|
+
"""Number of elements/cells."""
|
|
1215
|
+
return self._num_elements
|
|
1216
|
+
|
|
1217
|
+
@property
|
|
1218
|
+
def num_faces(self) -> int:
|
|
1219
|
+
"""Number of faces."""
|
|
1220
|
+
return self._num_faces
|
|
1221
|
+
|
|
1222
|
+
@property
|
|
1223
|
+
def num_boundary_faces(self) -> int:
|
|
1224
|
+
"""Number of boundary faces."""
|
|
1225
|
+
return self._num_boundary_faces
|
|
1226
|
+
|
|
1227
|
+
@property
|
|
1228
|
+
def num_boundary_connections(self) -> int:
|
|
1229
|
+
"""Total number of boundary connections over all boundary faces."""
|
|
1230
|
+
return self._num_boundary_connections
|
|
1231
|
+
|
|
1232
|
+
@property
|
|
1233
|
+
def shared_connectivity(self) -> int | None:
|
|
1234
|
+
"""0-based source zone index if connectivity is shared, else None."""
|
|
1235
|
+
return self._shared_connectivity
|
|
1236
|
+
|
|
1237
|
+
def _face_map_digest(self) -> str:
|
|
1238
|
+
"""Return a hash identifying this zone's grid, for matching grids across zones.
|
|
1239
|
+
|
|
1240
|
+
The face map is read without filling the array cache, so scanning many zones
|
|
1241
|
+
does not keep their arrays in memory.
|
|
1242
|
+
"""
|
|
1243
|
+
h = hashlib.blake2b(digest_size=16)
|
|
1244
|
+
h.update(
|
|
1245
|
+
f"{self.zone_type.name}:{self._num_nodes}:{self._num_elements}:"
|
|
1246
|
+
f"{self._num_faces}".encode()
|
|
1247
|
+
)
|
|
1248
|
+
keys: tuple[PolyArrayKey, ...] = (
|
|
1249
|
+
"face_nodes",
|
|
1250
|
+
"face_left_elements",
|
|
1251
|
+
"face_right_elements",
|
|
1252
|
+
)
|
|
1253
|
+
if self.zone_type is ZoneType.FEPOLYHEDRON:
|
|
1254
|
+
keys = ("face_node_counts", *keys)
|
|
1255
|
+
for key in keys:
|
|
1256
|
+
arr = np.ascontiguousarray(self._load_array(key))
|
|
1257
|
+
h.update(arr.data)
|
|
1258
|
+
return h.hexdigest()
|
|
1259
|
+
|
|
1260
|
+
# -- Lazy face-map arrays ----------------------------------------------------------
|
|
1261
|
+
|
|
1262
|
+
def _array(self, key: PolyArrayKey) -> npt.NDArray[np.int64]:
|
|
1263
|
+
"""Return the cached array for *key*, loading it on first use."""
|
|
1264
|
+
cache = self._array_cache
|
|
1265
|
+
arr = cache.get(key)
|
|
1266
|
+
if arr is None:
|
|
1267
|
+
arr = self._load_array(key)
|
|
1268
|
+
cache[key] = arr
|
|
1269
|
+
return arr
|
|
1270
|
+
|
|
1271
|
+
@abstractmethod
|
|
1272
|
+
def _load_array(self, key: PolyArrayKey) -> npt.NDArray[np.int64]:
|
|
1273
|
+
"""Read one face-map array, 0-based, as int64. Called at most once per key.
|
|
1274
|
+
|
|
1275
|
+
Never called for ``face_node_counts`` of a FEPOLYGON zone, which is
|
|
1276
|
+
synthesized by the base class.
|
|
1277
|
+
"""
|
|
1278
|
+
|
|
1279
|
+
@property
|
|
1280
|
+
def face_node_counts(self) -> npt.NDArray[np.int64]:
|
|
1281
|
+
"""Number of nodes of each face, shape ``(num_faces,)``."""
|
|
1282
|
+
if self.zone_type is ZoneType.FEPOLYGON:
|
|
1283
|
+
cache = self._array_cache
|
|
1284
|
+
arr = cache.get("face_node_counts")
|
|
1285
|
+
if arr is None:
|
|
1286
|
+
arr = np.full(self._num_faces, 2, dtype=np.int64)
|
|
1287
|
+
cache["face_node_counts"] = arr
|
|
1288
|
+
return arr
|
|
1289
|
+
return self._array("face_node_counts")
|
|
1290
|
+
|
|
1291
|
+
@property
|
|
1292
|
+
def face_node_offsets(self) -> npt.NDArray[np.int64]:
|
|
1293
|
+
"""Running offsets into :attr:`face_nodes`, shape ``(num_faces + 1,)``.
|
|
1294
|
+
|
|
1295
|
+
The nodes of face ``f`` are ``face_nodes[offsets[f]:offsets[f + 1]]``.
|
|
1296
|
+
"""
|
|
1297
|
+
arr = self._array_cache.get("face_node_offsets")
|
|
1298
|
+
if arr is None:
|
|
1299
|
+
arr = counts_to_offsets(self.face_node_counts)
|
|
1300
|
+
self._array_cache["face_node_offsets"] = arr
|
|
1301
|
+
return arr
|
|
1302
|
+
|
|
1303
|
+
@property
|
|
1304
|
+
def face_nodes(self) -> npt.NDArray[np.int64]:
|
|
1305
|
+
"""Flat 0-based node indices of all faces, in face order."""
|
|
1306
|
+
return self._array("face_nodes")
|
|
1307
|
+
|
|
1308
|
+
@property
|
|
1309
|
+
def face_left_elements(self) -> npt.NDArray[np.int64]:
|
|
1310
|
+
"""Element on the left of each face, shape ``(num_faces,)``, see class doc."""
|
|
1311
|
+
return self._array("face_left_elements")
|
|
1312
|
+
|
|
1313
|
+
@property
|
|
1314
|
+
def face_right_elements(self) -> npt.NDArray[np.int64]:
|
|
1315
|
+
"""Element on the right of each face, shape ``(num_faces,)``, see class doc."""
|
|
1316
|
+
return self._array("face_right_elements")
|
|
1317
|
+
|
|
1318
|
+
@property
|
|
1319
|
+
def boundary_connection_counts(self) -> npt.NDArray[np.int64]:
|
|
1320
|
+
"""Connections of each boundary face, shape ``(num_boundary_faces,)``."""
|
|
1321
|
+
if self._num_boundary_faces == 0:
|
|
1322
|
+
return np.zeros(0, dtype=np.int64)
|
|
1323
|
+
return self._array("boundary_connection_counts")
|
|
1324
|
+
|
|
1325
|
+
@property
|
|
1326
|
+
def boundary_connection_offsets(self) -> npt.NDArray[np.int64]:
|
|
1327
|
+
"""Running offsets into the boundary connection arrays.
|
|
1328
|
+
|
|
1329
|
+
Shape ``(num_boundary_faces + 1,)``.
|
|
1330
|
+
"""
|
|
1331
|
+
arr = self._array_cache.get("boundary_connection_offsets")
|
|
1332
|
+
if arr is None:
|
|
1333
|
+
arr = counts_to_offsets(self.boundary_connection_counts)
|
|
1334
|
+
self._array_cache["boundary_connection_offsets"] = arr
|
|
1335
|
+
return arr
|
|
1336
|
+
|
|
1337
|
+
@property
|
|
1338
|
+
def boundary_connection_elements(self) -> npt.NDArray[np.int64]:
|
|
1339
|
+
"""0-based neighbor element of every boundary connection, flat."""
|
|
1340
|
+
if self._num_boundary_connections == 0:
|
|
1341
|
+
return np.zeros(0, dtype=np.int64)
|
|
1342
|
+
return self._array("boundary_connection_elements")
|
|
1343
|
+
|
|
1344
|
+
@property
|
|
1345
|
+
def boundary_connection_zones(self) -> npt.NDArray[np.int64]:
|
|
1346
|
+
"""0-based zone of the neighbor of every boundary connection, flat."""
|
|
1347
|
+
if self._num_boundary_connections == 0:
|
|
1348
|
+
return np.zeros(0, dtype=np.int64)
|
|
1349
|
+
return self._array("boundary_connection_zones")
|
|
1350
|
+
|
|
1351
|
+
def element_faces(self) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]:
|
|
1352
|
+
"""Return the faces of every element as ``(offsets, faces)``.
|
|
1353
|
+
|
|
1354
|
+
The faces of element ``e`` are ``faces[offsets[e]:offsets[e + 1]]``, in ascending
|
|
1355
|
+
face order. They come from :attr:`face_left_elements` and
|
|
1356
|
+
:attr:`face_right_elements`. A side that is no element of this zone (``-1`` or a
|
|
1357
|
+
boundary face reference) is skipped, so a face next to another zone is listed
|
|
1358
|
+
only for its own element. The arrays are computed on each call, not cached.
|
|
1359
|
+
|
|
1360
|
+
Returns:
|
|
1361
|
+
The ``offsets`` with shape ``(num_elements + 1,)`` and the flat ``faces``.
|
|
1362
|
+
"""
|
|
1363
|
+
return faces_by_element(
|
|
1364
|
+
self.face_left_elements, self.face_right_elements, self._num_elements
|
|
1365
|
+
)
|
|
1366
|
+
|
|
1367
|
+
def element_nodes(self) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]:
|
|
1368
|
+
"""Return the distinct nodes of every element as ``(offsets, nodes)``.
|
|
1369
|
+
|
|
1370
|
+
The nodes of element ``e`` are ``nodes[offsets[e]:offsets[e + 1]]``. They are the
|
|
1371
|
+
nodes of the element's faces with repeats removed, in ascending order. That is a
|
|
1372
|
+
set, not a cell node order, because a polyhedron has no natural node order. The
|
|
1373
|
+
arrays are computed on each call, not cached.
|
|
1374
|
+
|
|
1375
|
+
Returns:
|
|
1376
|
+
The ``offsets`` with shape ``(num_elements + 1,)`` and the flat ``nodes``.
|
|
1377
|
+
"""
|
|
1378
|
+
offsets, faces = self.element_faces()
|
|
1379
|
+
return nodes_by_element(
|
|
1380
|
+
self.face_nodes, self.face_node_offsets, offsets, faces, self._num_nodes
|
|
1381
|
+
)
|
|
1382
|
+
|
|
1383
|
+
|
|
943
1384
|
# ======================================================================================
|
|
944
1385
|
# TecplotReader
|
|
945
1386
|
# ======================================================================================
|