Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make f64 the default inner type for all quantities #186

Merged
merged 1 commit into from
Sep 4, 2023
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
17 changes: 5 additions & 12 deletions benches/state_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::sync::Arc;
fn npt<E: Residual>(
(eos, t, p, n, rho0): (
&Arc<E>,
Temperature<f64>,
Pressure<f64>,
Temperature,
Pressure,
&Moles<Array1<f64>>,
DensityInitialization,
),
Expand Down Expand Up @@ -44,18 +44,11 @@ where
}

/// Evaluate temperature, pressure flash.
fn tp_flash<E: Residual>(
(eos, t, p, feed): (
&Arc<E>,
Temperature<f64>,
Pressure<f64>,
&Moles<Array1<f64>>,
),
) {
fn tp_flash<E: Residual>((eos, t, p, feed): (&Arc<E>, Temperature, Pressure, &Moles<Array1<f64>>)) {
PhaseEquilibrium::tp_flash(eos, t, p, feed, None, Default::default(), None).unwrap();
}

fn bubble_point<E: Residual>((eos, t, x): (&Arc<E>, Temperature<f64>, &Array1<f64>)) {
fn bubble_point<E: Residual>((eos, t, x): (&Arc<E>, Temperature, &Array1<f64>)) {
PhaseEquilibrium::bubble_point(
eos,
t,
Expand All @@ -67,7 +60,7 @@ fn bubble_point<E: Residual>((eos, t, x): (&Arc<E>, Temperature<f64>, &Array1<f6
.unwrap();
}

fn dew_point<E: Residual>((eos, t, y): (&Arc<E>, Temperature<f64>, &Array1<f64>)) {
fn dew_point<E: Residual>((eos, t, y): (&Arc<E>, Temperature, &Array1<f64>)) {
PhaseEquilibrium::dew_point(
eos,
t,
Expand Down
12 changes: 3 additions & 9 deletions benches/state_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn property<E: Residual, T, F: Fn(&State<E>, Contributions) -> T>(
(eos, property, t, v, n, contributions): (
&Arc<E>,
F,
Temperature<f64>,
Volume<f64>,
Temperature,
Volume,
&Moles<Array1<f64>>,
Contributions,
),
Expand All @@ -31,13 +31,7 @@ fn property<E: Residual, T, F: Fn(&State<E>, Contributions) -> T>(
/// Evaluate a property with of a state given the EoS, the property to compute,
/// temperature, volume, moles.
fn property_no_contributions<E: Residual, T, F: Fn(&State<E>) -> T>(
(eos, property, t, v, n): (
&Arc<E>,
F,
Temperature<f64>,
Volume<f64>,
&Moles<Array1<f64>>,
),
(eos, property, t, v, n): (&Arc<E>, F, Temperature, Volume, &Moles<Array1<f64>>),
) -> T {
let state = State::new_nvt(eos, t, v, n).unwrap();
property(&state)
Expand Down
12 changes: 6 additions & 6 deletions feos-core/src/density_iteration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::sync::Arc;

pub fn density_iteration<E: Residual>(
eos: &Arc<E>,
temperature: Temperature<f64>,
pressure: Pressure<f64>,
temperature: Temperature,
pressure: Pressure,
moles: &Moles<Array1<f64>>,
initial_density: Density<f64>,
initial_density: Density,
) -> EosResult<State<E>> {
let maxdensity = eos.max_density(Some(moles))?;
let (abstol, reltol) = (1e-12, 1e-14);
Expand Down Expand Up @@ -137,10 +137,10 @@ pub fn density_iteration<E: Residual>(

fn pressure_spinodal<E: Residual>(
eos: &Arc<E>,
temperature: Temperature<f64>,
rho_init: Density<f64>,
temperature: Temperature,
rho_init: Density,
moles: &Moles<Array1<f64>>,
) -> EosResult<(Pressure<f64>, Density<f64>)> {
) -> EosResult<(Pressure, Density)> {
let maxiter = 30;
let abstol = 1e-8;

Expand Down
18 changes: 9 additions & 9 deletions feos-core/src/equation_of_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ impl<I: IdealGas, R: Residual> Residual for EquationOfState<I, R> {
impl<I: IdealGas, R: Residual + EntropyScaling> EntropyScaling for EquationOfState<I, R> {
fn viscosity_reference(
&self,
temperature: Temperature<f64>,
volume: Volume<f64>,
temperature: Temperature,
volume: Volume,
moles: &Moles<Array1<f64>>,
) -> EosResult<Viscosity<f64>> {
) -> EosResult<Viscosity> {
self.residual
.viscosity_reference(temperature, volume, moles)
}
Expand All @@ -95,10 +95,10 @@ impl<I: IdealGas, R: Residual + EntropyScaling> EntropyScaling for EquationOfSta
}
fn diffusion_reference(
&self,
temperature: Temperature<f64>,
volume: Volume<f64>,
temperature: Temperature,
volume: Volume,
moles: &Moles<Array1<f64>>,
) -> EosResult<Diffusivity<f64>> {
) -> EosResult<Diffusivity> {
self.residual
.diffusion_reference(temperature, volume, moles)
}
Expand All @@ -107,10 +107,10 @@ impl<I: IdealGas, R: Residual + EntropyScaling> EntropyScaling for EquationOfSta
}
fn thermal_conductivity_reference(
&self,
temperature: Temperature<f64>,
volume: Volume<f64>,
temperature: Temperature,
volume: Volume,
moles: &Moles<Array1<f64>>,
) -> EosResult<ThermalConductivity<f64>> {
) -> EosResult<ThermalConductivity> {
self.residual
.thermal_conductivity_reference(temperature, volume, moles)
}
Expand Down
38 changes: 18 additions & 20 deletions feos-core/src/equation_of_state/residual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ pub trait Residual: Components + Send + Sync {
/// equilibria and other iterations. It is not explicitly meant to
/// be a mathematical limit for the density (if those exist in the
/// equation of state anyways).
fn max_density(&self, moles: Option<&Moles<Array1<f64>>>) -> EosResult<Density<f64>> {
fn max_density(&self, moles: Option<&Moles<Array1<f64>>>) -> EosResult<Density> {
let mr = self.validate_moles(moles)?.to_reduced();
Ok(Density::from_reduced(self.compute_max_density(&mr)))
}

/// Calculate the second virial coefficient $B(T)$
fn second_virial_coefficient(
&self,
temperature: Temperature<f64>,
temperature: Temperature,
moles: Option<&Moles<Array1<f64>>>,
) -> EosResult<<f64 as Div<Density<f64>>>::Output> {
) -> EosResult<<f64 as Div<Density>>::Output> {
let mr = self.validate_moles(moles)?;
let x = (&mr / mr.sum()).into_value();
let mut rho = HyperDual64::zero();
Expand All @@ -104,9 +104,9 @@ pub trait Residual: Components + Send + Sync {
#[allow(clippy::type_complexity)]
fn third_virial_coefficient(
&self,
temperature: Temperature<f64>,
temperature: Temperature,
moles: Option<&Moles<Array1<f64>>>,
) -> EosResult<<<f64 as Div<Density<f64>>>::Output as Div<Density<f64>>>::Output> {
) -> EosResult<<<f64 as Div<Density>>::Output as Div<Density>>::Output> {
let mr = self.validate_moles(moles)?;
let x = (&mr / mr.sum()).into_value();
let rho = Dual3_64::zero().derivative();
Expand All @@ -119,9 +119,9 @@ pub trait Residual: Components + Send + Sync {
#[allow(clippy::type_complexity)]
fn second_virial_coefficient_temperature_derivative(
&self,
temperature: Temperature<f64>,
temperature: Temperature,
moles: Option<&Moles<Array1<f64>>>,
) -> EosResult<<<f64 as Div<Density<f64>>>::Output as Div<Temperature<f64>>>::Output> {
) -> EosResult<<<f64 as Div<Density>>::Output as Div<Temperature>>::Output> {
let mr = self.validate_moles(moles)?;
let x = (&mr / mr.sum()).into_value();
let mut rho = HyperDual::zero();
Expand All @@ -138,12 +138,10 @@ pub trait Residual: Components + Send + Sync {
#[allow(clippy::type_complexity)]
fn third_virial_coefficient_temperature_derivative(
&self,
temperature: Temperature<f64>,
temperature: Temperature,
moles: Option<&Moles<Array1<f64>>>,
) -> EosResult<
<<<f64 as Div<Density<f64>>>::Output as Div<Density<f64>>>::Output as Div<
Temperature<f64>,
>>::Output,
<<<f64 as Div<Density>>::Output as Div<Density>>::Output as Div<Temperature>>::Output,
> {
let mr = self.validate_moles(moles)?;
let x = (&mr / mr.sum()).into_value();
Expand All @@ -160,23 +158,23 @@ pub trait Residual: Components + Send + Sync {
pub trait EntropyScaling {
fn viscosity_reference(
&self,
temperature: Temperature<f64>,
volume: Volume<f64>,
temperature: Temperature,
volume: Volume,
moles: &Moles<Array1<f64>>,
) -> EosResult<Viscosity<f64>>;
) -> EosResult<Viscosity>;
fn viscosity_correlation(&self, s_res: f64, x: &Array1<f64>) -> EosResult<f64>;
fn diffusion_reference(
&self,
temperature: Temperature<f64>,
volume: Volume<f64>,
temperature: Temperature,
volume: Volume,
moles: &Moles<Array1<f64>>,
) -> EosResult<Diffusivity<f64>>;
) -> EosResult<Diffusivity>;
fn diffusion_correlation(&self, s_res: f64, x: &Array1<f64>) -> EosResult<f64>;
fn thermal_conductivity_reference(
&self,
temperature: Temperature<f64>,
volume: Volume<f64>,
temperature: Temperature,
volume: Volume,
moles: &Moles<Array1<f64>>,
) -> EosResult<ThermalConductivity<f64>>;
) -> EosResult<ThermalConductivity>;
fn thermal_conductivity_correlation(&self, s_res: f64, x: &Array1<f64>) -> EosResult<f64>;
}
4 changes: 2 additions & 2 deletions feos-core/src/joback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl Joback {
/// Directly calculates the molar ideal gas heat capacity from the Joback model.
pub fn molar_isobaric_heat_capacity(
&self,
temperature: Temperature<f64>,
temperature: Temperature,
molefracs: &Array1<f64>,
) -> EosResult<MolarEntropy<f64>> {
) -> EosResult<MolarEntropy> {
let t = temperature.to_reduced();
let p = &self.parameters;
let c_p = (molefracs
Expand Down
Loading
Loading