From runs to arrays

Each simulation becomes rows of numbers: inputs X, outputs Y, and a run id on every row.

Outcome: Arrange scalar results as X (runs × parameters) and Y (runs × outputs); store fields as (runs × points × channels), or as one array per run when meshes differ; build the point-wise table that neural fields train on, with a run id on every row; check that the inputs determine the target: everything the solver was given that varies between runs.

Builds on Physical fields

Every run is first turned into arrays with a fixed layout: its inputs (the design parameters and operating conditions chosen) and its outputs (what the solver returned). NumPy arrays are the common format: scikit-learn and PyTorch both read them directly.

The course’s aircraft comes as two datasets of one solver. The interactive figures run a network trained and validated on 44 runs of 7,952 surface points. The listings use the download, aircraft-runs.npz (about 1 MB): 56 runs on 2,000 surface points, the same 44 designs, placed by a Latin hypercube (a design that spreads runs evenly over the box, sampling the design space), 36 for training and 8 for validation, and 12 test runs, 4 inside the training box (α\alpha −2° to 8°, Λ\Lambda 20° to 36°) and 8 outside. The shapes below are the download’s.

Scalars and fields

For scalar outputs, the runs are stacked as rows: X has shape (n_runs, n_params) and Y has shape (n_runs, n_outputs), and row i of both is the same run. The aircraft gives X of shape (56, 2), angle of attack and sweep, and Y of shape (56, 1) for the lift coefficient.

When every run uses the same mesh (same points, in the same order), fields stack into Y of shape (n_runs, n_points, n_channels), one channel per scalar quantity or vector component.

DefinitionChannel

One number stored at every point: a scalar quantity such as CpC_p, or one component of a vector such as the wall shear stress.

The aircraft gives (56, 2000, 1) for CpC_p alone. A viscous solver that also writes three wall-shear components would give (56, 2000, 4).

When each design is meshed on its own, the points differ from run to run, and the arrays cannot be stacked. The runs are kept as a list, with one array of shape (n_points_i, n_channels) per run. How networks deal with that is the subject of grids, meshes and point clouds.

The point-wise table

Some models, such as the neural field, learn from one point at a time. For them, the fields are flattened into a long table with one row per point per run: where the point is, which design it belongs to, and the value there. The aircraft gives 56 × 2,000 = 112,000 rows. Table 2-1 shows a few of them.

Table 2-1. A few rows of the aircraft’s point-wise table. The design columns are the first two runs; the point values are for illustration.
runxyzα\alpha (°)Λ\Lambda (°)CpC_p
01.920.310.126.0330.25-0.84
01.950.330.126.0330.25-0.61
02.030.360.116.0330.25-0.22
11.920.310.126.3324.14-0.47
11.950.330.126.3324.14-0.38
… 111,995 more rows

Example 2-2 starts the file of functions, aircraft.py, that later listings import from, then builds the arrays and the point-wise table from the download. The listings need Python 3.10 or later and pip install torch numpy scipy scikit-learn (PyTorch 2, SciPy 1.15, scikit-learn 1.4 or later).

Example 2-2. The start of aircraft.py: the runs as arrays, then as a point-wise table, with NumPy
# aircraft.py: the course's running example. Later listings
# add functions to this file and import from it.
import os
import urllib.request

import numpy as np

URL = "https://surrogatemodels.com/downloads/aircraft-runs.npz"
FILE = "aircraft-runs.npz"

def load_runs(path=FILE):
    """The 56 solver runs of the aircraft, as NumPy arrays."""
    if not os.path.exists(path):1
        req = urllib.request.Request(
            URL, headers={"User-Agent": "surrogate-course"})
        with urllib.request.urlopen(req) as r, \
                open(path, "wb") as f:
            f.write(r.read())
    return dict(np.load(path))

# Then, in a script or notebook next to aircraft.py:
import numpy as np
from aircraft import load_runs

d = load_runs()
for name, a in d.items():
    print(name, a.shape)

# X: alpha and sweep of each run. Y: (runs, points, channels).
X = np.column_stack([d["alpha"], d["sweep"]])
Y = d["cp"][:, :, None]2
print(X.shape, Y.shape)  # (56, 2) (56, 2000, 1)

# The point-wise table: one row per point per run.
n_runs, n_pts, _ = Y.shape
table = np.column_stack([
    np.repeat(np.arange(n_runs), n_pts),  # run id3
    d["xyz"].reshape(-1, 3),              # x, y, z4
    np.repeat(X, n_pts, axis=0),          # alpha, sweep
    Y.reshape(-1, 1),                     # cp5
])
print(table.shape)  # (112000, 7)
  1. load_runs downloads the file the first time and reads it from disk after that. dict(np.load(path)) reads every array into memory, so nothing returned depends on the open file.
  2. cp already has the shape (runs, points); [:, :, None] adds the channel axis, so one channel gives the shape (56, 2000, 1).
  3. np.repeat writes each run’s id once per point: the 2,000 rows of run 0, then those of run 1, and so on.
  4. xyz has the shape (56, 2000, 3): the points move with the sweep, so each run keeps its own coordinates. reshape(-1, 3) lays them out run after run, in the order of the other columns.
  5. Flattening Y runs through the points of run 0, then run 1, in the same order again, so each row of the table describes one point of one run.

