Metadata-Version: 2.4
Name: vcti-reader-converge-h5
Version: 0.1.0
Summary: Converge CFD post-file reader: the files of a run found and ordered by the output time each records, and per file its boundary table, streams, polyhedral face topology, cell-centered variables and parcels, read from HDF5 only when asked
Author: Visual Collaboration Technologies Inc.
License-Expression: LicenseRef-Proprietary
Project-URL: Repository, https://github.com/vcollab/vcti-python-reader-converge-h5
Project-URL: Changelog, https://github.com/vcollab/vcti-python-reader-converge-h5/blob/main/CHANGELOG.md
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Requires-Dist: h5py>=3.10
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: lint
Requires-Dist: ruff; extra == "lint"
Provides-Extra: typecheck
Requires-Dist: mypy; extra == "typecheck"
Dynamic: license-file

# Converge H5 Reader

Converge CFD post-file reader: the files of a run found and ordered by the output time each records, and per file its boundary table, streams, polyhedral face topology, cell-centered variables and parcels, read from HDF5 only when asked

## Overview

Converge writes its results as one HDF5 post file per output step. Each
file records the step in its root attributes, holds a boundary table, and
one or more **streams**: a polyhedral mesh whose faces are polygons, each
face naming the two cells it separates or, on a boundary, the one cell it
bounds and the boundary it lies on. A stream carries **cell-centered
variables**, one value per cell, with vectors stored as `_X`, `_Y` and
`_Z` components, and **parcels**: points with variables of their own,
their position among them.

This package does two things. It finds the files of a run from a path, a
list of paths or a glob pattern, checks they belong to the same run, and
orders them by the output time each file records, never by its name. And
it opens one file and exposes its structure as it is: the step attributes,
the boundaries, the streams and their variables, with every array read
from the file only when a caller asks for it, whole or by rows. It does
not build a cell connectivity, extract surfaces, average values or convert
anything; those are the jobs of whatever consumes it.

## Installation

```bash
pip install vcti-reader-converge-h5
```

### In `requirements.txt`

```
vcti-reader-converge-h5>=0.1.0
```

### In `pyproject.toml` dependencies

```toml
dependencies = [
    "vcti-reader-converge-h5>=0.1.0",
]
```

---

## Quick Start

The snippets below use the synthetic post file the package ships, written
with the same layout as a real one. Replace the paths with real files and
nothing else changes.

### Find the files of a run

```python
from vcti.reader.converge.h5 import open_series, write_synthetic

for step, time in ((1, 0.0), (2, 0.5), (3, 1.0)):
    write_synthetic(f"post{step:06d}.h5", output_time=time)

series = open_series("post*.h5")  # a path, several paths, or a pattern
print(series.abscissa, series.version, series.stream_ids)  # time (3, 0, 1) ('00', '01')
print([s.output_time for s in series.sources])  # [0.0, 0.5, 1.0]
```

The files are ordered by the `OUTPUT_TIME` each records, which is a time or,
when the run's `CRANK_FLAG` is set, a crank angle; `series.abscissa` says
which. Every file must agree on the Converge version, the crank flag, the
stream ids and the boundary table, or `open_series` raises naming the file
that does not.

### Open a step

```python
from vcti.reader.converge.h5 import ConvergeH5Reader

with ConvergeH5Reader(series.paths[-1]) as post:
    print(post.output_time, post.crank_flag, post.version)  # 1.0 False (3, 0, 1)
    print(post.stream_ids)  # ['00', '01']
    for boundary in post.boundaries:
        print(boundary.id, boundary.name, boundary.stream_id, boundary.num_elements)
```

Stream ids are kept exactly as the file spells them. `post.attributes` holds
every root attribute, each unwrapped from its one-element array.

### Read a stream's mesh

```python
with ConvergeH5Reader(series.paths[-1]) as post:
    stream = post.stream("00")
    print(stream.num_vertices, stream.num_faces, stream.num_cells)  # 12 11 2

    offsets = stream.face_offsets()  # num_faces + 1 offsets into face_vertices
    first_face = stream.face_vertices(slice(offsets[0], offsets[1]))
    print(first_face, stream.vertices(first_face[:1]))
```

Every array accessor takes `rows`: a slice or an increasing index array over
the first axis, or nothing for the whole array. Only those rows are read.

### Find the faces on each boundary

```python
with ConvergeH5Reader(series.paths[-1]) as post:
    stream = post.stream("00")
    ids = stream.face_boundary_ids()  # one read: boundary id per face, -1 inside
    print(ids.tolist())  # [0, 1, -1, 2, 2, 2, 2, 2, 2, 2, 2]
    walls = stream.boundary("walls (ID = 1)")
    print(len(stream.boundary_faces(walls)), walls.num_elements)  # 8 8
```

A boundary face has the boundary's `face_marker`, `-(id + 1)`, in one of
its two `face_cells` entries; the other entry is the cell it bounds. A
boundary the table lists with no faces is kept, and has none.

### Read cell-centered variables

```python
with ConvergeH5Reader(series.paths[-1]) as post:
    stream = post.stream("00")
    print(stream.cell_scalars, stream.cell_vectors)  # ['IDREG', 'PRESSURE'] ['VELOCITY']
    pressure = stream.cell_values("PRESSURE")  # one value per cell
    velocity = stream.cell_vector("VELOCITY", slice(0, 1))  # (1, 3), components stacked
    print(pressure, velocity)
```

### Read parcels

```python
with ConvergeH5Reader(series.paths[-1]) as post:
    stream = post.stream("00")
    if stream.has_parcels:
        print(stream.num_parcels, stream.parcel_scalars, stream.parcel_vectors)
        print(stream.parcel_positions(slice(0, 1)), stream.parcel_values("RADIUS")[0])
```

A stream that wrote no parcels at a step still lists the parcel variables
and holds empty datasets; `has_parcels` is then `False`.

---

## Key API

| Name | What it does |
|---|---|
| `open_series(sources)` | Find, validate and order the files of one run; a `Series` with `sources`, `paths`, `abscissa`, `version`, `stream_ids`, `boundaries` |
| `find_sources(sources)`, `probe(path)` | The same without the same-run check; one `Source` per file |
| `ConvergeH5Reader(path)` | Open a post file; a context manager with `output_time`, `crank_flag`, `version`, `attributes`, `boundaries`, `streams`, `stream(id)` |
| `Stream` | One stream: `vertices()`, `face_offsets()`, `face_vertices()`, `face_cells()`, `face_boundary_ids()`, `boundary_faces()`, `cell_values()`, `cell_vector()`, `parcel_positions()`, `parcel_values()` |
| `Boundary` | One row of the boundary table: `id`, `name`, `stream_id`, `num_elements`, `face_marker` |
| `split_variables(names)` | The scalar/vector split a name list implies |
| `write_synthetic(path)` | A small post file in the same layout, for tests and examples |

---

## Dependencies

- `numpy`
- `h5py`, which opens the file and reads the rows an accessor asks for.

---

## Documentation

| If you want to… | Read |
|---|---|
| Get started using the package | Quick Start above |
| Understand the file model, what is lazy and why | [docs/design.md](docs/design.md) |
| Navigate and understand the source | [docs/source-guide.md](docs/source-guide.md) |
