Skip to content
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
4 changes: 4 additions & 0 deletions feos-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Changed
- Made binary parameters in `from_records` Python routine an `Option`. [#35](https://github.com/feos-org/feos/pull/35)
- Added panic with message when parsing missing Identifiers variants. [#35](https://github.com/feos-org/feos/pull/35)

### Fixed
- Avoid panicking when calculating `ResidualNpt` properties of states with negative pressures. [#42](https://github.com/feos-org/feos/pull/42)

Expand Down
16 changes: 14 additions & 2 deletions feos-core/src/parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,20 @@ where
};
let n = pure_records.len();
Array2::from_shape_fn([n, n], |(i, j)| {
let id1 = pure_records[i].identifier.as_string(search_option).unwrap();
let id2 = pure_records[j].identifier.as_string(search_option).unwrap();
let id1 = pure_records[i]
.identifier
.as_string(search_option)
.expect(&format!(
"No identifier for given search_option for pure record {}.",
i
));
let id2 = pure_records[j]
.identifier
.as_string(search_option)
.expect(&format!(
"No identifier for given search_option for pure record {}.",
j
));
binary_map
.get(&(id1.clone(), id2.clone()))
.or_else(|| binary_map.get(&(id2, id1)))
Expand Down
1 change: 1 addition & 0 deletions feos-core/src/python/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::parameter::{
use crate::python::joback::PyJobackRecord;
use crate::python::parameter::PyIdentifier;
use crate::*;
use ndarray::Array2;
use numpy::PyReadonlyArray2;
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
Expand Down
40 changes: 24 additions & 16 deletions feos-core/src/python/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ macro_rules! impl_parameter {
/// ----------
/// pure_records : [PureRecord]
/// A list of pure component parameters.
/// binary_records : numpy.ndarray[float] or List[BinaryRecord]
/// binary_records : numpy.ndarray[float] or List[BinaryRecord], optional
/// A matrix of binary interaction parameters or a list
/// containing records for binary interactions.
/// search_option : IdentifierOption, optional, defaults to IdentifierOption.Name
Expand All @@ -551,25 +551,33 @@ macro_rules! impl_parameter {
#[pyo3(text_signature = "(pure_records, binary_records, search_option)")]
fn from_records(
pure_records: Vec<PyPureRecord>,
binary_records: &PyAny,
binary_records: Option<&PyAny>,
search_option: Option<IdentifierOption>,
) -> PyResult<Self> {
let prs = pure_records.into_iter().map(|pr| pr.0).collect();
let brs = if let Ok(br) = binary_records.extract::<PyReadonlyArray2<f64>>() {
Ok(br.to_owned_array().mapv(|r| r.try_into().unwrap()))
} else if let Ok(br) = binary_records.extract::<Vec<PyBinaryRecord>>() {
let brs: Vec<_> = br.into_iter().map(|br| br.0).collect();
Ok(<$parameter>::binary_matrix_from_records(
&prs,
&brs,
search_option.unwrap_or(IdentifierOption::Name),
))
if let Some(binary_records) = binary_records {
let brs = if let Ok(br) = binary_records.extract::<PyReadonlyArray2<f64>>() {
Ok(br.to_owned_array().mapv(|r| r.try_into().unwrap()))
} else if let Ok(br) = binary_records.extract::<Vec<PyBinaryRecord>>() {
let brs: Vec<_> = br.into_iter().map(|br| br.0).collect();
Ok(<$parameter>::binary_matrix_from_records(
&prs,
&brs,
search_option.unwrap_or(IdentifierOption::Name),
))
} else {
Err(PyErr::new::<PyTypeError, _>(format!(
"Could not parse binary input!"
)))
};
Ok(Self(Rc::new(<$parameter>::from_records(prs, brs.unwrap()))))
} else {
Err(PyErr::new::<PyTypeError, _>(format!(
"Could not parse binary input!"
)))
};
Ok(Self(Rc::new(<$parameter>::from_records(prs, brs.unwrap()))))
let n = prs.len();
Ok(Self(Rc::new(<$parameter>::from_records(
prs,
Array2::from_elem([n, n], <$parameter as Parameter>::Binary::default()),
))))
}
}

/// Creates parameters for a pure component from a pure record.
Expand Down
1 change: 0 additions & 1 deletion src/gc_pcsaft/dft/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use indexmap::IndexMap;
use ndarray::{Array1, Array2};
use petgraph::dot::{Config, Dot};
use petgraph::graph::{Graph, UnGraph};
use std::fmt::Write;

/// psi Parameter for heterosegmented DFT (Mairhofer2018)
const PSI_GC_DFT: f64 = 1.5357;
Expand Down
1 change: 1 addition & 0 deletions src/pcsaft/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use feos_core::parameter::{
use feos_core::python::joback::PyJobackRecord;
use feos_core::python::parameter::*;
use feos_core::*;
use ndarray::Array2;
use numpy::{PyArray2, PyReadonlyArray2, ToPyArray};
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
Expand Down