Skip to content

Commit

Permalink
chemical potential contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner committed Mar 4, 2024
1 parent 742606e commit 01a85d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions feos-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ 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)

### 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
Expand Down
10 changes: 7 additions & 3 deletions feos-core/src/python/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
32 changes: 20 additions & 12 deletions feos-core/src/state/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,30 @@ impl<E: Residual + IdealGas> State<E> {
}

/// 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
}

Expand Down

0 comments on commit 01a85d5

Please sign in to comment.