Skip to content

Commit

Permalink
do some clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Mar 18, 2024
1 parent a42c8bc commit c324e64
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 106 deletions.
1 change: 0 additions & 1 deletion src/core/ductwork.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::input::MVHRLocation;
use std::error::Error;
use std::f64::consts::PI;

// Set default value for the heat transfer coefficient inside the duct, in W / m^2 K
Expand Down
3 changes: 1 addition & 2 deletions src/core/energy_supply/energy_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::input::{
ElectricBattery, EnergyDiverter, EnergySupplyDetails, EnergySupplyInput, EnergySupplyType,
HeatNetwork,
};
use crate::simulation_time::SimulationTimeIterator;
use std::collections::HashMap;

// a slightly looser definition of an energy supply that includes heat networks
Expand Down Expand Up @@ -230,7 +229,7 @@ fn supply_from_details(
mod test {
use super::*;
use crate::input::EnergySupplyType::MainsGas;
use crate::simulation_time::SimulationTime;
use crate::simulation_time::{SimulationTime, SimulationTimeIterator};
use rstest::*;

#[fixture]
Expand Down
2 changes: 1 addition & 1 deletion src/core/heating_systems/boiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
use std::fmt;
use std::sync::Arc;

enum ServiceType {
pub enum ServiceType {
WaterCombi,
WaterRegular,
Space,
Expand Down
2 changes: 1 addition & 1 deletion src/core/heating_systems/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SpaceHeatSystem {
simulation_time_iteration: SimulationTimeIteration,
) -> (f64, f64) {
match self {
SpaceHeatSystem::Instant(instant) => unreachable!(), // it isn't expected that this will be called on instant heaters
SpaceHeatSystem::Instant(_instant) => unreachable!(), // it isn't expected that this will be called on instant heaters
SpaceHeatSystem::WarmAir(warm_air) => warm_air.running_time_throughput_factor(
energy_demand,
space_heat_running_time_cumulative,
Expand Down
2 changes: 1 addition & 1 deletion src/core/heating_systems/heat_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::core::common::WaterSourceWithTemperature;
use crate::core::controls::time_control::{per_control, Control, ControlBehaviour};
use crate::core::material_properties::WATER;
use crate::core::units::{HOURS_PER_DAY, WATTS_PER_KILOWATT};
use crate::core::water_heat_demand::cold_water_source::ColdWaterSource;
use crate::simulation_time::SimulationTimeIteration;
use parking_lot::Mutex;
use std::sync::Arc;
Expand Down Expand Up @@ -318,6 +317,7 @@ impl HeatNetwork {
mod tests {
use super::*;
use crate::core::controls::time_control::SetpointTimeControl;
use crate::core::water_heat_demand::cold_water_source::ColdWaterSource;
use crate::simulation_time::SimulationTime;
use rstest::*;

Expand Down
40 changes: 17 additions & 23 deletions src/core/heating_systems/heat_pump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ use itertools::Itertools;
use ordered_float::OrderedFloat;
use parking_lot::Mutex;
use polyfit_rs::polyfit_rs::polyfit;
use serde::Deserialize;
use serde_enum_str::Serialize_enum_str;
use std::collections::HashMap;
use std::hash::Hash;
use std::iter::Sum;
use std::ops::{Add, Div};
use std::sync::{Arc, MutexGuard, PoisonError};
use std::sync::Arc;

/// This module provides objects to represent heat pumps and heat pump test data.
/// The calculations are based on the DAHPSE method developed for generating PCDB
Expand Down Expand Up @@ -62,7 +60,7 @@ impl HeatPumpSourceType {
}

#[derive(Copy, Clone, Serialize_enum_str)]
enum ServiceType {
pub enum ServiceType {
Water,
Space,
}
Expand Down Expand Up @@ -133,7 +131,7 @@ fn interpolate_exhaust_air_heat_pump_test_data(
fixed_temps_and_test_letters = Some(fixed_temps_and_test_letters_this);
}
Some(ref fixed_temps_and_test_letters) => {
if (fixed_temps_and_test_letters != &fixed_temps_and_test_letters_this) {
if fixed_temps_and_test_letters != &fixed_temps_and_test_letters_this {
return Err("In heat pump test data, fixed temps and test_letters were not consistent for one air_flow_temp value".to_string());
}
}
Expand Down Expand Up @@ -211,7 +209,7 @@ fn test_letter(letter: &str) -> TestLetter {

#[derive(Derivative)]
#[derivative(PartialEq, Debug)]
struct TestDatumTempsAndTestLetters<'a> {
pub struct TestDatumTempsAndTestLetters<'a> {
#[derivative(PartialEq = "ignore")]
// we need to ignore air flow rate when performing comparisons
pub air_flow_rate: f64,
Expand All @@ -223,7 +221,7 @@ struct TestDatumTempsAndTestLetters<'a> {
}

#[derive(Copy, Clone, Debug, PartialEq)]
struct CompleteHeatPumpTestDatum {
pub struct CompleteHeatPumpTestDatum {
pub air_flow_rate: Option<f64>,
pub test_letter: TestLetter,
pub capacity: f64,
Expand All @@ -249,7 +247,7 @@ impl CompleteHeatPumpTestDatum {
}
}

enum DatumItem {
pub enum DatumItem {
CarnotCop,
TempOutlet,
TempSource,
Expand Down Expand Up @@ -330,9 +328,7 @@ impl HeatPumpTestData {
if !dsgn_flow_temps.contains(&dsgn_flow_temp) {
dsgn_flow_temps.push(dsgn_flow_temp);
}
test_data
.entry(dsgn_flow_temp)
.or_insert_with(|| Default::default());
test_data.entry(dsgn_flow_temp).or_default();
}

let mut duplicate = false;
Expand Down Expand Up @@ -444,9 +440,9 @@ impl HeatPumpTestData {
let temp_source = celsius_to_kelvin(datum.temp_source);
let temp_outlet = celsius_to_kelvin(datum.temp_outlet);

let theoretical_load_ratio = ((carnot_cops[i] / carnot_cop_cld)
let theoretical_load_ratio = (carnot_cops[i] / carnot_cop_cld)
* (temp_outlet_cld * temp_source / (temp_source_cld * temp_outlet))
.powf(N_EXER));
.powf(N_EXER);
acc.push(theoretical_load_ratio);
acc
});
Expand Down Expand Up @@ -1975,13 +1971,11 @@ impl HeatPump {
if temp_output > temp_limit_upper {
if temp_output == temp_used_for_scaling {
energy_output_required
} else if (temp_limit_upper - temp_used_for_scaling) >= self.temp_diff_flow_return_min {
energy_output_required * (temp_limit_upper - temp_used_for_scaling)
/ (temp_output - temp_used_for_scaling)
} else {
if (temp_limit_upper - temp_used_for_scaling) >= self.temp_diff_flow_return_min {
energy_output_required * (temp_limit_upper - temp_used_for_scaling)
/ (temp_output - temp_used_for_scaling)
} else {
0.
}
0.
}
} else {
energy_output_required
Expand Down Expand Up @@ -2434,8 +2428,8 @@ impl HeatPump {
(1. - deg_coeff_op_cond)
* (compressor_power_min_load / load_ratio_continuous_min)
* max_of_2(
(time_remaining_current_timestep
- load_ratio / load_ratio_continuous_min * timestep),
time_remaining_current_timestep
- load_ratio / load_ratio_continuous_min * timestep,
0.,
)
} else {
Expand Down Expand Up @@ -2714,12 +2708,12 @@ fn result_str(string: &str) -> ResultString {
name
}

enum TempSpreadCorrectionArg {
pub enum TempSpreadCorrectionArg {
Float(f64),
Callable(Box<dyn FnOnce(f64, f64) -> f64>),
}

enum ServiceResult {
pub enum ServiceResult {
Full(HeatPumpEnergyCalculation),
Aux(AuxiliaryParameters),
}
Expand Down
19 changes: 9 additions & 10 deletions src/core/heating_systems/storage_tank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use crate::core::controls::time_control::Control;
use crate::core::material_properties::MaterialProperties;
use crate::core::pipework::Pipework;
use crate::core::units::WATTS_PER_KILOWATT;
use crate::core::water_heat_demand::cold_water_source::ColdWaterSource;
use crate::corpus::{Controls, HeatSource, PositionedHeatSource};
use crate::corpus::{HeatSource, PositionedHeatSource};
use crate::external_conditions::ExternalConditions;
use crate::input::{HeatSource as HeatSourceInput, SolarCellLocation, WaterPipework};
use crate::input::{SolarCellLocation, WaterPipework};
use crate::simulation_time::SimulationTimeIteration;
use indexmap::IndexMap;
use itertools::Itertools;
use parking_lot::Mutex;
use std::collections::HashMap;
use std::iter::zip;
Expand Down Expand Up @@ -439,7 +437,7 @@ impl StorageTank {
// output energy delivered by the storage in kWh - timestep dependent
let mut q_sto_h_out_n: [f64; STORAGE_TANK_NB_VOL] = Default::default();

for i in (0..self.vol_n.len()) {
for i in 0..self.vol_n.len() {
delta_temp_n[i] =
(q_x_in_n[i] + q_sto_h_out_n[i]) / (self.rho * self.cp * self.vol_n[i]);
temp_s6_n[i] = temp_s3_n[i] + delta_temp_n[i];
Expand Down Expand Up @@ -467,7 +465,7 @@ impl StorageTank {

// loop through layers from bottom to top, without including top layer;
// this is because the top layer has no upper layer to compare to
for i in (0..self.vol_n.len() - 1) {
for i in 0..self.vol_n.len() - 1 {
if temp_s7_n[i] > temp_s7_n[i + 1] {
// set layers to mix
mix_layer_n[i] = 1;
Expand All @@ -482,7 +480,7 @@ impl StorageTank {
.map(|l| self.vol_n[l] * mix_layer_n[l] as f64)
.sum::<f64>();
// set same temperature for all applicable layers
for j in (0..i + 2) {
for j in 0..i + 2 {
if mix_layer_n[j] == 1 {
temp_s7_n[j] = temp_mix;
}
Expand Down Expand Up @@ -532,7 +530,7 @@ impl StorageTank {
// timestep (it seems to assume a 1 hour timestep implicitly), but it is
// necessary to convert the rate of heat loss to a total heat loss over
// the time period
for i in (0..self.vol_n.len()) {
for i in 0..self.vol_n.len() {
q_ls_n[i] = (h_sto_ls * self.rho * self.cp)
* (self.vol_n[i] / self.volume_total_in_litres)
* (*[temp_s7_n[i], self.temp_set_on]
Expand All @@ -553,7 +551,7 @@ impl StorageTank {
// the final value of the temperature is reduced due to the effect of the thermal losses.
// check temperature compared to set point
// the temperature for each volume are limited to the set point for any volume controlled
for i in (0..self.vol_n.len()) {
for i in 0..self.vol_n.len() {
temp_s8_n[i] = if temp_s7_n[i] > self.temp_set_on {
// Case 2 - Temperature exceeding the set point
self.temp_set_on
Expand Down Expand Up @@ -1162,7 +1160,7 @@ impl SolarThermalSystem {
let mut inlet_temp2: f64 = Default::default(); // need a running slot in the loop for this to be overridden each time

// calculation of collector efficiency
for _ in (0..4) {
for _ in 0..4 {
// Eq 53
let th = (avg_collector_water_temp
- self.external_conditions.air_temp(simulation_time))
Expand Down Expand Up @@ -1243,6 +1241,7 @@ mod tests {
use super::*;
use crate::core::controls::time_control::{per_control, OnOffTimeControl};
use crate::core::material_properties::WATER;
use crate::core::water_heat_demand::cold_water_source::ColdWaterSource;
use crate::corpus::HeatSource;
use crate::input::{EnergySupplyType, HeatSourceControl, HeatSourceControlType};
use crate::simulation_time::SimulationTime;
Expand Down
2 changes: 0 additions & 2 deletions src/core/schedule.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::input::{Schedule, WaterHeatingEvent};
use serde_json::Value;
use std::collections::HashMap;
use std::ops::Index;

pub type BooleanSchedule = Vec<bool>;
pub type NumericSchedule = Vec<f64>;
Expand Down
6 changes: 3 additions & 3 deletions src/core/space_heat_demand/thermal_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub enum ThermalBridge {
}

pub fn heat_transfer_coefficient_for_thermal_bridge(thermal_bridge: &ThermalBridge) -> f64 {
match thermal_bridge {
&ThermalBridge::Linear {
match *thermal_bridge {
ThermalBridge::Linear {
linear_thermal_transmittance: t,
length: l,
} => t * l,
&ThermalBridge::Point {
ThermalBridge::Point {
heat_transfer_coefficient: h,
} => h,
}
Expand Down
14 changes: 7 additions & 7 deletions src/core/space_heat_demand/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ pub fn space_heat_cool_demand(
temp_setpnt_heat: f64,
temp_setpnt_cool: f64,
throughput_factor: Option<f64>,
building_elements: &Vec<NamedBuildingElement>,
element_positions: &Vec<(usize, usize)>,
vent_elements: &Vec<VentilationElement>,
building_elements: &[NamedBuildingElement],
element_positions: &[(usize, usize)],
vent_elements: &[VentilationElement],
vent_cool_extra: &Option<WindowOpeningForCooling>,
simulation_time: &SimulationTimeIteration,
external_conditions: &ExternalConditions,
temp_prev: &Vec<f64>,
temp_prev: &[f64],
no_of_temps: usize,
area_el_total: f64,
area: f64,
Expand Down Expand Up @@ -822,16 +822,16 @@ fn calc_temperatures(
vent_extra_h_ve: Option<f64>,
throughput_factor: Option<f64>,
no_of_temps: usize,
building_elements: &Vec<NamedBuildingElement>,
element_positions: &Vec<(usize, usize)>,
building_elements: &[NamedBuildingElement],
element_positions: &[(usize, usize)],
external_conditions: &ExternalConditions,
simulation_time: &SimulationTimeIteration,
passed_zone_idx: usize,
area_el_total: f64,
volume: f64,
c_int: f64,
tb_heat_trans_coeff: f64,
vent_elements: &Vec<VentilationElement>,
vent_elements: &[VentilationElement],
vent_cool_extra: &Option<WindowOpeningForCooling>,
print_heat_balance: Option<bool>,
) -> (Vec<f64>, Option<()>) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/water_heat_demand/dhw_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl DomesticHotWaterDemand {
.flat_map(|input| {
let mut showers = vec![(
"mixer".to_owned(),
mixer_shower_input_to_shower(&input.mixer, cold_water_sources, &wwhrs),
mixer_shower_input_to_shower(&input.mixer, cold_water_sources, wwhrs),
)];
if let Some(ies) = &input.ies {
showers.push((
Expand Down Expand Up @@ -321,7 +321,7 @@ fn mixer_shower_input_to_shower(
let wwhrs_instance: Option<Wwhrs> = input
.waste_water_heat_recovery
.as_ref()
.and_then(|w| wwhrs.get(&w.to_string()).map(|system| system.clone()));
.and_then(|w| wwhrs.get(&w.to_string()).cloned());

Shower::MixerShower(MixerShower::new(
input.flowrate,
Expand Down
3 changes: 1 addition & 2 deletions src/core/water_heat_demand/other_hot_water_uses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ impl OtherHotWater {
// TODO (from Python) Account for behavioural variation factor fbeh (sic)
let vol_warm_water = self.flowrate * total_demand_duration;
// ^^^ litres = litres/minute * minutes
let vol_hot_water = vol_warm_water * frac_hot_water(temp_target, self.temp_hot, temp_cold);

vol_hot_water
vol_warm_water * frac_hot_water(temp_target, self.temp_hot, temp_cold)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/core/water_heat_demand/shower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::core::material_properties::WATER;
use crate::core::units::MINUTES_PER_HOUR;
use crate::core::water_heat_demand::cold_water_source::ColdWaterSource;
use crate::core::water_heat_demand::misc::frac_hot_water;
use crate::corpus::ColdWaterSources;

pub enum Shower {
MixerShower(MixerShower),
Expand Down
Loading

0 comments on commit c324e64

Please sign in to comment.