Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ecc6f54
Revised handling of ideal gas contribution
prehner Jun 1, 2023
5e55d55
ignore some specialized functionalities
prehner Jun 1, 2023
eb01939
added some residual properties.todo: check ideal gas parts
g-bauer Jun 1, 2023
d4bd127
feos-core compiles again
prehner Jun 1, 2023
75e24a3
Fancy StateBuilder
prehner Jun 1, 2023
89d6d8e
Adjusted parameters, cubic and Joback. Added EquationOfState and test…
g-bauer Jun 2, 2023
4476475
Added EntropyScaling in core, adjusted derive macros, started adjusti…
g-bauer Jun 2, 2023
a8cb089
Adjusted python interface, currently panics for residual properties w…
g-bauer Jun 2, 2023
0668a63
Phase equilibria routine; moved dmu_dni to residual_properties; UNTESTED
prehner Jun 2, 2023
9d18ad5
Added missing files for feos-derive
g-bauer Jun 2, 2023
48e98ba
moved subset to new Components trait, eliminated DeBroglieWavelength …
prehner Jun 4, 2023
5b6eed1
new file in feos-derive
prehner Jun 4, 2023
8191f15
First tiny steps for DFT implementation
prehner Jun 4, 2023
c8e453a
DFT almost implemented
prehner Jun 5, 2023
c538018
fix ln_phi
prehner Jun 5, 2023
b685380
Fixed rest of models. Python part still needs to be done.
g-bauer Jun 6, 2023
134b788
Change Joback parameters for test case
g-bauer Jun 6, 2023
5f63e75
Expose IdealGasModel and ResidualModel
g-bauer Jun 6, 2023
454100f
Fix calculation of critical points and some phase equilibria
prehner Jun 6, 2023
61fc6f3
Fix `init_pure_p`
prehner Jun 6, 2023
6ce52df
fix pdgt
prehner Jun 6, 2023
b62cd1b
revive DeBroglieWavelength traits
prehner Jun 6, 2023
6b2b895
Fix Python for basic equations of state (including user defined)
prehner Jun 6, 2023
4070732
docstrings, cleanup and tests
prehner Jun 6, 2023
1598705
Explicitly handle non-additive properties and simplify the rest
prehner Jun 6, 2023
cae0991
updated theory guide
prehner Jun 7, 2023
4cc8d31
Adjustment for Python interface. DFT + Python not yet working
g-bauer Jun 7, 2023
9d48a17
make ideal gas in DFT actually usable
prehner Jun 7, 2023
c6e9d35
Fix remaining tests and functionals
prehner Jun 7, 2023
21e471e
fix estimator
prehner Jun 7, 2023
cfeb488
clear Cargo.toml
prehner Jun 7, 2023
25ed0c9
WIP Python interface for DFT
g-bauer Jun 7, 2023
84a1a0d
Python wheels online
prehner Jun 7, 2023
5da4973
Pore equilibrium algorithm that does not rely on the ideal gas model.…
prehner Jun 9, 2023
a072af1
Final cleanup of rust code, moved Verbosity and SolverOptions to lib.rs
prehner Jun 9, 2023
dc02390
Cargo.toml once again
prehner Jun 9, 2023
46f7403
revert changes to pets
prehner Jun 9, 2023
003a214
Proper parameter treatment for Joback, renamed function in deBroglieW…
g-bauer Jun 15, 2023
e60e551
Updated tests
g-bauer Jun 15, 2023
daad0cf
Added Joback parameters for tests
g-bauer Jun 15, 2023
dd9e23d
Fix calculation of dln_phi_dt
prehner Jun 16, 2023
42f9501
Fix critical_point_binary_p
prehner Jun 16, 2023
3f11197
Updated changelog for feos-core
g-bauer Jun 19, 2023
5f2b0a0
Updated changelog for feos-dft
g-bauer Jun 19, 2023
a3e7f03
fix total_gibbs energy and hence accelerated successive substitution
prehner Jul 3, 2023
6b7cdb9
clarify docstring of residual Helmholtz and Gibbs energy
prehner Jul 5, 2023
6c6f023
update changelog
prehner Jul 7, 2023
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
moved subset to new Components trait, eliminated DeBroglieWavelength …
…trait
  • Loading branch information
