Skip to content

Commit d692d8d

Browse files
committed
Fully implemented new parameter struct
1 parent 39cdc7f commit d692d8d

File tree

108 files changed

+4151
-6804
lines changed

Some content is hidden

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

108 files changed

+4151
-6804
lines changed

crates/feos-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rayon = { workspace = true, optional = true }
2828
typenum = { workspace = true }
2929
itertools = { workspace = true }
3030
arrayvec = { workspace = true, features = ["serde"] }
31+
petgraph = { workspace = true }
3132

3233
[dev-dependencies]
3334
approx = { workspace = true }

crates/feos-core/src/cubic.rs

Lines changed: 5 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
//! The implementation closely follows the form of the equations given in
66
//! [this wikipedia article](https://en.wikipedia.org/wiki/Cubic_equations_of_state#Peng%E2%80%93Robinson_equation_of_state).
77
use crate::equation_of_state::{Components, Molarweight, Residual};
8-
use crate::parameter::{Identifier, ParameterStruct, PureRecord};
8+
use crate::parameter::{Identifier, Parameters, PureRecord};
99
use crate::state::StateHD;
1010
use crate::{FeosError, FeosResult};
1111
use ndarray::{Array1, Array2, ScalarOperand};
1212
use num_dual::DualNum;
13-
use quantity::{GRAM, MOL, MolarWeight};
13+
use quantity::MolarWeight;
1414
use serde::{Deserialize, Serialize};
1515
use std::f64::consts::SQRT_2;
16-
use std::fmt;
1716

1817
const KB_A3: f64 = 13806490.0;
1918

@@ -39,42 +38,8 @@ impl PengRobinsonRecord {
3938
}
4039
}
4140

42-
impl std::fmt::Display for PengRobinsonRecord {
43-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44-
write!(f, "PengRobinsonRecord(tc={} K", self.tc)?;
45-
write!(f, ", pc={} Pa", self.pc)?;
46-
write!(f, ", acentric factor={}", self.acentric_factor)
47-
}
48-
}
49-
5041
/// Peng-Robinson parameters for one ore more substances.
51-
pub type PengRobinsonParameters = ParameterStruct<PengRobinsonRecord, f64, ()>;
52-
53-
// /// Peng-Robinson parameters for one ore more substances.
54-
// pub struct PengRobinsonParameters {
55-
// /// Critical temperature in Kelvin
56-
// tc: Array1<f64>,
57-
// a: Array1<f64>,
58-
// b: Array1<f64>,
59-
// /// Binary interaction parameter
60-
// k_ij: Array2<f64>,
61-
// kappa: Array1<f64>,
62-
// /// Molar weight in units of g/mol
63-
// molarweight: Array1<f64>,
64-
// /// List of pure component records
65-
// pure_records: Vec<PureRecord<PengRobinsonRecord, ()>>,
66-
// /// List of binary records
67-
// binary_records: Vec<BinaryRecord<usize, f64, ()>>,
68-
// }
69-
70-
// impl std::fmt::Display for PengRobinsonParameters {
71-
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72-
// self.pure_records
73-
// .iter()
74-
// .try_for_each(|pr| writeln!(f, "{}", pr))?;
75-
// writeln!(f, "\nk_ij:\n{}", self.k_ij)
76-
// }
77-
// }
42+
pub type PengRobinsonParameters = Parameters<PengRobinsonRecord, f64, ()>;
7843

7944
impl PengRobinsonParameters {
8045
/// Build a simple parameter set without binary interaction parameters.
@@ -107,61 +72,6 @@ impl PengRobinsonParameters {
10772
}
10873
}
10974

