Skip to main content

qualia_core_db/solvers/units/
mod.rs

1//! **Units, physical constants & dimensional analysis** (Gap analysis §3.6).
2//!
3//! A unit-correct quantity is a value *plus* its physical dimension, and arithmetic on
4//! quantities is **dimensionally checked**: you cannot add a length to a time, and
5//! multiplying a force by a distance yields an energy. This serves the NL→3D /
6//! engineering work directly (unit-correct geometry and materials) and is a small,
7//! self-contained foundation the rest of the engine can lean on.
8//!
9//! Mission fit: dimensional consistency is a *correctness guard* — a calculation that
10//! is dimensionally wrong is wrong, full stop, and the type system catches it before a
11//! fabricated number can propagate. Fail-closed throughout ([`UnitsError`]).
12//!
13//! Layers (one concern per file, §11):
14//! * [`dimension`] — the 7-vector of SI base-dimension exponents + named dimensions.
15//! * [`quantity`] — a value with a dimension, and checked arithmetic.
16//! * [`conversion`] — units (linear factor + affine offset for temperature) and convert.
17//! * [`constants`] — CODATA physical constants as dimensioned quantities.
18//!
19//! Kernel-class `ElementwiseMap` (trivial CPU).
20
21pub mod constants;
22pub mod conversion;
23pub mod dimension;
24pub mod quantity;
25
26pub use conversion::{convert, Unit};
27pub use dimension::Dimension;
28pub use quantity::Quantity;
29
30/// Fail-closed errors for unit handling.
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub enum UnitsError {
33    /// An operation required matching dimensions and they differed (e.g. length + time,
34    /// or converting metres to seconds).
35    IncompatibleDimensions,
36    /// A value could not be represented (e.g. a non-integer dimension exponent).
37    InvalidOperation,
38}
39
40impl core::fmt::Display for UnitsError {
41    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42        match self {
43            UnitsError::IncompatibleDimensions => write!(f, "incompatible physical dimensions"),
44            UnitsError::InvalidOperation => write!(f, "invalid dimensional operation"),
45        }
46    }
47}
48impl std::error::Error for UnitsError {}