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.

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)$

Logarithm of the fugacity coefficient of all components treated as pure substance at mixture temperature and pressure.

Activity coefficient $\ln \gamma_i = \ln \varphi_i(T, p, \mathbf{N}) - \ln \varphi_i(T, p)$

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.

Chemical potential $\mu_i$ 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}$

Mass fractions: $w_i=\frac{m_i}{m}$

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.

Calculate the pure component critical point of all components.

Calculate the critical point of a system for given moles.

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.

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.

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.

  1. Create a state non-iteratively from the set of $T$, $V$, $\rho$, $\rho_i$, $N$, $N_i$ and $x_i$.
  2. Use a density iteration for a given pressure.
  3. 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.

Return a new State using a density iteration. DensityInitialization is used to influence the calculation with respect to the possible solutions.

Return a new State for given pressure $p$, volume $V$, temperature $T$ and composition $x_i$.

Return a new State for given pressure $p$ and molar enthalpy $h$.

Return a new State for given temperature $T$ and molar enthalpy $h$.

Return a new State for given temperature $T$ and molar entropy $s$.

Return a new State for given pressure $p$ and molar entropy $s$.

Return a new State for given volume $V$ and molar internal energy $u$.

Update the state with the given temperature

Update the state with the given chemical potential.

Update the state with the given molar Gibbs energy.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.