Airfoil geometry
Bora does not take airfoil coordinates. It takes 18 numbers that describe the shape, a Kulfan parameterization, also called CST for class-shape transformation (Kulfan, 2008). This is the shape description NeuralFoil's networks were trained on, so it is the only one they accept (Sharpe and Hansman, 2025).
pub struct KulfanParameters {
pub upper_weights: [f64; 8],
pub lower_weights: [f64; 8],
pub leading_edge_weight: f64,
pub te_thickness: f64,
}
The parameterization
Each surface is a smooth curve from the leading edge at to the trailing edge at . The upper surface is
and the lower surface has the same form with its own weights and the trailing-edge term subtracted instead of added. The are the Bernstein polynomials of degree 7,
Reading the terms from left to right:
- The class function gives every shape a round nose and a closed trailing edge.
- The eight weights per surface scale eight overlapping bumps. Weight 0 acts near the leading edge and weight 7 near the trailing edge; the weight at the nose sets the leading-edge radius. Lower-surface weights are negative for a conventional section, and a symmetric section has .
- The leading-edge weight adds a mode concentrated in the first few percent of chord, which sharpens the fit near the nose. It applies to both surfaces with the same sign, so it shifts the nose up or down.
- The trailing-edge thickness is the gap between the surfaces at , in chord lengths.
Two properties make this a good basis for a surrogate. It is compact: studies of parameterization methods find that aerodynamic prediction error falls off sharply at about this many parameters (Masters et al., 2017). And it is linear in the weights, so fitting it to coordinates is a linear least-squares problem.
From coordinates to parameters
fit_kulfan_parameters fits the 18 parameters to a list of points:
use bora::{Point2, fit_kulfan_parameters};
/// Reads a Selig-format coordinate file: an optional name line, then one
/// "x y" pair per line.
fn read_selig_dat(path: &str) -> std::io::Result<Vec<Point2>> {
let text = std::fs::read_to_string(path)?;
Ok(text
.lines()
.filter_map(|line| {
let mut fields = line.split_whitespace().map(str::parse::<f64>);
match (fields.next(), fields.next(), fields.next()) {
(Some(Ok(x)), Some(Ok(y)), None) => Some([x, y]),
_ => None, // name line or blank line
}
})
.collect())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let coordinates = read_selig_dat("my_airfoil.dat")?;
let kulfan = fit_kulfan_parameters(&coordinates)?;
println!("{kulfan:#?}");
Ok(())
}
The fit makes three assumptions about its input. It does not check them, and a violation gives a poor fit rather than an error.
- Selig ordering. Points run from the upper-surface trailing edge, forward around the leading edge, and back along the lower surface.
- Normalized chord. The leading edge is at and the trailing edge at . Bora does not translate, rotate or scale the points. This differs from AeroSandbox, which normalizes first, so normalize before calling if your coordinates are not already in this form.
- Enough points. At least 18 are required; real coordinate files have far more.
If the least-squares solution has a negative trailing-edge thickness, the fit
is repeated with the thickness fixed at zero. The function returns
Error::InvalidArgument for too few points and Error::SingularFit if the
problem is degenerate.
:::warning Check the fit An 18-parameter curve cannot follow every shape. Sections with flat segments, sharp corners, cusps or deflected flaps are reproduced only approximately, and the network then analyzes the fitted shape, not yours. Regenerate coordinates from the fitted parameters and compare them with the originals before relying on the result. :::
From parameters to coordinates
generate_kulfan_coordinates goes the other way, for plotting or for export
to another tool:
use bora::generate_kulfan_coordinates;
// 100 points per surface, cosine-spaced, in Selig order: 199 points in all.
let coordinates = generate_kulfan_coordinates(&kulfan, 100)?;
for [x, y] in &coordinates {
println!("{x:.6} {y:.6}");
}
It returns 2 n - 1 points for n points per side, because the two surfaces
share the leading-edge point. Both functions follow the corresponding routines
in AeroSandbox (Sharpe, 2021), so parameters
are interchangeable between Bora, NeuralFoil and AeroSandbox.