Example 2-2 prints the shape of every array in the file: alpha, sweep, split and CL (56,), one value per run; xyz and normal (56, 2000, 3); cp and area (56, 2000), one value per point (area is the surface each point stands for); and S_ref (1,), the reference area. The table has 56 × 2,000 = 112,000 rows of seven columns. split marks each run: 0 for training, 1 for validation, 2 for test.

The inputs must determine the target

Which inputs belong in X is a separate question from the layout, with one test: the columns of X must determine Y. A problem is called well-posed, in the sense due to Hadamard, when a solution exists, is unique and depends continuously on the data (Evans 2010, section 1.3). A solver’s data are the problem as posed: the geometry, the boundary conditions with the values they prescribe (inlet velocity, outlet pressure, wall temperature, loads and supports), the initial state of a transient run, and the properties of the medium (density, viscosity, stiffness). A surrogate stands in for the map from those data to the field, so it can be a function only if its inputs carry everything in them that varies between runs.

Of everything the solver was given, what varies between runs goes into X. What is fixed can stay out, and is recorded with the dataset, since the model then holds only under those conditions.

In a dataset, two runs with the same inputs and different fields usually mean that an input is missing: an inlet speed, an enclosure, a boundary condition or a fluid property that varied. No model can fit both runs; the fix is to add the input, or to find out why it varied. The exception is a problem that is not well-posed in the first place, such as a crash run that can fold in two ways: that scatter is real, and stays in the data (see Structures and crash data, below).

From solver files to arrays

Solvers write their own formats. Flow (CFD) results usually come as VTK, CGNS, EnSight or OpenFOAM case folders. Finite-element analysis (FEA, the standard way to simulate stresses and deformation in solid parts) gives Nastran .bdf and .op2, Abaqus .inp and .odb (model, then results), or LS-DYNA d3plot files.

meshio and PyVista read the common ones into NumPy arrays of point coordinates and point data; pyNastran reads Nastran files, and Abaqus .odb files are normally read with Abaqus’s own Python.

A point has to be defined. Most finite-volume CFD solvers store values at cell centres (some at the mesh vertices). A finite-element solver computes displacement at nodes, and stress, strain and plastic strain at integration points inside each element; what it writes depends on the output request. Integration-point values are extrapolated to the nodes and averaged, or kept per element, and the dataset states which; averaging across a change of material or thickness smears a real jump. Each point keeps its cell area or volume: Equation 3-3 weights errors by it.

Structures and crash data

  • Shells. Shell thickness and material are inputs per element, so they become input channels like the coordinates. Stress varies through the thickness, so the section kept (top, middle or bottom) has to be stated.
  • Peak stress. At a sharp re-entrant corner or a point load, a linear-elastic peak keeps rising as the mesh is refined, so it does not converge (Williams 1952). The training target should be a stress that does: at a real fillet radius, or a linearised or averaged value at a set distance.
  • Crash. Outputs are often time histories (intrusion, deceleration pulse), usually filtered with the channel frequency classes (CFC) of SAE J211 before training. Explicit runs can bifurcate: two near-identical designs can fold differently, and even repeats of one model need not match exactly (Mei and Thole 2005; Chaillou et al. 2026). That is scatter in the data, not noise to fit away.
  • Vibration. Modes are matched between designs by their shape (the modal assurance criterion, MAC), not by their order: the order can swap from one design to the next, and a model trained on ordered modes learns the swap as a jump.

Check yourself

  1. 1In a shape study every run has its own mesh, from 7,900 to 8,300 surface points. How should the fields be stored?
  2. 2A point-wise table has columns x, y, z, α, Λ, Cp. The rows are shuffled and 20 % held out for testing. Why is the test error not to be trusted?
  3. 3In the lesson’s code, the 56 downloaded runs of 2,000 surface points each become the point-wise table. What is its shape?
Two runs of a dataset have the same geometry and the same inputs, yet different fields. What does that indicate?

Most likely an input is missing: something the solver was given varied between them, such as the inlet speed, the enclosure, a boundary condition or a fluid property. No model can fit both runs. Add it as an input, or find out why it varied. If nothing varied, the problem itself has more than one outcome, as a crash run that can fold in two ways, and the scatter stays in the data.

Exercises

  1. Exercise 2-1. Load aircraft-runs.npz with load_runs(). Check that cp[i] and area[i] line up point for point with xyz[i], then count the rows of the point-wise table before printing it.

    Answer

    cp and area are (56, 2000) and xyz is (56, 2000, 3): the same run and point axes, so point j of run i has its pressure, area and position at index [i, j]. The table has one row per point per run, 56 × 2,000 = 112,000 rows.

  2. Exercise 2-2. Compute the lift of run 0 from cp, area and normal with the panel sum of the fields lesson, in the lift direction, perpendicular to the flow (nL = normal[..., 1] cos α − normal[..., 0] sin α), and compare it with CL[0].

    Answer

    It gives 0.563 against a stored 0.609: about 0.05 low, and 0.06 on average over the 56 runs. The site’s simple solver computes the lift with a vortex lattice and the surface Cp separately, strip by strip, so the two are not one consistent solution; compare models with each other on the integrated lift, not with the stored CL.

Go further