From 05570c6ee5ebe3796984b88a8aa55bf1e32134b8 Mon Sep 17 00:00:00 2001 From: Philipp Rehner Date: Tue, 27 Feb 2024 14:06:38 +0100 Subject: [PATCH 1/3] Enforce total_moles when providing molefracs that do not add up to 1 --- feos-core/src/state/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feos-core/src/state/mod.rs b/feos-core/src/state/mod.rs index ef8994564..3d52cd494 100644 --- a/feos-core/src/state/mod.rs +++ b/feos-core/src/state/mod.rs @@ -383,7 +383,7 @@ impl State { if let (None, None) = (volume, n) { n = Some(Moles::from_reduced(1.0)) } - let n_i = n.map(|n| &x_u * n); + let n_i = n.map(|n| &x_u * n / x_u.sum()); let v = volume.or_else(|| rho.and_then(|d| n.map(|n| n / d))); // check if new state can be created using default constructor @@ -392,6 +392,7 @@ impl State { } // Check if new state can be created using density iteration + println!("{:?} {:?} {:?}", pressure, temperature, n_i); if let (Some(p), Some(t), Some(n_i)) = (pressure, temperature, &n_i) { return Ok(Ok(State::new_npt(eos, t, p, n_i, density_initialization)?)); } From 0cd91338cb4fdf169f998345f4dd4e89e41be9b8 Mon Sep 17 00:00:00 2001 From: Philipp Rehner Date: Tue, 27 Feb 2024 14:13:03 +0100 Subject: [PATCH 2/3] add changelog --- feos-core/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/feos-core/CHANGELOG.md b/feos-core/CHANGELOG.md index 0c7542f8a..c5bb22e25 100644 --- a/feos-core/CHANGELOG.md +++ b/feos-core/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Added comparison for pressures of both phases in `PyPhaseDiagram.to_dict` to make the method work with `spinodal` constructor. [#224](https://github.com/feos-org/feos/pull/224) +- Enforce the total moles when providing `State::new` with molefracs that do not add up to 1. [#227](https://github.com/feos-org/feos/pull/227) ## [0.6.1] 2024-01-11 From 3a292f5484a0983af441ee4949f3d40116a20708 Mon Sep 17 00:00:00 2001 From: Philipp Rehner Date: Tue, 27 Feb 2024 14:13:31 +0100 Subject: [PATCH 3/3] remove print --- feos-core/src/state/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/feos-core/src/state/mod.rs b/feos-core/src/state/mod.rs index 3d52cd494..e853b0d44 100644 --- a/feos-core/src/state/mod.rs +++ b/feos-core/src/state/mod.rs @@ -392,7 +392,6 @@ impl State { } // Check if new state can be created using density iteration - println!("{:?} {:?} {:?}", pressure, temperature, n_i); if let (Some(p), Some(t), Some(n_i)) = (pressure, temperature, &n_i) { return Ok(Ok(State::new_npt(eos, t, p, n_i, density_initialization)?)); }