aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsam-anthony <samanthony6@protonmail.com>2022-01-15 20:31:04 -0330
committersam-anthony <samanthony6@protonmail.com>2022-01-15 20:31:04 -0330
commitef3980225a0a0ed5bea0d748709c1f227e33c851 (patch)
treeeafe6e82c02224ea62b5c7acdf75ae2fd93f2187
downloadvolute-ef3980225a0a0ed5bea0d748709c1f227e33c851.zip
units of measurement
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock241
-rw-r--r--Cargo.toml10
-rw-r--r--src/flow_rate.rs32
-rw-r--r--src/lib.rs14
-rw-r--r--src/main.rs16
-rw-r--r--src/mass.rs31
-rw-r--r--src/pressure.rs11
-rw-r--r--src/temperature.rs11
-rw-r--r--src/volume.rs23
10 files changed, 390 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..ce9c6e1
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,241 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "cassowary"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "crossterm"
+version = "0.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0ebde6a9dd5e331cd6c6f48253254d117642c31653baa475e394657c59c1f7d"
+dependencies = [
+ "bitflags",
+ "crossterm_winapi",
+ "libc",
+ "mio",
+ "parking_lot",
+ "signal-hook",
+ "signal-hook-mio",
+ "winapi",
+]
+
+[[package]]
+name = "crossterm_winapi"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a6966607622438301997d3dac0d2f6e9a90c68bb6bc1785ea98456ab93c0507"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "instant"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.112"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
+
+[[package]]
+name = "lock_api"
+version = "0.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
+dependencies = [
+ "scopeguard",
+]
+
+[[package]]
+name = "log"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "mio"
+version = "0.7.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
+dependencies = [
+ "libc",
+ "log",
+ "miow",
+ "ntapi",
+ "winapi",
+]
+
+[[package]]
+name = "miow"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "ntapi"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "parking_lot"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
+dependencies = [
+ "instant",
+ "lock_api",
+ "parking_lot_core",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
+dependencies = [
+ "cfg-if",
+ "instant",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "winapi",
+]
+
+[[package]]
+name = "redox_syscall"
+version = "0.2.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "scopeguard"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
+
+[[package]]
+name = "signal-hook"
+version = "0.3.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d"
+dependencies = [
+ "libc",
+ "signal-hook-registry",
+]
+
+[[package]]
+name = "signal-hook-mio"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29fd5867f1c4f2c5be079aee7a2adf1152ebb04a4bc4d341f504b7dece607ed4"
+dependencies = [
+ "libc",
+ "mio",
+ "signal-hook",
+]
+
+[[package]]
+name = "signal-hook-registry"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "smallvec"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
+
+[[package]]
+name = "tui"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "39c8ce4e27049eed97cfa363a5048b09d995e209994634a0efc26a14ab6c0c23"
+dependencies = [
+ "bitflags",
+ "cassowary",
+ "crossterm",
+ "unicode-segmentation",
+ "unicode-width",
+]
+
+[[package]]
+name = "unicode-segmentation"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
+
+[[package]]
+name = "unicode-width"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
+
+[[package]]
+name = "volute"
+version = "0.1.0"
+dependencies = [
+ "crossterm",
+ "tui",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..a37a388
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "volute"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+crossterm = "0.20"
+tui = { version="0.16", default-features=false, features=['crossterm'] }
diff --git a/src/flow_rate.rs b/src/flow_rate.rs
new file mode 100644
index 0000000..f8e15e0
--- /dev/null
+++ b/src/flow_rate.rs
@@ -0,0 +1,32 @@
+use crate::{mass::Mass, volume::Volume};
+use std::time::Duration;
+
+pub struct MassFlowRate {
+ pub mass: Mass,
+ pub duration: Duration,
+}
+
+impl MassFlowRate {
+ pub fn as_kilograms_per_minute(&self) -> f64 {
+ self.mass.as_kilograms() / (self.duration.as_secs() as f64 / 60.)
+ }
+
+ pub fn as_pounds_per_minute(&self) -> f64 {
+ self.mass.as_pounds() / (self.duration.as_secs() as f64 / 60.)
+ }
+}
+
+pub struct VolumetricFlowRate {
+ pub volume: Volume,
+ pub duration: Duration,
+}
+
+impl VolumetricFlowRate {
+ pub fn as_cubic_metres_per_second(&self) -> f64 {
+ self.volume.as_cubic_metres() / self.duration.as_secs() as f64
+ }
+
+ pub fn as_cubic_feet_per_minute(&self) -> f64 {
+ self.volume.as_cubic_feet() / (self.duration.as_secs() as f64 / 60.)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..79dda37
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,14 @@
+pub mod flow_rate;
+pub mod mass;
+pub mod pressure;
+pub mod temperature;
+pub mod volume;
+
+use crate::{pressure::Pressure, temperature::Temperature, volume::Volume};
+
+const GAS_CONSTANT: f64 = 8.314472;
+const MOLAR_MASS_OF_AIR: f64 = 0.0289647; // Kg/mol
+
+fn moles_from_gas_law(pressure: Pressure, volume: Volume, temperature: Temperature) -> f64 {
+ (pressure.as_pascals() * volume.as_cubic_metres()) / (GAS_CONSTANT * temperature.as_kelvin())
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..9c9692c
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,16 @@
+use std::time::Duration;
+use volute::{flow_rate::MassFlowRate, mass::Mass, pressure::Pressure};
+
+fn main() {
+ let mass = Mass::from_grams(1600.);
+ println!("{} Kg", mass.as_kilograms());
+
+ let mass_flow_rate = MassFlowRate {
+ mass: mass,
+ duration: Duration::from_secs(5),
+ };
+ println!("{:.2} Kg/min.", mass_flow_rate.as_kilograms_per_minute());
+
+ let pressure = Pressure::from_pascals(1500.52);
+ println!("{} Pa", pressure.as_pascals());
+}
diff --git a/src/mass.rs b/src/mass.rs
new file mode 100644
index 0000000..9c57f16
--- /dev/null
+++ b/src/mass.rs
@@ -0,0 +1,31 @@
+pub struct Mass(f64); // Base unit is grams
+
+impl Mass {
+ /* constructors */
+ pub fn from_grams(grams: f64) -> Mass {
+ Mass(grams)
+ }
+
+ pub fn from_kilograms(kilos: f64) -> Mass {
+ Mass(kilos / 1000.)
+ }
+
+ pub fn from_moles(moles: f64, molar_mass: f64) -> Mass {
+ let kilos = moles * molar_mass;
+ Mass::from_kilograms(kilos)
+ }
+
+ /* metric */
+ pub fn as_grams(&self) -> f64 {
+ self.0
+ }
+
+ pub fn as_kilograms(&self) -> f64 {
+ self.0 / 1000.
+ }
+
+ /* imperial */
+ pub fn as_pounds(&self) -> f64 {
+ self.0 * 0.002204623
+ }
+}
diff --git a/src/pressure.rs b/src/pressure.rs
new file mode 100644
index 0000000..f746186
--- /dev/null
+++ b/src/pressure.rs
@@ -0,0 +1,11 @@
+pub struct Pressure(f64); // Base unit is pascals
+
+impl Pressure {
+ pub fn from_pascals(pascals: f64) -> Self {
+ Self(pascals)
+ }
+
+ pub fn as_pascals(&self) -> f64 {
+ self.0
+ }
+}
diff --git a/src/temperature.rs b/src/temperature.rs
new file mode 100644
index 0000000..2eac48d
--- /dev/null
+++ b/src/temperature.rs
@@ -0,0 +1,11 @@
+pub struct Temperature(f64); // Base unit is kelvin
+
+impl Temperature {
+ pub fn from_kelvin(kelvin: f64) -> Temperature {
+ Temperature(kelvin)
+ }
+
+ pub fn as_kelvin(&self) -> f64 {
+ self.0
+ }
+}
diff --git a/src/volume.rs b/src/volume.rs
new file mode 100644
index 0000000..d6ef206
--- /dev/null
+++ b/src/volume.rs
@@ -0,0 +1,23 @@
+pub struct Volume(f64); // Base unit is cubic metres
+
+impl Volume {
+ pub fn from_cubic_metres(cubic_metres: f64) -> Volume {
+ Volume(cubic_metres)
+ }
+
+ pub fn from_cubic_centimetres(cubic_centimetres: f64) -> Volume {
+ Volume(cubic_centimetres / 1_000_000.)
+ }
+
+ pub fn as_cubic_metres(&self) -> f64 {
+ self.0
+ }
+
+ pub fn as_cubic_centimetres(&self) -> f64 {
+ self.0 * 1_000_000.
+ }
+
+ pub fn as_cubic_feet(&self) -> f64 {
+ self.0 * 35.3147
+ }
+}