NeuralFoil

repository·master·Indexed 19 days ago

https://github.com/peterdsharpe/neuralfoil

A physics-informed machine learning tool for rapid airfoil aerodynamics analysis, written in pure Python and NumPy. It serves as a high-speed, $C^\infty$-continuous alternative to XFoil, providing viscous and compressible aerodynamics with guaranteed convergence. NeuralFoil offers eight model sizes (from xxsmall to xxxlarge) to balance computational cost and accuracy, and is designed for efficient gradient-based shape optimization.

Tokens
3.9K
Snippets
6
Records
18
Agent score
16%

What's inside NeuralFoil

  1. Overview of NeuralFoil models and performance

    master

    NeuralFoil provides a spectrum of 8 neural network models ranging from xxsmall to xxxlarge. This spectrum allows users to trade off between computational cost and accuracy.

    Key features include:

    • Speed: ~30x faster than XFoil for single analyses and ~1000x faster for multipoint analysis.
    • Reliability: Guaranteed to return an answer (no non-convergence issues).
    • Optimization-friendly: The output is $C^\infty$-continuous, making it suitable for gradient-based optimization.
    • Uncertainty Quantification: Provides an analysis_confidence metric to flag queries where flow is sensitive or out-of-distribution.
  2. Select a NeuralFoil model size

    master

    NeuralFoil offers several model sizes that allow you to trade off accuracy for computational speed.

    Model Size Options:

    • xxsmall, xsmall, small, medium, large, xlarge, xxlarge, xxxlarge

    Selection Guidance:

    • Starting Point: It is generally recommended to start with the large model and adjust based on your needs.
    • Optimization: For gradient-based optimization, smaller models may be preferable as larger models can have more "wiggles" (less parsimonious) in their outputs while tracking XFoil physics more closely.
    • Robustness: Larger models are better at capturing a wider range of airfoils, including unusual or nonsensical shapes that might appear during an optimization process.
    • Speed: For batched analyses, NeuralFoil provides significant speedups (up to ~1,000x) compared to XFoil due to vectorization.
  3. Understand NeuralFoil performance and accuracy

    master

    NeuralFoil is designed to track XFoil predictions closely across a wide range of angles of attack ($\alpha$) and Reynolds numbers ($Re$).

    Key characteristics include:

    • Accuracy: Typically accurate to within a few percent of XFoil's predictions. Accuracy improves for airfoils that are closer to the training set.
    • Smoothing: NeuralFoil smooths out the "jagged" predictions often seen in XFoil when it fails to converge, which is beneficial for gradient-based optimization.
    • Uncertainty Quantification: The model provides an analysis_confidence output, which serves as a measure of uncertainty to flag regions with delicate or uncertain aerodynamic behavior.
    • Generalization: Due to its architecture, it generalizes well to out-of-sample scenarios, such as airfoils with extreme control surface deflections, even if those were not in the training data.
  4. NeuralFoil architecture and physics-informed design

    master

    The core of NeuralFoil is a Multi-Layer Perceptron (MLP) using Swish (SiLU) activation functions to ensure $C^\infty$-continuity. The model is considered "physics-informed" through three primary mechanisms:

    1. Latent Space Encoding/Decoding: Specific choices in how the input and output latent spaces are structured.
    2. Symmetry Embedding: Incorporating physical symmetry into the model.
    3. Dynamic Fusion: The model dynamically fuses a learned model with an empirical model based on the uncertainty of the learned model.

    Model Sizes

    NeuralFoil offers several model scales, varying in depth and width:

    Model SizeHidden LayersLayer Width
    xxsmall248
    xsmall348
    small364
    medium464
    large4128
    xlarge5128
    xxlarge5256
    xxxlarge6512
  5. How NeuralFoil compares to RANS CFD-trained networks

    master

    While neural networks can be trained on RANS CFD data, NeuralFoil uses a different approach:

    • Data Efficiency: RANS CFD is computationally expensive, making it difficult to gather the massive datasets required for good generalization. NeuralFoil was trained on nearly 8 million XFoil runs, allowing it to cover a much larger span of the airfoil design space.
    • Accuracy Trade-offs: Because it is trained on XFoil, NeuralFoil is highly accurate in the subsonic range (where XFoil itself is often more accurate than RANS). However, it is generally less accurate in the transonic range compared to models explicitly trained on RANS data.
  6. Why NeuralFoil limits accuracy and model size

    master

    Increasing the neural network size or shape parameterization dimensionality does not necessarily improve practical utility for aerospace engineers due to several factors:

    • Practical Utility vs. Pure Accuracy: The goal is to design airfoils that work in the real world. On the highest setting (xxxlarge), drag prediction error against XFoil is ~0.38%, which is already below the "noise floor" of what XFoil can reliably capture.
    • Avoiding Overfitting to XFoil Non-smoothness: Larger networks risk overfitting to the inherent non-smoothness of XFoil. Limiting parameter counts acts as a "low-pass filter" on the learned mapping, which is desirable for stable gradient-based optimization.
    • Design Space Constraints: The smaller geometry design space in NeuralFoil prevents the emergence of small, non-physical separation-bubble bumps that often plague point-optimization in other tools.
  7. How NeuralFoil compares to XFoil

    master

    NeuralFoil is a high-speed, differentiable surrogate model for airfoil analysis designed to overcome several limitations of XFoil:

    • Differentiability & Continuity: Unlike XFoil, which lacks $C^1$-continuity (causing "ragged" polars and inaccurate gradients), NeuralFoil is guaranteed to be $C^\infty$-continuous. This makes it ideal for gradient-based optimization.
    • Speed & Vectorization: NeuralFoil is approximately 1000x faster than XFoil and is fully vectorized, allowing for simultaneous analysis of large batches of airfoil cases.
    • Reliability: XFoil can fail to converge or crash on "ambitious" calculations. NeuralFoil will always produce an answer. If the result is potentially inaccurate, the analysis_confidence metric provides a warning.
    • Ease of Use: NeuralFoil is pure Python and NumPy, avoiding the complex compilation requirements often associated with XFoil on Mac or Linux.
    • Hysteresis: NeuralFoil avoids the hysteresis issues found in XFoil (where solutions vary depending on whether the angle of attack $\alpha$ is swept up or down).
  8. Understand NeuralFoil geometry parameterization

    master

    NeuralFoil uses the CST (Kulfan) parameterization to represent airfoil shapes. While you can provide airfoils as $(x,y)$ coordinates, .dat files, or AeroSandbox Airfoil objects, the underlying neural networks operate on an 18-parameter representation.

    This 18-parameter set is derived from:

    • 8 parameters for the upper surface
    • 8 parameters for the lower surface
    • 1 leading-edge-modification (LEM) parameter
    • 1 trailing-edge thickness parameter

    Total: $(8 \times 2) + 1 + 1 = 18$ parameters.

  9. Perform airfoil shape optimization with NeuralFoil

    master

    NeuralFoil can be used for airfoil shape optimization in conjunction with AeroSandbox.

    Benefits for Optimization:

    • Speed: Optimization processes can be extremely fast (e.g., ~30 seconds for a full design on a PC, or as quick as 0.5 seconds using lower model_size values).
    • Gradient Quality: Unlike XFoil, which has "ragged" gradients that make optimization difficult, NeuralFoil provides smoother surfaces suitable for gradient-based optimizers.
    • Robustness: When well-posed, NeuralFoil avoids "over-optimizing" to solutions that only perform well at a single design point, maintaining better off-design performance.
  10. Install NeuralFoil via pip

    master

    Install the standalone NeuralFoil package using pip. NeuralFoil is a pure Python+NumPy tool for rapid aerodynamics analysis of airfoils, providing a fast alternative to XFoil with guaranteed convergence and $C^ ext{infinity}$ continuity.

    pip install neuralfoil
  11. Use extended features via AeroSandbox

    master

    For advanced aerodynamic calculations, use NeuralFoil through the AeroSandbox interface using asb.Airfoil.get_aero_from_neuralfoil(). This enables:

    • Compressible Aerodynamics: Includes transonic and supersonic aerodynamics. It uses a Laitone correction for subsonic corrections and provides accurate critical Mach numbers (typically within $\pm 0.01$).
    • Post-stall Aerodynamics: Supports a full 360-degree range of $\alpha$, useful for wind turbine blades or propeller roots.
    • Control Surface Deflections: Supports trailing-edge control surface deflections.
  12. Perform airfoil aerodynamics analysis with NeuralFoil

    master

    NeuralFoil offers several entry points for performing aerodynamic analysis depending on your available data. The results are returned as a dictionary containing aerodynamic coefficients and boundary layer information.

    import neuralfoil as nf  # `pip install neuralfoil`
    import numpy as np
    
    # Option 1: Use a .dat file as an entry point
    aero = nf.get_aero_from_dat_file(
        filename="/path/to/my_airfoil_file.dat",
        alpha=5,  # Angle of attack [deg]
        Re=5e6,  # Reynolds number [-]
        model_size="xlarge",  # Optionally, specify your model size.
    )
    
    # Option 2: Use xy airfoil coordinates as an entry point
    # coordinates should be a 2-column numpy ndarray
    aero = nf.get_aero_from_coordinates(
        coordinates=n_by_2_numpy_ndarray_of_airfoil_coordinates,
        alpha=np.linspace(-25, 25, 1000),  # Vectorize your evaluations across `alpha` and `Re`
        Re=5e6,
    )
    
    # Option 3: Use AeroSandbox airfoils as an entry point
    import aerosandbox as asb  # `pip install aerosandbox`
    aero = nf.get_aero_from_airfoil(
        airfoil=asb.Airfoil("naca4412"),  # any UIUC or NACA airfoil name works
        alpha=5, Re=5e6,
    )
    
    # The resulting `aero` is a dictionary with keys: 
    # ["analysis_confidence", "CL", "CD", "CM", "Top_Xtr", "Bot_Xtr", ...]