prehner committed Jun 4, 2023
commit 48e98bafc059be447fe844ef47100dbf9faf5ac4
13 changes: 5 additions & 8 deletions feos-core/src/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! of state - with a single contribution to the Helmholtz energy - can be implemented.
//! The implementation closely follows the form of the equations given in
//! [this wikipedia article](https://en.wikipedia.org/wiki/Cubic_equations_of_state#Peng%E2%80%93Robinson_equation_of_state).
use crate::equation_of_state::{HelmholtzEnergy, HelmholtzEnergyDual, Residual};
use crate::equation_of_state::{Components, HelmholtzEnergy, HelmholtzEnergyDual, Residual};
use crate::parameter::{Identifier, Parameter, ParameterError, PureRecord};
use crate::si::{GRAM, MOL};
use crate::state::StateHD;
Expand Down Expand Up @@ -144,12 +144,7 @@ impl Parameter for PengRobinsonParameters {
}
}

fn records(
&self,
) -> (
&[PureRecord<PengRobinsonRecord>],
&Array2<f64>,
) {
fn records(&self) -> (&[PureRecord<PengRobinsonRecord>], &Array2<f64>) {
(&self.pure_records, &self.k_ij)
}
}
Expand Down Expand Up @@ -219,15 +214,17 @@ impl fmt::Display for PengRobinson {
}
}

