Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.

Commit 0b00458

Browse files
authored
Use vapor_pressure method in dataset/estimator (#27)
* Use vapor_pressure method in dataset/estimator * Remove Python object and py lifetime
1 parent 2ed2d5c commit 0b00458

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

src/python/utils.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,27 @@ macro_rules! impl_estimator {
296296
Ok(self.0.cost(&eos.0)?.view().to_pyarray(py))
297297
}
298298

299+
/// Return the properties as computed by the
300+
/// equation of state for each `DataSet`.
301+
///
302+
/// Parameters
303+
/// ----------
304+
/// eos : PyEos
305+
/// The equation of state that is used.
306+
///
307+
/// Returns
308+
/// -------
309+
/// List[SIArray1]
310+
#[pyo3(text_signature = "($self, eos)")]
311+
fn predict(&self, eos: &$py_eos) -> PyResult<Vec<PySIArray1>> {
312+
Ok(self
313+
.0
314+
.predict(&eos.0)?
315+
.iter()
316+
.map(|d| PySIArray1(d))
317+
.collect())
318+
}
319+
299320
/// Return the relative difference between experimental data
300321
/// and prediction of the equation of state for each ``DataSet``.
301322
///

src/utils/dataset.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! other models.
55
use crate::equation_of_state::{EquationOfState, MolarWeight};
66
use crate::phase_equilibria::{PhaseEquilibrium, VLEOptions};
7-
use crate::state::{Contributions, DensityInitialization, State};
7+
use crate::state::{DensityInitialization, State};
88
use crate::utils::estimator::FitError;
99
use crate::EosUnit;
1010
use ndarray::{arr1, Array1};
@@ -157,21 +157,11 @@ impl<U: EosUnit, E: EquationOfState> DataSet<U, E> for VaporPressure<U> {
157157
for i in 0..self.datapoints {
158158
let t = self.temperature.get(i);
159159
if t < tc {
160-
let state = PhaseEquilibrium::pure_t(
161-
eos,
162-
self.temperature.get(i),
163-
None,
164-
VLEOptions::default(),
165-
);
166-
if let Ok(s) = state {
167-
prediction
168-
.try_set(i, s.liquid().pressure(Contributions::Total))
169-
.unwrap();
160+
if let Some(pvap) =
161+
PhaseEquilibrium::vapor_pressure(eos, self.temperature.get(i))[0]
162+
{
163+
prediction.try_set(i, pvap).unwrap();
170164
} else {
171-
println!(
172-
"Failed to compute vapor pressure, T = {}",
173-
self.temperature.get(i)
174-
);
175165
prediction.try_set(i, f64::NAN * unit).unwrap();
176166
}
177167
} else {

src/utils/estimator.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::dataset::*;
44
use crate::equation_of_state::EquationOfState;
55
use crate::EosUnit;
66
use ndarray::{arr1, concatenate, Array1, ArrayView1, Axis};
7-
use quantity::{QuantityError, QuantityScalar};
7+
use quantity::{QuantityArray1, QuantityError, QuantityScalar};
88
use std::fmt;
99
use std::fmt::Write;
1010
use std::num::ParseFloatError;
@@ -74,6 +74,11 @@ where
7474
}
7575
}
7676

77+
/// Returns the properties as computed by the equation of state for each `DataSet`.
78+
pub fn predict(&self, eos: &Rc<E>) -> Result<Vec<QuantityArray1<U>>, FitError> {
79+
self.data.iter().map(|d| d.predict(eos)).collect()
80+
}
81+
7782
/// Returns the relative difference for each `DataSet`.
7883
pub fn relative_difference(&self, eos: &Rc<E>) -> Result<Vec<Array1<f64>>, FitError> {
7984
self.data

0 commit comments

Comments
 (0)