Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
Add partial derivatives of pressure wrt density and isothermal compre…
Browse files Browse the repository at this point in the history
…ssibility (#21)
  • Loading branch information
g-bauer authored Jan 21, 2022
1 parent bd7d0e4 commit c179716
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/python/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,23 @@ macro_rules! impl_state {
PySINumber::from(self.0.dp_dv(contributions.0))
}

/// Return partial derivative of pressure w.r.t. density.
///
/// Parameters
/// ----------
/// contributions: Contributions, optional
/// the contributions of the helmholtz energy.
/// Defaults to Contributions.Total.
///
/// Returns
/// -------
/// SINumber
#[args(contributions = "PyContributions::Total()")]
#[pyo3(text_signature = "($self, contributions)")]
fn dp_drho(&self, contributions: PyContributions) -> PySINumber {
PySINumber::from(self.0.dp_drho(contributions.0))
}

/// Return partial derivative of pressure w.r.t. temperature.
///
/// Parameters
Expand Down Expand Up @@ -419,6 +436,23 @@ macro_rules! impl_state {
PySINumber::from(self.0.d2p_dv2(contributions.0))
}

/// Return second partial derivative of pressure w.r.t. density.
///
/// Parameters
/// ----------
/// contributions: Contributions, optional
/// the contributions of the helmholtz energy.
/// Defaults to Contributions.Total.
///
/// Returns
/// -------
/// SINumber
#[args(contributions = "PyContributions::Total()")]
#[pyo3(text_signature = "($self, contributions)")]
fn d2p_drho2(&self, contributions: PyContributions) -> PySINumber {
PySINumber::from(self.0.d2p_drho2(contributions.0))
}

/// Return molar volume of each component.
///
/// Parameters
Expand Down Expand Up @@ -866,6 +900,16 @@ macro_rules! impl_state {
PySINumber::from(self.0.isentropic_compressibility())
}

/// Return isothermal compressibility coefficient.
///
/// Returns
/// -------
/// SINumber
#[pyo3(text_signature = "($self)")]
fn isothermal_compressibility(&self) -> PySINumber {
PySINumber::from(self.0.isothermal_compressibility())
}

/// Return structure factor.
///
/// Returns
Expand Down
17 changes: 17 additions & 0 deletions src/state/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
self.evaluate_property(Self::dp_dv_, contributions, true)
}

/// Partial derivative of pressure w.r.t. density: $\left(\frac{\partial p}{\partial \rho}\right)_{T,N_i}$
pub fn dp_drho(&self, contributions: Contributions) -> QuantityScalar<U> {
-self.volume / self.density * self.dp_dv(contributions)
}

/// Partial derivative of pressure w.r.t. temperature: $\left(\frac{\partial p}{\partial T}\right)_{V,N_i}$
pub fn dp_dt(&self, contributions: Contributions) -> QuantityScalar<U> {
self.evaluate_property(Self::dp_dt_, contributions, true)
Expand All @@ -258,6 +263,12 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
self.evaluate_property(Self::d2p_dv2_, contributions, true)
}

/// Second partial derivative of pressure w.r.t. density: $\left(\frac{\partial^2 p}{\partial \rho^2}\right)_{T,N_j}$
pub fn d2p_drho2(&self, contributions: Contributions) -> QuantityScalar<U> {
self.volume / (self.density * self.density)
* (self.volume * self.d2p_dv2(contributions) + 2.0 * self.dp_dv(contributions))
}

/// Partial molar volume: $v_i=\left(\frac{\partial V}{\partial N_i}\right)_{T,p,N_j}$
pub fn molar_volume(&self, contributions: Contributions) -> QuantityArray1<U> {
let func = |s: &Self, evaluate: Evaluate| -s.dp_dni_(evaluate) / s.dp_dv_(evaluate);
Expand Down Expand Up @@ -444,6 +455,12 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
-self.c_v(c) / (self.c_p(c) * self.dp_dv(c) * self.volume)
}

/// Isothermal compressibility: $\kappa_T=-\frac{1}{V}\left(\frac{\partial V}{\partial p}\right)_{T,N_i}$
pub fn isothermal_compressibility(&self) -> QuantityScalar<U> {
let c = Contributions::Total;
-1.0 / (self.dp_dv(c) * self.volume)
}

/// Structure factor: $S(0)=k_BT\left(\frac{\partial\rho}{\partial p}\right)_{T,N_i}$
pub fn structure_factor(&self) -> f64 {
-(U::gas_constant() * self.temperature * self.density)
Expand Down

0 comments on commit c179716

Please sign in to comment.