comp_flow/
mach_to.rs

1//! Collection of functions for isentropic compressible flow.
2#[doc(no_inline)]
3use num::Float;
4
5/// Prandtl-Meyer angle in radians for a given mach number and specific heat ratio.
6///
7/// # Examples
8///
9/// ```
10/// use comp_flow::mach_to_pm_angle;
11///
12/// assert_eq!(mach_to_pm_angle(2.0_f32, 1.4_f32), 0.4604136818474);
13/// assert_eq!(mach_to_pm_angle(1.0_f64, 1.4_f64), 0.0);
14/// ```
15pub fn mach_to_pm_angle<F: Float>(mach: F, gamma: F) -> F {
16    ((gamma + F::one()) / (gamma - F::one())).sqrt()
17        * ((gamma - F::one()) / (gamma + F::one()) * (mach.powi(2) - F::one()))
18            .sqrt()
19            .atan()
20        - (mach.powi(2) - F::one()).sqrt().atan()
21}
22
23/// Mach angle in radians for a given mach number.
24///
25/// # Examples
26///
27/// ```
28/// use comp_flow::mach_to_mach_angle;
29///
30/// assert_eq!(mach_to_mach_angle(2.0_f32), 0.5235988);
31/// assert_eq!(mach_to_mach_angle(1.0_f64), 1.5707963267948966);
32/// ```
33pub fn mach_to_mach_angle<F: Float>(mach: F) -> F {
34    (F::one() / mach).asin()
35}
36
37/// Total temperature ratio for given mach number and specific heat ratio
38///
39/// # Examples
40///
41/// ```
42/// use comp_flow::mach_to_t_t0;
43///
44/// assert_eq!(mach_to_t_t0(0.0, 1.4), 1.0);
45/// assert_eq!(mach_to_t_t0(1.0, 1.4), 0.8333333333333334);
46/// assert_eq!(mach_to_t_t0(2.0_f32, 1.4), 0.55555556);
47/// ```
48pub fn mach_to_t_t0<F: Float>(mach: F, gamma: F) -> F {
49    let half = F::from(0.5).unwrap();
50    (F::one() + half * (gamma - F::one()) * mach.powi(2)).powi(-1)
51}
52
53/// Total pressure ratio for given mach number and specific heat ratio
54///
55/// # Examples
56///
57/// ```
58/// use comp_flow::mach_to_p_p0;
59///
60/// assert_eq!(mach_to_p_p0(0.0, 1.4), 1.0);
61/// assert_eq!(mach_to_p_p0(1.0, 1.4), 0.5282817877171742);
62/// assert_eq!(mach_to_p_p0(2.0, 1.4), 0.12780452546295096);
63/// ```
64pub fn mach_to_p_p0<F: Float>(mach: F, gamma: F) -> F {
65    let half = F::from(0.5).unwrap();
66    (F::one() + half * (gamma - F::one()) * mach.powi(2)).powf((gamma) / (F::one() - gamma))
67}
68
69/// Stagnation density ratio for given mach number and specific heat ratio
70///
71/// # Examples
72///
73/// ```
74/// use comp_flow::mach_to_rho_rho0;
75///
76/// assert_eq!(mach_to_rho_rho0(0.0, 1.4), 1.0);
77/// assert_eq!(mach_to_rho_rho0(1.0, 1.4), 0.633938145260609);
78/// assert_eq!(mach_to_rho_rho0(2.0, 1.4), 0.2300481458333117);
79/// ```
80pub fn mach_to_rho_rho0<F: Float>(mach: F, gamma: F) -> F {
81    let half = F::from(0.5).unwrap();
82    (F::one() + half * (gamma - F::one()) * mach.powi(2)).powf(F::one() / (F::one() - gamma))
83}
84
85/// Critical area ratio for given mach number and specific heat ratio
86///
87/// # Examples
88///
89/// ```
90/// use comp_flow::mach_to_a_ac;
91///
92/// assert_eq!(mach_to_a_ac(0.1, 1.4), 5.821828750000001);
93/// assert_eq!(mach_to_a_ac(1.0, 1.4), 1.0);
94/// assert_eq!(mach_to_a_ac(2.0, 1.4), 1.6875000000000002);
95/// ```
96pub fn mach_to_a_ac<F: Float>(mach: F, gamma: F) -> F {
97    let half = F::from(0.5).unwrap();
98    F::one() / mach
99        * ((F::one() + half * (gamma - F::one()) * mach.powi(2)) / (half * (gamma + F::one())))
100            .powf(half * (gamma + F::one()) / (gamma - F::one()))
101}