Repository navigation
fix: validated CLI flap polars without silent fallback #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aeronauty-flexcompute
merged 14 commits into
codex/solver-docs-review
from
harry/rustfoil-cli-flap
Oct 14, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9694a76
feat(rustfoil-cli): add --flap option to polar and faithful-polar
aeronauty 62b263e
Fix CLI flap validation and temp race
cursoragent 0525b84
Merge branch 'codex/solver-docs-review' into codex/flap-validation
aeronauty 06a169e
fix: reject invalid CLI flaps before producing polar output
aeronauty c26bb06
Merge reviewed docs base and verified lock metadata
aeronauty 9892e2f
fix: preserve run history and match cache provenance
aeronauty 5a6b482
Merge branch 'codex/solver-docs-review' into codex/flap-validation
aeronauty b0522fa
Merge branch 'codex/flap-validation' into codex/preserve-run-cache
aeronauty 4f05bb9
fix: match canonical wall-shear drag to XFOIL CDCALC
aeronauty 8c5ec25
fix: reject short flap buffers and heal inviscid contours
aeronauty ad4a361
Merge branch 'codex/flap-validation' into codex/preserve-run-cache
aeronauty 5a056e4
Merge branch 'codex/preserve-run-cache' into codex/reference-drag-com…
aeronauty 8ca9796
Merge pull request #40 from flexcompute/codex/reference-drag-components
aeronauty-flexcompute bda3db5
Merge pull request #39 from flexcompute/codex/preserve-run-cache
aeronauty-flexcompute File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| use std::process::Command; | ||
| use std::path::Path; | ||
|
|
||
| #[test] | ||
| fn invalid_flaps_fail_before_any_polar_or_file_access() { | ||
| for mode in ["polar", "faithful-polar"] { | ||
| for spec in ["0.72:0.5", "0.72:0.5:12deg", "nan:0.5:12", "0.72:inf:12", "0.72:0.5:nan", "0:0.5:12", "1:0.5:12", "-0.1:0.5:12", "0.72:0.5:inf", "0.72:1.5:12", "0.72:-0.1:12"] { | ||
| let output = Command::new(env!("CARGO_BIN_EXE_rustfoil")) | ||
| .args([mode, "/file-that-does-not-exist.dat", "--flap", spec]).output().unwrap(); | ||
| assert!(!output.status.success(), "{mode}: {spec}"); | ||
| assert!(output.stdout.is_empty(), "must not print an unflapped polar"); | ||
| let error = String::from_utf8_lossy(&output.stderr); | ||
| assert!(error.contains("finite hinge_x"), "{mode}: {spec}: {error}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn valid_flap_changes_polar_and_zero_deflection_preserves_it() { | ||
| let foil = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../testdata/naca0012.dat"); | ||
| let run = |flap: Option<&str>| { | ||
| let mut command = Command::new(env!("CARGO_BIN_EXE_rustfoil")); | ||
| command.arg("polar").arg(&foil).args(["--alpha-start", "4", "--alpha-end", "4"]); | ||
| if let Some(spec) = flap { command.args(["--flap", spec]); } | ||
| let output = command.output().unwrap(); | ||
| assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr)); | ||
| output.stdout | ||
| }; | ||
| assert_eq!(run(None), run(Some("0.72:0.5:0"))); | ||
| assert_ne!(run(None), run(Some("0.72:0.5:12"))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn nonzero_flap_on_a_short_contour_is_rejected() { | ||
| let path = std::env::temp_dir().join(format!("rustfoil-short-flap-{}.dat", std::process::id())); | ||
| std::fs::write(&path,"short\n1 .01\n.5 .1\n0 0\n.5 -.1\n1 -.01\n").unwrap(); | ||
| for mode in ["polar", "faithful-polar"] { | ||
| let mut command = Command::new(env!("CARGO_BIN_EXE_rustfoil")); | ||
| command.arg(mode).arg(&path).args(["--flap","0.72:0.5:12"]); | ||
| if mode == "faithful-polar" { command.args(["--alpha","0:0:1","--re","1000000"]); } | ||
| let output = command.output().unwrap(); | ||
| assert!(!output.status.success()); | ||
| assert!(output.stdout.is_empty()); | ||
| assert!(String::from_utf8_lossy(&output.stderr).contains("at least six contour points")); | ||
| } | ||
| std::fs::remove_file(path).unwrap(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn inviscid_cli_flap_matches_the_healed_sdk_geometry() { | ||
| use rustfoil_core::{point, Body, CubicSpline, PanelingParams}; | ||
| use rustfoil_solver::inviscid::{FlowConditions, InviscidSolver}; | ||
| let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../testdata/naca0012.dat"); | ||
| let text=std::fs::read_to_string(&path).unwrap(); | ||
| let points:Vec<_>=text.lines().skip(1).filter(|line| !line.trim().is_empty()).map(|line| { | ||
| let values:Vec<f64>=line.split_whitespace().map(|value|value.parse().unwrap()).collect(); | ||
| point(values[0],values[1]) | ||
| }).collect(); | ||
| let buffer=rustfoil_core::flap::xfoil_flap(&points,0.72,0.5,12.); | ||
| let healed=CubicSpline::from_points(&buffer).unwrap().resample_xfoil(points.len(),&PanelingParams::default()); | ||
| let body=Body::from_points("SDK reference",&healed).unwrap(); | ||
| let expected=InviscidSolver::new().solve(&[body],&FlowConditions::with_alpha_deg(4.)).unwrap(); | ||
| let output=Command::new(env!("CARGO_BIN_EXE_rustfoil")).arg("polar").arg(path).args(["--alpha-start","4","--alpha-end","4","--flap","0.72:0.5:12"]).output().unwrap(); | ||
| assert!(output.status.success()); | ||
| let stdout=String::from_utf8(output.stdout).unwrap(); | ||
| let values:Vec<f64>=stdout.lines().last().unwrap().split_whitespace().map(|value|value.parse().unwrap()).collect(); | ||
| assert!((values[1]-expected.cl).abs()<5.1e-5); | ||
| assert!((values[2]-expected.cm).abs()<5.1e-5); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| title: CLI trailing-edge flap | ||
| --- | ||
|
|
||
| import SourceCode from '@site/src/components/SolverGate/SourceCode'; | ||
| import FlapInspector from '@site/src/components/Flap/Inspector'; | ||
|
|
||
| ## What it is | ||
|
|
||
| `rustfoil polar` and `rustfoil faithful-polar` accept `--flap hinge_x:hinge_y_fraction:deflection_degrees`. The CLI validates the flag before reading the airfoil or printing a polar. Hinge x is a chord fraction strictly between zero and one; hinge y is a local thickness fraction between zero (lower surface) and one (upper). Deflection is a finite number in degrees, positive downward. Bad flags exit nonzero rather than returning an unflapped result. The original airfoil name is retained. | ||
|
|
||
| The input contour can use any consistent coordinate unit. `xfoil_flap` computes its chord from the minimum and maximum x, finds the hinge by spline intersection, rotates aft points, and heals the contour. It returns points in the input coordinate frame and units. This is a single contour transformation, not an interacting multi-element solver. | ||
|
|
||
| ## Theory | ||
|
|
||
| The core follows XFOIL GDES FLAP/GETXYF. Let the hinge be $(x_h,y_h)$ and the clockwise deflection be $\delta$ in radians. The rigid rotation step is: | ||
|
|
||
| $$ | ||
| \begin{bmatrix}x'\\y'\end{bmatrix}=\begin{bmatrix}x_h\\y_h\end{bmatrix}+\begin{bmatrix}\cos\delta&\sin\delta\\-\sin\delta&\cos\delta\end{bmatrix}\begin{bmatrix}x-x_h\\y-y_h\end{bmatrix}\label{eq:cli-flap-rotation} | ||
| $$ | ||
|
|
||
| Equation $\eqref{eq:cli-flap-rotation}$ preserves distance from the hinge. Zero deflection leaves the contour unchanged. The full contour operation also performs intersection and point deletion/insertion around the hinge; the widget illustrates only the rotation. Source: [official XFOIL 6.99 GDES implementation](https://web.mit.edu/drela/Public/web/xfoil/), `xgdes.f` FLAP/GETXYF. | ||
|
|
||
| ## Code and working call | ||
|
|
||
| ```sh | ||
| cargo run --release -p rustfoil-cli -- polar testdata/naca0012.dat \ | ||
| --alpha-start 4 --alpha-end 4 --flap 0.72:0.5:12 | ||
| cargo run --release -p rustfoil-cli -- faithful-polar testdata/naca0012.dat \ | ||
| --alpha 0:8:2 --re 1000000 --mach 0 --flap 0.72:0.5:12 | ||
| ``` | ||
|
|
||
| Both commands apply the real Rust geometry transformation. The faithful command uses the Rust faithful solver, not a temporary file handed to an external XFOIL executable. Polar convergence must be checked; a valid flap flag alone does not establish numerical or physical accuracy. | ||
|
|
||
| <SourceCode path="crates/rustfoil-cli/src/main.rs" name="parse_flap_spec" /> | ||
| <SourceCode path="crates/rustfoil-cli/src/main.rs" name="prepare_cli_flap" /> | ||
| <SourceCode path="crates/rustfoil-cli/src/main.rs" name="run_polar" /> | ||
| <SourceCode path="crates/rustfoil-cli/src/main.rs" name="run_faithful_polar" /> | ||
| <SourceCode path="crates/rustfoil-core/src/flap.rs" name="xfoil_flap" /> | ||
|
|
||
| ## Interactive rotation | ||
|
|
||
| <FlapInspector /> | ||
| <SourceCode path="docs-site/src/components/Flap/Inspector.jsx" name="FlapInspector" /> | ||
|
|
||
| ## Why and limits | ||
|
|
||
| Use Clap's shared value parser for both commands so invalid specifications cannot fall through to a different geometry. Reject NaN/infinity and out-of-range fractions at the CLI boundary instead of relying on the core's y-fraction clamp. Preserve the existing XFOIL-style spline/contour operation rather than adding another flap algorithm. Tests exercise the compiled CLI: bad flags print no polar, valid deflection changes the inviscid result, and zero deflection preserves it. Those tests do not establish complete XFOIL equivalence for every flap or validate stalled/flapped viscous flow. | ||
|
|
||
| A requested nonzero flap requires at least six finite contour points; short contours fail before polar output instead of silently dropping the flap. The geometry function returns a buffer with an opening-side break for later spline healing. Nonzero inviscid flaps are healed with the existing XFOIL-style spline repaneler at the original point count before Body construction. Faithful polars use their existing requested-panel repaneling step. Zero deflection retains the original inviscid points. A compiled CLI regression compares inviscid coefficients with the same documented SDK geometry/solver path; it does not claim full XFOIL flap equivalence. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.