phipict.io.domain_io

Saving and loading of multi-block domains to/from .json + .npz files.

A domain is stored as a pair of files next to each other, <name>.json (the structure: blocks, boundaries and settings) and <name>.npz (the tensors, referenced by index from the JSON). Both functions take the path of the pair without the extension, as a pathlib.Path:

save_domain(domain, Path("runs/case/domain"))  # domain.json + domain.npz
domain = load_domain(Path("runs/case/domain"), dtype=torch.float64)

Saving is atomic per file and the two files carry a shared id, so a save that was interrupted (e.g. a killed job checkpointing) is detected on load instead of silently mixing an old structure with new tensors.

Module Attributes

FORMAT_VERSION

Version of the file layout written by save_domain().

Functions

bound_idx_to_str(idx)

Convert a boundary index to its face string.

boundary_condition_string_to_type(bound_type)

Convert a boundary condition name to its type.

boundary_condition_type_to_string(bound_type)

Convert a boundary condition type to its name.

dtype_to_string(dtype)

Convert a saved tensor's dtype to its name.

load_domain(path[, dtype, device, with_scalar])

Load a domain saved with save_domain().

save_domain(domain, path)

Save a domain to <path>.json and <path>.npz.