use twine_core::constraint::{Constrained, ConstraintError, StrictlyPositive};
use uom::si::f64::{MassRate, Power};
use crate::{
PropertyError, State,
capability::{HasEnthalpy, ThermoModel},
};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Stream<Fluid> {
pub rate: Constrained<MassRate, StrictlyPositive>,
pub state: State<Fluid>,
}
impl<Fluid> Stream<Fluid> {
pub fn new(rate: MassRate, state: State<Fluid>) -> Result<Self, ConstraintError> {
let rate = Constrained::new(rate)?;
Ok(Self::from_constrained(rate, state))
}
pub fn from_constrained(
rate: Constrained<MassRate, StrictlyPositive>,
state: State<Fluid>,
) -> Self {
Self { rate, state }
}
pub fn enthalpy_flow<Model>(&self, model: &Model) -> Result<Power, PropertyError>
where
Model: ThermoModel<Fluid = Fluid> + HasEnthalpy,
{
let m_dot = self.rate.into_inner();
let h = model.enthalpy(&self.state)?;
Ok(m_dot * h)
}
}