Compare commits

...

2 Commits

Author SHA1 Message Date
elfeiin da397ddd25
improved 2024-04-27 21:56:06 -07:00
elfeiin e0d2c821da
updated to work new way 2024-04-27 21:53:01 -07:00
1 changed files with 23 additions and 8 deletions

View File

@ -1,8 +1,20 @@
#![feature(generic_const_exprs)]
use std::f64::consts::TAU;
use units::{
dimensions::{Energy, Frequency, Length, Mass, MassMoment, Scalar},
prefixes::Kilo,
units::{Grams, Joules, Meters, Rpm, Watthours},
dimensions::{
Energy,
Frequency,
Length,
Mass,
MassMoment,
}, units::{
Gram,
Joule,
Meter,
Rpm,
Watthour,
}, Kilo, Unit
};
#[derive(Debug)]
@ -21,6 +33,7 @@ impl Flywheel {
inertial_constant: 0.606,
}
}
pub fn new_good(mass: Mass, radius: Length) -> Self {
Self {
mass,
@ -29,9 +42,11 @@ impl Flywheel {
inertial_constant: 1.0,
}
}
pub fn inertial_moment(&self) -> MassMoment {
self.mass * self.inertial_constant * (self.radius * self.radius)
}
pub fn energy(&self, spin_rate: Frequency) -> Energy {
let angular_velocity = spin_rate * TAU;
self.inertial_moment() * (angular_velocity * angular_velocity) / 2.0
@ -39,14 +54,14 @@ impl Flywheel {
}
fn main() {
let flywheel = Flywheel::new_good(Mass::new::<Kilo<Grams>>(300.0), Length::new::<Meters>(0.5));
let frequency = Frequency::new::<Rpm>(60000.0);
let flywheel = Flywheel::new_good(Kilo::<Gram>::new(300.0), Meter::new(0.5));
let frequency = Rpm::new(60000.0);
let energy = flywheel.energy(frequency);
println!["{flywheel:?}"];
println![
"Energy at {} rpm: {} joules or {} kilowatthours",
frequency.val::<Rpm>(),
energy.val::<Joules>(),
energy.val::<Watthours>() / 1000.0
frequency.to_units::<Rpm>(),
energy.to_units::<Joule>(),
energy.to_units::<Watthour>() / 1000.0
];
}