tecio.plt.Write#

class tecio.plt.Write#

Bases: object

Write Tecplot PLT (.plt) files using the classic TecIO API.

The classic TecIO API maintains a single implicit global file context; only one PLT file may be open at a time. This class wraps that procedural API behind the same interface as szl.Write.

Dataset- and variable-level auxiliary data can be set at any time before the first zone is written. They are buffered and flushed automatically when the first zone header is created. Zone-level auxiliary data is passed directly to each zone-writing method.

Like szl.Write, the file can be opened eagerly (when variables is supplied to __init__) or lazily (deferred until the first write_ijk_zone() or write_fe_zone() call, at which point variables must be provided to that call).

Parameters:
  • path – Output file path (should end in .plt).

  • title – Dataset title string.

  • variables – Variable name list. If provided the file is opened immediately. If None, the file is opened on the first zone write.

  • file_typeFileType enum. Defaults to FULL.

path#

Output file path.

Type:

str

title#

Dataset title string.

Type:

str

variables#

Variable name list, or None if the file has not been opened yet.

Type:

list[str] | None

file_type#

File type (FULL, GRID, or SOLUTION).

Type:

FileType

current_zone#

The index of the most recently written zone. Before any zones have been written, current_zone is 0. During a call to a zone writing method, current_zone still refers to the previously written zone. current_zone is incremented only after a zone writing method successfully completes.

Type:

int

auxdataset#

Buffered dataset-level auxiliary data, flushed before the first zone.

Type:

dict[str, Any]

auxvar#

Buffered variable-level auxiliary data, flushed before the first zone.

Type:

dict[int, dict[str, Any]]

Caution

Unlike the SZL writer, zone data must be written strictly in order: header → variable data → connectivity. This is enforced internally by the write methods.

Examples

Define file header fields on open.

>>> with plt.Write("out.plt", variables=["X", "Y", "P"]) as w:
...     w.write_ijk_zone(data=[x, y, p], title="Zone 1")

If writer handle is opened with just the file name, the variable name list can be provided with the first zone written.

>>> with plt.Write("out.plt") as w:
...     w.write_ijk_zone(
...         data=[x, y, p],
...         variables=["X", "Y", "P"],
...         title="Zone 1",
...     )
__enter__()[source]#

Support with statement — returns self.

__exit__(exc_type, exc_value, traceback)[source]#

Close the file on context-manager exit.

The file is closed regardless of whether an exception was raised in the with block. If closing itself raises, that secondary exception is only re-raised when the with block completed without error; otherwise the original exception takes precedence.

__init__(path, title='untitled', variables=None, file_type=FileType.FULL)[source]#

Store configuration; open the file immediately if variables given.

add_auxdataset_dict(auxdict)[source]#

Create buffered auxdataset items from input dictionary.

add_auxvar_dict(auxdict)[source]#

Create buffered auxvar items from input dictionary.

close()[source]#

Finalize and close the PLT file (safe to call more than once).

Calls tecend142 only if the file was opened.

flush_aux()[source]#

Write buffered dataset- and variable-level aux data to the file.

Must be called after tecini142 and before the first teczne142. The zone-writing methods call this automatically; users need not call it directly unless flushing explicitly.

In the classic API:

  • Dataset aux data is written via tecauxstr142.

  • Variable aux data is written via tecvauxstr142.

Both must appear before the first zone header.

write_fe_zone(data, zone_type, *, node_map=None, title=None, variables=None, value_locations=None, passive_vars=None, var_sharing=None, con_sharing=0, face_neighbors=None, face_nbr_mode=FaceNeighborMode.LOCAL_ONE_TO_ONE, solution_time=0.0, strand_id=0, aux=None, datapacking=DataPacking.BLOCK)[source]#

Write a complete finite-element zone.

The full sequence required by the classic TecIO API is issued internally:

  1. teczne142() — zone header.

  2. teczauxstr142() — zone-level aux data (if any), before data.

  3. tecdat142() — one call per active variable.

  4. tecnode142() — node map.

  5. tecface142() — face-neighbour connections (if provided).

