forked from 1b-agent/fieldcraft-upstream
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.
This commit is contained in:
1 parent
6b87dc508d
commit
9e19ba9bcd
3 files changed
+11
-5
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user