Skip to content

Commit

Permalink
Add binary datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner committed Aug 7, 2023
1 parent f5f662d commit 7e24294
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 211 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pets = []
saftvrqmie = []
rayon = ["dep:rayon", "ndarray/rayon", "feos-core/rayon", "feos-dft?/rayon"]
python = ["pyo3", "numpy", "quantity/python", "feos-core/python", "feos-dft?/python", "rayon"]
all_models = ["dft", "pcsaft", "gc_pcsaft", "uvtheory", "pets", "saftvrqmie"]
all_models = ["dft", "estimator", "pcsaft", "gc_pcsaft", "uvtheory", "pets", "saftvrqmie"]

[[bench]]
name = "state_properties"
Expand Down
22 changes: 8 additions & 14 deletions feos-core/src/phase_equilibria/bubble_dew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ pub trait TemperatureOrPressure: Copy {

fn temperature_pressure(&self, tp_init: Self::Other) -> (Temperature<f64>, Pressure<f64>);

fn pressure_temperature<E: Residual>(state: &State<E>) -> Self::Other;
fn from_state<E: Residual>(state: &State<E>) -> Self::Other;

fn linspace(
&self,
start: Self::Other,
end: Self::Other,
n: usize,
) -> (Temperature<Array1<f64>>, Pressure<Array1<f64>>);
}

pub trait BubbleDewSpecification: TemperatureOrPressure {
fn bubble_dew_point<E: Residual>(
eos: &Arc<E>,
tp_spec: Self,
Expand Down Expand Up @@ -76,7 +74,7 @@ impl TemperatureOrPressure for Temperature<f64> {
(*self, tp_init)
}

fn pressure_temperature<E: Residual>(state: &State<E>) -> Self::Other {
fn from_state<E: Residual>(state: &State<E>) -> Self::Other {
state.pressure(Contributions::Total)
}

Expand All @@ -91,9 +89,7 @@ impl TemperatureOrPressure for Temperature<f64> {
Pressure::linspace(start, end, n),
)
}
}

impl BubbleDewSpecification for Temperature<f64> {
fn bubble_dew_point<E: Residual>(
eos: &Arc<E>,
temperature: Self,
Expand Down Expand Up @@ -270,7 +266,7 @@ impl TemperatureOrPressure for Quantity<f64, SIUnit<N2, N1, P1, Z0, Z0, Z0, Z0>>
(tp_init, *self)
}

fn pressure_temperature<E: Residual>(state: &State<E>) -> Self::Other {
fn from_state<E: Residual>(state: &State<E>) -> Self::Other {
state.temperature
}

Expand All @@ -285,9 +281,7 @@ impl TemperatureOrPressure for Quantity<f64, SIUnit<N2, N1, P1, Z0, Z0, Z0, Z0>>
Pressure::linspace(*self, *self, n),
)
}
}

