diff --git a/src/dft/mod.rs b/src/dft/mod.rs index 0271541..8012cdd 100644 --- a/src/dft/mod.rs +++ b/src/dft/mod.rs @@ -2,6 +2,7 @@ use crate::eos::PcSaftOptions; use crate::parameters::PcSaftParameters; use association::AssociationFunctional; use dispersion::AttractiveFunctional; +use feos_core::parameter::Parameter; use feos_core::MolarWeight; use feos_dft::adsorption::FluidParameters; use feos_dft::fundamental_measure_theory::{FMTContribution, FMTProperties, FMTVersion}; @@ -30,21 +31,19 @@ pub struct PcSaftFunctional { } impl PcSaftFunctional { - pub fn new(parameters: PcSaftParameters) -> DFT { + pub fn new(parameters: Rc) -> DFT { Self::new_with_options(parameters, FMTVersion::WhiteBear, PcSaftOptions::default()) } - pub fn new_full(parameters: PcSaftParameters, fmt_version: FMTVersion) -> DFT { + pub fn new_full(parameters: Rc, fmt_version: FMTVersion) -> DFT { Self::new_with_options(parameters, fmt_version, PcSaftOptions::default()) } fn new_with_options( - parameters: PcSaftParameters, + parameters: Rc, fmt_version: FMTVersion, saft_options: PcSaftOptions, ) -> DFT { - let parameters = Rc::new(parameters); - let mut contributions: Vec> = Vec::with_capacity(4); if matches!( @@ -100,7 +99,7 @@ impl PcSaftFunctional { impl HelmholtzEnergyFunctional for PcSaftFunctional { fn subset(&self, component_list: &[usize]) -> DFT { Self::new_with_options( - self.parameters.subset(component_list), + Rc::new(self.parameters.subset(component_list)), self.fmt_version, self.options, ) diff --git a/src/eos/association.rs b/src/eos/association.rs index aae6744..7e1d4bc 100644 --- a/src/eos/association.rs +++ b/src/eos/association.rs @@ -7,12 +7,10 @@ use std::f64::consts::{FRAC_PI_3, PI}; use std::fmt; use std::rc::Rc; -#[derive(Debug, Clone)] pub struct Association { pub parameters: Rc, } -#[derive(Debug, Clone)] pub struct CrossAssociation { pub parameters: Rc, pub max_iter: usize, diff --git a/src/eos/dispersion.rs b/src/eos/dispersion.rs index 94b8cef..7bbe64e 100644 --- a/src/eos/dispersion.rs +++ b/src/eos/dispersion.rs @@ -60,7 +60,6 @@ pub const B2: [f64; 7] = [ -29.66690558514725, ]; -#[derive(Debug, Clone)] pub struct Dispersion { pub parameters: Rc, } @@ -132,7 +131,7 @@ mod tests { #[test] fn helmholtz_energy() { let disp = Dispersion { - parameters: Rc::new(propane_parameters()), + parameters: propane_parameters(), }; let t = 250.0; let v = 1000.0; @@ -145,13 +144,13 @@ mod tests { #[test] fn mix() { let c1 = Dispersion { - parameters: Rc::new(propane_parameters()), + parameters: propane_parameters(), }; let c2 = Dispersion { - parameters: Rc::new(butane_parameters()), + parameters: butane_parameters(), }; let c12 = Dispersion { - parameters: Rc::new(propane_butane_parameters()), + parameters: propane_butane_parameters(), }; let t = 250.0; let v = 2.5e28; diff --git a/src/eos/hard_chain.rs b/src/eos/hard_chain.rs index 291d853..7381bbe 100644 --- a/src/eos/hard_chain.rs +++ b/src/eos/hard_chain.rs @@ -6,7 +6,6 @@ use num_dual::*; use std::fmt; use std::rc::Rc; -#[derive(Debug, Clone)] pub struct HardChain { pub parameters: Rc, } @@ -45,7 +44,7 @@ mod tests { #[test] fn helmholtz_energy() { let hc = HardChain { - parameters: Rc::new(propane_parameters()), + parameters: propane_parameters(), }; let t = 250.0; let v = 1000.0; @@ -58,13 +57,13 @@ mod tests { #[test] fn mix() { let c1 = HardChain { - parameters: Rc::new(propane_parameters()), + parameters: propane_parameters(), }; let c2 = HardChain { - parameters: Rc::new(butane_parameters()), + parameters: butane_parameters(), }; let c12 = HardChain { - parameters: Rc::new(propane_butane_parameters()), + parameters: propane_butane_parameters(), }; let t = 250.0; let v = 2.5e28; diff --git a/src/eos/hard_sphere.rs b/src/eos/hard_sphere.rs index ce0c803..083eb55 100644 --- a/src/eos/hard_sphere.rs +++ b/src/eos/hard_sphere.rs @@ -14,7 +14,6 @@ impl PcSaftParameters { } } -#[derive(Debug, Clone)] pub struct HardSphere { pub parameters: Rc, } @@ -76,7 +75,7 @@ mod tests { #[test] fn helmholtz_energy() { let hs = HardSphere { - parameters: Rc::new(propane_parameters()), + parameters: propane_parameters(), }; let t = 250.0; let v = 1000.0; @@ -89,13 +88,13 @@ mod tests { #[test] fn mix() { let c1 = HardSphere { - parameters: Rc::new(propane_parameters()), + parameters: propane_parameters(), }; let c2 = HardSphere { - parameters: Rc::new(butane_parameters()), + parameters: butane_parameters(), }; let c12 = HardSphere { - parameters: Rc::new(propane_butane_parameters()), + parameters: propane_butane_parameters(), }; let t = 250.0; let v = 2.5e28; diff --git a/src/eos/mod.rs b/src/eos/mod.rs index 85bd3f5..91120d9 100644 --- a/src/eos/mod.rs +++ b/src/eos/mod.rs @@ -1,5 +1,6 @@ use crate::parameters::PcSaftParameters; use feos_core::joback::Joback; +use feos_core::parameter::Parameter; use feos_core::{ Contributions, EntropyScaling, EosError, EosResult, EosUnit, EquationOfState, HelmholtzEnergy, IdealGasContribution, MolarWeight, State, @@ -53,12 +54,11 @@ pub struct PcSaft { } impl PcSaft { - pub fn new(parameters: PcSaftParameters) -> Self { + pub fn new(parameters: Rc) -> Self { Self::with_options(parameters, PcSaftOptions::default()) } - pub fn with_options(parameters: PcSaftParameters, options: PcSaftOptions) -> Self { - let parameters = Rc::new(parameters); + pub fn with_options(parameters: Rc, options: PcSaftOptions) -> Self { let mut contributions: Vec> = Vec::with_capacity(7); contributions.push(Box::new(HardSphere { parameters: parameters.clone(), @@ -117,17 +117,10 @@ impl EquationOfState for PcSaft { } fn subset(&self, component_list: &[usize]) -> Self { - Self::with_options(self.parameters.subset(component_list), self.options) - // match &self.ideal_gas { - // IdealGasContributions::QSPR(_) => { - // Self::with_options(self.parameters.subset(component_list), self.options, None) - // } - // IdealGasContributions::Joback(joback) => Self::with_options( - // self.parameters.subset(component_list), - // self.options, - // Some(joback.parameters.subset(component_list)), - // ), - // } + Self::with_options( + Rc::new(self.parameters.subset(component_list)), + self.options, + ) } fn compute_max_density(&self, moles: &Array1) -> f64 { diff --git a/src/eos/polar.rs b/src/eos/polar.rs index 01c2d6d..85f54bf 100644 --- a/src/eos/polar.rs +++ b/src/eos/polar.rs @@ -181,7 +181,6 @@ fn triplet_integral_ijk_dq>(mijk: f64, eta: D, c: &[[f64; 2]]) - .sum() } -#[derive(Debug, Clone)] pub struct Dipole { pub parameters: Rc, } @@ -278,7 +277,6 @@ impl fmt::Display for Dipole { } } -#[derive(Debug, Clone)] pub struct Quadrupole { pub parameters: Rc, } @@ -376,13 +374,12 @@ impl fmt::Display for Quadrupole { } } -#[derive(Debug, Clone)] +#[derive(Clone, Copy)] pub enum DQVariants { DQ35, DQ44, } -#[derive(Debug, Clone)] pub struct DipoleQuadrupole { pub parameters: Rc, pub variant: DQVariants, diff --git a/src/eos/qspr.rs b/src/eos/qspr.rs index 49b2546..2dcf761 100644 --- a/src/eos/qspr.rs +++ b/src/eos/qspr.rs @@ -63,7 +63,6 @@ const AP_400: [f64; 6] = [ -12669.4196622924, ]; -#[derive(Debug)] #[allow(clippy::upper_case_acronyms)] pub struct QSPR { pub parameters: Rc, diff --git a/src/parameters.rs b/src/parameters.rs index 2b738ae..867c4f5 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -1,14 +1,12 @@ use feos_core::joback::JobackRecord; -use feos_core::parameter::{ - BinaryRecord, FromSegments, Identifier, Parameter, ParameterError, PureRecord, -}; +use feos_core::parameter::{FromSegments, FromSegmentsBinary, Parameter, PureRecord}; use ndarray::{Array, Array1, Array2}; use quantity::si::{JOULE, KB, KELVIN}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; /// PcSaft parameter set. -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Clone, Default)] pub struct PcSaftRecord { /// Segment number pub m: f64, @@ -45,11 +43,7 @@ pub struct PcSaftRecord { } impl FromSegments for PcSaftRecord { - type Binary = f64; - fn from_segments( - segments: &[(Self, f64)], - _binary_records: Option<&[BinaryRecord]>, - ) -> Result { + fn from_segments(segments: &[(Self, f64)]) -> Self { let mut m = 0.0; let mut sigma3 = 0.0; let mut epsilon_k = 0.0; @@ -65,45 +59,29 @@ impl FromSegments for PcSaftRecord { let q = match q.len() { 0 => None, 1 => Some(q[0]), - _ => { - return Err(ParameterError::HomoGc(String::from( - "More than one segment with quadrupole moment.", - ))) - } + _ => panic!("More than one segment with quadrupole moment."), }; let mu: Vec = segments.iter().filter_map(|s| s.0.mu).collect(); let mu = match mu.len() { 0 => None, 1 => Some(mu[0]), - _ => { - return Err(ParameterError::HomoGc(String::from( - "More than one segment with dipole moment.", - ))) - } + _ => panic!("More than one segment with dipole moment."), }; let kappa_ab: Vec = segments.iter().filter_map(|s| s.0.kappa_ab).collect(); let kappa_ab = match kappa_ab.len() { 0 => None, 1 => Some(kappa_ab[0]), - _ => { - return Err(ParameterError::HomoGc(String::from( - "More than one segment with association site.", - ))) - } + _ => panic!("More than one segment with association site."), }; let epsilon_k_ab: Vec = segments.iter().filter_map(|s| s.0.epsilon_k_ab).collect(); let epsilon_k_ab = match epsilon_k_ab.len() { 0 => None, 1 => Some(epsilon_k_ab[0]), - _ => { - return Err(ParameterError::HomoGc(String::from( - "More than one segment with association site", - ))) - } + _ => panic!("More than one segment with association site"), }; let na = Some(1.0); let nb = Some(1.0); - Ok(Self { + Self { m, sigma: (sigma3 / m).cbrt(), epsilon_k: epsilon_k / m, @@ -116,7 +94,7 @@ impl FromSegments for PcSaftRecord { viscosity: None, diffusion: None, thermal_conductivity: None, - }) + } } } @@ -188,7 +166,24 @@ impl PcSaftRecord { } } -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Clone, Default)] +pub struct PcSaftBinaryRecord { + k_ij: f64, +} + +impl From for PcSaftBinaryRecord { + fn from(k_ij: f64) -> Self { + Self { k_ij } + } +} + +impl FromSegmentsBinary for PcSaftBinaryRecord { + fn from_segments_binary(segments: &[(Self, f64, f64)]) -> Self { + let k_ij = segments.iter().map(|(br, n1, n2)| br.k_ij * n1 * n2).sum(); + Self { k_ij } + } +} + pub struct PcSaftParameters { pub molarweight: Array1, pub m: Array1, @@ -218,29 +213,19 @@ pub struct PcSaftParameters { pub diffusion: Option>, pub thermal_conductivity: Option>, pub pure_records: Vec>, + pub binary_records: Array2, pub joback_records: Option>, - pub binary_records: Option>>, -} - -impl PcSaftParameters { - pub fn subset(&self, component_list: &[usize]) -> Self { - let pure_records = component_list - .iter() - .map(|&i| self.pure_records[i].clone()) - .collect(); - Self::from_records(pure_records, self.binary_records.clone()).unwrap() - } } impl Parameter for PcSaftParameters { type Pure = PcSaftRecord; type IdealGas = JobackRecord; - type Binary = f64; + type Binary = PcSaftBinaryRecord; fn from_records( pure_records: Vec>, - binary_records: Option>>, - ) -> Result { + binary_records: Array2, + ) -> Self { let n = pure_records.len(); let mut molarweight = Array::zeros(n); @@ -318,18 +303,7 @@ impl Parameter for PcSaftParameters { } } - let mut k_ij = Array::zeros([n, n]); - match &binary_records { - Some(bs) => bs.iter().for_each(|record| { - let i = component_index.get(&record.id1); - let j = component_index.get(&record.id2); - if let (Some(i), Some(j)) = (i, j) { - k_ij[[*i, *j]] = record.model_record; - k_ij[[*j, *i]] = record.model_record - } - }), - None => (), - } + let k_ij = binary_records.map(|br| br.k_ij); let mut epsilon_k_ij = Array::zeros((n, n)); let mut sigma_ij = Array::zeros((n, n)); let mut e_k_ij = Array::zeros((n, n)); @@ -377,7 +351,7 @@ impl Parameter for PcSaftParameters { .map(|r| r.ideal_gas_record.clone()) .collect(); - Ok(Self { + Self { molarweight, m, sigma, @@ -406,9 +380,18 @@ impl Parameter for PcSaftParameters { diffusion: diffusion_coefficients, thermal_conductivity: thermal_conductivity_coefficients, pure_records, + binary_records, joback_records, - binary_records: binary_records.map(|br| br.to_vec()), - }) + } + } + + fn records( + &self, + ) -> ( + &[PureRecord], + &Array2, + ) { + (&self.pure_records, &self.binary_records) } } @@ -416,6 +399,7 @@ impl Parameter for PcSaftParameters { pub mod utils { use super::*; use feos_core::joback::JobackRecord; + use std::rc::Rc; // use feos_core::parameter::SegmentRecord; // pub fn pure_record_vec() -> Vec> { @@ -579,7 +563,7 @@ pub mod utils { // PcSaftParameters::from_records(vec![methane_record], None).unwrap() // } - pub fn propane_parameters() -> PcSaftParameters { + pub fn propane_parameters() -> Rc { let propane_json = r#" { "identifier": { @@ -602,7 +586,7 @@ pub mod utils { }"#; let propane_record: PureRecord = serde_json::from_str(propane_json).expect("Unable to parse json."); - PcSaftParameters::from_records(vec![propane_record], None).unwrap() + Rc::new(PcSaftParameters::new_pure(propane_record)) } // pub fn propane_homogc_parameters() -> PcSaftParameters { @@ -673,10 +657,10 @@ pub mod utils { }"#; let co2_record: PureRecord = serde_json::from_str(co2_json).expect("Unable to parse json."); - PcSaftParameters::from_records(vec![co2_record], None).unwrap() + PcSaftParameters::new_pure(co2_record) } - pub fn butane_parameters() -> PcSaftParameters { + pub fn butane_parameters() -> Rc { let butane_json = r#" { "identifier": { @@ -696,7 +680,7 @@ pub mod utils { }"#; let butane_record: PureRecord = serde_json::from_str(butane_json).expect("Unable to parse json."); - PcSaftParameters::from_records(vec![butane_record], None).unwrap() + Rc::new(PcSaftParameters::new_pure(butane_record)) } pub fn dme_parameters() -> PcSaftParameters { @@ -720,7 +704,7 @@ pub mod utils { }"#; let dme_record: PureRecord = serde_json::from_str(dme_json).expect("Unable to parse json."); - PcSaftParameters::from_records(vec![dme_record], None).unwrap() + PcSaftParameters::new_pure(dme_record) } pub fn water_parameters() -> PcSaftParameters { @@ -745,7 +729,7 @@ pub mod utils { }"#; let water_record: PureRecord = serde_json::from_str(water_json).expect("Unable to parse json."); - PcSaftParameters::from_records(vec![water_record], None).unwrap() + PcSaftParameters::new_pure(water_record) } pub fn dme_co2_parameters() -> PcSaftParameters { @@ -787,10 +771,10 @@ pub mod utils { ]"#; let binary_record: Vec> = serde_json::from_str(binary_json).expect("Unable to parse json."); - PcSaftParameters::from_records(binary_record, None).unwrap() + PcSaftParameters::new_binary(binary_record, None) } - pub fn propane_butane_parameters() -> PcSaftParameters { + pub fn propane_butane_parameters() -> Rc { let binary_json = r#"[ { "identifier": { @@ -832,7 +816,7 @@ pub mod utils { ]"#; let binary_record: Vec> = serde_json::from_str(binary_json).expect("Unable to parse json."); - PcSaftParameters::from_records(binary_record, None).unwrap() + Rc::new(PcSaftParameters::new_binary(binary_record, None)) } // pub fn water_hexane_parameters() -> PcSaftParameters { diff --git a/src/python/dft.rs b/src/python/dft.rs index 17bb7a6..4991508 100644 --- a/src/python/dft.rs +++ b/src/python/dft.rs @@ -37,7 +37,7 @@ pub struct PyPcSaftFunctional(pub Rc>); impl PyPcSaftFunctional { #[new] fn new(parameters: PyPcSaftParameters) -> Self { - Self(Rc::new(PcSaftFunctional::new(parameters.0.clone()))) + Self(Rc::new(PcSaftFunctional::new(parameters.0))) } /// PCP SAFT Helmholtz energy functional without simplifications @@ -57,8 +57,8 @@ impl PyPcSaftFunctional { #[pyo3(text_signature = "(parameters, fmt_version)")] fn new_full(parameters: PyPcSaftParameters, fmt_version: PyFMTVersion) -> Self { Self(Rc::new(PcSaftFunctional::new_full( - parameters.0.clone(), - fmt_version.0.clone(), + parameters.0, + fmt_version.0, ))) } } diff --git a/src/python/eos.rs b/src/python/eos.rs index e6ce8c9..50ed838 100644 --- a/src/python/eos.rs +++ b/src/python/eos.rs @@ -58,7 +58,7 @@ impl PyPcSaft { max_iter_cross_assoc, tol_cross_assoc, }; - Self(Rc::new(PcSaft::with_options(parameters.0.clone(), options))) + Self(Rc::new(PcSaft::with_options(parameters.0, options))) } } diff --git a/src/python/parameters.rs b/src/python/parameters.rs index 6e7d412..963a260 100644 --- a/src/python/parameters.rs +++ b/src/python/parameters.rs @@ -1,15 +1,15 @@ use crate::parameters::{PcSaftParameters, PcSaftRecord}; use feos_core::joback::JobackRecord; use feos_core::parameter::{ - IdentifierOption, Parameter, ParameterError, PureRecord, SegmentRecord, + BinaryRecord, IdentifierOption, Parameter, ParameterError, PureRecord, SegmentRecord, }; use feos_core::python::joback::PyJobackRecord; -use feos_core::python::parameter::{ - PyBinaryRecord, PyBinarySegmentRecord, PyChemicalRecord, PyIdentifier, -}; +use feos_core::python::parameter::{PyBinarySegmentRecord, PyChemicalRecord, PyIdentifier}; use feos_core::*; +use numpy::PyArray2; use pyo3::prelude::*; use std::convert::TryFrom; +use std::rc::Rc; /// Create a set of PC-Saft parameters from records. #[pyclass(name = "PcSaftRecord", unsendable)] @@ -84,7 +84,7 @@ impl_segment_record!(PcSaftRecord, PyPcSaftRecord, JobackRecord, PyJobackRecord) text_signature = "(pure_records, binary_records=None, substances=None, search_option='Name')" )] #[derive(Clone)] -pub struct PyPcSaftParameters(pub PcSaftParameters); +pub struct PyPcSaftParameters(pub Rc); impl_parameter!(PcSaftParameters, PyPcSaftParameters); impl_parameter_from_segments!(PcSaftParameters, PyPcSaftParameters); diff --git a/tests/critical_point.rs b/tests/critical_point.rs index a8e2a90..7072c74 100644 --- a/tests/critical_point.rs +++ b/tests/critical_point.rs @@ -15,7 +15,7 @@ fn test_critical_point_pure() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let saft = Rc::new(PcSaft::new(params)); + let saft = Rc::new(PcSaft::new(Rc::new(params))); let t = 300.0 * KELVIN; let cp = State::critical_point(&saft, None, Some(t), Default::default())?; assert_relative_eq!(cp.temperature, 375.12441 * KELVIN, max_relative = 1e-8); @@ -35,7 +35,7 @@ fn test_critical_point_mix() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let saft = Rc::new(PcSaft::new(params)); + let saft = Rc::new(PcSaft::new(Rc::new(params))); let t = 300.0 * KELVIN; let moles = arr1(&[1.5, 1.5]) * MOL; let cp = State::critical_point(&saft, Some(&moles), Some(t), Default::default())?; diff --git a/tests/dft.rs b/tests/dft.rs index f8f93e3..355e234 100644 --- a/tests/dft.rs +++ b/tests/dft.rs @@ -16,16 +16,16 @@ fn test_bulk_implementations() -> Result<(), Box> { let KB_old = 1.38064852e-23 * JOULE / KELVIN; let NAV_old = 6.022140857e23 / MOL; - let params = PcSaftParameters::from_json( + let params = Rc::new(PcSaftParameters::from_json( &["water_np"], "tests/test_parameters.json", None, IdentifierOption::Name, - )?; + )?); let eos = Rc::new(PcSaft::new(params.clone())); let func_pure = Rc::new(PcSaftFunctional::new(params.clone())); let func_full = Rc::new(PcSaftFunctional::new_full( - params.clone(), + params, FMTVersion::KierlikRosinberg, )); let t = 300.0 * KELVIN; @@ -91,12 +91,12 @@ fn test_dft_propane() -> Result<(), Box> { let KB_old = 1.38064852e-23 * JOULE / KELVIN; let NAV_old = 6.022140857e23 / MOL; - let params = PcSaftParameters::from_json( + let params = Rc::new(PcSaftParameters::from_json( &["propane"], "tests/test_parameters.json", None, IdentifierOption::Name, - )?; + )?); let func_pure = Rc::new(PcSaftFunctional::new(params.clone())); let func_full = Rc::new(PcSaftFunctional::new_full( params.clone(), @@ -215,12 +215,12 @@ fn test_dft_water() -> Result<(), Box> { let KB_old = 1.38064852e-23 * JOULE / KELVIN; let NAV_old = 6.022140857e23 / MOL; - let params = PcSaftParameters::from_json( + let params = Rc::new(PcSaftParameters::from_json( &["water_np"], "tests/test_parameters.json", None, IdentifierOption::Name, - )?; + )?); let func_pure = Rc::new(PcSaftFunctional::new(params.clone())); let func_full_vec = Rc::new(PcSaftFunctional::new_full(params, FMTVersion::WhiteBear)); let t = 400.0 * KELVIN; @@ -302,7 +302,7 @@ fn test_entropy_bulk_values() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let func = Rc::new(PcSaftFunctional::new(params)); + let func = Rc::new(PcSaftFunctional::new(Rc::new(params))); let vle = PhaseEquilibrium::pure_t(&func, 350.0 * KELVIN, None, Default::default())?; let profile = PlanarInterface::from_pdgt(&vle, 2048)?.solve(None)?; let s_res = profile.profile.entropy_density(Contributions::Residual)?; diff --git a/tests/properties.rs b/tests/properties.rs index a1b9b87..d0d2851 100644 --- a/tests/properties.rs +++ b/tests/properties.rs @@ -15,7 +15,7 @@ fn test_dln_phi_dp() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let saft = Rc::new(PcSaft::new(params)); + let saft = Rc::new(PcSaft::new(Rc::new(params))); let t = 300.0 * KELVIN; let p = BAR; let h = 1e-1 * PASCAL; @@ -48,7 +48,7 @@ fn test_virial_is_not_nan() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let saft = Rc::new(PcSaft::new(params)); + let saft = Rc::new(PcSaft::new(Rc::new(params))); let virial_b = saft.second_virial_coefficient(300.0 * KELVIN, None)?; assert!(!virial_b.is_nan()); Ok(()) diff --git a/tests/stability_analysis.rs b/tests/stability_analysis.rs index e2df778..bada090 100644 --- a/tests/stability_analysis.rs +++ b/tests/stability_analysis.rs @@ -14,7 +14,7 @@ fn test_stability_analysis() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let mix = Rc::new(PcSaft::new(params)); + let mix = Rc::new(PcSaft::new(Rc::new(params))); let unstable = State::new_npt( &mix, 300.0 * KELVIN, @@ -31,7 +31,7 @@ fn test_stability_analysis() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let mix = Rc::new(PcSaft::new(params)); + let mix = Rc::new(PcSaft::new(Rc::new(params))); let vle = PhaseEquilibrium::bubble_point_tx( &mix, 300.0 * KELVIN, diff --git a/tests/state_creation_mixture.rs b/tests/state_creation_mixture.rs index c8066bc..9bb5abb 100644 --- a/tests/state_creation_mixture.rs +++ b/tests/state_creation_mixture.rs @@ -8,13 +8,13 @@ use quantity::si::*; use std::error::Error; use std::rc::Rc; -fn propane_butane_parameters() -> Result { - PcSaftParameters::from_json( +fn propane_butane_parameters() -> Result, ParameterError> { + Ok(Rc::new(PcSaftParameters::from_json( &["propane", "butane"], "tests/test_parameters.json", None, IdentifierOption::Name, - ) + )?)) } #[test] diff --git a/tests/state_creation_pure.rs b/tests/state_creation_pure.rs index 2e861e1..98c3ad6 100644 --- a/tests/state_creation_pure.rs +++ b/tests/state_creation_pure.rs @@ -10,13 +10,13 @@ use quantity::QuantityScalar; use std::error::Error; use std::rc::Rc; -fn propane_parameters() -> Result { - PcSaftParameters::from_json( +fn propane_parameters() -> Result, ParameterError> { + Ok(Rc::new(PcSaftParameters::from_json( &["propane"], "tests/test_parameters.json", None, IdentifierOption::Name, - ) + )?)) } #[test] diff --git a/tests/tp_flash.rs b/tests/tp_flash.rs index 3c8c43d..d491569 100644 --- a/tests/tp_flash.rs +++ b/tests/tp_flash.rs @@ -7,13 +7,13 @@ use quantity::si::*; use std::error::Error; use std::rc::Rc; -fn read_params(components: &[&str]) -> Result { - PcSaftParameters::from_json( +fn read_params(components: &[&str]) -> Result, ParameterError> { + Ok(Rc::new(PcSaftParameters::from_json( components, "tests/test_parameters.json", None, IdentifierOption::Name, - ) + )?)) } #[test] diff --git a/tests/vle_pure.rs b/tests/vle_pure.rs index 417027a..727d80c 100644 --- a/tests/vle_pure.rs +++ b/tests/vle_pure.rs @@ -14,7 +14,7 @@ fn vle_pure_temperature() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let saft = Rc::new(PcSaft::new(params)); + let saft = Rc::new(PcSaft::new(Rc::new(params))); let temperatures = [ 170.0 * KELVIN, 200.0 * KELVIN, @@ -42,7 +42,7 @@ fn vle_pure_pressure() -> Result<(), Box> { None, IdentifierOption::Name, )?; - let saft = Rc::new(PcSaft::new(params)); + let saft = Rc::new(PcSaft::new(Rc::new(params))); let pressures = [0.1 * BAR, 1.0 * BAR, 10.0 * BAR, 30.0 * BAR, 44.0 * BAR]; for &p in pressures.iter() { let state = PhaseEquilibrium::pure_p(&saft, p, None, Default::default())?;