Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion to Watts #465

Closed
jchidley opened this issue Mar 15, 2024 · 1 comment
Closed

Conversion to Watts #465

jchidley opened this issue Mar 15, 2024 · 1 comment

Comments

@jchidley
Copy link

I have this function:

    fn ventilation_heat_loss() {
        let β = 50.0; //efficiency as percentage
        let cp_air = SpecificHeatCapacity::new::<kilojoule_per_kilogram_kelvin>(0.7171);
        let ρ_air = MassDensity::new::<kilogram_per_cubic_meter>(1.276);
        let t_i = TemperatureInterval::new::<temperature_interval::degree_celsius>(20.0);
        let t_o = TemperatureInterval::new::<temperature_interval::degree_celsius>(10.0);
        let qv = VolumeRate::new::<cubic_meter_per_second>(15.0 / 1000.0);
        let hv = (1.0 - β / 100.0) * cp_air * ρ_air * qv * (t_i - t_o); // watts

        println!("{hv:#?}");

This prints an answer in these units: m^2 kg^1 s^-3 or, as I normally think about it, watts.

I can't figure out, for the life of me, how to get the answer into actual watts in uom (or even what the correct watts is). I can see that uom a really comprehensive and useful library but, as a newbie to rust and the library, it is daunting with a few examples and no tutorial.

This doesn't work:

62 |         let watts = Power::new::<watt>(hv);
   |                     ------------------ ^^ expected `f32`, found `Quantity<dyn Dimension<I = ..., J = ..., Kind = ..., L = ..., M = ..., N = ..., T = ..., Th = ...>, ..., ...>`

Which tells me that I am doing the conversion wrongly.

@jchidley
Copy link
Author

So, of course, I found the answer in the unit.rs example a few minutes after I posted my question.

Once I had added this two lines at the top:

use uom::fmt::DisplayStyle::Description;
use uom::si::power::watt;

I could print using this statement:

println!("{}", hv.into_format_args(watt, Description));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant