Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.3] - 2025-05-28
### Changed
- Simplify the `Eigen` trait for better readable trait bounds. [#5](https://github.com/feos-org/feos-ad/pull/5)

## [0.2.2] - 2025-05-28
### Fixed
- Import `Eigen` to be able to calculate critical points for pure components and binary mixtures generically. [#4](https://github.com/feos-org/feos-ad/pull/4)
- Export `Eigen` to be able to calculate critical points for pure components and binary mixtures generically. [#4](https://github.com/feos-org/feos-ad/pull/4)

## [0.2.1] - 2025-04-14
### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "feos-ad"
version = "0.2.2"
version = "0.2.3"
authors = ["Philipp Rehner <prehner@ethz.ch"]
edition = "2021"
readme = "README.md"
Expand Down
22 changes: 11 additions & 11 deletions src/core/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<'a, E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize>
molefracs: SVector<D, N>,
) -> EosResult<Self>
where
SMatrix<DualVec<D, f64, Const<2>>, N, N>: Eigen<DualVec<D, f64, Const<2>>, N>,
Const<N>: Eigen<N>,
{
let moles = Moles::from_reduced(arr1(molefracs.map(|x| x.re()).as_slice()));
let state = State::critical_point(&eos.eos, Some(&moles), None, Default::default())?;
Expand All @@ -232,7 +232,7 @@ impl<E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize> Stat
molefracs: &SVector<DualVec<D, f64, Const<2>>, N>,
) -> SVector<DualVec<D, f64, Const<2>>, 2>
where
SMatrix<DualVec<D, f64, Const<2>>, N, N>: Eigen<DualVec<D, f64, Const<2>>, N>,
Const<N>: Eigen<N>,
{
// calculate M
let sqrt_z = molefracs.map(|z| z.sqrt());
Expand All @@ -249,7 +249,7 @@ impl<E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize> Stat
let m = m.component_mul(&z_mix) / temperature + SMatrix::identity();

// calculate smallest eigenvalue and corresponding eigenvector
let (l, u) = m.eigen();
let (l, u) = <Const<N> as Eigen<N>>::eigen(m);

let (_, _, _, c2) = third_derivative(
|s| {
Expand All @@ -268,20 +268,20 @@ impl<E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize> Stat
}
}

pub trait Eigen<D, const N: usize> {
fn eigen(&self) -> (D, SVector<D, N>);
pub trait Eigen<const N: usize> {
fn eigen<D: DualNum<f64> + Copy>(matrix: SMatrix<D, N, N>) -> (D, SVector<D, N>);
}

impl<D: DualNum<f64> + Copy> Eigen<D, 1> for SMatrix<D, 1, 1> {
fn eigen(&self) -> (D, SVector<D, 1>) {
let [[l]] = self.data.0;
impl Eigen<1> for Const<1> {
fn eigen<D: DualNum<f64> + Copy>(matrix: SMatrix<D, 1, 1>) -> (D, SVector<D, 1>) {
let [[l]] = matrix.data.0;
(l, SVector::from([D::one()]))
}
}

impl<D: DualNum<f64> + Copy> Eigen<D, 2> for SMatrix<D, 2, 2> {
fn eigen(&self) -> (D, SVector<D, 2>) {
let [[a, b], [_, c]] = self.data.0;
impl Eigen<2> for Const<2> {
fn eigen<D: DualNum<f64> + Copy>(matrix: SMatrix<D, 2, 2>) -> (D, SVector<D, 2>) {
let [[a, b], [_, c]] = matrix.data.0;
let l = (a + c - ((a - c).powi(2) + b * b * 4.0).sqrt()) * 0.5;
let u = SVector::from([D::one(), (l - a) / b]);
let u = u / (u[0] * u[0] + u[1] * u[1]).sqrt();
Expand Down