Skip to content

Commit

Permalink
Revised handling of ideal gas contribution (#158)
Browse files Browse the repository at this point in the history
Co-authored-by: Gernot Bauer <bauer@itt.uni-stuttgart.de>
  • Loading branch information
prehner and g-bauer authored Jul 7, 2023
1 parent 263dd91 commit d48b09a
Show file tree
Hide file tree
Showing 101 changed files with 4,100 additions and 3,279 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added `IdealGasModel` enum that collects all implementors of the `IdealGas` trait. [#158](https://github.com/feos-org/feos/pull/158)
- Added `feos.ideal_gas` module in Python from which (currently) `Joback` and `JobackParameters` are available. [#158](https://github.com/feos-org/feos/pull/158)

### Changed
- Changed the internal implementation of the association contribution to accomodate more general association schemes. [#150](https://github.com/feos-org/feos/pull/150)
- To comply with the new association implementation, the default values of `na` and `nb` are now `0` rather than `1`. Parameter files have been adapted accordingly. [#150](https://github.com/feos-org/feos/pull/150)
- Added the possibility to specify a pure component correction parameter `phi` for the heterosegmented gc PC-SAFT equation of state. [#157](https://github.com/feos-org/feos/pull/157)
- Renamed `EosVariant` to `ResidualModel`. [#158](https://github.com/feos-org/feos/pull/158)
- Added methods to add an ideal gas contribution to an initialized equation of state object in Python. [#158](https://github.com/feos-org/feos/pull/158)

### Packaging
- Updated `num-dual` dependency to 0.7. [#137](https://github.com/feos-org/feos/pull/137)
Expand Down
2 changes: 1 addition & 1 deletion benches/contributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use feos_core::parameter::{IdentifierOption, Parameter};
use feos_core::{DensityInitialization, Derivative, EquationOfState, State};
use feos_core::{DensityInitialization, Derivative, Residual, State};
use ndarray::arr1;
use quantity::si::*;
use std::sync::Arc;
Expand Down
6 changes: 3 additions & 3 deletions benches/dual_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use feos_core::{
parameter::{IdentifierOption, Parameter},
Derivative, EquationOfState, HelmholtzEnergy, HelmholtzEnergyDual, State, StateHD,
Derivative, HelmholtzEnergy, HelmholtzEnergyDual, Residual, State, StateHD,
};
use ndarray::{arr1, Array};
use num_dual::DualNum;
Expand All @@ -28,15 +28,15 @@ fn state_pcsaft(parameters: PcSaftParameters) -> State<PcSaft> {
}

/// Residual Helmholtz energy given an equation of state and a StateHD.
fn a_res<D: DualNum<f64> + Copy, E: EquationOfState>(inp: (&Arc<E>, &StateHD<D>)) -> D
fn a_res<D: DualNum<f64> + Copy, E: Residual>(inp: (&Arc<E>, &StateHD<D>)) -> D
where
(dyn HelmholtzEnergy + 'static): HelmholtzEnergyDual<D>,
{
inp.0.evaluate_residual(inp.1)
}

/// Benchmark for evaluation of the Helmholtz energy for different dual number types.
fn bench_dual_numbers<E: EquationOfState>(c: &mut Criterion, group_name: &str, state: State<E>) {
fn bench_dual_numbers<E: Residual>(c: &mut Criterion, group_name: &str, state: State<E>) {
let mut group = c.benchmark_group(group_name);
group.bench_function("a_f64", |b| {
b.iter(|| a_res((&state.eos, &state.derive0())))
Expand Down
18 changes: 9 additions & 9 deletions benches/state_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use feos_core::{
parameter::{IdentifierOption, Parameter},
Contributions, DensityInitialization, EquationOfState, PhaseEquilibrium, State,
Contributions, DensityInitialization, PhaseEquilibrium, Residual, State,
};
use ndarray::{Array, Array1};
use quantity::si::*;
use std::sync::Arc;

/// Evaluate NPT constructor
fn npt<E: EquationOfState>(
fn npt<E: Residual>(
(eos, t, p, n, rho0): (
&Arc<E>,
SINumber,
Expand All @@ -22,26 +22,26 @@ fn npt<E: EquationOfState>(
}

/// Evaluate critical point constructor
fn critical_point<E: EquationOfState>((eos, n): (&Arc<E>, Option<&SIArray1>)) {
fn critical_point<E: Residual>((eos, n): (&Arc<E>, Option<&SIArray1>)) {
State::critical_point(eos, n, None, Default::default()).unwrap();
}

/// Evaluate critical point constructor for binary systems at given T or p
fn critical_point_binary<E: EquationOfState>((eos, tp): (&Arc<E>, SINumber)) {
fn critical_point_binary<E: Residual>((eos, tp): (&Arc<E>, SINumber)) {
State::critical_point_binary(eos, tp, None, None, Default::default()).unwrap();
}

/// VLE for pure substance for given temperature or pressure
fn pure<E: EquationOfState>((eos, t_or_p): (&Arc<E>, SINumber)) {
fn pure<E: Residual>((eos, t_or_p): (&Arc<E>, SINumber)) {
PhaseEquilibrium::pure(eos, t_or_p, None, Default::default()).unwrap();
}

/// Evaluate temperature, pressure flash.
fn tp_flash<E: EquationOfState>((eos, t, p, feed): (&Arc<E>, SINumber, SINumber, &SIArray1)) {
fn tp_flash<E: Residual>((eos, t, p, feed): (&Arc<E>, SINumber, SINumber, &SIArray1)) {
PhaseEquilibrium::tp_flash(eos, t, p, feed, None, Default::default(), None).unwrap();
}

fn bubble_point<E: EquationOfState>((eos, t, x): (&Arc<E>, SINumber, &Array1<f64>)) {
fn bubble_point<E: Residual>((eos, t, x): (&Arc<E>, SINumber, &Array1<f64>)) {
PhaseEquilibrium::bubble_point(
eos,
t,
Expand All @@ -53,7 +53,7 @@ fn bubble_point<E: EquationOfState>((eos, t, x): (&Arc<E>, SINumber, &Array1<f64
.unwrap();
}

fn dew_point<E: EquationOfState>((eos, t, y): (&Arc<E>, SINumber, &Array1<f64>)) {
fn dew_point<E: Residual>((eos, t, y): (&Arc<E>, SINumber, &Array1<f64>)) {
PhaseEquilibrium::dew_point(
eos,
t,
Expand All @@ -65,7 +65,7 @@ fn dew_point<E: EquationOfState>((eos, t, y): (&Arc<E>, SINumber, &Array1<f64>))
.unwrap();
}

fn bench_states<E: EquationOfState>(c: &mut Criterion, group_name: &str, eos: &Arc<E>) {
fn bench_states<E: Residual>(c: &mut Criterion, group_name: &str, eos: &Arc<E>) {
let ncomponents = eos.components();
let x = Array::from_elem(ncomponents, 1.0 / ncomponents as f64);
let n = &x * 100.0 * MOL;
Expand Down
36 changes: 9 additions & 27 deletions benches/state_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use feos_core::{
parameter::{IdentifierOption, Parameter},
Contributions, EquationOfState, State,
Contributions, Residual, State,
};
use ndarray::arr1;
use quantity::si::*;
Expand All @@ -12,7 +12,7 @@ type S = State<PcSaft>;

/// Evaluate a property of a state given the EoS, the property to compute,
/// temperature, volume, moles, and the contributions to consider.
fn property<E: EquationOfState, T, F: Fn(&State<E>, Contributions) -> T>(
fn property<E: Residual, T, F: Fn(&State<E>, Contributions) -> T>(
(eos, property, t, v, n, contributions): (
&Arc<E>,
F,
Expand All @@ -28,7 +28,7 @@ fn property<E: EquationOfState, T, F: Fn(&State<E>, Contributions) -> T>(

/// Evaluate a property with of a state given the EoS, the property to compute,
/// temperature, volume, moles.
fn property_no_contributions<E: EquationOfState, T, F: Fn(&State<E>) -> T>(
fn property_no_contributions<E: Residual, T, F: Fn(&State<E>) -> T>(
(eos, property, t, v, n): (&Arc<E>, F, SINumber, SINumber, &SIArray1),
) -> T {
let state = State::new_nvt(eos, t, v, n).unwrap();
Expand All @@ -52,7 +52,7 @@ fn properties_pcsaft(c: &mut Criterion) {

let mut group = c.benchmark_group("state_properties_pcsaft_methane_ethane_propane");
group.bench_function("a", |b| {
b.iter(|| property((&eos, S::helmholtz_energy, t, v, &m, Contributions::Total)))
b.iter(|| property_no_contributions((&eos, S::residual_helmholtz_energy, t, v, &m)))
});
group.bench_function("compressibility", |b| {
b.iter(|| property((&eos, S::compressibility, t, v, &m, Contributions::Total)))
Expand All @@ -61,19 +61,10 @@ fn properties_pcsaft(c: &mut Criterion) {
b.iter(|| property_no_contributions((&eos, S::ln_phi, t, v, &m)))
});
group.bench_function("c_v", |b| {
b.iter(|| property((&eos, S::c_v, t, v, &m, Contributions::ResidualNvt)))
b.iter(|| property_no_contributions((&eos, S::c_v_res, t, v, &m)))
});
group.bench_function("partial_molar_volume", |b| {
b.iter(|| {
property((
&eos,
S::partial_molar_volume,
t,
v,
&m,
Contributions::ResidualNvt,
))
})
b.iter(|| property_no_contributions((&eos, S::partial_molar_volume, t, v, &m)))
});
}

Expand All @@ -94,7 +85,7 @@ fn properties_pcsaft_polar(c: &mut Criterion) {

let mut group = c.benchmark_group("state_properties_pcsaft_polar");
group.bench_function("a", |b| {
b.iter(|| property((&eos, S::helmholtz_energy, t, v, &m, Contributions::Total)))
b.iter(|| property_no_contributions((&eos, S::residual_helmholtz_energy, t, v, &m)))
});
group.bench_function("compressibility", |b| {
b.iter(|| property((&eos, S::compressibility, t, v, &m, Contributions::Total)))
Expand All @@ -103,19 +94,10 @@ fn properties_pcsaft_polar(c: &mut Criterion) {
b.iter(|| property_no_contributions((&eos, S::ln_phi, t, v, &m)))
});
group.bench_function("c_v", |b| {
b.iter(|| property((&eos, S::c_v, t, v, &m, Contributions::ResidualNvt)))
b.iter(|| property_no_contributions((&eos, S::c_v_res, t, v, &m)))
});
group.bench_function("partial_molar_volume", |b| {
b.iter(|| {
property((
&eos,
S::partial_molar_volume,
t,
v,
&m,
Contributions::ResidualNvt,
))
})
b.iter(|| property_no_contributions((&eos, S::partial_molar_volume, t, v, &m)))
});
}

Expand Down
Loading

0 comments on commit d48b09a

Please sign in to comment.