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 ( −2° to 8°, 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
The aircraft gives (56, 2000, 1) for 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.
| run | x | y | z | (°) | (°) | |
|---|---|---|---|---|---|---|
| 0 | 1.92 | 0.31 | 0.12 | 6.03 | 30.25 | -0.84 |
| 0 | 1.95 | 0.33 | 0.12 | 6.03 | 30.25 | -0.61 |
| 0 | 2.03 | 0.36 | 0.11 | 6.03 | 30.25 | -0.22 |
| 1 | 1.92 | 0.31 | 0.12 | 6.33 | 24.14 | -0.47 |
| 1 | 1.95 | 0.33 | 0.12 | 6.33 | 24.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).
# 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)
load_runsdownloads 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.cpalready has the shape (runs, points);[:, :, None]adds the channel axis, so one channel gives the shape(56, 2000, 1).np.repeatwrites each run’s id once per point: the 2,000 rows of run 0, then those of run 1, and so on.xyzhas 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.- Flattening
Yruns 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.