From 1054d731f73ba92ded81ae262adbebd15587b946 Mon Sep 17 00:00:00 2001 From: Gernot Bauer Date: Fri, 27 Jan 2023 12:16:39 +0100 Subject: [PATCH 1/2] early return if vapor pressure data set is empty --- CHANGELOG.md | 1 + src/estimator/vapor_pressure.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c81da85d5..1feb3e2df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed incorrect indexing that lead to panics in the polar contribution of gc-PC-SAFT. [#104](https://github.com/feos-org/feos/pull/104) +- `VaporPressure` now returns an empty array instead of crashing. [#124](https://github.com/feos-org/feos/pull/124) ## [0.3.0] - 2022-09-14 - Major restructuring of the entire `feos` project. All individual models are reunited in the `feos` crate. `feos-core` and `feos-dft` still live as individual crates within the `feos` workspace. diff --git a/src/estimator/vapor_pressure.rs b/src/estimator/vapor_pressure.rs index 25168355d..8a1a73fa3 100644 --- a/src/estimator/vapor_pressure.rs +++ b/src/estimator/vapor_pressure.rs @@ -71,6 +71,10 @@ impl DataSet for VaporPressure { } fn predict(&self, eos: &Arc) -> Result { + if self.datapoints == 0 { + return Ok(arr1(&[]) * SIUnit::reference_pressure()) + } + let critical_point = State::critical_point(eos, None, Some(self.max_temperature), self.solver_options) .or_else(|_| State::critical_point(eos, None, None, self.solver_options))?; From 03cca901abf8c1b030254aca5cf0f8506b53c010 Mon Sep 17 00:00:00 2001 From: Gernot Bauer Date: Fri, 27 Jan 2023 12:29:22 +0100 Subject: [PATCH 2/2] add missing import --- src/estimator/vapor_pressure.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/estimator/vapor_pressure.rs b/src/estimator/vapor_pressure.rs index 8a1a73fa3..19d9e2fb7 100644 --- a/src/estimator/vapor_pressure.rs +++ b/src/estimator/vapor_pressure.rs @@ -1,6 +1,6 @@ use super::{DataSet, EstimatorError}; use feos_core::{Contributions, EosUnit, EquationOfState, PhaseEquilibrium, SolverOptions, State}; -use ndarray::Array1; +use ndarray::{arr1, Array1}; use quantity::si::{SIArray1, SINumber, SIUnit}; use std::collections::HashMap; use std::sync::Arc; @@ -72,7 +72,7 @@ impl DataSet for VaporPressure { fn predict(&self, eos: &Arc) -> Result { if self.datapoints == 0 { - return Ok(arr1(&[]) * SIUnit::reference_pressure()) + return Ok(arr1(&[]) * SIUnit::reference_pressure()); } let critical_point =