Skip to content

Commit 13d6ac6

Browse files
committed
Update quantity to 0.13 and remove typenum dependency (#328)
1 parent 1cc94ff commit 13d6ac6

File tree

40 files changed

+149
-160
lines changed

40 files changed

+149
-160
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Breaking]
8+
### Packaging
9+
- Updated `quantity` dependency to 0.13 and removed the `typenum` dependency. [#323](https://github.com/feos-org/feos/pull/323)
10+
711
## [Unreleased]
812
### Added
913
- Added `py-feos` tests to GitHub Actions and moved `pyo3/extension-module` feature to `pyproject.toml`. [#334](https://github.com/feos-org/feos/pull/334)

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ keywords = [
2222
categories = ["science"]
2323

2424
[workspace.dependencies]
25-
quantity = "0.12"
25+
quantity = "0.13"
2626
num-dual = "0.13"
2727
ndarray = "0.17"
2828
nalgebra = "0.34"
@@ -33,7 +33,6 @@ serde = "1.0"
3333
serde_json = "1.0"
3434
indexmap = "2.0"
3535
itertools = "0.14"
36-
typenum = "1.16"
3736
rayon = "1.11"
3837
petgraph = "0.8"
3938
rustdct = "0.7"

crates/feos-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ serde = { workspace = true, features = ["derive"] }
2525
serde_json = { workspace = true, features = ["preserve_order"] }
2626
indexmap = { workspace = true, features = ["serde"] }
2727
rayon = { workspace = true, optional = true }
28-
typenum = { workspace = true }
2928
itertools = { workspace = true }
3029

3130
[dev-dependencies]

crates/feos-core/src/equation_of_state/residual.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use nalgebra::{DVector, DefaultAllocator, Dim, Dyn, OMatrix, OVector, U1, alloca
33
use num_dual::{DualNum, Gradients, partial, partial2, second_derivative, third_derivative};
44
use quantity::ad::first_derivative;
55
use quantity::*;
6-
use std::ops::Deref;
6+
use std::ops::{Deref, Div};
77
use std::sync::Arc;
8-
use typenum::Quot;
8+
9+
type Quot<T1, T2> = <T1 as Div<T2>>::Output;
910

1011
/// Molar weight of all components.
1112
///

crates/feos-core/src/lib.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![warn(clippy::allow_attributes)]
44
use quantity::{Quantity, SIUnit};
55
use std::ops::{Div, Mul};
6-
use typenum::Integer;
76

87
/// Print messages with level `Verbosity::Iter` or higher.
98
#[macro_export]
@@ -132,20 +131,20 @@ const fn powi(x: f64, n: i32) -> f64 {
132131
/// Conversion between reduced units and SI units.
133132
pub trait ReferenceSystem {
134133
type Inner;
135-
type T: Integer;
136-
type L: Integer;
137-
type M: Integer;
138-
type I: Integer;
139-
type THETA: Integer;
140-
type N: Integer;
141-
type J: Integer;
142-
const FACTOR: f64 = powi(REFERENCE_VALUES[0], Self::T::I32)
143-
* powi(REFERENCE_VALUES[1], Self::L::I32)
144-
* powi(REFERENCE_VALUES[2], Self::M::I32)
145-
* powi(REFERENCE_VALUES[3], Self::I::I32)
146-
* powi(REFERENCE_VALUES[4], Self::THETA::I32)
147-
* powi(REFERENCE_VALUES[5], Self::N::I32)
148-
* powi(REFERENCE_VALUES[6], Self::J::I32);
134+
const T: i8;
135+
const L: i8;
136+
const M: i8;
137+
const I: i8;
138+
const THETA: i8;
139+
const N: i8;
140+
const J: i8;
141+
const FACTOR: f64 = powi(REFERENCE_VALUES[0], Self::T as i32)
142+
* powi(REFERENCE_VALUES[1], Self::L as i32)
143+
* powi(REFERENCE_VALUES[2], Self::M as i32)
144+
* powi(REFERENCE_VALUES[3], Self::I as i32)
145+
* powi(REFERENCE_VALUES[4], Self::THETA as i32)
146+
* powi(REFERENCE_VALUES[5], Self::N as i32)
147+
* powi(REFERENCE_VALUES[6], Self::J as i32);
149148

150149
fn from_reduced(value: Self::Inner) -> Self
151150
where
@@ -161,17 +160,25 @@ pub trait ReferenceSystem {
161160
}
162161

163162
/// Conversion to and from reduced units
164-
impl<Inner, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer>
165-
ReferenceSystem for Quantity<Inner, SIUnit<T, L, M, I, THETA, N, J>>
163+
impl<
164+
Inner,
165+
const T: i8,
166+
const L: i8,
167+
const M: i8,
168+
const I: i8,
169+
const THETA: i8,
170+
const N: i8,
171+
const J: i8,
172+
> ReferenceSystem for Quantity<Inner, SIUnit<T, L, M, I, THETA, N, J>>
166173
{
167174
type Inner = Inner;
168-
type T = T;
169-
type L = L;
170-
type M = M;
171-
type I = I;
172-
type THETA = THETA;
173-
type N = N;
174-
type J = J;
175+
const T: i8 = T;
176+
const L: i8 = L;
177+
const M: i8 = M;
178+
const I: i8 = I;
179+
const THETA: i8 = THETA;
180+
const N: i8 = N;
181+
const J: i8 = J;
175182
fn from_reduced(value: Inner) -> Self
176183
where
177184
Inner: Mul<f64, Output = Inner>,

crates/feos-core/src/phase_equilibria/bubble_dew.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use ndarray::Array1;
1212
use num_dual::linalg::LU;
1313
use num_dual::{DualNum, DualStruct, Gradients};
1414
use quantity::{Density, Dimensionless, Moles, Pressure, Quantity, RGAS, SIUnit, Temperature};
15-
use typenum::{N1, N2, P1, Z0};
1615

1716
const MAX_ITER_INNER: usize = 5;
1817
const TOL_INNER: f64 = 1e-9;
@@ -94,7 +93,7 @@ impl<D: DualNum<f64> + Copy> TemperatureOrPressure<D> for Temperature<D> {
9493
// used instead of the explicit unit. Maybe the type is too complicated for the
9594
// compiler?
9695
impl<D: DualNum<f64> + Copy> TemperatureOrPressure<D>
97-
for Quantity<D, SIUnit<N2, N1, P1, Z0, Z0, Z0, Z0>>
96+
for Quantity<D, SIUnit<-2, -1, 1, 0, 0, 0, 0>>
9897
{
9998
type Other = Temperature<D>;
10099
const IDENTIFIER: &'static str = "pressure";

crates/feos-core/src/state/builder.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ use quantity::*;
1414
/// # use quantity::*;
1515
/// # use nalgebra::dvector;
1616
/// # use approx::assert_relative_eq;
17-
/// # use typenum::P3;
1817
/// # fn main() -> FeosResult<()> {
1918
/// // Create a state for given T,V,N
2019
/// let eos = &PengRobinson::new(PengRobinsonParameters::new_simple(&[369.8], &[41.9 * 1e5], &[0.15], &[15.0])?);
2120
/// let state = StateBuilder::new(&eos)
2221
/// .temperature(300.0 * KELVIN)
23-
/// .volume(12.5 * METER.powi::<P3>())
22+
/// .volume(12.5 * METER.powi::<3>())
2423
/// .moles(&(dvector![2.5] * MOL))
2524
/// .build()?;
26-
/// assert_eq!(state.density, 0.2 * MOL / METER.powi::<P3>());
25+
/// assert_eq!(state.density, 0.2 * MOL / METER.powi::<3>());
2726
///
2827
/// // For a pure component, the composition does not need to be specified.
2928
/// let eos = &PengRobinson::new(PengRobinsonParameters::new_simple(&[369.8], &[41.9 * 1e5], &[0.15], &[15.0])?);
3029
/// let state = StateBuilder::new(&eos)
3130
/// .temperature(300.0 * KELVIN)
32-
/// .volume(12.5 * METER.powi::<P3>())
31+
/// .volume(12.5 * METER.powi::<3>())
3332
/// .total_moles(2.5 * MOL)
3433
/// .build()?;
35-
/// assert_eq!(state.density, 0.2 * MOL / METER.powi::<P3>());
34+
/// assert_eq!(state.density, 0.2 * MOL / METER.powi::<3>());
3635
///
3736
/// // The state can be constructed without providing any extensive property.
3837
/// let eos = &PengRobinson::new(
@@ -45,10 +44,10 @@ use quantity::*;
4544
/// );
4645
/// let state = StateBuilder::new(&eos)
4746
/// .temperature(300.0 * KELVIN)
48-
/// .partial_density(&(dvector![0.2, 0.6] * MOL / METER.powi::<P3>()))
47+
/// .partial_density(&(dvector![0.2, 0.6] * MOL / METER.powi::<3>()))
4948
/// .build()?;
5049
/// assert_relative_eq!(state.molefracs, dvector![0.25, 0.75]);
51-
/// assert_relative_eq!(state.density, 0.8 * MOL / METER.powi::<P3>());
50+
/// assert_relative_eq!(state.density, 0.8 * MOL / METER.powi::<3>());
5251
/// # Ok(())
5352
/// # }
5453
/// ```

crates/feos-core/src/state/cache.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use nalgebra::allocator::Allocator;
22
use nalgebra::{DefaultAllocator, Dim, OVector, Scalar};
33
use quantity::*;
4+
use std::ops::Sub;
45
use std::sync::OnceLock;
5-
use typenum::Diff;
6+
7+
type Diff<T1, T2> = <T1 as Sub<T2>>::Output;
68

79
#[derive(Clone, Debug)]
810
#[expect(clippy::type_complexity)]

crates/feos-core/src/state/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -798,52 +798,51 @@ mod critical_point;
798798
mod tests {
799799
use super::*;
800800
use nalgebra::dvector;
801-
use typenum::P3;
802801

803802
#[test]
804803
fn test_validate() {
805804
let temperature = 298.15 * KELVIN;
806-
let density = 3000.0 * MOL / METER.powi::<P3>();
805+
let density = 3000.0 * MOL / METER.powi::<3>();
807806
let molefracs = dvector![0.03, 0.02, 0.05];
808807
assert!(validate(temperature, density, &molefracs).is_ok());
809808
}
810809

811810
#[test]
812811
fn test_negative_temperature() {
813812
let temperature = -298.15 * KELVIN;
814-
let density = 3000.0 * MOL / METER.powi::<P3>();
813+
let density = 3000.0 * MOL / METER.powi::<3>();
815814
let molefracs = dvector![0.03, 0.02, 0.05];
816815
assert!(validate(temperature, density, &molefracs).is_err());
817816
}
818817

819818
#[test]
820819
fn test_nan_temperature() {
821820
let temperature = f64::NAN * KELVIN;
822-
let density = 3000.0 * MOL / METER.powi::<P3>();
821+
let density = 3000.0 * MOL / METER.powi::<3>();
823822
let molefracs = dvector![0.03, 0.02, 0.05];
824823
assert!(validate(temperature, density, &molefracs).is_err());
825824
}
826825

827826
#[test]
828827
fn test_negative_mole_number() {
829828
let temperature = 298.15 * KELVIN;
830-
let density = 3000.0 * MOL / METER.powi::<P3>();
829+
let density = 3000.0 * MOL / METER.powi::<3>();
831830
let molefracs = dvector![-0.03, 0.02, 0.05];
832831
assert!(validate(temperature, density, &molefracs).is_err());
833832
}
834833

835834
#[test]
836835
fn test_nan_mole_number() {
837836
let temperature = 298.15 * KELVIN;
838-
let density = 3000.0 * MOL / METER.powi::<P3>();
837+
let density = 3000.0 * MOL / METER.powi::<3>();
839838
let molefracs = dvector![f64::NAN, 0.02, 0.05];
840839
assert!(validate(temperature, density, &molefracs).is_err());
841840
}
842841

843842
#[test]
844843
fn test_negative_density() {
845844
let temperature = 298.15 * KELVIN;
846-
let density = -3000.0 * MOL / METER.powi::<P3>();
845+
let density = -3000.0 * MOL / METER.powi::<3>();
847846
let molefracs = dvector![0.01, 0.02, 0.05];
848847
assert!(validate(temperature, density, &molefracs).is_err());
849848
}

crates/feos-dft/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ num-traits = { workspace = true }
2525
libm = { workspace = true }
2626
gauss-quad = { workspace = true, optional = true }
2727
petgraph = { workspace = true }
28-
typenum = { workspace = true }
2928

3029
feos-core = { workspace = true }
3130

0 commit comments

Comments
 (0)