Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 29a0c74

Browse files
authored
Simplify the Eigen trait (#5)
1 parent 867907f commit 29a0c74

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.2.3] - 2025-05-28
10+
### Changed
11+
- Simplify the `Eigen` trait for better readable trait bounds. [#5](https://github.com/feos-org/feos-ad/pull/5)
12+
913
## [0.2.2] - 2025-05-28
1014
### Fixed
11-
- 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)
15+
- 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)
1216

1317
## [0.2.1] - 2025-04-14
1418
### Added

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "feos-ad"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
authors = ["Philipp Rehner <[email protected]"]
55
edition = "2021"
66
readme = "README.md"

src/core/state.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'a, E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize>
210210
molefracs: SVector<D, N>,
211211
) -> EosResult<Self>
212212
where
213-
SMatrix<DualVec<D, f64, Const<2>>, N, N>: Eigen<DualVec<D, f64, Const<2>>, N>,
213+
Const<N>: Eigen<N>,
214214
{
215215
let moles = Moles::from_reduced(arr1(molefracs.map(|x| x.re()).as_slice()));
216216
let state = State::critical_point(&eos.eos, Some(&moles), None, Default::default())?;
@@ -232,7 +232,7 @@ impl<E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize> Stat
232232
molefracs: &SVector<DualVec<D, f64, Const<2>>, N>,
233233
) -> SVector<DualVec<D, f64, Const<2>>, 2>
234234
where
235-
SMatrix<DualVec<D, f64, Const<2>>, N, N>: Eigen<DualVec<D, f64, Const<2>>, N>,
235+
Const<N>: Eigen<N>,
236236
{
237237
// calculate M
238238
let sqrt_z = molefracs.map(|z| z.sqrt());
@@ -249,7 +249,7 @@ impl<E: ResidualHelmholtzEnergy<N>, D: DualNum<f64> + Copy, const N: usize> Stat
249249
let m = m.component_mul(&z_mix) / temperature + SMatrix::identity();
250250

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

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

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

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

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

0 commit comments

Comments
 (0)