STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
constants.py
Go to the documentation of this file.
1"""
2Physical and engineering constants used throughout the pintle engine pipeline.
3
4This module centralizes all magic numbers and default values to improve maintainability
5and make the physical meaning of constants explicit.
6
7⚠️ IMPORTANT: DEPRECATED DEFAULT/FALLBACK CONSTANTS ⚠️
8===========================================================
9Many constants in this file with names starting with DEFAULT_* or FALLBACK_*
10are DEPRECATED and should NOT be used to hide missing values or failed calculations.
11
12WRONG usage (DO NOT DO THIS):
13 gamma = cea_props.get("gamma", DEFAULT_GAMMA_ND) # WRONG!
14 density = max(calculated_density, MIN_DENS_KG_M3) # WRONG!
15
16CORRECT usage:
17 if "gamma" not in cea_props:
18 raise KeyError("Missing gamma in CEA properties")
19 gamma = cea_props["gamma"]
20 if not (1.0 < gamma < 2.0):
21 raise ValueError(f"Invalid gamma: {gamma}")
22
23These constants should only be used for:
241. Physical limits (e.g., GRAVITATIONAL_ACCEL_M_S2)
252. Model parameters explicitly chosen by design (not fallbacks)
263. Testing with explicit test data
27===========================================================
28
29Naming Convention:
30- All constants include units in their names (e.g., _K, _PA, _M, _M_S)
31- Dimensionless constants use _ND suffix (non-dimensional)
32- This prevents unit confusion and makes conversions explicit
33"""
34
35# ============================================================================
36# FUNDAMENTAL PHYSICAL CONSTANTS
37# ============================================================================
38
39# Stefan-Boltzmann constant for blackbody radiation
40# Units: W/(m²·K⁴)
41STEFAN_BOLTZMANN_W_M2_K4 = 5.670374419e-8
42
43# Universal gas constant
44# Units: J/(kmol·K)
45UNIVERSAL_GAS_CONST_J_KMOL_K = 8314.462618
46
47# Standard gravitational acceleration
48# Units: m/s²
49GRAVITATIONAL_ACCEL_M_S2 = 9.80665
50
51# ============================================================================
52# DEFAULT GAS PROPERTIES (Combustion Products)
53# ============================================================================
54# These are fallback values used when gas properties are not available from CEA
55# or other sources. Values are typical for hydrocarbon/LOX rocket combustion.
56
57# Default specific heat ratio (gamma) for combustion products
58# Typical range: 1.20-1.25 for hydrocarbon/LOX
59# Used when gas_props dict doesn't contain "gamma"
60DEFAULT_GAMMA_ND = 1.2
61
62# Default gas constant for combustion products
63# Units: J/(kg·K)
64# For molecular weight M ~ 24 kg/kmol: R = R_universal / M ≈ 346 J/(kg·K)
65# Typical range: 350-400 J/(kg·K) depending on mixture ratio
66# Used when gas_props dict doesn't contain "R"
67DEFAULT_GAS_CONST_J_KG_K = 350.0
68
69# Default chamber temperature
70# Units: K
71# Typical range: 3200-3600 K for hydrocarbon/LOX
72# Used when gas_props dict doesn't contain "Tc"
73DEFAULT_CHAMBER_TEMP_K = 3500.0
74
75# Default ideal characteristic velocity
76# Units: m/s
77# Typical range: 1700-1900 m/s for hydrocarbon/LOX
78# Used when cstar_ideal is not available
79DEFAULT_CSTAR_IDEAL_M_S = 1800.0
80
81# Default mixture ratio
82# Typical range: 2.0-3.0 for hydrocarbon/LOX
83DEFAULT_MIXTURE_RATIO_ND = 2.5
84
85# Default chamber pressure
86# Units: Pa
87DEFAULT_CHAMBER_PRESS_PA = 4.0e6 # 4 MPa
88
89# ============================================================================
90# DEFAULT FLUID PROPERTIES
91# ============================================================================
92
93# Default coolant properties (typical for RP-1 fuel)
94DEFAULT_COOLANT_SPEC_HEAT_J_KG_K = 2000.0 # J/(kg·K)
95DEFAULT_COOLANT_THERMAL_COND_W_M_K = 0.1 # W/(m·K)
96DEFAULT_COOLANT_DENS_KG_M3 = 700.0 # kg/m³
97DEFAULT_COOLANT_TEMP_K = 300.0 # K (ambient)
98
99# Default fuel properties (RP-1)
100DEFAULT_FUEL_DENS_KG_M3 = 810.0 # kg/m³
101DEFAULT_FUEL_BOILING_POINT_K = 489.0 # K
102
103# Default oxidizer properties (LOX)
104DEFAULT_LOX_DENS_KG_M3 = 1140.0 # kg/m³
105
106# Default hot gas properties
107DEFAULT_HOT_GAS_VISC_PA_S = 4.0e-5 # Pa·s
108DEFAULT_HOT_GAS_THERMAL_COND_W_M_K = 0.1 # W/(m·K)
109DEFAULT_HOT_GAS_PRANDTL_ND = 0.7 # Dimensionless
110
111# ============================================================================
112# HEAT TRANSFER CONSTANTS
113# ============================================================================
114
115# Default radiation properties
116DEFAULT_EMISSIVITY_ND = 0.8 # Typical for hot gas/combustion products
117DEFAULT_VIEW_FACTOR_ND = 1.0 # Full view (no obstruction)
118
119# Default turbulence intensity
120# Typical range: 0.05-0.15 for rocket chambers
121DEFAULT_TURBULENCE_INTENSITY_ND = 0.08 # 8% turbulence
122DEFAULT_TURBULENCE_INTENSITY_COOLANT_ND = 0.05 # 5% for coolant flow
123
124# Nusselt number constants for heat transfer correlations
125# Laminar flow (Re < 2000): Nu = 4.36 for constant wall temperature
126NU_LAMINAR_ND = 4.36
127
128# Turbulent flow Dittus-Boelter correlation constants
129# Nu = C × Re^0.8 × Pr^0.4
130NU_TURBULENT_COEFFICIENT_ND = 0.023
131NU_TURBULENT_RE_EXPONENT_ND = 0.8
132NU_TURBULENT_PR_EXPONENT_ND = 0.4
133
134# Turbulent boundary layer recovery factor
135# Used to calculate adiabatic wall temperature: Taw = Tc × recovery_factor
136# Typical range: 0.90-0.98 for turbulent boundary layers in rocket chambers
137# Accounts for kinetic energy recovery in the boundary layer
138# Higher values (closer to 1.0) indicate more efficient recovery
139DEFAULT_RECOVERY_FACTOR_ND = 0.94 # Typical value for turbulent flow in rocket chambers
140
141# ============================================================================
142# GEOMETRIC DEFAULTS
143# ============================================================================
144
145# Default chamber length
146# Units: m
147# Used when chamber length is not specified
148DEFAULT_CHAMBER_LEN_M = 0.1 # 10 cm
149
150# Default chamber diameter (fallback)
151# Units: m
152DEFAULT_CHAMBER_DIAM_M = 0.08 # 8 cm
153
154# Default throat area (fallback)
155# Units: m²
156DEFAULT_THROAT_AREA_M2 = 1e-3 # 1 cm²
157
158# Default throat diameter
159# Units: m
160DEFAULT_THROAT_DIAM_M = 0.033 # 3.3 cm
161
162# ============================================================================
163# COMBUSTION CHEMISTRY CONSTANTS
164# ============================================================================
165
166# Reference conditions for reaction rate calculations
167REF_PRESS_PA = 1.0e6 # 1 MPa [Pa]
168REF_TEMP_K = 3500.0 # K
169
170# Activation energies for different fuel types
171# Units: J/mol
172ACTIVATION_ENERGY_HC_J_MOL = 80000.0 # RP-1, kerosene
173ACTIVATION_ENERGY_H2_J_MOL = 40000.0 # H2
174
175# Pre-exponential factors for reaction rates
176# Units: 1/s
177PRE_EXPONENTIAL_HC_1_S = 1e7
178PRE_EXPONENTIAL_H2_1_S = 1e9
179
180# Pressure exponents for reaction rates
181PRESSURE_EXPONENT_HC_ND = 0.8
182PRESSURE_EXPONENT_H2_ND = 0.5
183PRESSURE_EXPONENT_PRE_FACTOR_ND = 0.3 # Pre-exponential pressure dependence
184
185# Reaction time scale reference
186# Units: s
187DEFAULT_REACTION_TIME_REF_S = 0.005 # 5 ms
188
189# Normalized activation energy for reaction time calculations
190# Dimensionless
191EA_NORM_FUEL_RICH_ND = 12.0
192EA_NORM_STOICHIOMETRIC_ND = 10.0
193EA_NORM_OXIDIZER_RICH_ND = 8.0
194
195# ============================================================================
196# ABLATIVE MATERIAL CONSTANTS
197# ============================================================================
198
199# Default ablative material properties
200DEFAULT_ABLATOR_DENS_KG_M3 = 1600.0 # kg/m³ (phenolic ablator typical)
201DEFAULT_ABLATOR_THERMAL_COND_W_M_K = 0.35 # W/(m·K)
202DEFAULT_ABLATOR_SPEC_HEAT_J_KG_K = 1500.0 # J/(kg·K)
203DEFAULT_ABLATOR_INIT_THICK_M = 0.01 # m (10 mm)
204DEFAULT_ABLATOR_SURF_TEMP_LIMIT_K = 1200.0 # K
205DEFAULT_ABLATOR_PYROLYSIS_TEMP_K = 900.0 # K
206DEFAULT_ABLATOR_BLOWING_EFF_ND = 0.8 # Dimensionless (0-1)
207DEFAULT_ABLATOR_CHAR_LAYER_COND_W_M_K = 0.2 # W/(m·K)
208DEFAULT_ABLATOR_CHAR_LAYER_THICK_M = 0.001 # m (1 mm)
209
210# Default heat of ablation
211# Units: J/kg
212DEFAULT_HEAT_ABLATION_J_KG = 2.5e6
213
214# Default throat recession multiplier (conservative)
215DEFAULT_THROAT_RECESSION_MULT_ND = 1.3
216
217# ============================================================================
218# GRAPHITE INSERT CONSTANTS
219# ============================================================================
220
221DEFAULT_GRAPHITE_DENS_KG_M3 = 1800.0 # kg/m³
222DEFAULT_GRAPHITE_THERMAL_COND_W_M_K = 100.0 # W/(m·K)
223DEFAULT_GRAPHITE_SURF_TEMP_LIMIT_K = 2500.0 # K
224DEFAULT_GRAPHITE_OXIDATION_TEMP_K = 800.0 # K
225DEFAULT_GRAPHITE_OXIDATION_RATE_M_S = 1e-6 # m/s
226DEFAULT_GRAPHITE_CHAR_LAYER_COND_W_M_K = 5.0 # W/(m·K)
227DEFAULT_GRAPHITE_CHAR_LAYER_THICK_M = 0.0005 # m (0.5 mm)
228
229# ============================================================================
230# FILM COOLING CONSTANTS
231# ============================================================================
232
233DEFAULT_FILM_MASS_FRAC_ND = 0.05 # 5% of total flow
234DEFAULT_FILM_EFF_REF_ND = 0.4 # 40% effectiveness
235DEFAULT_FILM_DECAY_LEN_M = 0.1 # m
236DEFAULT_FILM_REF_BLOWING_RATIO_ND = 0.5
237DEFAULT_FILM_BLOWING_EXP_ND = 0.6
238DEFAULT_FILM_REF_WALL_TEMP_K = 1100.0 # K
239
240# ============================================================================
241# SPRAY AND EVAPORATION CONSTANTS
242# ============================================================================
243
244# Default Sauter Mean Diameter (SMD)
245# Units: m
246DEFAULT_SMD_M = 100e-6 # 100 microns
247
248# Default evaporation length
249# Units: m
250DEFAULT_EVAPORATION_LEN_M = 0.1 # 10 cm
251
252# Default Weber number minimum for breakup
253DEFAULT_WEBER_MIN_ND = 15.0
254
255# ============================================================================
256# NUMERICAL AND COMPUTATIONAL CONSTANTS
257# ============================================================================
258
259# Small epsilon values for numerical stability
260EPSILON_SMALL = 1e-6
261EPSILON_TINY = 1e-8
262
263# ============================================================================
264# DEPRECATED: DO NOT USE THESE DEFAULT/FALLBACK CONSTANTS
265# ============================================================================
266#
267# These constants were previously used to hide missing values or failed
268# calculations. This practice is now FORBIDDEN in the codebase.
269#
270# **DO NOT USE THESE** - They are kept only for reference and to prevent
271# breaking old code during transition. Any new code using these will be rejected.
272#
273# Instead of using defaults/fallbacks:
274# 1. Explicitly validate that required values are present
275# 2. Raise clear ValueError/KeyError if values are missing
276# 3. Fix the root cause (missing config, failed calculation, etc.)
277#
278# Examples of INCORRECT usage (DO NOT DO THIS):
279# density = some_dict.get("density", FALLBACK_DENS_KG_M3) # WRONG!
280# velocity = max(calculated_velocity, MIN_VELOCITY_M_S) # WRONG!
281#
282# Examples of CORRECT usage:
283# if "density" not in some_dict:
284# raise KeyError("Missing 'density' in results")
285# density = some_dict["density"]
286# if density <= 0:
287# raise ValueError(f"Invalid density: {density}")
288# ============================================================================
289
290# DEPRECATED - DO NOT USE
291MIN_DENS_KG_M3 = 0.01 # kg/m³
292MIN_TEMP_K = 1.0 # K
293MIN_PRESS_PA = 1e5 # Pa (1 bar)
294MIN_VELOCITY_M_S = 0.0 # m/s
295MIN_AREA_M2 = 1e-6 # m²
296
297# DEPRECATED - DO NOT USE
298FALLBACK_DENS_KG_M3 = 1.0 # kg/m³
299FALLBACK_SOUND_SPEED_M_S = 1000.0 # m/s
300FALLBACK_VELOCITY_M_S = 50.0 # m/s
301FALLBACK_MACH_NUMBER_ND = 0.01
302FALLBACK_RESIDENCE_TIME_S = 0.001 # s (1 ms)
303FALLBACK_REYNOLDS_NUMBER_ND = 10000.0
304
305# ============================================================================
306# STABILITY AND FEED SYSTEM CONSTANTS
307# ============================================================================
308
309# Critical damping ratio for feed system stability
310CRITICAL_DAMPING_RATIO_ND = 0.05
311
312# Default feed system dimensions
313DEFAULT_FEED_LENGTH_M = 1.0 # m
314DEFAULT_FEED_DIAMETER_M = 0.01 # m (1 cm)
315
316# Default chamber time constant (fallback)
317# Units: s
318DEFAULT_CHAMBER_TIME_CONST_S = 0.01 # 10 ms
319
320# ============================================================================
321# COMBUSTION EFFICIENCY CONSTANTS
322# ============================================================================
323
324# Default combustion efficiency parameters
325# η_c* = 1 - C × exp(-K × L*)
326DEFAULT_EFFICIENCY_C_ND = 0.3
327DEFAULT_EFFICIENCY_K_ND = 0.15
328
329# Default frozen flow parameter
330DEFAULT_FROZEN_FLOW_PARAM_ND = 0.1
331
332# ============================================================================
333# TIME SERIES CONSTANTS
334# ============================================================================
335
336# Default decay constant for exponential time series
337DEFAULT_DECAY_CONST_ND = 3.0
338
339# Default power exponent for power-law time series
340DEFAULT_POWER_EXP_ND = 2.0
341
342# ============================================================================
343# PRESSURE DROP CONSTANTS
344# ============================================================================
345
346# Entrance loss coefficient (sharp entrance)
347K_ENTRANCE_SHARP_ND = 0.5
348
349# ============================================================================
350# UNIT CONVERSION CONSTANTS
351# ============================================================================
352
353# Feet to meters
354FEET_TO_METERS = 0.3048
355
356# Rankine to Kelvin conversion
357# T_Rankine = T_Kelvin × RANKINE_PER_KELVIN
358RANKINE_PER_KELVIN = 1.8
359
360# Viscosity unit conversion for Huzel & Huang's gas-viscosity fit (eq. 4-16),
361# mu = 46.6e-10 M^0.5 T[R]^0.6, which is in lbm/(in*s) -- MASS pounds, not lbf*s/in^2.
362# 1 lbm/(in*s) = 0.45359237 kg / 0.0254 m / s = 17.857967 Pa*s.
363# (Treating it as lbf*s/in^2, 6894.76, made the viscosity g_c = 386x too high and the
364# Bartz convective coefficient ~117x too low -- the long-standing "convection 283x low".)
365LBM_PER_IN_S_TO_PA_S = 0.45359237 / 0.0254
366#: lbf*s/in^2 -> Pa*s. Not the unit of the Huzel fit; kept for anything genuinely in lbf*s/in^2.
367LB_S_PER_IN2_TO_PA_S = 6894.76
368
369# ============================================================================
370# MIXING AND TURBULENCE CONSTANTS
371# ============================================================================
372
373# Default mixing efficiency factors
374DEFAULT_MIXING_EFFICIENCY_ND = 1.0 # Perfect mixing
375DEFAULT_TURBULENCE_EFFICIENCY_ND = 0.9 # 90% efficiency
376
377# Default spray quality factors (when unknown)
378DEFAULT_SMD_FACTOR_ND = 0.5 # Assume poor spray quality
379DEFAULT_EVAP_FACTOR_ND = 0.5 # Assume moderate evaporation
380
381# ============================================================================
382# REACTION PROGRESS CONSTANTS
383# ============================================================================
384
385# Default reaction progress values
386DEFAULT_PROGRESS_INJECTION_ND = 0.0 # No reaction at injection
387DEFAULT_PROGRESS_MID_ND = 0.5 # 50% at mid-chamber
388DEFAULT_PROGRESS_THROAT_ND = 1.0 # Complete at throat
389
390# ============================================================================
391# AMBIENT CONDITIONS
392# ============================================================================
393
394# Standard atmospheric conditions
395STANDARD_ATMOSPHERE_PRESS_PA = 101325.0 # Pa (sea level)
396STANDARD_AMBIENT_TEMP_K = 300.0 # K (27°C)
397
398# ============================================================================
399# FEED SYSTEM (lumped Δp_feed geometry helpers)
400# ============================================================================
401#
402# Used by ``delta_p_feed()`` in ``feed_loss.py`` via YAML ``feed_system``.
403# Nominal hydraulic ID for ``3/8 in`` tubing: (3/8) × (25.4 mm/in) [m].
404FEED_LINE_D_3_8_IN_NOMINAL_M = (3.0 / 8.0) * 25.4e-3
405#
406# Two identical parallel 3/8" runs with a balanced split carry ṁ_total/2 each.
407# Effective area doubles vs one line ⇒ equivalent round inlet for the lumped model:
408#
409# π (d_eq/2)² = 2 × π (d_line/2)² ⇒ d_eq = √2 × d_line
410#
411FEED_LINE_DUAL_3_8_EQUIVALENT_D_INLET_M = FEED_LINE_D_3_8_IN_NOMINAL_M * (2.0 ** 0.5)
412#
413# Explicit total hydraulic area consistent with dual 3/8″ lines [m²].
414FEED_LINE_DUAL_3_8_EQUIVALENT_A_HYDRAULIC_M2 = 2.0 * 3.141592653589793 * (
415 FEED_LINE_D_3_8_IN_NOMINAL_M / 2.0
416) ** 2
417