tecio.szl.Write#
- class tecio.szl.Write#
Bases:
objectWrite Tecplot SZL (
.szplt) files with a lazy-open file handle.Supports lazy-open: if variables is
Noneat construction, the file is created on the first zone write. Auxiliary data is buffered and flushed automatically before the first zone.The tecio library requires a list of variables when the output file is opened. However if writing data on the fly, it may be beneficial to store file outputs until the first zone is passed to the writer. Then file header will be garanteed to be consistent with the first zone variables.
For the SZL API, file contents can be written out of order after creating zones.
- Parameters:
path – Output file path.
title – Dataset title.
variables – Variable name list.
Nonedefers file creation.file_type – File type enum (FULL, GRID, or SOLUTION).
- path#
Output file path.
- title#
Dataset title string.
- variables#
Variable name list, or
Noneif the file has not been opened yet.
- file_type#
File type (FULL, GRID, or SOLUTION).
- 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.
- auxdataset#
Buffered dataset-level auxiliary data, flushed before the first zone.
- auxvar#
Buffered variable-level auxiliary data, flushed before the first zone.
- __exit__(exc_type, exc_value, traceback)[source]#
Exit Write class context manager regardless of exceptions.
Only raise an exception if closing the file fails, not if an exception is raised in the with block.
- __init__(path, title='untitled', variables=None, file_type=FileType.FULL)[source]#
Store minimum necessary info until first zone is ready to write.
- flush_aux()[source]#
Write buffered dataset and variable aux data to the file.
Called automatically before the first zone is created. You only need to call this directly if you want to be explicit.
The C library requires dataset and variable aux data to be written after the file is intialized. Therefore in cases of lazy loading (buffered file info until first zone is defined), aux data is also buffered then flushed on first zone creation.
- 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.
Node and cell counts are inferred from node_map. The 32- or 64-bit write path is chosen automatically from the max index.
- Parameters:
data – Sequence of 1-D arrays, one per dataset variable. NODAL arrays must have length
num_nodes; CELL_CENTERED arrays must have lengthnum_cells.num_nodesandnum_cellsare inferred fromnode_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)containing 1-based node indices. 32- or 64-bit write is chosen automatically based on the maximum index value.title – Zone title string. Defaults to
"FE_Zone_{current_zone + 1}"if not provided.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. Defaults to all active (False).
var_sharing – Per-variable share from zone index. Defaults to no sharing.
con_sharing – Optional zone index that the connectivity is shared from Pass 0 to indicate no connectivity. You must pass 0 for the first zone in a dataset. Connectivity cannot be shared when face neighbor mode is set to global. Connectivity cannot be shared between cell-based and face-based finite element zones.
face_neighbors – Optional face-neighbor connectivity array.
num_face_consin the zone header is set tolen(face_neighbors)automatically when this is supplied.face_nbr_mode – Face-neighbor mode, used only when
face_neighborsis provided. Defaults to LOCAL_ONE_TO_ONE.solution_time – Solution time for transient data (0.0 = static).
strand_id – Strand ID for transient data (0 = static).
aux – Zone-level auxiliary data as
{name: value}strings.datapacking – Must be
BLOCK(the default).POINTis an ASCII-only layout and is not supported by the SZL binary format. Defined only for parity with ASCII writer.
- Raises:
NotImplementedError – For FEPOLYGON, FEPOLYHEDRON, or if datapacking is
POINT.ValueError – On variable count or array length mismatch.
ValueError – If I/O operation attempted on closed or None file handle.
RuntimeError – If attempting to write variable aux before variables are defined.
Note
FE variable arrays are 1-D and node-ordered — no axis-ordering considerations apply (unlike IJK zones).
write_datahandles dtype inference and F-order ravel internally; 1-D arrays are unaffected by memory order.
- 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.
Dimensions are inferred from the first array’s shape. Arrays may be 1-D, 2-D, or 3-D; missing trailing dimensions default to 1.
- Parameters:
data – One NumPy array per dataset variable. Array shape is used to infer
imax,jmax, andkmax; Fortran (column-major) order is assumed. PassNoneto write a zone header only.title – Zone title. Defaults to
"IJK_Zone_{current_zone + 1}".variables – Variable name list. Required on the first call when the file has not been opened yet (lazy-open path); ignored 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. Defaults to all active (
False).var_sharing – Per-variable share-from zone index (1-based). Defaults to no sharing (all zeros).
solution_time – Solution time for transient data. Use
0.0for static zones. Default to0.0if not defined.strand_id – Strand ID for transient data. Use
0for static zones. Default to0(static) if not defined.aux – Zone-level auxiliary data as
{name: value}string pairs.datapacking – Must be
BLOCK(the default).POINTis an ASCII-only layout and is not supported by the SZL binary format. Defined only for parity with ASCII writer.
- Raises:
NotImplementedError – If datapacking is
POINT.ValueError – If I/O operation attempted on closed or None file handle.
RuntimeError – If attempting to write variable aux before variables are defined.
Note
If the file is already open,
dataandvariablesmay be omitted to write a zone header only. If the file has not been opened yet,variablesmust be provided on this call.Note
Data arrays are written as DOUBLE precision by default. To write other types, cast the NumPy arrays before calling (e.g.
arr.astype(np.float32)).Note
Separate grid files (where all variables are cell-centred) are not handled automatically; use the low-level API for that case.