Public Documentation

Documentation for the public interface of NNFoil.jl.

Index

Public interface

NNFoil.KulfanParametersType
KulfanParameters{Vu, Vl, Tl, Tt}

Parameter container for the Kulfan (CST) airfoil shape parameterization.

Fields

  • upper_weights::Vu: Weights for the upper surface.
  • lower_weights::Vl: Weights for the lower surface.
  • leading_edge_weight::Tl: Scalar parameter controlling leading-edge thickness/rounding.
  • trailing_edge_thickness::Tt: Scalar trailing-edge thickness parameter.
source
NNFoil.KulfanParametersMethod
KulfanParameters(coordinates)

Fits Kulfan (CST) parameters to a set of airfoil coordinates.

This method assumes that the input coordinates follow the Selig ordering, i.e., starting at the trailing edge, proceeding along the upper surface to the leading edge, and returning along the lower surface. The number of Bernstein weights per surface is currently fixed internally at eight, following the implementation used in NeuralFoil.

Arguments

  • coordinates::AbstractMatrix: Airfoil coordinates with columns [x, y].

Returns

source
NNFoil.NeuralNetworkCacheType
NeuralNetworkCache

Mutable cache that stores preallocated arrays used during repeated neural network evaluations.

Fields

  • parameters<:NeuralNetworkParameters: pretrained network parameters.
  • output<:NeuralNetworkOutput: output buffers for aerodynamic coefficients.
  • y: network outputs for the original inputs.
  • y_flipped: network outputs for symmetry-flipped inputs.
  • x: original input features.
  • x_flipped: symmetry-flipped input features.
  • tmp_x: layer-activation cache used when evaluating x.
  • tmp_x_flipped: layer-activation cache used when evaluating x_flipped.
  • tmp_x_smd1: temporary workspace for Mahalanobis-distance intermediates.
  • tmp_x_smd2: temporary workspace for Mahalanobis-distance intermediates.
  • tmp_y_smd: temporary workspace for Mahalanobis-distance outputs.
source
NNFoil.NeuralNetworkOutputType
NeuralNetworkOutput{V}

Stores the aerodynamic coefficients predicted by the neural network.

Type Parameters

  • V<:AbstractVector{<:Real}

Fields

  • analysis_confidence::V: confidence level of the neural network prediction.
  • CL::V: lift coefficient values.
  • CD::V: drag coefficient values.
  • CM::V: moment coefficient values.
  • Top_Xtr::V: transition location on the upper surface.
  • Bot_Xtr::V: transition location on the lower surface.
Note

Boundary-layer related outputs are currently not supported. Support for these outputs is planned in a future version.

source
NNFoil.NeuralNetworkParametersType
NeuralNetworkParameters{R, V, M, W, B}

Stores the parameters of the pretrained neural network model.

Type Parameters

  • R<:Real: numeric type used for all elements.
  • V<:AbstractVector{R}
  • M<:AbstractMatrix{R}
  • W<:AbstractVector{M}
  • B<:AbstractVector{V}

Fields

  • mean_inputs_scaled::V: mean values of the scaled input features.
  • cov_inputs_scaled::M: covariance matrix of the scaled inputs.
  • inv_cov_inputs_scaled::M: inverse of the covariance matrix.
  • weights::W: vector of weight matrices for each layer.
  • biases::B: vector of bias vectors for each layer.
source
NNFoil.NeuralNetworkParametersMethod
NeuralNetworkParameters(; model_size=:xlarge, T=Float64)

Convenience constructor that loads and converts the pretrained neural network parameters.

Keyword arguments

  • model_size::Symbol: Size of the pretrained model parameters to load.
  • T::Type: Numerical type to which all loaded arrays will be converted.

Returns

source
NNFoil.allocate_forward_cacheMethod
allocate_forward_cache(network_parameters, x)

Allocate output and activation buffers for in-place neural network evaluation.

