Skip to main content

hpr_aero/
blunt_tip.rs

1//! A blunt or vertical nose tip faster than sound: modified Newtonian pressures on the cap, handed
2//! over to the second-order shock-expansion method ([`crate::shock_expansion`]) where the surface
3//! slope falls to the steepest wedge an attached shock can turn. After C. M. Jackson Jr.,
4//! W. C. Sawyer and R. S. Smith, *A Method for Determining Surface Pressures on Blunt Bodies of
5//! Revolution at Small Angles of Attack in Supersonic Flow*, NASA TN D-4865 (1968) ([J68]).
6//!
7//! **Flown faster than sound** since the milestone
8//! [M1.8e7](https://hpr.fusionspace.co/decisions-and-roadmap.html#m1-8e7), for noses whose
9//! tip is vertical (power-series noses with `n < 1`, Haack series, elliptical noses) through
10//! [`crate::model::SupersonicBody`]. The guide's
11//! [Blunt tips](https://hpr.fusionspace.co/physics/aero.html#blunt-tips) explains it and
12//! how it was checked.
13//!
14//! ```
15//! use hpr_aero::blunt_tip::{handover_angle_rad, newtonian_loading, pitot_pressure_ratio};
16//!
17//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
18//! // Behind a normal shock at Mach 2 the pitot pressure is 5.640 times the free stream's
19//! // (NACA Report 1135, Table II).
20//! assert!((pitot_pressure_ratio(2.0)? - 5.6404).abs() < 1e-4);
21//! // The cap hands over where its slope falls to the steepest wedge an attached shock turns
22//! // at Mach 1.5, 12.1°.
23//! assert!((handover_angle_rad(1.5)?.to_degrees() - 12.11).abs() < 0.01);
24//! // Where the cap's slope is 45° its loading is C_p,max/2, 0.829 at Mach 2.
25//! let loading = newtonian_loading(2.0, 45f64.to_radians())?;
26//! assert!((loading - 0.8286).abs() < 1e-4);
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! **The cap.** Near a blunt tip the shock stands off the body and the flow behind it is subsonic,
32//! where the shock-expansion method, which marches supersonic flow from a pointed tip, can't
33//! start. The report's cap is modified Newtonian (eq. 1, p. 5):
34//!
35//! `p_s/p₀ = (p_t2/p₀ − 1) sin²δ + 1`,
36//!
37//! with `δ` the surface's slope to the wind and `p_t2` the pitot pressure behind a normal shock
38//! (the Rayleigh pitot formula, NACA Report 1135, 1953, eq. 100, p. 619):
39//!
40//! `p_t2/p₀ = [(γ + 1)M²/2]^(γ/(γ − 1)) · [(γ + 1)/(2γM² − (γ − 1))]^(1/(γ − 1))`.
41//!
42//! In coefficient form `C_p = C_p,max sin²δ`, `C_p,max = (p_t2/p₀ − 1)/(γM²/2)`.
43//!
44//! **The handover.** The shock-expansion method starts "at the point where the surface slope is
45//! the same as that required for shock attachment to a two-dimensional wedge at the free-stream
46//! Mach number", chosen "simply because it gave the best agreement with the available data in the
47//! low supersonic-speed range" (p. 5): the wedge's largest deflection `δ_max`, from the shock angle
48//! of NACA Report 1135 eq. 168 (p. 624),
49//!
50//! `sin²θ = [(γ + 1)M²/4 − 1 + √((γ + 1)((γ + 1)M⁴/16 + (γ − 1)M²/2 + 1))]/(γM²)`,
51//!
52//! turned into a deflection by eq. 138 (p. 621), `tan δ = 2 cot θ (M² sin²θ − 1)/(2 + M²(γ + 1 −
53//! 2 sin²θ))`. It is 12.1° at Mach 1.5 and 22.97° at Mach 2. HPR Sim hands over at the lesser of
54//! `δ_max` and 24° ([`MAX_HANDOVER_RAD`]), so from Mach 2.06 up the cap reaches further aft than
55//! the report's. The cap is a cap because the method reads the tangent cone's normal-force slope
56//! at the handover, and those tables ([`crate::shock_expansion::cone_normal_force_slope`]) once
57//! stopped at TN 3527 Fig. 2's 24°. They now reach 30° ([`CONE_TABLE_CAP_RAD`]), and the
58//! handover doesn't, because the march does not carry it there yet: measured over the whole
59//! sweep in [ADR-043][adr-043], a 30° handover reads nearer TN D-4865's own sphere-cone at every
60//! row where a cap binds at all, and on the committed Arcas Robin nose above about Mach 4 it puts
61//! most of the march's elements into `η < 0`
62//! ([issue #108](https://github.com/nrdptel/fusionspace-eridanus/issues/108)), where the answer moves with the
63//! element count. No cap above 24° holds its answer to Mach 5, and the failure isn't orderly in
64//! the cap: 28° is the worst of the four measured. [`handover_angle_capped_rad`] takes the cap as
65//! a parameter so both ends are measured rather than argued.
66//!
67//! **The flow behind it: HPR Sim's choice, not the report's.** HPR Sim starts TN 3527's march at the
68//! handover as the method starts at a pointed vertex: with the flow on the cone tangent to the
69//! body there (Taylor–Maccoll), that cone's loading `tan δ (dC_N/dα)_tc`, and no pressure gradient
70//! (TN 3527 sketch (a), p. 6). The report starts it from the Newtonian pressure and Mach number
71//! instead (eq. 2 and p. 5). Read that way at `α → 0`, the march on the committed Arcas Robin nose
72//! reduces elements from Mach 2.96 ([issue #81](https://github.com/nrdptel/fusionspace-eridanus/issues/81),
73//! the method's open question there), so its answer changes as elements are added, and
74//! fails from Mach 3.96, where the Newtonian pressure at the handover lies below the tangent
75//! cone's; the tangent cone's start holds to Mach 5 and converges. [`crate::shock_expansion::HandoverStart`] keeps the report's start to compare,
76//! and the decision record on it, [ADR-038][adr-038], gives both readings' numbers.
77//!
78//! **The loading at `α → 0`.** On the cap, TN 3527's loading form ([`crate::shock_expansion`]),
79//! whose `C_Nα = (2π/A_ref) ∫ Λ r dx` makes `Λ` half the windward meridian's `∂C_p/∂α`, takes
80//! the wind's slope `δ + α cos φ` in `C_p = C_p,max sin²δ`: `Λ = C_p,max sin δ cos δ`
81//! ([`newtonian_loading`]). A hemisphere then carries `C_Nα = C_p,max/2`, its Newtonian drag turned
82//! into the body's axes, as it must. Behind the handover the loading is the method's. The handover
83//! itself is held where it sits on the body, as TN 3527 holds every other point; the report's
84//! equivalent bodies turn the body about the sphere's center, sliding the handover along the
85//! surface, and that term is left out. Nothing here measures what it is worth.
86//!
87//! **What it covers.** The report checked spherical caps only: a sphere-cone (a 0.175-diameter
88//! nose radius on an 11.5° cone) and a sphere on a flared body, from Mach 1.50 to 4.63 and up to
89//! 12°, calling its results "adequate engineering estimates … except where flow separation or
90//! detached secondary shock waves are present" (p. 13). A power-series, Haack or elliptical nose
91//! has no sphere at its tip; applying the slope rule to it is an extrapolation, stated. The
92//! wedge's deflection, the pitot pressure and the Newtonian pressure are exact for a perfect gas
93//! with `γ = 1.4`; the loading is only as good as Newtonian theory on the cap. A cap that shrinks
94//! to nothing doesn't reach the cone it sits on, because the march keeps its start cone's total
95//! pressure ([issue #101](https://github.com/nrdptel/fusionspace-eridanus/issues/101)), and near the join's
96//! start the cap can cover half a slender nose, far more than the report's own.
97//!
98//! [J68]: https://ntrs.nasa.gov/citations/19690000884
99//! [adr-038]: https://github.com/nrdptel/fusionspace-eridanus/blob/main/docs/DECISIONS.md#adr-038-blunt-and-vertical-nose-tips-faster-than-sound-by-a-newtonian-cap-the-method-started-from-the-tangent-cone-2026-09-19
100//! [adr-043]: https://github.com/nrdptel/fusionspace-eridanus/blob/main/docs/DECISIONS.md#adr-043-the-blunt-tips-handover-cap-what-it-is-worth-and-what-stops-it-moving-2026-09-20
101
102use crate::afterbody::GAMMA;
103use crate::error::AeroError;
104
105/// The steepest slope the cap hands over at, as HPR Sim flies it: 24°. It was TN 3527 Fig. 2's
106/// steepest tangent cone, the steepest whose normal-force slope the method could read; since the
107/// milestone [M1.8e11](https://hpr.fusionspace.co/decisions-and-roadmap.html#m1-8e11),
108/// which took the cone slopes to 30°, the tables reach [`CONE_TABLE_CAP_RAD`], and 24° is kept
109/// because that is as far as the march carries the handover, not as far as the tables do
110/// ([ADR-043: what the handover's cap is worth][adr-043]).
111///
112/// [adr-043]: https://github.com/nrdptel/fusionspace-eridanus/blob/main/docs/DECISIONS.md#adr-043-the-blunt-tips-handover-cap-what-it-is-worth-and-what-stops-it-moving-2026-09-20
113pub const MAX_HANDOVER_RAD: f64 = 24.0 * std::f64::consts::PI / 180.0;
114
115/// The steepest cap the method can be given, 30°: the steepest cone its normal-force slopes
116/// cover ([`crate::shock_expansion::cone_normal_force_slope`]), where NASA SP-3007's tables stop
117/// ("cone angles from 2.5° to 30°", Foreword, p. iii). A handover steeper than this has no
118/// tangent cone to start the march from.
119pub const CONE_TABLE_CAP_RAD: f64 = 30.0 * std::f64::consts::PI / 180.0;
120
121/// The Mach number must be finite and above 1: the cap stands behind a normal shock.
122fn check_mach(mach: f64) -> Result<(), AeroError> {
123    if mach.is_finite() && mach > 1.0 {
124        Ok(())
125    } else {
126        Err(AeroError::Domain {
127            what: "Mach number of a blunt tip's cap",
128            value: mach,
129        })
130    }
131}
132
133/// A slope to the wind within `[0, π/2]`.
134fn check_slope(slope_rad: f64) -> Result<(), AeroError> {
135    if slope_rad.is_finite() && (0.0..=std::f64::consts::FRAC_PI_2).contains(&slope_rad) {
136        Ok(())
137    } else {
138        Err(AeroError::Domain {
139            what: "surface slope on a blunt tip's cap",
140            value: slope_rad,
141        })
142    }
143}
144
145/// The pitot pressure behind a normal shock over the free stream's, `p_t2/p₀`, at Mach `mach`
146/// (the Rayleigh pitot formula, NACA Report 1135 eq. 100, p. 619; TN D-4865 eq. 1).
147///
148/// # Errors
149///
150/// [`AeroError::Domain`] for a Mach number that isn't finite and above 1, or so large (past about
151/// 1e76) that the ratio overflows.
152pub fn pitot_pressure_ratio(mach: f64) -> Result<f64, AeroError> {
153    check_mach(mach)?;
154    let ratio = pitot(mach);
155    if ratio.is_finite() {
156        Ok(ratio)
157    } else {
158        Err(AeroError::Domain {
159            what: "Mach number of a blunt tip's cap, too large for the pitot pressure",
160            value: mach,
161        })
162    }
163}
164
165fn pitot(mach: f64) -> f64 {
166    let m2 = mach * mach;
167    let g = GAMMA;
168    (0.5 * (g + 1.0) * m2).powf(g / (g - 1.0))
169        * ((g + 1.0) / (2.0 * g * m2 - (g - 1.0))).powf(1.0 / (g - 1.0))
170}
171
172/// The largest angle a two-dimensional wedge can turn the flow at Mach `mach` behind an attached
173/// shock, rad: the shock angle of NACA Report 1135 eq. 168 (p. 624) put into eq. 138 (p. 621).
174///
175/// # Errors
176///
177/// [`AeroError::Domain`] for a Mach number that isn't finite and above 1.
178pub fn wedge_detachment_angle_rad(mach: f64) -> Result<f64, AeroError> {
179    check_mach(mach)?;
180    let g = GAMMA;
181    // Both equations divided through by M² (and M⁴ under the root), so nothing overflows.
182    let i2 = 1.0 / (mach * mach);
183    let root = ((g + 1.0) * ((g + 1.0) / 16.0 + 0.5 * (g - 1.0) * i2 + i2 * i2)).sqrt();
184    let sin2 = ((0.25 * (g + 1.0) - i2 + root) / g).min(1.0);
185    let cot = ((1.0 - sin2) / sin2).sqrt();
186    let tan = 2.0 * cot * (sin2 - i2) / (2.0 * i2 + g + 1.0 - 2.0 * sin2);
187    Ok(tan.atan())
188}
189
190/// The pressure coefficient on a face of a two-dimensional wedge turning the flow by
191/// `deflection_rad` at Mach `mach` behind an attached shock: the weak shock's angle `θ` from
192/// NACA Report 1135 eq. 138 (p. 621), solved by bisection between the Mach angle and the
193/// detachment shock angle of eq. 168, then the pressure across it by eq. 128,
194/// `p₂/p₁ = (2γM² sin²θ − (γ − 1))/(γ + 1)`, as `C_p = (p₂/p₁ − 1)/(γM²/2)`, which is
195/// `4(sin²θ − 1/M²)/(γ + 1)`, the form used so that nothing overflows at a large Mach number.
196/// The report believes only the weak shock "can occur attached to an isolated convex body"
197/// (p. 624). For a thin wedge it tends to linear theory's `2δ/√(M² − 1)`.
198///
199/// # Errors
200///
201/// [`AeroError::Domain`] for a Mach number that isn't finite and above 1, a deflection outside
202/// `[0, π/2)`, or one past the wedge's largest at that Mach number
203/// ([`wedge_detachment_angle_rad`]), where the shock stands off and no attached solution exists.
204pub fn wedge_pressure_coefficient(mach: f64, deflection_rad: f64) -> Result<f64, AeroError> {
205    check_mach(mach)?;
206    if !(deflection_rad.is_finite() && (0.0..std::f64::consts::FRAC_PI_2).contains(&deflection_rad))
207    {
208        return Err(AeroError::Domain {
209            what: "wedge deflection",
210            value: deflection_rad,
211        });
212    }
213    let largest = wedge_detachment_angle_rad(mach)?;
214    if deflection_rad > largest {
215        return Err(AeroError::Domain {
216            what: "wedge deflection past the attached shock's largest",
217            value: deflection_rad,
218        });
219    }
220    let g = GAMMA;
221    let i2 = 1.0 / (mach * mach);
222    // Eq. 138 divided through by M², as in `wedge_detachment_angle_rad`.
223    let deflection = |sin2: f64| {
224        let cot = ((1.0 - sin2) / sin2).sqrt();
225        (2.0 * cot * (sin2 - i2) / (2.0 * i2 + g + 1.0 - 2.0 * sin2)).atan()
226    };
227    let root = ((g + 1.0) * ((g + 1.0) / 16.0 + 0.5 * (g - 1.0) * i2 + i2 * i2)).sqrt();
228    // The deflection rises from 0 at the Mach angle (sin²θ = 1/M²) to its largest at eq. 168's
229    // shock angle: the weak branch, where the bisection stays.
230    let (mut lo, mut hi) = (i2, ((0.25 * (g + 1.0) - i2 + root) / g).min(1.0));
231    for _ in 0..200 {
232        let mid = 0.5 * (lo + hi);
233        // Once the bracket is two adjacent numbers, halving it changes nothing.
234        if mid <= lo || mid >= hi {
235            break;
236        }
237        if deflection(mid) < deflection_rad {
238            lo = mid;
239        } else {
240            hi = mid;
241        }
242    }
243    let sin2 = 0.5 * (lo + hi);
244    Ok(4.0 * (sin2 - i2) / (g + 1.0))
245}
246
247/// The slope at which the cap hands over to the shock-expansion method at Mach `mach`, rad: the
248/// lesser of the wedge's largest deflection ([`wedge_detachment_angle_rad`], TN D-4865 p. 5) and
249/// [`MAX_HANDOVER_RAD`], the cap HPR Sim flies.
250///
251/// # Errors
252///
253/// As [`wedge_detachment_angle_rad`].
254pub fn handover_angle_rad(mach: f64) -> Result<f64, AeroError> {
255    handover_angle_capped_rad(mach, MAX_HANDOVER_RAD)
256}
257
258/// The handover slope at Mach `mach` under a cap of `cap_rad` rather than the flown
259/// [`MAX_HANDOVER_RAD`], rad: the lesser of the wedge's largest deflection and the cap. What
260/// [ADR-043][adr-043] sweeps; a body takes it through
261/// [`crate::shock_expansion::ShockExpansionBody::with_handover_cap_rad`].
262///
263/// # Errors
264///
265/// - As [`wedge_detachment_angle_rad`] for the Mach number.
266/// - [`AeroError::Domain`] for a cap outside `(0, `[`CONE_TABLE_CAP_RAD`]`]`, where the march has
267///   no tangent cone to start from.
268///
269/// [adr-043]: https://github.com/nrdptel/fusionspace-eridanus/blob/main/docs/DECISIONS.md#adr-043-the-blunt-tips-handover-cap-what-it-is-worth-and-what-stops-it-moving-2026-09-20
270pub fn handover_angle_capped_rad(mach: f64, cap_rad: f64) -> Result<f64, AeroError> {
271    if !(cap_rad.is_finite() && cap_rad > 0.0 && cap_rad <= CONE_TABLE_CAP_RAD) {
272        return Err(AeroError::Domain {
273            what: "cap on a blunt tip's handover slope",
274            value: cap_rad,
275        });
276    }
277    Ok(wedge_detachment_angle_rad(mach)?.min(cap_rad))
278}
279
280/// Modified Newtonian `C_p,max = (p_t2/p₀ − 1)/(γM²/2)` at Mach `mach`.
281///
282/// # Errors
283///
284/// As [`pitot_pressure_ratio`].
285pub fn newtonian_pressure_coefficient_max(mach: f64) -> Result<f64, AeroError> {
286    Ok((pitot_pressure_ratio(mach)? - 1.0) / (0.5 * GAMMA * mach * mach))
287}
288
289/// The cap's surface pressure over the free stream's where its slope to the wind is `slope_rad`
290/// (TN D-4865 eq. 1): `(p_t2/p₀ − 1) sin²δ + 1`.
291///
292/// # Errors
293///
294/// [`AeroError::Domain`] for a Mach number that isn't finite and above 1, or a slope outside
295/// `[0, π/2]`.
296pub fn newtonian_pressure_ratio(mach: f64, slope_rad: f64) -> Result<f64, AeroError> {
297    check_slope(slope_rad)?;
298    let sin = slope_rad.sin();
299    Ok((pitot_pressure_ratio(mach)? - 1.0) * sin * sin + 1.0)
300}
301
302/// The cap's surface Mach number where its pressure is `pressure_ratio` times the free stream's,
303/// isentropic from the pitot pressure (TN D-4865 eq. 2); zero at the stagnation point. The
304/// report's march starts from it ([`crate::shock_expansion::HandoverStart::Newtonian`]).
305///
306/// # Errors
307///
308/// [`AeroError::Domain`] for a Mach number that isn't finite and above 1, or a pressure that
309/// isn't positive and at most the pitot pressure.
310pub fn newtonian_surface_mach(mach: f64, pressure_ratio: f64) -> Result<f64, AeroError> {
311    let pitot = pitot_pressure_ratio(mach)?;
312    if !(pressure_ratio.is_finite() && pressure_ratio > 0.0 && pressure_ratio <= pitot) {
313        return Err(AeroError::Domain {
314            what: "surface pressure ratio on a blunt tip's cap",
315            value: pressure_ratio,
316        });
317    }
318    let g = GAMMA;
319    let m2 = 2.0 / (g - 1.0) * ((pressure_ratio / pitot).powf(-(g - 1.0) / g) - 1.0);
320    Ok(m2.max(0.0).sqrt())
321}
322
323/// The cap's loading at `α → 0` where its slope to the axis is `slope_rad`, `Λ = C_p,max sin δ
324/// cos δ`: half the windward `∂C_p/∂α` of `C_p = C_p,max sin²(δ + α cos φ)`, in the units of
325/// TN 3527's loading ([`crate::shock_expansion`]).
326///
327/// # Errors
328///
329/// As [`newtonian_pressure_ratio`].
330pub fn newtonian_loading(mach: f64, slope_rad: f64) -> Result<f64, AeroError> {
331    check_slope(slope_rad)?;
332    Ok(newtonian_pressure_coefficient_max(mach)? * slope_rad.sin() * slope_rad.cos())
333}
334
335/// [`newtonian_loading`] from the slope `dr/dx` itself, which may be infinite (a vertical tip):
336/// `sin δ cos δ = 1/(t + 1/t)` with `t = dr/dx`, zero at both ends. `c_p_max` is
337/// [`newtonian_pressure_coefficient_max`].
338pub(crate) fn newtonian_loading_at_slope(c_p_max: f64, slope: f64) -> f64 {
339    let t = slope.abs();
340    if t == 0.0 || t.is_infinite() {
341        0.0
342    } else {
343        c_p_max / (t + 1.0 / t)
344    }
345}
346
347/// The loading just behind a handover that holds still in the wind, `Λ = λ/(γM²)`, with
348/// `λ = 2γp/sin 2μ` at the handover's pressure `pressure_ratio` (times the free stream's) and
349/// surface Mach number `surface_mach`, and `M` the free stream's: the Prandtl–Meyer flow's
350/// `∂p/∂ν` over the free stream's `γM²/2`, halved as TN 3527's loading is. It is TN D-4865's
351/// equivalent bodies (eqs. 4a and 4b, the body turned about the sphere's center) read at `α → 0`,
352/// HPR Sim's reading ([`crate::shock_expansion::HandoverStart::Newtonian`]).
353///
354/// # Errors
355///
356/// [`AeroError::Domain`] for a free-stream or surface Mach number that isn't finite and above 1,
357/// or a pressure that isn't finite and positive.
358pub fn handover_loading(
359    mach: f64,
360    pressure_ratio: f64,
361    surface_mach: f64,
362) -> Result<f64, AeroError> {
363    check_mach(mach)?;
364    if !(surface_mach.is_finite() && surface_mach > 1.0) {
365        return Err(AeroError::Domain {
366            what: "surface Mach number at a blunt tip's handover",
367            value: surface_mach,
368        });
369    }
370    if !(pressure_ratio.is_finite() && pressure_ratio > 0.0) {
371        return Err(AeroError::Domain {
372            what: "surface pressure ratio at a blunt tip's handover",
373            value: pressure_ratio,
374        });
375    }
376    let m2 = surface_mach * surface_mach;
377    let lambda = GAMMA * pressure_ratio * m2 / (m2 - 1.0).sqrt();
378    Ok(lambda / (GAMMA * mach * mach))
379}
380
381#[cfg(test)]
382mod tests {
383    use super::*;
384    use std::f64::consts::FRAC_PI_2;
385
386    fn close(got: f64, want: f64, tol: f64, what: &str) {
387        assert!(
388            (got - want).abs() <= tol,
389            "{what}: got {got}, want {want} ± {tol}"
390        );
391    }
392
393    /// NACA Report 1135, Table II (normal shock, γ = 1.4): `p_t2/p₁` at M = 1.5, 2, 3 and 5.
394    #[test]
395    fn the_pitot_pressure_is_rayleighs() {
396        close(pitot_pressure_ratio(1.5).unwrap(), 3.413, 5e-4, "M 1.5");
397        close(pitot_pressure_ratio(2.0).unwrap(), 5.640, 5e-4, "M 2");
398        close(pitot_pressure_ratio(3.0).unwrap(), 12.06, 5e-3, "M 3");
399        close(pitot_pressure_ratio(5.0).unwrap(), 32.65, 5e-3, "M 5");
400        // At Mach 1 the shock vanishes: the pitot pressure is the isentropic total, 1.8929.
401        close(pitot(1.0), 1.892_929, 1e-6, "M 1");
402    }
403
404    /// NACA Report 1135, chart 2: the largest wedge deflection is 12.1° at Mach 1.5, 22.97° at
405    /// Mach 2, 34.07° at Mach 3 and 41.1° at Mach 5, rising to 45.6° as Mach → ∞.
406    #[test]
407    fn the_wedge_detaches_where_naca_1135_says() {
408        let deg = |m: f64| wedge_detachment_angle_rad(m).unwrap().to_degrees();
409        close(deg(1.5), 12.11, 0.01, "M 1.5");
410        close(deg(2.0), 22.97, 0.01, "M 2");
411        close(deg(3.0), 34.07, 0.01, "M 3");
412        close(deg(5.0), 41.12, 0.02, "M 5");
413        close(deg(1e6), 45.58, 0.01, "M → ∞");
414        close(deg(1e200), 45.58, 0.01, "M → ∞, no overflow");
415        assert!(matches!(
416            pitot_pressure_ratio(1e200),
417            Err(AeroError::Domain { .. })
418        ));
419        // Near Mach 1 it falls to zero like (M² − 1)^(3/2).
420        assert!(deg(1.0 + 1e-9) < 1e-9);
421        // It rises with Mach.
422        let mut last = 0.0;
423        for i in 1..400 {
424            let d = deg(1.0 + 0.02 * f64::from(i));
425            assert!(d > last);
426            last = d;
427        }
428    }
429
430    /// An attached wedge's face pressure by the weak oblique shock. At Mach 2 and 10° the shock
431    /// stands at 39.31°, its normal Mach number `M sin θ` is 1.2671, and Report 1135's Table II
432    /// (the normal shock, read at `M sin θ` as its p. 624 allows), interpolated there, gives
433    /// `p₂/p₁` 1.7066, so `C_p`
434    /// 0.2524; at Mach 3 and 5°, 23.13°, 1.1786 and 1.4540, so `C_p` 0.0721. For a thin wedge it
435    /// is linear theory's `2δ/√(M² − 1)`, and past detachment it is refused.
436    #[test]
437    fn a_wedge_s_face_pressure_is_the_weak_shock_s() {
438        close(
439            wedge_pressure_coefficient(2.0, 10f64.to_radians()).unwrap(),
440            (1.7066 - 1.0) / (0.7 * 4.0),
441            1e-4,
442            "M 2, 10°",
443        );
444        close(
445            wedge_pressure_coefficient(3.0, 5f64.to_radians()).unwrap(),
446            (1.4540 - 1.0) / (0.7 * 9.0),
447            1e-4,
448            "M 3, 5°",
449        );
450        for mach in [1.3, 1.832, 2.375, 3.147] {
451            let d = 1e-4;
452            let linear = 2.0 * d / (mach * mach - 1.0_f64).sqrt();
453            let got = wedge_pressure_coefficient(mach, d).unwrap();
454            assert!(
455                (got / linear - 1.0).abs() < 1e-3,
456                "Mach {mach}: {got} {linear}"
457            );
458        }
459        assert!(wedge_pressure_coefficient(2.0, 0.0).unwrap().abs() < 1e-12);
460        let past = wedge_detachment_angle_rad(1.5).unwrap() + 1e-6;
461        assert!(matches!(
462            wedge_pressure_coefficient(1.5, past),
463            Err(AeroError::Domain { .. })
464        ));
465        assert!(wedge_pressure_coefficient(1.0, 0.01).is_err());
466        // The largest deflection itself is attached; a NaN, a negative or a right angle is not
467        // a deflection, nor a NaN a Mach number.
468        assert!(wedge_pressure_coefficient(1.5, past - 1e-6).is_ok());
469        for bad in [f64::NAN, -0.01, std::f64::consts::FRAC_PI_2] {
470            assert!(wedge_pressure_coefficient(2.0, bad).is_err(), "{bad}");
471        }
472        assert!(wedge_pressure_coefficient(f64::NAN, 0.01).is_err());
473        // Where M² overflows the coefficient still converges on its hypersonic limit.
474        let far = wedge_pressure_coefficient(1e200, 0.1).unwrap();
475        let near = wedge_pressure_coefficient(1e10, 0.1).unwrap();
476        assert!(
477            far.is_finite() && (far - near).abs() < 1e-12,
478            "{far} {near}"
479        );
480    }
481
482    /// Below the cap the handover is the wedge's own detachment angle, above it the cap. The
483    /// flown cap, 24°, binds from Mach 2.06; the steepest the tables carry, 30°, from Mach 2.52.
484    #[test]
485    fn the_handover_is_the_wedges_until_the_cap_binds() {
486        close(
487            handover_angle_rad(1.5).unwrap(),
488            wedge_detachment_angle_rad(1.5).unwrap(),
489            0.0,
490            "M 1.5",
491        );
492        assert_eq!(handover_angle_rad(3.0).unwrap(), MAX_HANDOVER_RAD);
493        // Where each cap starts to bind, bisected against the wedge's own angle.
494        let binds_from = |cap: f64| {
495            let (mut low, mut high) = (1.0_f64, 20.0_f64);
496            for _ in 0..200 {
497                let mid = 0.5 * (low + high);
498                if wedge_detachment_angle_rad(mid).unwrap() < cap {
499                    low = mid;
500                } else {
501                    high = mid;
502                }
503            }
504            0.5 * (low + high)
505        };
506        close(binds_from(MAX_HANDOVER_RAD), 2.0614, 5e-4, "24° binds from");
507        close(
508            binds_from(CONE_TABLE_CAP_RAD),
509            2.5192,
510            5e-4,
511            "30° binds from",
512        );
513        // Under a cap of its own the handover is the lesser of the two, and the cap can't ask for
514        // a cone the tables don't carry.
515        assert_eq!(
516            handover_angle_capped_rad(3.0, CONE_TABLE_CAP_RAD).unwrap(),
517            CONE_TABLE_CAP_RAD
518        );
519        close(
520            handover_angle_capped_rad(1.5, CONE_TABLE_CAP_RAD).unwrap(),
521            wedge_detachment_angle_rad(1.5).unwrap(),
522            0.0,
523            "M 1.5, 30° cap",
524        );
525        for bad in [0.0, -1.0, f64::NAN, CONE_TABLE_CAP_RAD * 1.000_001] {
526            assert!(
527                matches!(
528                    handover_angle_capped_rad(3.0, bad),
529                    Err(AeroError::Domain { .. })
530                ),
531                "a cap of {bad} should be refused"
532            );
533        }
534    }
535
536    #[test]
537    fn newtonian_pressures() {
538        // At the stagnation point the pitot pressure; at zero slope the free stream's.
539        let pitot = pitot_pressure_ratio(2.0).unwrap();
540        close(
541            newtonian_pressure_ratio(2.0, FRAC_PI_2).unwrap(),
542            pitot,
543            1e-12,
544            "p",
545        );
546        close(newtonian_pressure_ratio(2.0, 0.0).unwrap(), 1.0, 0.0, "p₀");
547        // C_p,max at Mach 2: (5.6404 − 1)/2.8.
548        close(
549            newtonian_pressure_coefficient_max(2.0).unwrap(),
550            (5.640_4 - 1.0) / 2.8,
551            1e-4,
552            "C_p,max",
553        );
554        assert!(matches!(
555            newtonian_pressure_ratio(2.0, 2.0),
556            Err(AeroError::Domain { .. })
557        ));
558        assert!(matches!(
559            pitot_pressure_ratio(1.0),
560            Err(AeroError::Domain { .. })
561        ));
562    }
563
564    /// A hemisphere's Newtonian loading integrates to `C_Nα = C_p,max/2` on its base: the drag
565    /// `C_p,max/2` of a Newtonian hemisphere turned into body axes (the force on a sphere passes
566    /// through its center, so it lies along the wind).
567    #[test]
568    fn a_hemisphere_carries_its_drag_turned() {
569        let mach = 3.0;
570        let c_p_max = newtonian_pressure_coefficient_max(mach).unwrap();
571        // With r = sin θ, x = 1 − cos θ (unit radius) the slope is cot θ.
572        let n = 20_000;
573        let mut sum = 0.0;
574        for i in 0..n {
575            let theta = FRAC_PI_2 * (f64::from(i) + 0.5) / f64::from(n);
576            let slope = 1.0 / theta.tan();
577            let load = newtonian_loading_at_slope(c_p_max, slope);
578            let r = theta.sin();
579            // dx = sin θ dθ.
580            sum += load * r * theta.sin() * FRAC_PI_2 / f64::from(n);
581        }
582        // C_Nα = (2π/π) ∫ Λ r dx on the unit base.
583        close(2.0 * sum, 0.5 * c_p_max, 1e-8, "C_Nα");
584        close(
585            newtonian_loading(mach, 0.3).unwrap(),
586            newtonian_loading_at_slope(c_p_max, 0.3f64.tan()),
587            1e-15,
588            "Λ",
589        );
590        assert_eq!(newtonian_loading_at_slope(c_p_max, f64::INFINITY), 0.0);
591        assert_eq!(newtonian_loading_at_slope(c_p_max, 0.0), 0.0);
592    }
593
594    /// A Newtonian cone of half-angle δ carries `C_Nα = C_p,max cos²δ` on its base, the classical
595    /// result; TN 3527's loading form gives it from `Λ = C_p,max sin δ cos δ`: `C_Nα = Λ/tan δ`.
596    #[test]
597    fn a_newtonian_cone_carries_c_p_max_cos_squared() {
598        let delta = 0.2_f64;
599        let load = newtonian_loading(2.5, delta).unwrap();
600        let c_p_max = newtonian_pressure_coefficient_max(2.5).unwrap();
601        close(
602            load / delta.tan(),
603            c_p_max * delta.cos().powi(2),
604            1e-14,
605            "cone",
606        );
607    }
608
609    #[test]
610    fn newtonian_surface_mach_numbers() {
611        let pitot = pitot_pressure_ratio(2.0).unwrap();
612        close(newtonian_surface_mach(2.0, pitot).unwrap(), 0.0, 1e-12, "M");
613        // Expanded to the free stream's pressure through the normal shock's total, the surface
614        // flow is slower than the free stream.
615        let m = newtonian_surface_mach(2.0, 1.0).unwrap();
616        assert!(m > 1.5 && m < 2.0, "{m}");
617        assert!(matches!(
618            newtonian_surface_mach(2.0, pitot * 1.01),
619            Err(AeroError::Domain { .. })
620        ));
621    }
622
623    /// Behind a handover fixed in the wind the loading is the Prandtl–Meyer flow's: a turn `dν`
624    /// lowers the pressure by `λ dν`, checked by a finite difference of the expansion itself.
625    #[test]
626    fn the_handover_loading_is_the_expansions() {
627        use crate::afterbody::{inverse_prandtl_meyer, prandtl_meyer};
628        let mach = 2.3;
629        let delta = handover_angle_rad(mach).unwrap();
630        let p = newtonian_pressure_ratio(mach, delta).unwrap();
631        let m = newtonian_surface_mach(mach, p).unwrap();
632        let total = pitot_pressure_ratio(mach).unwrap();
633        let static_at = |nu: f64| {
634            let ms = inverse_prandtl_meyer(nu);
635            total / (1.0 + 0.2 * ms * ms).powf(3.5)
636        };
637        let h = 1e-6;
638        let nu = prandtl_meyer(m);
639        // A turn smaller by ε raises the pressure by λε, C_p by 2λε/(γM²); Λ is half that.
640        let dp = (static_at(nu - h) - static_at(nu + h)) / (2.0 * h);
641        let want = dp / (GAMMA * mach * mach);
642        close(
643            handover_loading(mach, p, m).unwrap(),
644            want,
645            1e-6 * want,
646            "Λ",
647        );
648        assert!(matches!(
649            handover_loading(mach, p, 1.0),
650            Err(AeroError::Domain { .. })
651        ));
652    }
653}