transport-wings-500 / wing_generation_explained.md
ecopus's picture
Upload wing_generation_explained.md
b3e7be2 verified
# How the 500 Wing Samples Are Generated
This document explains how the Python pipeline creates the **500 aircraft‑style wings** in your dataset—what varies, what’s fixed, and the exact math behind the values stored.
---
## 1) Inputs & Reproducibility
- **Airfoil geometry**: Each airfoil file contains two columns \((x, y)\) forming a closed perimeter ordered **TE → upper → LE → lower → TE**.
- On load, \(x\) is normalized to \([0,1]\); the perimeter is rotated so the first point is closest to the **trailing edge** \((1,0)\) and the **upper surface** comes first.
- **Polars (optional)**: QBlade/XFOIL exports with \(\alpha, C_l, C_d, C_m\).
- Files are matched to airfoils by flexible filename heuristics.
- Polars are parsed (3–4 numeric columns), **deduplicated in \(\alpha\)**, and **sorted by \(\alpha\)**.
- **Random seed**: We use `np.random.default_rng(42)` so all 500 wings are reproducible bit‑for‑bit.
---
## 2) Per‑Wing Planform Sampling (What Varies)
We generate **500** wings. Airfoils are cycled round‑robin (≈50 wings per foil). For each wing we sample:
- **Half‑span** \(s\) (inches):
\(s \sim \mathcal{U}[60,\;120]\).
- **Root chord** \(c_{\text{root}}\) (inches):
\(c_{\text{root}} \sim \mathcal{U}[18,\;36]\).
- **Taper ratio** \(\lambda\):
\(\lambda \sim \mathcal{U}[0.25,\;0.50]\), so \(c_{\text{tip}}=\lambda\,c_{\text{root}}\).
- **Twist endpoints (washout)** (degrees):
\(i_{\text{root}} \sim \mathcal{U}[0,\;2]\), \(i_{\text{tip}} \sim \mathcal{U}[-6,\;-2]\).
- The final twist distribution is **linear** from root to tip; then we **pin** the very first station to **0°** so the wing “hinges” at the root plane (legacy convention).
We use **20 stations** along the half‑span:
\[
\text{Dis}[j] = y_j = \frac{j-1}{19}\; s,\quad j=1..20.
\]
---
## 3) Chord Distribution: Schrenk’s Approximation
We blend a trapezoid with an ellipse to approximate an elliptical lift distribution:
- Linear (trapezoid) chord:
\[
c_{\text{trap}}(y) = c_{\text{root}} + (c_{\text{tip}} - c_{\text{root}})\,\frac{y}{s}.
\]
- Elliptic surrogate:
\[
c_{\text{ell}}(y) = c_{\text{root}}\sqrt{1 - \left(\frac{y}{s}\right)^2}.
\]
- **Schrenk chord** at each station:
\[
c(y) = \tfrac{1}{2}\left[c_{\text{trap}}(y) + c_{\text{ell}}(y)\right].
\]
A small clamp prevents pathological tips for extreme tapers:
\[
c(y) \leftarrow \max\!\big(c(y),\;0.25\cdot\min\nolimits_y c_{\text{trap}}(y)\big).
\]
This yields the **Cho** vector (inches) over the 20 stations.
---
## 4) Twist (Washout) Distribution
With sampled endpoints \(i_{\text{root}}\) and \(i_{\text{tip}}\), define a **linear** twist:
\[
\text{Twi}[j] = i_{\text{root}} + \big(i_{\text{tip}} - i_{\text{root}}\big)\frac{y_j}{s},\quad j=1..20.
\]
Then set \(\text{Twi}[1]=0^\circ\) (root plane hinge).
---
## 5) Lofting the 3D Wing for Previews
Given the normalized perimeter \((\bar{x},\bar{y})\) (TE→upper→LE→lower→TE), we scale and twist each section about the **quarter‑chord** \(x_{\text{pivot}}=0.25\):
1. Shift section to pivot origin: \(x_c = \bar{x} - 0.25\).
2. Scale to local chord \(c_j\) (inches): \(X_s = x_c\,c_j,\; Y_s = \bar{y}\,c_j\).
3. Rotate by \(\theta_j=\text{Twi}[j]\cdot\pi/180\):
\[
\begin{bmatrix} Y \\ Z \end{bmatrix}
= \begin{bmatrix} \cos\theta_j & -\sin\theta_j \\ \sin\theta_j & \cos\theta_j \end{bmatrix}
\begin{bmatrix} X_s \\ Y_s \end{bmatrix}.
\]
4. Spanwise coordinate for the whole perimeter at station \(j\): \(S=y_j\) (inches).
The arrays \(S, Y, Z\) generate a fast **wireframe 3D PNG** used as the dataset’s `render_png` field.
---
## 6) Planform Integrals & Derived Metrics
Treat `Dis`/`Cho` as samples over the **half‑span** \([0,s]\) in **inches**. We integrate with the trapezoidal rule, then convert to SI for storage.
- **Wing area** (full wing):
\[
S_{\tfrac{1}{2}} = \int_0^s c(y)\,dy \;\approx\; \operatorname{trapz}(\text{Dis},\text{Cho})\quad [\text{in}^2],
\qquad
S_{\text{full}} = 2\,S_{\tfrac{1}{2}}.
\]
Convert: \(S_{\text{full (m}^2)} = S_{\text{full}}\cdot(0.0254)^2\).
- **Mean Aerodynamic Chord** (full wing):
\[
\text{MAC} = \frac{2}{S_{\text{full}}} \int_{-s}^{s} c(y)^2\,dy
= \frac{4}{S_{\text{full}}} \int_0^s c(y)^2\,dy.
\]
We integrate on the half‑span (inches), then convert MAC to meters.
- **Aspect Ratio** (full span \(b=2s\cdot 0.0254\) meters):
\[
\text{AR} = \frac{b^2}{S_{\text{full (m}^2)}}.
\]
- **Polar‑derived metrics** (if a polar is found):
- \(C_{l,\max}=\max C_l\) at \(\alpha_{C_{l,\max}}\).
- \(C_{d,\min}=\min C_d\) at \(\alpha_{C_{d,\min}}\).
- \((L/D)_{\max} = \max(C_l/C_d)\) at \(\alpha_{(L/D)_{\max}}\).
- Small‑angle lift slope and zero‑lift angle (linear fit on \(\alpha\in[-5^\circ,5^\circ]\)):
\[
C_l \approx m\,\alpha_{\deg} + b
\;\Rightarrow\;
C_{l_\alpha}\;[\text{per rad}] = m\cdot \frac{180}{\pi},
\quad
\alpha_{0L}\;[^\circ] = -\frac{b}{m}.
\]
- Also stored as objective‑style **scores**:
- `score_min_cd = min(C_d)`
- `score_max_cl = max(C_l)`
- `score_max_ld = max(C_l/C_d)`
If a polar is not found, these fields are **NaN**; geometry is still fully populated.
---
## 7) Station Count & Units
- **Stations**: always **20** over the half‑span (keeps compatibility with legacy builders).
- **Units**: dataset stores **SI** (`dis_m`, `chord_m`, `span_m`, `area_m2`, `mac_m`). Inches are used internally during generation for readability and then converted.
---
## 8) Image Preview Column
Each wing includes a 3D wireframe PNG (`render_png`) created from the lofted \(S,Y,Z\) arrays:
- Section loops at every station,
- ~14 spanwise polylines to suggest the surface,
- Isometric view (elev \(20^\circ\), azim \(35^\circ\)),
- Title string with span, root/tip chords, and taper.
This renders directly in the Hugging Face Dataset viewer.
---
## 9) Why These Look Like Transport Wings
- **Aspect ratio** typically in the 7–11 range (after area settles) due to sampled spans/cords.
- **Taper** \(0.25\to 0.50\) and **washout** \(-6^\circ\to -2^\circ\) are characteristic of transport wings aimed at cruise efficiency and benign stall.
- **Quarter‑chord pivot** is the standard torsion axis.
- **Schrenk chord** smooths the planform compared to pure linear taper, approximating more elliptical loading.
---
## 10) Worked Example (Representative Draw)
Let \(s=100\) in, \(c_{\text{root}}=30\) in, \(\lambda=0.35 \Rightarrow c_{\text{tip}}=10.5\) in, stations=20.
Twist endpoints: \(i_{\text{root}}=1.0^\circ\), \(i_{\text{tip}}=-4.0^\circ\), then \(\text{Twi}[1]=0^\circ\).
Mid‑span chord \(y=50\) in:
\[
c_{\text{trap}}(50) = 30 + (10.5-30)\cdot 0.5 = 20.25\text{ in},\quad
c_{\text{ell}}(50) = 30\sqrt{1-0.5^2} \approx 25.98\text{ in},
\]
\[
c(50) \approx \tfrac{1}{2}(20.25+25.98) \approx 23.11\text{ in}.
\]
If \(S_{\text{full}} \approx 5000\;\text{in}^2 \Rightarrow S_{\text{full}} \approx 3.226\;\text{m}^2\) and full span \(b=200\) in \(=5.08\) m, then:
\[
\text{AR} = \frac{b^2}{S} \approx \frac{(5.08)^2}{3.226} \approx 8.0.
\]
MAC comes from the \(c(y)^2\) integral and is often in the \(0.3\text{–}0.5\) m range here.
---
## 11) What Makes Each of the 500 Unique?
- **Airfoil choice** (≈50 samples per foil) → geometry & polar behavior differ.
- **Planform**: each wing draws a new \((s,\;c_{\text{root}},\;\lambda)\) → different area, AR, MAC.
- **Twist**: each wing draws \((i_{\text{root}}, i_{\text{tip}})\) → different load tendency.
- **Performance summaries**: objective‑style scores (\(\min C_d\), \(\max C_l\), \(\max C_l/C_d\)) and the \(\alpha\) at which they occur differ per wing.
---
### Notes for Objective‑Conditioned Training
To bias toward a given objective at training time:
- **Condition** on `objective ∈ {min Cd, max Cl, max Cl/Cd}` and **airfoil** (name or perimeter).
- Use the scalar **scores** as targets (e.g., regress `score_min_cd`) or form **ranking** pairs within the same airfoil.
- Optionally **post‑select** the top‑k wings per airfoil by the chosen objective as exemplar targets.