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

Commit c179716

Browse files
authored
Add partial derivatives of pressure wrt density and isothermal compressibility (#21)
1 parent bd7d0e4 commit c179716

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/python/state.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,23 @@ macro_rules! impl_state {
368368
PySINumber::from(self.0.dp_dv(contributions.0))
369369
}
370370

371+
/// Return partial derivative of pressure w.r.t. density.
372+
///
373+
/// Parameters
374+
/// ----------
375+
/// contributions: Contributions, optional
376+
/// the contributions of the helmholtz energy.
377+
/// Defaults to Contributions.Total.
378+
///
379+
/// Returns
380+
/// -------
381+
/// SINumber
382+
#[args(contributions = "PyContributions::Total()")]
383+
#[pyo3(text_signature = "($self, contributions)")]
384+
fn dp_drho(&self, contributions: PyContributions) -> PySINumber {
385+
PySINumber::from(self.0.dp_drho(contributions.0))
386+
}
387+
371388
/// Return partial derivative of pressure w.r.t. temperature.
372389
///
373390
/// Parameters
@@ -419,6 +436,23 @@ macro_rules! impl_state {
419436
PySINumber::from(self.0.d2p_dv2(contributions.0))
420437
}
421438

439+
/// Return second partial derivative of pressure w.r.t. density.
440+
///
441+
/// Parameters
442+
/// ----------
443+
/// contributions: Contributions, optional
444+
/// the contributions of the helmholtz energy.
445+
/// Defaults to Contributions.Total.
446+
///
447+
/// Returns
448+
/// -------
449+
/// SINumber
450+
#[args(contributions = "PyContributions::Total()")]
451+
#[pyo3(text_signature = "($self, contributions)")]
452+
fn d2p_drho2(&self, contributions: PyContributions) -> PySINumber {
453+
PySINumber::from(self.0.d2p_drho2(contributions.0))
454+
}
455+
422456
/// Return molar volume of each component.
423457
///
424458
/// Parameters
@@ -866,6 +900,16 @@ macro_rules! impl_state {
866900
PySINumber::from(self.0.isentropic_compressibility())
867901
}
868902

903+
/// Return isothermal compressibility coefficient.
904+
///
905+
/// Returns
906+
/// -------
907+
/// SINumber
908+
#[pyo3(text_signature = "($self)")]
909+
fn isothermal_compressibility(&self) -> PySINumber {
910+
PySINumber::from(self.0.isothermal_compressibility())
911+
}
912+
869913
/// Return structure factor.
870914
///
871915
/// Returns

src/state/properties.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
243243
self.evaluate_property(Self::dp_dv_, contributions, true)
244244
}
245245

246+
/// Partial derivative of pressure w.r.t. density: $\left(\frac{\partial p}{\partial \rho}\right)_{T,N_i}$
247+
pub fn dp_drho(&self, contributions: Contributions) -> QuantityScalar<U> {
248+
-self.volume / self.density * self.dp_dv(contributions)
249+
}
250+
246251
/// Partial derivative of pressure w.r.t. temperature: $\left(\frac{\partial p}{\partial T}\right)_{V,N_i}$
247252
pub fn dp_dt(&self, contributions: Contributions) -> QuantityScalar<U> {
248253
self.evaluate_property(Self::dp_dt_, contributions, true)
@@ -258,6 +263,12 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
258263
self.evaluate_property(Self::d2p_dv2_, contributions, true)
259264
}
260265

266+
/// Second partial derivative of pressure w.r.t. density: $\left(\frac{\partial^2 p}{\partial \rho^2}\right)_{T,N_j}$
267+
pub fn d2p_drho2(&self, contributions: Contributions) -> QuantityScalar<U> {
268+
self.volume / (self.density * self.density)
269+
* (self.volume * self.d2p_dv2(contributions) + 2.0 * self.dp_dv(contributions))
270+
}
271+
261272
/// Partial molar volume: $v_i=\left(\frac{\partial V}{\partial N_i}\right)_{T,p,N_j}$
262273
pub fn molar_volume(&self, contributions: Contributions) -> QuantityArray1<U> {
263274
let func = |s: &Self, evaluate: Evaluate| -s.dp_dni_(evaluate) / s.dp_dv_(evaluate);
@@ -444,6 +455,12 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
444455
-self.c_v(c) / (self.c_p(c) * self.dp_dv(c) * self.volume)
445456
}
446457

458+
/// Isothermal compressibility: $\kappa_T=-\frac{1}{V}\left(\frac{\partial V}{\partial p}\right)_{T,N_i}$
459+
pub fn isothermal_compressibility(&self) -> QuantityScalar<U> {
460+
let c = Contributions::Total;
461+
-1.0 / (self.dp_dv(c) * self.volume)
462+
}
463+
447464
/// Structure factor: $S(0)=k_BT\left(\frac{\partial\rho}{\partial p}\right)_{T,N_i}$
448465
pub fn structure_factor(&self) -> f64 {
449466
-(U::gas_constant() * self.temperature * self.density)

0 commit comments

Comments
 (0)