NeuralFoil
NeuralFoil is a practical airfoil aerodynamics analysis tool using physics-informed machine learning, exposed to end-users in pure Python/NumPy.
Install / Use
/learn @peterdsharpe/NeuralFoilREADME
by Peter Sharpe (<pds [at] mit [dot] edu>)
NeuralFoil is a tool for rapid aerodynamics analysis of airfoils, similar to XFoil. NeuralFoil is a hybrid of physics-informed machine learning techniques and analytical models, leveraging domain knowledge. Its learned core is trained on tens of millions of XFoil runs.
NeuralFoil is available here as a pure Python+NumPy standalone (trained in PyTorch, runtime-executed in NumPy), but it is also available within AeroSandbox, which extends it with advanced features. With this extension, NeuralFoil can give you viscous, compressible airfoil aerodynamics for (nearly) any airfoil, with control surface deflections, across $360^\circ$ angle of attack, at any Reynolds number, all very quickly (~5 milliseconds). And, it's guaranteed to return an answer (no non-convergence issues), it's vectorized, and it's $C^\infty$-continuous (critical for gradient-based optimization). For aerodynamics experts: NeuralFoil will also give you fine-grained boundary layer control ($N_{\rm crit}$, forced trips) and information ($\theta$, $H$, $u_e/V_\infty$, and pressure distributions).
A unique feature is that NeuralFoil also assesses its own trustworthiness, yielding an "analysis_confidence" output: queries where flow is sensitive or strongly out-of-distribution are flagged. This is especially useful for design optimization, where constraining this uncertainty metric ensures designs are robust to small changes in shape and flow conditions.
NeuralFoil is ~30x faster than XFoil for a single analysis, and ~1000x faster for multipoint analysis, all with minimal loss in accuracy compared to XFoil. Due to the diversity of training data and the embedding of several physics-based invariants, this accuracy is seen even on out-of-distribution airfoils (i.e., airfoils it wasn't trained on). More comparisons to XFoil are here. NeuralFoil aims to be lightweight, with minimal dependencies and a small and easily-understood code-base (<500 lines of user-facing code).
pip install neuralfoil

(The above figure is an excerpt from the author's PhD thesis)
For example usage of NeuralFoil, see here.
For more technical details, validation cases, and case studies, see the pre-print of the NeuralFoil paper. (Citation info here).
Overview
NeuralFoil comes with 8 different neural network models, with increasing levels of complexity:
<div align="center"> <table> <tr> <td>"xxsmall"</td> <td>"xsmall"</td> <td>"small"</td> <td>"medium"</td> <td>"large"</td> <td>"xlarge"</td> <td>"xxlarge"</td> <td>"xxxlarge"</td> </tr> </table> </div>This spectrum offers a tradeoff between accuracy and computational cost.
In addition to its neural network models, NeuralFoil also has a bonus "Linear $C_L$ model" that predicts lift coefficient $C_L$ as a purely-affine function of angle of attack $\alpha$ (though it is not affine with respect to the shape variables). This model is well-suited for linear lifting-line or blade-element-method analyses, where the $C_L(\alpha)$ linearity can be used to solve the resulting system of equations "in one shot" as a linear solve, rather than a less-numerically-robust iterative nonlinear solve.
Using NeuralFoil is dead-simple, and also offers several possible "entry points" for inputs. Here's an example showing this:
import neuralfoil as nf # `pip install neuralfoil`
import numpy as np
aero = nf.get_aero_from_dat_file( # You can use a .dat file as an entry point
dat_file_path="/path/to/my_airfoil_file.dat",
alpha=5, # Angle of attack [deg]
Re=5e6, # Reynolds number [-]
model_size="xlarge", # Optionally, specify your model size.
)
aero = nf.get_aero_from_coordinates( # You can use xy airfoil coordinates as an entry point
coordinates=n_by_2_numpy_ndarray_of_airfoil_coordinates,
alpha=np.linspace(-25, 25, 1000), # Vectorize your evaluations across `alpha` and `Re`
Re=5e6,
)
import aerosandbox as asb # `pip install aerosandbox`
aero = nf.get_aero_from_airfoil( # You can use AeroSandbox airfoils as an entry point
airfoil=asb.Airfoil("naca4412"), # any UIUC or NACA airfoil name works
alpha=5, Re=5e6,
)
# `aero` is a dictionary with keys: ["analysis_confidence", "CL", "CD", "CM", "Top_Xtr", "Bot_Xtr", ...]
Performance
Accuracy
Qualitatively, NeuralFoil tracks XFoil very closely across a wide range of $\alpha$ and $Re$ values. In the figure below, we compare the performance of NeuralFoil to XFoil on $C_L, C_D$ polar prediction. Notably, the airfoil analyzed here was developed "from scratch" for a real-world aircraft development program and is completely separate from the airfoils used during NeuralFoil's training, so NeuralFoil isn't cheating by "memorizing" this airfoil's performance. Each color in the figure below represents analyses at a different Reynolds number.
<a name="clcd-polar"></a>
<p align="center"> <img src="./benchmarking/neuralfoil_point_comparison.svg" width="1000" /> </p>NeuralFoil is typically accurate to within a few percent of XFoil's predictions. Note that this figure is on a truly out-of-sample airfoil, so airfoils that are closer to the training set will have even more accurate results.
NeuralFoil also has the benefit of smoothing out XFoil's "jagged" predictions (for example, near $C_L=1.4$ at $Re=\mathrm{80k}$) in cases where XFoil is not reliably converging, which would otherwise make optimization difficult. On that note, NeuralFoil will also give you an "analysis_confidence" output, which is a measure of uncertainty. Below, we show the same figure as before, but color the NeuralFoil results by analysis confidence. This illustrates how regions with delicate or uncertain aerodynamic behavior are flagged.
Due to domain knowledge embedded into its architecture, NeuralFoil is unusually capable of accurate generalization well beyond its training data. For example, the figure below shows that NeuralFoil can accurately predict aerodynamics on airfoils with extreme control surface deflections - despite the fact that none of NeuralFoil's training samples have deflected control surfaces. More details on this benchmark setup are available in the NeuralFoil whitepaper.
<p align="center"> <img src="./studies/control_surface_accuracy.svg" width="700" /> </p>Speed
In the table below, we quantify the performance of the NeuralFoil ("NF") models with respect to XFoil more precisely. At a basic level, we care about two things:
- Accuracy: how close are the predictions to XFoil's?
- Computational Cost: how long does it take to run?
This table details both of these considerations. The first few columns show the error with respect to XFoil on the test dataset. The test dataset is completely isolated from the training dataset, and NeuralFoil was not allowed to learn from the test dataset. Thus, the performance on the test dataset gives a good idea of NeuralFoil's performance "in the wild". The second set of columns gives the runtime speed of the models, both for a single analysis and for a large batch analysis.
<table><thead><tr><th>Aerodynamics Model</th><th colspan="4">Mean Absolute Error (MAE) of Given Metric, on the Test Dataset, with respect to XFoil</th><th colspan="2">Computational Cost to Run (CPU)</th></tr></thead><tbody><tr><td></td><td>Lift Coeff.<br>$C_L$</td><td>Fractional Drag Coeff.<br>$\ln(C_D)$ †</td><td>Moment Coeff.<br>$C_M$</td><td>Transition Locations<br>$x_{tr}/c$</td><td>Runtime<br>(1 run)</td><td>Total Runtime<br>(100,000 runs)</td></tr> <tr><td>NF "xxsmall"</td><td>0.040</td><td>0.078</td><td>0.007</td><td>0.044</td><td>1.2 ms</td><td>0.87 sec</td></tr> <tr><td>NF "xsmall"</td><td>0.030</td><td>0.057</td><td>0.005</td><td>0.033</td><td>1.2 ms</td><td>1.03 sec</td></tr> <tr><td>NF "small"</td><td>0.027</td><td>0.050</td><td>0.005</td><td>0.027</td><td>1.3 ms</td><td