Skip to content

From a stored case to a dataset

Inspect a completed OpenFOAM case, export velocity and pressure, then package eligible Cartesian data as HDF5. StackNordic reads stored results; this example does not start a solver.

Prepare the input

Install StackNordic and provide an existing case containing system/controlDict, constant/ and stored U and p fields. Supported decomposed layouts can be read directly. For the packaging steps, the mesh must resolve to a verified Cartesian grid; cell-indexed data remains usable for analysis but cannot use this HDF5 packaging path.

Use a new or empty output directory. The example keeps the source case intact and leaves overwrite disabled. Run the following blocks in the same Python session.

Inspect the case

from pathlib import Path
import stacknordic as sno

case_dir = Path("cases/cavity")
dataset_dir = Path("datasets/cavity")
snapshot_dir = Path("datasets/cavity-snapshots")
case = sno.OpenFOAM.case(case_dir=case_dir)
print(case.reconstructed_times)
print(case.decomposed_times)

Replace case_dir with the completed case path. Inspection reports stored physical times. An active OpenFOAM runtime is needed only when the requested operation invokes an OpenFOAM utility; this example selects direct export of existing U and p.

Export U and p

dataset = case.export(
    output_dir=dataset_dir,
    fields={"U": ("Ux", "Uy", "Uz"), "p": "p"},
    times=None, mode="direct", dtype="float32", n_jobs=1, progress=True,
)
print(dataset.output_dir)

times=None selects every complete stored time. The output contains NumPy-compatible scalar arrays and info.json, which records times, components, precision and spatial layout. The logical velocity field remains U, with exported components Ux, Uy and Uz. See dataset export for explicit time and field selection.

Package Cartesian snapshots

Continue only when the exported manifest describes a verified Cartesian dataset:

snapshots = sno.Dataset.package(
    dataset_dir=dataset_dir, output_dir=snapshot_dir, name="cavity",
    fields={"U": "fields/U", "p": "fields/p"}, n_jobs=1, progress=True,
)

Each HDF5 snapshot contains fields/U, fields/p, grid axes and a StackNordic data contract. Scalar arrays use (z, y, x) order; velocity adds the final component axis. The package mapping uses logical U, rather than the individual exported component names.

Compile a time series

series = sno.Dataset.compile(
    dataset_dir=snapshot_dir, output_file=Path("datasets/cavity.h5"),
    pattern="cavity_id*.h5", progress=True,
)

The compiler validates snapshot contracts before publishing the combined file. Snapshot counts and values depend on the input case.

Continue with physical filtering when comparing DNS and LES data. If the case was generated by FoamNordic, follow the run-to-dataset workflow to obtain its completed case path.