Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move StateVec to state module and fix some documentation issues
  • Loading branch information
prehner committed Mar 21, 2022
commit 453201ef4ef6c3a8f834963eab59a7aaa354fdb2
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ pub use equation_of_state::{
};
pub use errors::{EosError, EosResult};
pub use phase_equilibria::{
PhaseDiagram, PhaseDiagramHetero, PhaseEquilibrium, SolverOptions, StateVec, Verbosity,
PhaseDiagram, PhaseDiagramHetero, PhaseEquilibrium, SolverOptions, Verbosity,
};
pub use state::{Contributions, DensityInitialization, State, StateBuilder, StateHD};
pub use state::{Contributions, DensityInitialization, State, StateBuilder, StateHD, StateVec};

#[cfg(feature = "python")]
pub mod python;
Expand Down
2 changes: 1 addition & 1 deletion src/phase_equilibria/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod stability_analysis;
mod tp_flash;
mod vle_pure;
pub use phase_diagram_binary::PhaseDiagramHetero;
pub use phase_diagram_pure::{PhaseDiagram, StateVec};
pub use phase_diagram_pure::PhaseDiagram;

/// Level of detail in the iteration output.
#[derive(Copy, Clone, PartialOrd, PartialEq)]
Expand Down
2 changes: 0 additions & 2 deletions src/phase_equilibria/phase_diagram_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ impl<U: EosUnit, E: EquationOfState> PhaseDiagram<U, E> {
let mut states = Vec::with_capacity(npoints);
let tp: TPSpec<U> = temperature_or_pressure.try_into()?;

// let feed = arr1(&[x_feed, 1.0 - x_feed]) * U::reference_moles();

let tp_vec = QuantityArray1::linspace(min_tp, max_tp, npoints)?;
let mut vle = None;
for i in 0..npoints {
Expand Down
78 changes: 3 additions & 75 deletions src/phase_equilibria/phase_diagram_pure.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{PhaseEquilibrium, SolverOptions};
use crate::equation_of_state::{EquationOfState, MolarWeight};
use crate::equation_of_state::EquationOfState;
use crate::errors::EosResult;
use crate::state::{Contributions, State};
use crate::state::{State, StateVec};
use crate::EosUnit;
use ndarray::prelude::*;
use quantity::{QuantityArray1, QuantityScalar};
use quantity::QuantityScalar;
use std::rc::Rc;

/// Pure component and binary mixture phase diagrams.
Expand Down Expand Up @@ -67,75 +67,3 @@ impl<U: EosUnit, E: EquationOfState> PhaseDiagram<U, E> {
}
}
}

/// A list of states for a simple access to properties
/// of multiple states.
pub struct StateVec<'a, U, E> {
pub states: Vec<&'a State<U, E>>,
}

impl<'a, U: EosUnit, E: EquationOfState> StateVec<'a, U, E> {
pub fn temperature(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| self.states[i].temperature)
}

pub fn pressure(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].pressure(Contributions::Total)
})
}

pub fn compressibility(&self) -> Array1<f64> {
Array1::from_shape_fn(self.states.len(), |i| {
self.states[i].compressibility(Contributions::Total)
})
}

pub fn density(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| self.states[i].density)
}

pub fn molefracs(&self) -> Array2<f64> {
Array2::from_shape_fn(
(self.states.len(), self.states[0].eos.components()),
|(i, j)| self.states[i].molefracs[j],
)
}

pub fn molar_enthalpy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].molar_enthalpy(Contributions::Total)
})
}

pub fn molar_entropy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].molar_entropy(Contributions::Total)
})
}
}

impl<'a, U: EosUnit, E: EquationOfState + MolarWeight<U>> StateVec<'a, U, E> {
pub fn mass_density(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| self.states[i].mass_density())
}

pub fn massfracs(&self) -> Array2<f64> {
Array2::from_shape_fn(
(self.states.len(), self.states[0].eos.components()),
|(i, j)| self.states[i].massfracs()[j],
)
}

pub fn specific_enthalpy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].specific_enthalpy(Contributions::Total)
})
}

