Skip to content

Commit 65322fd

Browse files
prehnerg-bauer
andcommitted
Revised handling of ideal gas contribution (#158)
Co-authored-by: Gernot Bauer <bauer@itt.uni-stuttgart.de>
1 parent 34532e3 commit 65322fd

File tree

102 files changed

+4099
-3284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+4099
-3284
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Added `IdealGasModel` enum that collects all implementors of the `IdealGas` trait. [#158](https://github.com/feos-org/feos/pull/158)
10+
- Added `feos.ideal_gas` module in Python from which (currently) `Joback` and `JobackParameters` are available. [#158](https://github.com/feos-org/feos/pull/158)
11+
812
### Changed
913
- Changed the internal implementation of the association contribution to accomodate more general association schemes. [#150](https://github.com/feos-org/feos/pull/150)
1014
- 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)
1115
- 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)
1216
- Adjusted all models' implementation of the `Parameter` trait which now requires `Result`s in some methods. [#161](https://github.com/feos-org/feos/pull/161)
17+
- Renamed `EosVariant` to `ResidualModel`. [#158](https://github.com/feos-org/feos/pull/158)
18+
- 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)
1319

1420
### Packaging
1521
- Updated `num-dual` dependency to 0.7. [#137](https://github.com/feos-org/feos/pull/137)

benches/contributions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use criterion::{criterion_group, criterion_main, Criterion};
99
use feos::pcsaft::{PcSaft, PcSaftParameters};
1010
use feos_core::parameter::{IdentifierOption, Parameter};
11-
use feos_core::{DensityInitialization, Derivative, EquationOfState, State};
11+
use feos_core::{DensityInitialization, Derivative, Residual, State};
1212
use ndarray::arr1;
1313
use quantity::si::*;
1414
use std::sync::Arc;

benches/dual_numbers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
77
use feos::pcsaft::{PcSaft, PcSaftParameters};
88
use feos_core::{
99
parameter::{IdentifierOption, Parameter},
10-
Derivative, EquationOfState, HelmholtzEnergy, HelmholtzEnergyDual, State, StateHD,
10+
Derivative, HelmholtzEnergy, HelmholtzEnergyDual, Residual, State, StateHD,
1111
};
1212
use ndarray::{arr1, Array};
1313
use num_dual::DualNum;
@@ -28,15 +28,15 @@ fn state_pcsaft(parameters: PcSaftParameters) -> State<PcSaft> {
2828
}
2929

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

3838
/// Benchmark for evaluation of the Helmholtz energy for different dual number types.
39-
fn bench_dual_numbers<E: EquationOfState>(c: &mut Criterion, group_name: &str, state: State<E>) {
39+
fn bench_dual_numbers<E: Residual>(c: &mut Criterion, group_name: &str, state: State<E>) {
4040
let mut group = c.benchmark_group(group_name);
4141
group.bench_function("a_f64", |b| {
4242
b.iter(|| a_res((&state.eos, &state.derive0())))

benches/state_creation.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use criterion::{criterion_group, criterion_main, Criterion};
22
use feos::pcsaft::{PcSaft, PcSaftParameters};
33
use feos_core::{
44
parameter::{IdentifierOption, Parameter},
5-
Contributions, DensityInitialization, EquationOfState, PhaseEquilibrium, State,
5+
Contributions, DensityInitialization, PhaseEquilibrium, Residual, State,
66
};
77
use ndarray::{Array, Array1};
88
use quantity::si::*;
99
use std::sync::Arc;
1010

1111
/// Evaluate NPT constructor
12-
fn npt<E: EquationOfState>(
12+
fn npt<E: Residual>(
1313
(eos, t, p, n, rho0): (
1414
&Arc<E>,
1515
SINumber,
@@ -22,26 +22,26 @@ fn npt<E: EquationOfState>(
2222
}
2323

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

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

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

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

44-
fn bubble_point<E: EquationOfState>((eos, t, x): (&Arc<E>, SINumber, &Array1<f64>)) {
44+
fn bubble_point<E: Residual>((eos, t, x): (&Arc<E>, SINumber, &Array1<f64>)) {
4545
PhaseEquilibrium::bubble_point(
4646
eos,
4747
t,
@@ -53,7 +53,7 @@ fn bubble_point<E: EquationOfState>((eos, t, x): (&Arc<E>, SINumber, &Array1<f64
5353
.unwrap();
5454
}
5555

56-
fn dew_point<E: EquationOfState>((eos, t, y): (&Arc<E>, SINumber, &Array1<f64>)) {
56+
fn dew_point<E: Residual>((eos, t, y): (&Arc<E>, SINumber, &Array1<f64>)) {
5757
PhaseEquilibrium::dew_point(
5858
eos,
5959
t,
@@ -65,7 +65,7 @@ fn dew_point<E: EquationOfState>((eos, t, y): (&Arc<E>, SINumber, &Array1<f64>))
6565
.unwrap();
6666
}
6767

68-
fn bench_states<E: EquationOfState>(c: &mut Criterion, group_name: &str, eos: &Arc<E>) {
68+
fn bench_states<E: Residual>(c: &mut Criterion, group_name: &str, eos: &Arc<E>) {
6969
let ncomponents = eos.components();
7070
let x = Array::from_elem(ncomponents, 1.0 / ncomponents as f64);
7171
let n = &x * 100.0 * MOL;

benches/state_properties.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
22
use feos::pcsaft::{PcSaft, PcSaftParameters};
33
use feos_core::{
44
parameter::{IdentifierOption, Parameter},
5-
Contributions, EquationOfState, State,
5+
Contributions, Residual, State,
66
};
77
use ndarray::arr1;
88
use quantity::si::*;
@@ -12,7 +12,7 @@ type S = State<PcSaft>;
1212

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

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

5353
let mut group = c.benchmark_group("state_properties_pcsaft_methane_ethane_propane");
5454
group.bench_function("a", |b| {
55-
b.iter(|| property((&eos, S::helmholtz_energy, t, v, &m, Contributions::Total)))
55+
b.iter(|| property_no_contributions((&eos, S::residual_helmholtz_energy, t, v, &m)))
5656
});
5757
group.bench_function("compressibility", |b| {
5858
b.iter(|| property((&eos, S::compressibility, t, v, &m, Contributions::Total)))
@@ -61,19 +61,10 @@ fn properties_pcsaft(c: &mut Criterion) {
6161
b.iter(|| property_no_contributions((&eos, S::ln_phi, t, v, &m)))
6262
});
6363
group.bench_function("c_v", |b| {
64-
b.iter(|| property((&eos, S::c_v, t, v, &m, Contributions::ResidualNvt)))
64+
b.iter(|| property_no_contributions((&eos, S::c_v_res, t, v, &m)))
6565
});
6666
group.bench_function("partial_molar_volume", |b| {
67-
b.iter(|| {
68-
property((
69-
&eos,
70-
S::partial_molar_volume,
71-
t,
72-
v,
73-
&m,
74-
Contributions::ResidualNvt,
75-
))
76-
})
67+
b.iter(|| property_no_contributions((&eos, S::partial_molar_volume, t, v, &m)))
7768
});
7869
}
7970

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

9586
let mut group = c.benchmark_group("state_properties_pcsaft_polar");
9687
group.bench_function("a", |b| {
97-
b.iter(|| property((&eos, S::helmholtz_energy, t, v, &m, Contributions::Total)))
88+
b.iter(|| property_no_contributions((&eos, S::residual_helmholtz_energy, t, v, &m)))
9889
});
9990
group.bench_function("compressibility", |b| {
10091
b.iter(|| property((&eos, S::compressibility, t, v, &m, Contributions::Total)))
@@ -103,19 +94,10 @@ fn properties_pcsaft_polar(c: &mut Criterion) {
10394
b.iter(|| property_no_contributions((&eos, S::ln_phi, t, v, &m)))
10495
});
10596
group.bench_function("c_v", |b| {
106-
b.iter(|| property((&eos, S::c_v, t, v, &m, Contributions::ResidualNvt)))
97+
b.iter(|| property_no_contributions((&eos, S::c_v_res, t, v, &m)))
10798
});
10899
group.bench_function("partial_molar_volume", |b| {
109-
b.iter(|| {
110-
property((
111-
&eos,
112-
S::partial_molar_volume,
113-
t,
114-
v,
115-
&m,
116-
Contributions::ResidualNvt,
117-
))
118-
})
100+
b.iter(|| property_no_contributions((&eos, S::partial_molar_volume, t, v, &m)))
119101
});
120102
}
121103

0 commit comments

Comments
 (0)