impl BubbleDewSpecification for Quantity<f64, SIUnit<N2, N1, P1, Z0, Z0, Z0, Z0>> {
fn bubble_dew_point<E: Residual>(
eos: &Arc<E>,
pressure: Self,
Expand Down Expand Up @@ -451,7 +445,7 @@ impl BubbleDewSpecification for Quantity<f64, SIUnit<N2, N1, P1, Z0, Z0, Z0, Z0>
impl<E: Residual> PhaseEquilibrium<E, 2> {
/// Calculate a phase equilibrium for a given temperature
/// or pressure and composition of the liquid phase.
pub fn bubble_point<TP: BubbleDewSpecification>(
pub fn bubble_point<TP: TemperatureOrPressure>(
eos: &Arc<E>,
temperature_or_pressure: TP,
liquid_molefracs: &Array1<f64>,
Expand All @@ -472,7 +466,7 @@ impl<E: Residual> PhaseEquilibrium<E, 2> {

/// Calculate a phase equilibrium for a given temperature
/// or pressure and composition of the vapor phase.
pub fn dew_point<TP: BubbleDewSpecification>(
pub fn dew_point<TP: TemperatureOrPressure>(
eos: &Arc<E>,
temperature_or_pressure: TP,
vapor_molefracs: &Array1<f64>,
Expand All @@ -491,7 +485,7 @@ impl<E: Residual> PhaseEquilibrium<E, 2> {
)
}

pub(super) fn bubble_dew_point<TP: BubbleDewSpecification>(
pub(super) fn bubble_dew_point<TP: TemperatureOrPressure>(
eos: &Arc<E>,
tp_spec: TP,
tp_init: Option<TP::Other>,
Expand All @@ -511,7 +505,7 @@ impl<E: Residual> PhaseEquilibrium<E, 2> {
)
}

fn iterate_bubble_dew<TP: BubbleDewSpecification>(
fn iterate_bubble_dew<TP: TemperatureOrPressure>(
eos: &Arc<E>,
tp_spec: TP,
tp_init: TP::Other,
Expand Down Expand Up @@ -659,7 +653,7 @@ fn starting_x2_dew<E: Residual>(
Ok([vapor_state, liquid_state])
}

fn bubble_dew<E: Residual, TP: BubbleDewSpecification>(
fn bubble_dew<E: Residual, TP: TemperatureOrPressure>(
tp_spec: TP,
mut var_tp: TP::Other,
mut state1: State<E>,
Expand Down
16 changes: 8 additions & 8 deletions feos-core/src/phase_equilibria/phase_diagram_binary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::bubble_dew::{BubbleDewSpecification, TemperatureOrPressure};
use super::bubble_dew::TemperatureOrPressure;
use super::{PhaseDiagram, PhaseEquilibrium};
use crate::equation_of_state::Residual;
use crate::errors::{EosError, EosResult};
Expand All @@ -18,7 +18,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
/// If a heteroazeotrope occurs and the composition of the liquid
/// phases are known, they can be passed as `x_lle` to avoid
/// the calculation of unstable branches.
pub fn binary_vle<TP: BubbleDewSpecification>(
pub fn binary_vle<TP: TemperatureOrPressure>(
eos: &Arc<E>,
temperature_or_pressure: TP,
npoints: Option<usize>,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
}

#[allow(clippy::type_complexity)]
fn calculate_vlle<TP: BubbleDewSpecification>(
fn calculate_vlle<TP: TemperatureOrPressure>(
eos: &Arc<E>,
tp: TP,
npoints: usize,
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
}
}

fn iterate_vle<E: Residual, TP: BubbleDewSpecification>(
fn iterate_vle<E: Residual, TP: TemperatureOrPressure>(
eos: &Arc<E>,
tp: TP,
x_lim: &[f64],
Expand All @@ -197,7 +197,7 @@ fn iterate_vle<E: Residual, TP: BubbleDewSpecification>(
x.slice(s![1..])
};

let tp_0 = Some(TP::pressure_temperature(vle_0.vapor()));
let tp_0 = Some(TP::from_state(vle_0.vapor()));
let mut tp_old = tp_0;
let mut y_old = None;
vle_vec.push(vle_0);
Expand All @@ -218,7 +218,7 @@ fn iterate_vle<E: Residual, TP: BubbleDewSpecification>(
} else {
vle.liquid().molefracs.clone()
});
tp_old = Some(TP::pressure_temperature(vle.vapor()));
tp_old = Some(TP::from_state(vle.vapor()));
vle_vec.push(vle.clone());
} else {
y_old = None;
Expand All @@ -245,7 +245,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
///
/// The `x_lle` parameter is used as initial values for the calculation
/// of the heteroazeotrope.
pub fn binary_vlle<TP: BubbleDewSpecification>(
pub fn binary_vlle<TP: TemperatureOrPressure>(
eos: &Arc<E>,
temperature_or_pressure: TP,
x_lle: (f64, f64),
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
// calculate liquid liquid equilibrium
let lle = tp_lim_lle
.map(|tp_lim| {
let tp_hetero = TP::pressure_temperature(vlle.vapor());
let tp_hetero = TP::from_state(vlle.vapor());
let x_feed = 0.5 * (x_hetero.0 + x_hetero.1);
let feed = Moles::from_reduced(arr1(&[x_feed, 1.0 - x_feed]));
PhaseDiagram::lle(
Expand Down
Loading

0 comments on commit 7e24294

Please sign in to comment.