Gamut

Keeps a study and its fitted models in open files with units, meshes and definitions intact.

Open source · Apache 2.0

Python

$ cat read_cp.py
import gamut
s = gamut.open("capsules.gamut")
r = s.select("split == test")
cp = s.get_field("cp", rows=r)
print(cp.shape)
for v in cp[4, :3]:
    print(f"{v:.17g}")
$ python read_cp.py
(21, 7106)
1.6174062238055535
1.3308219605178968
1.325393076320601

MATLAB

$ cat read_cp.m
s = gamut.open('capsules.gamut');
r = s.select('split == test');
cp = s.getField('cp', 'rows', r);
disp(size(cp))
fprintf('%.17g\n', cp(5, 1:3))
$ matlab -batch read_cp
          21        7106

1.6174062238055535
1.3308219605178968
1.325393076320601

Julia

$ cat read_cp.jl
using Gamut, Printf
s = Gamut.open("capsules.gamut")
r = Gamut.select(s, "split == test")
cp = Gamut.get_field(s, "cp"; rows=r)
println(size(cp))
for v in cp[5, 1:3]
    @printf("%.17g\n", v)
end
$ julia read_cp.jl
(21, 7106)
1.6174062238055535
1.3308219605178968
1.325393076320601

C++

$ cat read_cp.cpp
#include <cstdio>

#include <gamut/gamut.hpp>

int main() {
  auto s = gamut::open("capsules.gamut");
  auto r = s.select("split == test");
  auto cp = s.get_field("cp", r);
  std::printf("%lld x %lld\n", (long long)cp.shape[0], (long long)cp.shape[1]);
  for (int k = 0; k < 3; ++k) std::printf("%.17g\n", cp(4, k));
}
$ ./read_cp_cpp
21 x 7106
1.6174062238055535
1.3308219605178968
1.325393076320601

C

$ cat read_cp.c
#include <stdio.h>
#include <stdlib.h>

#include <gamut/gamut.h>

static gamut_error err;
#define CHECK(call) if ((call) != 0) { fprintf(stderr, "%s\n", err.message); return 1; }

int main(void) {
  gamut_file* f;
  int64_t rows[301], n, shape[4];  /* room for the file's 301 runs */
  int rank;
  CHECK(gamut_open("capsules.gamut", &f, &err));
  CHECK(gamut_select(f, "split == test", rows, 301, &n, &err));
  const gamut_sel r = {GAMUT_SEL_INDEX, 0, 0, rows, n};
  CHECK(gamut_shape(f, "cp", &r, NULL, &rank, shape, 4, &err));
  int64_t bytes = (int64_t)sizeof(double) * shape[0] * shape[1];
  double* cp = malloc(bytes);  /* runs x nodes, in C order */
  CHECK(gamut_read(f, "cp", &r, NULL, GAMUT_FLOAT64, cp, bytes, &err));
  printf("%lld x %lld\n", (long long)shape[0], (long long)shape[1]);
  for (int k = 0; k < 3; ++k) printf("%.17g\n", cp[4 * shape[1] + k]);
  return gamut_close(f, &err);
}
$ ./read_cp_c
21 x 7106
1.6174062238055535
1.3308219605178968
1.325393076320601

Rust

$ cat read_cp.rs
fn main() -> Result<(), gamut::Error> {
    let s = gamut::open("capsules.gamut")?;
    let r = s.select("split == test")?;
    let cp = s.get_field("cp", &r, ..)?;
    println!("{:?}", cp.shape);
    for k in 0..3 {
        println!("{}", cp[[4, k]]);
    }
    Ok(())
}
$ ./read_cp_rs
[21, 7106]
1.6174062238055535
1.3308219605178968
1.325393076320601
The run the six programs print, drawn on its own mesh: cp of row 4 of capsules.gamut, 7106 nodes, colored from 0 to 2, darker for higher. The forebody, facing the flow, is dark; the sheltered afterbody is pale at cp 0 (engineering-level modified Newtonian pressure, not CFD).

The same values from Python, MATLAB, Julia, C++, C and Rust: one program in each language reads the same file, selects the same runs and prints the field's shape and the same three values, every digit equal. Beside them, the run they print, drawn on its own 7106-node mesh: cp of row 4 of capsules.gamut. The data are engineering-level (modified Newtonian pressure), not CFD. GitHub · PyPI

Features.

Read only the runs, nodes or regions you need.

Select runs with a query, and read one field for just those runs, or for a few nodes of them.

>>> import gamut
>>> s = gamut.open("capsules.gamut")
>>> s.row_count
301
>>> r = s.select("split == test and alpha == 20")
>>> r
array([ 4, 18, 39])
>>> s.get_field("cp", rows=r, nodes=[0, 1, 2])
array([[1.61740622, 1.33082196, 1.32539308],
       [1.61740623, 1.41956438, 1.4215723 ],
       [1.61740595, 0.75793199, 0.8774544 ]])

Measured against Exodus II, CGNS and PhysicsNeMo-Mesh.

File size and read time on a capsule family and an airfoil sweep. The benchmarks also list the workloads where another approach is faster. All the benchmarks

File size and read times of Exodus II, CGNS and PhysicsNeMo-Mesh relative to Gamut, for a triangulated capsule family and an XFOIL airfoil sweep. Every format uses the same mesh within each dataset.

The Gamut file is the smallest in both datasets (compressed Exodus II is 3.0% larger on the capsule family) and reads one capsule run fastest. On the small airfoil sweep, PhysicsNeMo-Mesh reads faster, and Exodus II and CGNS select runs by condition faster. On the capsule family, PhysicsNeMo-Mesh reads one node across every run faster than Gamut on one thread.

The format.

Studies
Runs over design parameters and operating conditions, each with single-number results and, optionally, fields on a mesh.
Time series
A row is one run, or one saved time step of a run.
Meshes
No mesh; one mesh shared by every run, so node k is the same point in every run; or a mesh per run, or per geometry of a family.
Units
Every parameter and result carries its units. Units that do not parse are refused.
Relationships
A result can declare that it is the uncertainty of another (a standard deviation or a quantile) or its derivative with respect to a parameter or to node position.
Portion marking
A file can carry its author's marking. Extracts and copies keep it, appending refuses rows marked otherwise, and a reader is asked to show it whole when the file opens.
Models
Model files hold definitions and state as plain data, without executable code. Declared inputs and outputs can be read without the model's implementation; evaluating it needs an implementation of the recorded model type.
Array orientation
Gamut reads a field as runs × nodes in every language. MATLAB's own ncread returns the same array with its axes reversed.
One core, six languages
Python, MATLAB, Julia, C++, C and Rust read and write through one core, so each reads what another wrote, value for value, and a refusal names the same rule in every language.
Specification
A published specification defines every structure and numbered rule, and the files are HDF5 laid out as netCDF-4, so h5py, xarray and the netCDF tools read them too. The specification

Facts.

Languages
Python 3.11 or later, MATLAB R2023b or later, Julia 1.10 or later, C++17 and C, Rust 1.70 or later.
Install
pip install bijective-gamut, then import gamut. MATLAB, Julia, C, C++ and Rust are in the installation guide.
Storage
HDF5, as netCDF-4.
License
Apache 2.0, open source.

Documentation

Install, examples and the specification.

Step-by-step examples in each language.

Dataset

A whole study in one file.

1024 heat shields on one shared mesh, in a single 55 MB Gamut file.