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
new new_pure and new_binary routines for Parameter to compensat…
…e for the now non-optional `binary_records`
  • Loading branch information
prehner committed Nov 26, 2021
commit df328317781c33eff021714f748bd8c200b5bf5f
22 changes: 22 additions & 0 deletions src/parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ where
binary_records: Array2<Self::Binary>,
) -> Self;

/// Creates parameters for a pure component from a pure record.
fn new_pure(pure_record: PureRecord<Self::Pure, Self::IdealGas>) -> Self {
let binary_record = Array2::from_elem([1, 1], Self::Binary::default());
Self::from_records(vec![pure_record], binary_record)
}

/// Creates parameters for a binary system from pure records and an optional
/// binary interaction parameter.
fn new_binary(
pure_records: Vec<PureRecord<Self::Pure, Self::IdealGas>>,
binary_record: Option<Self::Binary>,
) -> Self {
let binary_record = Array2::from_shape_fn([2, 2], |(i, j)| {
if i == j {
Self::Binary::default()
} else {
binary_record.clone().unwrap_or_default()
}
});
Self::from_records(pure_records, binary_record)
}

/// Return the original pure and binary records that werde used to construct the parameters.
#[allow(clippy::type_complexity)]
fn records(
Expand Down
46 changes: 38 additions & 8 deletions src/python/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,48 @@ macro_rules! impl_parameter {
/// ----------
/// pure_records : [PureRecord]
/// A list of pure component parameters.
/// binary_records : [BinaryRecord], optional
/// A list of binary interaction parameters.
/// binary_records : numpy.ndarray[float]
/// A matrix of binary interaction parameters.
#[staticmethod]
#[pyo3(text_signature = "(pure_records, binary_records=None)")]
#[pyo3(text_signature = "(pure_records, binary_records)")]
fn from_records(
pure_records: Vec<PyPureRecord>,
binary_records: Option<Vec<PyBinaryRecord>>,
) -> Result<Self, ParameterError> {
Ok(Self(<$parameter>::from_records(
binary_records: &PyArray2<f64>,
) -> Self {
Self(<$parameter>::from_records(
pure_records.into_iter().map(|pr| pr.0).collect(),
binary_records.map(|br| br.into_iter().map(|br| br.0).collect()),
)?))
binary_records.to_owned_array(),
))
}

/// Creates parameters for a pure component from a pure record.
///
/// Parameters
/// ----------
/// pure_record : PureRecord
/// The pure component parameters.
#[staticmethod]
#[pyo3(text_signature = "(pure_record)")]
fn new_pure(pure_record: PyPureRecord) -> Self {
Self(<$parameter>::new_pure(pure_record.0))
}

/// Creates parameters for a binary system from pure records and an optional
/// binary interaction parameter.
///
/// Parameters
/// ----------
/// pure_records : [PureRecord]
/// A list of pure component parameters.
/// binary_record : float, optional
/// The binary interaction parameter.
#[staticmethod]
#[pyo3(text_signature = "(pure_records, binary_record)")]
fn new_binary(pure_records: Vec<PyPureRecord>, binary_record: Option<f64>) -> Self {
Self(<$parameter>::new_binary(
pure_records.into_iter().map(|pr| pr.0).collect(),
binary_record,
))
}

/// Creates parameters from json files.
Expand Down