Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
ExponentialAtmosphere.hpp
Go to the documentation of this file.
1// Exponential Atmosphere Model
2// Simple exponential atmosphere for quick estimates and validation
3#pragma once
4
5#include <janus/janus.hpp>
6
8
9// ============================================================================
10// Physical Constants
11// ============================================================================
12
14inline constexpr double RHO_0 = 1.225;
15
17inline constexpr double P_0 = 101325.0;
18
20inline constexpr double T_0 = 288.15;
21
24inline constexpr double DEFAULT_SCALE_HEIGHT = 8500.0;
25
27inline constexpr double G_0 = 9.80665;
28
30inline constexpr double R_AIR = 287.058;
31
33inline constexpr double GAMMA = 1.4;
34
35// ============================================================================
36// Atmospheric State Struct
37// ============================================================================
38
47template <typename Scalar> struct AtmosphericState {
48 Scalar temperature;
49 Scalar pressure;
50 Scalar density;
52};
53
54// ============================================================================
55// Public API - Individual Property Accessors
56// ============================================================================
57
75template <typename Scalar>
76Scalar density(const Scalar &altitude,
77 double scale_height = DEFAULT_SCALE_HEIGHT) {
78 return RHO_0 * janus::exp(-altitude / scale_height);
79}
80
95template <typename Scalar>
96Scalar pressure(const Scalar &altitude,
97 double scale_height = DEFAULT_SCALE_HEIGHT) {
98 return P_0 * janus::exp(-altitude / scale_height);
99}
100
113template <typename Scalar>
114Scalar temperature(const Scalar &altitude,
115 double scale_height = DEFAULT_SCALE_HEIGHT) {
116 // Isothermal assumption - return constant temperature
117 // Use janus multiplication to ensure proper type for symbolic inputs
118 (void)scale_height; // Unused
119 return altitude * 0.0 + T_0;
120}
121
135template <typename Scalar>
136Scalar speed_of_sound(const Scalar &altitude,
137 double scale_height = DEFAULT_SCALE_HEIGHT) {
138 // a = sqrt(gamma * R * T)
139 // For isothermal atmosphere, this is constant
140 Scalar T = temperature(altitude, scale_height);
141 return janus::sqrt(GAMMA * R_AIR * T);
142}
143
144// ============================================================================
145// Public API - Combined State Accessor
146// ============================================================================
147
159template <typename Scalar>
160AtmosphericState<Scalar> state(const Scalar &altitude,
161 double scale_height = DEFAULT_SCALE_HEIGHT) {
162 Scalar T = temperature(altitude, scale_height);
163 Scalar exp_factor = janus::exp(-altitude / scale_height);
164
165 return AtmosphericState<Scalar>{.temperature = T,
166 .pressure = P_0 * exp_factor,
167 .density = RHO_0 * exp_factor,
168 .speed_of_sound =
169 janus::sqrt(GAMMA * R_AIR * T)};
170}
171
172// ============================================================================
173// Utility Functions
174// ============================================================================
175
186inline double compute_scale_height(double temperature = T_0,
187 double gravity = G_0) {
188 return R_AIR * temperature / gravity;
189}
190
202template <typename Scalar>
203Scalar altitude_from_density(const Scalar &rho,
204 double scale_height = DEFAULT_SCALE_HEIGHT) {
205 return -scale_height * janus::log(rho / RHO_0);
206}
207
219template <typename Scalar>
220Scalar altitude_from_pressure(const Scalar &P,
221 double scale_height = DEFAULT_SCALE_HEIGHT) {
222 return -scale_height * janus::log(P / P_0);
223}
224
225} // namespace vulcan::exponential_atmosphere
Definition ExponentialAtmosphere.hpp:7
AtmosphericState< Scalar > state(const Scalar &altitude, double scale_height=DEFAULT_SCALE_HEIGHT)
Exponential atmosphere - Complete atmospheric state.
Definition ExponentialAtmosphere.hpp:160
Scalar speed_of_sound(const Scalar &altitude, double scale_height=DEFAULT_SCALE_HEIGHT)
Exponential atmosphere - Speed of Sound.
Definition ExponentialAtmosphere.hpp:136
constexpr double T_0
Sea-level reference temperature [K].
Definition ExponentialAtmosphere.hpp:20
Scalar temperature(const Scalar &altitude, double scale_height=DEFAULT_SCALE_HEIGHT)
Exponential atmosphere - Temperature.
Definition ExponentialAtmosphere.hpp:114
Scalar density(const Scalar &altitude, double scale_height=DEFAULT_SCALE_HEIGHT)
Exponential atmosphere - Density.
Definition ExponentialAtmosphere.hpp:76
constexpr double DEFAULT_SCALE_HEIGHT
Definition ExponentialAtmosphere.hpp:24
Scalar pressure(const Scalar &altitude, double scale_height=DEFAULT_SCALE_HEIGHT)
Exponential atmosphere - Pressure.
Definition ExponentialAtmosphere.hpp:96
Scalar altitude_from_pressure(const Scalar &P, double scale_height=DEFAULT_SCALE_HEIGHT)
Compute altitude from pressure.
Definition ExponentialAtmosphere.hpp:220
constexpr double GAMMA
Ratio of specific heats for air (γ = Cp/Cv).
Definition ExponentialAtmosphere.hpp:33
constexpr double P_0
Sea-level reference pressure [Pa].
Definition ExponentialAtmosphere.hpp:17
constexpr double G_0
Sea-level gravitational acceleration [m/s²].
Definition ExponentialAtmosphere.hpp:27
double compute_scale_height(double temperature=T_0, double gravity=G_0)
Compute scale height from reference conditions.
Definition ExponentialAtmosphere.hpp:186
constexpr double R_AIR
Specific gas constant for air [J/(kg·K)].
Definition ExponentialAtmosphere.hpp:30
Scalar altitude_from_density(const Scalar &rho, double scale_height=DEFAULT_SCALE_HEIGHT)
Compute altitude from density.
Definition ExponentialAtmosphere.hpp:203
constexpr double RHO_0
Sea-level reference density [kg/m³].
Definition ExponentialAtmosphere.hpp:14
Definition GravityTypes.hpp:7
Complete atmospheric state at a given altitude.
Definition ExponentialAtmosphere.hpp:47
Scalar speed_of_sound
Speed of sound [m/s].
Definition ExponentialAtmosphere.hpp:51
Scalar temperature
Temperature [K].
Definition ExponentialAtmosphere.hpp:48
Scalar density
Air density [kg/m³].
Definition ExponentialAtmosphere.hpp:50
Scalar pressure
Pressure [Pa].
Definition ExponentialAtmosphere.hpp:49