Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
Revive phi in hetero gc PC-SAFT
  • Loading branch information
prehner committed Apr 14, 2023
commit 5f60be7853c9f6037e89c78f98c8f868ae38fcf9
18 changes: 17 additions & 1 deletion src/gc_pcsaft/eos/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ pub struct GcPcSaftChemicalRecord {
pub identifier: Identifier,
pub segments: HashMap<String, f64>,
pub bonds: HashMap<[String; 2], f64>,
phi: f64,
}

impl GcPcSaftChemicalRecord {
pub fn new(
identifier: Identifier,
segments: HashMap<String, f64>,
bonds: HashMap<[String; 2], f64>,
phi: f64,
) -> Self {
Self {
identifier,
segments,
bonds,
phi,
}
}
}
Expand All @@ -53,11 +56,13 @@ impl From<ChemicalRecord> for GcPcSaftChemicalRecord {
chemical_record.identifier.clone(),
chemical_record.segment_count(),
chemical_record.bond_count(),
1.0,
)
}
}

/// Parameter set required for the gc-PC-SAFT equation of state.
#[derive(Clone)]
pub struct GcPcSaftEosParameters {
pub molarweight: Array1<f64>,
pub component_index: Array1<usize>,
Expand Down Expand Up @@ -116,11 +121,14 @@ impl ParameterHetero for GcPcSaftEosParameters {
let mut sigma_mix = Vec::new();
let mut epsilon_k_mix = Vec::new();

let mut phi = Vec::new();

let mut joback_records = Vec::new();

for (i, chemical_record) in chemical_records.iter().cloned().enumerate() {
let mut segment_indices = IndexMap::with_capacity(segment_records.len());
let segment_map = chemical_record.segment_map(&segment_records)?;
phi.push(chemical_record.phi);

let mut m_i = 0.0;
let mut sigma_i = 0.0;
Expand Down Expand Up @@ -214,7 +222,7 @@ impl ParameterHetero for GcPcSaftEosParameters {
let sigma_ij =
Array2::from_shape_fn([sigma.len(); 2], |(i, j)| 0.5 * (sigma[i] + sigma[j]));
let epsilon_k_ij = Array2::from_shape_fn([epsilon_k.len(); 2], |(i, j)| {
(epsilon_k[i] * epsilon_k[j]).sqrt()
(epsilon_k[i] * phi[component_index[i]] * epsilon_k[j] * phi[component_index[j]]).sqrt()
}) * (1.0 - &k_ij);

// Combining rules polar
Expand Down Expand Up @@ -271,6 +279,14 @@ impl ParameterHetero for GcPcSaftEosParameters {
}
}

impl GcPcSaftEosParameters {
pub fn phi(self, phi: &[f64]) -> Result<Self, ParameterError> {
let mut cr = self.chemical_records;
cr.iter_mut().zip(phi.iter()).for_each(|(c, &p)| c.phi = p);
Self::from_segments(cr, self.segment_records, self.binary_segment_records)
}
}

impl HardSphereProperties for GcPcSaftEosParameters {
fn monomer_shape<N: DualNum<f64>>(&self, _: N) -> MonomerShape<N> {
let m = self.m.mapv(N::from);
Expand Down
4 changes: 4 additions & 0 deletions src/gc_pcsaft/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl_parameter_from_segments!(GcPcSaftEosParameters, PyGcPcSaftEosParameters);

#[pymethods]
impl PyGcPcSaftEosParameters {
fn phi(&self, phi: Vec<f64>) -> PyResult<Self> {
Ok(Self(Arc::new((*self.0).clone().phi(&phi)?)))
}

fn _repr_markdown_(&self) -> String {
self.0.to_markdown()
}
Expand Down