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 all commits
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
10 changes: 1 addition & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ authors = ["Gernot Bauer <bauer@itt.uni-stuttgart.de>",
"Philipp Rehner <rehner@itt.uni-stuttgart.de"]
edition = "2018"

[lib]
name = "feos_core"
crate-type = ["rlib", "cdylib"]

[dependencies]
quantity = { version = "0.3", features = ["linalg"] }
approx = "0.4"
Expand All @@ -24,11 +20,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
indexmap = "1.7"
numpy = { version = "0.14", optional = true }

[dependencies.pyo3]
version = "0.14"
features = ["extension-module", "abi3", "abi3-py36"]
optional = true
pyo3 = { version = "0.14", optional = true }

[features]
default = []
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ Add this to your `Cargo.toml`
[dependencies]
feos-core = "0.1.0"
```

## Test building python wheel

From within a Python virtual environment with `maturin` installed, type

```
maturin build --release --out dist --no-sdist -m build_wheel/Cargo.toml
```
17 changes: 17 additions & 0 deletions build_wheel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "feos_core"
version = "0.1.0"
authors = ["Gernot Bauer <bauer@itt.uni-stuttgart.de>",
"Philipp Rehner <rehner@itt.uni-stuttgart.de"]
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
feos-core = { path = "..", features = ["python", "openblas-static"] }

[dependencies.pyo3]
version = "0.14"
features = ["extension-module", "abi3", "abi3-py36"]

7 changes: 7 additions & 0 deletions build_wheel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use feos_core::python::feos_core;
use pyo3::prelude::*;

#[pymodule]
pub fn build_wheel(py: Python<'_>, m: &PyModule) -> PyResult<()> {
feos_core(py, m)
}
2 changes: 1 addition & 1 deletion src/joback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::fmt;
///
/// Contains an additional fourth order polynomial coefficient `e`
/// which is not used in the original publication but is used in
/// parametrizations for additional molecules in other publications.
/// parametrization for additional molecules in other publications.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct JobackRecord {
a: f64,
Expand Down
20 changes: 18 additions & 2 deletions src/python/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use std::collections::HashMap;
use std::convert::TryFrom;
use std::rc::Rc;


/// A pure substance parameter for the Peng-Robinson equation of state.
#[pyclass(name = "PengRobinsonRecord", unsendable)]
#[derive(Clone)]
pub struct PyPengRobinsonRecord(PengRobinsonRecord);
Expand All @@ -40,14 +42,18 @@ impl_pure_record!(
/// ----------
/// pure_records : List[PureRecord]
/// pure substance records.
/// binary_records : List[BinarySubstanceRecord], optional
/// binary_records : List[BinaryRecord], optional
/// binary parameter records
/// substances : List[str], optional
/// The substances to use. Filters substances from `pure_records` according to
/// `search_option`.
/// When not provided, all entries of `pure_records` are used.
/// search_option : {'Name', 'Cas', 'Inchi', 'IupacName', 'Formula', 'Smiles'}, optional, defaults to 'Name'.
/// Identifier that is used to search substance.
///
/// Returns
/// -------
/// PengRobinsonParameters
#[pyclass(name = "PengRobinsonParameters", unsendable)]
#[pyo3(
text_signature = "(pure_records, binary_records=None, substances=None, search_option='Name')"
Expand All @@ -59,9 +65,19 @@ impl_parameter!(PengRobinsonParameters, PyPengRobinsonParameters);

/* EQUATION OF STATE */

/// A simple version of the Peng-Robinson equation of state.
///
/// Parameters
/// ----------
/// parameters : PengRobinsonParameters
/// The parameters of the Peng-Robinson equation of state to use.
///
/// Returns
/// -------
/// PengRobinson
#[pyclass(name = "PengRobinson", unsendable)]
#[pyo3(
text_signature = "(parameters, max_eta, max_iter_cross_assoc, tol_cross_assoc, joback_parameters)"
text_signature = "(parameters)"
)]
#[derive(Clone)]
pub struct PyPengRobinson(pub Rc<PengRobinson>);
Expand Down
12 changes: 6 additions & 6 deletions src/python/joback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ use pyo3::prelude::*;
/// The fourth order coefficient `e` is not present in the
/// orginial publication by Joback and Reid but is required
/// for correlations for some pure components that are modeled
/// using the samen polynomial approach.
/// using the same polynomial approach.
///
/// Parameters
/// ----------
/// a : float
/// zeroth order coefficint
/// zeroth order coefficient
/// b : float
/// first order coefficint
/// first order coefficient
/// c : float
/// second order coefficint
/// second order coefficient
/// d : float
/// third order coefficint
/// third order coefficient
/// e : float
/// fourth order coefficint
/// fourth order coefficient
///
/// Returns
/// -------
Expand Down
7 changes: 0 additions & 7 deletions src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ mod user_defined;
mod utils;

pub use cubic::PyInit_cubic;
use joback::PyJobackRecord;
use parameter::{PyChemicalRecord, PyIdentifier};
pub use user_defined::PyInit_user_defined;

/// Helmholtz energy contributions to consider
Expand Down Expand Up @@ -102,11 +100,6 @@ impl From<EosError> for PyErr {

#[pymodule]
pub fn feos_core(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyIdentifier>()?;
m.add_class::<PyVerbosity>()?;
m.add_class::<PyContributions>()?;
m.add_class::<PyChemicalRecord>()?;
m.add_class::<PyJobackRecord>()?;
m.add_wrapped(wrap_pymodule!(quantity))?;
m.add_wrapped(wrap_pymodule!(user_defined))?;
m.add_wrapped(wrap_pymodule!(cubic))?;
Expand Down
2 changes: 1 addition & 1 deletion src/python/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ macro_rules! impl_segment_record {
/// model_record : ModelRecord
/// The segment model parameters.
/// ideal_gas_record: IdealGasRecord, optional
/// The seg,ment ideal gas parameters.
/// The segment ideal gas parameters.
///
/// Returns
/// -------
Expand Down
84 changes: 14 additions & 70 deletions src/python/phase_equilibria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ macro_rules! impl_vle_state {
///
/// Raises
/// ------
/// RuntimeError :
/// RuntimeError
/// When pressure iteration fails or no phase equilibrium is found.
///
/// Example
/// -------
/// .. todo::
///
/// Add examples.
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature, initial_state=None, max_iter=None, tol=None, verbosity=None)")]
pub fn pure_t(
Expand Down Expand Up @@ -84,14 +78,8 @@ macro_rules! impl_vle_state {
///
/// Raises
/// ------
/// RuntimeError :
/// RuntimeError
/// When pressure iteration fails or no phase equilibrium is found.
///
/// Example
/// -------
/// .. todo::
///
/// Add examples.
#[staticmethod]
#[pyo3(text_signature = "(eos, pressure, initial_state=None, max_iter=None, tol=None, verbosity=None)")]
pub fn pure_p(
Expand Down Expand Up @@ -141,14 +129,8 @@ macro_rules! impl_vle_state {
///
/// Raises
/// ------
/// RuntimeError :
/// RuntimeError
/// When pressure iteration fails or no phase equilibrium is found.
///
/// Example
/// -------
/// .. todo::
///
/// Add examples.
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature, pressure, feed, initial_vle_state=None, max_iter=None, tol=None, verbosity=None, non_volatile_components=None)")]
pub fn tp_flash(
Expand Down Expand Up @@ -201,14 +183,6 @@ macro_rules! impl_vle_state {
/// Returns
/// -------
/// PhaseEquilibrium
///
/// Raises
/// ------
/// .. todo::
///
/// Example
/// -------
/// .. todo::
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature, liquid_molefracs, pressure=None, vapor_molefracs=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
pub fn bubble_point_tx(
Expand Down Expand Up @@ -266,14 +240,6 @@ macro_rules! impl_vle_state {
/// Returns
/// -------
/// PhaseEquilibrium
///
/// Raises
/// ------
/// .. todo::
///
/// Example
/// -------
/// .. todo::
#[staticmethod]
#[pyo3(text_signature = "(eos, pressure, liquid_molefracs, temperature=None, vapor_molefracs=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
pub fn bubble_point_px(
Expand Down Expand Up @@ -331,14 +297,6 @@ macro_rules! impl_vle_state {
/// Returns
/// -------
/// PhaseEquilibrium
///
/// Raises
/// ------
/// .. todo::
///
/// Example
/// -------
/// .. todo::
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature, vapor_molefracs, pressure=None, liquid_molefracs=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
pub fn dew_point_tx(
Expand Down Expand Up @@ -396,14 +354,6 @@ macro_rules! impl_vle_state {
/// Returns
/// -------
/// PhaseEquilibrium
///
/// Raises
/// ------
/// .. todo::
///
/// Example
/// -------
/// .. todo::
#[staticmethod]
#[pyo3(text_signature = "(eos, pressure, vapor_molefracs, temperature=None, liquid_molefracs=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
pub fn dew_point_px(
Expand Down Expand Up @@ -724,15 +674,9 @@ macro_rules! impl_vle_state {
///
/// Raises
/// ------
/// RuntimeError :
/// RuntimeError
/// When pressure iteration fails or no phase equilibrium is found.
///
/// Example
/// -------
/// .. todo::
///
/// Add examples.
#[pyo3(text_signature = "(initial_vle_state=None, max_iter=None, tol=None, verbosity=None, non_volatile_components=None)")]
#[pyo3(text_signature = "($self, initial_vle_state=None, max_iter=None, tol=None, verbosity=None, non_volatile_components=None)")]
pub fn tp_flash(
&self,
init_vle_state: Option<&PyPhaseEquilibrium>,
Expand Down Expand Up @@ -761,7 +705,8 @@ macro_rules! impl_vle_state {
/// The number of points.
/// critical_temperature: SINumber, optional
/// An estimate for the critical temperature to initialize
/// the calculation if necessary. For most components not necessary
/// the calculation if necessary. For most components not necessary.
/// Defaults to `None`.
/// max_iter : int, optional
/// The maximum number of iterations.
/// tol: float, optional
Expand Down Expand Up @@ -849,19 +794,18 @@ macro_rules! impl_vle_state {

/// Returns the phase diagram as dictionary.
///
/// Returns
/// -------
/// dict[str, list[float]]
/// Keys: property names.
/// Values: property for each state.
///
/// Units
/// -----
/// Note
/// ----
/// temperature : K
/// pressure : Pa
/// densities : mol / m³
/// molar enthalpies : kJ / mol
/// molar entropies : kJ / mol / K
///
/// Returns
/// -------
/// dict[str, list[float]]
/// Keys: property names. Values: property for each state.
pub fn to_dict(&self) -> PyResult<HashMap<String, Vec<f64>>> {
let mut result = HashMap::with_capacity(8);
result.insert(String::from("temperature"), (self.0.temperature() / KELVIN).into_value()?.into_raw_vec());
Expand Down
Loading