110-
// impl Parameter for PengRobinsonParameters {
111-
// type Pure = PengRobinsonRecord;
112-
// type Binary = f64;
113-
// type Association = ();
114-
115-
// /// Creates parameters from pure component records.
116-
// fn from_records(
117-
// pure_records: Vec<PureRecord<Self::Pure, ()>>,
118-
// binary_records: Vec<BinaryRecord<usize, Self::Binary, ()>>,
119-
// ) -> FeosResult<Self> {
120-
// let n = pure_records.len();
121-
122-
// let mut tc = Array1::zeros(n);
123-
// let mut a = Array1::zeros(n);
124-
// let mut b = Array1::zeros(n);
125-
// let mut molarweight = Array1::zeros(n);
126-
// let mut kappa = Array1::zeros(n);
127-
128-
// for (i, record) in pure_records.iter().enumerate() {
129-
// molarweight[i] = record.molarweight;
130-
// let r = &record.model_record;
131-
// tc[i] = r.tc;
132-
// a[i] = 0.45724 * r.tc.powi(2) * KB_A3 / r.pc;
133-
// b[i] = 0.07780 * r.tc * KB_A3 / r.pc;
134-
// kappa[i] = 0.37464 + (1.54226 - 0.26992 * r.acentric_factor) * r.acentric_factor;
135-
// }
136-
137-
// let mut k_ij = Array2::zeros([n; 2]);
138-
// for r in &binary_records {
139-
// k_ij[[r.id1, r.id2]] = r.model_record.unwrap_or_default();
140-
// k_ij[[r.id2, r.id1]] = r.model_record.unwrap_or_default();
141-
// }
142-
143-
// Ok(Self {
144-
// tc,
145-
// a,
146-
// b,
147-
// k_ij,
148-
// kappa,
149-
// molarweight,
150-
// pure_records,
151-
// binary_records,
152-
// })
153-
// }
154-
155-
// fn records(
156-
// &self,
157-
// ) -> (
158-
// &[PureRecord<PengRobinsonRecord, ()>],
159-
// &[BinaryRecord<usize, f64, ()>],
160-
// ) {
161-
// (&self.pure_records, &self.binary_records)
162-
// }
163-
// }
164-
16575
/// A simple version of the Peng-Robinson equation of state.
16676
pub struct PengRobinson {
16777
/// Parameters
@@ -173,15 +83,12 @@ pub struct PengRobinson {
17383
/// Binary interaction parameter
17484
k_ij: Array2<f64>,
17585
kappa: Array1<f64>,
176-
/// Molar weight in units of g/mol
177-
molarweight: Array1<f64>,
17886
}
17987

18088
impl PengRobinson {
18189
/// Create a new equation of state from a set of parameters.
18290
pub fn new(parameters: PengRobinsonParameters) -> Self {
18391
let [tc, pc, ac] = parameters.collate(|r| [r.tc, r.pc, r.acentric_factor]);
184-
let molarweight = parameters.molar_weight();
18592
let [k_ij] = parameters.collate_binary(|br| [br.unwrap_or_default()]);
18693

18794
let a = 0.45724 * tc.powi(2) * KB_A3 / &pc;
@@ -194,17 +101,10 @@ impl PengRobinson {
194101
b,
195102
k_ij,
196103
kappa,
197-
molarweight,
198104
}
199105
}
200106
}
201107

202-
impl fmt::Display for PengRobinson {
203-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
204-
write!(f, "Peng Robinson")
205-
}
206-
}
207-
208108
impl Components for PengRobinson {
209109
fn components(&self) -> usize {
210110
self.parameters.pure_records.len()
@@ -260,8 +160,8 @@ impl Residual for PengRobinson {
260160
}
261161

262162
impl Molarweight for PengRobinson {
263-
fn molar_weight(&self) -> MolarWeight<Array1<f64>> {
264-
&self.molarweight * (GRAM / MOL)
163+
fn molar_weight(&self) -> &MolarWeight<Array1<f64>> {
164+
&self.parameters.molar_weight
265165
}
266166
}
267167

crates/feos-core/src/equation_of_state/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<I: IdealGas, R: Residual> Residual for EquationOfState<I, R> {
9494
}
9595

9696
impl<I, R: Molarweight> Molarweight for EquationOfState<I, R> {
97-
fn molar_weight(&self) -> MolarWeight<Array1<f64>> {
97+
fn molar_weight(&self) -> &MolarWeight<Array1<f64>> {
9898
self.residual.molar_weight()
9999
}
100100
}

crates/feos-core/src/equation_of_state/residual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use typenum::Quot;
1212
///
1313
/// Enables calculation of (mass) specific properties.
1414
pub trait Molarweight {
15-
fn molar_weight(&self) -> MolarWeight<Array1<f64>>;
15+
fn molar_weight(&self) -> &MolarWeight<Array1<f64>>;
1616
}
1717

1818
/// A residual Helmholtz energy model.

0 commit comments

Comments
 (0)