API reference
Common
Cell types (MeshCell, VTKPolyhedron, VTKCellTypes, PolyData.*) and data locations (VTKPointData, VTKCellData, VTKFieldData) are re-exported from VTKBase.jl and are used for both writing and reading.
VTKHDF.VTKRowData — Type
VTKRowData()The data location of Table columns, usable wherever VTKPointData() etc. are: tbl["a", VTKRowData()] = col when writing, r["a", VTKRowData()] and keys(r, VTKRowData()) when reading.
Writing
File constructors
VTKHDF.vtkhdf_grid — Function
vtkhdf_grid(filename, points, cells; kwargs...)
vtkhdf_grid(filename, x, [y, [z]]; kwargs...)
vtkhdf_grid(filename, xyz::AbstractArray{T,4}; kwargs...)
vtkhdf_grid(dataset_type, filename, args...; kwargs...)
vtkhdf_grid(dataset_type, filename; kwargs...)Create a VTKHDF file for one of the grid dataset types. The type is inferred from the arguments (mirroring WriteVTK.jl). The last form — just a VTKUnstructuredGrid()/VTKPolyData() tag and no geometry — creates the file empty, so partitions can be appended one at a time with add_partition:
- UnstructuredGrid:
pointsandcells.pointsis a3×Nmatrix (smaller first dimensions are zero-padded), a vector of point-like objects, or a tuple of coordinate vectors;cellsis a vector ofMeshCell/VTKPolyhedron. - PolyData:
pointsplus one or more vectors ofMeshCells withPolyData.*cell types (e.g.PolyData.Polys()); each vector must contain a single category. On disk (and for cell data) cells are ordered Vertices, Lines, Polygons, Strips. - ImageData: 1–3
AbstractRanges (uniform spacing), orvtkhdf_grid(VTKImageData(), filename, dims; origin, spacing, direction, whole_extent). - RectilinearGrid: 1–3 coordinate
AbstractVectors, at least one of which is not a range (or the explicitVTKRectilinearGrid()tag). - StructuredGrid: a
(3, ni, nj, nk)coordinate array, or three(ni, nj, nk)arraysx, y, z.
Data arrays are written with vtk["name"] = data; the location is inferred from the size, or given explicitly as vtk["name", VTKCellData()] = data. Vector and tensor data uses the component-first convention ((3, N) for vectors, like WriteVTK.jl), or a vector of static vectors or tuples. The attribute keyword marks active attributes: vtk["u", VTKPointData(), attribute = :Vectors] = u.
Common keyword arguments:
temporal::Bool = false: open the file for time-dependent writing withwrite_timestep.compress = false:true(gzip level 6) or an integer level0-9.chunk_size = 0: override the automatic HDF5 chunk length along the append dimension.
All forms support a leading function for the do-block idiom, which closes the file afterwards. When filename has no extension, .vtkhdf is appended. Instead of a filename, (collection, blockname) can be passed to create the dataset as a block of a composite file (see vtkhdf_collection).
VTKHDF.vtkhdf_table — Function
vtkhdf_table(filename; temporal = false, compress = false, kwargs...)Create a VTKHDF Table file. Columns are written with tbl[name] = column where a column is a vector or a (ncomponents, nrows) matrix; all columns must have the same number of rows. For temporal tables, write columns inside write_timestep.
Supports the do-block form vtkhdf_table(fname) do tbl ... end.
VTKHDF.vtkhdf_amr — Function
vtkhdf_amr(filename; origin, grid_description = :XYZ, compress = false)Create a VTKHDF OverlappingAMR file. Levels are added with add_level and boxes with add_box:
vtkhdf_amr("amr"; origin = (0, 0, 0)) do amr
lvl = add_level(amr; spacing = (1.0, 1.0, 1.0))
add_box(lvl, (0, 4, 0, 4, 0, 4); celldata = ("ρ" => ρ,))
endTemporal AMR is not supported.
VTKHDF.vtkhdf_htg — Function
vtkhdf_htg(filename; dimensions, branch_factor = 2, kwargs...)Create a VTKHDF HyperTreeGrid file. dimensions is the number of coordinate points per direction. The number of trees is the product of max(nᵢ - 1, 1) over the directions, so a direction with a single coordinate contributes no trees. Pieces (partitions) are appended with add_piece.
Optional keywords: transposed_root_indexing::Bool, interface_normals_name, interface_intercepts_name.
Temporal HyperTreeGrid writing is not supported.
VTKHDF.vtkhdf_collection — Function
vtkhdf_collection(filename) -> collection
vtkhdf_multiblock(filename) -> collectionCreate a composite VTKHDF file: a PartitionedDataSetCollection, or a MultiBlockDataSet for vtkhdf_multiblock. Blocks are created with the usual constructors, passing (collection, name) instead of a filename, e.g. vtkhdf_grid(col, "mesh", points, cells). They behave like standalone files, temporal writing included, except that all temporal blocks must share the same time values. The block hierarchy is defined with add_node and add_block_ref; add_empty_block creates a type-less block.
Supports the do-block form. Closing the collection closes all blocks.
VTKHDF.vtkhdf_multiblock — Function
vtkhdf_multiblock(filename)Shorthand for vtkhdf_collection(filename; multiblock = true); see vtkhdf_collection.
Data arrays
Base.setindex! — Method
vtk["name"] = data
vtk["name", loc] = data
vtk["name", loc, attribute = :Scalars] = dataWrite a data array. Without a location the location is inferred from the array size; loc (VTKPointData(), VTKCellData(), VTKFieldData(), VTKRowData()) gives it explicitly. attribute (:Scalars, :Vectors, ...) marks the array as the location's active attribute. See the manual's Data arrays for the accepted array shapes.
Time series
VTKHDF.write_timestep — Function
write_timestep(f::Function, vtk, t::Real; geometry...)Write one time step with time value t to a temporal VTKHDF file. Data arrays are written inside the do-block with the same vtk[name] = data syntax used for static files.
With no geometry keyword arguments, the previous step's geometry is reused and stored only once. Passing new geometry (points/cells for unstructured grids, x/y/z for rectilinear grids, points for structured grids) appends it; this step and later ones then use it.
The set of data arrays (names, element types, component counts) must be the same for every step; it is fixed by the first step.
vtk = vtkhdf_grid("sim", points, cells; temporal = true)
for (t, u) in timesteps
write_timestep(vtk, t) do frame
frame["u"] = u
end
end
close(vtk)Partitions, levels and pieces
VTKHDF.add_partition — Function
add_partition(vtk, points, cells; pointdata = (), celldata = ()) # UnstructuredGrid
add_partition(vtk, points, cellvecs...; pointdata = (), celldata = ()) # PolyDataAppend one partition of geometry (and optionally its data) to an unstructured grid or poly data file (usually one created without geometry, via vtkhdf_grid(VTKUnstructuredGrid(), filename) / vtkhdf_grid(VTKPolyData(), filename)). For PolyData, pass one homogeneous cell vector per category, as in the constructor. For temporal files this must be called inside write_timestep (all partitions of a step must be supplied when its geometry changes); a file created without geometry can also add its initial partitions before the first step.
pointdata/celldata are iterables of name => data pairs whose lengths are validated against this partition. Alternatively, data for all partitions of a step can be written afterwards with vtk[name] = data using the concatenated arrays.
VTKHDF.add_level — Function
add_level(amr; spacing) -> levelAppend a refinement level (Level0, Level1, ...) with the given cell spacing to an OverlappingAMR file.
VTKHDF.add_box — Function
add_box(level, (imin, imax, jmin, jmax, kmin, kmax); pointdata = (), celldata = (), fielddata = ())Append one AMR box (inclusive cell extents) to a level. Data arrays are serialized per box, in the order boxes are added; sizes are validated against the box extents (imax - imin + 1 cells and imax - imin + 2 points per direction). Data can alternatively be written for a whole level at once with level[name, VTKCellData()] = data after adding its boxes.
VTKHDF.add_piece — Function
add_piece(
htg; descriptors, depth_per_tree, tree_ids,
number_of_cells_per_tree_depth, xcoordinates, ycoordinates,
zcoordinates, mask = nothing, celldata = ()
)Append one piece (partition) to a HyperTreeGrid file:
descriptors::AbstractVector{Bool}: refinement bits for each tree in turn, level by level within the tree (each tree's deepest level carries no bits); bit-packed MSB-first on disk. Each refined cell must have exactlybranch_factor^dimcells on the next level.depth_per_tree,tree_ids: depth and id of each tree in the piece.number_of_cells_per_tree_depth: cells per depth, tree by tree (sum(depth_per_tree)entries); its total is the piece's cell count.x/y/zcoordinates: tree coordinates for this piece (lengths matchingdimensions).mask: optionalAbstractVector{Bool}of length equal to the cell count, in descriptor cell order; refined cells cannot be masked.celldata: iterable ofname => arraypairs (HyperTreeGrids have no point data).
Composite assembly
VTKHDF.add_node — Function
add_node(col_or_node, name) -> nodeCreate a group node in the Assembly hierarchy of a composite file (under the root assembly, or nested under another node).
VTKHDF.add_block_ref — Function
add_block_ref(col_or_node, block)Reference a block from the Assembly hierarchy (a soft link named after the block). A block may be referenced from several nodes.
VTKHDF.add_empty_block — Function
add_empty_block(col, name) -> blockAdd a block with no dataset type to a composite file (a placeholder allowed by the spec). The returned handle can be referenced from the Assembly with add_block_ref.
Reading
Opening files and reading geometry
VTKHDF.vtkhdf_open — Function
vtkhdf_open(filename) -> reader
vtkhdf_open(f::Function, filename)Open a VTKHDF file for reading. Returns a VTKHDFReader for simple datasets or a VTKHDFCollectionReader for composite files (PartitionedDataSetCollection/MultiBlockDataSet); the reader must be closed (the do-block form does so automatically).
Data arrays are read by indexing (the location is found automatically, or passed explicitly): r["u"], r["u", VTKCellData()]. Geometry is read with read_points, read_cells and read_coordinates. Temporal files are read one step at a time via read_timestep.
See the manual for the full reading API (much of which — nsteps, time_values, grid_info, ... — is public but not exported).
VTKHDF.read_timestep — Function
read_timestep(r, i) -> stepA view of time step i (1-based) of a temporal file. The step supports the same data and geometry access as a static reader — step["u"], read_points(step), read_cells(step), ... — plus time_value. It holds no resources of its own (the parent reader must stay open).
VTKHDF.read_points — Function
read_points(r_or_step)Point coordinates: a 3 × N matrix for UnstructuredGrid/PolyData, a (3, ni, nj, nk) array for StructuredGrid.
VTKHDF.read_cells — Function
read_cells(r_or_step)The cells of an UnstructuredGrid (a vector of MeshCell/VTKPolyhedron with 1-based connectivity into read_points), or of a PolyData (a NamedTuple (; vertices, lines, polygons, strips) of MeshCell vectors). Multi-partition files are concatenated with point ids rebased; see partition_ranges for the partition structure.
VTKHDF.read_coordinates — Function
read_coordinates(r_or_step) -> (x, y, z)The coordinate vectors of a RectilinearGrid.
Data arrays
Base.getindex — Method
r["name"]
r["name", loc]Read a data array by name from a reader or a time step. Without a location the dataset's locations are searched (an ambiguous name throws); loc reads from that location only. Values come back as plain arrays in the writing shape convention (see Data arrays).
Base.getindex — Method
col[name] -> block readerOpen block name of a composite file. Typed blocks return a reader with the full reading API; type-less placeholder blocks return a handle whose dataset_type is nothing. Block readers share the collection's file handle and are invalidated when the collection is closed.
Metadata and structure
Unexported (call as VTKHDF.f):
VTKHDF.dataset_type — Function
dataset_type(r) -> StringThe VTKHDF dataset type of an open reader (the Type attribute), e.g. "UnstructuredGrid". For composite files, "PartitionedDataSetCollection" or "MultiBlockDataSet"; for an empty (type-less) composite block, nothing.
VTKHDF.file_version — Function
file_version(r) -> (major, minor)The VTKHDF specification version of the file (the Version attribute).
VTKHDF.is_temporal — Function
is_temporal(r) -> BoolWhether the file contains time-dependent data (a Steps group). Temporal data is read step by step with read_timestep.
VTKHDF.nsteps — Function
nsteps(r) -> IntNumber of time steps in a temporal file (is_temporal).
VTKHDF.time_values — Function
time_values(r) -> Vector{Float64}The time value of every step of a temporal file.
VTKHDF.time_value — Function
time_value(step) -> Float64The time value of a step obtained from read_timestep.
VTKHDF.grid_info — Function
grid_info(r) -> NamedTupleThe metadata attributes stored at the dataset root, per dataset type:
- ImageData:
(; dims, origin, spacing, direction, whole_extent) - RectilinearGrid, StructuredGrid:
(; dims, whole_extent) - OverlappingAMR:
(; origin, grid_description) - HyperTreeGrid:
(; dimensions, branch_factor, transposed_root_indexing)
UnstructuredGrid and PolyData store no such attributes and have no grid_info method.
VTKHDF.npoints — Function
npoints(r_or_step) -> IntTotal number of points (UnstructuredGrid, PolyData, ImageData, RectilinearGrid, StructuredGrid; also amr_level handles).
VTKHDF.ncells — Function
ncells(r_or_step) -> IntTotal number of cells (UnstructuredGrid, PolyData, ImageData, RectilinearGrid, StructuredGrid, HyperTreeGrid; also amr_level handles).
VTKHDF.nrows — Function
nrows(r_or_step) -> IntNumber of rows of a Table (for a temporal table: of one time step).
VTKHDF.npartitions — Function
npartitions(r_or_step) -> IntNumber of geometry partitions (UnstructuredGrid, PolyData).
VTKHDF.partition_ranges — Function
partition_ranges(r_or_step) -> NamedTupleThe index ranges of each partition into the concatenated point/cell data arrays. For UnstructuredGrid: (; points, cells), each a vector with one range per partition. For PolyData additionally cells_by_category: per partition, a (; vertices, lines, polygons, strips) NamedTuple of ranges into the cell-data arrays (on disk, PolyData cell data is partition-major with the categories in that order inside each partition). For an amr_level handle: (; points, cells) with one range per AMR box.
VTKHDF.active_attributes — Function
active_attributes(r, loc) -> Dict{Symbol, String}The active-attribute roles (:Scalars, :Vectors, ...) defined for the data-array group at loc, mapping role to array name. Both spec encodings are understood: group attributes (PointData attribute "Vectors" => "u") take precedence; per-array Attribute attributes (spec 2.6, matched case-insensitively) fill in roles the group does not define.
VTKHDF.data_attributes — Function
data_attributes(r, name, loc) -> Vector{Symbol}All active-attribute roles resolved to the array name at loc (see active_attributes).
VTKHDF.read_assembly — Function
read_assembly(col) -> AssemblyTreeNodeThe Assembly hierarchy of a composite file as a tree. Each node has name, children::Vector{AssemblyTreeNode} (nested assembly nodes) and blocks::Vector{String} (names of the blocks referenced from this node), both in creation order. The root node is named "Assembly".
VTKHDF.nlevels — Function
nlevels(r) -> IntNumber of refinement levels of an OverlappingAMR file.
VTKHDF.amr_level — Function
amr_level(r, l) -> levelThe refinement level l of an OverlappingAMR file, with l the on-disk level number in 0:nlevels(r)-1 (Level0 is the coarsest). The level supports level_info, keys(level, loc), data reading by indexing (level["ρ"], level["ρ", VTKCellData()] — arrays are concatenated over the level's boxes) and partition_ranges with one point/cell range per box.
VTKHDF.level_info — Function
level_info(level) -> (; spacing, boxes)Spacing and AMR boxes (inclusive cell extents (imin, imax, jmin, jmax, kmin, kmax)) of an amr_level.
VTKHDF.npieces — Function
npieces(r) -> IntNumber of pieces (partitions) of a HyperTreeGrid file.
VTKHDF.htg_piece — Function
htg_piece(r, p) -> NamedTuplePiece p (1-based) of a HyperTreeGrid file, as the exact inverse of add_piece: a NamedTuple with descriptors::Vector{Bool}, tree_ids, depth_per_tree, number_of_cells_per_tree_depth, xcoordinates/ycoordinates/zcoordinates, mask::Union{Nothing, Vector{Bool}} and celldata::Dict{String, Any} (this piece's slice of every cell-data array).
Module
VTKHDF.VTKHDF — Module
VTKHDFWrite and read VTK data in the VTKHDF file format (HDF5-based, spec version 2.x). Supports static and temporal data for all basic VTK dataset types and composite datasets.
Main entry points for writing: vtkhdf_grid, vtkhdf_table, vtkhdf_amr, vtkhdf_htg, vtkhdf_collection, vtkhdf_multiblock and write_timestep; for reading: vtkhdf_open and read_timestep.