use super::traits::EquationOfState;
use crate::thermophysics::constants::R_UNIVERSAL;
use crate::thermophysics::imports::*;
#[derive(Debug, Clone, Copy)]
pub struct RhoConst {
mol_weight: MolarMass,
rho0: MassDensity,
}
impl RhoConst {
pub fn new(mol_weight: MolarMass, rho0: MassDensity) -> Self {
Self { mol_weight, rho0 }
}
}
impl EquationOfState for RhoConst {
fn mol_weight(&self) -> MolarMass {
self.mol_weight
}
fn r(&self) -> SpecificHeatCapacity {
let w = self.mol_weight.get::<kilogram_per_mole>();
SpecificHeatCapacity::new::<joule_per_kilogram_kelvin>(R_UNIVERSAL / w)
}
fn rho(&self, _p: Pressure, _t: ThermodynamicTemperature) -> MassDensity {
self.rho0
}
fn psi(&self, _p: Pressure, _t: ThermodynamicTemperature) -> Compressibility {
MassDensity::new::<kilogram_per_cubic_meter>(0.0) / Pressure::new::<pascal>(1.0)
}
fn z(&self, p: Pressure, t: ThermodynamicTemperature) -> Ratio {
p / (self.rho0 * self.r() * t)
}
fn cp_m_cv(&self, _p: Pressure, _t: ThermodynamicTemperature) -> SpecificHeatCapacity {
SpecificHeatCapacity::new::<joule_per_kilogram_kelvin>(0.0)
}
fn cp_eos(&self, _p: Pressure, _t: ThermodynamicTemperature) -> SpecificHeatCapacity {
SpecificHeatCapacity::new::<joule_per_kilogram_kelvin>(0.0)
}
fn h_eos(&self, _p: Pressure, _t: ThermodynamicTemperature) -> AvailableEnergy {
AvailableEnergy::new::<joule_per_kilogram>(0.0)
}
fn e_eos(&self, _p: Pressure, _t: ThermodynamicTemperature) -> AvailableEnergy {
AvailableEnergy::new::<joule_per_kilogram>(0.0)
}
fn s_eos(&self, _p: Pressure, _t: ThermodynamicTemperature) -> SpecificHeatCapacity {
SpecificHeatCapacity::new::<joule_per_kilogram_kelvin>(0.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
use approx::assert_relative_eq;
use uom::si::mass_density::kilogram_per_cubic_meter;
use uom::si::molar_mass::gram_per_mole;
use uom::si::pressure::pascal;
use uom::si::thermodynamic_temperature::kelvin;
fn water() -> RhoConst {
RhoConst::new(
MolarMass::new::<gram_per_mole>(18.015),
MassDensity::new::<kilogram_per_cubic_meter>(998.0),
)
}
#[test]
fn constant_density() {
let w = water();
let p1 = Pressure::new::<pascal>(101_325.0);
let p2 = Pressure::new::<pascal>(10e6);
let t = ThermodynamicTemperature::new::<kelvin>(300.0);
assert_relative_eq!(
w.rho(p1, t).get::<kilogram_per_cubic_meter>(),
w.rho(p2, t).get::<kilogram_per_cubic_meter>(),
epsilon = 1e-10
);
}
#[test]
fn zero_compressibility() {
let w = water();
let p = Pressure::new::<pascal>(101_325.0);
let t = ThermodynamicTemperature::new::<kelvin>(300.0);
let psi_times_p = (w.psi(p, t) * p).get::<kilogram_per_cubic_meter>();
assert_relative_eq!(psi_times_p, 0.0, epsilon = 1e-10);
}
}