diff --git a/feos-core/CHANGELOG.md b/feos-core/CHANGELOG.md index c5bb22e25..94a8184c3 100644 --- a/feos-core/CHANGELOG.md +++ b/feos-core/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed the interface for Helmholtz energy calculation in `Residual` and `IdealGas` which removes the need for the `HelmholtzEnergy` and `HelmholtzEnergyDual` traits and trait objects. [#226](https://github.com/feos-org/feos/pull/226) - Adjusted Python macros to account for the removal of trait objects. [#226](https://github.com/feos-org/feos/pull/226) - Changed deprecated `remove` method of `IndexMap` to `shift_remove`. [#226](https://github.com/feos-org/feos/pull/226) +- Added `contributions` argument to `State::chemical_potential_contributions` and fixed the corresponding Python function. [#228](https://github.com/feos-org/feos/pull/228) ### Removed - Removed `HelmholtzEnergyDual`, `HelmholzEnergy`, `DeBroglieWavelengthDual` and `DeBroglieWavelength` traits. [#226](https://github.com/feos-org/feos/pull/226) @@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Added comparison for pressures of both phases in `PyPhaseDiagram.to_dict` to make the method work with `spinodal` constructor. [#224](https://github.com/feos-org/feos/pull/224) - Enforce the total moles when providing `State::new` with molefracs that do not add up to 1. [#227](https://github.com/feos-org/feos/pull/227) +- ## [0.6.1] 2024-01-11 diff --git a/feos-core/src/python/state.rs b/feos-core/src/python/state.rs index 2fd9cbb82..85ef9eb5a 100644 --- a/feos-core/src/python/state.rs +++ b/feos-core/src/python/state.rs @@ -496,20 +496,24 @@ macro_rules! impl_state { PySIArray1::from(self.0.chemical_potential(contributions)) } - /// Return residual chemical potential contributions. + /// Return chemical potential contributions. /// /// Parameters /// ---------- /// component: int /// the component for which the contributions /// are calculated + /// contributions: Contributions, optional + /// the contributions of the Helmholtz energy. + /// Defaults to Contributions.Total. /// /// Returns /// ------- /// List[Tuple[str, SINumber]] - fn residual_chemical_potential_contributions(&self, component: usize) -> Vec<(String, PySINumber)> { + #[pyo3(signature = (component, contributions=Contributions::Total), text_signature = "($self, component, contributions)")] + fn chemical_potential_contributions(&self, component: usize, contributions: Contributions) -> Vec<(String, PySINumber)> { self.0 - .chemical_potential_contributions(component) + .chemical_potential_contributions(component, contributions) .into_iter() .map(|(s, q)| (s, PySINumber::from(q))) .collect() diff --git a/feos-core/src/state/properties.rs b/feos-core/src/state/properties.rs index 7973bbcbd..14bb9d617 100644 --- a/feos-core/src/state/properties.rs +++ b/feos-core/src/state/properties.rs @@ -252,22 +252,30 @@ impl State { } /// Chemical potential $\mu_i$ evaluated for each contribution of the equation of state. - pub fn chemical_potential_contributions(&self, component: usize) -> Vec<(String, MolarEnergy)> { + pub fn chemical_potential_contributions( + &self, + component: usize, + contributions: Contributions, + ) -> Vec<(String, MolarEnergy)> { let new_state = self.derive1(DN(component)); - let contributions = self.eos.residual_helmholtz_energy_contributions(&new_state); - let mut res = Vec::with_capacity(contributions.len() + 1); - res.push(( - self.eos.ideal_gas_model(), - MolarEnergy::from_reduced( - (self.eos.ideal_gas_helmholtz_energy(&new_state) * new_state.temperature).eps, - ), - )); - for (s, v) in contributions { + let mut res = Vec::new(); + if let Contributions::IdealGas | Contributions::Total = contributions { res.push(( - s, - MolarEnergy::from_reduced((v * new_state.temperature).eps), + self.eos.ideal_gas_model(), + MolarEnergy::from_reduced( + (self.eos.ideal_gas_helmholtz_energy(&new_state) * new_state.temperature).eps, + ), )); } + if let Contributions::Residual | Contributions::Total = contributions { + let contributions = self.eos.residual_helmholtz_energy_contributions(&new_state); + for (s, v) in contributions { + res.push(( + s, + MolarEnergy::from_reduced((v * new_state.temperature).eps), + )); + } + } res }