pub fn specific_entropy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].specific_entropy(Contributions::Total)
})
}
}
2 changes: 1 addition & 1 deletion src/phase_equilibria/vle_pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl<U: EosUnit, E: EquationOfState> PhaseEquilibrium<U, E, 2> {
}

/// Calculate the pure component phase equilibria of all
/// components in the system for the given temperature.
/// components in the system.
pub fn vle_pure_comps(
eos: &Rc<E>,
temperature_or_pressure: QuantityScalar<U>,
Expand Down
36 changes: 18 additions & 18 deletions src/python/phase_equilibria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure : SINumber
/// The system temperature or pressure.
/// initial_state : PhaseEquilibrium, optional
Expand Down Expand Up @@ -60,8 +60,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature : SINumber
/// The system temperature.
/// pressure : SINumber
Expand Down Expand Up @@ -114,8 +114,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure : SINumber
/// The system temperature_or_pressure.
/// liquid_molefracs : numpy.ndarray
Expand Down Expand Up @@ -173,8 +173,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure : SINumber
/// The system temperature or pressure.
/// vapor_molefracs : numpy.ndarray
Expand Down Expand Up @@ -257,8 +257,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure : SINumber
/// The system temperature or pressure.
///
Expand All @@ -279,8 +279,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature : SINumber
/// The system temperature.
///
Expand All @@ -301,8 +301,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// pressure : SINumber
/// The system pressure.
///
Expand Down Expand Up @@ -339,8 +339,8 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos : Saft
/// The SAFT equation of state.
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure : SINumber
/// The system temperature or pressure.
/// x_init : list[float]
Expand Down Expand Up @@ -558,7 +558,7 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos: $eos
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure: SINumber
/// The constant temperature or pressure.
Expand Down Expand Up @@ -616,7 +616,7 @@ macro_rules! impl_phase_equilibrium {
///
/// Parameters
/// ----------
/// eos: $eos
/// eos : $py_eos
/// The equation of state.
/// temperature_or_pressure: SINumber
/// The consant temperature or pressure.
Expand Down
2 changes: 1 addition & 1 deletion src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod builder;
mod cache;
mod properties;
pub use builder::StateBuilder;
pub use properties::Contributions;
pub use properties::{Contributions, StateVec};

/// Initial values in a density iteration.
#[derive(Clone, Copy)]
Expand Down
72 changes: 72 additions & 0 deletions src/state/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,75 @@ impl<U: EosUnit, E: EquationOfState + EntropyScaling<U>> State<U, E> {
.thermal_conductivity_reference(self.temperature, self.volume, &self.moles)
}
}

/// A list of states for a simple access to properties
/// of multiple states.
pub struct StateVec<'a, U, E> {
pub states: Vec<&'a State<U, E>>,
}

impl<'a, U: EosUnit, E: EquationOfState> StateVec<'a, U, E> {
pub fn temperature(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| self.states[i].temperature)
}

pub fn pressure(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].pressure(Contributions::Total)
})
}

pub fn compressibility(&self) -> Array1<f64> {
Array1::from_shape_fn(self.states.len(), |i| {
self.states[i].compressibility(Contributions::Total)
})
}

pub fn density(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| self.states[i].density)
}

pub fn molefracs(&self) -> Array2<f64> {
Array2::from_shape_fn(
(self.states.len(), self.states[0].eos.components()),
|(i, j)| self.states[i].molefracs[j],
)
}

pub fn molar_enthalpy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].molar_enthalpy(Contributions::Total)
})
}

pub fn molar_entropy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].molar_entropy(Contributions::Total)
})
}
}

impl<'a, U: EosUnit, E: EquationOfState + MolarWeight<U>> StateVec<'a, U, E> {
pub fn mass_density(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| self.states[i].mass_density())
}

pub fn massfracs(&self) -> Array2<f64> {
Array2::from_shape_fn(
(self.states.len(), self.states[0].eos.components()),
|(i, j)| self.states[i].massfracs()[j],
)
}

pub fn specific_enthalpy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].specific_enthalpy(Contributions::Total)
})
}

pub fn specific_entropy(&self) -> QuantityArray1<U> {
QuantityArray1::from_shape_fn(self.states.len(), |i| {
self.states[i].specific_entropy(Contributions::Total)
})
}
}