FEPOLYGON and FEPOLYHEDRON zone types are not supported (they require tecpolyface142 / tecpolybconn142); use the low-level libtecio API directly for those types.

Parameters:
  • data – Sequence of 1-D NumPy arrays, one per active variable. NODAL arrays must have length num_nodes; CELL_CENTERED arrays must have length num_cells. Both counts are inferred from node_map.

  • zone_type – FE zone type from the ZoneType enum. Must be one of the types in _FE_SIMPLE.

  • node_map – Integer array of shape (num_cells, nodes_per_cell) with 1-based node indices.

  • title – Zone title. Defaults to "FE_Zone_{current_zone + 1}".

  • variables – Variable name list. Required only when the file has not been opened yet (lazy-open path). Ignored on subsequent zones once the file is already initialised. Default to [V1, V2, V3, ...] if not provided in open or zone call.

  • value_locations – Per-variable ValueLocation. Defaults to all NODAL.

  • passive_vars – Per-variable passive flags (dataset-length). Defaults to all active.

  • var_sharing – Per-variable sharing zone indices (dataset- length). Defaults to no sharing.

  • con_sharing – Source-zone index for connectivity sharing. Pass 0 for no sharing (mandatory for the first zone).

  • face_neighbors – Optional face-neighbour connection array. Its length sets num_face_connections in the zone header automatically.

  • face_nbr_mode – Face-neighbour mode; used only when face_neighbors is provided.

  • solution_time – Solution time for transient data.

  • strand_id – Strand ID for transient data.

  • aux – Zone-level auxiliary data as {name: value}.

  • datapacking – Must be BLOCK (the default). POINT is an ASCII-only layout and is not supported by the PLT binary format.Defined only for parity with ASCII writer.

Raises:
  • NotImplementedError – If zone_type is not in _FE_SIMPLE, or if datapacking is POINT.

  • ValueError – On variable count or array length mismatch

  • RuntimeError – If attempting to write variable aux before variables are defined.

write_ijk_zone(data, *, title=None, variables=None, value_locations=None, passive_vars=None, var_sharing=None, solution_time=0.0, strand_id=0, aux=None, datapacking=DataPacking.BLOCK)[source]#

Write a complete IJK-ordered zone.

The zone header (teczne142), variable data (tecdat142), and optional zone aux data (teczauxstr142) are all written in strict sequence, as required by the classic TecIO API.

The zone dimensions imax × jmax × kmax are inferred from the shape of the first nodal data array. 1-D arrays produce a (N, 1, 1) zone; 2-D arrays produce an (I, J, 1) zone.

Parameters:
  • data – Sequence of NumPy arrays, one per active variable. NODAL arrays must all share the same shape. CELL_CENTERED arrays must have shape (imax-1, jmax-1, kmax-1) (minimum 1 in each dimension).

  • title – Zone title. Defaults to "IJK_Zone_{current_zone + 1}".

  • variables – Variable name list. Required only when the file has not been opened yet (lazy-open path). Ignored on subsequent zones once the file is already initialised. Default to [V1, V2, V3, ...] if not provided in open or zone call.

  • value_locations – Per-variable ValueLocation. Defaults to all NODAL.

  • passive_vars – Per-variable passive flags (one per dataset variable, not just active variables). Defaults to all active (False).

  • var_sharing – Per-variable source-zone sharing indices (one per dataset variable). 0 means no sharing. Defaults to no sharing.

  • solution_time – Solution time for transient data (0.0 indicates steady-state).

  • strand_id – Strand ID for transient data (0 indicates steady-state).

  • aux – Zone-level auxiliary data as {name: value} strings. Written immediately after the zone header and before variable data.

  • datapacking – Must be BLOCK (the default). POINT is an ASCII-only layout and is not supported by the PLT binary format. Defined only for parity with ASCII writer.

Raises:
  • NotImplementedError – If datapacking is POINT.

  • ValueError – If the number of supplied data arrays does not match the number of active (non-passive, non-shared) variables, or if array shapes are inconsistent.