From 1c843780dd04fcf08c47161779f78762984acdf6 Mon Sep 17 00:00:00 2001 From: Philipp Rehner Date: Thu, 25 Aug 2022 14:39:35 +0200 Subject: [PATCH] Avoid calling bubble_point_p without initial temperature within phase diagram calculation --- feos-core/CHANGELOG.md | 1 + feos-core/src/parameter/mod.rs | 1 + feos-core/src/phase_equilibria/phase_diagram_binary.rs | 5 +++-- feos-core/src/state/critical_point.rs | 7 +++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/feos-core/CHANGELOG.md b/feos-core/CHANGELOG.md index 4bcf2ec2a..eeea6e84a 100644 --- a/feos-core/CHANGELOG.md +++ b/feos-core/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Made binary parameters in `from_records` Python routine an `Option`. [#35](https://github.com/feos-org/feos/pull/35) - Added panic with message when parsing missing Identifiers variants. [#35](https://github.com/feos-org/feos/pull/35) - Generalized the initialization routines for pure component VLEs at given temperature to multicomponent systems. [#23](https://github.com/feos-org/feos/pull/23) +- Increased the default number of maximum iterations for binary critical point calculations from 50 to 200. [#47](https://github.com/feos-org/feos/pull/47) ### Removed - Removed the (internal) `SpinodalPoint` struct that was used within density iterations in favor of a simpler interface. [#23](https://github.com/feos-org/feos/pull/23) diff --git a/feos-core/src/parameter/mod.rs b/feos-core/src/parameter/mod.rs index 2df800c86..f592b214f 100644 --- a/feos-core/src/parameter/mod.rs +++ b/feos-core/src/parameter/mod.rs @@ -74,6 +74,7 @@ where /// /// If the identifiers in `binary_records` are not a subset of those in /// `pure_records`, the `Default` implementation of Self::Binary is used. + #[allow(clippy::expect_fun_call)] fn binary_matrix_from_records( pure_records: &Vec>, binary_records: &[BinaryRecord], diff --git a/feos-core/src/phase_equilibria/phase_diagram_binary.rs b/feos-core/src/phase_equilibria/phase_diagram_binary.rs index c158b87e0..eb865192e 100644 --- a/feos-core/src/phase_equilibria/phase_diagram_binary.rs +++ b/feos-core/src/phase_equilibria/phase_diagram_binary.rs @@ -205,7 +205,8 @@ where x.slice(s![1..]) }; - let mut tp_old = Some(vle_0.vapor().tp(tp)); + let tp_0 = Some(vle_0.vapor().tp(tp)); + let mut tp_old = tp_0; let mut y_old = None; vle_vec.push(vle_0); for xi in x { @@ -232,7 +233,7 @@ where vle_vec.push(vle.clone()); } else { y_old = None; - tp_old = None; + tp_old = tp_0; } } if let Some(vle_1) = vle_1 { diff --git a/feos-core/src/state/critical_point.rs b/feos-core/src/state/critical_point.rs index fd875e56d..34f01d8a3 100644 --- a/feos-core/src/state/critical_point.rs +++ b/feos-core/src/state/critical_point.rs @@ -12,6 +12,7 @@ use std::convert::TryFrom; use std::rc::Rc; const MAX_ITER_CRIT_POINT: usize = 50; +const MAX_ITER_CRIT_POINT_BINARY: usize = 200; const TOL_CRIT_POINT: f64 = 1e-8; /// # Critical points @@ -185,7 +186,8 @@ impl State { where QuantityScalar: std::fmt::Display, { - let (max_iter, tol, verbosity) = options.unwrap_or(MAX_ITER_CRIT_POINT, TOL_CRIT_POINT); + let (max_iter, tol, verbosity) = + options.unwrap_or(MAX_ITER_CRIT_POINT_BINARY, TOL_CRIT_POINT); let t = temperature.to_reduced(U::reference_temperature())?; let x = StaticVec::new_vec(initial_molefracs.unwrap_or([0.5, 0.5])); @@ -271,7 +273,8 @@ impl State { where QuantityScalar: std::fmt::Display, { - let (max_iter, tol, verbosity) = options.unwrap_or(MAX_ITER_CRIT_POINT, TOL_CRIT_POINT); + let (max_iter, tol, verbosity) = + options.unwrap_or(MAX_ITER_CRIT_POINT_BINARY, TOL_CRIT_POINT); let p = pressure.to_reduced(U::reference_pressure())?; let mut t = initial_temperature