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.
Files changed (39) hide show
  1. tecio/__init__.py +46 -2
  2. tecio/_constants.py +2 -2
  3. tecio/_dat_read.py +268 -17
  4. tecio/_dat_write.py +347 -10
  5. tecio/_elements.py +1311 -0
  6. tecio/_io.py +108 -31
  7. tecio/_meta.py +47 -20
  8. tecio/_plt_legacy.py +9 -1
  9. tecio/_plt_read.py +285 -89
  10. tecio/_plt_write.py +286 -9
  11. tecio/_reader.py +460 -19
  12. tecio/_szl_read.py +155 -17
  13. tecio/_szl_write.py +322 -11
  14. tecio/_utils.py +78 -15
  15. tecio/_writer.py +963 -102
  16. tecio/cli/tec2mat.py +69 -30
  17. tecio/cli/tecaux.py +24 -30
  18. tecio/cli/tecdump.py +67 -5
  19. tecio/cli/tecelretyp.py +1096 -0
  20. tecio/cli/tecextract.py +57 -14
  21. tecio/cli/tecfix.py +32 -14
  22. tecio/cli/tecmerge.py +289 -45
  23. tecio/cli/teconvert.py +29 -16
  24. tecio/cli/tecscale.py +40 -13
  25. tecio/cli/tecslice.py +158 -69
  26. tecio/cli/tecstats.py +6 -2
  27. tecio/libtecio.py +192 -67
  28. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/matlab/tecmat2struct.m +18 -18
  29. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/paraview/TecplotTecioReader.py +463 -38
  30. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/paraview/TecplotTecioWriter.py +459 -84
  31. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/METADATA +33 -17
  32. tecio_python-0.4.2.dist-info/RECORD +40 -0
  33. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/WHEEL +1 -1
  34. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/entry_points.txt +1 -0
  35. tecio_python-0.4.0.dist-info/RECORD +0 -38
  36. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/matlab/contourfe.m +0 -0
  37. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/licenses/LICENSE +0 -0
  38. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/licenses/NOTICE +0 -0
  39. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/top_level.txt +0 -0
