Skip to content

Commit 84c7199

Browse files
committed
Update quantity to 0.13 and remove typenum dependency
1 parent baf5330 commit 84c7199

File tree

20 files changed

+85
-81
lines changed

20 files changed

+85
-81
lines changed

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 = { git = "https://github.com/itt-ustutt/quantity", branch = "consts_instead_of_typenum" }
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/phase_equilibria/tp_flash.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ impl<E: Residual> State<E> {
9090
log_iter!(verbosity, "{:-<77}", "");
9191
log_iter!(
9292
verbosity,
93-
" {:4} | | {:10.8} | {:10.8}",
93+
" {:4} | | {:10.8?} | {:10.8?}",
9494
0,
95-
new_vle_state.vapor().molefracs,
96-
new_vle_state.liquid().molefracs,
95+
new_vle_state.vapor().molefracs.data.as_vec(),
96+
new_vle_state.liquid().molefracs.data.as_vec(),
9797
);
9898

9999
let mut iter = 0;
@@ -279,11 +279,11 @@ impl<E: Residual> PhaseEquilibrium<E, 2> {
279279
let res = res_vec.norm();
280280
log_iter!(
281281
verbosity,
282-
" {:4} | {:14.8e} | {:.8} | {:.8}",
282+
" {:4} | {:14.8e} | {:.8?} | {:.8?}",
283283
iter,
284284
res,
285-
self.vapor().molefracs,
286-
self.liquid().molefracs,
285+
self.vapor().molefracs.data.as_vec(),
286+
self.liquid().molefracs.data.as_vec(),
287287
);
288288
if res < abs_tol {
289289
return Ok(true);

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

crates/feos-dft/src/adsorption/pore.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use quantity::{
1919
Temperature, Volume,
2020
};
2121
use rustdct::DctNum;
22-
use typenum::Diff;
22+
use std::ops::Sub;
2323

2424
const POTENTIAL_OFFSET: f64 = 2.0;
2525
const DEFAULT_GRID_POINTS: usize = 2048;
2626

27-
pub type _HenryCoefficient = Diff<_Moles, _Pressure>;
27+
pub type _HenryCoefficient = <_Moles as Sub<_Pressure>>::Output;
2828
pub type HenryCoefficient<T> = Quantity<T, _HenryCoefficient>;
2929

3030
/// Parameters required to specify a 1D pore.
@@ -139,9 +139,9 @@ where
139139
}
140140

141141
pub fn enthalpy_of_adsorption(&self) -> FeosResult<MolarEnergy> {
142-
Ok((self.partial_molar_enthalpy_of_adsorption()?
143-
* Dimensionless::new(&self.profile.bulk.molefracs))
144-
.sum())
142+
Ok(self
143+
.partial_molar_enthalpy_of_adsorption()?
144+
.dot(&Dimensionless::new(self.profile.bulk.molefracs.clone())))
145145
}
146146

147147
fn _henry_coefficients<N: DualNum<f64> + Copy + DctNum>(&self, temperature: N) -> DVector<N> {

0 commit comments

Comments
 (0)