pub struct State<U, E> {
pub eos: Rc<E>,
pub temperature: QuantityScalar<U>,
pub volume: QuantityScalar<U>,
pub moles: QuantityArray1<U>,
pub total_moles: QuantityScalar<U>,
pub partial_density: QuantityArray1<U>,
pub density: QuantityScalar<U>,
pub molefracs: Array1<f64>,
/* private fields */
}
Expand description
Thermodynamic state of the system.
The state is always specified by the variables of the Helmholtz energy: volume $V$, temperature $T$ and mole numbers $N_i$. Additional to these variables, the state saves properties like the density, that can be calculated directly from the basic variables. The state also contains a reference to the equation of state used to create the state. Therefore, it can be used directly to calculate all state properties.
Calculated partial derivatives are cached in the state. Therefore, the second evaluation of a property like the pressure, does not require a recalculation of the equation of state. This can be used in situations where both lower and higher order derivatives are required, as in a calculation of a derivative all lower derivatives have to be calculated internally as well. Since they are cached it is more efficient to calculate the highest derivatives first. For example during the calculation of the isochoric heat capacity $c_v$, the entropy and the Helmholtz energy are calculated as well.
State
objects are meant to be immutable. If individual fields like volume
are changed, the
calculations are wrong as the internal fields of the state are not updated.
Contents
Fields
eos: Rc<E>
Equation of state
temperature: QuantityScalar<U>
Temperature $T$
volume: QuantityScalar<U>
Volume $V$
moles: QuantityArray1<U>
Mole numbers $N_i$
total_moles: QuantityScalar<U>
Total number of moles $N=\sum_iN_i$
partial_density: QuantityArray1<U>
Partial densities $\rho_i=\frac{N_i}{V}$
density: QuantityScalar<U>
Total density $\rho=\frac{N}{V}=\sum_i\rho_i$
molefracs: Array1<f64>
Mole fractions $x_i=\frac{N_i}{N}=\frac{\rho_i}{\rho}$
Implementations
Determine if the state is stable, i.e. if a phase split should occur or not.
Perform a stability analysis. The result is a list of States with negative tangent plane distance (i.e. lower Gibbs energy) that can be used as initial estimates for a phase equilibrium calculation.
pub fn tp_flash(
&self,
init_vle_state: Option<&PhaseEquilibrium<U, E, 2>>,
options: VLEOptions,
non_volatile_components: Option<Vec<usize>>
) -> EosResult<PhaseEquilibrium<U, E, 2>>
pub fn tp_flash(
&self,
init_vle_state: Option<&PhaseEquilibrium<U, E, 2>>,
options: VLEOptions,
non_volatile_components: Option<Vec<usize>>
) -> EosResult<PhaseEquilibrium<U, E, 2>>
Perform a Tp-flash calculation using the State as feed. If no initial values are given, the solution is initialized using a stability analysis.
The algorithm can be use to calculate phase equilibria of systems containing non-volatile components (e.g. ions).
Pressure: $p=-\left(\frac{\partial A}{\partial V}\right)_{T,N_i}$
Compressibility factor: $Z=\frac{pV}{NRT}$
Partial derivative of pressure w.r.t. volume: $\left(\frac{\partial p}{\partial V}\right)_{T,N_i}$
Partial derivative of pressure w.r.t. density: $\left(\frac{\partial p}{\partial \rho}\right)_{T,N_i}$
Partial derivative of pressure w.r.t. temperature: $\left(\frac{\partial p}{\partial T}\right)_{V,N_i}$
Partial derivative of pressure w.r.t. moles: $\left(\frac{\partial p}{\partial N_i}\right)_{T,V,N_j}$
Second partial derivative of pressure w.r.t. volume: $\left(\frac{\partial^2 p}{\partial V^2}\right)_{T,N_j}$
Second partial derivative of pressure w.r.t. density: $\left(\frac{\partial^2 p}{\partial \rho^2}\right)_{T,N_j}$
Partial molar volume: $v_i=\left(\frac{\partial V}{\partial N_i}\right)_{T,p,N_j}$
Chemical potential: $\mu_i=\left(\frac{\partial A}{\partial N_i}\right)_{T,V,N_j}$
Partial derivative of chemical potential w.r.t. temperature: $\left(\frac{\partial\mu_i}{\partial T}\right)_{V,N_i}$
Partial derivative of chemical potential w.r.t. moles: $\left(\frac{\partial\mu_i}{\partial \mu_j}\right)_{T,V,N_k}$
Logarithm of the fugacity coefficient: $\ln\varphi_i=\beta\mu_i^\mathrm{res}\left(T,p,\lbrace N_i\rbrace\right)$
Partial derivative of the logarithm of the fugacity coefficient w.r.t. temperature: $\left(\frac{\partial\ln\varphi_i}{\partial T}\right)_{p,N_i}$
Partial derivative of the logarithm of the fugacity coefficient w.r.t. pressure: $\left(\frac{\partial\ln\varphi_i}{\partial p}\right)_{T,N_i}$
Partial derivative of the logarithm of the fugacity coefficient w.r.t. moles: $\left(\frac{\partial\ln\varphi_i}{\partial N_j}\right)_{T,p,N_k}$
Thermodynamic factor: $\Gamma_{ij}=\delta_{ij}+x_i\left(\frac{\partial\ln\varphi_i}{\partial x_j}\right)_{T,p,\Sigma}$
Molar isochoric heat capacity: $c_v=\left(\frac{\partial u}{\partial T}\right)_{V,N_i}$
Partial derivative of the molar isochoric heat capacity w.r.t. temperature: $\left(\frac{\partial c_V}{\partial T}\right)_{V,N_i}$
Molar isobaric heat capacity: $c_p=\left(\frac{\partial h}{\partial T}\right)_{p,N_i}$
Entropy: $S=-\left(\frac{\partial A}{\partial T}\right)_{V,N_i}$
Partial derivative of the entropy w.r.t. temperature: $\left(\frac{\partial S}{\partial T}\right)_{V,N_i}$
molar entropy: $s=\frac{S}{N}$
Enthalpy: $H=A+TS+pV$
molar enthalpy: $h=\frac{H}{N}$
Helmholtz energy: $A$
molar Helmholtz energy: $a=\frac{A}{N}$
Internal energy: $U=A+TS$
Molar internal energy: $u=\frac{U}{N}$
Gibbs energy: $G=A+pV$
Molar Gibbs energy: $g=\frac{G}{N}$
Partial molar entropy: $s_i=\left(\frac{\partial S}{\partial N_i}\right)_{T,p,N_j}$
Partial molar enthalpy: $h_i=\left(\frac{\partial H}{\partial N_i}\right)_{T,p,N_j}$
Joule Thomson coefficient: $\mu_{JT}=\left(\frac{\partial T}{\partial p}\right)_{H,N_i}$
Isentropic compressibility: $\kappa_s=-\frac{1}{V}\left(\frac{\partial V}{\partial p}\right)_{S,N_i}$
Isothermal compressibility: $\kappa_T=-\frac{1}{V}\left(\frac{\partial V}{\partial p}\right)_{T,N_i}$
Structure factor: $S(0)=k_BT\left(\frac{\partial\rho}{\partial p}\right)_{T,N_i}$
Helmholtz energy $A$ evaluated for each contribution of the equation of state.
Pressure $p$ evaluated for each contribution of the equation of state.
Mass specific state properties
These properties are available for equations of state that implement the MolarWeight trait.
Total molar weight: $MW=\sum_ix_iMW_i$
Mass of each component: $m_i=n_iMW_i$
Total mass: $m=\sum_im_i=nMW$
Mass density: $\rho^{(m)}=\frac{m}{V}$
Specific entropy: $s^{(m)}=\frac{S}{m}$
Specific enthalpy: $h^{(m)}=\frac{H}{m}$
Specific Helmholtz energy: $a^{(m)}=\frac{A}{m}$
Specific internal energy: $u^{(m)}=\frac{U}{m}$
Specific Gibbs energy: $g^{(m)}=\frac{G}{m}$
Speed of sound: $c=\sqrt{\left(\frac{\partial p}{\partial\rho}\right)_{S,N_i}}$
Transport properties
These properties are available for equations of state that implement the EntropyScaling trait.
Return the viscosity via entropy scaling.
Return the logarithm of the reduced viscosity.
This term equals the viscosity correlation function that is used for entropy scaling.
Return the viscosity reference as used in entropy scaling.
Return the diffusion via entropy scaling.
Return the logarithm of the reduced diffusion.
This term equals the diffusion correlation function that is used for entropy scaling.
Return the diffusion reference as used in entropy scaling.
Return the thermal conductivity via entropy scaling.
Return the logarithm of the reduced thermal conductivity.
This term equals the thermal conductivity correlation function that is used for entropy scaling.
Return the thermal conductivity reference as used in entropy scaling.
pub fn critical_point_pure(
eos: &Rc<E>,
initial_temperature: Option<QuantityScalar<U>>,
options: VLEOptions
) -> EosResult<Vec<Self>> where
QuantityScalar<U>: Display,
pub fn critical_point_pure(
eos: &Rc<E>,
initial_temperature: Option<QuantityScalar<U>>,
options: VLEOptions
) -> EosResult<Vec<Self>> where
QuantityScalar<U>: Display,
Calculate the pure component critical point of all components.
pub fn critical_point_binary_t(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
options: VLEOptions
) -> EosResult<Self> where
QuantityScalar<U>: Display,
pub fn critical_point_binary_t(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
options: VLEOptions
) -> EosResult<Self> where
QuantityScalar<U>: Display,
Calculate the critical point of a binary system for given temperature.
pub fn critical_point_binary_p(
eos: &Rc<E>,
pressure: QuantityScalar<U>,
options: VLEOptions
) -> EosResult<Self> where
QuantityScalar<U>: Display,
pub fn critical_point_binary_p(
eos: &Rc<E>,
pressure: QuantityScalar<U>,
options: VLEOptions
) -> EosResult<Self> where
QuantityScalar<U>: Display,
Calculate the critical point of a binary system for given pressure.
pub fn critical_point(
eos: &Rc<E>,
moles: Option<&QuantityArray1<U>>,
initial_temperature: Option<QuantityScalar<U>>,
options: VLEOptions
) -> EosResult<Self> where
QuantityScalar<U>: Display,
pub fn critical_point(
eos: &Rc<E>,
moles: Option<&QuantityArray1<U>>,
initial_temperature: Option<QuantityScalar<U>>,
options: VLEOptions
) -> EosResult<Self> where
QuantityScalar<U>: Display,
Calculate the critical point of a system for given moles.
pub fn new_nvt(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
volume: QuantityScalar<U>,
moles: &QuantityArray1<U>
) -> EosResult<Self>
pub fn new_nvt(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
volume: QuantityScalar<U>,
moles: &QuantityArray1<U>
) -> EosResult<Self>
Return a new State
given a temperature, an array of mole numbers and a volume.
This function will perform a validation of the given properties, i.e. test for signs and if values are finite. It will not validate physics, i.e. if the resulting densities are below the maximum packing fraction.
pub fn new_pure(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
density: QuantityScalar<U>
) -> EosResult<Self>
pub fn new_pure(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
density: QuantityScalar<U>
) -> EosResult<Self>
Return a new State
for a pure component given a temperature and a density. The moles
are set to the reference value for each component.
This function will perform a validation of the given properties, i.e. test for signs and if values are finite. It will not validate physics, i.e. if the resulting densities are below the maximum packing fraction.
pub fn new(
eos: &Rc<E>,
temperature: Option<QuantityScalar<U>>,
volume: Option<QuantityScalar<U>>,
density: Option<QuantityScalar<U>>,
partial_density: Option<&QuantityArray1<U>>,
total_moles: Option<QuantityScalar<U>>,
moles: Option<&QuantityArray1<U>>,
molefracs: Option<&Array1<f64>>,
pressure: Option<QuantityScalar<U>>,
molar_enthalpy: Option<QuantityScalar<U>>,
molar_entropy: Option<QuantityScalar<U>>,
molar_internal_energy: Option<QuantityScalar<U>>,
density_initialization: DensityInitialization<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
pub fn new(
eos: &Rc<E>,
temperature: Option<QuantityScalar<U>>,
volume: Option<QuantityScalar<U>>,
density: Option<QuantityScalar<U>>,
partial_density: Option<&QuantityArray1<U>>,
total_moles: Option<QuantityScalar<U>>,
moles: Option<&QuantityArray1<U>>,
molefracs: Option<&Array1<f64>>,
pressure: Option<QuantityScalar<U>>,
molar_enthalpy: Option<QuantityScalar<U>>,
molar_entropy: Option<QuantityScalar<U>>,
molar_internal_energy: Option<QuantityScalar<U>>,
density_initialization: DensityInitialization<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
Return a new State
for the combination of inputs.
The function attempts to create a new state using the given input values. If the state is overdetermined, it will choose a method based on the following hierarchy.
- Create a state non-iteratively from the set of $T$, $V$, $\rho$, $\rho_i$, $N$, $N_i$ and $x_i$.
- Use a density iteration for a given pressure.
- Determine the state using a Newton iteration from (in this order): $(p, h)$, $(p, s)$, $(T, h)$, $(T, s)$, $(V, u)$
The StateBuilder provides a convenient way of calling this function without the need to provide all the optional input values.
Errors
When the state cannot be created using the combination of inputs.
pub fn new_npt(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
pressure: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>
) -> EosResult<Self>
pub fn new_npt(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
pressure: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>
) -> EosResult<Self>
Return a new State
using a density iteration. DensityInitialization is used to
influence the calculation with respect to the possible solutions.
pub fn new_nph(
eos: &Rc<E>,
pressure: QuantityScalar<U>,
molar_enthalpy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
pub fn new_nph(
eos: &Rc<E>,
pressure: QuantityScalar<U>,
molar_enthalpy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
Return a new State
for given pressure $p$ and molar enthalpy $h$.
pub fn new_nth(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
molar_enthalpy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>
) -> EosResult<Self>
pub fn new_nth(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
molar_enthalpy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>
) -> EosResult<Self>
Return a new State
for given temperature $T$ and molar enthalpy $h$.
pub fn new_nts(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
molar_entropy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>
) -> EosResult<Self>
pub fn new_nts(
eos: &Rc<E>,
temperature: QuantityScalar<U>,
molar_entropy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>
) -> EosResult<Self>
Return a new State
for given temperature $T$ and molar entropy $s$.
pub fn new_nps(
eos: &Rc<E>,
pressure: QuantityScalar<U>,
molar_entropy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
pub fn new_nps(
eos: &Rc<E>,
pressure: QuantityScalar<U>,
molar_entropy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
density_initialization: DensityInitialization<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
Return a new State
for given pressure $p$ and molar entropy $s$.
pub fn new_nvu(
eos: &Rc<E>,
volume: QuantityScalar<U>,
molar_internal_energy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
pub fn new_nvu(
eos: &Rc<E>,
volume: QuantityScalar<U>,
molar_internal_energy: QuantityScalar<U>,
moles: &QuantityArray1<U>,
initial_temperature: Option<QuantityScalar<U>>
) -> EosResult<Self>
Return a new State
for given volume $V$ and molar internal energy $u$.
Update the state with the given temperature
pub fn update_chemical_potential(
&mut self,
chemical_potential: &QuantityArray1<U>
) -> EosResult<()>
pub fn update_chemical_potential(
&mut self,
chemical_potential: &QuantityArray1<U>
) -> EosResult<()>
Update the state with the given chemical potential.
Update the state with the given molar Gibbs energy.
Trait Implementations
impl<U, E> Display for State<U, E> where
QuantityScalar<U>: Display,
QuantityArray1<U>: Display,
E: EquationOfState,
impl<U, E> Display for State<U, E> where
QuantityScalar<U>: Display,
QuantityArray1<U>: Display,
E: EquationOfState,
Auto Trait Implementations
impl<U, E> !RefUnwindSafe for State<U, E>
impl<U, E> UnwindSafe for State<U, E> where
E: RefUnwindSafe,
U: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more