Skip to content
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
Python fixes
  • Loading branch information
prehner committed Feb 16, 2024
commit 00696883cdc77d50576d318fd7592ee6066ab4e6
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ 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", "estimator", "pcsaft", "gc_pcsaft", "uvtheory", "pets", "saftvrqmie"]
all_models = ["dft", "estimator", "pcsaft", "gc_pcsaft", "pets", "saftvrqmie"]
#all_models = ["dft", "estimator", "pcsaft", "gc_pcsaft", "uvtheory", "pets", "saftvrqmie"]

[[bench]]
name = "state_properties"
Expand Down
2 changes: 1 addition & 1 deletion feos-core/src/python/parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ macro_rules! impl_parameter {
binary_records: Option<&PyAny>,
identifier_option: IdentifierOption,
) -> PyResult<Self> {
let prs = pure_records.into_iter().map(|pr| pr.0).collect();
let prs: Vec<_> = pure_records.into_iter().map(|pr| pr.0).collect();
let binary_records = binary_records
.map(|binary_records| {
if let Ok(br) = binary_records.extract::<PyReadonlyArray2<f64>>() {
Expand Down
8 changes: 4 additions & 4 deletions feos-core/src/python/user_defined.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::si::MolarWeight;
use crate::{Components, IdealGas, Residual, StateHD};
use ndarray::Array1;
use ndarray::{Array1, ScalarOperand};
use num_dual::*;
use numpy::convert::IntoPyArray;
use numpy::{PyArray, PyReadonlyArray1, PyReadonlyArrayDyn};
Expand Down Expand Up @@ -62,8 +62,8 @@ impl Components for PyIdealGas {
macro_rules! impl_ideal_gas {
($($py_hd_id:ident, $hd_ty:ty);*) => {
impl IdealGas for PyIdealGas {
fn ideal_gas_name(&self) -> String {
"Python".to_string()
fn ideal_gas_model(&self) -> String {
"Ideal gas (Python)".to_string()
}

fn ln_lambda3<D: DualNum<f64> + Copy>(&self, temperature: D) -> Array1<D> {
Expand Down Expand Up @@ -206,7 +206,7 @@ macro_rules! impl_residual {
panic!("helmholtz_energy: input data type not understood")
}

fn residual_helmholtz_energy_contributions<D: DualNum<f64> + Copy>(
fn residual_helmholtz_energy_contributions<D: DualNum<f64> + Copy + ScalarOperand>(
&self,
state: &StateHD<D>,
) -> Vec<(String, D)> {
Expand Down
4 changes: 2 additions & 2 deletions src/python/eos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::saftvrqmie::python::PySaftVRQMieParameters;
#[cfg(feature = "saftvrqmie")]
use crate::saftvrqmie::{SaftVRQMie, SaftVRQMieOptions};
#[cfg(feature = "uvtheory")]
use crate::uvtheory::python::PyUVParameters;
use crate::uvtheory::python::PyUVTheoryParameters;
#[cfg(feature = "uvtheory")]
use crate::uvtheory::{Perturbation, UVTheory, UVTheoryOptions, VirialOrder};

Expand Down Expand Up @@ -233,7 +233,7 @@ impl PyEquationOfState {
text_signature = "(parameters, max_eta=0.5, perturbation, virial_order)"
)]
fn uvtheory(
parameters: PyUVParameters,
parameters: PyUVTheoryParameters,
max_eta: f64,
perturbation: Perturbation,
virial_order: VirialOrder,
Expand Down
47 changes: 26 additions & 21 deletions src/uvtheory/python.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::parameters::{NoRecord, UVBinaryRecord, UVParameters, UVRecord};
use super::parameters::{NoRecord, UVTheoryBinaryRecord, UVTheoryParameters, UVTheoryRecord};
use super::{Perturbation, VirialOrder};
use feos_core::parameter::{
BinaryRecord, Identifier, IdentifierOption, Parameter, ParameterError, PureRecord,
Expand All @@ -17,36 +17,36 @@ use std::sync::Arc;
struct PyNoRecord(NoRecord);

/// Create a set of UV Theory parameters from records.
#[pyclass(name = "UVRecord")]
#[pyclass(name = "UVTheoryRecord")]
#[derive(Clone)]
pub struct PyUVRecord(UVRecord);
pub struct PyUVTheoryRecord(UVTheoryRecord);

#[pymethods]
impl PyUVRecord {
impl PyUVTheoryRecord {
#[new]
#[pyo3(text_signature = "(rep, att, sigma, epsilon_k)")]
fn new(rep: f64, att: f64, sigma: f64, epsilon_k: f64) -> Self {
Self(UVRecord::new(rep, att, sigma, epsilon_k))
Self(UVTheoryRecord::new(rep, att, sigma, epsilon_k))
}

fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}

impl_json_handling!(PyUVRecord);
impl_json_handling!(PyUVTheoryRecord);

#[pyclass(name = "UVBinaryRecord")]
#[pyclass(name = "UVTheoryBinaryRecord")]
#[derive(Clone)]
pub struct PyUVBinaryRecord(UVBinaryRecord);
impl_binary_record!(UVBinaryRecord, PyUVBinaryRecord);
pub struct PyUVTheoryBinaryRecord(UVTheoryBinaryRecord);
impl_binary_record!(UVTheoryBinaryRecord, PyUVTheoryBinaryRecord);

#[pyclass(name = "UVParameters")]
#[pyclass(name = "UVTheoryParameters")]
#[derive(Clone)]
pub struct PyUVParameters(pub Arc<UVParameters>);
pub struct PyUVTheoryParameters(pub Arc<UVTheoryParameters>);

#[pymethods]
impl PyUVParameters {
impl PyUVTheoryParameters {
/// Create a set of UV Theory parameters from lists.
///
/// Parameters
Expand All @@ -62,7 +62,7 @@ impl PyUVParameters {
///
/// Returns
/// -------
/// UVParameters
/// UVTheoryParameters
#[pyo3(text_signature = "(rep, att, sigma, epsilon_k)")]
#[staticmethod]
fn from_lists(
Expand All @@ -82,11 +82,11 @@ impl PyUVParameters {
None,
None,
);
let model_record = UVRecord::new(rep[i], att[i], sigma[i], epsilon_k[i]);
let model_record = UVTheoryRecord::new(rep[i], att[i], sigma[i], epsilon_k[i]);
PureRecord::new(identifier, 1.0, model_record)
})
.collect();
Ok(Self(Arc::new(UVParameters::from_records(
Ok(Self(Arc::new(UVTheoryParameters::from_records(
pure_records,
None,
)?)))
Expand All @@ -107,22 +107,27 @@ impl PyUVParameters {
///
/// Returns
/// -------
/// UVParameters
/// UVTheoryParameters
///
/// # Info
///
/// Molar weight is one. No ideal gas contribution is considered.
#[pyo3(text_signature = "(rep, att, sigma, epsilon_k)")]
#[staticmethod]
fn new_simple(rep: f64, att: f64, sigma: f64, epsilon_k: f64) -> PyResult<Self> {
Ok(Self(Arc::new(UVParameters::new_simple(
Ok(Self(Arc::new(UVTheoryParameters::new_simple(
rep, att, sigma, epsilon_k,
)?)))
}
}

impl_pure_record!(UVRecord, PyUVRecord);
impl_parameter!(UVParameters, PyUVParameters, PyUVRecord, PyUVBinaryRecord);
impl_pure_record!(UVTheoryRecord, PyUVTheoryRecord);
impl_parameter!(
UVTheoryParameters,
PyUVTheoryParameters,
PyUVTheoryRecord,
PyUVTheoryBinaryRecord
);

#[pymodule]
pub fn uvtheory(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
Expand All @@ -132,9 +137,9 @@ pub fn uvtheory(_py: Python<'_>, m: &PyModule) -> PyResult<()> {

m.add_class::<Perturbation>()?;
m.add_class::<VirialOrder>()?;
m.add_class::<PyUVRecord>()?;
m.add_class::<PyUVTheoryRecord>()?;
m.add_class::<PyPureRecord>()?;
m.add_class::<PyBinaryRecord>()?;
m.add_class::<PyUVParameters>()?;
m.add_class::<PyUVTheoryParameters>()?;
Ok(())
}