tecio.plt.Write#
- class tecio.plt.Write#
Bases:
objectWrite 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 (whenvariablesis supplied to__init__) or lazily (deferred until the firstwrite_ijk_zone()orwrite_fe_zone()call, at which pointvariablesmust 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_type –
FileTypeenum. Defaults toFULL.
- current_zone#
The index of the most recently written zone. Before any zones have been written,
current_zoneis0. During a call to a zone writing method,current_zonestill refers to the previously written zone.current_zoneis incremented only after a zone writing method successfully completes.- Type:
- auxdataset#
Buffered dataset-level auxiliary data, flushed before the first zone.
- auxvar#
Buffered variable-level auxiliary data, flushed before the first zone.
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", ... )
- __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
withblock. If closing itself raises, that secondary exception is only re-raised when thewithblock 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.
- close()[source]#
Finalize and close the PLT file (safe to call more than once).
Calls
tecend142only if the file was opened.
- flush_aux()[source]#
Write buffered dataset- and variable-level aux data to the file.
Must be called after
tecini142and before the firstteczne142. 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:
teczne142()— zone header.teczauxstr142()— zone-level aux data (if any), before data.tecdat142()— one call per active variable.tecnode142()— node map.tecface142()— face-neighbour connections (if provided).
FEPOLYGONandFEPOLYHEDRONzone types are not supported (they requiretecpolyface142/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 lengthnum_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 allNODAL.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
0for no sharing (mandatory for the first zone).face_neighbors – Optional face-neighbour connection array. Its length sets
num_face_connectionsin 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).POINTis 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 isPOINT.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 × kmaxare 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 allNODAL.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).
0means no sharing. Defaults to no sharing.solution_time – Solution time for transient data (
0.0indicates steady-state).strand_id – Strand ID for transient data (
0indicates 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).POINTis 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.