Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chemical potential contributions #228

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading