Compare commits

...
Author SHA1 Message Date
Christian Svensson 9e19ba9bcd engine: name the temperature unit from the model's unit system
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.
2026-10-18 12:40:36 +02:00
3 changed files with 11 additions and 5 deletions

No files matched your search

+8 -3
View File
@@ -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<String> {
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);
}
+1 -1
View File
@@ -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;
+2 -1
View File
@@ -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.