Skip to content

Commit 5e6025c

Browse files
authored
added solver options to vapor pressure and equilibrium datasets (#41)
1 parent 9b2d464 commit 5e6025c

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

src/estimator/liquid_density.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,22 @@ pub struct EquilibriumLiquidDensity<U: EosUnit> {
105105
pub target: QuantityArray1<U>,
106106
temperature: QuantityArray1<U>,
107107
datapoints: usize,
108+
solver_options: SolverOptions,
108109
}
109110

110111
impl<U: EosUnit> EquilibriumLiquidDensity<U> {
111112
/// A new data set for liquid densities with pressures and temperatures as input.
112113
pub fn new(
113114
target: QuantityArray1<U>,
114115
temperature: QuantityArray1<U>,
116+
vle_options: Option<SolverOptions>,
115117
) -> Result<Self, EstimatorError> {
116118
let datapoints = target.len();
117119
Ok(Self {
118120
target,
119121
temperature,
120122
datapoints,
123+
solver_options: vle_options.unwrap_or_default(),
121124
})
122125
}
123126

@@ -151,7 +154,7 @@ impl<U: EosUnit, E: EquationOfState + MolarWeight<U>> DataSet<U, E>
151154
let mut prediction = Array1::zeros(self.datapoints) * unit;
152155
for i in 0..self.datapoints {
153156
let t = self.temperature.get(i);
154-
if let Ok(state) = PhaseEquilibrium::pure(eos, t, None, SolverOptions::default()) {
157+
if let Ok(state) = PhaseEquilibrium::pure(eos, t, None, self.solver_options) {
155158
prediction.try_set(i, state.liquid().mass_density())?;
156159
} else {
157160
prediction.try_set(i, f64::NAN * U::reference_mass() / U::reference_volume())?

src/estimator/python.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,16 @@ macro_rules! impl_estimator {
221221
/// Use Antoine type equation to extrapolate vapor
222222
/// pressure if experimental data is above critial
223223
/// point of model. Defaults to False.
224-
///
224+
/// max_iter : int, optional
225+
/// The maximum number of iterations for critical point
226+
/// and VLE algorithms.
227+
/// tol: float, optional
228+
/// Solution tolerance for critical point
229+
/// and VLE algorithms.
230+
/// verbosity : Verbosity, optional
231+
/// Verbosity for critical point
232+
/// and VLE algorithms.
233+
///
225234
/// Returns
226235
/// -------
227236
/// ``DataSet``
@@ -231,11 +240,15 @@ macro_rules! impl_estimator {
231240
target: &PySIArray1,
232241
temperature: &PySIArray1,
233242
extrapolate: Option<bool>,
243+
max_iter: Option<usize>,
244+
tol: Option<f64>,
245+
verbosity: Option<Verbosity>,
234246
) -> PyResult<Self> {
235247
Ok(Self(Rc::new(VaporPressure::<SIUnit>::new(
236248
target.clone().into(),
237249
temperature.clone().into(),
238250
extrapolate.unwrap_or(false),
251+
Some((max_iter, tol, verbosity).into()),
239252
)?)))
240253
}
241254

@@ -276,6 +289,15 @@ macro_rules! impl_estimator {
276289
/// Experimental data for liquid density.
277290
/// temperature : SIArray1
278291
/// Temperature for experimental data points.
292+
/// max_iter : int, optional
293+
/// The maximum number of iterations for critical point
294+
/// and VLE algorithms.
295+
/// tol: float, optional
296+
/// Solution tolerance for critical point
297+
/// and VLE algorithms.
298+
/// verbosity : Verbosity, optional
299+
/// Verbosity for critical point
300+
/// and VLE algorithms.
279301
///
280302
/// Returns
281303
/// -------
@@ -285,10 +307,14 @@ macro_rules! impl_estimator {
285307
fn equilibrium_liquid_density(
286308
target: &PySIArray1,
287309
temperature: &PySIArray1,
310+
max_iter: Option<usize>,
311+
tol: Option<f64>,
312+
verbosity: Option<Verbosity>,
288313
) -> PyResult<Self> {
289314
Ok(Self(Rc::new(EquilibriumLiquidDensity::<SIUnit>::new(
290315
target.clone().into(),
291316
temperature.clone().into(),
317+
Some((max_iter, tol, verbosity).into())
292318
)?)))
293319
}
294320

src/estimator/vapor_pressure.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct VaporPressure<U: EosUnit> {
1313
max_temperature: QuantityScalar<U>,
1414
datapoints: usize,
1515
extrapolate: bool,
16+
solver_options: SolverOptions,
1617
}
1718

1819
impl<U: EosUnit> VaporPressure<U> {
@@ -28,6 +29,7 @@ impl<U: EosUnit> VaporPressure<U> {
2829
target: QuantityArray1<U>,
2930
temperature: QuantityArray1<U>,
3031
extrapolate: bool,
32+
solver_options: Option<SolverOptions>,
3133
) -> Result<Self, EstimatorError> {
3234
let datapoints = target.len();
3335
let max_temperature = temperature
@@ -42,6 +44,7 @@ impl<U: EosUnit> VaporPressure<U> {
4244
max_temperature,
4345
datapoints,
4446
extrapolate,
47+
solver_options: solver_options.unwrap_or_default(),
4548
})
4649
}
4750

@@ -68,17 +71,13 @@ impl<U: EosUnit, E: EquationOfState> DataSet<U, E> for VaporPressure<U> {
6871
where
6972
QuantityScalar<U>: std::fmt::Display + std::fmt::LowerExp,
7073
{
71-
let critical_point = State::critical_point(
72-
eos,
73-
None,
74-
Some(self.max_temperature),
75-
SolverOptions::default(),
76-
)?;
74+
let critical_point =
75+
State::critical_point(eos, None, Some(self.max_temperature), self.solver_options)?;
7776
let tc = critical_point.temperature;
7877
let pc = critical_point.pressure(Contributions::Total);
7978

8079
let t0 = 0.9 * tc;
81-
let p0 = PhaseEquilibrium::pure(eos, t0, None, SolverOptions::default())?
80+
let p0 = PhaseEquilibrium::pure(eos, t0, None, self.solver_options)?
8281
.vapor()
8382
.pressure(Contributions::Total);
8483

0 commit comments

Comments
 (0)