Skip to main content

qualia_core_db/solvers/units/
constants.rs

1//! Physical constants as dimensioned [`Quantity`]s (CODATA / SI-2019 defined values
2//! where exact). Each carries its dimension so it composes correctly in unit-checked
3//! arithmetic — e.g. `½·m·v²` divided by `k_B·T` is dimensionless by construction.
4
5use super::dimension::Dimension;
6use super::quantity::Quantity;
7
8/// Speed of light in vacuum, `c` (exact, SI-2019). 299 792 458 m/s.
9pub const SPEED_OF_LIGHT: Quantity = Quantity::new(299_792_458.0, Dimension::VELOCITY);
10
11/// Newtonian constant of gravitation, `G`. m³·kg⁻¹·s⁻².
12pub const GRAVITATIONAL: Quantity =
13    Quantity::new(6.674_30e-11, Dimension::new([3, -1, -2, 0, 0, 0, 0]));
14
15/// Planck constant, `h` (exact, SI-2019). J·s = m²·kg·s⁻¹.
16pub const PLANCK: Quantity =
17    Quantity::new(6.626_070_15e-34, Dimension::new([2, 1, -1, 0, 0, 0, 0]));
18
19/// Reduced Planck constant, `ħ = h/2π`. Same dimension as `h`.
20pub const REDUCED_PLANCK: Quantity = Quantity::new(
21    6.626_070_15e-34 / (2.0 * core::f64::consts::PI),
22    Dimension::new([2, 1, -1, 0, 0, 0, 0]),
23);
24
25/// Boltzmann constant, `k_B` (exact, SI-2019). J/K = m²·kg·s⁻²·K⁻¹.
26pub const BOLTZMANN: Quantity =
27    Quantity::new(1.380_649e-23, Dimension::new([2, 1, -2, 0, -1, 0, 0]));
28
29/// Avogadro constant, `N_A` (exact, SI-2019). mol⁻¹.
30pub const AVOGADRO: Quantity =
31    Quantity::new(6.022_140_76e23, Dimension::new([0, 0, 0, 0, 0, -1, 0]));
32
33/// Elementary charge, `e` (exact, SI-2019). Coulomb = A·s.
34pub const ELEMENTARY_CHARGE: Quantity = Quantity::new(1.602_176_634e-19, Dimension::CHARGE);
35
36/// Molar gas constant, `R = N_A·k_B` (exact). J·mol⁻¹·K⁻¹.
37pub const GAS_CONSTANT: Quantity = Quantity::new(
38    8.314_462_618_153_24,
39    Dimension::new([2, 1, -2, 0, -1, -1, 0]),
40);
41
42/// Stefan–Boltzmann constant, `σ`. W·m⁻²·K⁻⁴ = kg·s⁻³·K⁻⁴.
43pub const STEFAN_BOLTZMANN: Quantity =
44    Quantity::new(5.670_374_419e-8, Dimension::new([0, 1, -3, 0, -4, 0, 0]));
45
46/// Standard gravity, `g₀` (defined). m/s².
47pub const STANDARD_GRAVITY: Quantity = Quantity::new(9.806_65, Dimension::ACCELERATION);
48
49/// Standard atmosphere (defined). 101 325 Pa.
50pub const STANDARD_ATMOSPHERE: Quantity = Quantity::new(101_325.0, Dimension::PRESSURE);
51
52/// Electron mass, `m_e`. kg.
53pub const ELECTRON_MASS: Quantity = Quantity::new(9.109_383_7015e-31, Dimension::MASS);
54/// Proton mass, `m_p`. kg.
55pub const PROTON_MASS: Quantity = Quantity::new(1.672_621_923_69e-27, Dimension::MASS);
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn constants_carry_correct_dimensions() {
63        assert_eq!(SPEED_OF_LIGHT.dimension, Dimension::VELOCITY);
64        assert_eq!(STANDARD_GRAVITY.dimension, Dimension::ACCELERATION);
65        assert_eq!(ELEMENTARY_CHARGE.dimension, Dimension::CHARGE);
66        assert_eq!(STANDARD_ATMOSPHERE.dimension, Dimension::PRESSURE);
67    }
68
69    #[test]
70    fn gas_constant_is_avogadro_times_boltzmann() {
71        // R = N_A · k_B, both value and dimension.
72        let r = AVOGADRO.mul(&BOLTZMANN);
73        assert!((r.value - GAS_CONSTANT.value).abs() / GAS_CONSTANT.value < 1e-9);
74        assert_eq!(r.dimension, GAS_CONSTANT.dimension);
75    }
76
77    #[test]
78    fn photon_energy_e_equals_h_nu_is_dimensionally_energy() {
79        // E = h·ν, with ν a frequency (s⁻¹) → energy.
80        let nu = Quantity::new(5.0e14, Dimension::FREQUENCY); // visible light
81        let e = PLANCK.mul(&nu);
82        assert_eq!(e.dimension, Dimension::ENERGY);
83        assert!(e.value > 0.0);
84    }
85
86    #[test]
87    fn thermal_energy_kt_is_energy() {
88        let t = Quantity::new(300.0, Dimension::TEMPERATURE);
89        let kt = BOLTZMANN.mul(&t);
90        assert_eq!(kt.dimension, Dimension::ENERGY);
91    }
92}