Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
70c3e74
Merge feos-ad functionalities into feos
prehner Aug 18, 2025
81b045e
rebase
prehner Aug 18, 2025
9ab473a
use first_derivative from quantity for virial coefficients
prehner Aug 18, 2025
3be6e39
Minor optimizations for the ideal gas models
prehner Aug 18, 2025
afaced3
Fix robustness issue in vle_pure_t and revive Estimator interface wit…
prehner Aug 18, 2025
58a038f
fix import
prehner Aug 18, 2025
f0fb586
fix Cargo.toml
prehner Aug 19, 2025
8e9757a
moved GcPcSaftAD and therefore concluded the feos-ad integration
prehner Aug 19, 2025
25c789e
update workflow
prehner Aug 19, 2025
81fc7f8
fix python for gc_pcsaft
prehner Aug 19, 2025
6640601
fixed for gc-pcsaft
prehner Aug 25, 2025
982f421
newest lints
prehner Aug 25, 2025
ba7d6ec
use derivatives with units for state properties
prehner Aug 25, 2025
6112b2a
remove nshare dependency
prehner Aug 25, 2025
3dd4d15
fix dft for PC-SAFT
prehner Aug 29, 2025
71eb3ac
Updated SAFT-VR Mie model
g-bauer Aug 27, 2025
15ff86e
Updated PeTS
g-bauer Aug 27, 2025
23b9348
fix test
prehner Aug 29, 2025
2826fa4
finalized adaption of PC-SAFT family
prehner Aug 30, 2025
24aeafe
update to pyo3 0.26
prehner Aug 30, 2025
9cfafbc
python bindings for the libraries that are already updated
prehner Aug 30, 2025
f80b34e
make ndarray optional (a bit of a mess in the polar terms though :/)
prehner Sep 3, 2025
38147a9
fix dft
prehner Sep 3, 2025
79c76d9
fix sign in hc term
prehner Sep 3, 2025
5d9dc3d
implement AD for all state constructors
prehner Sep 3, 2025
5664a09
updated saftvrqmie and UV
prehner Sep 4, 2025
c2fca34
bikeshedding for the IdealGas traits
prehner Sep 5, 2025
424b778
more ideal gas bikeshedding
prehner Sep 5, 2025
687212a
final(?) ideal gas bikeshed
prehner Sep 5, 2025
4738d5c
fixed stability_analysis
prehner Sep 9, 2025
b6dcf3f
fix markdown and String representations of states
prehner Sep 9, 2025
043875b
fix some regression in the parameter handling in python
prehner Sep 9, 2025
e182cc9
add getters for Identifier
prehner Sep 9, 2025
3d631bc
remove some string allocations
prehner Sep 9, 2025
987bd7f
rebase
prehner Sep 12, 2025
01e98ab
pretty significant bug, no idea why it did not show earlier
prehner Sep 12, 2025
0277e02
fixes for num_dual change
prehner Sep 17, 2025
e575ae6
Fix bubble Newton step for bubble points at given pressure
prehner Sep 17, 2025
b03222a
Add tests for newton methods within bubble and dew point iterations
prehner Sep 17, 2025
f6be6aa
reactivate (and fix) PC-SAFT tests
prehner Sep 17, 2025
d352ed7
update num-dual and quantity dependencies
prehner Sep 28, 2025
bb8f5e5
get rid of most Arcs
prehner Sep 28, 2025
935b651
remove the ResidualConst trait
prehner Sep 29, 2025
6472647
replace PureProperty and BinaryProperty with new Estimator struct
prehner Sep 29, 2025
d51c8d9
rebase
prehner Oct 10, 2025
898c917
adding final docstrings to feos-core
prehner Oct 10, 2025
ba952f5
removed stuff that accidentally ended up here
prehner Oct 10, 2025
3ed1307
make python package usable without the "ad" feature
prehner Oct 10, 2025
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
get rid of most Arcs
  • Loading branch information
