From 9e19ba9bcd3b70b91ed6e6c6ec86448e38e0e1d8 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sun, 18 Oct 2026 12:40:36 +0200 Subject: [PATCH] engine: name the temperature unit from the model's unit system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The results legend, probe rows and replies said "°C or K" for a temperature. The unit system says which scale goes with it, so name it: °C for the metric systems, °F for in-lbf-s-psi. Values are still shown as entered; nothing is converted. An unspecified system still names no unit. Part of #157. --- crates/engine/src/results.rs | 11 ++++++++--- crates/ui-egui/src/results.rs | 2 +- docs/control-protocol.md | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/results.rs b/crates/engine/src/results.rs index b0526f0..936beb9 100644 --- a/crates/engine/src/results.rs +++ b/crates/engine/src/results.rs @@ -332,8 +332,9 @@ pub enum Quantity { impl Quantity { /// Its unit in `system` (`mm`, `MPa`, `N·mm`, `mW`…), or `None` (no unit, or the system is - /// unspecified). The model never converts, so this only names the system's own unit; a - /// temperature is in whatever scale its values were entered in. + /// unspecified). The model never converts, so this only names the system's own unit. A + /// temperature is named in the scale that goes with the system: °C for the metric systems, + /// °F for inch–pound-force–second. pub fn unit(self, system: UnitSystem) -> Option { let dim = match self { Quantity::None => return None, @@ -359,7 +360,8 @@ impl Quantity { Quantity::Energy => energy, Quantity::HeatFlow => power, Quantity::HeatFlux => flux, - _ => "°C or K", + _ if system == UnitSystem::InLbfS => "°F", + _ => "°C", } .into(), ); @@ -874,6 +876,9 @@ mod tests { assert_eq!(unit(Quantity::Moment, mm).as_deref(), Some("N·mm")); assert_eq!(unit(Quantity::Energy, UnitSystem::MKgS).as_deref(), Some("J")); assert_eq!(unit(Quantity::Temperature, UnitSystem::Unspecified), None); + assert_eq!(unit(Quantity::Temperature, mm).as_deref(), Some("°C")); + assert_eq!(unit(Quantity::Temperature, UnitSystem::MKgS).as_deref(), Some("°C")); + assert_eq!(unit(Quantity::Temperature, UnitSystem::InLbfS).as_deref(), Some("°F")); assert_eq!(unit(Quantity::None, mm), None); } diff --git a/crates/ui-egui/src/results.rs b/crates/ui-egui/src/results.rs index 232e582..9a801b7 100644 --- a/crates/ui-egui/src/results.rs +++ b/crates/ui-egui/src/results.rs @@ -494,7 +494,7 @@ pub(crate) mod tests { s.execute("results.slice", &json!({"field": "temperature"})).unwrap(); let p = plot_at(&s, &base, None).unwrap(); assert_eq!(p.contour.as_ref().unwrap().field, Field::Temperature); - assert!(Field::Temperature.title(&p.result, p.units).contains("°C or K")); + assert!(Field::Temperature.title(&p.result, p.units).ends_with("[°C]")); assert!(Field::available(&p.result).any(|f| f == Field::Temperature)); assert!(p.contour.as_ref().unwrap().max.1 > 20.0); let last = p.frame().unwrap().2 - 1; diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 62b6029..f74b4df 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -146,7 +146,8 @@ A solved fluid step with temperature in every saved frame offers `temperature` i Results field list and through `results.contour`, `results.slice`, `results.surface` and `results.streamlines` (`{"field":"temperature"}`). Slices and obstacle surfaces sample fluid-cell temperature; streamline colours sample temperature along the velocity traces. -The legend and existing `solve.probe` use the model's temperature scale, without conversion. +The legend and `solve.probe` name the temperature unit that goes with the model's unit system +(°C for the metric systems, °F for in-lbf-s-psi); values are shown as entered, never converted. An isothermal step hides the field and rejects an explicit request with an explanation. The frame slider and `results.frame` select the field's time, including the initial frame.