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
removed unit generics from feos, fixes in core and dft in python macros
  • Loading branch information
g-bauer committed Jan 20, 2023
commit 5e94f76779ad89f79a139b92dbe81294b7225d02
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Export `EosVariant` and `FunctionalVariant` directly in the crate root instead of their own modules. [#62](https://github.com/feos-org/feos/pull/62)
- Changed constructors `VaporPressure::new` and `DataSet.vapor_pressure` (Python) to take a new optional argument `critical_temperature`. [#86](https://github.com/feos-org/feos/pull/86)
- The limitations of the homo gc method for PC-SAFT are enforced more strictly. [#88](https://github.com/feos-org/feos/pull/88)
- Removed generics for units in all structs and traits in favor of static SI units. [#115](https://github.com/feos-org/feos/pull/115)

## [0.3.0] - 2022-09-14
- Major restructuring of the entire `feos` project. All individual models are reunited in the `feos` crate. `feos-core` and `feos-dft` still live as individual crates within the `feos` workspace.
Expand Down
4 changes: 2 additions & 2 deletions benches/dual_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::sync::Arc;
/// - temperature is 80% of critical temperature,
/// - volume is critical volume,
/// - molefracs (or moles) for equimolar mixture.
fn state_pcsaft(parameters: PcSaftParameters) -> State<SIUnit, PcSaft> {
fn state_pcsaft(parameters: PcSaftParameters) -> State<PcSaft> {
let n = parameters.pure_records.len();
let eos = Arc::new(PcSaft::new(Arc::new(parameters)));
let moles = Array::from_elem(n, 1.0 / n as f64) * 10.0 * MOL;
Expand All @@ -39,7 +39,7 @@ where
fn bench_dual_numbers<E: EquationOfState>(
c: &mut Criterion,
group_name: &str,
state: State<SIUnit, E>,
state: State<E>,
) {
let mut group = c.benchmark_group(group_name);
group.bench_function("a_f64", |b| {
Expand Down
2 changes: 1 addition & 1 deletion benches/state_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn npt<E: EquationOfState>(
SINumber,
SINumber,
&SIArray1,
DensityInitialization<SIUnit>,
DensityInitialization,
),
) {
State::new_npt(eos, t, p, n, rho0).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions benches/state_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use ndarray::arr1;
use quantity::si::*;
use std::sync::Arc;

type S = State<SIUnit, PcSaft>;
type S = State<PcSaft>;

/// Evaluate a property of a state given the EoS, the property to compute,
/// temperature, volume, moles, and the contributions to consider.
fn property<E: EquationOfState, T, F: Fn(&State<SIUnit, E>, Contributions) -> T>(
fn property<E: EquationOfState, T, F: Fn(&State<E>, Contributions) -> T>(
(eos, property, t, v, n, contributions): (
&Arc<E>,
F,
Expand All @@ -28,7 +28,7 @@ fn property<E: EquationOfState, T, F: Fn(&State<SIUnit, E>, Contributions) -> T>

/// Evaluate a property with of a state given the EoS, the property to compute,
/// temperature, volume, moles.
fn property_no_contributions<E: EquationOfState, T, F: Fn(&State<SIUnit, E>) -> T>(
fn property_no_contributions<E: EquationOfState, T, F: Fn(&State<E>) -> T>(
(eos, property, t, v, n): (&Arc<E>, F, SINumber, SINumber, &SIArray1),
) -> T {
let state = State::new_nvt(eos, t, v, n).unwrap();
Expand Down
1 change: 1 addition & 0 deletions feos-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `StateVec::moles` getter. [#113](https://github.com/feos-org/feos/pull/113)
- Added public constructors `PhaseDiagram::new` and `StateVec::new` that allow the creation of the respective structs from a list of `PhaseEquilibrium`s or `State`s in Rust and Python. [#113](https://github.com/feos-org/feos/pull/113)
- Added new variant `EosError::Error` which allows dispatching generic errors that are not covered by the existing variants. [#98](https://github.com/feos-org/feos/pull/98)
- Removed generics for units in all structs and traits in favor of static SI units. [#115](https://github.com/feos-org/feos/pull/115)

### Changed
- Added `Sync` and `Send` as supertraits to `EquationOfState`. [#57](https://github.com/feos-org/feos/pull/57)
Expand Down
12 changes: 4 additions & 8 deletions feos-core/src/phase_equilibria/phase_diagram_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
x_lle: Option<(f64, f64)>,
bubble_dew_options: (SolverOptions, SolverOptions),
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let npoints = npoints.unwrap_or(DEFAULT_POINTS);
let tp = temperature_or_pressure.try_into()?;
Expand Down Expand Up @@ -106,8 +105,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
vle_sat: [Option<PhaseEquilibrium<E, 2>>; 2],
bubble_dew_options: (SolverOptions, SolverOptions),
) -> EosResult<(Vec<PhaseEquilibrium<E, 2>>, Vec<PhaseEquilibrium<E, 2>>)>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
match vle_sat {
[Some(vle2), Some(vle1)] => {
Expand Down Expand Up @@ -151,8 +149,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
max_tp: SINumber,
npoints: Option<usize>,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let npoints = npoints.unwrap_or(DEFAULT_POINTS);
let mut states = Vec::with_capacity(npoints);
Expand Down Expand Up @@ -272,8 +269,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
npoints_lle: Option<usize>,
bubble_dew_options: (SolverOptions, SolverOptions),
) -> EosResult<PhaseDiagramHetero<E>>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let npoints_vle = npoints_vle.unwrap_or(DEFAULT_POINTS);
let tp = temperature_or_pressure.try_into()?;
Expand Down
9 changes: 3 additions & 6 deletions feos-core/src/phase_equilibria/phase_diagram_pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
critical_temperature: Option<SINumber>,
options: SolverOptions,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let mut states = Vec::with_capacity(npoints);

Expand Down Expand Up @@ -80,8 +79,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
temperatures: ArrayView1<f64>,
options: SolverOptions,
) -> EosResult<Vec<PhaseEquilibrium<E, 2>>>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let mut states = Vec::with_capacity(temperatures.len());
let mut vle = None;
Expand Down Expand Up @@ -109,8 +107,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
critical_temperature: Option<SINumber>,
options: SolverOptions,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let sc = State::critical_point(eos, None, critical_temperature, SolverOptions::default())?;

Expand Down
9 changes: 3 additions & 6 deletions feos-core/src/phase_equilibria/phase_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
critical_temperature: Option<SINumber>,
options: (SolverOptions, SolverOptions),
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let mut states = Vec::with_capacity(npoints);

Expand Down Expand Up @@ -68,8 +67,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
critical_temperature: Option<SINumber>,
options: (SolverOptions, SolverOptions),
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let mut states = Vec::with_capacity(npoints);

Expand Down Expand Up @@ -136,8 +134,7 @@ impl<E: EquationOfState> PhaseDiagram<E, 2> {
critical_temperature: Option<SINumber>,
options: SolverOptions,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let mut states = Vec::with_capacity(npoints);

Expand Down
21 changes: 7 additions & 14 deletions feos-core/src/phase_equilibria/vle_pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
initial_state: Option<&PhaseEquilibrium<E, 2>>,
options: SolverOptions,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
match TPSpec::try_from(temperature_or_pressure)? {
TPSpec::Temperature(t) => Self::pure_t(eos, t, initial_state, options),
Expand All @@ -38,8 +37,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
initial_state: Option<&PhaseEquilibrium<E, 2>>,
options: SolverOptions,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let (max_iter, tol, verbosity) = options.unwrap_or(MAX_ITER_PURE, TOL_PURE);

Expand Down Expand Up @@ -68,8 +66,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
}

fn iterate_pure_t(self, max_iter: usize, tol: f64, verbosity: Verbosity) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let mut p_old = self.vapor().pressure(Contributions::Total);
let [mut vapor, mut liquid] = self.0;
Expand Down Expand Up @@ -172,8 +169,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
initial_state: Option<&Self>,
options: SolverOptions,
) -> EosResult<Self>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
let (max_iter, tol, verbosity) = options.unwrap_or(MAX_ITER_PURE, TOL_PURE);

Expand Down Expand Up @@ -362,8 +358,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
/// Calculate the pure component vapor pressures of all
/// components in the system for the given temperature.
pub fn vapor_pressure(eos: &Arc<E>, temperature: SINumber) -> Vec<Option<SINumber>>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
(0..eos.components())
.map(|i| {
Expand All @@ -378,8 +373,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
/// Calculate the pure component boiling temperatures of all
/// components in the system for the given pressure.
pub fn boiling_temperature(eos: &Arc<E>, pressure: SINumber) -> Vec<Option<SINumber>>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
(0..eos.components())
.map(|i| {
Expand All @@ -397,8 +391,7 @@ impl<E: EquationOfState> PhaseEquilibrium<E, 2> {
eos: &Arc<E>,
temperature_or_pressure: SINumber,
) -> Vec<Option<PhaseEquilibrium<E, 2>>>
where
SINumber: std::fmt::Display + std::fmt::LowerExp,

{
(0..eos.components())
.map(|i| {
Expand Down
2 changes: 1 addition & 1 deletion feos-derive/src/dft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn impl_molar_weight(
}
}
Ok(quote! {
impl MolarWeight<SIUnit> for FunctionalVariant {
impl MolarWeight for FunctionalVariant {
fn molar_weight(&self) -> SIArray1 {
match self {
#(#molar_weight,)*
Expand Down
4 changes: 2 additions & 2 deletions feos-derive/src/eos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn impl_molar_weight(
}
}
Ok(quote! {
impl MolarWeight<SIUnit> for EosVariant {
impl MolarWeight for EosVariant {
fn molar_weight(&self) -> SIArray1 {
match self {
#(#molar_weight,)*
Expand Down Expand Up @@ -148,7 +148,7 @@ fn impl_entropy_scaling(
}

Ok(quote! {
impl EntropyScaling<SIUnit> for EosVariant {
impl EntropyScaling for EosVariant {
fn viscosity_reference(
&self,
temperature: SINumber,
Expand Down
1 change: 1 addition & 0 deletions feos-dft/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed the `3d_dft` feature to `rayon` in accordance to the other feos crates. [#62](https://github.com/feos-org/feos/pull/62)
- internally rewrote the implementation of the Euler-Lagrange equation to use a bulk density instead of the chemical potential as variable. [#60](https://github.com/feos-org/feos/pull/60)
- Renamed the parameter `beta` of the Picard iteration and Anderson mixing solvers to `damping_coefficient`. [#75](https://github.com/feos-org/feos/pull/75)
- Removed generics for units in all structs and traits in favor of static SI units. [#115](https://github.com/feos-org/feos/pull/115)

## [0.3.2] - 2022-10-13
### Changed
Expand Down
4 changes: 2 additions & 2 deletions feos-dft/src/python/adsorption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ macro_rules! impl_adsorption {
($func:ty, $py_func:ty) => {
/// Container structure for adsorption isotherms in 1D pores.
#[pyclass(name = "Adsorption1D")]
pub struct PyAdsorption1D(Adsorption1D<SIUnit, $func>);
pub struct PyAdsorption1D(Adsorption1D<$func>);

/// Container structure for adsorption isotherms in 3D pores.
#[pyclass(name = "Adsorption3D")]
pub struct PyAdsorption3D(Adsorption3D<SIUnit, $func>);
pub struct PyAdsorption3D(Adsorption3D<$func>);

impl_adsorption_isotherm!($func, $py_func, PyAdsorption1D, PyPore1D, PyPoreProfile1D);
impl_adsorption_isotherm!($func, $py_func, PyAdsorption3D, PyPore3D, PyPoreProfile3D);
Expand Down
8 changes: 4 additions & 4 deletions feos-dft/src/python/adsorption/pore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ macro_rules! impl_pore {
///
#[pyclass(name = "Pore1D")]
#[pyo3(text_signature = "(geometry, pore_size, potential, n_grid=None, potential_cutoff=None)")]
pub struct PyPore1D(Pore1D<SIUnit>);
pub struct PyPore1D(Pore1D);

#[pyclass(name = "PoreProfile1D")]
pub struct PyPoreProfile1D(PoreProfile1D<SIUnit, $func>);
pub struct PyPoreProfile1D(PoreProfile1D<$func>);

impl_1d_profile!(PyPoreProfile1D, [get_r, get_z]);

Expand Down Expand Up @@ -149,10 +149,10 @@ macro_rules! impl_pore {
///
#[pyclass(name = "Pore3D")]
#[pyo3(text_signature = "(system_size, n_grid, coordinates, sigma_ss, epsilon_k_ss, potential_cutoff=None, cutoff_radius=None)")]
pub struct PyPore3D(Pore3D<SIUnit>);
pub struct PyPore3D(Pore3D);

#[pyclass(name = "PoreProfile3D")]
pub struct PyPoreProfile3D(PoreProfile3D<SIUnit, $func>);
pub struct PyPoreProfile3D(PoreProfile3D<$func>);

impl_3d_profile!(PyPoreProfile3D, get_x, get_y, get_z);

Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ macro_rules! impl_planar_interface {
($func:ty) => {
/// A one-dimensional density profile of a vapor-liquid or liquid-liquid interface.
#[pyclass(name = "PlanarInterface")]
pub struct PyPlanarInterface(PlanarInterface<SIUnit, $func>);
pub struct PyPlanarInterface(PlanarInterface<$func>);

impl_1d_profile!(PyPlanarInterface, [get_z]);

Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/interface/surface_tension_diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro_rules! impl_surface_tension_diagram {
///
#[pyclass(name = "SurfaceTensionDiagram")]
#[pyo3(text_signature = "(dia, init_densities=None, n_grid=None, l_grid=None, critical_temperature=None, fix_equimolar_surface=None, solver=None)")]
pub struct PySurfaceTensionDiagram(SurfaceTensionDiagram<SIUnit, $func>);
pub struct PySurfaceTensionDiagram(SurfaceTensionDiagram<$func>);

#[pymethods]
impl PySurfaceTensionDiagram {
Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro_rules! impl_profile {
log: bool,
py: Python<'py>,
) -> PyResult<(&'py $arr2<f64>, &'py PyArray1<f64>, f64)> {
let (res_rho, res_mres_norm) = self.0.profile.residual(log)?;
let (res_rho, res_mu, res_norm) = self.0.profile.residual(log)?;
Ok((res_rho.view().to_pyarray(py), res_mu.view().to_pyarray(py), res_norm))
}

Expand Down
4 changes: 2 additions & 2 deletions feos-dft/src/python/solvation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! impl_solvation_profile {
///
#[pyclass(name = "SolvationProfile")]
#[pyo3(text_signature = "(bulk, n_grid, coordinates, sigma, epsilon_k, system_size=None, cutoff_radius=None, potential_cutoff=None)")]
pub struct PySolvationProfile(SolvationProfile<SIUnit, $func>);
pub struct PySolvationProfile(SolvationProfile<$func>);

impl_3d_profile!(PySolvationProfile, get_x, get_y, get_z);

Expand Down Expand Up @@ -94,7 +94,7 @@ macro_rules! impl_pair_correlation {
///
#[pyclass(name = "PairCorrelation")]
#[pyo3(text_signature = "(bulk, test_particle, n_grid, width)")]
pub struct PyPairCorrelation(PairCorrelation<SIUnit, $func>);
pub struct PyPairCorrelation(PairCorrelation<$func>);

impl_1d_profile!(PyPairCorrelation, [get_r]);

Expand Down
Loading