Skip to main content

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 temperature ratio for given mach number and specific heat ratio
54///
55/// # Examples
56///
57/// ```
58/// use comp_flow::mach_to_t0_t;
59///
60/// assert_eq!(mach_to_t0_t(0.0, 1.4), 1.0);
61/// assert_eq!(mach_to_t0_t(1.0, 1.4), 1.2);
62/// assert_eq!(mach_to_t0_t(2.0_f32, 1.4), 1.8);
63/// ```
64pub fn mach_to_t0_t<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)
67}
68
69/// Total pressure ratio for given mach number and specific heat ratio
70///
71/// # Examples
72///
73/// ```
74/// use comp_flow::mach_to_p_p0;
75///
76/// assert_eq!(mach_to_p_p0(0.0, 1.4), 1.0);
77/// assert_eq!(mach_to_p_p0(1.0, 1.4), 0.5282817877171742);
78/// assert_eq!(mach_to_p_p0(2.0, 1.4), 0.12780452546295096);
79/// ```
80pub fn mach_to_p_p0<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((gamma) / (F::one() - gamma))
83}
84
85/// Total pressure ratio for given mach number and specific heat ratio
86///
87/// # Examples
88///
89/// ```
90/// use comp_flow::mach_to_p0_p;
91///
92/// assert_eq!(mach_to_p0_p(0.0, 1.4), 1.0);
93/// assert_eq!(mach_to_p0_p(1.0, 1.4), 1.892929158737854);
94/// assert_eq!(mach_to_p0_p(2.0, 1.4), 7.824449066867263);
95/// ```
96pub fn mach_to_p0_p<F: Float>(mach: F, gamma: F) -> F {
97    let half = F::from(0.5).unwrap();
98    (F::one() + half * (gamma - F::one()) * mach.powi(2)).powf((gamma) / (gamma - F::one()))
99}
100
101/// Stagnation density ratio for given mach number and specific heat ratio
102///
103/// # Examples
104///
105/// ```
106/// use comp_flow::mach_to_rho_rho0;
107///
108/// assert_eq!(mach_to_rho_rho0(0.0, 1.4), 1.0);
109/// assert_eq!(mach_to_rho_rho0(1.0, 1.4), 0.633938145260609);
110/// assert_eq!(mach_to_rho_rho0(2.0, 1.4), 0.2300481458333117);
111/// ```
112pub fn mach_to_rho_rho0<F: Float>(mach: F, gamma: F) -> F {
113    let half = F::from(0.5).unwrap();
114    (F::one() + half * (gamma - F::one()) * mach.powi(2)).powf(F::one() / (F::one() - gamma))
115}
116
117/// Stagnation density ratio for given mach number and specific heat ratio
118///
119/// # Examples
120///
121/// ```
122/// use comp_flow::mach_to_rho0_rho;
123///
124/// assert_eq!(mach_to_rho0_rho(0.0, 1.4), 1.0);
125/// assert_eq!(mach_to_rho0_rho(1.0, 1.4), 1.5774409656148785);
126/// assert_eq!(mach_to_rho0_rho(2.0, 1.4), 4.3469161482595915);
127/// ```
128pub fn mach_to_rho0_rho<F: Float>(mach: F, gamma: F) -> F {
129    let half = F::from(0.5).unwrap();
130    (F::one() + half * (gamma - F::one()) * mach.powi(2)).powf(F::one() / (gamma - F::one()))
131}
132
133/// Critical area ratio for given Mach number and specific heat ratio
134///
135/// # Examples
136///
137/// ```
138/// use comp_flow::mach_to_a_ac;
139///
140/// assert_eq!(mach_to_a_ac(0.1, 1.4), 5.821828750000001);
141/// assert_eq!(mach_to_a_ac(1.0, 1.4), 1.0);
142/// assert_eq!(mach_to_a_ac(2.0, 1.4), 1.6875000000000002);
143/// ```
144pub fn mach_to_a_ac<F: Float>(mach: F, gamma: F) -> F {
145    let half = F::from(0.5).unwrap();
146    F::one() / mach
147        * ((F::one() + half * (gamma - F::one()) * mach.powi(2)) / (half * (gamma + F::one())))
148            .powf(half * (gamma + F::one()) / (gamma - F::one()))
149}
150
151/// Normalised velocity for given Mach number and specific heat ratio
152pub fn mach_to_v_cpt0<F: Float>(mach: F, gamma: F) -> F {
153    let half = F::from(0.5).unwrap();
154    (gamma - F::one()).sqrt()
155        * mach
156        * (F::one() + half * (gamma - F::one()) * mach.powi(2))
157            .sqrt()
158            .powi(-1)
159}
160
161/// Normalised mass flow for given Mach number and specific heat ratio
162pub fn mach_to_mcpt0_ap0<F: Float>(mach: F, gamma: F) -> F {
163    let half = F::from(0.5).unwrap();
164    gamma / (gamma - F::one()).sqrt()
165        * mach
166        * (F::one() + half * (gamma - F::one()) * mach.powi(2))
167            .powf(-half * (gamma + F::one()) / (gamma - F::one()))
168}
169
170/// Static normalised mass flow for given Mach number and specific heat ratio
171pub fn mach_to_mcpt0_ap<F: Float>(mach: F, gamma: F) -> F {
172    let half = F::from(0.5).unwrap();
173    gamma / (gamma - F::one()).sqrt()
174        * mach
175        * (F::one() + half * (gamma - F::one()) * mach.powi(2)).sqrt()
176}
177
178/// Impulse function for given Mach number and specific heat ratio
179pub fn mach_to_f_mcpt<F: Float>(mach: F, gamma: F) -> F {
180    let half = F::from(0.5).unwrap();
181    (gamma - F::one()).sqrt() / gamma * (F::one() + gamma * mach.powi(2)) / mach
182        * (F::one() + half * (gamma - F::one()) * mach.powi(2))
183            .sqrt()
184            .powi(-1)
185}