Skip to content

Commit

Permalink
Replace #[allow(...)] with #[expect(...)] and incoroporate clippy…
Browse files Browse the repository at this point in the history
… suggestions (#255)
  • Loading branch information
prehner authored Sep 28, 2024
1 parent 4f0993c commit a361e55
Show file tree
Hide file tree
Showing 49 changed files with 91 additions and 51 deletions.
10 changes: 5 additions & 5 deletions benches/dual_numbers_saftvrmie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ fn bench_dual_numbers<E: Residual>(
) {
let mut group = c.benchmark_group(group_name);
group.bench_function("d_f64", |b| {
b.iter(|| d_hs((&parameters, state.derive0().temperature)))
b.iter(|| d_hs((parameters, state.derive0().temperature)))
});
group.bench_function("d_dual", |b| {
b.iter(|| d_hs((&parameters, state.derive1(Derivative::DT).temperature)))
b.iter(|| d_hs((parameters, state.derive1(Derivative::DT).temperature)))
});
group.bench_function("d_dual2", |b| {
b.iter(|| d_hs((&parameters, state.derive2(Derivative::DT).temperature)))
b.iter(|| d_hs((parameters, state.derive2(Derivative::DT).temperature)))
});
group.bench_function("d_hyperdual", |b| {
b.iter(|| {
d_hs((
&parameters,
parameters,
state
.derive2_mixed(Derivative::DT, Derivative::DT)
.temperature,
))
})
});
group.bench_function("d_dual3", |b| {
b.iter(|| d_hs((&parameters, state.derive3(Derivative::DT).temperature)))
b.iter(|| d_hs((parameters, state.derive3(Derivative::DT).temperature)))
});

group.bench_function("a_f64", |b| {
Expand Down
2 changes: 1 addition & 1 deletion feos-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.7.0"
authors = ["Gernot Bauer <[email protected]>",
"Philipp Rehner <[email protected]"]
edition = "2021"
rust-version = "1.80"
license = "MIT OR Apache-2.0"
description = "Core traits and functionalities for the `feos` project."
homepage = "https://github.com/feos-org"
Expand Down Expand Up @@ -34,7 +35,6 @@ rayon = { version = "1.5", optional = true }
typenum = "1.16"
approx = "0.5"
regex = "1.9"
once_cell = "1.18"
ang = "0.6"

[features]
Expand Down
3 changes: 1 addition & 2 deletions feos-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![warn(clippy::all)]
#![allow(clippy::reversed_empty_ranges)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::too_many_arguments)]
#![warn(clippy::allow_attributes)]

/// Print messages with level `Verbosity::Iter` or higher.
#[macro_export]
Expand Down
2 changes: 1 addition & 1 deletion feos-core/src/parameter/model_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<M> PureRecord<M> {
// collect into vec in correct order
Ok(substances
.iter()
.map(|s| records.get(&s.to_string()).unwrap().clone())
.map(|&s| records.get(s).unwrap().clone())
.collect())
}
}
Expand Down
2 changes: 2 additions & 0 deletions feos-core/src/phase_equilibria/phase_diagram_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
}
}

#[expect(clippy::too_many_arguments)]
fn iterate_vle<E: Residual, TP: TemperatureOrPressure>(
eos: &Arc<E>,
tp: TP,
Expand Down Expand Up @@ -242,6 +243,7 @@ impl<E: Residual> PhaseDiagram<E, 2> {
///
/// The `x_lle` parameter is used as initial values for the calculation
/// of the heteroazeotrope.
#[expect(clippy::too_many_arguments)]
pub fn binary_vlle<TP: TemperatureOrPressure>(
eos: &Arc<E>,
temperature_or_pressure: TP,
Expand Down
7 changes: 3 additions & 4 deletions feos-core/src/phase_equilibria/stability_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{SolverOptions, Verbosity};
use ndarray::*;
use num_dual::linalg::smallest_ev;
use num_dual::linalg::LU;
use std::f64::EPSILON;
use std::ops::MulAssign;

const X_DOMINANT: f64 = 0.99;
Expand Down Expand Up @@ -164,7 +163,7 @@ impl<E: Residual> State<E> {
let mut hesse = (self.dln_phi_dnj() * Moles::from_reduced(1.0)).into_value();
let lnphi = self.ln_phi();
let y = self.moles.to_reduced();
let ln_y = Zip::from(&y).map_collect(|&y| if y > EPSILON { y.ln() } else { 0.0 });
let ln_y = Zip::from(&y).map_collect(|&y| if y > f64::EPSILON { y.ln() } else { 0.0 });
let sq_y = y.mapv(f64::sqrt);
let gradient = (&ln_y + &lnphi - di) * &sq_y;

Expand All @@ -173,7 +172,7 @@ impl<E: Residual> State<E> {
hesse
.index_axis_mut(Axis(0), i)
.mul_assign(&(sq_y[i] * &sq_y));
if y[i] > EPSILON {
if y[i] > f64::EPSILON {
hesse[[i, i]] += ln_y[i] + lnphi[i] - di[i];
}
}
Expand Down Expand Up @@ -212,7 +211,7 @@ impl<E: Residual> State<E> {
}

let y = (&sq_y - &(delta_y / 2.0)).mapv(|v| v.powi(2));
let ln_y = Zip::from(&y).map_collect(|&y| if y > EPSILON { y.ln() } else { 0.0 });
let ln_y = Zip::from(&y).map_collect(|&y| if y > f64::EPSILON { y.ln() } else { 0.0 });
*tpd = 1.0 + (&y * &(&ln_y + &lnphi - di - 1.0)).sum();
if *tpd > tpd_old + 0.0 * 1E-03 && eta_h < 30.0 {
eta_h += ETA_STEP;
Expand Down
1 change: 1 addition & 0 deletions feos-core/src/phase_equilibria/tp_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ impl<E: Residual> PhaseEquilibrium<E, 2> {
Err(EosError::NotConverged("TP flash".to_owned()))
}

#[expect(clippy::too_many_arguments)]
fn successive_substitution(
&mut self,
feed_state: &State<E>,
Expand Down
10 changes: 10 additions & 0 deletions feos-core/src/python/phase_equilibria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ macro_rules! impl_phase_equilibrium {
/// When pressure iteration fails or no phase equilibrium is found.
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature, pressure, feed, initial_state=None, max_iter=None, tol=None, verbosity=None, non_volatile_components=None)")]
#[expect(clippy::too_many_arguments)]
pub fn tp_flash(
eos: $py_eos,
temperature: PySINumber,
Expand Down Expand Up @@ -155,6 +156,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseEquilibrium
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature_or_pressure, liquid_molefracs, tp_init=None, vapor_molefracs=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn bubble_point<'py>(
eos: $py_eos,
temperature_or_pressure: PySINumber,
Expand Down Expand Up @@ -232,6 +234,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseEquilibrium
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature_or_pressure, vapor_molefracs, tp_init=None, liquid_molefracs=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn dew_point<'py>(
eos: $py_eos,
temperature_or_pressure: PySINumber,
Expand Down Expand Up @@ -449,6 +452,7 @@ macro_rules! impl_phase_equilibrium {
/// The verbosity of the bubble/dew point iteration.
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature_or_pressure, x_init, tp_init=None, max_iter=None, tol=None, verbosity=None, max_iter_bd_inner=None, max_iter_bd_outer=None, tol_bd_inner=None, tol_bd_outer=None, verbosity_bd=None)")]
#[expect(clippy::too_many_arguments)]
fn heteroazeotrope(
eos: $py_eos,
temperature_or_pressure: PySINumber,
Expand Down Expand Up @@ -659,6 +663,7 @@ macro_rules! impl_phase_equilibrium {
#[cfg(feature = "rayon")]
#[staticmethod]
#[pyo3(text_signature = "(eos, min_temperature, npoints, chunksize, nthreads, critical_temperature=None, max_iter=None, tol=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn par_pure(
eos: &$py_eos,
min_temperature: PySINumber,
Expand Down Expand Up @@ -721,6 +726,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseDiagram
#[staticmethod]
#[pyo3(text_signature = "(eos, moles, min_temperature, npoints, critical_temperature=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn bubble_point_line(
eos: &$py_eos,
moles: PySIArray1,
Expand Down Expand Up @@ -783,6 +789,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseDiagram
#[staticmethod]
#[pyo3(text_signature = "(eos, moles, min_temperature, npoints, critical_temperature=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn dew_point_line(
eos: &$py_eos,
moles: PySIArray1,
Expand Down Expand Up @@ -837,6 +844,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseDiagram
#[staticmethod]
#[pyo3(text_signature = "(eos, moles, min_temperature, npoints, critical_temperature=None, max_iter=None, tol=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn spinodal(
eos: &$py_eos,
moles: PySIArray1,
Expand Down Expand Up @@ -972,6 +980,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseDiagram
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature_or_pressure, npoints=None, x_lle=None, max_iter_inner=None, max_iter_outer=None, tol_inner=None, tol_outer=None, verbosity=None)")]
#[expect(clippy::too_many_arguments)]
pub fn binary_vle(
eos: $py_eos,
temperature_or_pressure: PySINumber,
Expand Down Expand Up @@ -1115,6 +1124,7 @@ macro_rules! impl_phase_equilibrium {
/// PhaseDiagramHetero
#[staticmethod]
#[pyo3(text_signature = "(eos, temperature_or_pressure, x_lle, tp_lim_lle=None, tp_init_vlle=None, npoints_vle=None, npoints_lle=None, max_iter_bd_inner=None, max_iter_bd_outer=None, tol_bd_inner=None, tol_bd_outer=None, verbosity_bd=None)")]
#[expect(clippy::too_many_arguments)]
pub fn binary_vlle(
eos: $py_eos,
temperature_or_pressure: PySINumber,
Expand Down
1 change: 1 addition & 0 deletions feos-core/src/python/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ macro_rules! impl_state {
impl PyState {
#[new]
#[pyo3(text_signature = "(eos, temperature=None, volume=None, density=None, partial_density=None, total_moles=None, moles=None, molefracs=None, pressure=None, molar_enthalpy=None, molar_entropy=None, molar_internal_energy=None, density_initialization=None, initial_temperature=None)")]
#[expect(clippy::too_many_arguments)]
pub fn new<'py>(
eos: $py_eos,
temperature: Option<PySINumber>,
Expand Down
4 changes: 2 additions & 2 deletions feos-core/src/si/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::*;
use ndarray::{Array, Dimension};
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::fmt;
use std::sync::LazyLock;
use typenum::{Quot, N1, N2, N3, P2, P3, P4};

const UNIT_SYMBOLS: [&str; 7] = ["s", "m", "kg", "A", "K", "mol", "cd"];
Expand Down Expand Up @@ -144,7 +144,7 @@ fn get_prefix(value: f64, has_prefix: Option<f64>) -> (f64, &'static str) {
(value, "")
}

static PREFIX_SYMBOLS: Lazy<HashMap<i8, &'static str>> = Lazy::new(|| {
static PREFIX_SYMBOLS: LazyLock<HashMap<i8, &'static str>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert(0, " ");
m.insert(-24, "y");
Expand Down
10 changes: 6 additions & 4 deletions feos-core/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl<E: Residual> State<E> {
/// # Errors
///
/// When the state cannot be created using the combination of inputs.
#[expect(clippy::too_many_arguments)]
pub fn new(
eos: &Arc<E>,
temperature: Option<Temperature>,
Expand Down Expand Up @@ -317,6 +318,7 @@ impl<E: Residual> State<E> {
.map_err(|_| EosError::UndeterminedState(String::from("Missing input parameters.")))
}

#[expect(clippy::too_many_arguments)]
fn _new(
eos: &Arc<E>,
temperature: Option<Temperature>,
Expand Down Expand Up @@ -505,6 +507,7 @@ impl<E: Residual + IdealGas> State<E> {
/// # Errors
///
/// When the state cannot be created using the combination of inputs.
#[expect(clippy::too_many_arguments)]
pub fn new_full(
eos: &Arc<E>,
temperature: Option<Temperature>,
Expand Down Expand Up @@ -759,7 +762,7 @@ fn is_close<U: Copy>(
(x - y).abs() <= atol + rtol * y.abs()
}

fn newton<E: Residual, F, X: Copy, Y: Copy>(
fn newton<E: Residual, F, X: Copy, Y>(
mut x0: Quantity<f64, X>,
mut f: F,
atol: Quantity<f64, X>,
Expand Down Expand Up @@ -852,7 +855,6 @@ mod critical_point;
#[cfg(test)]
mod tests {
use super::*;
use std::f64::NAN;
use typenum::P3;

#[test]
Expand All @@ -873,7 +875,7 @@ mod tests {

#[test]
fn test_nan_temperature() {
let temperature = NAN * KELVIN;
let temperature = f64::NAN * KELVIN;
let volume = 3000.0 * METER.powi::<P3>();
let moles = &arr1(&[0.03, 0.02, 0.05]) * MOL;
assert!(validate(temperature, volume, &moles).is_err());
Expand All @@ -891,7 +893,7 @@ mod tests {
fn test_nan_mole_number() {
let temperature = 298.15 * KELVIN;
let volume = 3000.0 * METER.powi::<P3>();
let moles = &arr1(&[NAN, 0.02, 0.05]) * MOL;
let moles = &arr1(&[f64::NAN, 0.02, 0.05]) * MOL;
assert!(validate(temperature, volume, &moles).is_err());
}

Expand Down
1 change: 1 addition & 0 deletions feos-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This crate provides derive macros used for the EosVariant and
//! FunctionalVariant enums in FeOs. The macros implement
//! the boilerplate for the EquationOfState and HelmholtzEnergyFunctional traits.
#![warn(clippy::all)]
use components::expand_components;
use dft::expand_helmholtz_energy_functional;
use functional_contribution::expand_functional_contribution;
Expand Down
7 changes: 3 additions & 4 deletions feos-dft/src/adsorption/external_potential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ pub trait FluidParameters: HelmholtzEnergyFunctional {
fn sigma_ff(&self) -> &Array1<f64>;
}

#[allow(unused_variables)]
impl ExternalPotential {
// Evaluate the external potential in cartesian coordinates for a given grid and fluid parameters.
pub fn calculate_cartesian_potential<P: FluidParameters>(
&self,
z_grid: &Array1<f64>,
fluid_parameters: &P,
temperature: f64,
#[cfg_attr(not(feature = "rayon"), expect(unused_variables))] temperature: f64,
) -> Array2<f64> {
if let ExternalPotential::Custom(potential) = self {
return potential.clone();
Expand Down Expand Up @@ -228,7 +227,7 @@ impl ExternalPotential {
r_grid: &Array1<f64>,
pore_size: f64,
fluid_parameters: &P,
temperature: f64,
#[cfg_attr(not(feature = "rayon"), expect(unused_variables))] temperature: f64,
) -> Array2<f64> {
if let ExternalPotential::Custom(potential) = self {
return potential.clone();
Expand Down Expand Up @@ -394,7 +393,7 @@ impl ExternalPotential {
r_grid: &Array1<f64>,
pore_size: f64,
fluid_parameters: &P,
temperature: f64,
#[cfg_attr(not(feature = "rayon"), expect(unused_variables))] temperature: f64,
) -> Array2<f64> {
if let ExternalPotential::Custom(potential) = self {
return potential.clone();
Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/adsorption/fea_potential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use feos_core::si::Length;
use gauss_quad::GaussLegendre;
use ndarray::{Array1, Array2, Zip};
use std::f64::consts::PI;
use std::usize;

// Calculate free-energy average potential for given solid structure.
#[expect(clippy::too_many_arguments)]
pub fn calculate_fea_potential(
grid: &Array1<f64>,
mi: f64,
Expand Down
1 change: 1 addition & 0 deletions feos-dft/src/adsorption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ where
}

/// Calculate the phase transition from an empty to a filled pore.
#[expect(clippy::too_many_arguments)]
pub fn phase_equilibrium<S: PoreSpecification<D>>(
functional: &Arc<DFT<F>>,
temperature: Temperature,
Expand Down
2 changes: 2 additions & 0 deletions feos-dft/src/adsorption/pore3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Pore3D {
}

impl Pore3D {
#[expect(clippy::too_many_arguments)]
pub fn new(
system_size: [Length; 3],
n_grid: [usize; 3],
Expand Down Expand Up @@ -107,6 +108,7 @@ impl PoreSpecification<Ix3> for Pore3D {
}
}

#[expect(clippy::too_many_arguments)]
pub fn external_potential_3d<F: FluidParameters>(
functional: &F,
axis: [&Axis; 3],
Expand Down
3 changes: 3 additions & 0 deletions feos-dft/src/convolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) struct BulkConvolver<T> {
}

impl<T: DualNum<f64> + Copy + Send + Sync> BulkConvolver<T> {
#[expect(clippy::new_ret_no_self)]
pub(crate) fn new(weight_functions: Vec<WeightFunctionInfo<T>>) -> Arc<dyn Convolver<T, Ix0>> {
let weight_constants = weight_functions
.into_iter()
Expand Down Expand Up @@ -163,6 +164,7 @@ where
D::Larger: Dimension<Smaller = D>,
<D::Larger as Dimension>::Larger: Dimension<Smaller = D::Larger>,
{
#[expect(clippy::new_ret_no_self)]
fn new(
axis: Option<&Axis>,
cartesian_axes: &[&Axis],
Expand Down Expand Up @@ -560,6 +562,7 @@ where
D::Smaller: Dimension<Larger = D>,
<D::Larger as Dimension>::Larger: Dimension<Smaller = D::Larger>,
{
#[expect(clippy::new_ret_no_self)]
fn new(
r: &Axis,
z: &[&Axis],
Expand Down
1 change: 1 addition & 0 deletions feos-dft/src/convolver/periodic_convolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ where
Self::new(axes, f, weight_functions, lanczos)
}

#[expect(clippy::new_ret_no_self)]
pub fn new<F: Fn(&mut Array<f64, D::Larger>)>(
axes: &[&Axis],
non_orthogonal_correction: F,
Expand Down
Loading

0 comments on commit a361e55

Please sign in to comment.