Update project structure and configurations
This commit is contained in:
@@ -28,23 +28,26 @@ fn one() -> f64 {
|
||||
/// | `f_ua` | UA factor | UA_eff = f_ua × UA_nominal | Evaporator, Condenser |
|
||||
/// | `f_power` | power factor | Ẇ_eff = f_power × Ẇ_nominal | Compressor |
|
||||
/// | `f_etav` | volumetric efficiency | η_v,eff = f_etav × η_v,nominal | Compressor (displacement) |
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Calib {
|
||||
/// f_m: ṁ_eff = f_m × ṁ_nominal (Compressor, Valve)
|
||||
#[serde(default = "one", alias = "calib_flow")]
|
||||
#[serde(default = "one", alias = "f_m", alias = "calib_flow")]
|
||||
pub f_m: f64,
|
||||
/// f_dp: ΔP_eff = f_dp × ΔP_nominal (Pipe, HX)
|
||||
#[serde(default = "one", alias = "calib_dpr")]
|
||||
#[serde(default = "one", alias = "f_dp", alias = "calib_dpr")]
|
||||
pub f_dp: f64,
|
||||
/// f_ua: UA_eff = f_ua × UA_nominal (Evaporator, Condenser)
|
||||
#[serde(default = "one", alias = "calib_ua")]
|
||||
#[serde(default = "one", alias = "f_ua", alias = "calib_ua")]
|
||||
pub f_ua: f64,
|
||||
/// f_power: Ẇ_eff = f_power × Ẇ_nominal (Compressor)
|
||||
#[serde(default = "one")]
|
||||
#[serde(default = "one", alias = "f_power")]
|
||||
pub f_power: f64,
|
||||
/// f_etav: η_v,eff = f_etav × η_v,nominal (Compressor displacement)
|
||||
#[serde(default = "one")]
|
||||
#[serde(default = "one", alias = "f_etav")]
|
||||
pub f_etav: f64,
|
||||
/// Traceability: identifier or hash of the test data used to derive these factors.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub calibration_source: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Calib {
|
||||
@@ -55,6 +58,7 @@ impl Default for Calib {
|
||||
f_ua: 1.0,
|
||||
f_power: 1.0,
|
||||
f_etav: 1.0,
|
||||
calibration_source: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,6 +106,18 @@ const MIN_F: f64 = 0.5;
|
||||
const MAX_F: f64 = 2.0;
|
||||
|
||||
impl Calib {
|
||||
/// Updates a single factor by name. Returns `true` if the factor was recognized.
|
||||
pub fn set_factor(&mut self, factor: &str, value: f64) -> bool {
|
||||
match factor {
|
||||
"f_m" => { self.f_m = value; true }
|
||||
"f_dp" => { self.f_dp = value; true }
|
||||
"f_ua" => { self.f_ua = value; true }
|
||||
"f_power" => { self.f_power = value; true }
|
||||
"f_etav" => { self.f_etav = value; true }
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Validates that all factors lie in [0.5, 2.0]. Returns `Ok(())` or the first invalid factor.
|
||||
pub fn validate(&self) -> Result<(), CalibValidationError> {
|
||||
let check = |name: &'static str, value: f64| {
|
||||
@@ -146,6 +162,7 @@ mod tests {
|
||||
f_ua: 2.0,
|
||||
f_power: 1.0,
|
||||
f_etav: 1.0,
|
||||
calibration_source: None,
|
||||
};
|
||||
assert!(ok.validate().is_ok());
|
||||
|
||||
@@ -173,6 +190,7 @@ mod tests {
|
||||
f_ua: 1.0,
|
||||
f_power: 1.05,
|
||||
f_etav: 1.0,
|
||||
calibration_source: None,
|
||||
};
|
||||
let json = serde_json::to_string(&c).unwrap();
|
||||
let c2: Calib = serde_json::from_str(&json).unwrap();
|
||||
@@ -190,4 +208,23 @@ mod tests {
|
||||
assert_eq!(c.f_power, 1.0);
|
||||
assert_eq!(c.f_etav, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calib_calibration_source() {
|
||||
let c = Calib {
|
||||
f_m: 1.05,
|
||||
calibration_source: Some("test-bench-2024-01-15".into()),
|
||||
..Default::default()
|
||||
};
|
||||
let json = serde_json::to_string(&c).unwrap();
|
||||
let c2: Calib = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(c2.calibration_source.as_deref(), Some("test-bench-2024-01-15"));
|
||||
|
||||
// Without calibration_source, field is absent from JSON
|
||||
let c_no = Calib::default();
|
||||
let json_no = serde_json::to_string(&c_no).unwrap();
|
||||
assert!(!json_no.contains("calibrationSource"));
|
||||
let c3: Calib = serde_json::from_str(&json_no).unwrap();
|
||||
assert_eq!(c3.calibration_source, None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,11 @@ impl std::error::Error for InvalidStateLengthError {}
|
||||
/// assert_eq!(h.to_kilojoules_per_kg(), 400.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SystemState {
|
||||
#[serde(alias = "data")]
|
||||
data: Vec<f64>,
|
||||
#[serde(alias = "edge_count")]
|
||||
edge_count: usize,
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ use serde::{Deserialize, Serialize};
|
||||
/// assert_eq!(p.to_pascals(), 100_000.0);
|
||||
/// assert_eq!(p.to_bar(), 1.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Pressure(pub f64);
|
||||
|
||||
impl Pressure {
|
||||
@@ -148,7 +148,7 @@ impl Div<f64> for Pressure {
|
||||
/// assert_eq!(t.to_kelvin(), 273.15);
|
||||
/// assert_eq!(t.to_celsius(), 0.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Temperature(pub f64);
|
||||
|
||||
impl Temperature {
|
||||
@@ -247,7 +247,7 @@ impl Div<f64> for Temperature {
|
||||
/// let h = Enthalpy::from_joules_per_kg(1000.0);
|
||||
/// assert_eq!(h.to_joules_per_kg(), 1000.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Enthalpy(pub f64);
|
||||
|
||||
impl Enthalpy {
|
||||
@@ -350,7 +350,7 @@ pub const MIN_MASS_FLOW_REGULARIZATION_KG_S: f64 = 1e-12;
|
||||
/// let m = MassFlow::from_kg_per_s(0.5);
|
||||
/// assert_eq!(m.to_kg_per_s(), 0.5);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct MassFlow(pub f64);
|
||||
|
||||
impl MassFlow {
|
||||
@@ -450,7 +450,7 @@ impl Div<f64> for MassFlow {
|
||||
/// assert_eq!(p.to_watts(), 1000.0);
|
||||
/// assert_eq!(p.to_kilowatts(), 1.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Power(pub f64);
|
||||
|
||||
impl Power {
|
||||
@@ -551,7 +551,7 @@ impl Div<f64> for Power {
|
||||
/// assert_eq!(c.to_fraction(), 0.5);
|
||||
/// assert_eq!(c.to_percent(), 50.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Concentration(pub f64);
|
||||
|
||||
impl Concentration {
|
||||
@@ -649,7 +649,7 @@ impl Div<f64> for Concentration {
|
||||
/// let reverse = VolumeFlow::from_m3_per_s(-0.5);
|
||||
/// assert_eq!(reverse.to_m3_per_s(), -0.5);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct VolumeFlow(pub f64);
|
||||
|
||||
impl VolumeFlow {
|
||||
@@ -760,7 +760,7 @@ impl Div<f64> for VolumeFlow {
|
||||
/// assert_eq!(rh.to_fraction(), 0.6);
|
||||
/// assert_eq!(rh.to_percent(), 60.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct RelativeHumidity(pub f64);
|
||||
|
||||
impl RelativeHumidity {
|
||||
@@ -854,7 +854,7 @@ impl Div<f64> for RelativeHumidity {
|
||||
/// let q2 = VaporQuality::from_fraction(0.5);
|
||||
/// assert_eq!(q2.to_percent(), 50.0);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct VaporQuality(pub f64);
|
||||
|
||||
impl VaporQuality {
|
||||
@@ -950,7 +950,7 @@ impl Div<f64> for VaporQuality {
|
||||
}
|
||||
|
||||
/// Entropy in J/(kg·K).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Entropy(pub f64);
|
||||
|
||||
impl Entropy {
|
||||
|
||||
Reference in New Issue
Block a user