salt_water/
property_tables.rs

1use strum::IntoEnumIterator;
2use strum_macros::{EnumCount,EnumIter};
3use std::sync::LazyLock;
4use cobia::{CapeOpenMap,CapeStringConstProvider};
5
6/// Singleton table of supported properties with lookup function
7pub(crate) struct PropertyTables {
8    /// Lookup table for single phase properties by identifier, case insensive.
9	single_phase_property_map : CapeOpenMap<SinglePhaseProperty>,
10}
11
12/// Enumeration containing all supported single phase properties
13#[derive(EnumIter,EnumCount)]
14pub(crate) enum SinglePhaseProperty {
15	/// Viscosity, Pa*s
16	Viscosity,
17	/// Temperature derivative of Viscosity, Pa*s/K
18	ViscositydTemperature,
19	/// Pressure derivative of Viscosity, Pa*s/Pa
20	ViscositydPressure,
21	/// Mole fraction derivative of viscosity, Pa*s
22	ViscositydMoles,
23	/// Mole number derivative of viscosity, Pa*s/mol
24	ViscositydMolFraction,
25	/// Thermal conductivity, W/m/K
26	ThermalConductivity,
27	/// Temperature derivative of thermal conductivity, W/m/K^2
28	ThermalConductivitydTemperature,
29	/// Pressure derivative of thermal conductivity, W/m/K/Pa
30	ThermalConductivitydPressure,
31	/// Mole fraction derivative of thermal conductivity, W/m/K
32	ThermalConductivitydMoles,
33	/// Mole number derivative of thermal conductivity, W/m/mol
34	ThermalConductivitydMolFraction,
35	/// Enthalpy, J/mol
36	Enthalpy,
37	/// Temperature derivative of enthalpy, J/mol/K
38	EnthalpydTemperature,
39	/// Pressure derivative of enthalpy, J/mol/Pa
40	EnthalpydPressure,
41	/// Mole fraction derivative of enthalpy, J/mol
42	EnthalpydMoles,
43	/// Mole number derivative of enthalpy, J/mol
44	EnthalpydMolFraction,
45	/// Entropy, J/mol/K
46	Entropy,
47	/// Temperature derivative of entropy, J/mol/K^2
48	EntropydTemperature,
49	/// Pressure derivative of entropy, J/mol/K/Pa
50	EntropydPressure,
51	/// Mole fraction derivative of entropy, J/mol/K
52	EntropydMoles,
53	/// Mole number derivative of entropy, J/mol/K
54	EntropydMolFraction,
55	/// Density, mol/m^3
56	Density,
57	/// Temperature derivative of density, mol/m^3/K
58	DensitydTemperature,
59	/// Pressure derivative of density, mol/m^3/Pa
60	DensitydPressure,
61	/// Mole fraction derivative of density, mol/m^3
62	DensitydMoles,
63	/// Mole number derivative of density, mol/m^3/mol
64	DensitydMolFraction,
65	/// Volume, m^3/mol
66	Volume,
67	/// Temperature derivative of volume, m^3/mol/K
68	VolumedTemperature,
69	/// Pressure derivative of volume, m^3/mol/Pa
70	VolumedPressure,
71	/// Mole fraction of volume, m^3/mol
72	VolumedMoles,
73	/// Mole number derivative of volume, m^3/mol
74	VolumedMolFraction,
75}
76
77impl SinglePhaseProperty {
78
79	/// Returns the name of the property as a string.
80	/// 
81	/// # Returns
82	/// A string slice representing the name of the property.
83	pub(crate) fn name(&self) -> &str {
84		match self {
85			SinglePhaseProperty::Viscosity => "viscosity",
86			SinglePhaseProperty::ViscositydTemperature => "viscosity.Dtemperature",
87			SinglePhaseProperty::ViscositydPressure => "viscosity.Dpressure",
88			SinglePhaseProperty::ViscositydMoles => "viscosity.Dmoles",
89			SinglePhaseProperty::ViscositydMolFraction => "viscosity.Dmolfraction",
90			SinglePhaseProperty::ThermalConductivity => "thermalConductivity",
91			SinglePhaseProperty::ThermalConductivitydTemperature => "thermalConductivity.Dtemperature",
92			SinglePhaseProperty::ThermalConductivitydPressure => "thermalConductivity.Dpressure",
93			SinglePhaseProperty::ThermalConductivitydMoles => "thermalConductivity.Dmoles",
94			SinglePhaseProperty::ThermalConductivitydMolFraction => "thermalConductivity.Dmolfraction",
95			SinglePhaseProperty::Enthalpy => "enthalpy",
96			SinglePhaseProperty::EnthalpydTemperature => "enthalpy.Dtemperature",
97			SinglePhaseProperty::EnthalpydPressure => "enthalpy.Dpressure",
98			SinglePhaseProperty::EnthalpydMoles => "enthalpy.Dmoles",
99			SinglePhaseProperty::EnthalpydMolFraction => "enthalpy.Dmolfraction",
100			SinglePhaseProperty::Entropy=> "entropy",
101			SinglePhaseProperty::EntropydTemperature => "entropy.Dtemperature",
102			SinglePhaseProperty::EntropydPressure => "entropy.Dpressure",
103			SinglePhaseProperty::EntropydMoles => "entropy.Dmoles",
104			SinglePhaseProperty::EntropydMolFraction => "entropy.Dmolfraction",
105			SinglePhaseProperty::Density=> "density",
106			SinglePhaseProperty::DensitydTemperature => "density.Dtemperature",
107			SinglePhaseProperty::DensitydPressure => "density.Dpressure",
108			SinglePhaseProperty::DensitydMoles => "density.Dmoles",
109			SinglePhaseProperty::DensitydMolFraction => "density.Dmolfraction",
110			SinglePhaseProperty::Volume=> "volume",
111			SinglePhaseProperty::VolumedTemperature => "volume.Dtemperature",
112			SinglePhaseProperty::VolumedPressure => "volume.Dpressure",
113			SinglePhaseProperty::VolumedMoles => "volume.Dmoles",
114			SinglePhaseProperty::VolumedMolFraction => "volume.Dmolfraction",
115		}
116	}
117}
118
119impl PropertyTables {
120
121	/// Construction of the singleton instance of the property tables.
122	///
123	/// Builds the property table.
124	///
125	/// # Returns
126	/// A new instance of `PropertyTables`.
127	fn new() -> PropertyTables {
128
129		let mut single_phase_property_map = CapeOpenMap::new();
130		for prop in SinglePhaseProperty::iter() {
131			single_phase_property_map.insert(prop.name().into(),prop);
132		}
133		PropertyTables {
134			single_phase_property_map,
135		}
136	}
137
138	/// Single-phase property lookup by identifier.
139	///
140	/// # Arguments
141	/// * `prop_name` - Property name - can be any class that implements `CapeStringConstProvider`.
142	///
143	/// # Returns
144	/// * `Option<&SinglePhaseProperty>` - A reference to the property if found, otherwise `None`.
145	pub fn get_single_phase_property<'a,'b,S:CapeStringConstProvider>(&'a self,prop_name:&'b S) -> Option<&'a SinglePhaseProperty> where 'b:'a {
146		self.single_phase_property_map.get(prop_name)
147	}
148
149}
150
151/// Global shared instance of the property tables, constructed on first use.
152pub(crate) static PROPERTYTABLES: LazyLock<PropertyTables> = LazyLock::new(|
153|{PropertyTables::new()});