mechanical_engineering/
constants.rs1pub mod gas {
2 use crate::units::pressure::{self, Pressure};
3 use crate::units::temperature::{self, Temperature};
4 use ratatui::text::Text;
5
6 const IDEAL_GAS_CONST: f32 = 8.314_463;
8
9 pub fn gas_list() -> Vec<Gas> {
10 vec![AIR, ARGON, NITROGEN]
11 }
12
13 pub struct Gas {
15 pub name: &'static str,
16 pub chemical_formula: &'static str,
17 pub specific_heat_cp: f32,
18 pub specific_heat_cv: f32,
19 pub standard_density: f32,
20 pub molar_mass: f32,
21 }
22
23 impl Gas {
24 pub fn density(&self, temperature: Temperature, pressure: Pressure) -> f32 {
25 let ref_pressure = 100.0; let ref_temperature = 273.15; let mut temperature = temperature.clone();
29 temperature.convert_unit(temperature::Unit::K);
30 let mut pressure = pressure.clone();
31 pressure.convert_unit(pressure::Unit::Kpa);
32 self.standard_density * pressure.value() / ref_pressure * ref_temperature
33 / temperature.value()
34 }
35
36 pub fn name(&self) -> &'static str {
37 self.name
38 }
39
40 pub fn formula(&self) -> &'static str {
41 self.chemical_formula
42 }
43
44 pub fn specific_heat_cp(&self) -> f32 {
45 self.specific_heat_cp
46 }
47
48 pub fn specific_heat_cv(&self) -> f32 {
49 self.specific_heat_cv
50 }
51
52 pub fn specific_heat_ratio(&self) -> f32 {
53 self.specific_heat_cp / self.specific_heat_cv
54 }
55
56 pub fn standard_density(&self) -> String {
57 self.standard_density.to_string()
58 }
59
60 pub fn molar_mass(&self) -> f32 {
61 self.molar_mass
62 }
63 }
64
65 impl<'a> Into<Text<'a>> for Gas {
66 fn into(self) -> Text<'a> {
67 let name = ratatui::text::Line::from(self.name);
68 let lines = vec![name];
69 Text { lines }
70 }
71 }
72
73 pub const AIR: Gas = Gas {
74 name: "Air",
75 chemical_formula: "",
76 specific_heat_cp: 1.005,
77 specific_heat_cv: 0.7164,
78 standard_density: 1.293, molar_mass: 28.9647,
80 };
81
82 pub const ARGON: Gas = Gas {
83 name: "Argon",
84 chemical_formula: "Ar",
85 specific_heat_cp: 0.520,
86 specific_heat_cv: 0.312,
87 standard_density: 1.7837, molar_mass: 39.948,
89 };
90
91 pub const NITROGEN: Gas = Gas {
92 name: "Nitrogen",
93 chemical_formula: "N2",
94 specific_heat_cp: 1.04,
95 specific_heat_cv: 0.743,
96 standard_density: 1.2506, molar_mass: 28.013,
98 };
99}
100
101pub mod fluid {
102 pub mod specific_heat {}
103}