tecio/_plt_write.py CHANGED
@@ -21,6 +21,7 @@ from ._constants import (
21
21
  DataPacking,
22
22
  DataType,
23
23
  FaceNeighborMode,
24
+ FeCellShape,
24
25
  FileFormat,
25
26
  FileType,
26
27
  ValueLocation,
@@ -31,12 +32,14 @@ from ._writer import (
31
32
  PassiveVarsSpec,
32
33
  PreparedFEZone,
33
34
  PreparedOrderedZone,
35
+ PreparedPolyZone,
34
36
  TecplotWriter,
35
37
  VarSharingSpec,
36
38
  convert_face_connections_to_one_based,
37
39
  normalize_precision,
38
40
  prepare_fe_zone,
39
41
  prepare_ordered_zone,
42
+ prepare_poly_zone,
40
43
  var_sharing_for_libtecio,
41
44
  zone_for_libtecio,
42
45
  )
@@ -65,6 +68,9 @@ def _infer_data_type(dt: DataType | np.dtype) -> DataType:
65
68
  FLOAT and DOUBLE are supported; all integer types are upcast to DOUBLE. precision
66
69
  is promoted to ``FLOAT``; 64-bit integers are promoted to ``INT32``; ``int8`` and
67
70
  ``uint8`` map to ``BYTE``.
71
+
72
+ Raises:
73
+ ValueError: If the dtype is not supported.
68
74
  """
69
75
  closest: dict[np.dtype, DataType] = {
70
76
  np.dtype(np.float64): DataType.DOUBLE,
@@ -546,9 +552,8 @@ class TecplotPltWriter(TecplotWriter):
546
552
  5. :func:`~tecio.libtecio.tecface142` — face-neighbour connections (if
547
553
  provided).
548
554
 
549
- ``FEPOLYGON`` and ``FEPOLYHEDRON`` zone types are not supported
550
- (they require ``tecpolyface142`` / ``tecpolybconn142``); use the
551
- low-level libtecio API directly for those types.
555
+ ``FEPOLYGON`` and ``FEPOLYHEDRON`` zones are face-based, write them with
556
+ :meth:`write_poly_zone`.
552
557
 
553
558
  Args:
554
559
  data (Sequence[npt.ArrayLike]):
@@ -623,13 +628,13 @@ class TecplotPltWriter(TecplotWriter):
623
628
 
624
629
  Raises:
625
630
  NotImplementedError:
626
- For FEPOLYGON, FEPOLYHEDRON, or if *datapacking* is
627
- :attr:`~tecio.libtecio.DataPacking.POINT`.
631
+ If *datapacking* is :attr:`~tecio.libtecio.DataPacking.POINT`.
628
632
  TypeError:
629
633
  If *passive_vars*/*var_sharing* isn't a list/tuple/set/mapping as
630
634
  appropriate, or mixes variable names and indices.
631
635
  ValueError:
632
- On variable count or array length mismatch; if ``node_map`` is omitted
636
+ For FEPOLYGON or FEPOLYHEDRON (use :meth:`write_poly_zone`); on
637
+ variable count or array length mismatch; if ``node_map`` is omitted
633
638
  without ``con_sharing``; if ``var_sharing``/``con_sharing`` reference a
634
639
  zone with no recorded node/cell count, or one whose count disagrees with
635
640
  this zone's; or a variable named in both *passive_vars* and
@@ -658,11 +663,13 @@ class TecplotPltWriter(TecplotWriter):
658
663
  "by the PLT binary format. Use DataPacking.BLOCK (the default) "
659
664
  "or write to a .dat file instead."
660
665
  )
666
+ if zone_type in (ZoneType.FEPOLYGON, ZoneType.FEPOLYHEDRON):
667
+ raise ValueError(
668
+ f"{zone_type.name} zones are face-based, use write_poly_zone."
669
+ )
661
670
  if zone_type not in _FE_SIMPLE:
662
671
  raise NotImplementedError(
663
- f"Zone type {zone_type.name!r} is not supported by "
664
- "write_fe_zone. FEPOLYGON and FEPOLYHEDRON zones require "
665
- "the low-level libtecio API."
672
+ f"Zone type {zone_type.name!r} is not supported by write_fe_zone."
666
673
  )
667
674
 
668
675
  # Convert input data to NumPy arrays
@@ -791,3 +798,273 @@ class TecplotPltWriter(TecplotWriter):
791
798
  num_face_connections=num_face_cons or None,
792
799
  )
793
800
  )
801
+
802
+ def write_femixed_zone(
803
+ self,
804
+ data: Sequence[npt.ArrayLike],
805
+ cell_shapes: Sequence[FeCellShape | int | str] | None = None,
806
+ node_maps: Sequence[npt.ArrayLike] | None = None,
807
+ *,
808
+ title: str | None = None,
809
+ variables: list[str] | None = None,
810
+ value_locations: Sequence[ValueLocation] | None = None,
811
+ passive_vars: PassiveVarsSpec | None = None,
812
+ var_sharing: VarSharingSpec | None = None,
813
+ con_sharing: int | None = None,
814
+ solution_time: float = 0.0,
815
+ strand_id: int = 0,
816
+ aux: dict[str, Any] | None = None,
817
+ datapacking: DataPacking | str = DataPacking.BLOCK,
818
+ ) -> None:
819
+ """Not supported: PLT files cannot hold FEMIXED zones.
820
+
821
+ The signature matches :meth:`TecplotSzlWriter.write_femixed_zone` so every
822
+ writer exposes the same interface.
823
+
824
+ Raises:
825
+ NotImplementedError: Always. Write a ``.szplt`` file instead, see
826
+ :meth:`TecplotSzlWriter.write_femixed_zone`.
827
+ """
828
+ raise NotImplementedError(
829
+ "The PLT file format does not support FEMIXED (mixed finite-element) "
830
+ "zones. Write a .szplt file instead."
831
+ )
832
+
833
+ def write_poly_zone(
834
+ self,
835
+ data: Sequence[npt.ArrayLike],
836
+ zone_type: ZoneType,
837
+ *,
838
+ face_nodes: npt.ArrayLike | None = None,
839
+ face_node_counts: npt.ArrayLike | None = None,
840
+ face_left_elements: npt.ArrayLike | None = None,
841
+ face_right_elements: npt.ArrayLike | None = None,
842
+ boundary_connection_counts: npt.ArrayLike | None = None,
843
+ boundary_connection_elements: npt.ArrayLike | None = None,
844
+ boundary_connection_zones: npt.ArrayLike | None = None,
845
+ title: str | None = None,
846
+ variables: list[str] | None = None,
847
+ value_locations: Sequence[ValueLocation] | None = None,
848
+ passive_vars: PassiveVarsSpec | None = None,
849
+ var_sharing: VarSharingSpec | None = None,
850
+ con_sharing: int | None = None,
851
+ solution_time: float = 0.0,
852
+ strand_id: int = 0,
853
+ aux: dict[str, Any] | None = None,
854
+ datapacking: DataPacking | str = DataPacking.BLOCK,
855
+ ) -> None:
856
+ """Write a complete FEPOLYGON or FEPOLYHEDRON (face-based) zone.
857
+
858
+ Node and element counts are inferred from the face map, or from the
859
+ *con_sharing* source zone when it is omitted. Every index is 0-based. The
860
+ arguments match what :class:`~tecio.TecplotPolyZoneReader` returns, so a zone
861
+ read from a file can be written back unchanged.
862
+
863
+ The classic TecIO sequence is issued internally: ``tecpolyzne142`` (header),
864
+ ``teczauxstr142`` (aux data), ``tecdat142`` (one call per active variable),
865
+ then ``tecpolyface142`` and, with boundary connections, ``tecpolybconn142``.
866
+ Connectivity is skipped when shared via *con_sharing*.
867
+
868
+ Args:
869
+ data (Sequence[npt.ArrayLike]):
870
+ Sequence of 1-D arrays, one per active (non-passive, non-shared) dataset
871
+ variable, in dataset order. NODAL arrays need ``num_nodes`` values,
872
+ CELL_CENTERED arrays ``num_elements``, both inferred from the face map.
873
+ zone_type (ZoneType):
874
+ :attr:`~tecio.ZoneType.FEPOLYGON` or
875
+ :attr:`~tecio.ZoneType.FEPOLYHEDRON`.
876
+ face_nodes (npt.ArrayLike):
877
+ Flat 0-based node indices of all faces, in face order. Two per face
878
+ for a polygon zone. Required unless ``con_sharing`` is set.
879
+ face_node_counts (npt.ArrayLike):
880
+ Number of nodes of each face. Required for FEPOLYHEDRON. Optional for
881
+ FEPOLYGON, where every face has 2 nodes.
882
+ face_left_elements (npt.ArrayLike):
883
+ Element on the left of each face: a 0-based element index, ``-1`` for
884
+ no element, or ``-(b + 2)`` for boundary face ``b`` (0-based).
885
+ face_right_elements (npt.ArrayLike):
886
+ Element on the right of each face, same convention as
887
+ ``face_left_elements``.
888
+ boundary_connection_counts (npt.ArrayLike):
889
+ Number of connections of each boundary face. Boundary faces describe
890
+ neighbors in other zones, or faces with more than one neighbor.
891
+ boundary_connection_elements (npt.ArrayLike):
892
+ Flat 0-based neighbor element of every boundary connection.
893
+ boundary_connection_zones (npt.ArrayLike):
894
+ Flat 0-based zone of every neighbor element. May only reference a zone
895
+ already written or this zone.
896
+ title (str):
897
+ Zone title string. Defaults to ``"Poly_Zone_{index}"``, with this
898
+ zone's 0-based index.
899
+ variables (list[str]):
900
+ Variable name list, only used when the file has not been opened yet
901
+ (lazy-open path). Defaults to ``[V1, V2, V3, ...]``.
902
+ value_locations (Sequence[ValueLocation]):
903
+ Per-active-variable :class:`~tecio.ValueLocation`. Defaults to all
904
+ ``NODAL``.
905
+ passive_vars (list | tuple | set | None):
906
+ Variables to mark passive: a list, tuple, or set of variable names, or
907
+ of 0-based indices. Defaults to all active.
908
+ var_sharing (Mapping[int | str, int]):
909
+ Variables to share from another zone: a ``{variable: source zone}``
910
+ mapping, name or 0-based index to 0-based zone index.
911
+ con_sharing (int):
912
+ Zone index to share the face map from, which must be a zone of the
913
+ same type without boundary faces (TecIO does not allow sharing those).
914
+ ``None`` means this zone owns its connectivity.
915
+ solution_time (float):
916
+ Solution time for transient data. Defaults to ``0.0``.
917
+ strand_id (int):
918
+ Strand ID for transient data, ``0`` for static zones.
919
+ aux (dict[str, str | float | int]):
920
+ Zone-level auxiliary data as ``{name: value}`` pairs.
921
+ datapacking (DataPacking | str):
922
+ Must be :attr:`~tecio.DataPacking.BLOCK`, the only layout of the PLT
923
+ binary format.
924
+
925
+ Raises:
926
+ TypeError:
927
+ If *passive_vars*/*var_sharing* isn't a list/tuple/set/mapping as
928
+ appropriate, or mixes variable names and indices.
929
+ ValueError:
930
+ If *datapacking* is :attr:`~tecio.DataPacking.POINT`. For a
931
+ *zone_type* other than FEPOLYGON or FEPOLYHEDRON (use
932
+ :meth:`write_fe_zone`); on a missing, inconsistent, or out of range
933
+ face map, boundary connection, or variable array.
934
+ KeyError:
935
+ A *passive_vars*/*var_sharing* name doesn't match any dataset variable.
936
+ IndexError:
937
+ A *passive_vars*/*var_sharing* index is out of range.
938
+ """
939
+ if isinstance(datapacking, str):
940
+ try:
941
+ datapacking = DataPacking[datapacking.upper()]
942
+ except KeyError:
943
+ raise ValueError(
944
+ f"datapacking={datapacking!r} is not a recognised value; "
945
+ "use DataPacking.BLOCK or the string 'BLOCK'."
946
+ ) from None
947
+ if datapacking != DataPacking.BLOCK:
948
+ raise ValueError(
949
+ "Polygon and polyhedron zones must use BLOCK data packing."
950
+ )
951
+
952
+ arrays: list[npt.NDArray] = [np.asarray(arr) for arr in data]
953
+
954
+ if title is None:
955
+ title = f"Poly_Zone_{self.current_zone + 1}"
956
+ if variables is None:
957
+ variables = [f"V{i}" for i in range(1, len(arrays) + 1)]
958
+
959
+ # Open the file if lazily loaded and flush buffered aux data
960
+ if not self._opened:
961
+ self._open(variables)
962
+ if self.current_zone == -1:
963
+ self.flush_aux()
964
+
965
+ variable_types = [self.precision] * len(arrays)
966
+
967
+ prepared: PreparedPolyZone | None = prepare_poly_zone(
968
+ arrays,
969
+ variable_types,
970
+ zone_type,
971
+ face_nodes=face_nodes,
972
+ face_node_counts=face_node_counts,
973
+ face_left_elements=face_left_elements,
974
+ face_right_elements=face_right_elements,
975
+ boundary_connection_counts=boundary_connection_counts,
976
+ boundary_connection_elements=boundary_connection_elements,
977
+ boundary_connection_zones=boundary_connection_zones,
978
+ value_locations=value_locations,
979
+ passive_vars=passive_vars,
980
+ var_sharing=var_sharing,
981
+ con_sharing=con_sharing,
982
+ dataset_variables=self._check_variables(),
983
+ meta=self._meta,
984
+ )
985
+ if prepared is None:
986
+ return
987
+ conn = prepared.connectivity
988
+ share_idx = prepared.var_sharing
989
+
990
+ libtecio.tecpolyzne142(
991
+ zone_title=title,
992
+ zone_type=zone_type,
993
+ num_nodes=conn.num_nodes,
994
+ num_faces=conn.num_faces,
995
+ num_elements=conn.num_cells,
996
+ var_sharing=(
997
+ var_sharing_for_libtecio(share_idx)
998
+ if any(s is not None for s in share_idx)
999
+ else None
1000
+ ),
1001
+ value_locations=prepared.value_locations_global,
1002
+ pas_vars=prepared.passive_vars,
1003
+ con_sharing=zone_for_libtecio(prepared.con_sharing),
1004
+ strand=strand_id,
1005
+ solution_time=solution_time,
1006
+ total_num_face_nodes=conn.total_face_nodes,
1007
+ num_connected_boundary_faces=conn.num_boundary_faces,
1008
+ total_num_boundary_connections=conn.num_boundary_connections,
1009
+ )
1010
+ self.current_zone += 1
1011
+
1012
+ # Zone-level aux data must be immediately after the zone header, before data.
1013
+ if aux is not None:
1014
+ for name, value in aux.items():
1015
+ libtecio.teczauxstr142(str(name), str(value))
1016
+
1017
+ for var_idx, arr, dtype in zip(
1018
+ prepared.active_var_idx, arrays, variable_types, strict=True
1019
+ ):
1020
+ self.current_var = var_idx
1021
+ _write_data(arr, dtype)
1022
+
1023
+ # Face map (if not shared), after all data arrays. TecIO is 1-based with 0 for
1024
+ # no element and -k for the k-th boundary face, which is the 0-based API
1025
+ # convention shifted by one for every array.
1026
+ if prepared.con_sharing is None:
1027
+ assert conn.face_nodes is not None
1028
+ assert (
1029
+ conn.face_left_elements is not None
1030
+ and conn.face_right_elements is not None
1031
+ )
1032
+ # Polygon: counts are NULL, every face is a two node edge.
1033
+ libtecio.tecpolyface142(
1034
+ conn.face_node_counts,
1035
+ conn.face_nodes.astype(np.int32) + 1,
1036
+ conn.face_left_elements.astype(np.int32) + 1,
1037
+ conn.face_right_elements.astype(np.int32) + 1,
1038
+ num_faces=conn.num_faces,
1039
+ )
1040
+ if conn.num_boundary_faces:
1041
+ assert conn.boundary_connection_counts is not None
1042
+ assert conn.boundary_connection_elements is not None
1043
+ assert conn.boundary_connection_zones is not None
1044
+ libtecio.tecpolybconn142(
1045
+ conn.boundary_connection_counts,
1046
+ conn.boundary_connection_elements.astype(np.int32) + 1,
1047
+ conn.boundary_connection_zones.astype(np.int32) + 1,
1048
+ )
1049
+
1050
+ # Finally set zone metadata after successfully completing TecIO calls
1051
+ self._meta.record_zone(
1052
+ ZoneMeta(
1053
+ index=self.current_zone,
1054
+ title=title,
1055
+ zone_type=zone_type,
1056
+ solution_time=solution_time,
1057
+ strand_id=strand_id,
1058
+ num_aux_items=len(aux) if aux else 0,
1059
+ num_nodes=conn.num_nodes,
1060
+ num_elements=conn.num_cells,
1061
+ num_faces=conn.num_faces,
1062
+ total_face_nodes=conn.total_face_nodes,
1063
+ num_boundary_faces=conn.num_boundary_faces,
1064
+ num_boundary_connections=conn.num_boundary_connections,
1065
+ value_locations=tuple(prepared.value_locations_global),
1066
+ passive_vars=tuple(prepared.passive_vars),
1067
+ shared_vars=tuple(share_idx),
1068
+ data_types=tuple(prepared.variable_types_global),
1069
+ )
1070
+ )