prehner committed Sep 28, 2025
commit bb8f5e52034ebed8a7c3fdf02f0798d7cd54dca0
2 changes: 1 addition & 1 deletion crates/feos-core/src/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl ResidualDyn for PengRobinson {
let x = &state.molefracs;
let ak = &self
.tc
.map(|tc| (D::one() - (state.temperature / tc).sqrt()))
.map(|tc| D::one() - (state.temperature / tc).sqrt())
.component_mul(&self.kappa.map(D::from))
.map(|x| (x + 1.0).powi(2))
.component_mul(&self.a.map(D::from));
Expand Down
19 changes: 8 additions & 11 deletions crates/feos-core/src/equation_of_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use nalgebra::{
Const, DVector, DefaultAllocator, Dim, Dyn, OVector, SVector, U1, allocator::Allocator,
};
use num_dual::DualNum;
use quantity::{Energy, MolarEnergy, MolarWeight, Moles, Temperature, Volume};
use quantity::{Energy, MolarEnergy, Moles, Temperature, Volume};

mod residual;
pub use residual::{Molarweight, NoResidual, Residual, ResidualConst, ResidualDyn, Subset};
Expand All @@ -18,6 +18,13 @@ pub struct EquationOfState<I, R> {
pub residual: R,
}

impl<I, R> Deref for EquationOfState<I, R> {
type Target = R;
fn deref(&self) -> &R {
&self.residual
}
}

impl<I, R> EquationOfState<I, R> {
/// Return a new [EquationOfState] with the given ideal gas
/// and residual models.
Expand Down Expand Up @@ -95,16 +102,6 @@ impl<I: Clone, R: ResidualConst<N, D>, D: DualNum<f64> + Copy, const N: usize> R
}
}

impl<I, R: Molarweight<N, D>, N: Dim, D: DualNum<f64> + Copy> Molarweight<N, D>
for EquationOfState<I, R>
where
DefaultAllocator: Allocator<N>,
{
fn molar_weight(&self) -> MolarWeight<OVector<D, N>> {
self.residual.molar_weight()
}
}