Arguments

  • network_parameters::NeuralNetworkParameters: Pretrained network weights and biases.
  • x::AbstractVecOrMat{<:Real}: Input features used to determine the shape of the allocated buffers.

Returns

  • y: Output array matching the network output dimensions.
  • x: Vector of arrays storing temporary cache, where cache[1] corresponds to the input and subsequent entries store intermediate results.
source
NNFoil.bernsteinMethod
bernstein(x, v, n)

Evaluate the Bernstein basis polynomial of degree n and index v at x.

Arguments

  • x: Evaluation points (scalar, vector, or array).
  • v: Index of the basis polynomial (0 ≤ v ≤ n).
  • n: Degree of the polynomial.

Returns

  • Array of the same shape as x: Values of the Bernstein polynomial.
source
NNFoil.build_featuresMethod
build_features(kulfan_parameters, alpha, Reynolds;
    n_crit=9, xtr_upper=1, xtr_lower=1)

Construct a 25 x N neural-network input feature array expected by the neural network from Kulfan shape parameters and flow conditions.

The 25 features are:

  • 18 Kulfan parameters (8 upper weights, 8 lower weights, leading edge weight, trailing edge thickness scaled by 50)
  • sin(2α) (α in degrees)
  • cos(α) (α in degrees)
  • 1 - cos²(α) (α in degrees)
  • (log(Reynolds) - 12.5) / 3.5
  • (n_crit - 9) / 4.5
  • xtr_upper
  • xtr_lower

Arguments

  • kulfan_parameters::KulfanParameters: Airfoil geometry defined by Kulfan (CST) parameters.
  • alpha: Angle of attack in degrees. Can be a scalar or a vector.
  • Reynolds: Reynolds number. Can be a scalar or a vector.

Keyword Arguments

  • n_crit::Real=9: Critical amplification factor used in transition modeling.
  • xtr_upper::Real=1: Forced transition location on the upper surface (0–1).
  • xtr_lower::Real=1: Forced transition location on the lower surface (0–1).

Returns

  • AbstractVector{<:Real}: Feature vector when alpha and Reynolds are scalars.
  • AbstractMatrix{<:Real}: Feature matrix of size (n_features, N) when either alpha or Reynolds are vectors. Each column corresponds to one sample.

Throws

  • DimensionMismatch: If alpha and Reynolds are vectors of different lengths.
source
NNFoil.class_functionMethod
class_function(x)

Evaluate the class function used in Kulfan’s parametrization.

In NeuralFoil, the class-shape exponents N1 and N2 are hardcoded as N1=0.5 and N2=1.0.

Arguments

  • x: Nondimensional chordwise coordinates [0–1].

Returns

  • Array of the same shape as x: Values of the class function.
source
NNFoil.confidence_correction!Method
confidence_correction!(y, x, network_parameters)
confidence_correction!(y, x, cache)

Apply Mahalanobis-distance-based confidence correction to the network outputs.

This function adjusts the first output channel (confidence) based on the distance between the input features and the training data distribution.

Arguments

  • y::AbstractArray{<:Real}: Network output array. The first row is modified in-place.
  • x::AbstractArray{<:Real}: Input feature array.
  • network_parameters::NeuralNetworkParameters: Pretrained network parameters
  • cache::NeuralNetworkCache: Cache containing preallocated arrays

Notes

  • The cache-based method avoids intermediate allocations and is preferred in performance-critical loops.
source
NNFoil.cstMethod
cst(x, coefficients, leading_edge_weight, trailing_edge_thickness)

CST (Class–Shape Transformation) surface parametrization.

Arguments

  • x: Nondimensional chordwise coordinates [0, 1].
  • coefficients::AbstractVector: Shape function weights.
  • leading_edge_weight::Real: Leading-edge modification term.
  • trailing_edge_thickness::Real: Trailing-edge thickness parameter.

Returns

  • Same shape as x: Airfoil surface coordinates defined by the CST parametrization.
