Skip to main content
Version: 0.2.0

How NeuralFoil works

This page describes the model Bora evaluates. The design is Peter Sharpe's, and the authoritative account is the NeuralFoil paper (Sharpe and Hansman, 2025) together with the chapter on NeuralFoil in his thesis (Sharpe, 2024). What follows is a summary for users of Bora, with the exact transformations as Bora implements them in src/neuralfoil.rs.

A learned core inside a physical frame​

NeuralFoil is a neural network trained to reproduce XFoil (Drela, 1989). The network itself is small and ordinary. What makes the model work is the structure around it, which builds known aerodynamics into the calculation so that the network has less to learn and extrapolates sensibly. Sharpe describes the result as physics-informed machine learning, while noting that it is not a "PINN" in the usual sense of a network trained on the residual of a differential equation.

An analysis runs in five steps.

23 inputs: shape and operating point1. encode25 encoded valuesas givenmirror image2. network2. network3. subtract distance term3. subtract distance termmap back4. average the two5. decodelift, drag, moment, transition, confidence,momentum thickness, shape factor, edge velocity
One analysis. The dashed branch evaluates the mirror image, the shape flipped top to bottom at the negated angle of attack, which enforces the symmetry exactly.

Encoding​

The 23 user inputs become a vector of 25 numbers, the network's input. The 18 shape parameters pass through almost unchanged. The operating point is transformed:

Network inputComputed fromWhy
8 upper and 8 lower weights, leading-edge weightUnchanged
50 tTE50\,t_{TE}Trailing-edge thicknessBrings it to the same scale as the weights
sin⁡2α\sin 2\alphaAngle of attackProportional to lift in simple post-stall models
cos⁡α\cos\alphaAngle of attackCompletes a periodic description of the angle
sin⁡2α\sin^2\alphaAngle of attackProportional to drag in simple post-stall models
(ln⁡Re−12.5)/3.5(\ln Re - 12.5)/3.5Reynolds numberDrag follows power laws in ReRe, which are straight lines in ln⁡Re\ln Re
(Ncrit−9)/4.5(N_\mathrm{crit} - 9)/4.5Critical amplification factorCentered and scaled
xtr,ux_{tr,u}, xtr,lx_{tr,l}Forced transition locationsUnchanged

The scalings center typical inputs near zero with a spread near one, which helps training. The trigonometric encoding of the angle of attack makes the model periodic in α\alpha by construction: 0° and 360° are the same input. Taking the logarithm of the Reynolds number, together with the logarithm of the drag on the output side, means that a straight line in the network's coordinates is a power law in physical ones, which is what boundary-layer theory predicts for both laminar and turbulent skin friction.

The network​

The 25 inputs pass through a fully connected network to 198 outputs. Each hidden layer applies a weight matrix and bias and then the Swish activation,

σ(x)=x1+e−x.\sigma(x) = \frac{x}{1 + e^{-x}} .

Swish is smooth everywhere, so the whole model is infinitely differentiable, which is what makes its gradients useful to an optimizer. It also grows linearly for large arguments, so far from the training data the network tends toward a straight line rather than flattening out, which suits the logarithmic encodings above. The eight network sizes differ only in the number of hidden layers (2 to 6) and their width (48 to 512).

Symmetry​

Flip an airfoil top to bottom and negate the angle of attack, and the flow is the mirror image of the original: the lift and moment change sign, the drag does not, and the upper and lower surfaces trade places. A plain network would only learn this approximately.

NeuralFoil enforces it exactly. Every analysis evaluates the network twice, once for the airfoil as given and once for its mirror image at −α-\alpha, maps the second result back, and averages the two. In terms of the network ff and the mirror operations MinM_\mathrm{in} and MoutM_\mathrm{out},

zout=12[ f(zin)+Mout f(Min zin) ].z_\mathrm{out} = \tfrac{1}{2}\left[\, f(z_\mathrm{in}) + M_\mathrm{out}\, f(M_\mathrm{in}\, z_\mathrm{in}) \,\right] .

The average is symmetric by construction, whatever ff is. This is why a symmetric section at zero angle of attack returns exactly zero lift and moment. Bora evaluates the pair in a single pass over the weights, so the two evaluations cost less than twice one.

Decoding​

The 198 network outputs are six scalars followed by six boundary-layer distributions of 32 values each. They are converted to physical quantities as follows, writing zz for the corresponding network output.

QuantityDecoding
Analysis confidenceLogistic function of zz after the distance correction below
CLC_Lz/2z/2
CDC_Dexp⁡ ⁣(2 (z−2))\exp\!\big(2\,(z - 2)\big)
CMC_Mz/20z/20
Transition locationszz clipped to [0,1][0, 1]
Momentum thickness θ\theta10z−0.1∣ue/V∞∣  Re\dfrac{10^{z} - 0.1}{\lvert u_e/V_\infty\rvert\; Re}
Shape factor HH2.6 ez2.6\, e^{z}
Edge velocity ue/V∞u_e/V_\inftyzz

The exponential guarantees a positive drag coefficient. The momentum thickness is learned through a Reynolds number based on it, ReθRe_\theta, and the shape factor relative to its laminar flat-plate value of 2.6; in both cases the network predicts a quantity that varies far less across the training data than the raw one.

Confidence​

The first network output is a logit: the logarithm of the odds that XFoil would converge for this case. Before it is turned into a probability, a term is subtracted that grows with the distance of the query from the training data,

confidence=logistic⁡ ⁣(z0−(zin−μ)T S−1 (zin−μ)2N),N=25,\text{confidence} = \operatorname{logistic}\!\left( z_0 - \frac{(z_\mathrm{in} - \mu)^\mathsf{T}\, S^{-1}\, (z_\mathrm{in} - \mu)}{2 N} \right), \qquad N = 25 ,

where μ\mu and SS are the mean and covariance of the training inputs in the encoded space. The numerator is a squared Mahalanobis distance: a distance measured in units of the data's own spread along each direction.

Without this term nothing would force the confidence down far from the data, since a network's raw output can drift anywhere. With it, the confidence is guaranteed to tend to zero in every direction, because the quadratic eventually dominates the roughly linear growth of the logit. For a query drawn from the training distribution the term averages to 0.5, a small correction. The same term was present during training, so it does not distort the model inside the data.

Bora stores μ\mu and S−1S^{-1} in scaled_input_distribution.h5 and applies the correction to both of the mirrored evaluations before they are averaged.

Training​

Bora does not train anything; it uses NeuralFoil's published weights. For context, the paper reports the following.

  • Data. 7.9 million XFoil cases on synthetic airfoils, each made by blending three airfoils from a database of about 2,000, scaling the thickness and perturbing the Kulfan parameters. Angle of attack, Reynolds number, NcritN_\mathrm{crit} and forced transition were drawn at random. All cases are incompressible.
  • Convergence. 56% of the cases converged in XFoil. The rest were not used to train the physical outputs, but whether a case converged is exactly the label the confidence output learns.
  • Split. 95% of the data trained the networks; 5% was held back to measure the accuracies quoted in Choosing a network size.
  • Loss. A Huber loss on the encoded outputs, weighted most heavily toward drag. Sharpe notes that drag accuracy improved when the boundary-layer outputs were given some weight too, rather than training on drag alone.

What Bora adds​

Bora implements the five steps above so that they reproduce Python NeuralFoil 0.3.3, and it differentiates them. The forward-mode path carries a 23-column Jacobian through every layer alongside the values. The reverse-mode path propagates one adjoint per scalar output backward through the layers. Both are written by hand against the same kernels as the value computation; no automatic-differentiation library is involved. See Gradients.