/// Ideal gas Helmholtz energy contribution.
pub trait IdealGas<D = f64> {
/// Implementation of an ideal gas model in terms of the
Expand Down
1 change: 0 additions & 1 deletion crates/feos-core/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use quantity::*;
/// # use feos_core::{FeosResult, StateBuilder};
/// # use feos_core::cubic::{PengRobinson, PengRobinsonParameters};
/// # use quantity::*;
/// # use std::sync::Arc;
/// # use nalgebra::dvector;
/// # use approx::assert_relative_eq;
/// # use typenum::P3;
Expand Down
7 changes: 0 additions & 7 deletions crates/feos-core/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ where

Self {
temperature,
// molar_volume,
molefracs: molefracs.clone(),
partial_density,
}
Expand All @@ -100,7 +99,6 @@ where

Self {
temperature,
// molar_volume,
molefracs,
partial_density: partial_density.clone(),
}
Expand All @@ -109,14 +107,9 @@ where
// Since the molefracs can not be reproduced from moles if the density is zero,
// this constructor exists specifically for these cases.
pub(crate) fn new_virial(temperature: D, density: D, molefracs: &OVector<D, N>) -> Self {
// let volume = D::one();
let partial_density = molefracs * density;
// let moles = partial_density.map(|pd| pd * volume);
// let molefracs = molefracs.map(D::from);
Self {
temperature,
// volume,
// moles,
molefracs: molefracs.clone(),
partial_density,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/feos-dft/src/adsorption/external_potential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ndarray::{Array1, Array2, Axis as Axis_nd};
#[cfg(feature = "rayon")]
use quantity::Length;
use std::f64::consts::PI;
use std::ops::Deref;

const DELTA_STEELE: f64 = 3.35;

Expand Down Expand Up @@ -73,7 +74,7 @@ pub trait FluidParameters {
fn sigma_ff(&self) -> DVector<f64>;
}

impl<T: FluidParameters> FluidParameters for std::sync::Arc<T> {
impl<C: Deref<Target = T>, T: FluidParameters> FluidParameters for C {
fn epsilon_k_ff(&self) -> DVector<f64> {
T::epsilon_k_ff(self)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/feos-dft/src/adsorption/pore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ pub trait PoreSpecification<D: Dimension> {
}

/// Density profile and properties of a confined system in arbitrary dimensions.
#[derive(Clone)]
pub struct PoreProfile<D: Dimension, F> {
pub profile: DFTProfile<D, F>,
pub grand_potential: Option<Energy>,
Expand Down Expand Up @@ -165,7 +164,7 @@ where
.profile
.bulk
.eos
.bond_integrals(temperature, &exp_pot, &convolver);
.bond_integrals(temperature, &exp_pot, convolver.as_ref());
self.profile.integrate_reduced_segments(&(exp_pot * bonds))
}

Expand Down
24 changes: 11 additions & 13 deletions crates/feos-dft/src/convolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use num_dual::*;
use num_traits::Zero;
use rustdct::DctNum;
use std::ops::{AddAssign, MulAssign, SubAssign};
use std::sync::Arc;

mod periodic_convolver;
mod transform;
Expand Down Expand Up @@ -42,12 +41,12 @@ pub(crate) struct BulkConvolver<T> {

impl<T: DualNum<f64> + Copy + Send + Sync> BulkConvolver<T> {
#[expect(clippy::new_ret_no_self)]
pub(crate) fn new(weight_functions: Vec<WeightFunctionInfo<T>>) -> Arc<dyn Convolver<T, Ix0>> {
pub(crate) fn new(weight_functions: Vec<WeightFunctionInfo<T>>) -> Box<dyn Convolver<T, Ix0>> {
let weight_constants = weight_functions
.into_iter()
.map(|w| w.weight_constants(Zero::zero(), 0))
.collect();
Arc::new(Self { weight_constants })
Box::new(Self { weight_constants })
}
}

Expand Down Expand Up @@ -112,7 +111,6 @@ impl<T, D: Dimension> FFTWeightFunctions<T, D> {
/// compute convolutions in Fourier space.
///
/// Parametrized over the data type `T` and the dimension `D`.
#[derive(Clone)]
pub struct ConvolverFFT<T, D: Dimension> {
/// k vectors
k_abs: Array<f64, D>,
Expand All @@ -121,9 +119,9 @@ pub struct ConvolverFFT<T, D: Dimension> {
/// Lanczos sigma factor
lanczos_sigma: Option<Array<f64, D>>,
/// Possibly curvilinear Fourier transform in the first dimension
transform: Arc<dyn FourierTransform<T>>,
transform: Box<dyn FourierTransform<T>>,
/// Vector of additional cartesian Fourier transforms in the other dimensions
cartesian_transforms: Vec<Arc<CartesianTransform<T>>>,
cartesian_transforms: Vec<CartesianTransform<T>>,
}

impl<T, D: Dimension + RemoveAxis + 'static> ConvolverFFT<T, D>
Expand All @@ -138,7 +136,7 @@ where
grid: &Grid,
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Arc<dyn Convolver<T, D>> {
) -> Box<dyn Convolver<T, D>> {
match grid {
Grid::Polar(r) => CurvilinearConvolver::new(r, &[], weight_functions, lanczos),
Grid::Spherical(r) => CurvilinearConvolver::new(r, &[], weight_functions, lanczos),
Expand Down Expand Up @@ -170,7 +168,7 @@ where
cartesian_axes: &[&Axis],
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Arc<dyn Convolver<T, D>> {
) -> Box<dyn Convolver<T, D>> {
// initialize the Fourier transform
let mut cartesian_transforms = Vec::with_capacity(cartesian_axes.len());
let mut k_vec = Vec::with_capacity(cartesian_axes.len() + 1);
Expand Down Expand Up @@ -267,7 +265,7 @@ where
}

// Return `FFTConvolver<T, D>`
Arc::new(Self {
Box::new(Self {
k_abs,
weight_functions: fft_weight_functions,
lanczos_sigma,
Expand Down Expand Up @@ -550,8 +548,8 @@ where
/// The curvilinear convolver accounts for the shift that has to be performed
/// for spherical and polar transforms.
struct CurvilinearConvolver<T, D> {
convolver: Arc<dyn Convolver<T, D>>,
convolver_boundary: Arc<dyn Convolver<T, D>>,
convolver: Box<dyn Convolver<T, D>>,
convolver_boundary: Box<dyn Convolver<T, D>>,
}

impl<T, D: Dimension + RemoveAxis + 'static> CurvilinearConvolver<T, D>
Expand All @@ -567,8 +565,8 @@ where
z: &[&Axis],
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Arc<dyn Convolver<T, D>> {
Arc::new(Self {
) -> Box<dyn Convolver<T, D>> {
Box::new(Self {
convolver: ConvolverFFT::new(Some(r), z, weight_functions, lanczos),
convolver_boundary: ConvolverFFT::new(None, z, weight_functions, lanczos),
})
Expand Down
9 changes: 4 additions & 5 deletions crates/feos-dft/src/convolver/periodic_convolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::f64::consts::PI;
use std::ops::AddAssign;
use std::sync::Arc;

#[derive(Clone)]
pub struct PeriodicConvolver<T, D: Dimension> {
/// k vectors
k_abs: Array<f64, D>,
Expand All @@ -36,7 +35,7 @@ where
angle: Angle,
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Arc<dyn Convolver<T, D>> {
) -> Box<dyn Convolver<T, D>> {
let f = |k: &mut Array<f64, D::Larger>| {
let k_y =
(&k.index_axis(Axis(0), 1) - &k.index_axis(Axis(0), 0) * angle.cos()) / angle.sin();
Expand All @@ -50,7 +49,7 @@ where
angles: [Angle; 3],
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Arc<dyn Convolver<T, D>> {
) -> Box<dyn Convolver<T, D>> {
let f = |k: &mut Array<f64, D::Larger>| {
let [alpha, beta, gamma] = angles;
let [k_u, k_v, k_w] = [0, 1, 2].map(|i| k.index_axis(Axis(0), i));
Expand All @@ -73,7 +72,7 @@ where
non_orthogonal_correction: F,
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Arc<dyn Convolver<T, D>> {
) -> Box<dyn Convolver<T, D>> {
// initialize the Fourier transform
let mut planner = FftPlanner::new();
let mut forward_transforms = Vec::with_capacity(axes.len());
Expand Down Expand Up @@ -175,7 +174,7 @@ where
});
}

Arc::new(Self {
Box::new(Self {
k_abs,
weight_functions: fft_weight_functions,
lanczos_sigma,
Expand Down
20 changes: 10 additions & 10 deletions crates/feos-dft/src/convolver/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub(super) struct CartesianTransform<T> {

impl<T: DualNum<f64> + DctNum> CartesianTransform<T> {
#[expect(clippy::new_ret_no_self)]
pub(super) fn new(axis: &Axis) -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
pub(super) fn new(axis: &Axis) -> (Box<dyn FourierTransform<T>>, Array1<f64>) {
let (s, k) = Self::init(axis);
(Arc::new(s), k)
(Box::new(s), k)
}

pub(super) fn new_cartesian(axis: &Axis) -> (Arc<Self>, Array1<f64>) {
pub(super) fn new_cartesian(axis: &Axis) -> (Self, Array1<f64>) {
let (s, k) = Self::init(axis);
(Arc::new(s), k)
(s, k)
}

fn init(axis: &Axis) -> (Self, Array1<f64>) {
Expand Down Expand Up @@ -132,12 +132,12 @@ pub(super) struct SphericalTransform<T> {

impl<T: DualNum<f64> + DctNum> SphericalTransform<T> {
#[expect(clippy::new_ret_no_self)]
pub(super) fn new(axis: &Axis) -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
pub(super) fn new(axis: &Axis) -> (Box<dyn FourierTransform<T>>, Array1<f64>) {
let points = axis.grid.len();
let length = axis.length();
let k_grid: Array1<_> = (0..=points).map(|v| PI * v as f64 / length).collect();
(
Arc::new(Self {
Box::new(Self {
r_grid: axis.grid.clone(),
k_grid: k_grid.clone(),
dct: DctPlanner::new().plan_dct2(points),
Expand Down Expand Up @@ -229,7 +229,7 @@ pub(super) struct PolarTransform<T: DctNum> {

impl<T: DualNum<f64> + DctNum> PolarTransform<T> {
#[expect(clippy::new_ret_no_self)]
pub(super) fn new(axis: &Axis) -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
pub(super) fn new(axis: &Axis) -> (Box<dyn FourierTransform<T>>, Array1<f64>) {
let points = axis.grid.len();

let mut alpha = 0.002_f64;
Expand Down Expand Up @@ -268,7 +268,7 @@ impl<T: DualNum<f64> + DctNum> PolarTransform<T> {
ifft.process(jv.as_slice_mut().unwrap());

(
Arc::new(Self {
Box::new(Self {
r_grid: axis.grid.clone(),
k_grid: k_grid.clone(),
fft,
Expand Down Expand Up @@ -335,8 +335,8 @@ pub(super) struct NoTransform();

impl NoTransform {
#[expect(clippy::new_ret_no_self)]
pub(super) fn new<T: DualNum<f64>>() -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
(Arc::new(Self()), arr1(&[0.0]))
pub(super) fn new<T: DualNum<f64>>() -> (Box<dyn FourierTransform<T>>, Array1<f64>) {
(Box::new(Self()), arr1(&[0.0]))
}
}

Expand Down
23 changes: 2 additions & 21 deletions crates/feos-dft/src/functional.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::adsorption::FluidParameters;
use crate::convolver::Convolver;
use crate::functional_contribution::*;
use crate::ideal_chain_contribution::IdealChainContribution;
use crate::solvation::PairPotential;
use crate::weight_functions::{WeightFunction, WeightFunctionInfo, WeightFunctionShape};
use feos_core::{EquationOfState, FeosResult, Residual, ResidualDyn, StateHD};
use nalgebra::{DVector, dvector};
Expand All @@ -13,7 +11,6 @@ use petgraph::graph::{Graph, UnGraph};
use petgraph::visit::EdgeRef;
use std::borrow::Cow;
use std::ops::{Deref, MulAssign};
use std::sync::Arc;

impl<I: Clone, F: HelmholtzEnergyFunctionalDyn> HelmholtzEnergyFunctionalDyn
for EquationOfState<Vec<I>, F>
Expand All @@ -36,22 +33,6 @@ impl<I: Clone, F: HelmholtzEnergyFunctionalDyn> HelmholtzEnergyFunctionalDyn
}
}

impl<I, F: PairPotential> PairPotential for EquationOfState<I, F> {
fn pair_potential(&self, i: usize, r: &Array1<f64>, temperature: f64) -> Array2<f64> {
self.residual.pair_potential(i, r, temperature)
}
}

impl<I, F: FluidParameters> FluidParameters for EquationOfState<I, F> {
fn epsilon_k_ff(&self) -> DVector<f64> {
self.residual.epsilon_k_ff()
}

fn sigma_ff(&self) -> DVector<f64> {
self.residual.sigma_ff()
}
}

/// Different representations for molecules within DFT.
pub enum MoleculeShape<'a> {
/// For spherical molecules, the number of components.
Expand Down Expand Up @@ -135,7 +116,7 @@ pub trait HelmholtzEnergyFunctional: Residual {
&self,
temperature: N,
density: &Array<N, D::Larger>,
convolver: &Arc<dyn Convolver<N, D>>,
convolver: &dyn Convolver<N, D>,
) -> FeosResult<(Array<N, D>, Array<N, D::Larger>)>
where
D: Dimension,
Expand Down Expand Up @@ -170,7 +151,7 @@ pub trait HelmholtzEnergyFunctional: Residual {
&self,
temperature: N,
exponential: &Array<N, D::Larger>,
convolver: &Arc<dyn Convolver<N, D>>,
convolver: &dyn Convolver<N, D>,
) -> Array<N, D::Larger>
where
D: Dimension,
Expand Down
Loading
Loading