Public Documentation
Documentation for the public interface of NNFoil.jl.
Index
NNFoil.NNFoilNNFoil.KulfanParametersNNFoil.KulfanParametersNNFoil.NeuralNetworkCacheNNFoil.NeuralNetworkOutputNNFoil.NeuralNetworkParametersNNFoil.NeuralNetworkParametersNNFoil.allocate_forward_cacheNNFoil.bernsteinNNFoil.build_featuresNNFoil.class_functionNNFoil.confidence_correction!NNFoil.cstNNFoil.cst_y_coordinatesNNFoil.decode_outputs!NNFoil.evaluateNNFoil.evaluate!NNFoil.flip_inputs!NNFoil.flip_outputs!NNFoil.forwardNNFoil.forward!NNFoil.fuse_predictions!NNFoil.normalize_coordinates!NNFoil.pack_outputNNFoil.pack_output!NNFoil.shape_functionNNFoil.sigmoidNNFoil.split_upper_lower_surfacesNNFoil.squared_mahalanobis_distanceNNFoil.squared_mahalanobis_distance!NNFoil.swishNNFoil.update_features!
Public interface
NNFoil.NNFoil — Module
NNFoil.jl – a partial Julia translation of NeuralFoil v0.3.2.
NNFoil.KulfanParameters — Type
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.
NNFoil.KulfanParameters — Method
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
NNFoil.NeuralNetworkCache — Type
NeuralNetworkCacheMutable 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 evaluatingx.tmp_x_flipped: layer-activation cache used when evaluatingx_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.
NNFoil.NeuralNetworkOutput — Type
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.
NNFoil.NeuralNetworkParameters — Type
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.
NNFoil.NeuralNetworkParameters — Method
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
NNFoil.allocate_forward_cache — Method
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, wherecache[1]corresponds to the input and subsequent entries store intermediate results.
NNFoil.bernstein — Method
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.
NNFoil.build_features — Method
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.5xtr_upperxtr_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 whenalphaandReynoldsare scalars.AbstractMatrix{<:Real}: Feature matrix of size(n_features, N)when eitheralphaorReynoldsare vectors. Each column corresponds to one sample.
Throws
DimensionMismatch: IfalphaandReynoldsare vectors of different lengths.
NNFoil.class_function — Method
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.
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 parameterscache::NeuralNetworkCache: Cache containing preallocated arrays
Notes
- The cache-based method avoids intermediate allocations and is preferred in performance-critical loops.
NNFoil.cst — Method
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.
NNFoil.cst_y_coordinates — Method
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 inx.
Returns
Vector{<:Real}: Airfoil surface y-coordinates corresponding tox.
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.
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
- Build the cache using the
NeuralNetworkCacheconstructor. - Use
update_features!to modify inputs before evaluation.
See also
evaluate: out-of-place version that allocates outputs and intermediate computations.
NNFoil.evaluate — Method
evaluate(network_parameters, x) -> NeuralNetworkOutputEvaluate 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
NeuralNetworkOutput: Predicted aerodynamic coefficients.
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.
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.
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, wherex[1]contains the input features and subsequent entries store intermediate layer outputs.
Notes
- Use
allocate_forward_cacheto createyandxcaches.
NNFoil.forward — Method
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}
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.
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.
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.
NNFoil.pack_output — Method
pack_output(y) -> NeuralNetworkOutputConvert a decoded output array into a NeuralNetworkOutput struct.
Arguments
y::AbstractArray{<:Real}: Decoded network output array.
Returns
NNFoil.shape_function — Method
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.
NNFoil.sigmoid — Method
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
xwith values in the range (0, 1).
NNFoil.split_upper_lower_surfaces — Method
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.
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 sizesize(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 asx.tmp2::AbstractArray{<:Real}: Temporary array the same size asx.
NNFoil.squared_mahalanobis_distance — Method
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}
NNFoil.swish — Method
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.
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 ascache.x.
Throws
DimensionMismatch: Ifxdoes 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.