qualia_core_db/solvers/units/
constants.rs1use super::dimension::Dimension;
6use super::quantity::Quantity;
7
8pub const SPEED_OF_LIGHT: Quantity = Quantity::new(299_792_458.0, Dimension::VELOCITY);
10
11pub const GRAVITATIONAL: Quantity =
13 Quantity::new(6.674_30e-11, Dimension::new([3, -1, -2, 0, 0, 0, 0]));
14
15pub const PLANCK: Quantity =
17 Quantity::new(6.626_070_15e-34, Dimension::new([2, 1, -1, 0, 0, 0, 0]));
18
19pub 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
25pub const BOLTZMANN: Quantity =
27 Quantity::new(1.380_649e-23, Dimension::new([2, 1, -2, 0, -1, 0, 0]));
28
29pub const AVOGADRO: Quantity =
31 Quantity::new(6.022_140_76e23, Dimension::new([0, 0, 0, 0, 0, -1, 0]));
32
33pub const ELEMENTARY_CHARGE: Quantity = Quantity::new(1.602_176_634e-19, Dimension::CHARGE);
35
36pub 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
42pub const STEFAN_BOLTZMANN: Quantity =
44 Quantity::new(5.670_374_419e-8, Dimension::new([0, 1, -3, 0, -4, 0, 0]));
45
46pub const STANDARD_GRAVITY: Quantity = Quantity::new(9.806_65, Dimension::ACCELERATION);
48
49pub const STANDARD_ATMOSPHERE: Quantity = Quantity::new(101_325.0, Dimension::PRESSURE);
51
52pub const ELECTRON_MASS: Quantity = Quantity::new(9.109_383_7015e-31, Dimension::MASS);
54pub 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 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 let nu = Quantity::new(5.0e14, Dimension::FREQUENCY); 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}