impl Residual for PengRobinson {
impl Components for PengRobinson {
fn components(&self) -> usize {
self.parameters.b.len()
}

fn subset(&self, component_list: &[usize]) -> Self {
Self::new(Arc::new(self.parameters.subset(component_list)))
}
}

impl Residual for PengRobinson {
fn compute_max_density(&self, moles: &Array1<f64>) -> f64 {
let b = (moles * &self.parameters.b).sum() / moles.sum();
0.9 / b
Expand Down
100 changes: 0 additions & 100 deletions feos-core/src/equation_of_state/__ideal_gas.rs

This file was deleted.

47 changes: 0 additions & 47 deletions feos-core/src/equation_of_state/debroglie.rs

This file was deleted.

25 changes: 7 additions & 18 deletions feos-core/src/equation_of_state/ideal_gas.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::Components;
use crate::StateHD;
use ndarray::Array1;
use num_dual::DualNum;
use std::fmt;

use super::debroglie::{DeBroglieWavelength, DeBroglieWavelengthDual};

/// Ideal gas Helmholtz energy contribution that can
/// be evaluated using generalized (hyper) dual numbers.
Expand All @@ -11,28 +10,18 @@ use super::debroglie::{DeBroglieWavelength, DeBroglieWavelengthDual};
/// the specific types in the supertraits of [IdealGasContribution]
/// so that the implementor can be used as an ideal gas
/// contribution in the equation of state.
pub trait IdealGas: Sync + Send + fmt::Display {
// /// Return the number of components
// fn components(&self) -> usize;

/// Return an equation of state consisting of the components
/// contained in component_list.
fn subset(&self, component_list: &[usize]) -> Self;
pub trait IdealGas: Components + Sync + Send {
fn de_broglie_wavelength<D: DualNum<f64> + Copy>(&self, temperature: D) -> Array1<D>;

fn ideal_gas_model(&self) -> &Box<dyn DeBroglieWavelength>;
fn ideal_gas_model(&self) -> String;

/// Evaluate the ideal gas contribution for a given state.
///
/// In some cases it could be advantageous to overwrite this
/// implementation instead of implementing the de Broglie
/// wavelength.
fn evaluate_ideal_gas<D: DualNum<f64> + Copy>(&self, state: &StateHD<D>) -> D
where
dyn DeBroglieWavelength: DeBroglieWavelengthDual<D>,
{
let lambda = self
.ideal_gas_model()
.de_broglie_wavelength(state.temperature);
fn evaluate_ideal_gas<D: DualNum<f64> + Copy>(&self, state: &StateHD<D>) -> D {
let lambda = self.de_broglie_wavelength(state.temperature);
((lambda
+ state.partial_density.mapv(|x| {
if x.re() == 0.0 {
Expand Down
61 changes: 23 additions & 38 deletions feos-core/src/equation_of_state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use ndarray::Array1;
use num_dual::DualNum;
use quantity::si::{SIArray1, SINumber};
use std::{fmt::Display, sync::Arc};
use std::sync::Arc;

pub mod debroglie;
pub mod helmholtz_energy;
pub mod ideal_gas;
pub mod residual;
use crate::{EosResult, StateHD};
use crate::EosResult;

pub use self::debroglie::{DeBroglieWavelength, DeBroglieWavelengthDual};
pub use helmholtz_energy::{HelmholtzEnergy, HelmholtzEnergyDual};
pub use ideal_gas::IdealGas;
pub use residual::{EntropyScaling, Residual};
Expand All @@ -22,42 +20,34 @@ pub trait MolarWeight {
fn molar_weight(&self) -> SIArray1;
}

pub trait Components {
/// Return the number of components of the model.
fn components(&self) -> usize;

/// Return a model consisting of the components
/// contained in component_list.
fn subset(&self, component_list: &[usize]) -> Self;
}

#[derive(Clone)]
pub struct EquationOfState<I, R> {
pub ideal_gas: Arc<I>,
pub residual: Arc<R>,
components: usize,
}

impl<I: IdealGas, R: Residual> Display for EquationOfState<I, R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} {}",
self.ideal_gas.to_string(),
self.residual.to_string()
)
}
}

impl<I: IdealGas, R: Residual> EquationOfState<I, R> {
impl<I, R> EquationOfState<I, R> {
pub fn new(ideal_gas: Arc<I>, residual: Arc<R>) -> Self {
// assert_eq!(residual.components(), ideal_gas.components());
let components = residual.components();
Self {
ideal_gas,
residual,
components,
}
}
}

impl<I: IdealGas, R: Residual> IdealGas for EquationOfState<I, R> {
fn evaluate_ideal_gas<D: DualNum<f64> + Copy>(&self, state: &StateHD<D>) -> D
where
dyn DeBroglieWavelength: DeBroglieWavelengthDual<D>,
{
self.ideal_gas.evaluate_ideal_gas(state)
impl<I: Components, R: Components> Components for EquationOfState<I, R> {
fn components(&self) -> usize {
assert_eq!(self.residual.components(), self.ideal_gas.components());
self.residual.components()
}

fn subset(&self, component_list: &[usize]) -> Self {
Expand All @@ -66,24 +56,19 @@ impl<I: IdealGas, R: Residual> IdealGas for EquationOfState<I, R> {
Arc::new(self.residual.subset(component_list)),
)
}

fn ideal_gas_model(&self) -> &Box<dyn DeBroglieWavelength> {
self.ideal_gas.ideal_gas_model()
}
}

impl<I: IdealGas, R: Residual> Residual for EquationOfState<I, R> {
fn components(&self) -> usize {
self.residual.components()
impl<I: IdealGas, R: Residual> IdealGas for EquationOfState<I, R> {
fn de_broglie_wavelength<D: DualNum<f64> + Copy>(&self, temperature: D) -> Array1<D> {
self.ideal_gas.de_broglie_wavelength(temperature)
}

fn subset(&self, component_list: &[usize]) -> Self {
Self::new(
Arc::new(self.ideal_gas.subset(component_list)),
Arc::new(self.residual.subset(component_list)),
)
fn ideal_gas_model(&self) -> String {
self.ideal_gas.ideal_gas_model()
}
}

impl<I: IdealGas, R: Residual> Residual for EquationOfState<I, R> {
fn compute_max_density(&self, moles: &Array1<f64>) -> f64 {
self.residual.compute_max_density(moles)
}
Expand Down
14 changes: 3 additions & 11 deletions feos-core/src/equation_of_state/residual.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use super::{HelmholtzEnergy, HelmholtzEnergyDual};
use super::{Components, HelmholtzEnergy, HelmholtzEnergyDual};
use crate::StateHD;
use crate::{EosError, EosResult, EosUnit};
use ndarray::prelude::*;
use num_dual::*;
use num_traits::{One, Zero};
use quantity::si::{SIArray1, SINumber, SIUnit};
use std::fmt;

/// A general equation of state.
pub trait Residual: Send + Sync + fmt::Display {
/// Return the number of components of the equation of state.
fn components(&self) -> usize;

/// Return an equation of state consisting of the components
/// contained in component_list.
fn subset(&self, component_list: &[usize]) -> Self;

pub trait Residual: Components + Send + Sync {
/// Return the maximum density in Angstrom^-3.
///
/// This value is used as an estimate for a liquid phase for phase
Expand Down Expand Up @@ -177,4 +169,4 @@ pub trait EntropyScaling {
moles: &SIArray1,
) -> EosResult<SINumber>;
fn thermal_conductivity_correlation(&self, s_res: f64, x: &Array1<f64>) -> EosResult<f64>;
}
}
Loading