Find a NACA airfoil that gives you the lift you need.
You tell the program the flow conditions (fluid, speed, chord), the angle of attack and the lift coefficient you want. It searches an airfoil family (NACA 4-digit by default, NACA 5-digit, or free CST shapes) for a shape that hits that target, then saves the coordinates, the plots and the raw data.
The project comes with two solvers that follow the same workflow:
- In-house potential solver – our own panel method, written in pure Python. No external programs needed. It gives lift and pressure distribution, but it ignores viscosity, so it cannot compute drag.
- XFOIL viscous solver – runs XFOIL in the background. Slower, but it includes the boundary layer, so it also gives drag: it can find the lowest drag at a target lift, or the highest lift under a drag limit.
A third script compares the two, so you can see how far potential flow is from the viscous result, and why.
What every symbol, message and number means, and why each value was chosen, is explained in Reference.
Naca-optimizer/
├── run.py # Start here: python run.py (you choose the solver, or --solver)
├── inputs.py # Input file: python run.py --input inputs.py (no questions)
├── naca_core/ # All the code
│ ├── __init__.py
│ ├── input_file.py # Defaults, fluids and the reader of the input file
│ ├── panel_method.py # In-house solver (source + vortex panel method)
│ ├── xfoil.py # XFOIL solver: writes the script, runs XFOIL, reads the polar
│ ├── inhouse_optimizer.py # Connects the panel method to the search
│ ├── xfoil_optimizer.py # Connects XFOIL to the search, with the two objectives
│ ├── optimization.py # Shared search: Genetic Algorithm + SLSQP, table, box, seed
│ ├── airfoil.py # Airfoil geometry and families (NACA 4-digit, NACA 5-digit, CST)
│ ├── export.py # DXF, CSV, VTK, STL
│ ├── plotting.py # Plots
│ ├── pre_run_checks.py # Library and XFOIL checks
│ └── bin/ # XFOIL executable (not versioned)
├── validation_inhouse_vs_xfoil/ # In-house vs XFOIL comparison
│ ├── run_validation.py
│ └── README.md
├── tests/ # Checks to run after a change (see "Checking your changes")
│ ├── baseline_check.py # Numerical baseline: geometry + panel method
│ ├── baseline_reference.json
│ ├── terminal_regression_check.py # Whole terminal output of a fixed in-house run
│ ├── terminal_regression_reference.txt
│ ├── regression_inputs.py # Input file of that fixed run
│ └── stl_export_check.py # STL export quality
├── Results/ # Created by the scripts, not versioned
│ ├── Re<Re>_Alpha<a>_<objective>_<solver>[_<family>]_seed<N>/ # one folder per optimization run
│ │ └── export/ # CAD, ParaView and OpenFOAM files
│ └── validation/
│ └── Re<Re>_Mach<M>/ # one folder per validation run
├── requirements.txt # Python libraries: pip install -r requirements.txt
├── TODO.md # Open items and planned work
└── _Original_projects/ # Original MATLAB script and first Python version (reference only)
Each airfoil is built from a few numbers, which depend on the airfoil family.
The family is chosen in the input file (AIRFOIL_FAMILY); the questions in the terminal always use NACA 4-digit.
NACA 4-digit ("naca4", default). Starts from NACA 2412.
| Parameter | Meaning | Example (NACA 2412) | Search range |
|---|---|---|---|
m |
maximum camber (fraction of chord) | 0.02 | 0 – 0.09 |
p |
position of maximum camber (fraction of chord) | 0.4 | 0.1 – 0.7 |
t |
maximum thickness (fraction of chord) | 0.12 | 0.05 – 0.25 |
NACA 5-digit ("naca5"), non-reflex mean line (the 210 to 250 series, e.g. NACA 23012). Same thickness as NACA 4-digit; the mean line is a cubic up to x = r and a straight line after it. Starts from NACA 23012.
| Parameter | Meaning | Example (NACA 23012) | Search range |
|---|---|---|---|
cl_d |
design lift coefficient (first digit × 0.15) | 0.3 | 0.05 – 0.6 |
p |
position of maximum camber (second digit ÷ 20) | 0.15 | 0.05 – 0.25 |
t |
maximum thickness (fraction of chord) | 0.12 | 0.05 – 0.25 |
The name is rebuilt from the rounded values: NACA + round(cl_d / 0.15) + round(p · 20) + 0 + round(t · 100). The mean-line constants r and k₁ are computed for any p, instead of being read from the five-row table of Abbott & von Doenhoff: r from p = r·(1 − √(r/3)), k₁ = 6·cl_d / Q(r). With the tabulated r they give the tabulated k₁ within 0.03 % for the 230, 240 and 250 mean lines. For 210 and 220 the historical table differs from its own formula (k₁ 361.4 against 351.6 for 210), a difference of about 0.0003 of the chord on the shape.
CST, free shape ("cst"). Upper and lower surface are two independent curves (Kulfan's Class-Shape Transformation):
y(x) = √x · (1 − x) · Σ Aᵢ · Bᵢ(x)
where Bᵢ are the Bernstein polynomials of order CST_ORDER (default 3). The factor √x·(1 − x) always gives a round leading edge and a closed trailing edge. Each surface has CST_ORDER + 1 coefficients: Au0 … Au3 for the upper surface and Al0 … Al3 for the lower one (negative for a usual airfoil), so 8 parameters with the default order. There is no NACA name: the airfoil is called CST-3 and the .dat header and the CSV give every coefficient.
- Starting airfoil: the CST copy (least-squares fit) of NACA 2412, so the search starts from the same shape as NACA 4-digit.
- Search range: the CST fits of NACA 4-digit airfoils over the whole NACA 4-digit range (m 0 / 0.045 / 0.09, p 0.1 / 0.4 / 0.7, t 0.05 / 0.15 / 0.25), widened by 25 % on each side. NACA shapes that a CST cannot follow (fit further than 0.005 of the chord: high camber very close to the leading edge, which reaches ahead of x = 0) are left out.
- Invalid shapes: with free coefficients the upper surface can go below the lower one. Such a shape is not analysed:
Crossedappears in the Cl column and it gets the failure penalty. With the default order about 29 % of random shapes in the search range are crossed. - Trailing edge: as for NACA (see below), the analyses use a small trailing-edge gap (0.0025 of the chord, as NACA 2412, added linearly along the chord) and the exported airfoil is closed.
- Accuracy of the NACA copies (order 3): 0.0002 (NACA 0012) to 0.0017 (NACA 9512) of the chord; higher orders improve it only slightly.
- Cost: 8 parameters instead of 3, so the search takes longer (see Limitations).
Points are placed with cosine spacing, so there are more of them near the leading and trailing edge, where the flow changes fastest.
Trailing edge. The analyses (in-house and XFOIL) use the original NACA formula, which leaves a small gap at the trailing edge (0.0025 of the chord for t = 0.12). The airfoil you get back (.dat, plots, CAD and mesh files) has a closed, sharp trailing edge: the last thickness coefficient is −0.1036 instead of −0.1015, so upper and lower surface end at the same point. The two shapes differ only near the trailing edge, by at most that gap. Why not analyse the closed shape too: on a sharp trailing edge XFOIL's viscous solution jumps between two results (see Values and why).
- In-house: a source + vortex panel method. The surface is split into straight panels; each panel carries its own (uniformly distributed) source strength and all panels share one (uniformly distributed) vortex strength. The Kutta condition at the trailing edge closes the system. Lift comes from the total circulation (Kutta–Joukowski). This solver was first written in MATLAB (
_Original_projects/Original_Matlab_Project/Prova_finale.m) and then ported to Python. - XFOIL: viscous mode at your Reynolds and Mach number, with free transition (Ncrit = 9). XFOIL analyses the same points as the in-house solver (no re-paneling), so the number of panels you choose applies to both. To help convergence, the angle of attack is reached in 1° steps before the target value.
The program changes the parameters of the airfoil family (m, p, t for NACA 4-digit) to make a score as small as possible. The score depends on the solver:
- In-house (no drag available): reach the target Cl.
score = (10 · (Cl − Cl_target))² - XFOIL, two objectives chosen at start:
- Minimum Cd at a target Cl. The score is Cd in drag counts (1 count = 0.0001). If Cl is outside
Cl_target ± 0.005, a penalty is added that quickly outweighs any Cd difference. - Maximum Cl with a Cd limit. The score is −Cl. If Cd is above the limit, a penalty is added.
- Minimum Cd at a target Cl. The score is Cd in drag counts (1 count = 0.0001). If Cl is outside
A large penalty is added when the solver fails. An airfoil taller than your bounding box is not analysed at all: it gets a penalty that grows with the excess height.
Both solvers use the same two-phase search:
- Genetic Algorithm (global search, scipy differential evolution): a random population of airfoils, which always includes the starting airfoil of the family (NACA 2412, NACA 23012, or the CST copy of NACA 2412), evolves for a few generations. The population is 5 airfoils per parameter: 15 for the NACA families, 40 for CST of order 3.
- SLSQP (local refinement): a gradient-based method starts from the best airfoil of phase 1. The finite-difference step is 1e-4 for the in-house solver and 2e-3 for XFOIL, because XFOIL prints Cl with only 4 decimals.
The random population depends on a seed: the same seed gives exactly the same run.
Search limits: see Airfoil families (NACA 4-digit: 0 ≤ m ≤ 0.09, 0.1 ≤ p ≤ 0.7, 0.05 ≤ t ≤ 0.25).
- Python 3.12 or newer (tested with 3.12 and 3.14)
numpy,scipy,matplotlib,ezdxf(for the DXF export); minimum versions inrequirements.txt- XFOIL – only for the XFOIL solver and the validation script
git clone https://github.com/LS-aeroteam/Naca-Optimizer.git
cd Naca-Optimizer
python -m pip install -r requirements.txtXFOIL setup
- Windows: the program looks for
xfoil.exeinnaca_core/bin/. If it is not there, it downloads XFOIL 6.99 from the official MIT page and puts it there. - Linux / macOS: install XFOIL yourself and make sure the
xfoilcommand is on your PATH, or copy the executable intonaca_core/bin/.
naca_core/bin/ is ignored by git, so the executable never ends up in a commit.
Both scripts check the Python libraries at start-up and, if some are missing, ask whether to install them with pip. XFOIL is checked only when you choose the XFOIL solver, and by the validation script.
Every prompt has a default value: just press Enter to accept it.
From the repository folder:
python run.pyThe first question is the solver:
Select the solver:
1. In-house panel method (potential flow, fast, no drag)
2. XFOIL (viscous, slower, gives drag)
You can skip it by choosing the solver on the command line, which is handy when you launch several cases from a script:
python run.py --solver inhouse
python run.py --solver xfoilpython run.py --help lists the options. Without --solver the question is asked as above, or the solver is taken from the input file (see Input file).
Then the setup, the same for both solvers:
| Prompt | Default | Notes |
|---|---|---|
| Fluid | 1 (air) | 1 = air at sea level, 2 = water at 20 °C |
| Design speed | 50 m/s | |
| Chord | 1.0 m | Reynolds and Mach are computed from speed, chord and fluid |
| Angle of attack | 4.0° | |
| Objective | 1 | XFOIL only: 1 = minimum Cd at a target Cl, 2 = maximum Cl with a Cd limit |
| Target Cl | 0.8 | Asked with objective 1, and always with the in-house solver |
| Maximum Cd | 0.006 | XFOIL, objective 2 only |
| Bounding box max height | 0.3 m | Maximum total height of the airfoil (thickness + camber) |
| Number of panels | 160 | 60 = fast, 160 = accurate |
| Random seed | random | Enter a number to repeat a run exactly. The seed used is printed at the end and saved in the CSV |
| Span for the 3D export | same as the chord | Length of the extruded wing in the STL file, in metres |
Instead of answering the questions, you can write every input in a file and run:
python run.py --input inputs.pyNo question is asked in the terminal. inputs.py in the repository root is a plain Python file, ready to edit: one line per input, grouped in six sections (solver, airfoil family, flow conditions, objective, search, export), each with its unit, allowed values and meaning. The values in it are the defaults of the table above. Copy it to keep several cases (for example cases/water_6deg.py) and pass the copy with --input.
FLUID = "air" # "air" sea level, nu = 1.46e-5 m^2/s, a = 340.3 m/s
# "water" 20 deg C, nu = 1.00e-6 m^2/s, a = 1482 m/s
SPEED = 50.0 # [m/s] design speed
CHORD = 1.0 # [m] airfoil chord
ALPHA = 4.0 # [deg] angle of attack| Variable | Same as the prompt | Values |
|---|---|---|
SOLVER |
Solver | "inhouse" or "xfoil". --solver on the command line replaces it |
AIRFOIL_FAMILY |
— (input file only) | "naca4" (default), "naca5" or "cst", see Airfoil families. The questions in the terminal always use NACA 4-digit |
CST_ORDER |
— (input file only) | whole number, default 3 (8 parameters); used only with "cst" |
FLUID |
Fluid | "air" or "water" |
SPEED, CHORD, ALPHA |
Design speed (m/s), chord (m), angle of attack (°) | numbers |
OBJECTIVE |
Objective (XFOIL only) | "min_cd" (= 1) or "max_cl" (= 2). Ignored with the in-house solver, which always reaches TARGET_CL |
TARGET_CL, MAX_CD |
Target Cl, maximum Cd | numbers |
MAX_HEIGHT_BOX |
Bounding box max height (m) | number |
NUM_PANELS |
Number of panels | whole number |
SEED |
Random seed | whole number, or None for a random seed |
SPAN |
Span for the 3D export (m) | number, or None to use the chord |
Every line is optional: a variable that is not in the file takes its default. It is normal Python, so text goes in quotes, # starts a comment and you can write expressions (e.g. SPEED = 180 / 3.6 for 180 km/h); only UPPERCASE names are read as inputs. The run stops with a [!] Input file ... message, before any computation, if the file is missing or has a Python error (with the line number), if a variable is unknown (e.g. a typo), if a number is written as text, or if a choice is not one of those listed. The values themselves are not checked any further, exactly as with the questions.
At the end of a run with a random seed, the message tells you the SEED = N line to set in the file to repeat the run.
While it runs, you see one table row per evaluated airfoil:
| Eval | m | p | t | Cl | Cd | BB | Score |
| 1 | 0.0200 | 0.4000 | 0.1200 | 0.7359 | - | | 4.1077e-01 |
| 2 | 0.0441 | 0.1438 | 0.1791 | 1.0147 | - | | 4.6090e+00 |
BB shows OUT when the airfoil is taller than the bounding box (it is not analysed). With the in-house solver Cd shows -, because potential flow has no drag.
With XFOIL, Failed in the Cl column means XFOIL did not converge at the target angle, and Timeout means it took more than 30 s. Both are treated as failed evaluations.
cd validation_inhouse_vs_xfoil
python run_validation.pyIt runs NACA 0012, 2412 and 4412 over an angle-of-attack sweep (default −4° to 10°, step 2°) and explains why the in-house Cl differs from XFOIL.
The reference is XFOIL viscous at the real Mach number. The in-house solver differs from it for three reasons, so for every angle XFOIL is run four times (inviscid and viscous, each at Mach 0 and at the real Mach) and the difference is split into three parts:
dCl total = in-house Cl − XFOIL viscous Cl (real Mach)
= num + Mach + visc
| Part | What it measures |
|---|---|
num |
Numerical error of the panel method: in-house vs XFOIL inviscid at Mach 0 (same physics) |
Mach |
Compressibility, which the in-house solver ignores |
visc |
Boundary layer, which the in-house solver ignores |
A positive value means the in-house solver overestimates Cl. Mach and viscosity affect each other, so their parts are the average of the two possible orders (Mach first, viscosity first); the three parts always add up exactly to the total.
If one of the intermediate XFOIL runs fails, the script uses the runs that worked instead of dropping the point, and marks the line:
| Failed run | Breakdown | Mark |
|---|---|---|
| viscous at Mach 0 | Mach first | (Mach first) |
| inviscid at the real Mach | viscosity first | (visc first) |
| both of the above | Mach and viscosity together | (Mach+visc combined) |
| inviscid at Mach 0 | only the total | (breakdown N/A) |
With a single order, the split between Mach and viscosity can differ from the average by a few thousandths of Cl. In the error plot these points have hollow markers.
Example output:
> Alpha = 4.0 deg ... [OK] In-House Cl: 0.7359 | XFOIL Cl: 0.6892 | dCl total +0.0467 = num -0.0078 | Mach -0.0098 | visc +0.0643
Typically the boundary layer explains most of the difference: it makes the real airfoil behave as if it had less camber.
Everything goes into one Results/ folder in the repository root, created by the scripts and ignored by git, so your runs never end up in a commit. Each optimization run gets its own subfolder, named after the case, the solver and the seed:
Results/Re<Reynolds>_Alpha<angle>_Cl<target>_<solver>_seed<N>/ (target-Cl runs)
Results/Re<Reynolds>_Alpha<angle>_CdMax<limit>_xfoil_seed<N>/ (XFOIL, maximum-Cl runs)
<solver> is inhouse or xfoil. For example Results/Re3424658_Alpha4.0_Cl0.8_xfoil_seed42/. The same case solved with both solvers ends up in two folders side by side, and runs with different seeds never overwrite each other. With an airfoil family other than NACA 4-digit its name comes before the seed, e.g. Results/Re3424658_Alpha4.0_Cl0.8_xfoil_naca5_seed42/.
| File | Content |
|---|---|
airfoil_NACA_xxxx.dat |
Airfoil coordinates (x y), closed trailing edge, in XFOIL's format. The first line is the name with the exact m, p, t. To analyse it in XFOIL yourself, mind that its viscous results on a sharp trailing edge are not reliable (see Values and why) |
geometry_NACA_xxxx.svg |
Airfoil shape |
pressure_distribution_NACA_xxxx.svg |
Cp on upper and lower surface |
lift_distribution_NACA_xxxx.svg |
ΔCp = Cp,lower − Cp,upper along the chord (both taken at the same x/c) |
optimization_history.csv |
Every evaluated airfoil with its Cl, Cd and score |
optimization_history.svg |
How m, p, t and the score changed during the search |
aerodynamic_data_NACA_xxxx.csv |
Global coefficients, exact m, p, t and Cp distribution |
export/airfoil_NACA_xxxx.dxf |
CAD: closed 2D profile in mm, ready to extrude |
export/airfoil_NACA_xxxx_mm.csv |
CAD: list of points x,y,z in mm (z = 0); the first and the last point are the trailing edge |
export/airfoil_NACA_xxxx_surface.vtk |
ParaView: airfoil contour in m with Cp and V/V∞ (in-house panel method) |
export/airfoil_NACA_xxxx_wing.stl |
OpenFOAM, CAD, 3D printing: the airfoil extruded along z (closed surface, in m) |
The validation script saves in Results/validation/Re<Reynolds>_Mach<Mach>/:
| File | Content |
|---|---|
validation_results.csv |
All Cl values (in-house and the four XFOIL runs), viscous Cd, the error parts and the breakdown method used |
validation_plot_cl.svg |
Cl vs alpha for each airfoil: in-house, XFOIL inviscid (Mach 0), XFOIL viscous |
validation_plot_error.svg |
Error parts vs alpha for each airfoil, with the total |
The files in export/ use the chord you entered, so they already have the real size.
CAD
- The easiest route is the DXF: import or insert it into a sketch on the plane you want. It is in millimetres and already closed (one spline that starts and ends at the trailing edge), so you can extrude it straight away. For a tapered or twisted wing, place scaled or rotated copies on parallel planes and use a loft.
- The CSV is for CAD tools that build a curve from a list of points. It is comma-separated, in millimetres, without a header. The first and the last point are both the trailing edge, so the curve is closed (some CAD tools want the last point removed or a "closed curve" option instead). Check which separator and units your CAD expects before importing.
- The STL opens as a mesh body: fine for 3D printing or as a reference, but not editable like a solid.
ParaView
- Open the
.vtkfile and press Apply. Colour byCporV_over_Vinf. - For a Cp–x/c plot use the filter Plot Data with
Points_Xon the x axis. - The values come from the in-house panel method (potential flow), also in XFOIL runs.
OpenFOAM
- Copy the
.stlintoconstant/triSurface/of your case and use it as geometry insnappyHexMeshDict. Coordinates are in metres, the wing goes from z = −span/2 to +span/2. - For a 2D case, make the background mesh thinner in z than the span, so that the wing crosses the whole domain.
- Tested with OpenFOAM v1912:
surfaceCheckreports a closed surface, one zone, consistent normals and no illegal triangles;snappyHexMeshremoves the cells inside the airfoil and ends with "Finished meshing without any errors". In our quick test the case was not set up as a proper 2D case, socheckMeshthen complains about the empty patches: that is the test case, not the geometry.
If you touch the geometry or the panel method, run:
python tests/baseline_check.pyIt compares Cl and the full Cp distribution of NACA 0012, 2412 and 4412 at three angles of attack with a saved reference. If everything matches it ends with All 24 quantities match the baseline. If a change in results is intended, delete tests/baseline_reference.json and create a new one with python tests/baseline_check.py --generate.
If you touch anything that the optimization or the terminal output depends on (search, scores, messages, inputs, export), also run:
python tests/terminal_regression_check.pyIt runs python run.py --input tests/regression_inputs.py (in-house solver, default conditions, seed 2412, about 5 s) and compares the whole terminal output, line by line, with tests/terminal_regression_reference.txt: every evaluated airfoil with its Cl and score, the final airfoil, the messages and the export summary. The repository path is replaced by <repo> and \ by /, so the reference is the same on every computer. If everything matches it ends with Terminal output identical to the reference; otherwise it prints the lines that changed. If the change is intended, delete the reference and create a new one with python tests/terminal_regression_check.py --generate. Like any run, it writes Results/Re3424658_Alpha4.0_Cl0.8_inhouse_seed2412/.
XFOIL is not part of this test: its output depends on the XFOIL executable and the platform. A different numpy version could, in rare cases, change the last printed digit of a value: if only such digits differ, check that the change comes from the environment and not from the code, then regenerate the reference.
- Potential flow has no drag. The in-house solver cannot predict drag, stall or the loss of lift caused by the boundary layer. Its Cl is usually higher than the viscous one.
- Reynolds and Mach don't change the in-house result. They are shown on screen and used in the folder name, but the panel method does not use them (no compressibility correction).
- The in-house solver cannot minimise drag yet. Only the XFOIL solver has the minimum-Cd objective; the in-house one needs a boundary-layer model first.
- Many shapes give the same Cl. The in-house search only matches the target Cl (plus the bounding box), so the airfoil it returns is one valid answer among many. The global search is random, so two runs can return different airfoils unless you enter the same seed.
- The NACA name is rounded. The optimizer works with continuous values (for example
m = 0.0190,p = 0.529,t = 0.1975is saved as "NACA 2520"). The saved geometry uses the exact values, which are printed at the end of the run and written in the.datheader and in the CSV. - XFOIL does not always converge. Airfoils where it fails get a large penalty and the search moves on.
- Three airfoil families: NACA 4-digit, NACA 5-digit (non-reflex) and CST. Reflex NACA 5-digit mean lines are not included.
- CST is slow with XFOIL and the search is short for it. With the default inputs (160 panels, seed 5) a CST run took 8 s with the in-house solver and about 10.5 minutes with XFOIL (249 evaluations, 46 crossed shapes, 34 XFOIL failures), against about 1 minute for NACA. With the same short search as NACA (5 generations), that XFOIL run ended at Cd 0.00636 for Cl 0.804, not better than a NACA 5-digit run with the same seed (Cd 0.00559, with 60 panels): more freedom of shape needs a longer search to pay off.
- XFOIL can still jump on CST shapes. With the open trailing edge a fine sweep of one coefficient gave one isolated outlier in 22 points (with a closed trailing edge the whole sweep was noisy).
- Thickness is applied perpendicular to the mean line (the standard NACA definition). XFOIL's own NACA generator adds it vertically, so its NACA airfoils differ from ours by up to 0.001 (NACA 2412) to 0.003 (NACA 23012) of the chord, near the leading edge.
- The export does not mesh or run a CFD case. It gives geometry and surface data; mesh, boundary conditions and solver setup are up to you.
Open items and planned work are tracked in TODO.md.
This section explains everything you see on screen and every number the code uses. When a value comes from the original code and was never tuned, we say so.
| Symbol | Meaning |
|---|---|
m |
Maximum camber, as a fraction of the chord |
p |
Position of the maximum camber, as a fraction of the chord |
t |
Maximum thickness, as a fraction of the chord |
NACA mptt |
Name of the airfoil: first digit = m·100, second = p·10, last two = t·100, each rounded. The name is only a label: the geometry uses the exact values |
| Alpha (α) | Angle of attack, in degrees |
| Cl | Lift coefficient |
| Cd | Drag coefficient. 1 drag count = 0.0001 of Cd |
| Cp | Pressure coefficient. In the panel method Cp = 1 − (V/V∞)² |
| ΔCp | Cp,lower − Cp,upper, both taken at the same x/c. It shows where the lift is produced along the chord |
| x/c | Position along the chord: 0 = leading edge, 1 = trailing edge |
| Re | Reynolds number = speed · chord / kinematic viscosity |
| Mach | Speed / speed of sound |
| Ncrit | XFOIL transition parameter (eⁿ method): the higher it is, the later the boundary layer becomes turbulent |
| BB | Bounding box: the maximum total height the airfoil may have, in metres. It is the distance between the highest and the lowest point of the airfoil (thickness plus camber), measured at 0° angle of attack. Typical use: the space available inside a wing. OUT in the BB column means the airfoil is taller than this limit |
| Seed | Number that fixes the random part of the search. Same seed and same inputs give the same run |
| Prefix | Meaning |
|---|---|
[+] |
A step starts or ends |
[i] |
Information (computed conditions, exact parameters, seed, where files are saved) |
[!] |
Warning or error: read it |
PHASE 1 / 2 / 3 |
Main steps: 1 = optimization, 2 = geometry and plots, 3 = pressure analysis of the final airfoil |
--> Phase 1 / Phase 2 |
The two parts of the search inside PHASE 1: Genetic Algorithm, then SLSQP |
| Eval | m | p | t | Cl | Cd | BB | Score |
| Column | Meaning |
|---|---|
| Eval | Number of the evaluation. The final message calls them "iterations": it is the total number of airfoils tried, including the ones outside the box or failed |
| m, p, t | Parameters of the airfoil being tried |
| Cl, Cd | Result of the analysis. Cd is - in the in-house solver (potential flow has no drag) |
| BB | OUT = the airfoil is taller than the bounding box. It is not analysed and gets a penalty |
| Score | The number the optimizer tries to make as small as possible (see below). Lower is better |
Special values in the Cl column:
| Value | Meaning |
|---|---|
Failed |
The analysis did not give a valid result. For XFOIL this includes "did not converge at the target angle" |
Timeout |
XFOIL took more than 30 s and was stopped |
- |
Not analysed (airfoil outside the bounding box) |
Crossed |
CST only: the upper surface goes below the lower one, so the shape is not analysed |
| Solver / objective | Score | Unit |
|---|---|---|
| In-house | (10 · (Cl − Cl_target))² | none |
| XFOIL, minimum Cd | Cd · 10⁴ + 10⁶ · Cl excess + (10⁴ · Cl excess)², where Cl excess = how far Cl is outside target ± 0.005 |
drag counts |
| XFOIL, maximum Cl | −Cl + 10⁴ · Cd excess + (10⁴ · Cd excess)², where Cd excess = how far Cd is above the limit | none (negative is normal) |
| Failed or timeout | 10⁹ + a small term that is lower for airfoils closer to t = 0.12 and m = 0.05 | none |
| Outside the box | 10⁹ + ((height − box) · 1000)² | none |
> Alpha = 4.0 deg ... [OK] In-House Cl: 0.7359 | XFOIL Cl: 0.6892 | dCl total +0.0467 = num -0.0078 | Mach -0.0098 | visc +0.0643
| Part | Meaning |
|---|---|
[OK] |
All five analyses worked |
[FAILED <run>], [TIMEOUT <run>] |
That XFOIL run failed. <run> is inviscid M0, inviscid M, viscous M0 or viscous M (M0 = Mach 0, M = real Mach) |
| XFOIL Cl | The reference: XFOIL viscous at the real Mach |
| dCl total | In-house Cl − reference. Positive = the in-house solver overestimates Cl |
| num | Numerical error of the panel method (in-house vs XFOIL inviscid, both at Mach 0) |
| Mach | Part due to compressibility, which the in-house solver ignores |
| visc | Part due to the boundary layer, which the in-house solver ignores |
(Mach first), (visc first) |
A single order was used because an intermediate run failed |
(Mach+visc combined) |
Mach and viscosity could only be computed together |
(breakdown N/A) |
Only the total is available |
| Value | Where | Why |
|---|---|---|
| Air: ν = 1.46·10⁻⁵ m²/s, a = 340.3 m/s | Fluid choice 1 | Standard atmosphere at sea level (15 °C) |
| Water: ν = 1.00·10⁻⁶ m²/s, a = 1482 m/s | Fluid choice 2 | Water at about 20 °C |
| 50 m/s, 1 m, 4°, Cl 0.8 | Default inputs | Example values from the original code. In air they give Re ≈ 3.4·10⁶ and Mach ≈ 0.15 |
| Bounding box 0.3 m | Default input | From the original code. With a 1 m chord the tallest airfoil in the search range is 0.27 m high, so by default the box never cuts anything |
| 160 panels | Default input | Accurate enough (panel-method error about 1% of Cl against XFOIL inviscid) and fast |
| 0 ≤ m ≤ 0.09 | Search range | Keeps the first digit of the NACA name a single digit |
| 0.1 ≤ p ≤ 0.7, 0.05 ≤ t ≤ 0.25 | Search range | From the original code. They cover the usual NACA 4-digit airfoils; not tuned |
| NACA 2412 | Starting airfoil, always in the initial population | Common reference airfoil, from the original code |
| Population 5, 5 generations | Genetic Algorithm | From the original code: 15 airfoils × 6 generations = 90 evaluations. A short global search is enough because SLSQP refines the result |
| SLSQP: max 50 iterations, ftol 10⁻⁴ | Local search | From the original code; not tuned |
| Step 10⁻⁴ (in-house), 2·10⁻³ (XFOIL) | SLSQP finite differences | XFOIL writes Cl with 4 decimals. With a step of 10⁻⁴ the change of Cl due to p and t is below 0.0001, so the gradient came out as zero and the search stopped early. The panel method has no such limit |
| Weight 10 | In-house score | From the original code. It only scales the score: the best airfoil does not change |
| 10⁹ | Score of failed and out-of-box airfoils | Must be higher than any valid airfoil. The worst valid score is about 4·10⁸ (Cl 2.0 away from the target), so 10⁹ always ranks a valid airfoil first |
| Small term towards t = 0.12, m = 0.05 | Failed airfoils | From the original code: among failed airfoils it prefers usual shapes, so the search moves back towards shapes that converge |
| (excess · 1000)² | Out-of-box penalty | Grows with the excess height, so the search knows which way to go back |
| ± 0.005 | Cl tolerance, minimum-Cd objective | 0.6% of a Cl of 0.8: well above XFOIL's resolution (0.0001) and small enough to keep the target meaningful. An exact Cl would be impossible to hit numerically |
| 10⁶ | Linear Cl penalty weight, minimum-Cd objective | 0.0001 of Cl outside the tolerance costs 100 drag counts, from the very edge of the tolerance. With the quadratic term alone the penalty is flat at the edge, so going slightly outside paid off: with seed 657086 the final Cl was 0.7947 (0.0003 outside = 9 counts of penalty) for about 9 counts of Cd saved. With the linear term the same run ends at Cl 0.7989. Over six seeds (657086, 1, 2, 3, 42, 2412) it changes only that run: the other five give the same airfoil as before |
| 10⁴ | Quadratic Cl penalty weight, minimum-Cd objective | 0.001 of Cl outside the tolerance costs 100 drag counts more, and the penalty grows fast further out |
| 10⁴ | Linear Cd penalty weight, maximum-Cl objective | 1 drag count above the limit costs 1.0 of Cl, from the very edge of the limit. Near the default limit the search gains about 0.024 of Cl per count, so going above it never pays off. With the quadratic term alone the penalty was flat at the edge: with the default limit the final Cd was 0.00601 (seed 42), and with a limit of 0.0065 it was up to 2.4 counts above |
| 10⁴ | Quadratic Cd penalty weight, maximum-Cl objective | 1 drag count above the limit costs 1.0 of Cl more, and the penalty grows fast further out |
| Cd 0.006 | Default limit, maximum-Cl objective | Chosen so that the limit drives the result at the default conditions. Without an effective limit (the old default 0.02) the search ends at the highest camber of the search range, Cl ≈ 1.59 with Cd ≈ 0.007, so any limit above ≈ 0.007 has no effect. With 0.006 the final Cd sits just below the limit (0.00597 and 0.00596) and Cl ≈ 1.21–1.28 (seeds 42 and 1). The starting airfoil NACA 2412 (Cd 0.00591) is inside the limit, so the search starts from an allowed airfoil. Below the Cd of NACA 2412 (e.g. 0.0055) runs with different seeds ended far apart (Cl 0.82 and 0.70, measured before the linear Cd penalty was added) |
| Ncrit = 9 | XFOIL | XFOIL's default, the usual value for an average wind tunnel |
| ITER 500 | XFOIL | Maximum viscous iterations per angle, from the original code |
| 1° steps up to the target angle | XFOIL | XFOIL converges more easily when each angle starts from the previous solution. From the original code |
| 0.1° | Angle tolerance | If XFOIL's closest converged angle is further than this from the target, its Cl belongs to another angle and the evaluation counts as failed |
| 30 s | XFOIL timeout | From the original code. A normal XFOIL run takes about a second |
| 1 – 999 999 | Random seed | Any integer works; the range just keeps it short to type |
| 10⁻⁹ | Baseline tolerance (tests/) |
Far above round-off (we see about 10⁻¹⁵) and far below a real change (a deliberate small error in the code changed Cp by 2·10⁻⁵) |
| NACA 0012, 2412, 4412 | Validation airfoils | Symmetric, mild camber, higher camber |
| mm (DXF, CSV), m (VTK, STL) | Export units | CAD programs work in millimetres; OpenFOAM and ParaView in SI units |
| Span = chord | Default for the STL | A square planform is a neutral starting point; it only sets the length of the extrusion |
| 399 points | DXF, CSV, STL | Same points as the .dat file. The DXF spline stays within 0.01 mm of the exact NACA shape for a 250 mm chord |
| −0.1036 | Last thickness coefficient of the exported airfoil (closed trailing edge) | Standard closed-trailing-edge variant of the NACA formula: the coefficients add up to zero, so the thickness is zero at x/c = 1 and the profile is closed for CAD, STL and meshing |
| −0.1015 (open trailing edge) | Geometry used by the analyses | The original NACA formula, also used by XFOIL's own NACA airfoils. With a sharp trailing edge XFOIL's viscous solution is not reliable: for m = 0.03, p = 0.4 and t from 0.1200 to 0.1240 (steps of 0.0004) Cl jumped between 0.80 and 0.65, with or without XFOIL's own re-paneling, while with the open trailing edge it goes smoothly from 0.826 to 0.820. In an optimization test (six seeds, minimum Cd at Cl 0.8) the closed trailing edge gave a worse airfoil in four runs out of six (up to Cd 0.0116 instead of 0.0065) and one run outside the Cl tolerance |
| −4° to 10°, step 2° | Validation sweep | From the original code |
- No valid result: if no airfoil was analysed successfully, the run stops with
[!] No airfoil could be analysed successfullyinstead of reporting a meaningless airfoil. - Final checks (XFOIL): after the search, XFOIL runs once more on the best airfoil. A warning appears if it does not converge, if it converges at another angle, if Cl is outside the tolerance (minimum-Cd objective) or if Cd is above the limit (maximum-Cl objective).
- Missing libraries: the script asks before installing them with pip. Answer no and it prints the command to run yourself.
- Invalid input: the optimizers stop. With an input file they stop before the environment checks, with a message that names the wrong key. The validation script instead falls back to fixed values (Re 10⁶, Mach 0, alpha −4° to 10°), which are not the same as its prompt defaults.
- Trailing edge: open in the analyses, closed (sharp) in the airfoil you get back (
.dat, plots, DXF, CSV, STL), see Geometry. The ParaView file (.vtk) carries the Cp of the analysis, so its points are those of the open trailing edge. A contour with a gap would still be exported closed (a straight line in the DXF, flat faces in the STL).
- XFOIL is developed by Mark Drela and Harold Youngren (MIT) and released under the GNU General Public License.