source
NNFoil.cst_y_coordinatesMethod
cst_y_coordinates(x, parameters, x_split_id)

Generate the airfoil surface coordinates from Kulfan parameters.

Arguments

  • x::AbstractVector: Nondimensional chordwise coordinates, following the Selig ordering.
  • parameters::AbstractVector: Vector containing the CST parameters: upper and lower weights, leading-edge weight, and trailing-edge thickness.
  • x_split_id::Int: Index separating the upper and lower surface coordinates in x.

Returns

  • Vector{<:Real}: Airfoil surface y-coordinates corresponding to x.
source
NNFoil.decode_outputs!Method
decode_outputs!(y)

Transform raw neural network outputs into physically meaningful quantities.

This function applies scaling, nonlinear transformations, and clamping to convert network outputs into aerodynamic coefficients and transition locations.

Arguments

  • y::AbstractArray{<:Real}: Network output array modified in-place.
Note

The ordering and scaling of outputs are part of the trained model and must not be modified without retraining the network.

source
NNFoil.evaluate!Method
evaluate!(cache)

Evaluate the neural network in-place using a preallocated cache.

Arguments

  • cache::NeuralNetworkCache: Cache containing input features, intermediate buffers, and output storage.

Notes

See also

  • evaluate: out-of-place version that allocates outputs and intermediate computations.
source
NNFoil.evaluateMethod
evaluate(network_parameters, x) -> NeuralNetworkOutput

Evaluate the neural network for the input features x using the pretrained parameters network_parameters. It then applies post-processing transformations to produce physically meaningful aerodynamic coefficients.

Arguments

  • network_parameters::NeuralNetworkParameters: Pretrained parameters of the neural network.
  • x::AbstractMatrix: Matrix of preprocessed features characterizing the airfoil geometry and the flow conditions. Each column corresponds to one input sample.

Returns

source
NNFoil.flip_inputs!Method
flip_inputs!(x)

Flip the input array in-place, creating a geometrically mirrored version of the input features.

Arguments

  • x::AbstractArray: Input array of size (25, *) where each column represents a sample. Flipping is applied on specific rows.
source
NNFoil.flip_outputs!Method
flip_outputs!(y, tmp)

Transform neural network outputs so that they are consistent with the original (non-flipped) reference frame.

Arguments

  • y::AbstractArray{<:Real}: Output array to be transformed in-place.
  • tmp::AbstractVector{<:Real}: Temporary array used to swap outputs.
source
NNFoil.forward!Method
forward!(y, network_parameters, x)

Evaluate the neural network in-place using preallocated buffers.

Arguments

  • y::AbstractArray{<:Real}: Output array that will store the network predictions.
  • network_parameters::NeuralNetworkParameters: Pretrained network weights and biases.
  • x::AbstractVector{<:}: Temporary cache, where x[1] contains the input features and subsequent entries store intermediate layer outputs.

Notes

source
NNFoil.forwardMethod
forward(network_parameters::NetworkParameters, x::AbstractMatrix{<:Real})

Evaluate the neural network using the pretrained network parameters on the given input x.

Arguments

  • network_parameters::NeuralNetworkParameters: pretrained network weights and biases.
  • x::AbstractArray{<:Real}: Input data of size (25, :).

Returns

  • AbstractMatrix{<:Real}
source
NNFoil.fuse_predictions!Method
fuse_predictions!(y, y_flipped)

Average predictions from original and symmetry-flipped inputs.

Arguments

  • y::AbstractArray{<:Real}: Output array that will store the fused result.
  • y_flipped::AbstractArray{<:Real}: Output array from flipped inputs.

Notes

  • The result overwrites y.
  • Both arrays must have identical sizes.
source
NNFoil.normalize_coordinates!Method
normalize_coordinates!(coordinates)

Normalize the input coordinates in place so that the x values lie within the unit interval [0, 1].

