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
2 changes: 2 additions & 0 deletions build_wheel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2018"
crate-type = ["cdylib"]

[dependencies]
quantity = "0.5"
feos-core = { path = "..", features = ["python"] }
pyo3 = { version = "0.16", features = ["extension-module", "abi3", "abi3-py37"] }
numpy = "0.16"

53 changes: 53 additions & 0 deletions build_wheel/src/cubic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use feos_core::cubic::PengRobinson;
use feos_core::python::cubic::PyPengRobinsonParameters;
use feos_core::*;
use numpy::convert::ToPyArray;
use numpy::{PyArray1, PyArray2};
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use quantity::python::*;
use quantity::si::*;
use std::collections::HashMap;
use std::rc::Rc;

/// 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)")]
#[derive(Clone)]
pub struct PyPengRobinson(pub Rc<PengRobinson>);

#[pymethods]
impl PyPengRobinson {
#[new]
fn new(parameters: PyPengRobinsonParameters) -> Self {
Self(Rc::new(PengRobinson::new(parameters.0.clone())))
}
}

impl_equation_of_state!(PyPengRobinson);
impl_virial_coefficients!(PyPengRobinson);

impl_state!(PengRobinson, PyPengRobinson);
impl_state_molarweight!(PengRobinson, PyPengRobinson);
impl_vle_state!(PengRobinson, PyPengRobinson);

#[pymodule]
pub fn cubic(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyPengRobinson>()?;
m.add_class::<PyPengRobinsonParameters>()?;
m.add_class::<PyState>()?;
m.add_class::<PyPhaseDiagramPure>()?;
m.add_class::<PyPhaseDiagramBinary>()?;
m.add_class::<PyPhaseDiagramHetero>()?;
m.add_class::<PyPhaseEquilibrium>()?;
Ok(())
}
40 changes: 37 additions & 3 deletions build_wheel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
use feos_core::python::feos_core;
use feos_core::python::joback::PyJobackRecord;
use feos_core::python::parameter::*;
use feos_core::{Contributions, Verbosity};
use pyo3::prelude::*;
use pyo3::wrap_pymodule;
use quantity::python::__PYO3_PYMODULE_DEF_QUANTITY;

mod cubic;
mod user_defined;
use cubic::__PYO3_PYMODULE_DEF_CUBIC;
use user_defined::__PYO3_PYMODULE_DEF_USER_DEFINED;

#[pymodule]
pub fn build_wheel(py: Python<'_>, m: &PyModule) -> PyResult<()> {
feos_core(py, m)
pub fn feos_core(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyIdentifier>()?;
m.add_class::<Verbosity>()?;
m.add_class::<Contributions>()?;
m.add_class::<PyChemicalRecord>()?;
m.add_class::<PyJobackRecord>()?;

m.add_wrapped(wrap_pymodule!(user_defined))?;
m.add_wrapped(wrap_pymodule!(cubic))?;
m.add_wrapped(wrap_pymodule!(quantity))?;

py.run(
"\
import sys
sys.modules['feos_core.cubic'] = cubic
sys.modules['feos_core.user_defined'] = user_defined
quantity.SINumber.__module__ = 'feos_core.si'
quantity.SIArray1.__module__ = 'feos_core.si'
quantity.SIArray2.__module__ = 'feos_core.si'
quantity.SIArray3.__module__ = 'feos_core.si'
quantity.SIArray4.__module__ = 'feos_core.si'
sys.modules['feos_core.si'] = quantity
",
None,
Some(m.dict()),
)?;
Ok(())
}
69 changes: 69 additions & 0 deletions build_wheel/src/user_defined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use feos_core::python::user_defined::*;
use feos_core::python::statehd::*;
use feos_core::*;
use numpy::convert::ToPyArray;
use numpy::{PyArray1, PyArray2};
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use quantity::python::*;
use quantity::si::*;
use std::collections::HashMap;
use std::rc::Rc;


/// Equation of state implemented as python class.
///
/// Parameters
/// ----------
/// obj : python class object
/// The class that implements the equation of state.
///
/// Returns
/// -------
/// UserDefinedEos
///
/// Raises
/// ------
/// RunTimeError
/// If the class does not implement all necessary methods.
#[pyclass(name = "UserDefinedEos", unsendable)]
#[derive(Clone)]
#[pyo3(text_signature = "(obj)")]
pub struct PyUserDefinedEos(Rc<PyEoSObj>);

#[pymethods]
impl PyUserDefinedEos {
#[new]
fn new(obj: Py<PyAny>) -> PyResult<Self> {
Ok(Self(Rc::new(PyEoSObj::new(obj)?)))
}
}

impl_equation_of_state!(PyUserDefinedEos);
impl_virial_coefficients!(PyUserDefinedEos);
impl_state!(PyEoSObj, PyUserDefinedEos);
impl_state_molarweight!(PyEoSObj, PyUserDefinedEos);
impl_vle_state!(PyEoSObj, PyUserDefinedEos);

#[pymodule]
pub fn user_defined(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<PyStateHD>()?;
m.add_class::<PyStateD>()?;
m.add_class::<PyStateDDV3>()?;
m.add_class::<PyStateD3>()?;
m.add_class::<PyStateF>()?;
m.add_class::<PyStateHDD>()?;
m.add_class::<PyStateHDDV2>()?;
m.add_class::<PyStateHDDV3>()?;
m.add_class::<PyStateD3D>()?;
m.add_class::<PyStateD3DV2>()?;
m.add_class::<PyStateD3DV3>()?;
m.add_class::<PyUserDefinedEos>()?;
m.add_class::<PyState>()?;
m.add_class::<PyPhaseEquilibrium>()?;
m.add_class::<PyPhaseDiagramPure>()?;
m.add_class::<PyPhaseDiagramBinary>()?;
m.add_class::<PyPhaseDiagramHetero>()?;
m.add_class::<PyPhaseEquilibrium>()?;
Ok(())
}
Loading