1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2026 Vallés Puig, Ramon
//! # ICAO International Standard Atmosphere (ISA)
//!
//! ## Scientific scope
//!
//! The ICAO Standard Atmosphere (ISA) is the reference pressure-altitude
//! model defined in ICAO Doc 7488, 3rd edition (1993). It divides the
//! atmosphere into layers with constant temperature lapse rates; within each
//! layer pressure and density follow hydrostatic equilibrium.
//!
//! This module implements:
//! - Pressure from geometric altitude, covering the troposphere (0–11 km)
//! and lower stratosphere (11–20 km).
//! - The inverse: pressure altitude from static pressure.
//! - Geopotential ↔ geometric altitude conversion using the standard WGS-84
//! Earth radius of 6 356.766 km.
//!
//! Validity range: geometric altitude 0–20 km (−2 000 m to 20 000 m is
//! supported; values outside produce extrapolated results).
//!
//! ## Technical scope
//!
//! All public functions accept and return typed [`crate::qtty`] values:
//!
//! | Function | Input | Output |
//! |----------|-------|--------|
//! | [`pressure_at_altitude`] | geometric altitude ([`Meters`]) | static pressure ([`Pascals`]) |
//! | [`pressure_altitude_m`] | static pressure ([`Pascals`]) | pressure altitude ([`Meters`]) |
//! | [`temperature_at_altitude`] | geometric altitude ([`Meters`]) | temperature ([`Kelvins`]) |
//! | [`geopotential_altitude_m`] | geometric altitude ([`Meters`]) | geopotential altitude ([`Meters`]) |
//! | [`geometric_altitude_m`] | geopotential altitude ([`Meters`]) | geometric altitude ([`Meters`]) |
//!
//! ## References
//!
//! - ICAO (1993). *Manual of the ICAO Standard Atmosphere*, 3rd ed. Doc
//! 7488. International Civil Aviation Organization.
//! - ICAO (2010). *Annex 2 — Rules of the Air*, 10th edition.
use crate;
// =============================================================================
// ISA constants
// =============================================================================
/// ISA sea-level pressure (Pa).
const P0: f64 = 101_325.0;
/// ISA sea-level temperature (K).
const T0: f64 = 288.15;
/// ISA tropopause temperature (K); constant from 11 km to 20 km.
const T_TROPO: f64 = 216.65;
/// Tropospheric lapse rate (K/m).
const LAPSE_RATE: f64 = -6.5e-3;
/// Tropopause geometric altitude (m).
const H_TROPO: f64 = 11_000.0;
/// ISA molar mass of dry air (kg/mol).
const M: f64 = 0.028_964_4;
/// Universal gas constant (J/(mol·K)).
const R: f64 = 8.314_462_618;
/// Standard acceleration of gravity (m/s²).
const G0: f64 = 9.806_65;
/// WGS-84 mean Earth radius used for geopotential altitude (km → m: 6 356 766 m).
const R_EARTH: f64 = 6_356_766.0;
// Derived constant for the barometric formula: g0·M / (R·|L|).
const EXP_TROP: f64 = G0 * M / ;
/// ISA pressure at the tropopause base (Pa).
///
/// Computed from the troposphere formula at H_TROPO to ensure consistency
/// with `pressure_at_altitude` and its inverse.
// =============================================================================
// Public API
// =============================================================================
/// Static pressure at a given geometric altitude.
///
/// Troposphere (0–11 km): hydrostatic gradient model.
/// Lower stratosphere (11–20 km): isothermal at 216.65 K.
///
/// # Arguments
///
/// - `altitude` — geometric altitude above MSL.
///
/// # Returns
///
/// Static pressure in [`Pascals`].
///
/// # Examples
///
/// ```rust
/// use siderust::bodies::aircraft::isa::pressure_at_altitude;
/// use siderust::qtty::Meters;
///
/// // Sea level: 101 325 Pa
/// let p_sl = pressure_at_altitude(Meters::new(0.0));
/// assert!((p_sl.value() - 101_325.0).abs() < 1.0);
///
/// // FL350 ≈ 10 668 m: ~23 842 Pa
/// let p_fl350 = pressure_at_altitude(Meters::new(10_668.0));
/// assert!(p_fl350.value() > 23_000.0 && p_fl350.value() < 24_500.0);
/// ```
/// Pressure altitude (ISA barometric altitude) from static pressure.
///
/// Inverts [`pressure_at_altitude`]. Returns the geometric altitude at which
/// the ISA model produces the given pressure.
///
/// # Arguments
///
/// - `pressure` — static pressure in [`Pascals`].
///
/// # Returns
///
/// Pressure altitude in [`Meters`].
///
/// # Examples
///
/// ```rust
/// use siderust::bodies::aircraft::isa::{pressure_at_altitude, pressure_altitude_m};
/// use siderust::qtty::Meters;
///
/// let h_in = Meters::new(8_500.0);
/// let p = pressure_at_altitude(h_in);
/// let h_out = pressure_altitude_m(p);
/// assert!((h_out.value() - h_in.value()).abs() < 0.01);
/// ```
/// ISA air temperature at a given geometric altitude.
///
/// # Arguments
///
/// - `altitude` — geometric altitude above MSL.
///
/// # Returns
///
/// Temperature in [`Kelvins`].
///
/// # Examples
///
/// ```rust
/// use siderust::bodies::aircraft::isa::temperature_at_altitude;
/// use siderust::qtty::Meters;
///
/// // Sea level: 288.15 K
/// let t = temperature_at_altitude(Meters::new(0.0));
/// assert!((t.value() - 288.15).abs() < 1e-6);
///
/// // Above tropopause: isothermal at 216.65 K
/// let t_strat = temperature_at_altitude(Meters::new(15_000.0));
/// assert!((t_strat.value() - 216.65).abs() < 1e-6);
/// ```
/// Geopotential altitude from geometric altitude.
///
/// Uses the standard WGS-84 mean Earth radius (6 356 766 m).
///
/// # Arguments
///
/// - `geometric` — geometric altitude above MSL.
///
/// # Returns
///
/// Geopotential altitude in [`Meters`].
///
/// # Examples
///
/// ```rust
/// use siderust::bodies::aircraft::isa::geopotential_altitude_m;
/// use siderust::qtty::Meters;
///
/// // At sea level, geopotential ≈ geometric
/// let h = geopotential_altitude_m(Meters::new(0.0));
/// assert!((h.value() - 0.0).abs() < 1e-6);
///
/// // At 10 km the difference is ~15 m
/// let h = geopotential_altitude_m(Meters::new(10_000.0));
/// assert!((h.value() - 10_000.0).abs() < 20.0);
/// ```
/// Geometric altitude from geopotential altitude.
///
/// Inverse of [`geopotential_altitude_m`].
///
/// # Arguments
///
/// - `geopotential` — geopotential altitude above MSL.
///
/// # Returns
///
/// Geometric altitude in [`Meters`].
///
/// # Examples
///
/// ```rust
/// use siderust::bodies::aircraft::isa::{geopotential_altitude_m, geometric_altitude_m};
/// use siderust::qtty::Meters;
///
/// let z_in = Meters::new(10_000.0);
/// let hp = geopotential_altitude_m(z_in);
/// let z_out = geometric_altitude_m(hp);
/// assert!((z_out.value() - z_in.value()).abs() < 1e-6);
/// ```
// =============================================================================
// Tests
// =============================================================================