Skip to main content

feos_core/ad/properties/
liquid_density.rs

1use super::PropertyAD;
2use crate::DensityInitialization::Liquid;
3use crate::density_iteration::density_iteration;
4use crate::{FeosResult, Residual};
5use nalgebra::allocator::Allocator;
6use nalgebra::{DefaultAllocator, Dim};
7use num_dual::{DualNum, DualStruct};
8use quantity::{_Density, Density, KELVIN, PASCAL, Pressure, Temperature};
9
10/// Liquid density of a pure component as function of temperature and pressure.
11pub struct LiquidDensity(pub Temperature, pub Pressure);
12
13impl<'a> From<&'a [f64]> for LiquidDensity {
14    fn from(value: &'a [f64]) -> Self {
15        Self(value[0] * KELVIN, value[1] * PASCAL)
16    }
17}
18
19impl<N: Dim> PropertyAD<N> for LiquidDensity
20where
21    DefaultAllocator: Allocator<N>,
22{
23    type Unit = _Density;
24    const REFERENCE: Density = Density::new(1000.0);
25
26    fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
27        &self,
28        eos: &E,
29    ) -> FeosResult<Density<D>> {
30        let x = E::pure_molefracs();
31        let t = Temperature::from_inner(&self.0);
32        let p = Pressure::from_inner(&self.1);
33        density_iteration(eos, t, p, &x, Some(Liquid))
34    }
35}