Arguments

  • coordinates::AbstractMatrix: Matrix of airfoil coordinates with columns representing the x and y values.
Warning

The current normalization is a temporary workaround and may be revised in future versions of NNFoil so that it more closely matches how NeuralFoil normalizes coordinates.

source
NNFoil.pack_output!Method
pack_output!(output, y)

Store decoded outputs into a preallocated NeuralNetworkOutput struct.

Arguments

  • output::NeuralNetworkOutput: Output container to be updated.
  • y::AbstractArray{<:Real}: Decoded network output array.
source
NNFoil.pack_outputMethod
pack_output(y) -> NeuralNetworkOutput

Convert a decoded output array into a NeuralNetworkOutput struct.

Arguments

  • y::AbstractArray{<:Real}: Decoded network output array.

Returns

source
NNFoil.shape_functionMethod
shape_function(x, coefficients)

Kulfan shape function defined as a weighted sum of Bernstein polynomials.

Arguments

  • x: Nondimensional chordwise coordinates.
  • coefficients::AbstractVector: Weights for the Bernstein polynomials.

Returns

  • Same shape as x: Values of the shape function.
source
NNFoil.sigmoidMethod
sigmoid(x::T; ln_eps=log(10 / floatmax(eltype(T)))) where {T}

Sigmoid activation function with input clipping for numerical stability.

Arguments

  • x::T: Input value.
  • ln_eps::Real=log(10 / floatmax(eltype(T))): Logarithmic bound used to clip input values for stability.

Returns

  • Scalar or Array of the same shape as x with values in the range (0, 1).
source
NNFoil.split_upper_lower_surfacesMethod
split_upper_lower_surfaces(coordinates)

Split airfoil coordinates into upper and lower surfaces.

Arguments

  • coordinates::AbstractMatrix: Matrix of airfoil coordinates with columns representing the x and y values.

Returns

  • (upper, lower): Two matrices containing the coordinates of the upper and lower surfaces, respectively.
source
NNFoil.squared_mahalanobis_distance!Method
squared_mahalanobis_distance!(y, params::NetworkParameters, x, tmp1, tmp2)

In-place, non-allocating version of squared_mahalanobis_distance.

Compute the squared Mahalanobis distance between the input array x and the mean of the scaled input distribution.

Arguments

  • y::AbstractVector{<:Real}: Output vector of size size(x, 2).
  • params::NetworkParameters: pretrained neural network parameters containing the mean and inverse covariance of the scaled input distribution.
  • x::AbstractArray{<:Real}: Input samples.
  • tmp1::AbstractArray{<:Real}: Temporary array the same size as x.
  • tmp2::AbstractArray{<:Real}: Temporary array the same size as x.
source
NNFoil.squared_mahalanobis_distanceMethod
squared_mahalanobis_distance(params::NetworkParameters, x)

Compute the squared Mahalanobis distance between the input array x and the mean of the scaled input distribution.

Arguments

  • params::NetworkParameters: pretrained neural network parameters containing the mean and inverse covariance of the scaled input distribution.
  • x::AbstractArray{<:Real}: Input samples.

Returns

  • AbstractArray{<:Real}
source
NNFoil.swishMethod
swish(x; beta=1)

Apply the Swish activation function elementwise.

Arguments

  • x: Input value.
  • beta::Real=1: Slope parameter controlling smoothness.

Returns

  • Scalar or Array of the same shape as x: Activated values.
source
NNFoil.update_features!Method
update_features!(cache, x)

Update the input feature arrays stored in the cache.

This function replaces the current input features with x and updates the symmetry-flipped features accordingly.

Arguments

  • cache::NeuralNetworkCache: Cache containing input and workspace arrays.
  • x::AbstractArray{<:Real}: New input feature array of the same size as cache.x.

Throws

  • DimensionMismatch: If x does not match the size of the cached input.

Notes

  • This function does not recompute network outputs. After updating the inputs, evaluate! must be called to obtain updated predictions.
source