Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
removed unused method from hard sphere module, added tests to CI, mov…
…ed vr mie benches, removed fmt from Cargo.toml
  • Loading branch information
g-bauer committed Apr 17, 2024
commit d8c03332f8dd46497c80bc03a254737644860d42
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
model: [pcsaft, gc_pcsaft, pets, uvtheory, saftvrqmie]
model: [pcsaft, gc_pcsaft, pets, uvtheory, saftvrqmie, saftvrmie]

steps:
- uses: actions/checkout@v4
Expand Down
37 changes: 7 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
[package]
name = "feos"
version = "0.6.1"
authors = [
"Gernot Bauer <[email protected]>",
"Philipp Rehner <[email protected]>",
]
authors = ["Gernot Bauer <[email protected]>", "Philipp Rehner <[email protected]>"]
edition = "2021"
readme = "README.md"
license = "MIT OR Apache-2.0"
description = "FeOs - A framework for equations of state and classical density functional theory."
homepage = "https://github.com/feos-org"
repository = "https://github.com/feos-org/feos"
keywords = [
"physics",
"thermodynamics",
"equations_of_state",
"phase_equilibria",
]
keywords = ["physics", "thermodynamics", "equations_of_state", "phase_equilibria"]
categories = ["science"]

[package.metadata.docs.rs]
features = ["all_models", "rayon"]
rustdoc-args = ["--html-in-header", "./docs-header.html"]
rustdoc-args = [ "--html-in-header", "./docs-header.html" ]

[workspace]
members = ["feos-core", "feos-dft", "feos-derive"]
Expand Down Expand Up @@ -63,6 +55,7 @@ inherits = "release"
lto = true
codegen-units = 1


[features]
default = []
dft = ["feos-dft", "petgraph"]
Expand All @@ -73,26 +66,10 @@ gc_pcsaft = ["association"]
uvtheory = ["lazy_static"]
pets = []
saftvrqmie = []
saftvrmie = ["association"]
saftvrmie = []
rayon = ["dep:rayon", "ndarray/rayon", "feos-core/rayon", "feos-dft?/rayon"]
python = [
"pyo3",
"numpy",
"quantity/python",
"feos-core/python",
"feos-dft?/python",
"rayon",
]
all_models = [
"dft",
"estimator",
"pcsaft",
"gc_pcsaft",
"uvtheory",
"pets",
"saftvrqmie",
"saftvrmie",
]
python = ["pyo3", "numpy", "quantity/python", "feos-core/python", "feos-dft?/python", "rayon"]
all_models = ["dft", "estimator", "pcsaft", "gc_pcsaft", "uvtheory", "pets", "saftvrqmie", "saftvrmie"]

[[bench]]
name = "state_properties"
Expand Down
72 changes: 3 additions & 69 deletions benches/dual_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@
//! on the dual number type used without the overhead of the `State`
//! creation.
use criterion::{criterion_group, criterion_main, Criterion};
use feos::hard_sphere::HardSphereProperties;
#[cfg(feature = "pcsaft")]
use feos::pcsaft::{PcSaft, PcSaftParameters};
#[cfg(feature = "saftvrmie")]
use feos::saftvrmie::{SaftVRMie, SaftVRMieParameters};
use feos_core::si::*;
use feos_core::{
parameter::{IdentifierOption, Parameter},
Derivative, Residual, State, StateHD,
};
use ndarray::{arr1, Array, ScalarOperand};
use num_dual::{Dual2_64, Dual3_64, Dual64, DualNum, HyperDual64};
use num_dual::DualNum;
use std::sync::Arc;
use typenum::P3;

