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: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ keywords = [
categories = ["science"]

[workspace.dependencies]
quantity = "0.14"
num-dual = "0.14"
quantity = "0.15"
num-dual = "0.15"
ndarray = "0.17"
nalgebra = "0.35"
thiserror = "2.0"
Expand Down
7 changes: 3 additions & 4 deletions crates/feos-core/src/ad/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod properties;
pub use dataset::*;
pub use properties::*;

pub(crate) type Gradient<const P: usize> = DualSVec<f64, f64, P>;
pub(crate) type Gradient<const P: usize> = DualSVec<f64, P>;

/// A model that can be evaluated with derivatives of its parameters.
pub trait ParametersAD<N: Dim>: Residual<N>
Expand All @@ -23,7 +23,7 @@ where
/// defines the canonical parameter order.
///
/// Set `differentiable` to `false` for fixed parameters.
fn build<D: DualNum<f64, Inner = f64> + Copy>(
fn build<D: DualNum<Primitive = f64, Inner = f64> + Copy>(
f: impl FnMut(&'static str, bool) -> D,
) -> Self::Lifted<D>;

Expand Down Expand Up @@ -66,8 +66,7 @@ where
idx += 1;
let mut d = Gradient::<P>::from(parameter_values[i]);
if let Some(seed_idx) = derivative_names.iter().position(|&n| n == name) {
d.eps =
Derivative::<_, _, Const<P>, _>::derivative_generic(Const::<P>, U1, seed_idx);
d.eps = Derivative::<_, Const<P>, _>::derivative_generic(Const::<P>, U1, seed_idx);
}
d
})
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/ad/properties/boiling_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
type Unit = _Temperature;
const REFERENCE: Temperature = KELVIN;

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Temperature<D>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
type Unit = _Pressure;
const REFERENCE: Pressure = PASCAL;

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Pressure<D>>
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/ad/properties/dew_point_pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
type Unit = _Pressure;
const REFERENCE: Pressure = PASCAL;

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Pressure<D>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
type Unit = _MolarEnergy;
const REFERENCE: MolarEnergy = MolarEnergy::new(1.0);

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<MolarEnergy<D>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
type Unit = _Density;
const REFERENCE: Density = Density::new(1000.0);

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Density<D>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/ad/properties/liquid_density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
type Unit = _Density;
const REFERENCE: Density = Density::new(1000.0);

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Density<D>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/ad/properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
const REFERENCE: Quantity<f64, Self::Unit>;

/// Evaluate the property for an arbitrary derivative.
fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Quantity<D, Self::Unit>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
type Unit = _MolarEntropy;
const REFERENCE: MolarEntropy = MolarEntropy::new(1.0);

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<MolarEntropy<D>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/ad/properties/vapor_pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
type Unit = _Pressure;
const REFERENCE: Pressure = PASCAL;

fn evaluate<E: Residual<N, D>, D: DualNum<f64, Inner = f64> + Copy>(
fn evaluate<E: Residual<N, D>, D: DualNum<Primitive = f64, Inner = f64> + Copy>(
&self,
eos: &E,
) -> FeosResult<Pressure<D>> {
Expand Down
4 changes: 2 additions & 2 deletions crates/feos-core/src/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ impl ResidualDyn for PengRobinson {
self.tc.len()
}

fn compute_max_density<D: DualNum<f64> + Copy>(&self, molefracs: &DVector<D>) -> D {
fn compute_max_density<D: DualNum<Primitive = f64> + Copy>(&self, molefracs: &DVector<D>) -> D {
D::from(0.9) / molefracs.dot(&self.b.map(D::from))
}

fn reduced_helmholtz_energy_density_contributions<D: DualNum<f64> + Copy>(
fn reduced_helmholtz_energy_density_contributions<D: DualNum<Primitive = f64> + Copy>(
&self,
state: &StateHD<D>,
) -> Vec<(&'static str, D)> {
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/density_iteration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use nalgebra::{DefaultAllocator, Dim, OVector};
use num_dual::{Dual, DualNum, first_derivative};
use quantity::{Density, Pressure, Temperature};

pub fn density_iteration<E: Residual<N, D>, N: Dim, D: DualNum<f64> + Copy>(
pub fn density_iteration<E: Residual<N, D>, N: Dim, D: DualNum<Primitive = f64> + Copy>(
eos: &E,
temperature: Temperature<D>,
pressure: Pressure<D>,
Expand Down
35 changes: 18 additions & 17 deletions crates/feos-core/src/equation_of_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ impl<I, R: ResidualDyn> ResidualDyn for EquationOfState<Vec<I>, R> {
self.residual.components()
}

fn compute_max_density<D: DualNum<f64> + Copy>(&self, molefracs: &DVector<D>) -> D {
fn compute_max_density<D: DualNum<Primitive = f64> + Copy>(&self, molefracs: &DVector<D>) -> D {
self.residual.compute_max_density(molefracs)
}

fn reduced_helmholtz_energy_density_contributions<D: DualNum<f64> + Copy>(
fn reduced_helmholtz_energy_density_contributions<D: DualNum<Primitive = f64> + Copy>(
&self,
state: &StateHD<D>,
) -> Vec<(&'static str, D)> {
Expand All @@ -79,19 +79,20 @@ impl<I: Clone, R: Subset> Subset for EquationOfState<Vec<I>, R> {
}
}

impl<I: Clone, R: Residual<Const<N>, D>, D: DualNum<f64> + Copy, const N: usize>
impl<I: Clone, R: Residual<Const<N>, D>, D: DualNum<Primitive = f64> + Copy, const N: usize>
Residual<Const<N>, D> for EquationOfState<[I; N], R>
{
fn components(&self) -> usize {
N
}

type Real = EquationOfState<[I; N], R::Real>;
type Lifted<D2: DualNum<f64, Inner = D> + Copy> = EquationOfState<[I; N], R::Lifted<D2>>;
type Lifted<D2: DualNum<Primitive = f64, Inner = D> + Copy> =
EquationOfState<[I; N], R::Lifted<D2>>;
fn re(&self) -> Self::Real {
EquationOfState::new(self.ideal_gas.clone(), self.residual.re())
}
fn lift<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2> {
fn lift<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2> {
EquationOfState::new(self.ideal_gas.clone(), self.residual.lift())
}

Expand All @@ -118,7 +119,7 @@ pub trait IdealGas {
/// Implementation of an ideal gas model in terms of the
/// logarithm of the cubic thermal de Broglie wavelength
/// in units ln(A³) for each component in the system.
fn ln_lambda3<D: DualNum<f64> + Copy>(&self, temperature: D) -> D;
fn ln_lambda3<D: DualNum<Primitive = f64> + Copy>(&self, temperature: D) -> D;

/// The name of the ideal gas model.
fn ideal_gas_model(&self) -> &'static str;
Expand All @@ -128,9 +129,9 @@ pub trait IdealGas {
/// respect to parameters.
pub trait IdealGasAD<D = f64>: Clone {
type Real: IdealGasAD;
type Lifted<D2: DualNum<f64, Inner = D> + Copy>: IdealGasAD<D2>;
type Lifted<D2: DualNum<Primitive = f64, Inner = D> + Copy>: IdealGasAD<D2>;
fn re(&self) -> Self::Real;
fn lift<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2>;
fn lift<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2>;

/// Implementation of an ideal gas model in terms of the
/// logarithm of the cubic thermal de Broglie wavelength
Expand All @@ -142,14 +143,14 @@ pub trait IdealGasAD<D = f64>: Clone {
}

/// A total Helmholtz energy model consisting of a [Residual] model and an [IdealGas] part.
pub trait Total<N: Dim = Dyn, D: DualNum<f64> + Copy = f64>: Residual<N, D>
pub trait Total<N: Dim = Dyn, D: DualNum<Primitive = f64> + Copy = f64>: Residual<N, D>
where
DefaultAllocator: Allocator<N>,
{
type RealTotal: Total<N, f64>;
type LiftedTotal<D2: DualNum<f64, Inner = D> + Copy>: Total<N, D2>;
type LiftedTotal<D2: DualNum<Primitive = f64, Inner = D> + Copy>: Total<N, D2>;
fn re_total(&self) -> Self::RealTotal;
fn lift_total<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::LiftedTotal<D2>;
fn lift_total<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::LiftedTotal<D2>;

fn ideal_gas_model(&self) -> &'static str;

Expand Down Expand Up @@ -199,15 +200,15 @@ impl<
I: IdealGas + 'static,
C: Deref<Target = EquationOfState<Vec<I>, R>> + Clone,
R: ResidualDyn + 'static,
D: DualNum<f64> + Copy,
D: DualNum<Primitive = f64> + Copy,
> Total<Dyn, D> for C
{
type RealTotal = Self;
type LiftedTotal<D2: DualNum<f64, Inner = D> + Copy> = Self;
type LiftedTotal<D2: DualNum<Primitive = f64, Inner = D> + Copy> = Self;
fn re_total(&self) -> Self::RealTotal {
self.clone()
}
fn lift_total<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::LiftedTotal<D2> {
fn lift_total<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::LiftedTotal<D2> {
self.clone()
}

Expand All @@ -225,19 +226,19 @@ impl<
}
}

impl<I: IdealGasAD<D>, R: Residual<Const<N>, D>, D: DualNum<f64> + Copy, const N: usize>
impl<I: IdealGasAD<D>, R: Residual<Const<N>, D>, D: DualNum<Primitive = f64> + Copy, const N: usize>
Total<Const<N>, D> for EquationOfState<[I; N], R>
{
type RealTotal = EquationOfState<[I::Real; N], R::Real>;
type LiftedTotal<D2: DualNum<f64, Inner = D> + Copy> =
type LiftedTotal<D2: DualNum<Primitive = f64, Inner = D> + Copy> =
EquationOfState<[I::Lifted<D2>; N], R::Lifted<D2>>;
fn re_total(&self) -> Self::RealTotal {
EquationOfState::new(
self.ideal_gas.each_ref().map(|i| i.re()),
self.residual.re(),
)
}
fn lift_total<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::LiftedTotal<D2> {
fn lift_total<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::LiftedTotal<D2> {
EquationOfState::new(
self.ideal_gas.each_ref().map(|i| i.lift()),
self.residual.lift(),
Expand Down
34 changes: 18 additions & 16 deletions crates/feos-core/src/equation_of_state/residual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type Quot<T1, T2> = <T1 as Div<T2>>::Output;
/// Molar weight of all components.
///
/// Enables calculation of (mass) specific properties.
pub trait Molarweight<N: Dim = Dyn, D: DualNum<f64> + Copy = f64>
pub trait Molarweight<N: Dim = Dyn, D: DualNum<Primitive = f64> + Copy = f64>
where
DefaultAllocator: Allocator<N>,
{
fn molar_weight(&self) -> MolarWeight<OVector<D, N>>;
}

impl<C: Deref<Target = T>, T: Molarweight<N, D>, N: Dim, D: DualNum<f64> + Copy> Molarweight<N, D>
for C
impl<C: Deref<Target = T>, T: Molarweight<N, D>, N: Dim, D: DualNum<Primitive = f64> + Copy>
Molarweight<N, D> for C
where
DefaultAllocator: Allocator<N>,
{
Expand Down Expand Up @@ -62,23 +62,25 @@ pub trait ResidualDyn {
/// equilibria and other iterations. It is not explicitly meant to
/// be a mathematical limit for the density (if those exist in the
/// equation of state anyways).
fn compute_max_density<D: DualNum<f64> + Copy>(&self, molefracs: &DVector<D>) -> D;
fn compute_max_density<D: DualNum<Primitive = f64> + Copy>(&self, molefracs: &DVector<D>) -> D;

/// Evaluate the reduced Helmholtz energy density of each individual contribution
/// and return them together with a string representation of the contribution.
fn reduced_helmholtz_energy_density_contributions<D: DualNum<f64> + Copy>(
fn reduced_helmholtz_energy_density_contributions<D: DualNum<Primitive = f64> + Copy>(
&self,
state: &StateHD<D>,
) -> Vec<(&'static str, D)>;
}

impl<C: Deref<Target = T> + Clone, T: ResidualDyn, D: DualNum<f64> + Copy> Residual<Dyn, D> for C {
impl<C: Deref<Target = T> + Clone, T: ResidualDyn, D: DualNum<Primitive = f64> + Copy>
Residual<Dyn, D> for C
{
type Real = Self;
type Lifted<D2: DualNum<f64, Inner = D> + Copy> = Self;
type Lifted<D2: DualNum<Primitive = f64, Inner = D> + Copy> = Self;
fn re(&self) -> Self::Real {
self.clone()
}
fn lift<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2> {
fn lift<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2> {
self.clone()
}
fn components(&self) -> usize {
Expand All @@ -96,7 +98,7 @@ impl<C: Deref<Target = T> + Clone, T: ResidualDyn, D: DualNum<f64> + Copy> Resid
}

/// A residual Helmholtz energy model.
pub trait Residual<N: Dim = Dyn, D: DualNum<f64> + Copy = f64>: Clone
pub trait Residual<N: Dim = Dyn, D: DualNum<Primitive = f64> + Copy = f64>: Clone
where
DefaultAllocator: Allocator<N>,
{
Expand All @@ -114,13 +116,13 @@ where
type Real: Residual<N>;

/// The residual model with the model parameters lifted to a higher dual number.
type Lifted<D2: DualNum<f64, Inner = D> + Copy>: Residual<N, D2>;
type Lifted<D2: DualNum<Primitive = f64, Inner = D> + Copy>: Residual<N, D2>;

/// Return the real part of the residual model.
fn re(&self) -> Self::Real;

/// Return the lifted residual model.
fn lift<D2: DualNum<f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2>;
fn lift<D2: DualNum<Primitive = f64, Inner = D> + Copy>(&self) -> Self::Lifted<D2>;

/// Return the maximum density in Angstrom^-3.
///
Expand Down Expand Up @@ -303,7 +305,7 @@ where
molefracs: &OVector<D, N>,
) -> (D, D, D, D, D) {
let molar_volume = density.recip();
let (a, da, d2a) = hessian::<_, _, _, U2, _>(
let (a, da, d2a) = hessian::<_, _, U2, _>(
partial(
|vt: SVector<_, 2>, x: &OVector<_, N>| {
let [[v, t]] = vt.data.0;
Expand Down Expand Up @@ -418,7 +420,7 @@ where
}

/// Reference values and residual entropy correlations for entropy scaling.
pub trait EntropyScaling<N: Dim = Dyn, D: DualNum<f64> + Copy = f64>
pub trait EntropyScaling<N: Dim = Dyn, D: DualNum<Primitive = f64> + Copy = f64>
where
DefaultAllocator: Allocator<N>,
{
Expand All @@ -445,7 +447,7 @@ where
fn thermal_conductivity_correlation(&self, s_res: D, x: &OVector<D, N>) -> D;
}

impl<C: Deref<Target = T>, T: EntropyScaling<N, D>, N: Dim, D: DualNum<f64> + Copy>
impl<C: Deref<Target = T>, T: EntropyScaling<N, D>, N: Dim, D: DualNum<Primitive = f64> + Copy>
EntropyScaling<N, D> for C
where
DefaultAllocator: Allocator<N>,
Expand Down Expand Up @@ -502,11 +504,11 @@ impl ResidualDyn for NoResidual {
self.0
}

fn compute_max_density<D: DualNum<f64> + Copy>(&self, _: &DVector<D>) -> D {
fn compute_max_density<D: DualNum<Primitive = f64> + Copy>(&self, _: &DVector<D>) -> D {
D::one()
}

fn reduced_helmholtz_energy_density_contributions<D: DualNum<f64> + Copy>(
fn reduced_helmholtz_energy_density_contributions<D: DualNum<Primitive = f64> + Copy>(
&self,
_: &StateHD<D>,
) -> Vec<(&'static str, D)> {
Expand Down
2 changes: 1 addition & 1 deletion crates/feos-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ mod tests {
"NoIdealGas"
}

fn ln_lambda3<D: DualNum<f64> + Copy>(&self, _: D) -> D {
fn ln_lambda3<D: DualNum<Primitive = f64> + Copy>(&self, _: D) -> D {
unreachable!()
}
}
Expand Down
Loading