Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
other combination rule and test for kij
  • Loading branch information
prehner committed Jan 27, 2023
commit 01348c7a771ce09e730081691c58f250a95adf51
45 changes: 40 additions & 5 deletions src/pcsaft/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ impl From<PcSaftBinaryRecord> for f64 {

impl<T: Copy + ValueInto<f64>> FromSegmentsBinary<T> for PcSaftBinaryRecord {
fn from_segments_binary(segments: &[(Self, T, T)]) -> Result<Self, ParameterError> {
let k_ij = segments
.iter()
.map(|(br, n1, n2)| br.k_ij * (*n1).value_into().unwrap() * (*n2).value_into().unwrap())
.sum();
Ok(Self { k_ij })
let (k_ij, n) = segments.iter().fold((0.0, 0.0), |(k_ij, n), (br, n1, n2)| {
let nab = (*n1).value_into().unwrap() * (*n2).value_into().unwrap();
(k_ij + br.k_ij * nab, n + nab)
});
Ok(Self { k_ij: k_ij / n })
}
}

Expand Down Expand Up @@ -523,6 +523,7 @@ impl std::fmt::Display for PcSaftParameters {
pub mod utils {
use super::*;
use feos_core::joback::JobackRecord;
use feos_core::parameter::{BinaryRecord, ChemicalRecord, SegmentRecord};
use std::sync::Arc;

pub fn propane_parameters() -> Arc<PcSaftParameters> {
Expand Down Expand Up @@ -733,4 +734,38 @@ pub mod utils {
serde_json::from_str(binary_json).expect("Unable to parse json.");
Arc::new(PcSaftParameters::new_binary(binary_record, None))
}

#[test]
pub fn test_kij() -> Result<(), ParameterError> {
let ch3: String = "CH3".into();
let ch2: String = "CH2".into();
let oh = "OH".into();
let propane = ChemicalRecord::new(
Default::default(),
vec![ch3.clone(), ch2.clone(), ch3.clone()],
None,
);
let ethanol = ChemicalRecord::new(Default::default(), vec![ch3, ch2, oh], None);
let segment_records = SegmentRecord::from_json("parameters/pcsaft/sauer2014_homo.json")?;
let kij = [("CH3", "OH", -0.2), ("CH2", "OH", -0.1)];
let binary_segment_records = kij
.iter()
.map(|&(id1, id2, k_ij)| {
BinaryRecord::new(id1.into(), id2.into(), PcSaftBinaryRecord { k_ij })
})
.collect();
let params = PcSaftParameters::from_segments(
vec![propane, ethanol],
segment_records,
Some(binary_segment_records),
)?;
let k_ij = &params.binary_records;
assert_eq!(k_ij[[0, 0]].k_ij, 0.0);
assert_eq!(k_ij[[0, 1]].k_ij, -0.5 / 9.);
assert_eq!(k_ij[[1, 0]].k_ij, -0.5 / 9.);
assert_eq!(k_ij[[1, 1]].k_ij, 0.0);
println!("{k_ij}");

Ok(())
}
}