/// Helper function to create a state for given parameters.
/// - temperature is 80% of critical temperature,
/// - volume is critical volume,
/// - molefracs (or moles) for equimolar mixture.
#[cfg(feature = "pcsaft")]
fn state_pcsaft(parameters: PcSaftParameters) -> State<PcSaft> {
let n = parameters.pure_records.len();
let eos = Arc::new(PcSaft::new(Arc::new(parameters)));
Expand All @@ -33,48 +28,11 @@ fn state_pcsaft(parameters: PcSaftParameters) -> State<PcSaft> {
State::new_nvt(&eos, temperature, cp.volume, &moles).unwrap()
}

#[cfg(feature = "saftvrmie")]
fn state_saftvrmie(parameters: &Arc<SaftVRMieParameters>) -> State<SaftVRMie> {
let n = parameters.pure_records.len();
let eos = Arc::new(SaftVRMie::new(parameters.clone()));
let moles = Array::from_elem(n, 1.0 / n as f64) * 10.0 * MOL;
let cp = State::critical_point(&eos, Some(&moles), None, Default::default()).unwrap();
let temperature = 0.8 * cp.temperature;
State::new_nvt(&eos, temperature, cp.volume, &moles).unwrap()
}

/// Residual Helmholtz energy given an equation of state and a StateHD.
fn a_res<D: DualNum<f64> + Copy + ScalarOperand, E: Residual>(inp: (&Arc<E>, &StateHD<D>)) -> D {
inp.0.residual_helmholtz_energy(inp.1)
}

fn d_hs<D: DualNum<f64> + Copy, P: HardSphereProperties>(inp: (&P, D)) -> D {
inp.0.hs_diameter(inp.1)[0]
}

/// Benchmark for evaluation of the hard sphere diameter
fn bench_diameter<P: HardSphereProperties>(
c: &mut Criterion,
group_name: &str,
temperature: f64,
parameters: &P,
) {
let mut group = c.benchmark_group(group_name);
group.bench_function("d_f64", |b| b.iter(|| d_hs((parameters, temperature))));
group.bench_function("d_dual", |b| {
b.iter(|| d_hs((parameters, Dual64::from_re(temperature).derivative())))
});
group.bench_function("d_dual2", |b| {
b.iter(|| d_hs((parameters, Dual2_64::from_re(temperature).derivative())))
});
group.bench_function("d_hyperdual", |b| {
b.iter(|| d_hs((parameters, HyperDual64::from_re(temperature).derivative1())))
});
group.bench_function("d_dual3", |b| {
b.iter(|| d_hs((parameters, Dual3_64::from_re(temperature).derivative())))
});
}

/// Benchmark for evaluation of the Helmholtz energy for different dual number types.
fn bench_dual_numbers<E: Residual>(c: &mut Criterion, group_name: &str, state: State<E>) {
let mut group = c.benchmark_group(group_name);
Expand All @@ -101,7 +59,6 @@ fn bench_dual_numbers<E: Residual>(c: &mut Criterion, group_name: &str, state: S
}

/// Benchmark for the PC-SAFT equation of state
#[cfg(feature = "pcsaft")]
fn pcsaft(c: &mut Criterion) {
// methane
let parameters = PcSaftParameters::from_json(
Expand Down Expand Up @@ -142,28 +99,8 @@ fn pcsaft(c: &mut Criterion) {
);
}

/// Benchmark for the SAFT VR Mie equation of state
#[cfg(feature = "saftvrmie")]
fn saftvrmie(c: &mut Criterion) {
use feos::saftvrmie::test_utils::test_parameters;

let parameters = Arc::new(test_parameters().remove("methane").unwrap());
bench_dual_numbers(
c,
"dual_numbers_saftvrmie_methane",
state_saftvrmie(&parameters),
);
bench_diameter(
c,
"dual_numbers_diameter_saftvrmie_methane",
200.0,
parameters.as_ref(),
);
}

/// Benchmark for the PC-SAFT equation of state.
/// Binary system of methane and co2 used to model biogas.
#[cfg(feature = "pcsaft")]
fn methane_co2_pcsaft(c: &mut Criterion) {
let parameters = PcSaftParameters::from_multiple_json(
&[
Expand Down Expand Up @@ -192,8 +129,5 @@ fn methane_co2_pcsaft(c: &mut Criterion) {
bench_dual_numbers(c, "dual_numbers_pcsaft_methane_co2", state);
}

#[cfg(feature = "pcsaft")]
criterion_group!(benches, pcsaft, methane_co2_pcsaft);
#[cfg(feature = "saftvrmie")]
criterion_group!(benches, saftvrmie);
criterion_main!(benches);
criterion_group!(bench, pcsaft, methane_co2_pcsaft);
criterion_main!(bench);
Loading